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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 23 Nov 2009 15:03:23 +0100
From:	Oleg Nesterov <oleg@...hat.com>
To:	Pekka Enberg <penberg@...helsinki.fi>
Cc:	André Goddard Rosa <andre.goddard@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org, Jiri Kosina <jkosina@...e.cz>
Subject: Re: [PATCH 1/2] pid: tighten pidmap spinlock critical section by
	removing kfree()

On 11/23, Pekka Enberg wrote:
> (Adding some CC's.)
>
> On Sat, Nov 21, 2009 at 2:16 PM, André Goddard Rosa
> <andre.goddard@...il.com> wrote:
> > Avoid calling kfree() under pidmap spinlock, calling it afterwards.
> >
> > Normally kfree() is very fast, but sometimes it can be slow, so avoid
> > calling it under the spinlock if we can.

kfree() is called when we race with another process which also
finds map->page == NULL, allocs the new page and takes pidmap_lock
before us. This is extremely unlikely case, right?

> > @@ -141,11 +141,12 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
> >                         * installing it:
> >                         */
> >                        spin_lock_irq(&pidmap_lock);
> > -                       if (map->page)
> > -                               kfree(page);
> > -                       else
> > +                       if (!map->page) {
> >                                map->page = page;
> > +                               page = NULL;
> > +                       }
> >                        spin_unlock_irq(&pidmap_lock);
> > +                       kfree(page);

And this change pessimizes (a little bit) the likely case, when
the race doesn't happen. And imho this change doesn't make the
code more readable.

But this is subjective, and technically the patch is correct
afaics.

> >                        if (unlikely(!map->page))
> >                         �

Hmm. Off-topic, but why alloc_pidmap() does not do this right
after kzalloc() ?

Oleg.

--
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