From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Elena Reshetova <elena.reshetova@intel.com>, daniel@iogearbox.net
Cc: ast@fb.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
peterz@infradead.org, keescook@chromium.org,
Hans Liljestrand <ishkamiel@gmail.com>,
David Windsor <dwindsor@gmail.com>
Subject: Re: [PATCH] net: convert sk_filter.refcnt from atomic_t to refcount_t
Date: Sat, 18 Mar 2017 17:33:22 +0300 [thread overview]
Message-ID: <a19263a2-141b-22ad-4300-0ffe54cae8d6@cogentembedded.com> (raw)
In-Reply-To: <1489841889-27601-1-git-send-email-elena.reshetova@intel.com>
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
next prev parent reply other threads:[~2017-03-18 17:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-18 12:58 Elena Reshetova
2017-03-18 14:33 ` Sergei Shtylyov [this message]
2017-03-20 9:31 ` Reshetova, Elena
2017-03-20 9:37 Elena Reshetova
2017-03-20 17:13 ` Daniel Borkmann
2017-03-21 10:43 ` Reshetova, Elena
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a19263a2-141b-22ad-4300-0ffe54cae8d6@cogentembedded.com \
--to=sergei.shtylyov@cogentembedded.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=dwindsor@gmail.com \
--cc=elena.reshetova@intel.com \
--cc=ishkamiel@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®