Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp360026imm; Thu, 14 Jun 2018 22:11:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKMYvJmrrGmE7r38YlY/GtEInWwrZd/SIxKt6z/ss7QuaKHpOQCasT7bUynADo3X0p/tetE X-Received: by 2002:aa7:80cf:: with SMTP id a15-v6mr209201pfn.19.1529039483604; Thu, 14 Jun 2018 22:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529039483; cv=none; d=google.com; s=arc-20160816; b=wrNadtRD3fUqiKLQOFveoh6uCho6nqJokoZMpBdhmgyL3hPtP+4Sa9zc+0jIEy0TYo d+4QhmvRedflRzIC3oZh8Olz7sdsMsf0o2D8qKJPwL9GeVFrcxzQNLqbgaDKj4IgtDLg nUTwWL4/cuzkvw/tQ2S2yqOQ8HK3OpkQe6gqoPnBbbCjK2zosIaaRtlRdTHu+PBou9ED vDxa3y9lultYEsBiM4UQUYorydJc98y+nqqODNlVUWT2b5fzV+mrwbq4eoj3iEAcudHG fFftdB7/bpjXeKyU+Tq3xk1/bp6WIXP/S/KFjRTSxIU2qJOBOwsm+GJwBV+n0CTiCoFP QqWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=T4HQDjAJyK5MXHIWj1ka3mxI+QwyVrXTPTwQOhHHsnY=; b=0S8rHcNAJl4+g9LQN9gXFIWFYmp+xQ5LZ5hoQv002XWcUw4nXObbv0RIOBFZGMU9+1 TSGbzEMnWMSi7HI0KVvJc24gAHC2NAzZaw28D9KQQR8x2yaLlKnmnaKY5S2IYyz7m6i5 PRtfzvOUEb8blfeAg+ATa7lt8mtb13pOt8vrc/5vkcilIsVZ7mx/6GcuLW3lMRFDZlRj YxGSRr1iyK2mSdhrINHMh0p9oKj/TKPhEod7Y9aav1VZem1nHfDAa4J0iHb2bp92VEZh KayH4p91W/6Gfnv3g8v/KHBaIboYkbGKMU9PWBgCJJO3md9L/GDMMHYSjC+MxWVYcoNk 7Qhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f89-v6si7241008pff.208.2018.06.14.22.10.39; Thu, 14 Jun 2018 22:11:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755654AbeFOFHJ (ORCPT + 99 others); Fri, 15 Jun 2018 01:07:09 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:48910 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755641AbeFOFGX (ORCPT ); Fri, 15 Jun 2018 01:06:23 -0400 X-IronPort-AV: E=Sophos;i="5.51,225,1526335200"; d="scan'208";a="268855213" Received: from abo-154-110-68.mrs.modulonet.fr (HELO [192.168.0.15]) ([85.68.110.154]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jun 2018 07:06:20 +0200 Date: Fri, 15 Jun 2018 07:06:20 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Kees Cook cc: Elena Reshetova , Masahiro Yamada , Julia Lawall , LKML , cocci@systeme.lip6.fr, Gilles Muller , Nicolas Palix , Michal Marek , Hans Liljestrand Subject: Re: [PATCH] Coccinelle: add atomic_as_refcounter script In-Reply-To: Message-ID: References: <1504258820-2122-1-git-send-email-elena.reshetova@intel.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 14 Jun 2018, Kees Cook wrote: > On Fri, Sep 1, 2017 at 2:40 AM, Elena Reshetova > wrote: > > atomic_as_refcounter.cocci script allows detecting > > cases when refcount_t type and API should be used > > instead of atomic_t. > > > > Signed-off-by: Elena Reshetova > > Acked-by: Julia Lawall > > Reviewed-by: Kees Cook > > Oops, I think this got lost. Who can take this patch? I thought Julia > ran the scripts/coccinelle/ tree, but looking at git log, it looks > more like it's Masahiro? Either way, let's get this in the tree. Who > can take it? Masahiro takes patches. julia > > Thanks! > > -Kees > > > --- > > scripts/coccinelle/api/atomic_as_refcounter.cocci | 131 ++++++++++++++++++++++ > > 1 file changed, 131 insertions(+) > > create mode 100644 scripts/coccinelle/api/atomic_as_refcounter.cocci > > > > diff --git a/scripts/coccinelle/api/atomic_as_refcounter.cocci b/scripts/coccinelle/api/atomic_as_refcounter.cocci > > new file mode 100644 > > index 0000000..bfa880d > > --- /dev/null > > +++ b/scripts/coccinelle/api/atomic_as_refcounter.cocci > > @@ -0,0 +1,131 @@ > > +// Check if refcount_t type and API should be used > > +// instead of atomic_t type when dealing with refcounters > > +// > > +// Copyright (c) 2016-2017, Elena Reshetova, Intel Corporation > > +// > > +// Confidence: Moderate > > +// URL: http://coccinelle.lip6.fr/ > > +// Options: --include-headers --very-quiet > > + > > +virtual report > > + > > +@r1 exists@ > > +identifier a, x; > > +position p1, p2; > > +identifier fname =~ ".*free.*"; > > +identifier fname2 =~ ".*destroy.*"; > > +identifier fname3 =~ ".*del.*"; > > +identifier fname4 =~ ".*queue_work.*"; > > +identifier fname5 =~ ".*schedule_work.*"; > > +identifier fname6 =~ ".*call_rcu.*"; > > + > > +@@ > > + > > +( > > + atomic_dec_and_test@p1(&(a)->x) > > +| > > + atomic_dec_and_lock@p1(&(a)->x, ...) > > +| > > + atomic_long_dec_and_lock@p1(&(a)->x, ...) > > +| > > + atomic_long_dec_and_test@p1(&(a)->x) > > +| > > + atomic64_dec_and_test@p1(&(a)->x) > > +| > > + local_dec_and_test@p1(&(a)->x) > > +) > > +... > > +( > > + fname@p2(a, ...); > > +| > > + fname2@p2(...); > > +| > > + fname3@p2(...); > > +| > > + fname4@p2(...); > > +| > > + fname5@p2(...); > > +| > > + fname6@p2(...); > > +) > > + > > + > > +@script:python depends on report@ > > +p1 << r1.p1; > > +p2 << r1.p2; > > +@@ > > +msg = "atomic_dec_and_test variation before object free at line %s." > > +coccilib.report.print_report(p1[0], msg % (p2[0].line)) > > + > > +@r4 exists@ > > +identifier a, x, y; > > +position p1, p2; > > +identifier fname =~ ".*free.*"; > > + > > +@@ > > + > > +( > > + atomic_dec_and_test@p1(&(a)->x) > > +| > > + atomic_dec_and_lock@p1(&(a)->x, ...) > > +| > > + atomic_long_dec_and_lock@p1(&(a)->x, ...) > > +| > > + atomic_long_dec_and_test@p1(&(a)->x) > > +| > > + atomic64_dec_and_test@p1(&(a)->x) > > +| > > + local_dec_and_test@p1(&(a)->x) > > +) > > +... > > +y=a > > +... > > +fname@p2(y, ...); > > + > > + > > +@script:python depends on report@ > > +p1 << r4.p1; > > +p2 << r4.p2; > > +@@ > > +msg = "atomic_dec_and_test variation before object free at line %s." > > +coccilib.report.print_report(p1[0], msg % (p2[0].line)) > > + > > +@r2 exists@ > > +identifier a, x; > > +position p1; > > +@@ > > + > > +( > > +atomic_add_unless(&(a)->x,-1,1)@p1 > > +| > > +atomic_long_add_unless(&(a)->x,-1,1)@p1 > > +| > > +atomic64_add_unless(&(a)->x,-1,1)@p1 > > +) > > + > > +@script:python depends on report@ > > +p1 << r2.p1; > > +@@ > > +msg = "atomic_add_unless" > > +coccilib.report.print_report(p1[0], msg) > > + > > +@r3 exists@ > > +identifier x; > > +position p1; > > +@@ > > + > > +( > > +x = atomic_add_return@p1(-1, ...); > > +| > > +x = atomic_long_add_return@p1(-1, ...); > > +| > > +x = atomic64_add_return@p1(-1, ...); > > +) > > + > > +@script:python depends on report@ > > +p1 << r3.p1; > > +@@ > > +msg = "x = atomic_add_return(-1, ...)" > > +coccilib.report.print_report(p1[0], msg) > > + > > + > > -- > > 2.7.4 > > > > > > -- > Kees Cook > Pixel Security >