Re: [PATCH RFC v9 0/7] Introduce the STACKLEAK feature and a test for it

2018-03-05 Thread Kees Cook
On Mon, Mar 5, 2018 at 11:42 AM, Dave Hansen
 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


Re: [PATCH RFC v9 0/7] Introduce the STACKLEAK feature and a test for it

2018-03-05 Thread Kees Cook
On Mon, Mar 5, 2018 at 11:42 AM, Dave Hansen
 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


Re: [PATCH RFC v9 0/7] Introduce the STACKLEAK feature and a test for it

2018-03-05 Thread Dave Hansen
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.



Re: [PATCH RFC v9 0/7] Introduce the STACKLEAK feature and a test for it

2018-03-05 Thread Dave Hansen
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.



Re: [PATCH RFC v9 0/7] Introduce the STACKLEAK feature and a test for it

2018-03-05 Thread Kees Cook
On Sat, Mar 3, 2018 at 12:00 PM, Alexander Popov  wrote:
> This is the 9th version of the patch series introducing STACKLEAK to the
> mainline kernel. STACKLEAK is a security feature developed by Grsecurity/PaX
> (kudos to them), which:
>  - reduces the information that can be revealed through kernel stack leak 
> bugs;
>  - blocks some uninitialized stack variable attacks (e.g. CVE-2017-17712,
> CVE-2010-2963);
>  - introduces some runtime checks for kernel stack overflow detection.

Thanks for continuing to chip away at this! I wonder if it's time to
drop the "RFC" part of this? It seems like this should be ready to
land pretty soon. I can start carrying this in the kspp -next tree,
for example. I'd like to get some sign-off from x86, though.

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?

-Kees

-- 
Kees Cook
Pixel Security


Re: [PATCH RFC v9 0/7] Introduce the STACKLEAK feature and a test for it

2018-03-05 Thread Kees Cook
On Sat, Mar 3, 2018 at 12:00 PM, Alexander Popov  wrote:
> This is the 9th version of the patch series introducing STACKLEAK to the
> mainline kernel. STACKLEAK is a security feature developed by Grsecurity/PaX
> (kudos to them), which:
>  - reduces the information that can be revealed through kernel stack leak 
> bugs;
>  - blocks some uninitialized stack variable attacks (e.g. CVE-2017-17712,
> CVE-2010-2963);
>  - introduces some runtime checks for kernel stack overflow detection.

Thanks for continuing to chip away at this! I wonder if it's time to
drop the "RFC" part of this? It seems like this should be ready to
land pretty soon. I can start carrying this in the kspp -next tree,
for example. I'd like to get some sign-off from x86, though.

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?

-Kees

-- 
Kees Cook
Pixel Security