From: David Laight <David.Laight@ACULAB.COM>
To: "'Rafael J. Wysocki'" <rafael@kernel.org>,
Kees Cook <keescook@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 1/1] linux/container_of.h: Warn about loss of constness
Date: Mon, 24 Oct 2022 21:24:18 +0000 [thread overview]
Message-ID: <4218173bd72b4f1899d4c41a8e251f0d@AcuMS.aculab.com> (raw)
In-Reply-To: <CAJZ5v0jczp8J89EdywFDbzPmmeKmoQ3wNFUmKxH_1xS7LPNzkA@mail.gmail.com>
From: Rafael J. Wysocki
> Sent: 24 October 2022 18:51
...
> > It looks like it was designed to handle the cases where the pointer was
> > ERR_OR_NULL:
> >
> > IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \
> > ((type *)(__mptr - offsetof(type, member))); })
> >
> > i.e. just pass through the NULL/ERR instead of attempting the cast,
> > which would fail spectacularly. :)
> >
> > It seems like this version should actually be used everywhere instead of
> > nowhere... (i.e. just drop container_of() and rename container_of_safe()
> > to container_of())
>
> As a rule, though, users of container_of() don't check the pointer
> returned by it against NULL, so I'm not sure how much of an
> improvement that would be.
>
> If NULL is passed to container_of(), there will be a spectacular
> failure, sooner or later ...
Certainly there isn't much difference between dereferencing
a -Exxxx value and -Exxxx - offsetof().
Both are in the same page - hopefully not mapped?
Missing ERR/NULL checks are a problem but adding one inside
container_of() doesn't really help.
You might as well add an explicit test before using container_of()
rather than adding one inside it AND requiring a test afterwards.
I don't think the compiler can assume the subtraction doesn't
generate NULL - so must check twice.
I've not even sure how many of the functions that can check can
ever actually be passed an invalid pointer.
Normally the caller bails out and returns the error before
passing it on.
The kernel really doesn't check every function parameter for
validity - it has to assume the caller is doing something sensible.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-10-24 23:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 8:26 Sakari Ailus
2022-10-24 8:43 ` Greg Kroah-Hartman
2022-10-24 8:45 ` Greg Kroah-Hartman
2022-10-24 9:00 ` Andy Shevchenko
2022-10-24 17:39 ` Kees Cook
2022-10-24 17:51 ` Rafael J. Wysocki
2022-10-24 21:24 ` David Laight [this message]
2022-10-25 7:47 ` Greg Kroah-Hartman
2022-10-24 9:11 ` Sakari Ailus
2022-10-24 9:22 ` Andy Shevchenko
2022-10-24 9:34 ` David Laight
2022-10-24 9:37 ` 'Andy Shevchenko'
2022-10-24 9:46 ` David Laight
2022-10-24 10:01 ` Greg Kroah-Hartman
2022-10-24 10:05 ` David Laight
2022-10-24 9:48 ` Greg Kroah-Hartman
2022-10-24 10:07 ` Sakari Ailus
2022-10-24 8:59 ` David Laight
2022-10-24 10:11 ` Sakari Ailus
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=4218173bd72b4f1899d4c41a8e251f0d@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sakari.ailus@linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome