Skip to content

Commit a3eaa2b

Browse files
t-8chIngo Molnar
authored andcommitted
x86/sysfs: Constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/20241202-sysfs-const-bin_attr-x86-v1-1-b767d5f0ac5c@weissschuh.net
1 parent 5a82223 commit a3eaa2b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

arch/x86/kernel/ksysfs.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ static ssize_t version_show(struct kobject *kobj,
2828
static struct kobj_attribute boot_params_version_attr = __ATTR_RO(version);
2929

3030
static ssize_t boot_params_data_read(struct file *fp, struct kobject *kobj,
31-
struct bin_attribute *bin_attr,
31+
const struct bin_attribute *bin_attr,
3232
char *buf, loff_t off, size_t count)
3333
{
3434
memcpy(buf, (void *)&boot_params + off, count);
3535
return count;
3636
}
3737

38-
static struct bin_attribute boot_params_data_attr = {
38+
static const struct bin_attribute boot_params_data_attr = {
3939
.attr = {
4040
.name = "data",
4141
.mode = S_IRUGO,
4242
},
43-
.read = boot_params_data_read,
43+
.read_new = boot_params_data_read,
4444
.size = sizeof(boot_params),
4545
};
4646

@@ -49,14 +49,14 @@ static struct attribute *boot_params_version_attrs[] = {
4949
NULL,
5050
};
5151

52-
static struct bin_attribute *boot_params_data_attrs[] = {
52+
static const struct bin_attribute *const boot_params_data_attrs[] = {
5353
&boot_params_data_attr,
5454
NULL,
5555
};
5656

5757
static const struct attribute_group boot_params_attr_group = {
5858
.attrs = boot_params_version_attrs,
59-
.bin_attrs = boot_params_data_attrs,
59+
.bin_attrs_new = boot_params_data_attrs,
6060
};
6161

6262
static int kobj_to_setup_data_nr(struct kobject *kobj, int *nr)
@@ -172,7 +172,7 @@ static ssize_t type_show(struct kobject *kobj,
172172

173173
static ssize_t setup_data_data_read(struct file *fp,
174174
struct kobject *kobj,
175-
struct bin_attribute *bin_attr,
175+
const struct bin_attribute *bin_attr,
176176
char *buf,
177177
loff_t off, size_t count)
178178
{
@@ -250,22 +250,22 @@ static struct bin_attribute data_attr __ro_after_init = {
250250
.name = "data",
251251
.mode = S_IRUGO,
252252
},
253-
.read = setup_data_data_read,
253+
.read_new = setup_data_data_read,
254254
};
255255

256256
static struct attribute *setup_data_type_attrs[] = {
257257
&type_attr.attr,
258258
NULL,
259259
};
260260

261-
static struct bin_attribute *setup_data_data_attrs[] = {
261+
static const struct bin_attribute *const setup_data_data_attrs[] = {
262262
&data_attr,
263263
NULL,
264264
};
265265

266266
static const struct attribute_group setup_data_attr_group = {
267267
.attrs = setup_data_type_attrs,
268-
.bin_attrs = setup_data_data_attrs,
268+
.bin_attrs_new = setup_data_data_attrs,
269269
};
270270

271271
static int __init create_setup_data_node(struct kobject *parent,

0 commit comments

Comments
 (0)