mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Kevin O'Connor" <kevin@koconnor.net>
To: Andries Brouwer <aebr@win.tue.nl>
Cc: Ed Tomlinson <tomlins@cam.org>,
	linux-kernel@vger.kernel.org,
	linux-usb-devel@lists.sourceforge.net
Subject: Re: Container_of considered harmful - was Re: usb storage sddr09
Date: Tue, 22 Oct 2002 21:43:45 -0400	[thread overview]
Message-ID: <20021022214345.A5642@arizona.localdomain> (raw)
In-Reply-To: <20021020182436.GA25975@win.tue.nl>; from aebr@win.tue.nl on Sun, Oct 20, 2002 at 08:24:36PM +0200

On Sun, Oct 20, 2002 at 08:24:36PM +0200, Andries Brouwer wrote:
> The oops is a dereference of fffffff0 in base/bus.c:driver_attach().
> I have seen several such oopses lately, various places in the kernel.
> The cause here is a NULL pointer that is turned into fffffff0 by
> container_of() and then fed to get_device(). And get_device() tests
> that it gets a non-NULL pointer, but that does not protect against
> fffffff0.

Just as an anecdote - I built a variant of container_of to protect against
cases where NULL can creep in:

#define test_container_of(ptr, type, member) ({               \
        const typeof( ((type *)0)->member ) *__p = (ptr);     \
        __p ? container_of(__p, type, member) : NULL;})

It calls the real container_of only if 'ptr' is not NULL.

-Kevin

-- 
 ------------------------------------------------------------------------
 | Kevin O'Connor                     "BTW, IMHO we need a FAQ for      |
 | kevin@koconnor.net                  'IMHO', 'FAQ', 'BTW', etc. !"    |
 ------------------------------------------------------------------------

      parent reply	other threads:[~2002-10-23  1:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-18  1:55 Ed Tomlinson
2002-10-18 19:35 ` Andries Brouwer
2002-10-20 13:52   ` Ed Tomlinson
2002-10-20 18:24     ` Container_of considered harmful - was " Andries Brouwer
2002-10-21  4:12       ` [linux-usb-devel] " Matthew Dharm
2002-10-23  1:43       ` Kevin O'Connor [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=20021022214345.A5642@arizona.localdomain \
    --to=kevin@koconnor.net \
    --cc=aebr@win.tue.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=tomlins@cam.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

all inboxes | Powered by JetHome®