From: Daniel Gomez <da.gomez@kernel.org>
To: Petr Pavlu <petr.pavlu@suse.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Daniel Gomez <da.gomez@samsung.com>,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] module: Restore the moduleparam prefix length check
Date: Mon, 28 Jul 2025 08:43:22 +0200 [thread overview]
Message-ID: <6868be4b-86d8-4b62-b545-9ee1c30c0a26@kernel.org> (raw)
In-Reply-To: <264b23ee-7046-4be9-8e01-d79a517e6256@suse.com>
On 21/07/2025 11.21, Petr Pavlu wrote:
> On 7/17/25 9:23 PM, Daniel Gomez wrote:
>> On 30/06/2025 16.32, Petr Pavlu wrote:
>>> The moduleparam code allows modules to provide their own definition of
>>> MODULE_PARAM_PREFIX, instead of using the default KBUILD_MODNAME ".".
>>>
>>> Commit 730b69d22525 ("module: check kernel param length at compile time,
>>> not runtime") added a check to ensure the prefix doesn't exceed
>>> MODULE_NAME_LEN, as this is what param_sysfs_builtin() expects.
>>>
>>> Later, commit 58f86cc89c33 ("VERIFY_OCTAL_PERMISSIONS: stricter checking
>>> for sysfs perms.") removed this check, but there is no indication this was
>>> intentional.
>>>
>>> Since the check is still useful for param_sysfs_builtin() to function
>>> properly, reintroduce it in __module_param_call(), but in a modernized form
>>> using static_assert().
>>>
>>> While here, clean up the __module_param_call() comments. In particular,
>>> remove the comment "Default value instead of permissions?", which comes
>>> from commit 9774a1f54f17 ("[PATCH] Compile-time check re world-writeable
>>> module params"). This comment was related to the test variable
>>> __param_perm_check_##name, which was removed in the previously mentioned
>>> commit 58f86cc89c33.
>>>
>>> Fixes: 58f86cc89c33 ("VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms.")
>>> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
>>> ---
>>> include/linux/moduleparam.h | 5 ++---
>>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
>>> index bfb85fd13e1f..110e9d09de24 100644
>>> --- a/include/linux/moduleparam.h
>>> +++ b/include/linux/moduleparam.h
>>> @@ -282,10 +282,9 @@ struct kparam_array
>>> #define __moduleparam_const const
>>> #endif
>>>
>>> -/* This is the fundamental function for registering boot/module
>>> - parameters. */
>>> +/* This is the fundamental function for registering boot/module parameters. */
>>> #define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
>>> - /* Default value instead of permissions? */ \
>>> + static_assert(sizeof(""prefix) - 1 <= MAX_PARAM_PREFIX_LEN); \
>>
>> Can you clarify if -1 to remove the dot from prefix?
>>
>> Final code
>> static_assert(sizeof(""prefix) - 1 <= __MODULE_NAME_LEN); \
>>
>> with __MODULE_NAME_LEN being:
>>
>> #define __MODULE_NAME_LEN (64 - sizeof(unsigned long))
>
> Correct, -1 is to account for the dot at the end of the prefix.
LGTM,
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
>
> I actually also wanted to assert that the prefix ends with a dot, but
> unfortunately prefix[sizeof(prefix)-2] (with prefix being a string
> literal) is not a constant expression in C.
>
But even if that would be possible, there are some calls that do not have
a prefix with dot. For example,
#define core_param(name, var, type, perm) \
param_check_##type(name, &(var)); \
__module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0)
So, you'd have to handle both cases. I mean, where __module_param_call(<prefix>
is used with either MODULE_PARAM_PREFIX or an empty string "".
next prev parent reply other threads:[~2025-07-28 6:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 14:32 [PATCH 0/5] module: Fix minor problems related to MODULE_NAME_LEN Petr Pavlu
2025-06-30 14:32 ` [PATCH 1/5] module: Prevent silent truncation of module name in delete_module(2) Petr Pavlu
2025-07-16 19:47 ` Daniel Gomez
2025-06-30 14:32 ` [PATCH 2/5] module: Remove unnecessary +1 from last_unloaded_module::name size Petr Pavlu
2025-07-16 19:49 ` Daniel Gomez
2025-06-30 14:32 ` [PATCH 3/5] module: Restore the moduleparam prefix length check Petr Pavlu
2025-07-17 19:23 ` Daniel Gomez
2025-07-21 9:21 ` Petr Pavlu
2025-07-28 6:43 ` Daniel Gomez [this message]
2025-06-30 14:32 ` [PATCH 4/5] tracing: Replace MAX_PARAM_PREFIX_LEN with MODULE_NAME_LEN Petr Pavlu
2025-07-28 6:48 ` Daniel Gomez
2025-07-28 14:34 ` Steven Rostedt
2025-06-30 14:32 ` [PATCH 5/5] module: Rename MAX_PARAM_PREFIX_LEN to __MODULE_NAME_LEN Petr Pavlu
2025-07-28 6:48 ` Daniel Gomez
2025-07-31 12:03 ` [PATCH 0/5] module: Fix minor problems related to MODULE_NAME_LEN Daniel Gomez
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=6868be4b-86d8-4b62-b545-9ee1c30c0a26@kernel.org \
--to=da.gomez@kernel.org \
--cc=da.gomez@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=samitolvanen@google.com \
/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®