Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp137001imm; Thu, 14 Jun 2018 16:59:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLVAoUdJv4MpP7cZlhAARJQ+jUJ8k8DT9k0+QPITQ083Z3TgGl1FdDwsVpFf27rSYGe/xIH X-Received: by 2002:a17:902:2006:: with SMTP id n6-v6mr5251771pla.125.1529020786222; Thu, 14 Jun 2018 16:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529020786; cv=none; d=google.com; s=arc-20160816; b=GYYSysqrbP5i3JjI0Q8kdcdoVs13u+nZc82ymdRjuejponXV9t5qgAT8K3CB2p63MR f2I8Df24zY1Jf4Na8SqHTwwtxCHDEdzonCcMxD6Vqk5SvJW8EEQShOqP4wB0PUPLuq8V +vhRqEDtYCyus3xihzelSuaKwwmJhf+8xsN3WwFBwvRpYHwiFc9zgC/r08Y4sVo1Xr2J hg8PDxKhWOw+7+xDEbTBmlKZ7mOF2UzdMtf19bAVElxcBzBsjSEILsQfcGtlp/t+GYRN W/kKm4Z0hSpzvnN4GMk5qRf65DKs90bX7rMU/vCYLIGq+ujr1QGq4R/FOwXZblUQcbL9 3Kqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=b9Y57Zcw0NoW8SSCQPbfjQuVqgilhOQhSYXtSwp/X1s=; b=RpVskfkDdochHhffEeWHjCk7z8OB0vT92KWZbKUOfGOnm3t6OoAhb+5191jrclmKkT cTKQiNeOrmtv1WdZSK1MzemM94QGwuTujE+e0gBQHGvlk6t+hLpk891BQ6Gd2fsUSXbL ywlobPU9Vre09t4Hc1cpKP8ve1v32zw8HGFjMa+TPM/b9BcvFZV57MXLzdfvcoCl+H/d 5SNicrXcEhA+A1FG0npO29XT/wSqL6ByC86MPKVC1/DS/e6frPFGhJSs/GXrCcYJ2KVX mcbBXZePQkOh6tV7mMzZ/CEw/9ZUPfJoEYvv+r2L2Kufu5KQ0OzM1WBVAlU4cgfXZUgc btHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=EuFajCPq; dkim=fail header.i=@chromium.org header.s=google header.b=YY1Pcp3z; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5-v6si6313111pls.518.2018.06.14.16.59.32; Thu, 14 Jun 2018 16:59:46 -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; dkim=fail header.i=@google.com header.s=20161025 header.b=EuFajCPq; dkim=fail header.i=@chromium.org header.s=google header.b=YY1Pcp3z; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965189AbeFNX6K (ORCPT + 99 others); Thu, 14 Jun 2018 19:58:10 -0400 Received: from mail-yb0-f193.google.com ([209.85.213.193]:41004 "EHLO mail-yb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965096AbeFNX6I (ORCPT ); Thu, 14 Jun 2018 19:58:08 -0400 Received: by mail-yb0-f193.google.com with SMTP id u11-v6so2894852ybi.8 for ; Thu, 14 Jun 2018 16:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=b9Y57Zcw0NoW8SSCQPbfjQuVqgilhOQhSYXtSwp/X1s=; b=EuFajCPqsh/77tWQn1RL4/Qjh5fsKcsKdhyd1kPqyCA9DHSud0qClhENFidPdGzs6L G+9O0WNAxBvGC3LcGWYDoNe3zpzCzMEvCujSXjdfPYe2shsQpFTs19SI6qy2RnWgmaYk jZ/Iv7Gde3l455rZ0m46UZkIJZC2LVhMMFv6TNhih/6gTap4ClSIXTFnY8pogdXvC4sE NcDdoqMGYE14X8CEeeNoWEiniaw2zvtT5r3SnWljhQqvydiuT9ZQa0IJCB/Qvh+7qClD ao3fovZ8sD8Keo/9Ig6vNi4/wfC6AZx7qCJMQTwM0pY+CVuercMSkt2YqAl6ayazb3Ls WA+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=b9Y57Zcw0NoW8SSCQPbfjQuVqgilhOQhSYXtSwp/X1s=; b=YY1Pcp3zuL3j91MIMPKlDVxn1bzJ3DuO3dnHCzaZT4zz6hpW8SBYlCCMsYJ6n14X8e hT/a1fvM/4lSWcg2Lxsmi0CoKGPHxi4CxQxEJuQNFpTLi5r6N+2T9bsjaYxBZoGq0uN+ ez6eqQm9b3ggWEM9wo+nyRySZhKJIZkc6PZ7s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=b9Y57Zcw0NoW8SSCQPbfjQuVqgilhOQhSYXtSwp/X1s=; b=V/fxdU1FJi1eT/TAFwSMQVtEvCRkD/ph1as0Yaj4+t0hQXQ23fyEB7guEKGrwkhCAW JXjX7E6UQbMj0T1oPRgE5g27PB1NMbkCvHMN2eD5Iw/jGJjND29HVb7Kuf7ovVdBaC++ iKlgNbJygz9g3sn1701v5A47xDzXJHABtTOQdd41A35nUlBl50Z3ce8NAteYrAYRA/57 76OpE8QCf0AJM7qtUGFxjfK68myD74TCvr6lGKqcrGWNKzqn+QfL1rA87UDVx+Wg3Pki MktgCIMeUfNDt+qcO+2ArRBGtp5olL2JX/zbtYDqnz/FxxMHRxTZKHonv46OTjywebkm MRfQ== X-Gm-Message-State: APt69E211PNlLDTFSXEGivsWtVgvHAnDYq9o5pekT57vTSPURs3xio6D +ZYS3aGCys+6zumJVJ2OazwgJ04R0MCJdU4qzeMilQ== X-Received: by 2002:a25:a301:: with SMTP id d1-v6mr2712981ybi.193.1529020687876; Thu, 14 Jun 2018 16:58:07 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:d6c5:0:0:0:0:0 with HTTP; Thu, 14 Jun 2018 16:58:07 -0700 (PDT) In-Reply-To: <1504258820-2122-1-git-send-email-elena.reshetova@intel.com> References: <1504258820-2122-1-git-send-email-elena.reshetova@intel.com> From: Kees Cook Date: Thu, 14 Jun 2018 16:58:07 -0700 X-Google-Sender-Auth: Q_qwhs3sQtZ3P5COMDUu0WbKk_U Message-ID: Subject: Re: [PATCH] Coccinelle: add atomic_as_refcounter script To: Elena Reshetova , Masahiro Yamada Cc: Julia Lawall , LKML , cocci@systeme.lip6.fr, Gilles Muller , Nicolas Palix , Michal Marek , Hans Liljestrand Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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