From: Jason Gunthorpe <jgg@nvidia.com>
To: Kees Cook <keescook@chromium.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
Christoph Hellwig <hch@infradead.org>,
Alex Elder <elder@linaro.org>,
corbet@lwn.net, workflows@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Documentation: coding-style: don't encourage WARN*()
Date: Thu, 18 Apr 2024 12:57:27 -0300 [thread overview]
Message-ID: <20240418155727.GA3368771@nvidia.com> (raw)
In-Reply-To: <202404150919.042E6FF@keescook>
On Mon, Apr 15, 2024 at 09:26:40AM -0700, Kees Cook wrote:
> On Mon, Apr 15, 2024 at 10:35:21AM +0200, Greg KH wrote:
> > On Mon, Apr 15, 2024 at 01:07:41AM -0700, Christoph Hellwig wrote:
> > > No, this advice is wronger than wrong. If you set panic_on_warn you
> > > get to keep the pieces.
> > >
> >
> > But don't add new WARN() calls please, just properly clean up and handle
> > the error. And any WARN() that userspace can trigger ends up triggering
> > syzbot reports which also is a major pain, even if you don't have
> > panic_on_warn enabled.
>
> Here's what was more recently written on WARN:
>
> https://docs.kernel.org/process/deprecated.html#bug-and-bug-on
>
> Specifically:
>
> - never use BUG*()
> - WARN*() should only be used for "expected to be unreachable" situations
>
> This, then, maps correctly to panic_on_warn: System owners may have set
> the panic_on_warn sysctl, to make sure their systems do not continue
> running in the face of "unreachable" conditions.
>
> As in, userspace should _never_ be able to reach a WARN(). If it can,
> either the logic leading to it needs to be fixed, or the WARN() needs to
> be changed to a pr_warn().
Exactly! No doubt there are mistakes, but we already document this too
a few lines above where this is touching:
Do not WARN lightly
*******************
WARN*() is intended for unexpected, this-should-never-happen situations.
WARN*() macros are not to be used for anything that is expected to happen
during normal operation. These are not pre- or post-condition asserts, for
example. Again: WARN*() must not be used for a condition that is expected
to trigger easily, for example, by user space actions. pr_warn_once() is a
possible alternative, if you need to notify the user of a problem.
Usages following that advice should be left alone and more should be
added. Invariant checks that indicate the kernel is malfunctioning are
desirable things to have!
Yes, by all means tell people to follow the above rules! But that
isn't a ban on WARN and shouldn't be communicated as "don't add new
WARN() calls please".
Let's all keep in mind that fuzzing reports are incredibly valuable to
make the kernel more secure and robust. We actually want *more*
invariants that indicate bugs for the fuzzers to trip up on!
As above, a correctly used WARN, should indicate a certain bug if it
triggers.
I'd guess about 30-40% of the syzkaller found bugs I've delt with are
from a correct use of WARN_ON not oops/kasn/etc. I wonder what a
datamine on the whole syzkaller database would indicate.
pr_warn/etc don't trigger fuzzer faults, and don't give a debugging
backtrace.
I also find it strange to want panic_on_warn to exist, and people want
to use it, while also saying that the WARN() calls that actually make
it do something and be valuable are forbidden :(
Jason
next prev parent reply other threads:[~2024-04-18 15:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-14 17:08 Alex Elder
2024-04-14 19:48 ` Laurent Pinchart
2024-04-14 20:06 ` Alex Elder
2024-04-15 5:21 ` Greg KH
2024-04-15 8:25 ` Laurent Pinchart
2024-04-15 8:33 ` Greg KH
2024-04-15 8:42 ` Laurent Pinchart
2024-04-15 5:22 ` Greg KH
2024-04-15 8:07 ` Christoph Hellwig
2024-04-15 8:35 ` Greg KH
2024-04-15 8:46 ` Christoph Hellwig
2024-04-15 16:26 ` Kees Cook
2024-04-18 15:57 ` Jason Gunthorpe [this message]
2024-04-18 16:14 ` Eric Biggers
2024-04-18 17:12 ` Kees Cook
2024-04-18 22:33 ` John Hubbard
2024-04-19 7:16 ` David Hildenbrand
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=20240418155727.GA3368771@nvidia.com \
--to=jgg@nvidia.com \
--cc=corbet@lwn.net \
--cc=elder@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=keescook@chromium.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=workflows@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox