lkml.org 
[lkml]   [2007]   [Jul]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: net/9p/mux.c: use-after-free
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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-07-26 16:33    [W:0.052 / U:0.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site