Re: Question on -fwrapv and -fwrapv-pointer

2023-09-23 Thread Kees Cook via Gcc
27;s mostly arbitrary. :( > (and thank you for your explanations) Sure thing! Thanks for your (and everyone's) help clarifying this whole area. :) -Kees -- Kees Cook

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-20 Thread Kees Cook via Gcc
the following question: In theĀ  > bug you refer to above, an unsigned variable was used > for something that is not meant for modulo arithmetic. > Is this done in the kernel to save space? I.e. because > 127 would not be enough as maximum but going to i16 takes > to much space? or is this for compatibility with some > on-the-wire protocol? I don't know the original rationale -- I expect the author wanted an unsigned variable but didn't expect to ever encounter > 255 entries. These kinds of expectations aren't uncommon in the kernel, and sometimes past expectations get violated when refactoring, etc. Basically I can't trust the sanity of the codebase, so I have to depend on the compiler to provide the runtime coverage to avoid these kinds of security flaws. > Would an attribute for variables help that tells the > compiler that if stores to the variable wrap around > then this is not intended and this is an error? > > u8 x [[nowrap]]; > > x = 256; // can be diagnosed ? I would need the reverse: I want to assume all math to not wrap, excepting a handful that are designed to. -fsanitize=nowrap u8 modulo [[wrapping]]; u8 counter; modulo = 256; // no diagnose counter = 256; // diagnose -- Kees Cook

Re: [wish] Flexible array members in unions

2023-05-11 Thread Kees Cook via Gcc
On Thu, May 11, 2023 at 09:43:49PM +, Joseph Myers wrote: > On Thu, 11 May 2023, Kees Cook via Gcc wrote: > > > Why are zero-sized objects missing in Standard C? Or, perhaps, the better > > question is: what's needed to support the idea of a zero-sized object? >

Re: [wish] Flexible array members in unions

2023-05-11 Thread Kees Cook via Gcc
On Thu, May 11, 2023 at 08:53:52PM +, Joseph Myers wrote: > On Thu, 11 May 2023, Kees Cook via Gcc wrote: > > > On Thu, May 11, 2023 at 06:29:10PM +0200, Alejandro Colomar wrote: > > > On 5/11/23 18:07, Alejandro Colomar wrote: > > > [...] > > > >

Re: [wish] Flexible array members in unions

2023-05-11 Thread Kees Cook via Gcc
overage over trailing arrays. All of this means that we're converting a lot of code that is happily using dynamically sized arrays in unions, etc. [1] https://people.kernel.org/kees/bounded-flexible-arrays-in-c -- Kees Cook

Re: [PATCH v2 5/5] gcc-plugins/stackleak: Add 'verbose' plugin parameter

2020-06-24 Thread Kees Cook via Gcc
c-plugins: > gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ > += -fplugin-arg-stackleak_plugin-verbose > > Signed-off-by: Alexander Popov Applied to for-next/gcc-plugins. -- Kees Cook

Re: [PATCH v2 2/5] ARM: vdso: Don't use gcc plugins for building vgettimeofday.c

2020-06-24 Thread Kees Cook via Gcc
On Wed, Jun 24, 2020 at 03:33:27PM +0300, Alexander Popov wrote: > Don't use gcc plugins for building arch/arm/vdso/vgettimeofday.c to > avoid unneeded instrumentation. > > Signed-off-by: Alexander Popov Applied to for-next/gcc-plugins. -- Kees Cook

Re: [PATCH v2 1/5] gcc-plugins/stackleak: Don't instrument itself

2020-06-24 Thread Kees Cook via Gcc
On Wed, Jun 24, 2020 at 03:33:26PM +0300, Alexander Popov wrote: > There is no need to try instrumenting functions in kernel/stackleak.c. > Otherwise that can cause issues if the cleanup pass of stackleak gcc plugin > is disabled. > > Signed-off-by: Alexander Popov > Acked-by:

Re: [PATCH v2 3/5] arm64: vdso: Don't use gcc plugins for building vgettimeofday.c

2020-06-24 Thread Kees Cook via Gcc
On Wed, Jun 24, 2020 at 03:33:28PM +0300, Alexander Popov wrote: > Don't use gcc plugins for building arch/arm64/kernel/vdso/vgettimeofday.c > to avoid unneeded instrumentation. > > Signed-off-by: Alexander Popov It looks like Will has taken this already, but: Acked-by: Kee

Re: [PATCH v2 5/5] gcc-plugins/stackleak: Add 'verbose' plugin parameter

2020-06-24 Thread Kees Cook via Gcc
ich is used for debugging the structleak plugin. > > This debugging feature clutters the kernel build output, I don't think that > many > people will use it. So IMO creating a separate argument for make is not really > needed. Yup, agreed. The precedent for plugin verbosity is via CONFIGs. They're not really general purpose enough to justify a "make" argument. -- Kees Cook

Re: [PATCH 3/5] gcc-plugins/stackleak: Add 'verbose' plugin parameter

2020-06-10 Thread Kees Cook via Gcc
On Wed, Jun 10, 2020 at 06:52:10PM +0300, Alexander Popov wrote: > On 09.06.2020 21:47, Kees Cook wrote: > > On Thu, Jun 04, 2020 at 04:49:55PM +0300, Alexander Popov wrote: > >> Add 'verbose' plugin parameter for stackleak gcc plugin. > >> It can be used f

Re: [PATCH 2/5] gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving

2020-06-10 Thread Kees Cook via Gcc
On Wed, Jun 10, 2020 at 06:47:14PM +0300, Alexander Popov wrote: > On 09.06.2020 21:46, Kees Cook wrote: > The inline asm statement that is used for instrumentation is arch-specific. > Trying to add > asm volatile("call stackleak_track_stack") > in gcc plugin o

Re: [PATCH 0/5] Improvements of the stackleak gcc plugin

2020-06-09 Thread Kees Cook via Gcc
GCC_PLUGINS architectures with vDSOs (which appears to be all of them except um). -- Kees Cook

Re: [PATCH 5/5] gcc-plugins/stackleak: Don't instrument vgettimeofday.c in arm64 VDSO

2020-06-09 Thread Kees Cook via Gcc
should likely be disabled too. sancov_plugin.c This should be tracking the KCOV directly (see scripts/Makefile.kcov), which is already disabled here. structleak_plugin.c This should be fine in the vDSO, but there's not security boundary here, so it wouldn't be important to KEEP it enabled. -- Kees Cook

Re: [PATCH 4/5] gcc-plugins/stackleak: Don't instrument itself

2020-06-09 Thread Kees Cook via Gcc
On Thu, Jun 04, 2020 at 04:49:56PM +0300, Alexander Popov wrote: > There is no need to try instrumenting functions in kernel/stackleak.c. > Otherwise that can cause issues if the cleanup pass of stackleak gcc plugin > is disabled. > > Signed-off-by: Alexander Popov Acke

Re: [PATCH 2/5] gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving

2020-06-09 Thread Kees Cook via Gcc
ately. Why does the architecture need to be tested? (i.e. when this flag becomes supported o other architectures, why must it still be x86-only?) -- Kees Cook

Re: [PATCH 3/5] gcc-plugins/stackleak: Add 'verbose' plugin parameter

2020-06-09 Thread Kees Cook via Gcc
c-plugins: > gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ > += -fplugin-arg-stackleak_plugin-verbose > > Signed-off-by: Alexander Popov Acked-by: Kees Cook -- Kees Cook

Re: [PATCH 1/5] gcc-plugins/stackleak: Exclude alloca() from the instrumentation logic

2020-06-09 Thread Kees Cook via Gcc
to be strictly tied together. > Another aspect: CONFIG_STACKLEAK_METRICS can be used for guessing kernel stack > offset, which is bad. It should be disabled if random_kstack_offset is on. Agreed. -- Kees Cook

Re: [PATCH 0/5] Improvements of the stackleak gcc plugin

2020-06-04 Thread Kees Cook via Gcc
On Thu, Jun 04, 2020 at 04:49:52PM +0300, Alexander Popov wrote: > In this patch series I collected various improvements of the stackleak > gcc plugin. Great; thank you! I'll take a closer look at this shortly! -- Kees Cook

Re: [PATCH v2 1/1] stackleak: Register the 'stackleak_cleanup' pass before the '*free_cfg' pass

2018-12-06 Thread Kees Cook
function prologues and epilogues are generated, and the > +* machine-dependent code transformations are not done. > */ > - PASS_INFO(stackleak_cleanup, "reload", 1, PASS_POS_INSERT_AFTER); > + PASS_INFO(stackleak_cleanup, "*free_cfg", 1, PASS_POS_INSERT_BEFORE); > > if (!plugin_default_version_check(version, &gcc_version)) { > error(G_("incompatible gcc/plugin versions")); > -- > 2.7.4 > -- Kees Cook