Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1527749ybg; Thu, 4 Jun 2020 11:59:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjKz94Vj2VMjogVq+88b/mEvQUmkbnIo45sXZ1xzvzU9NdSKsbZbv6GnrPc3n7Ad0HvEfG X-Received: by 2002:a17:906:f06:: with SMTP id z6mr5039684eji.105.1591297173940; Thu, 04 Jun 2020 11:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591297173; cv=none; d=google.com; s=arc-20160816; b=EfUHPsGkoQfzf7esvCZVy3M8lK1qQohSVAuYl4+dNamajVGz8hD4X4PqrpkN+AHKJR 74/9y9mkbGT7UPLlaS64ftn22GMRk7QpHi8OmGLE0XK04s4DwOpxNXrFZaY9nrB03w/r CDQCmvMrA4SMFiufY/SJnZrELOnME3rQm1fdAIK9nchPO3YewmIwIc8oG6//AH6IwzZS pbMhKeJQ5kVxgDkczBxSuYOQDcVh/ZI++bq++K2PH95BxdKRwCyMCRIj6wZ3cuG+ua+v t8e2hrhdo368ZztVaesnY2F0UHo4NOG+OtGnKES4M1z0r7dTlqoeNEHiYSNnQzdYKLjx BVAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:from:references:cc:to:reply-to; bh=r3pHeafroYjCOPxLj9S1OAEXhOignYglUX2vpauVcxc=; b=RPL4ScUSJyEspUkpriHbujrri0UpTA4Oh5Bi7+x1cVnrcDQPi1QBN79ol9VVEgTwq1 4vKJJOAcRrNyRfmIbGILpyeiAUj9esgghyMtc6Na7hwGePDBR2GA41e5QEKo6gFL3Dgn ZO7Y8YS+a4wIKpb8bJtewh8EImxgZTDx9P535/gmzSF1AnrJ1LloXufARaQtze34+8gy I12cTwLCRt//AHlb2rN/C8NbcVTO/37TaH+hNJZv0/MkuOvRAlyzi2qsx9LEKBxTGiPD nk3YN4O/x9RN+pkEQwPMoWZvBvkynsGQPqafwI73iQBjjCmtdexVLqPW/izfxPwE+BbK Jlkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n27si2104755eja.232.2020.06.04.11.59.10; Thu, 04 Jun 2020 11:59:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730073AbgFDRWW (ORCPT + 99 others); Thu, 4 Jun 2020 13:22:22 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:36120 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730043AbgFDRWV (ORCPT ); Thu, 4 Jun 2020 13:22:21 -0400 Received: by mail-lj1-f196.google.com with SMTP id a25so8316545ljp.3 for ; Thu, 04 Jun 2020 10:22:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=r3pHeafroYjCOPxLj9S1OAEXhOignYglUX2vpauVcxc=; b=p0anhZF2iv4Ad8pZ7TdBVQFm1FU4L6LgCHGIgFZ8PRhfLujC8hpR06O+s0ggcFomzo oAvK2Al+L3UpgYtiv+n1PKLwOB3w2zV+goEDbBcQW97B/qVdJmIPM4q4vrN2eIMrSB8P dc2n9yJwqsf+kdH8rDK/6c9Iw84JzmaC2zXD3QSX9vSM9t50FxJRXJTFnpWnThPMxYpR 99adMLZZV9iO6TfNJPfthfbK9O5eVHRUrYI8bn1//1AZM3Otv08BLitAoVT7v6aD173Z UtHMyaYCdCmPCiCBBhrlzgdqUvRRWCMUGSEZTxEn5PVSTORyWfpZ9aOwAcY5B02sVsFd yOPw== X-Gm-Message-State: AOAM532GfRT18/aYuVTdMo8fiEPJY1zL/UdX2xvbzOMPX//Xb1scEny1 OsmGkn4jMxYB9RPu6zr0uiJvRMcV X-Received: by 2002:a2e:7303:: with SMTP id o3mr2845188ljc.100.1591291336083; Thu, 04 Jun 2020 10:22:16 -0700 (PDT) Received: from [10.68.32.147] (broadband-37-110-38-130.ip.moscow.rt.ru. [37.110.38.130]) by smtp.gmail.com with ESMTPSA id 3sm57077lfq.55.2020.06.04.10.22.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Jun 2020 10:22:14 -0700 (PDT) Reply-To: efremov@linux.com To: Julia Lawall Cc: cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org References: <20200604140805.111613-1-efremov@linux.com> From: Denis Efremov Autocrypt: addr=efremov@linux.com; keydata= mQINBFsJUXwBEADDnzbOGE/X5ZdHqpK/kNmR7AY39b/rR+2Wm/VbQHV+jpGk8ZL07iOWnVe1 ZInSp3Ze+scB4ZK+y48z0YDvKUU3L85Nb31UASB2bgWIV+8tmW4kV8a2PosqIc4wp4/Qa2A/ Ip6q+bWurxOOjyJkfzt51p6Th4FTUsuoxINKRMjHrs/0y5oEc7Wt/1qk2ljmnSocg3fMxo8+ y6IxmXt5tYvt+FfBqx/1XwXuOSd0WOku+/jscYmBPwyrLdk/pMSnnld6a2Fp1zxWIKz+4VJm QEIlCTe5SO3h5sozpXeWS916VwwCuf8oov6706yC4MlmAqsQpBdoihQEA7zgh+pk10sCvviX FYM4gIcoMkKRex/NSqmeh3VmvQunEv6P+hNMKnIlZ2eJGQpz/ezwq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lp6Do+pRsOO1YNNO78SYABhMi3fEa7X37 WxL31TrNCPnIauTgZtf/KCFQJpKaakC3ffEkPhyTjEl7oOE9xccNjccZraadi+2uHV0ULA1m ycHhb817A03n1I00QwLf2wOkckdqTqRbFFI/ik69hF9hemK/BmAHpShI+z1JsYT9cSs8D7wb aF/jQVy4URensgAPkgXsRiboqOj/rTz9F5mpd/gPU/IOUPFEMoo4TInt/+dEVECHioU3RRrW EahrGMfRngbdp/mKs9aBR56ECMfFFUPyI3VJsNbgpcIJjV/0N+JdJKQpJ/4uQ2zNm0wH/RU8 CRJvEwtKemX6fp/zLI36Gvz8zJIjSBIEqCb7vdgvWarksrhmi6/Jay5zRZ03+k6YwiqgX8t7 ANwvYa1h1dQ36OiTqm1cIxRCGl4wrypOVGx3OjCar7sBLD+NkwO4RaqFvdv0xuuy4x01VnOF Subject: Re: [PATCH] coccinelle: api: add kzfree script Message-ID: <65dee3e0-7df9-5b38-fe4c-5de3f70380a0@linux.com> Date: Thu, 4 Jun 2020 20:22:13 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Could you send an example of some C code on which the result is not > suitable? I've updated the pattern to handle false positives: @ifok@ position p; expression *E; @@ ( if (...) { ... memset(E, 0, ...)@p; ... } | if (...) { ... } else { ... memset(E, 0, ...)@p; ... } ) // Ignore kzfree definition // Ignore kasan test @r depends on !patch && !(file in "lib/test_kasan.c") && !(file in "mm/slab_common.c")@ expression *E; position p != ifok.p; @@ * memset(E, 0, ...)@p; ... when != E when != if (...) { ... E ... } when != for (...;...;...) { ... E ... } when != while (...) { ... E ... } when strict * kfree(E); Example of false positives: void test_memset_under_if(void) { char *p = malloc(10, GFP_KERNEL); if (p % 5) { p[5] = 1; } else { memset(p, 0, 10); } kfree(p); } void test_memset_under_if(void) { int i; char *p = malloc(10, GFP_KERNEL); for (i = 0; i < 10; ++i) { memset(p, 0, 10); } kfree(p); } void test_E_in_if(void) { char *p = malloc(10, GFP_KERNEL); memset(p, 0, 10); // when != E is not enough if (10) { // when != if (...) { ... E ... } is required p[5] = 1; } kfree(p); } void test_E_in_for(void) { char *p = malloc(10, GFP_KERNEL); memset(p, 0, 10); for(;;) { p[5] = 1; } kfree(p); } void test_E_in_while(void) { char *p = malloc(10, GFP_KERNEL); memset(p, 0, 10); while(1) { p[6] = 2; } kfree(p); } void test_E_in_struct(void) { struct t { int a[3]; }; struct t *p = malloc(10 * sizeof(struct(struct t)), GFP_KERNEL); memset(p, 0, 10); for(;;) { if (1) { p->a[2] = 1; // I give up on this p->a[0] = 10; } } kfree(p); } After all it seems reasonable to me to add forall and memset_explicit rather than handle all these false positives. Something like this for v2? @r depends on !patch && !(file in "lib/test_kasan.c") && !(file in "mm/slab_common.c") forall@ expression *E; position p; @@ * \(memset\|memset_explicit\)(E, 0, ...); ... when != E * kfree(E)@p; Do I need to add "when strict" with forall or it's already enabled in this case? Do I need to enable forall for pathing "-/+"? Thanks, Denis