Re: [PATCH RFC v9 0/7] Introduce the STACKLEAK feature and a test for it
From: Kees Cook
Date: Mon Mar 05 2018 - 15:03:01 EST
On Mon, Mar 5, 2018 at 11:42 AM, Dave Hansen
<dave.hansen@xxxxxxxxxxxxxxx> wrote:
> On 03/05/2018 11:34 AM, Kees Cook wrote:
>> Boris, Andy, and Dave (Hansen), you've all looked at this; would you
>> be willing to give an Ack on the x86 parts? (Though I do now see a new
>> comment from Dave was just sent.) And if not, what changes would you
>> like to see?
>
> I think it could definitely use another cleanup and de-#ifdef'ing pass.
> It seems to have inherited the style from the original code and it's a
> bit more than we're used to in mainline.
There are a few places it could be minimized, that's true. It looked
like it might not be worth it, but the places I see are:
include/linux/compiler.h:
+#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
+/* Poison value points to the unused hole in the virtual memory map */
+# define STACKLEAK_POISON -0xBEEF
+# define STACKLEAK_POISON_CHECK_DEPTH 128
+#endif
This doesn't need an #ifdef wrapper...
arch/x86/kernel/process_64.c and arch/x86/kernel/process_32.c:
+#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
+ p->thread.lowest_stack = (unsigned long)task_stack_page(p) +
+ 2 * sizeof(unsigned long);
+#endif
This could be made into a helper function, maybe, in processor.h? Like:
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
# define record_lowest_stack(p) do { \
p->thread.lowest_stack = (unsigned long)task_stack_page(p) +
2 * sizeof(unsigned long);
} while (0)
#else
# define save_lowest_stack(p) do { } while (0)
#endif
And the uses in process_*.c would be:
save_lowest_stack(p);
?
And "fs/proc: Show STACKLEAK metrics in the /proc file system" could
maybe be adjusted too?
It doesn't seem like a lot of savings, but what do you think?
One new thing did pop out at me in this review, track_stack() likely
shouldn't live in fs/exec.c. It has nothing to do with exec(). There
aren't a lot of good places, but maybe a better place would be
mm/util.c. (A whole new source file seems like overkill.)
-Kees
--
Kees Cook
Pixel Security