From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Luis Chamberlain <mcgrof@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Sami Tolvanen <samitolvanen@google.com>,
Daniel Gomez <da.gomez@samsung.com>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org,
"Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v2 2/6] module: sysfs: Drop member 'module_sect_attr::address'
Date: Fri, 27 Dec 2024 14:23:21 +0100 [thread overview]
Message-ID: <20241227-sysfs-const-bin_attr-module-v2-2-e267275f0f37@weissschuh.net> (raw)
In-Reply-To: <20241227-sysfs-const-bin_attr-module-v2-0-e267275f0f37@weissschuh.net>
'struct bin_attribute' already contains the member 'private' to pass
custom data to the attribute handlers.
Use that instead of the custom 'address' member.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
kernel/module/sysfs.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/kernel/module/sysfs.c b/kernel/module/sysfs.c
index b7841f76a933114e6dbd0fc2d32a60b66b7966b6..8955b3da1b499881256670418d41c5d52d9e5a5e 100644
--- a/kernel/module/sysfs.c
+++ b/kernel/module/sysfs.c
@@ -21,7 +21,6 @@
#ifdef CONFIG_KALLSYMS
struct module_sect_attr {
struct bin_attribute battr;
- unsigned long address;
};
struct module_sect_attrs {
@@ -34,8 +33,6 @@ static ssize_t module_sect_read(struct file *file, struct kobject *kobj,
struct bin_attribute *battr,
char *buf, loff_t pos, size_t count)
{
- struct module_sect_attr *sattr =
- container_of(battr, struct module_sect_attr, battr);
char bounce[MODULE_SECT_READ_SIZE + 1];
size_t wrote;
@@ -52,7 +49,7 @@ static ssize_t module_sect_read(struct file *file, struct kobject *kobj,
*/
wrote = scnprintf(bounce, sizeof(bounce), "0x%px\n",
kallsyms_show_value(file->f_cred)
- ? (void *)sattr->address : NULL);
+ ? battr->private : NULL);
count = min(count, wrote);
memcpy(buf, bounce, count);
@@ -99,7 +96,6 @@ static int add_sect_attrs(struct module *mod, const struct load_info *info)
if (sect_empty(sec))
continue;
sysfs_bin_attr_init(&sattr->battr);
- sattr->address = sec->sh_addr;
sattr->battr.attr.name =
kstrdup(info->secstrings + sec->sh_name, GFP_KERNEL);
if (!sattr->battr.attr.name) {
@@ -107,6 +103,7 @@ static int add_sect_attrs(struct module *mod, const struct load_info *info)
goto out;
}
sattr->battr.read = module_sect_read;
+ sattr->battr.private = (void *)sec->sh_addr;
sattr->battr.size = MODULE_SECT_READ_SIZE;
sattr->battr.attr.mode = 0400;
*(gattr++) = &(sattr++)->battr;
--
2.47.1
next prev parent reply other threads:[~2024-12-27 13:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-27 13:23 [PATCH v2 0/6] module: sysfs: Cleanups and preparation for const struct bin_attribute Thomas Weißschuh
2024-12-27 13:23 ` [PATCH v2 1/6] module: sysfs: Drop member 'module_sect_attrs::nsections' Thomas Weißschuh
2024-12-27 13:23 ` Thomas Weißschuh [this message]
2024-12-27 13:23 ` [PATCH v2 3/6] module: sysfs: Drop 'struct module_sect_attr' Thomas Weißschuh
2024-12-27 13:23 ` [PATCH v2 4/6] module: sysfs: Simplify section attribute allocation Thomas Weißschuh
2024-12-27 13:23 ` [PATCH v2 5/6] module: sysfs: Add notes attributes through attribute_group Thomas Weißschuh
2024-12-27 13:23 ` [PATCH v2 6/6] module: sysfs: Use const 'struct bin_attribute' Thomas Weißschuh
2024-12-31 15:07 ` [PATCH v2 0/6] module: sysfs: Cleanups and preparation for const struct bin_attribute Petr Pavlu
2025-01-07 16:52 ` Greg KH
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=20241227-sysfs-const-bin_attr-module-v2-2-e267275f0f37@weissschuh.net \
--to=linux@weissschuh.net \
--cc=da.gomez@samsung.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--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