Skip to content

Commit 9c568db

Browse files
evdenisJuliaLawall
authored andcommitted
coccinelle: api: extend memdup_user rule with vmemdup_user()
Add vmemdup_user() transformations to the memdup_user.cocci rule. Commit 50fd2f2 ("new primitive: vmemdup_user()") introduced vmemdup_user(). The function uses kvmalloc with GPF_USER flag. Signed-off-by: Denis Efremov <[email protected]>
1 parent 547ade4 commit 9c568db

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

scripts/coccinelle/api/memdup_user.cocci

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ identifier l1,l2;
3939
- ...+>
4040
- }
4141

42+
@depends on patch@
43+
expression from,to,size;
44+
identifier l1,l2;
45+
@@
46+
47+
- to = \(kvmalloc\|kvzalloc\)(size,\(GFP_KERNEL\|GFP_USER\));
48+
+ to = vmemdup_user(from,size);
49+
if (
50+
- to==NULL
51+
+ IS_ERR(to)
52+
|| ...) {
53+
<+... when != goto l1;
54+
- -ENOMEM
55+
+ PTR_ERR(to)
56+
...+>
57+
}
58+
- if (copy_from_user(to, from, size) != 0) {
59+
- <+... when != goto l2;
60+
- -EFAULT
61+
- ...+>
62+
- }
63+
4264
@r depends on !patch@
4365
expression from,to,size;
4466
position p;
@@ -52,6 +74,17 @@ statement S1,S2;
5274
if (copy_from_user(to, from, size) != 0)
5375
S2
5476

77+
@rv depends on !patch@
78+
expression from,to,size;
79+
position p;
80+
statement S1,S2;
81+
@@
82+
83+
* to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_KERNEL\|GFP_USER\));
84+
if (to==NULL || ...) S1
85+
if (copy_from_user(to, from, size) != 0)
86+
S2
87+
5588
@script:python depends on org@
5689
p << r.p;
5790
@@
@@ -63,3 +96,15 @@ p << r.p;
6396
@@
6497
6598
coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user")
99+
100+
@script:python depends on org@
101+
p << rv.p;
102+
@@
103+
104+
coccilib.org.print_todo(p[0], "WARNING opportunity for vmemdup_user")
105+
106+
@script:python depends on report@
107+
p << rv.p;
108+
@@
109+
110+
coccilib.report.print_report(p[0], "WARNING opportunity for vmemdup_user")

0 commit comments

Comments
 (0)