Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <Julia.Lawall@inria.fr>
To: Kees Cook <kees@kernel.org>
Cc: cocci@inria.fr
Subject: Re: [cocci] __free() attribute inhibits matching?
Date: Tue, 18 Mar 2025 18:56:40 +0100	[thread overview]
Message-ID: <F7BB5789-F9F2-4D17-986A-AD7BC976F18B@inria.fr> (raw)
In-Reply-To: <202503180924.2135CF8FD@keescook>

I think you want

Expression *m;

A->@m b

B would be an identifier

Sent from my iPhone

> On 18 Mar 2025, at 17:31, Kees Cook <kees@kernel.org> wrote:
> 
> On Tue, Mar 18, 2025 at 04:43:30PM +0100, Julia Lawall wrote:
>>>> On 18 Mar 2025, at 16:39, Kees Cook <kees@kernel.org> wrote:
>>> 
>>> On Tue, Mar 18, 2025 at 12:13:15AM +0100, Julia Lawall wrote:
>>>> It makes the call just disappear.
>>> 
>>> Right, unfortunately this breaks replacement, because the __free
>>> vanishes completely even in the replacement:
>>> 
>>> -       struct platform_profile_handler *pprof __free(kfree) = kzalloc(
>>> -               sizeof(*pprof), GFP_KERNEL);
>>> +       struct platform_profile_handler *pprof = kzalloc_obj(*pprof, GFP_KERNEL);
>>> 
>>> How do we get __free to be treated like any other variable attribute?
>>> 
>> 
>> It would certainly be good to suppôt it better. But I have the impression that you are removing and recreating the whole part to the left of the equal? It could work better to remove and recreate only the kzalloc call.
> 
> Oh! Yes, thank you. That works. :)
> 
> Okay, next question. Based on your advise on constructing matches for
> arbitrarily long dereferences[1], I am trying to apply the same logic,
> but to also tie identifiers to types:
> 
> @direct depends on !(file in "tools") && !(file in "samples")@
> type TYPE;
> TYPE *P;
> TYPE *MEMBER;
> TYPE INST;
> expression COMP;
> identifier ALLOC =~ "^kv?[mz]alloc";
> fresh identifier ALLOC_OBJ = ALLOC ## "_obj";
> @@
> 
>        \(\(P\|COMP.MEMBER\|COMP->MEMBER\) \& VAR\)
> -       = ALLOC((\(sizeof(*VAR)\|sizeof(TYPE)\|sizeof(INST)\)), GFP);
> +       = ALLOC_OBJ(*VAR, GFP);
> 
> This won't parse:
> 
> minus: parse error:
>  File "scripts/coccinelle/api/kmalloc_objs.cocci", line 58, column 13, charpos = 1303
>  around = 'MEMBER',
>  whole content =       \(\(P\|COMP.MEMBER\|COMP->MEMBER\) \& VAR\)
> 
> 
> If I change MEMBER to:
> 
> identifier MEMBER;
> 
> it parses, but then I lose the association of "MEMBER" being a "TYPE"
> pointer. Is there some why to make that work?
> 
> Thanks!
> 
> -Kees
> 
> [1] https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2006182155260.2367@hadrien/
> 
> --
> Kees Cook


  reply	other threads:[~2025-03-18 17:56 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17 18:44 [cocci] __free() attribute inhibits matching? Kees Cook
2025-03-17 20:59 ` Julia Lawall
2025-03-17 23:02   ` Kees Cook
2025-03-17 23:13     ` Julia Lawall
2025-03-18 15:39       ` Kees Cook
2025-03-18 15:43         ` Julia Lawall
2025-03-18 16:30           ` Kees Cook
2025-03-18 17:56             ` Julia Lawall [this message]
2025-03-19  3:31               ` Kees Cook
2025-03-19  5:55                 ` Julia Lawall
2025-03-19  7:20                   ` [cocci] Checking the determination of type information? Markus Elfring
2025-03-19  7:44                 ` [cocci] __free() attribute inhibits matching? Julia Lawall
2025-03-19 20:06                   ` Kees Cook
2025-03-19 21:30                   ` Kees Cook
2025-03-19 23:25                     ` Julia Lawall
2025-03-21 13:52                     ` Markus Elfring
2025-03-19 10:24                 ` Markus Elfring
2025-03-19 10:57                 ` Markus Elfring
2025-03-18 17:43 ` Markus Elfring
2025-03-18 18:02   ` Kees Cook
2025-03-18 19:18     ` Markus Elfring

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=F7BB5789-F9F2-4D17-986A-AD7BC976F18B@inria.fr \
    --to=julia.lawall@inria.fr \
    --cc=cocci@inria.fr \
    --cc=kees@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).