Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp22666ybh; Mon, 20 Jul 2020 09:25:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfpLXNA1FsOQNmHlyAlTt0eyIqhkB3Khpqm2CRWNmL0D0bNILjo7FLNFv4/4VN3WNNCycA X-Received: by 2002:a17:906:4a45:: with SMTP id a5mr21017139ejv.384.1595262307523; Mon, 20 Jul 2020 09:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595262307; cv=none; d=google.com; s=arc-20160816; b=fykViFvrIRFnbW/iEeyacWmq4E9kw9vbWwuHrFpm11HhUmtGRtzzFoAonH72e/F4rj QieYO+EaFlHqQOJ02SZrsZjpyynqxKMGlQjuxWiP8vOZEmd3bGxoNxGLWLVEFHH1YBbz iJD5wqfqZ1r1fRDIIcDN28kxSHxauOW+kv8i3nRGXsx3501i2XQ54u2TkHlQQYAXAX7f JMudXXBcMPG9USs1nNgjmjJB7WYn8HdhfmwdT2ZliXrKL7c1WKAcpgFnCnuGkE7t+9Ea 9xO96To3K6D5RIF/0HkgrJG33V+l+AmTBQ/7m3rAkKf4Hy7aQcwokrIdJ9SD8wUCXAmr 3F9w== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+lKzMgNHSZBwMM73IvRnAjP9uhf7arni1ElfIUbtptY=; b=u36/t9pVb41+BuGPkkwQU3Ju0UpfjdB7qUakea35GNfAV4c2ba9t/Gs5eNgkkwUo/R T9No4O32PGAYvRchNqU60BPYPvGIuU8WM7sXz+28+wq2J03XScxy4fjuWXPMWKrkYUCL s066fuQp8/8+dFKpJvuQFY5uD6y3+n5pnajyq6QAt5x+gF9Pv/jaxw9weDwgDop3lxzF L0j7zL07hwBC9PyaVIK4fHzi1Z7Dx5rCk3K9GmIG0qrnbzw6BjovLA7Xae7Ns9nHzuSd lPXGGSZv0dp0+Yri7nfyRNoKLW+vZMbYRrmkHyi9kOvxDDHppqQjryxGNUgtNF5fRXtB FiGw== 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 i26si10787078ejx.372.2020.07.20.09.24.44; Mon, 20 Jul 2020 09:25:07 -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 S2388669AbgGTQXJ (ORCPT + 99 others); Mon, 20 Jul 2020 12:23:09 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:38851 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387878AbgGTQXF (ORCPT ); Mon, 20 Jul 2020 12:23:05 -0400 Received: by mail-lf1-f65.google.com with SMTP id t9so10046456lfl.5 for ; Mon, 20 Jul 2020 09:23:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+lKzMgNHSZBwMM73IvRnAjP9uhf7arni1ElfIUbtptY=; b=F3j3S8bFZayIwcwZZb7GCSuxjRH3w0kWjdV1izArfMOfD32TnJDqFMesD22uA0Mtpx giqwbPvWSxYzbSJqoHvY98MYtwBV/N2UX4bdLSv5B/CZX9/OxNc/tlW4nnrD8oJGtKxF stfBrpWqC67FT4cYhQTd1GJ0cr9pOqg5dvpXgOYZ8pDrAhN6j1iUYvL5O4VMWdd7FeWn eKoCuu72yWqIUjEfAD7AIq0BvQeY1FOGdnIY8FTvyl7jOttdD0PXdMlNqKw81qyUK/j8 6XMVolLxB2zEwekVB3SgfQfucbML32UcLtT6hlQcxqkFUNElJyk9Kj1UuZ8mjubVcyyE qi+A== X-Gm-Message-State: AOAM533UWNinRzgvfcR9vqb7Wi2zBFxa/ozy09KT1KQGI9d+/rV9Bw1j 6GJTSw00/EgOVHYqD3Atc2E= X-Received: by 2002:a19:414b:: with SMTP id o72mr10899004lfa.86.1595262182808; Mon, 20 Jul 2020 09:23:02 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-38-130.ip.moscow.rt.ru. [37.110.38.130]) by smtp.googlemail.com with ESMTPSA id a19sm925855lff.25.2020.07.20.09.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 09:23:02 -0700 (PDT) From: Denis Efremov To: Julia Lawall Cc: Denis Efremov , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] coccinelle: api: extend memdup_user rule with vmemdup_user() Date: Mon, 20 Jul 2020 19:22:15 +0300 Message-Id: <20200720162216.13248-3-efremov@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200720162216.13248-1-efremov@linux.com> References: <20200720162216.13248-1-efremov@linux.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add vmemdup_user() transformations to the memdup_user.cocci rule. Commit 50fd2f298bef ("new primitive: vmemdup_user()") introduced vmemdup_user(). The function uses kvmalloc with GPF_USER flag. Signed-off-by: Denis Efremov --- scripts/coccinelle/api/memdup_user.cocci | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/scripts/coccinelle/api/memdup_user.cocci b/scripts/coccinelle/api/memdup_user.cocci index 0e29d41ecab8..60027e21c5e6 100644 --- a/scripts/coccinelle/api/memdup_user.cocci +++ b/scripts/coccinelle/api/memdup_user.cocci @@ -39,6 +39,28 @@ identifier l1,l2; - ...+> - } +@depends on patch@ +expression from,to,size; +identifier l1,l2; +@@ + +- to = \(kvmalloc\|kvzalloc\)(size,\(GFP_KERNEL\|GFP_USER\)); ++ to = vmemdup_user(from,size); + if ( +- to==NULL ++ IS_ERR(to) + || ...) { + <+... when != goto l1; +- -ENOMEM ++ PTR_ERR(to) + ...+> + } +- if (copy_from_user(to, from, size) != 0) { +- <+... when != goto l2; +- -EFAULT +- ...+> +- } + @r depends on !patch@ expression from,to,size; position p; @@ -52,6 +74,17 @@ statement S1,S2; if (copy_from_user(to, from, size) != 0) S2 +@rv depends on !patch@ +expression from,to,size; +position p; +statement S1,S2; +@@ + +* to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_KERNEL\|GFP_USER\)); + if (to==NULL || ...) S1 + if (copy_from_user(to, from, size) != 0) + S2 + @script:python depends on org@ p << r.p; @@ @@ -63,3 +96,15 @@ p << r.p; @@ coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user") + +@script:python depends on org@ +p << rv.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING opportunity for vmemdup_user") + +@script:python depends on report@ +p << rv.p; +@@ + +coccilib.report.print_report(p[0], "WARNING opportunity for vmemdup_user") -- 2.26.2