All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ubsan: Silence W=1 warnings in self-test
@ 2024-02-02  9:45 Kees Cook
  2024-02-02  9:57 ` Marco Elver
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2024-02-02  9:45 UTC (permalink / raw)
  To: Marco Elver; +Cc: Kees Cook, kernel test robot, linux-kernel, linux-hardening

Silence a handful of W=1 warnings in the UBSan selftest, which set
variables without using them. For example:

   lib/test_ubsan.c:101:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable]
     101 |         int val1 = 10;
         |             ^

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202401310423.XpCIk6KO-lkp@intel.com/
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 lib/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/Makefile b/lib/Makefile
index 6b09731d8e61..bc36a5c167db 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
 obj-$(CONFIG_TEST_IDA) += test_ida.o
 obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
 CFLAGS_test_ubsan.o += $(call cc-disable-warning, vla)
+CFLAGS_test_ubsan.o += $(call cc-disable-warning, unused-but-set-variable)
 UBSAN_SANITIZE_test_ubsan.o := y
 obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
 obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubsan: Silence W=1 warnings in self-test
  2024-02-02  9:45 [PATCH] ubsan: Silence W=1 warnings in self-test Kees Cook
@ 2024-02-02  9:57 ` Marco Elver
  2024-02-02 10:41   ` Kees Cook
  0 siblings, 1 reply; 4+ messages in thread
From: Marco Elver @ 2024-02-02  9:57 UTC (permalink / raw)
  To: Kees Cook; +Cc: kernel test robot, linux-kernel, linux-hardening

On Fri, 2 Feb 2024 at 10:46, Kees Cook <keescook@chromium.org> wrote:
>
> Silence a handful of W=1 warnings in the UBSan selftest, which set
> variables without using them. For example:
>
>    lib/test_ubsan.c:101:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable]
>      101 |         int val1 = 10;
>          |             ^

This is the shift_out_of_bounds test? It looks like the neg and wrap
variables are volatile but the written-to variables aren't.
Technically the compiler just has to emit the reads to neg and wrap,
and can entirely omit the writes to val1 and val2.

Does making it volatile fix the warning?

>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202401310423.XpCIk6KO-lkp@intel.com/
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  lib/Makefile | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/lib/Makefile b/lib/Makefile
> index 6b09731d8e61..bc36a5c167db 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -69,6 +69,7 @@ obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
>  obj-$(CONFIG_TEST_IDA) += test_ida.o
>  obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
>  CFLAGS_test_ubsan.o += $(call cc-disable-warning, vla)
> +CFLAGS_test_ubsan.o += $(call cc-disable-warning, unused-but-set-variable)
>  UBSAN_SANITIZE_test_ubsan.o := y
>  obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
>  obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubsan: Silence W=1 warnings in self-test
  2024-02-02  9:57 ` Marco Elver
@ 2024-02-02 10:41   ` Kees Cook
  2024-02-02 10:43     ` Marco Elver
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2024-02-02 10:41 UTC (permalink / raw)
  To: Marco Elver; +Cc: kernel test robot, linux-kernel, linux-hardening

On Fri, Feb 02, 2024 at 10:57:11AM +0100, Marco Elver wrote:
> On Fri, 2 Feb 2024 at 10:46, Kees Cook <keescook@chromium.org> wrote:
> >
> > Silence a handful of W=1 warnings in the UBSan selftest, which set
> > variables without using them. For example:
> >
> >    lib/test_ubsan.c:101:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable]
> >      101 |         int val1 = 10;
> >          |             ^
> 
> This is the shift_out_of_bounds test? It looks like the neg and wrap
> variables are volatile but the written-to variables aren't.
> Technically the compiler just has to emit the reads to neg and wrap,
> and can entirely omit the writes to val1 and val2.
> 
> Does making it volatile fix the warning?

It does for some, but not all:

../lib/test_ubsan.c: In function 'test_ubsan_out_of_bounds':
../lib/test_ubsan.c:115:22: warning: variable 'arr' set but not used [-Wunused-but-set-variable]
  115 |         volatile int arr[4];
      |                      ^~~
../lib/test_ubsan.c:114:23: warning: variable 'above' set but not used [-Wunused-but-set-variable]
  114 |         volatile char above[4] = { }; /* Protect surrounding memory. */
      |                       ^~~~~
../lib/test_ubsan.c: In function 'test_ubsan_load_invalid_value':
../lib/test_ubsan.c:137:44: warning: variable 'eptr' set but not used [-Wunused-but-set-variable]
  137 |         enum ubsan_test_enum eval, eval2, *eptr;
      |                                            ^~~~
../lib/test_ubsan.c:136:26: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
  136 |         bool val, val2, *ptr;
      |                          ^~~


-- 
Kees Cook

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubsan: Silence W=1 warnings in self-test
  2024-02-02 10:41   ` Kees Cook
@ 2024-02-02 10:43     ` Marco Elver
  0 siblings, 0 replies; 4+ messages in thread
From: Marco Elver @ 2024-02-02 10:43 UTC (permalink / raw)
  To: Kees Cook; +Cc: kernel test robot, linux-kernel, linux-hardening

On Fri, 2 Feb 2024 at 11:41, Kees Cook <keescook@chromium.org> wrote:
>
> On Fri, Feb 02, 2024 at 10:57:11AM +0100, Marco Elver wrote:
> > On Fri, 2 Feb 2024 at 10:46, Kees Cook <keescook@chromium.org> wrote:
> > >
> > > Silence a handful of W=1 warnings in the UBSan selftest, which set
> > > variables without using them. For example:
> > >
> > >    lib/test_ubsan.c:101:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable]
> > >      101 |         int val1 = 10;
> > >          |             ^
> >
> > This is the shift_out_of_bounds test? It looks like the neg and wrap
> > variables are volatile but the written-to variables aren't.
> > Technically the compiler just has to emit the reads to neg and wrap,
> > and can entirely omit the writes to val1 and val2.
> >
> > Does making it volatile fix the warning?
>
> It does for some, but not all:
>
> ../lib/test_ubsan.c: In function 'test_ubsan_out_of_bounds':
> ../lib/test_ubsan.c:115:22: warning: variable 'arr' set but not used [-Wunused-but-set-variable]
>   115 |         volatile int arr[4];
>       |                      ^~~
> ../lib/test_ubsan.c:114:23: warning: variable 'above' set but not used [-Wunused-but-set-variable]
>   114 |         volatile char above[4] = { }; /* Protect surrounding memory. */
>       |                       ^~~~~
> ../lib/test_ubsan.c: In function 'test_ubsan_load_invalid_value':
> ../lib/test_ubsan.c:137:44: warning: variable 'eptr' set but not used [-Wunused-but-set-variable]
>   137 |         enum ubsan_test_enum eval, eval2, *eptr;
>       |                                            ^~~~
> ../lib/test_ubsan.c:136:26: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
>   136 |         bool val, val2, *ptr;
>       |                          ^~~

Then I'd just combine the compiler flag with switching most of these
variables to volatile so the tests keep working if the compiler
decides to optimize too much.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-02 10:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02  9:45 [PATCH] ubsan: Silence W=1 warnings in self-test Kees Cook
2024-02-02  9:57 ` Marco Elver
2024-02-02 10:41   ` Kees Cook
2024-02-02 10:43     ` Marco Elver

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.