Re: net/9p/mux.c: use-after-free

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/25/07, Andrew Morton <[email protected]> wrote:
On Wed, 25 Jul 2007 13:43:16 -0500 "Eric Van Hensbergen" <[email protected]> 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux