Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1604508

RE: [PATCH] net: convert sk_filter.refcnt from atomic_t to refcount_t

From "Reshetova, Elena" <elena.reshetova@intel.com>
Newsgroups linux.kernel
Subject RE: [PATCH] net: convert sk_filter.refcnt from atomic_t to refcount_t
Date 2017-03-20 13:50 +0100
Message-ID <tn4V4-4Nu-33@gated-at.bofh.it> (permalink)
References <tmm7E-6sP-7@gated-at.bofh.it> <tmqkV-1az-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


> Hello!
> 
> On 3/18/2017 3:58 PM, Elena Reshetova wrote:
> 
> > refcount_t type and corresponding API should be
> > used instead of atomic_t when the variable is used as
> > a reference counter. This allows to avoid accidental
> > refcounter overflows that might lead to use-after-free
> > situations.
> >
> > Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> > Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > Signed-off-by: David Windsor <dwindsor@gmail.com>
> [...]
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index ebaeaf2..62267e2 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> [...]
> > @@ -1179,12 +1179,13 @@ static int __sk_attach_prog(struct bpf_prog *prog,
> struct sock *sk)
> >  		return -ENOMEM;
> >
> >  	fp->prog = prog;
> > -	atomic_set(&fp->refcnt, 0);
> > +	refcount_set(&fp->refcnt, 1);
> >
> >  	if (!sk_filter_charge(sk, fp)) {
> >  		kfree(fp);
> >  		return -ENOMEM;
> >  	}
> > +	refcount_set(&fp->refcnt, 1);
> 
>     Why do it twice?
> 
> [...]
> 
> MBR, Sergei

Sorry I just realized that I had unsquashed changes when I sent this patch, so this is still the old version. 
Will send a new one now. 

Best Regards,
Elena.

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH] net: convert sk_filter.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-18 14:00 +0100
  Re: [PATCH] net: convert sk_filter.refcnt from atomic_t to refcount_t Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2017-03-18 18:30 +0100
    RE: [PATCH] net: convert sk_filter.refcnt from atomic_t to  refcount_t "Reshetova, Elena" <elena.reshetova@intel.com> - 2017-03-20 13:50 +0100

csiph-web