~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/coccinelle/api/memdup_user.cocci

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/coccinelle/api/memdup_user.cocci (Architecture alpha) and /scripts/coccinelle/api/memdup_user.cocci (Architecture m68k)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /// Use memdup_user rather than duplicating it      2 /// Use memdup_user rather than duplicating its implementation
  3 /// This is a little bit restricted to reduce       3 /// This is a little bit restricted to reduce false positives
  4 ///                                                 4 ///
  5 // Confidence: High                                 5 // Confidence: High
  6 // Copyright: (C) 2010-2012 Nicolas Palix.          6 // Copyright: (C) 2010-2012 Nicolas Palix.
  7 // Copyright: (C) 2010-2012 Julia Lawall, INRI      7 // Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
  8 // Copyright: (C) 2010-2012 Gilles Muller, INR      8 // Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
  9 // URL: https://coccinelle.gitlabpages.inria.f      9 // URL: https://coccinelle.gitlabpages.inria.fr/website
 10 // Comments:                                       10 // Comments:
 11 // Options: --no-includes --include-headers        11 // Options: --no-includes --include-headers
 12                                                    12 
 13 virtual patch                                      13 virtual patch
 14 virtual context                                    14 virtual context
 15 virtual org                                        15 virtual org
 16 virtual report                                     16 virtual report
 17                                                    17 
 18 @initialize:python@                                18 @initialize:python@
 19 @@                                                 19 @@
 20 filter = frozenset(['memdup_user', 'vmemdup_us     20 filter = frozenset(['memdup_user', 'vmemdup_user'])
 21                                                    21 
 22 def relevant(p):                                   22 def relevant(p):
 23     return not (filter & {el.current_element f     23     return not (filter & {el.current_element for el in p})
 24                                                    24 
 25 @depends on patch@                                 25 @depends on patch@
 26 expression from,to,size;                           26 expression from,to,size;
 27 identifier l1,l2;                                  27 identifier l1,l2;
 28 position p : script:python() { relevant(p) };      28 position p : script:python() { relevant(p) };
 29 @@                                                 29 @@
 30                                                    30 
 31 -  to = \(kmalloc@p\|kzalloc@p\)                   31 -  to = \(kmalloc@p\|kzalloc@p\)
 32 -               (size,\(GFP_KERNEL\|GFP_USER\|     32 -               (size,\(GFP_KERNEL\|GFP_USER\|
 33 -                     \(GFP_KERNEL\|GFP_USER\)     33 -                     \(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN\));
 34 +  to = memdup_user(from,size);                    34 +  to = memdup_user(from,size);
 35    if (                                            35    if (
 36 -      to==NULL                                    36 -      to==NULL
 37 +      IS_ERR(to)                                  37 +      IS_ERR(to)
 38                  || ...) {                         38                  || ...) {
 39    <+... when != goto l1;                          39    <+... when != goto l1;
 40 -  -ENOMEM                                         40 -  -ENOMEM
 41 +  PTR_ERR(to)                                     41 +  PTR_ERR(to)
 42    ...+>                                           42    ...+>
 43    }                                               43    }
 44 -  if (copy_from_user(to, from, size) != 0) {      44 -  if (copy_from_user(to, from, size) != 0) {
 45 -    <+... when != goto l2;                        45 -    <+... when != goto l2;
 46 -    -EFAULT                                       46 -    -EFAULT
 47 -    ...+>                                         47 -    ...+>
 48 -  }                                               48 -  }
 49                                                    49 
 50 @depends on patch@                                 50 @depends on patch@
 51 expression from,to,size;                           51 expression from,to,size;
 52 identifier l1,l2;                                  52 identifier l1,l2;
 53 position p : script:python() { relevant(p) };      53 position p : script:python() { relevant(p) };
 54 @@                                                 54 @@
 55                                                    55 
 56 -  to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_     56 -  to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_KERNEL\|GFP_USER\));
 57 +  to = vmemdup_user(from,size);                   57 +  to = vmemdup_user(from,size);
 58    if (                                            58    if (
 59 -      to==NULL                                    59 -      to==NULL
 60 +      IS_ERR(to)                                  60 +      IS_ERR(to)
 61                  || ...) {                         61                  || ...) {
 62    <+... when != goto l1;                          62    <+... when != goto l1;
 63 -  -ENOMEM                                         63 -  -ENOMEM
 64 +  PTR_ERR(to)                                     64 +  PTR_ERR(to)
 65    ...+>                                           65    ...+>
 66    }                                               66    }
 67 -  if (copy_from_user(to, from, size) != 0) {      67 -  if (copy_from_user(to, from, size) != 0) {
 68 -    <+... when != goto l2;                        68 -    <+... when != goto l2;
 69 -    -EFAULT                                       69 -    -EFAULT
 70 -    ...+>                                         70 -    ...+>
 71 -  }                                               71 -  }
 72                                                    72 
 73 @r depends on !patch@                              73 @r depends on !patch@
 74 expression from,to,size;                           74 expression from,to,size;
 75 position p : script:python() { relevant(p) };      75 position p : script:python() { relevant(p) };
 76 statement S1,S2;                                   76 statement S1,S2;
 77 @@                                                 77 @@
 78                                                    78 
 79 *  to = \(kmalloc@p\|kzalloc@p\)                   79 *  to = \(kmalloc@p\|kzalloc@p\)
 80                 (size,\(GFP_KERNEL\|GFP_USER\|     80                 (size,\(GFP_KERNEL\|GFP_USER\|
 81                       \(GFP_KERNEL\|GFP_USER\)     81                       \(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN\));
 82    if (to==NULL || ...) S1                         82    if (to==NULL || ...) S1
 83    if (copy_from_user(to, from, size) != 0)        83    if (copy_from_user(to, from, size) != 0)
 84    S2                                              84    S2
 85                                                    85 
 86 @rv depends on !patch@                             86 @rv depends on !patch@
 87 expression from,to,size;                           87 expression from,to,size;
 88 position p : script:python() { relevant(p) };      88 position p : script:python() { relevant(p) };
 89 statement S1,S2;                                   89 statement S1,S2;
 90 @@                                                 90 @@
 91                                                    91 
 92 *  to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_     92 *  to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_KERNEL\|GFP_USER\));
 93    if (to==NULL || ...) S1                         93    if (to==NULL || ...) S1
 94    if (copy_from_user(to, from, size) != 0)        94    if (copy_from_user(to, from, size) != 0)
 95    S2                                              95    S2
 96                                                    96 
 97 @script:python depends on org@                     97 @script:python depends on org@
 98 p << r.p;                                          98 p << r.p;
 99 @@                                                 99 @@
100                                                   100 
101 coccilib.org.print_todo(p[0], "WARNING opportu    101 coccilib.org.print_todo(p[0], "WARNING opportunity for memdup_user")
102                                                   102 
103 @script:python depends on report@                 103 @script:python depends on report@
104 p << r.p;                                         104 p << r.p;
105 @@                                                105 @@
106                                                   106 
107 coccilib.report.print_report(p[0], "WARNING op    107 coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user")
108                                                   108 
109 @script:python depends on org@                    109 @script:python depends on org@
110 p << rv.p;                                        110 p << rv.p;
111 @@                                                111 @@
112                                                   112 
113 coccilib.org.print_todo(p[0], "WARNING opportu    113 coccilib.org.print_todo(p[0], "WARNING opportunity for vmemdup_user")
114                                                   114 
115 @script:python depends on report@                 115 @script:python depends on report@
116 p << rv.p;                                        116 p << rv.p;
117 @@                                                117 @@
118                                                   118 
119 coccilib.report.print_report(p[0], "WARNING op    119 coccilib.report.print_report(p[0], "WARNING opportunity for vmemdup_user")
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php