Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4446097ybg; Mon, 8 Jun 2020 08:03:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoIQYKT0AyLdMN8bH75xkk0Lq5DGNMmhM0Y+iwxHHl4Sno8p61cTpVzMj6lYm0+GaLu/N3 X-Received: by 2002:a17:906:1c8e:: with SMTP id g14mr21131945ejh.136.1591628632465; Mon, 08 Jun 2020 08:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591628632; cv=none; d=google.com; s=arc-20160816; b=PMfIelYElQrz4GfpgiORlyNEw3EtBIe8cGw4qfIUxI4XPXBtnyut0JLw8pQUcmxfqd tFtuvijqm7vuXqZnjM8wlsje5FXHUAUybzkQBP6w2BHpZlVNPhJUoGxQahYUeUf/iKHy JD88+2Br9Q71vxagLPV7O3WmX44ZeETDBr2ei4wnk4WHp7LhS0prpPj/LxdnHndekKWY 1TDI/5kNAf5yacESYEZJfaTzZSszOJ+soKaqBDd0FUSNFnXylbKy3xbI6g9W6Pv4T8ac y/D1br7pXhFuWI0hxG0Y1QufMbKMF72wP/UOuNeP2k28TdFyKp9aMV1B8IyAC0rW0Hd5 NAXg== 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=i3uqReldNyB0HkYkJlYcEfBw/J6TVeoQE4OBnMgY2IY=; b=CUhEbCb5PQrZiEiBYoK1Ooe/6gCwRzDk76pZKYGZ0IJnnCljRiowDDu54tkmToOsHQ B6/+mBuXuVF6/aiQ8NlZlOBBSDXu73ItWqmn6MPioTJYcDYPmnp+/dz7lL9coBUdJV2z /VBMse+UcisnRcK4B/DDi7m2+3tHGV0HBeZWsXhDkF3HXBzq+mGyPaw/Mn7vlntZA9Zh Pl2UW3nIw0FupcBUaD+mDHxMXxvowHbLn2Q0975/KnVRi08JshoblrpBjanN7N9XTPAl 5phJGwsYHpLhUBLG/e5rJ4TXQZCw583s1fnGOQmJ+PsgE2usn+4cDtCuDCC9T9kJdX4m Lakg== 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 bc22si9127263edb.368.2020.06.08.08.03.28; Mon, 08 Jun 2020 08:03:52 -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 S1730189AbgFHPBY (ORCPT + 99 others); Mon, 8 Jun 2020 11:01:24 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:42159 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730161AbgFHPBU (ORCPT ); Mon, 8 Jun 2020 11:01:20 -0400 Received: by mail-lf1-f67.google.com with SMTP id x27so10399819lfg.9 for ; Mon, 08 Jun 2020 08:01:19 -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=i3uqReldNyB0HkYkJlYcEfBw/J6TVeoQE4OBnMgY2IY=; b=pNLp5tQylCo58kUKazHE4J9sIJuhKaHjHh4r60BsioXGMA7Lh5Uz3F3FeBAM+Eg92N hMz1cP8JX2u6YNdxuIF8rX9ABvkSN5nugZ04Ei9Zcc14IRd9B6QsAd69b1ZBsJsmEdBF zTfCQK+ElHhZA44cnK6GkF7i44B190nbaTDSlJc55zwqC/1TTxkMXVK+vOlJwu2C3GD5 3s1fhuAXhmA8BZoBdJK5eMVQOE0aoE3uxMt+m4LA1/c/AVNbcX2bmO0C+4q5iPl0qYey HBSmcwOqDtUAGDufUjTfg8bHVkte2RhoN/w59eZjr3IsqYfJT6p3+BzKkbTq+qOjNOou azaw== X-Gm-Message-State: AOAM530VrV565CFOh92/ggQz5bOnW9CK306BS3psZaQ3hFKKfGINfl84 pIu5BmxZ66pjM87Qz3O/hN4= X-Received: by 2002:a19:cb05:: with SMTP id b5mr12963374lfg.108.1591628478293; Mon, 08 Jun 2020 08:01:18 -0700 (PDT) Received: from localhost.localdomain ([213.87.137.116]) by smtp.googlemail.com with ESMTPSA id r16sm279228ljn.106.2020.06.08.08.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2020 08:01:17 -0700 (PDT) From: Denis Efremov To: Julia Lawall Cc: Denis Efremov , linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr Subject: [PATCH v2 2/4] coccinelle: api: extend memdup_user rule with vmemdup_user() Date: Mon, 8 Jun 2020 18:00:36 +0300 Message-Id: <20200608150038.223747-3-efremov@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200608150038.223747-1-efremov@linux.com> References: <20200608150038.223747-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 cadcc2e87881..d15c061a34ab 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