From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751705AbdCRR2A (ORCPT ); Sat, 18 Mar 2017 13:28:00 -0400 Received: from mail-lf0-f48.google.com ([209.85.215.48]:34958 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751127AbdCRR16 (ORCPT ); Sat, 18 Mar 2017 13:27:58 -0400 Subject: Re: [PATCH] net: convert sk_filter.refcnt from atomic_t to refcount_t To: Elena Reshetova , daniel@iogearbox.net References: <1489841889-27601-1-git-send-email-elena.reshetova@intel.com> Cc: ast@fb.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, keescook@chromium.org, Hans Liljestrand , David Windsor From: Sergei Shtylyov Message-ID: Date: Sat, 18 Mar 2017 17:33:22 +0300 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1489841889-27601-1-git-send-email-elena.reshetova@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Hans Liljestrand > Signed-off-by: Kees Cook > Signed-off-by: David Windsor [...] > 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