lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 26 Jul 2007 09:29:50 -0500
From:	"Eric Van Hensbergen" <ericvh@...il.com>
To:	"Andrew Morton" <akpm@...ux-foundation.org>
Cc:	"Latchesar Ionkov" <lucho@...kov.net>,
	"V9FS Developers" <v9fs-developer@...ts.sourceforge.net>,
	"kernel list" <linux-kernel@...r.kernel.org>
Subject: Re: net/9p/mux.c: use-after-free

On 7/25/07, Andrew Morton <akpm@...ux-foundation.org> wrote:
> On Wed, 25 Jul 2007 13:43:16 -0500 "Eric Van Hensbergen" <ericvh@...il.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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ