mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Eric Van Hensbergen" <ericvh@gmail.com>
To: "Andrew Morton" <akpm@linux-foundation.org>
Cc: "Latchesar Ionkov" <lucho@ionkov.net>,
	"V9FS Developers" <v9fs-developer@lists.sourceforge.net>,
	"kernel list" <linux-kernel@vger.kernel.org>
Subject: Re: net/9p/mux.c: use-after-free
Date: Thu, 26 Jul 2007 09:29:50 -0500	[thread overview]
Message-ID: <a4e6962a0707260729g4a451d13iaed2097428c7118a@mail.gmail.com> (raw)
In-Reply-To: <20070725202030.7ecf339c.akpm@linux-foundation.org>

On 7/25/07, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Wed, 25 Jul 2007 13:43:16 -0500 "Eric Van Hensbergen" <ericvh@gmail.com> wrote:
>
> >                 mtmp = ERR_PTR(PTR_ERR(m->tagpool));
>
> odd.  What does ERR_PTR(PTR_ERR(...)) do?
>

I kind of assumed it was a necessry evil to get the casting right.  A
quick grep shows it in 42 other places within the kernel.  Unpacking
the macros it looks like:

   (void *)(long)(struct p9_idpool *)

So all that you would really need is (void *) or ERR_PTR -- but that
might look confusing in the code.  Of course, broadening the context a
bit:

        m->tagpool = p9_idpool_create();
        if (!m->tagpool) {
                mtmp = ERR_PTR(PTR_ERR(m->tagpool));
                kfree(m);
                return mtmp;
        }

m->tagpool must be zero to enter the code at all, so we are returning
a NULL pointer, not really an error -- which is probably wrong (I
don't think it will properly trigger IS_ERR_VALUE) -- so we should
probably be returning -ENOMEM.

Of course, we really should be seeing an ERR_PTR returned from
p9_idpool_create, not 0 -- checking that code, it either returns
-ENOMEM or the correct value, never 0, so the check is wrong as well.
It should be:

        m->tagpool = p9_idpool_create();
        if (IS_ERR(m->tagpool)) {
                mtmp = ERR_PTR(-ENOMEM);
                kfree(m);
                return mtmp;
        }

We could have done:
   ERR_PTR(m->tagpool);
or kept the long:
   ERR_PTR(PTR_ERR(m->tagpool));
but I think returning an explicit error code keeps the code more clear.

So, which is the correct approach?

                   -eric

      parent reply	other threads:[~2007-07-26 14:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-23  1:20 Adrian Bunk
2007-07-25 18:43 ` Eric Van Hensbergen
2007-07-25 19:13   ` Latchesar Ionkov
2007-07-25 19:45     ` Eric Van Hensbergen
     [not found]   ` <20070725202030.7ecf339c.akpm@linux-foundation.org>
2007-07-26 14:29     ` Eric Van Hensbergen [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=a4e6962a0707260729g4a451d13iaed2097428c7118a@mail.gmail.com \
    --to=ericvh@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucho@ionkov.net \
    --cc=v9fs-developer@lists.sourceforge.net \
    /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®