From: Denis Efremov <efremov@linux.com> To: Julia Lawall <julia.lawall@inria.fr> Cc: cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: [Cocci] [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> (raw) In-Reply-To: <20200720162216.13248-1-efremov@linux.com> 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 <efremov@linux.com> --- 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 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply index Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-20 16:22 [Cocci] [PATCH v3 0/3] Update memdup_user.cocci Denis Efremov 2020-07-20 16:22 ` [Cocci] [PATCH v3 1/3] coccinelle: api: extend memdup_user transformation with GFP_USER Denis Efremov 2020-07-20 16:22 ` Denis Efremov [this message] 2020-07-20 16:22 ` [Cocci] [PATCH v3 3/3] coccinelle: api: filter out memdup_user definitions Denis Efremov 2020-07-24 20:02 ` [Cocci] [PATCH v3 0/3] Update memdup_user.cocci Julia Lawall [not found] <e3d2ffb9-2a47-3d77-0501-9d48845435bd@web.de> 2020-07-21 9:58 ` [Cocci] [PATCH v3 2/3] coccinelle: api: extend memdup_user rule with vmemdup_user() Julia Lawall [not found] ` <0b326e2b-723c-3482-c0ef-5d6592a9c6cb@web.de> 2020-07-22 6:02 ` Julia Lawall
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200720162216.13248-3-efremov@linux.com \ --to=efremov@linux.com \ --cc=cocci@systeme.lip6.fr \ --cc=julia.lawall@inria.fr \ --cc=linux-kernel@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Coccinelle Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \ cocci@systeme.lip6.fr public-inbox-index cocci Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci AGPL code for this site: git clone https://public-inbox.org/public-inbox.git