Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1366523imm; Wed, 10 Oct 2018 13:24:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV62AU7nRqgyfpms7AJwcFKKh73RB36onpZtLxWqZtsAB/NOgwvqos+BGSZUx9fq6lqP83nX8 X-Received: by 2002:a62:5ac6:: with SMTP id o189-v6mr7981052pfb.40.1539203048007; Wed, 10 Oct 2018 13:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539203047; cv=none; d=google.com; s=arc-20160816; b=wG9w2WeCUThwzHiuxRUlgWuwc7+693XKXxG6ZWkr42ESPH/Zt3jrxWpVMkx1wvJiwP vhkgWSP3tTmNZOPrFKxG8MNH2gDwahKznXyGgrtcIVU9nWOkYZZbognOEsP0dfJbkvcI ZpEIPbKGd1j5D8asDIdW05RJyre8ntpNFL03OWsllvbmExlMZJspmw8b/YTRInhOYef2 0S2NCy1uUNb0kYPMiDsxWzxTq6zwOri3eL6Ply3PPmyUbzh22h/g+HyWDTjHOH3+UvHX Lvtqz0kBq2vCKWP54/uchJuAfkPsG38uiqp7BO1SD/gAOmDVvz9NQRtIl64VDbozqomP t7Qg== 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; bh=SLoG52nMHJlPHkmrjXfSjDXLfhCassBve32klA9scCQ=; b=bhtTWEUTJzfuLVPQz4cfJvZ+Wbo3fZxfHgPp9vpooPVYPoI52nSwYCUEUatTh+cMyV KChmYpibLEtJxN56Ltkr1aD/pj5dThhVuiEvWN4/oBlBzrgKeHM99c0GZhbT92k9Krmk 8IBlxHo1sqCsBf5EB+JhiqVhfGQ3vnRSqqCzyOamKlMvZEzT+9QRuEkshPXVLRdOvkuI YhzswtYFg14uY0M4hfrsxBlQPfP/Aobb6YNRCZbC+mKFcP2aAwBHh0kqiFfyzBUu1zHb fDv42X0XtJTJUiVturM754mnGOKaEc3U5T4Gg6u7cO4Ei1sqUR4ROAu2su+WPzFPCB+c dK7g== 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 j19-v6si17403240pfh.63.2018.10.10.13.23.52; Wed, 10 Oct 2018 13:24:07 -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 S1727719AbeJKDrI (ORCPT + 99 others); Wed, 10 Oct 2018 23:47:08 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:56328 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbeJKDrI (ORCPT ); Wed, 10 Oct 2018 23:47:08 -0400 X-IronPort-AV: E=Sophos;i="5.54,365,1534802400"; d="scan'208";a="281717963" Received: from 89-157-201-244.rev.numericable.fr (HELO hadrien) ([89.157.201.244]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 22:23:18 +0200 Date: Wed, 10 Oct 2018 22:23:18 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Joel Fernandes cc: linux-kernel@vger.kernel.org, Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, Kees Cook Subject: Re: First coccinelle script, need some help. In-Reply-To: <20181010193854.GA93016@joelaf.mtv.corp.google.com> Message-ID: References: <20181010193854.GA93016@joelaf.mtv.corp.google.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) 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 Wed, 10 Oct 2018, Joel Fernandes wrote: > > Hi! > > I am trying to determine if a function argument is used across the whole > kernel for a certain kernel function. > > I mustered up enough courage to write my first coccinelle script after a few > late nights of reading up about it :) > > Here is .cocci script. I am trying to find if address is used at all in any > possible definitions of pte_alloc(): > > $ cat ~/pte_alloc.cocci > virtual report > > @pte_args depends on report@ > identifier E1, E2; > type T1, T2; > position p; > @@ > > pte_alloc@p(T1 E1, T2 E2) > { > ... > ( > ... > E2 > ... > ) > ... > } In report mode, by default, the pattern has to match on all paths. Also when you have ... before or after E2, there can be no occurrence of E2 in the code matched by the ... So your rule requires that on every possible execution path through the function, there is exactly one occurrence of E2. You can try the following instead: virtual report @pte_args depends on report exists@ identifier E1, E2; type T1, T2; position p; @@ pte_alloc@p(T1 E1, T2 E2) { ... when any E2 ... when any } The exists in the rule header means check one path at a time. The when any allows anything, including E2, to occur in the ... part. You could also drop the first when any. The E2 will only match the first one, but you don't care in this case. julia > > @script:python depends on report@ > p << pte_args.p; > @@ > coccilib.report.print_report(p[0], "WARNING: found definition of > apte_alloc_one with address used in the body") > > The above warning does fire on the following test.c program: > > struct page *pte_alloc(struct mm_struct *mm, unsigned long address) > { > address++; > if (condition()) { > return NULL; > } > } > > But, *not* if I move 'address' into the if block: > > struct page *pte_alloc(struct mm_struct *mm, unsigned long address) > { > if (condition()) { > address++; > return NULL; > } > } > > I could not understand why, In my view the "address" expression should be > matched across the function body even within if blocks. But if I move > "address" into the if block, then the match doesn't occur any longer. > > My coccicheck command is as follow: > make coccicheck COCCI=~/pte_alloc.cocci MODE=report M=test/test.c > > What am I missing? Thanks for any help. > > thanks, > > - Joel > >