Re: [PATCH v4] coccinelle: api: add kzfree script

2020-08-11 Thread Denis Efremov
On 8/11/20 2:45 AM, Eric Biggers wrote: > On Fri, Jul 17, 2020 at 10:39:20PM +0200, Julia Lawall wrote: >> >> >> On Fri, 17 Jul 2020, Denis Efremov wrote: >> >>> Check for memset()/memzero_explicit() followed by kfree()/vfree()/kvfree(). >>> >>> Signed-off-by: Denis Efremov >> >> Applied. > >

Re: [PATCH v4] coccinelle: api: add kzfree script

2020-08-10 Thread Eric Biggers
On Fri, Jul 17, 2020 at 10:39:20PM +0200, Julia Lawall wrote: > > > On Fri, 17 Jul 2020, Denis Efremov wrote: > > > Check for memset()/memzero_explicit() followed by kfree()/vfree()/kvfree(). > > > > Signed-off-by: Denis Efremov > > Applied. FYI, this new script is already outdated, since kzf

Re: [PATCH v4] coccinelle: api: add kzfree script

2020-07-17 Thread Julia Lawall
On Fri, 17 Jul 2020, Denis Efremov wrote: > Check for memset()/memzero_explicit() followed by kfree()/vfree()/kvfree(). > > Signed-off-by: Denis Efremov Applied. > --- > Changes in v2: > - memset_explicit() added > - kvfree_sensitive() added > - forall added to r1 > - ... between memset

Re: [PATCH v4] coccinelle: api: add kzfree script

2020-07-17 Thread Markus Elfring
I dare to repeat previous patch review aspects once more. https://lore.kernel.org/cocci/a316f076-1686-25d8-18fe-1bbc0cf9a...@web.de/ … > +virtual context > +virtual patch > +virtual org > +virtual report +virtual context, patch, org, report Is such a SmPL code variant more succinct? … > +if (.

[PATCH v4] coccinelle: api: add kzfree script

2020-07-17 Thread Denis Efremov
Check for memset()/memzero_explicit() followed by kfree()/vfree()/kvfree(). Signed-off-by: Denis Efremov --- Changes in v2: - memset_explicit() added - kvfree_sensitive() added - forall added to r1 - ... between memset and kfree added Changes in v3: - Explicit filter for definitions instead

Re: [Cocci] [PATCH v3] coccinelle: api: add kzfree script

2020-07-07 Thread Julia Lawall
On Mon, 15 Jun 2020, Denis Efremov wrote: > Check for memset()/memzero_explicit() followed by kfree()/vfree()/kvfree(). > > Signed-off-by: Denis Efremov > --- > Changes in v2: > - memset_explicit() added > - kvfree_sensitive() added > - forall added to r1 > - ... between memset and kfree a

Re: [Cocci] [PATCH v3] coccinelle: api: add kzfree script

2020-06-17 Thread Denis Efremov
>> +@rp_memset depends on patch@ >> +expression E, size; >> +position p : script:python() { relevant(p) }; >> +type T; >> +@@ >> + >> +- memset((T)E, size)@p; > > This is missing a 0 argument. > Thanks, I will send v4. > > >> + ... when != E >> + when strict >> +( >> +- kfree(E); >> +

Re: [Cocci] [PATCH v3] coccinelle: api: add kzfree script

2020-06-17 Thread Julia Lawall
On Mon, 15 Jun 2020, Denis Efremov wrote: > Check for memset()/memzero_explicit() followed by kfree()/vfree()/kvfree(). > > Signed-off-by: Denis Efremov > --- > Changes in v2: > - memset_explicit() added > - kvfree_sensitive() added > - forall added to r1 > - ... between memset and kfree a

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-15 Thread Denis Efremov
On 6/15/20 3:03 PM, Dan Carpenter wrote: > On Sun, Jun 14, 2020 at 10:42:54PM +0300, Denis Efremov wrote: >> On 6/4/20 7:27 PM, Joe Perches wrote: >>> On Thu, 2020-06-04 at 17:08 +0300, Denis Efremov wrote: Check for memset() with 0 followed by kfree(). >>> >>> Perhaps those uses should be

Re: [PATCH v3] coccinelle: api: add kzfree script

2020-06-15 Thread Markus Elfring
… > +virtual context > +virtual patch > +virtual org > +virtual report +virtual context, patch, org, report Is such a SmPL code variant more succinct? … > +if (...) > + \(memset@ok\|memzero_explicit@ok\)(...); Would you like to tolerate any extra source code around such a function call in an

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-15 Thread Dan Carpenter
On Sun, Jun 14, 2020 at 10:42:54PM +0300, Denis Efremov wrote: > On 6/4/20 7:27 PM, Joe Perches wrote: > > On Thu, 2020-06-04 at 17:08 +0300, Denis Efremov wrote: > >> Check for memset() with 0 followed by kfree(). > > > > Perhaps those uses should be memzero_explicit or kvfree_sensitive. > > >

[PATCH v3] coccinelle: api: add kzfree script

2020-06-14 Thread Denis Efremov
Check for memset()/memzero_explicit() followed by kfree()/vfree()/kvfree(). Signed-off-by: Denis Efremov --- Changes in v2: - memset_explicit() added - kvfree_sensitive() added - forall added to r1 - ... between memset and kfree added Changes in v3: - Explicit filter for definitions instead

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-14 Thread Joe Perches
On Sun, 2020-06-14 at 22:42 +0300, Denis Efremov wrote: > On 6/4/20 7:27 PM, Joe Perches wrote: > > On Thu, 2020-06-04 at 17:08 +0300, Denis Efremov wrote: > > > Check for memset() with 0 followed by kfree(). > > > > Perhaps those uses should be memzero_explicit or kvfree_sensitive. > > > Is it s

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-14 Thread Denis Efremov
On 6/4/20 7:27 PM, Joe Perches wrote: > On Thu, 2020-06-04 at 17:08 +0300, Denis Efremov wrote: >> Check for memset() with 0 followed by kfree(). > > Perhaps those uses should be memzero_explicit or kvfree_sensitive. > Is it safe to suggest to use kzfree instead of memzero_explicit && kfree? Or

Re: [Cocci] [PATCH v2] coccinelle: api: add kzfree script

2020-06-06 Thread Julia Lawall
On Fri, 5 Jun 2020, Denis Efremov wrote: > It looks like a good idea to add type cast, like: > > +// Ignore kzfree definition > +// Ignore kasan test > +@r depends on !patch && !(file in "lib/test_kasan.c") && !(file in > "mm/slab_common.c") forall@ > +expression *E; > +position p; > +type T;

Re: coccinelle: api: add kzfree script

2020-06-05 Thread Markus Elfring
> Is avoiding transforming the case where E is not verified to be a pointer a > concern? I imagine that answers to this question have got consequences also on the confidence level for such SmPL scripts. The desire and requirement to specify data type restrictions (for expressions) can influence d

Re: [PATCH v2] coccinelle: api: add kzfree script

2020-06-04 Thread Markus Elfring
> Check for memset()/memset_explicit() with 0 followed by > kfree()/vfree()/kvfree(). Another software evolution will become interesting here. > +/// memset_explicit with 0 followed by kfree How do you think about to extend this comment? Would you like to take the following SmPL code variants

Re: [PATCH v2] coccinelle: api: add kzfree script

2020-06-04 Thread Markus Elfring
> On the other hand, do you really require E to be a pointer? > If you do that, it will have to find the type of E. I suggest to reconsider this information. > If E refers to a structure field, then the type might not be available > in the current function, and you may need command line argments

Re: [Cocci] [PATCH v2] coccinelle: api: add kzfree script

2020-06-04 Thread Denis Efremov
It looks like a good idea to add type cast, like: +// Ignore kzfree definition +// Ignore kasan test +@r depends on !patch && !(file in "lib/test_kasan.c") && !(file in "mm/slab_common.c") forall@ +expression *E; +position p; +type T; +@@ + +* \(memset\|memset_explicit\)((T)E, 0, ...); + ... whe

Re: [Cocci] [PATCH v2] coccinelle: api: add kzfree script

2020-06-04 Thread Denis Efremov
On 6/4/20 11:57 PM, Julia Lawall wrote: > On the other hand, do you really require E to be a pointer? If you do > that, it will have to find the type of E. If E refers to a structure > field, then the type might not be available in the current function, and > you may need command line argments li

Re: [Cocci] [PATCH v2] coccinelle: api: add kzfree script

2020-06-04 Thread Julia Lawall
On Thu, 4 Jun 2020, Denis Efremov wrote: > Check for memset()/memset_explicit() with 0 followed by > kfree()/vfree()/kvfree(). > > Signed-off-by: Denis Efremov > --- > Changes in v2: > - memset_explicit() added > - kvfree_sensitive() added > - forall added to r1 > - ... between memset and kfre

[PATCH v2] coccinelle: api: add kzfree script

2020-06-04 Thread Denis Efremov
Check for memset()/memset_explicit() with 0 followed by kfree()/vfree()/kvfree(). Signed-off-by: Denis Efremov --- Changes in v2: - memset_explicit() added - kvfree_sensitive() added - forall added to r1 - ... between memset and kfree added Unfortunately, it doesn't work as I would expect it to

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Joe Perches
On Thu, 2020-06-04 at 20:30 +0300, Denis Efremov wrote: > > On 6/4/20 7:27 PM, Joe Perches wrote: > > On Thu, 2020-06-04 at 17:08 +0300, Denis Efremov wrote: > > > Check for memset() with 0 followed by kfree(). > > > > Perhaps those uses should be memzero_explicit or kvfree_sensitive. > > Thanks

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Denis Efremov
On 6/4/20 7:27 PM, Joe Perches wrote: > On Thu, 2020-06-04 at 17:08 +0300, Denis Efremov wrote: >> Check for memset() with 0 followed by kfree(). > > Perhaps those uses should be memzero_explicit or kvfree_sensitive. Thanks, I will add memzero_explicit(). However, I can't find kvfree_sensitive

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Julia Lawall
> After all it seems reasonable to me to add forall and memset_explicit rather > than handle all these false positives. Something like this for v2? > > @r depends on !patch && !(file in "lib/test_kasan.c") && !(file in > "mm/slab_common.c") forall@ > expression *E; > position p; > @@ > > * \(memse

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Denis Efremov
> Could you send an example of some C code on which the result is not > suitable? I've updated the pattern to handle false positives: @ifok@ position p; expression *E; @@ ( if (...) { ... memset(E, 0, ...)@p; ... } | if (...) { ... } else { ... memset(E, 0, ...)@p

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Joe Perches
On Thu, 2020-06-04 at 17:08 +0300, Denis Efremov wrote: > Check for memset() with 0 followed by kfree(). Perhaps those uses should be memzero_explicit or kvfree_sensitive.

Re: coccinelle: api: add kzfree script

2020-06-04 Thread Markus Elfring
>>> +virtual context >>> +virtual org >>> +virtual report >>> +virtual patch >> >> +virtual context, org, report, patch > > This is pointless. I find the proposed SmPL code variant more succinct. >> How does the SmPL asterisk functionality fit to the operation >> modes “org” and “report”? > > ma

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Julia Lawall
On Thu, 4 Jun 2020, Markus Elfring wrote: > > Check for memset() with 0 followed by kfree(). > > I suggest to simplify the SmPL code a bit like the following. > > > > +virtual context > > +virtual org > > +virtual report > > +virtual patch > > +virtual context, org, report, patch This is pointl

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Julia Lawall
On Thu, 4 Jun 2020, Denis Efremov wrote: > > > On 6/4/20 5:15 PM, Julia Lawall wrote: > > Did you try ... here but find that some subexpressions of E could be > > modified in between? > > Yes, I tried to use "... when != E = E1 when != &E" and results were bad. > Now, I've tried forall and when

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Denis Efremov
On 6/4/20 5:15 PM, Julia Lawall wrote: > Did you try ... here but find that some subexpressions of E could be > modified in between? Yes, I tried to use "... when != E = E1 when != &E" and results were bad. Now, I've tried forall and when strict. Here are examples: // forall added // Works wel

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Markus Elfring
> Check for memset() with 0 followed by kfree(). I suggest to simplify the SmPL code a bit like the following. > +virtual context > +virtual org > +virtual report > +virtual patch +virtual context, org, report, patch … > +@@ > + > +( > +* memset(E, 0, ...); > +| > +* memset(E, '\0', ...); > +

Re: [PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Julia Lawall
On Thu, 4 Jun 2020, Denis Efremov wrote: > Check for memset() with 0 followed by kfree(). > > Signed-off-by: Denis Efremov > --- > Patches: > 1. kzfree in drivers/w1 https://lkml.org/lkml/2020/6/4/438 > 2. kzfree in drivers/iommu/ https://lkml.org/lkml/2020/6/4/421 > 3. kzfree in drivers/scsi/

[PATCH] coccinelle: api: add kzfree script

2020-06-04 Thread Denis Efremov
Check for memset() with 0 followed by kfree(). Signed-off-by: Denis Efremov --- Patches: 1. kzfree in drivers/w1 https://lkml.org/lkml/2020/6/4/438 2. kzfree in drivers/iommu/ https://lkml.org/lkml/2020/6/4/421 3. kzfree in drivers/scsi/ https://lkml.org/lkml/2020/6/4/442 scripts/coccinelle/api