All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Kees Cook <keescook@chromium.org>
Cc: kernel test robot <lkp@intel.com>,
	linux-kernel@vger.kernel.org,  linux-hardening@vger.kernel.org
Subject: Re: [PATCH] ubsan: Silence W=1 warnings in self-test
Date: Fri, 2 Feb 2024 11:43:21 +0100	[thread overview]
Message-ID: <CANpmjNO6W2qDLYuwNRJs2SUCD_wquwPRWG53s65HfKfOiHztdQ@mail.gmail.com> (raw)
In-Reply-To: <202402020239.1EEA467@keescook>

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.

      reply	other threads:[~2024-02-02 10:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANpmjNO6W2qDLYuwNRJs2SUCD_wquwPRWG53s65HfKfOiHztdQ@mail.gmail.com \
    --to=elver@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.