Linux Audio

Check our new training course

Loading...
v4.17
 
 1/// Use memdup_user rather than duplicating its implementation
 2/// This is a little bit restricted to reduce false positives
 3///
 4// Confidence: High
 5// Copyright: (C) 2010-2012 Nicolas Palix.  GPLv2.
 6// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.  GPLv2.
 7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.  GPLv2.
 8// URL: http://coccinelle.lip6.fr/
 9// Comments:
10// Options: --no-includes --include-headers
11
12virtual patch
13virtual context
14virtual org
15virtual report
16
17@depends on patch@
18expression from,to,size;
19identifier l1,l2;
20@@
21
22-  to = \(kmalloc\|kzalloc\)(size,GFP_KERNEL);
23+  to = memdup_user(from,size);
24   if (
25-      to==NULL
26+      IS_ERR(to)
27                 || ...) {
28   <+... when != goto l1;
29-  -ENOMEM
30+  PTR_ERR(to)
31   ...+>
32   }
33-  if (copy_from_user(to, from, size) != 0) {
34-    <+... when != goto l2;
35-    -EFAULT
36-    ...+>
37-  }
38
39@r depends on !patch@
40expression from,to,size;
41position p;
42statement S1,S2;
43@@
44
45*  to = \(kmalloc@p\|kzalloc@p\)(size,GFP_KERNEL);
46   if (to==NULL || ...) S1
47   if (copy_from_user(to, from, size) != 0)
48   S2
49
50@script:python depends on org@
51p << r.p;
52@@
53
54coccilib.org.print_todo(p[0], "WARNING opportunity for memdup_user")
55
56@script:python depends on report@
57p << r.p;
58@@
59
60coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user")
v5.4
 1// SPDX-License-Identifier: GPL-2.0-only
 2/// Use memdup_user rather than duplicating its implementation
 3/// This is a little bit restricted to reduce false positives
 4///
 5// Confidence: High
 6// Copyright: (C) 2010-2012 Nicolas Palix.
 7// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
 8// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
 9// URL: http://coccinelle.lip6.fr/
10// Comments:
11// Options: --no-includes --include-headers
12
13virtual patch
14virtual context
15virtual org
16virtual report
17
18@depends on patch@
19expression from,to,size;
20identifier l1,l2;
21@@
22
23-  to = \(kmalloc\|kzalloc\)(size,GFP_KERNEL);
24+  to = memdup_user(from,size);
25   if (
26-      to==NULL
27+      IS_ERR(to)
28                 || ...) {
29   <+... when != goto l1;
30-  -ENOMEM
31+  PTR_ERR(to)
32   ...+>
33   }
34-  if (copy_from_user(to, from, size) != 0) {
35-    <+... when != goto l2;
36-    -EFAULT
37-    ...+>
38-  }
39
40@r depends on !patch@
41expression from,to,size;
42position p;
43statement S1,S2;
44@@
45
46*  to = \(kmalloc@p\|kzalloc@p\)(size,GFP_KERNEL);
47   if (to==NULL || ...) S1
48   if (copy_from_user(to, from, size) != 0)
49   S2
50
51@script:python depends on org@
52p << r.p;
53@@
54
55coccilib.org.print_todo(p[0], "WARNING opportunity for memdup_user")
56
57@script:python depends on report@
58p << r.p;
59@@
60
61coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user")