lkml.org 
[lkml]   [2019]   [Jul]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] Convert struct pid count to refcount_t
On Mon, Jul 01, 2019 at 07:48:26PM +0200, Jann Horn wrote:
> On Fri, Jun 28, 2019 at 9:35 PM Joel Fernandes (Google)
> <joel@joelfernandes.org> wrote:
> > struct pid's count is an atomic_t field used as a refcount. Use
> > refcount_t for it which is basically atomic_t but does additional
> > checking to prevent use-after-free bugs.
> [...]
> > struct pid
> > {
> > - atomic_t count;
> > + refcount_t count;
> [...]
> > diff --git a/kernel/pid.c b/kernel/pid.c
> > index 20881598bdfa..89c4849fab5d 100644
> > --- a/kernel/pid.c
> > +++ b/kernel/pid.c
> > @@ -37,7 +37,7 @@
> > #include <linux/init_task.h>
> > #include <linux/syscalls.h>
> > #include <linux/proc_ns.h>
> > -#include <linux/proc_fs.h>
> > +#include <linux/refcount.h>
> > #include <linux/sched/task.h>
> > #include <linux/idr.h>
> >
> > @@ -106,8 +106,7 @@ void put_pid(struct pid *pid)
>
> init_struct_pid is defined as follows:
>
> struct pid init_struct_pid = {
> .count = ATOMIC_INIT(1),
> [...]
> };
>
> This should be changed to REFCOUNT_INIT(1).
>
> You should have received a compiler warning about this; I get the
> following when trying to build with your patch applied:

Thanks. Andrew had fixed this in patch v1 but Linus dropped it for other
reasons. Anyway, I should have fixed this in my resubmit.

Sorry, I'll fix and resend!

- Joel


\
 
 \ /
  Last update: 2019-07-01 20:26    [W:1.054 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site