From: Matthieu Baerts <matttbe@kernel.org>
To: Kees Cook <kees@kernel.org>, Dan Carpenter <dan.carpenter@linaro.org>
Cc: "Rusty Russell" <rusty@rustcorp.com.au>,
"Petr Pavlu" <petr.pavlu@suse.com>,
"Daniel Gomez" <da.gomez@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
linux-modules@vger.kernel.org,
"Hans Verkuil" <hverkuil+cisco@kernel.org>,
"Malcolm Priestley" <tvboxspy@gmail.com>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Hans Verkuil" <hverkuil@kernel.org>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-hardening@vger.kernel.org,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Chris Li" <sparse@chrisli.org>,
linux-sparse@vger.kernel.org
Subject: Re: [PATCH v2 3/3] module: Add compile-time check for embedded NUL characters
Date: Fri, 19 Dec 2025 13:29:21 +0100 [thread overview]
Message-ID: <47a2f0c7-c25f-4734-840b-fdefc2f3c4a9@kernel.org> (raw)
In-Reply-To: <20251010030610.3032147-3-kees@kernel.org>
Hi Kees, Dan,
Sorry to react on an oldish patch, but I have a question about it, see
below.
On 10/10/2025 05:06, Kees Cook wrote:
> Long ago, the kernel module license checks were bypassed by embedding a
> NUL character in the MODULE_LICENSE() string[1]. By using a string like
> "GPL\0proprietary text", the kernel would only read "GPL" due to C string
> termination at the NUL byte, allowing proprietary modules to avoid kernel
> tainting and access GPL-only symbols.
>
> The MODULE_INFO() macro stores these strings in the .modinfo ELF
> section, and get_next_modinfo() uses strcmp()-family functions
> which stop at the first NUL. This split the embedded string into two
> separate .modinfo entries, with only the first part being processed by
> license_is_gpl_compatible().
>
> Add a compile-time check using static_assert that compares the full
> string length (sizeof - 1) against __builtin_strlen(), which stops at
> the first NUL. If they differ, compilation fails with a clear error
> message.
>
> While this check can still be circumvented by modifying the ELF binary
> post-compilation, it prevents accidental embedded NULs and forces
> intentional abuse to require deliberate binary manipulation rather than
> simple source-level tricks.
>
> Build tested with test modules containing both valid and invalid license
> strings. The check correctly rejects:
>
> MODULE_LICENSE("GPL\0proprietary")
>
> while accepting normal declarations:
>
> MODULE_LICENSE("GPL")
>
> Link: https://lwn.net/Articles/82305/ [1]
> Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: Petr Pavlu <petr.pavlu@suse.com>
> Cc: Daniel Gomez <da.gomez@kernel.org>
> Cc: Sami Tolvanen <samitolvanen@google.com>
> Cc: <linux-modules@vger.kernel.org>
> ---
> include/linux/moduleparam.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
> index 6907aedc4f74..915f32f7d888 100644
> --- a/include/linux/moduleparam.h
> +++ b/include/linux/moduleparam.h
> @@ -26,6 +26,9 @@
>
> /* Generic info of form tag = "info" */
> #define MODULE_INFO(tag, info) \
> + static_assert( \
> + sizeof(info) - 1 == __builtin_strlen(info), \
> + "MODULE_INFO(" #tag ", ...) contains embedded NUL byte"); \
When checking MPTCP code on top of Linus tree, I get this new warning
with all MPTCP KUnit tests (net/mptcp/*_test.c), e.g.
$ touch net/mptcp/crypto_test.c && make C=1 net/mptcp/crypto_test.o
CC [M] net/mptcp/crypto_test.o
CHECK net/mptcp/crypto_test.c
net/mptcp/crypto_test.c:72:1: error: bad integer constant expression
net/mptcp/crypto_test.c:72:1: error: static assertion failed: "MODULE_INFO(license, ...) contains embedded NUL byte"
net/mptcp/crypto_test.c:73:1: error: bad integer constant expression
net/mptcp/crypto_test.c:73:1: error: static assertion failed: "MODULE_INFO(description, ...) contains embedded NUL byte"
I'm using Sparse last development version with Dan's commit:
$ sparse --version
v0.6.4-73-gfbdde312
=> fbdde312 ("builtin: implement __builtin_strlen() for constants")
And the two lines causing the warnings don't have "\0":
72 MODULE_LICENSE("GPL");
73 MODULE_DESCRIPTION("KUnit tests for MPTCP Crypto");
Am I missing something?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2025-12-19 12:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251010030348.it.784-kees@kernel.org>
[not found] ` <68ed624c.050a0220.3ba739.64ea@mx.google.com>
[not found] ` <D1CBCBE2-3A54-410A-B15C-F1C621F9F56B@kernel.org>
[not found] ` <CANiDSCu6xZAuSF5_M-4BMRc52hbSh_1QfDQqaeGR4iD5fdQjQg@mail.gmail.com>
[not found] ` <202510141344.E0ABCD2C7@keescook>
[not found] ` <CANiDSCsBAq3Yx4ybarUb_1NkQ-bvfXvWqb-DfqXatkiYJFZWiQ@mail.gmail.com>
[not found] ` <202510201127.D97BCF2@keescook>
[not found] ` <CANiDSCtbrM4Fg_p56EdV09ts_j8HnMCc1hGH31-BZvv03Z0DjQ@mail.gmail.com>
[not found] ` <202510201146.F12EA92@keescook>
2025-11-11 13:14 ` [v2,0/3] module: Add compile-time check for embedded NUL characters Daniel Gomez
[not found] ` <20251010030610.3032147-3-kees@kernel.org>
2025-12-19 12:29 ` Matthieu Baerts [this message]
2025-12-19 12:41 ` [PATCH v2 3/3] " Daniel Gomez
2025-12-19 12:44 ` Dan Carpenter
2025-12-19 14:59 ` Matthieu Baerts
2026-01-16 23:35 ` Chris Li
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=47a2f0c7-c25f-4734-840b-fdefc2f3c4a9@kernel.org \
--to=matttbe@kernel.org \
--cc=da.gomez@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=hverkuil+cisco@kernel.org \
--cc=hverkuil@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mchehab@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=rusty@rustcorp.com.au \
--cc=samitolvanen@google.com \
--cc=sparse@chrisli.org \
--cc=tvboxspy@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/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).