From: Markus Elfring <Markus.Elfring@web.de>
To: Ella Ma <alansnape3058@gmail.com>,
cocci@inria.fr, Julia Lawall <Julia.Lawall@inria.fr>,
Nicolas Palix <nicolas.palix@imag.fr>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: Re: [cocci] [PATCH] coccinelle: free: add a checker for `__cleanup(kfree)` usage
Date: Mon, 31 Aug 2026 17:01:10 +0200 [thread overview]
Message-ID: <4209f4bf-48eb-4856-81c7-9332b491b65c@web.de> (raw)
In-Reply-To: <20260831134336.45540-1-alansnape3058@gmail.com>
> Using __cleanup(kfree) will pass the stack address of the annotated
> local variable to kfree functions.
I got the impression that this wording approach is improvable.
This attribute probably needs a pointer to an object which was
dynamically allocated.
How do you think about to handle an attribute parameter?
Would you like to support operation modes for coccicheck scripts
in a consistent way?
> This will lead to invalid
> deallocation issues. Inspired by CVE-2026-45959 and similar bugs
> recently detected.
Thanks for such background information.
…
> +++ b/scripts/coccinelle/free/cleanup-free.cocci
> @@ -0,0 +1,94 @@
…
> +/// Find __cleanup(kfree)
> +/// Using __cleanup(kfree) will pass the stack address of the annotated
> +/// local variable to kfree, causing an invalid free.
Would an other wording variant become more helpful?
> +/// I.e., `T v __cleanup(kfree);` --> `kfree(&v);`
> +/// Such usage is impossible to be correct.
…
> +// Suggesting using __free for the functions with a DEFINE_FREE definition.
> +// Update this list when new DEFINE_FREE definitions are added.
> +@free@
> +attribute name __cleanup;
> +symbol kfree, kfree_sensitive, kvfree, kvfree_atomic;
> +type T;
> +identifier v, n;
> +position p;
> +@@
> +
> +(
> + T v __cleanup@p(
> +(
> + n
> +&
> +(
> + kfree \| kfree_sensitive \| kvfree \| kvfree_atomic
> +)
How do you think about to specify relevant function names
on separate lines for such an SmPL conjunction?
Can symbol lists be converted into corresponding case distinctions?
Regards,
Markus
next prev parent reply other threads:[~2026-08-31 15:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 13:43 Ella Ma
2026-08-31 15:01 ` Markus Elfring [this message]
2026-09-24 16:25 ` [PATCH v2] " Ella Ma
2026-09-27 9:43 ` Julia Lawall
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=4209f4bf-48eb-4856-81c7-9332b491b65c@web.de \
--to=markus.elfring@web.de \
--cc=Julia.Lawall@inria.fr \
--cc=alansnape3058@gmail.com \
--cc=cocci@inria.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.palix@imag.fr \
/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
all inboxes | Powered by JetHome®