On Wed, Jul 07, 2021 at 05:38:02PM +0000, Qing Zhao wrote: > Hi, > > This is the 4th version of the patch for the new security feature for GCC. > > I have tested it with bootstrap on both x86 and aarch64, regression testing > on both x86 and aarch64. > Also compile and run CPU2017, without any issue. > > Please take a look and let me know your comments and suggestions.
Thanks for the update! It looks like padding initialization has regressed to where things where in version 1[1] (it was, however, working in version 2[2]). I'm seeing these failures again in the kernel self-test: test_stackinit: small_hole_static_all FAIL (uninit bytes: 3) test_stackinit: big_hole_static_all FAIL (uninit bytes: 61) test_stackinit: trailing_hole_static_all FAIL (uninit bytes: 7) test_stackinit: small_hole_dynamic_all FAIL (uninit bytes: 3) test_stackinit: big_hole_dynamic_all FAIL (uninit bytes: 61) test_stackinit: trailing_hole_dynamic_all FAIL (uninit bytes: 7) In looking at the gcc test cases, I think the wrong thing is being checked: we want to verify the padding itself. For example, in auto-init-17.c, the actual bytes after "four" need to be checked, rather than "four" itself. For example, something like this: struct test_trailing_hole { int one; int two; int three; char four; /* "sizeof(unsigned long) - 1" byte padding hole here. */ }; #define offsetofend(STRUCT, MEMBER) \ (__builtin_offsetof(STRUCT, MEMBER) + sizeof((((STRUCT *)0)->MEMBER))) int foo () { struct test_trailing_hole var[10]; unsigned char *ptr = (unsigned char *)&var[2]; int i; for (i = 0; i < sizeof(var[2]) - offsetofend(typeof(var[2]), four); i++) { if (ptr[i] != 0) return 1; } return 0; } But this isn't actually sufficient because they may _accidentally_ be zero already. The kernel tests specifically make sure to fill the about-to-be-used stack with 0xff before calling a function like foo() above. (And as an aside, it seems like naming the test cases with some details about what is being tested in the filename would be nice -- it was a little weird having to dig through their numeric names to find the padding tests.) Otherwise, this looks like it's coming along; I remain very excited! Thank you for sticking with it. :) -Kees [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565840.html [2] https://gcc.gnu.org/pipermail/gcc-patches/2021-April/567754.html -- Kees Cook