Skip to content

Commit f2b62c0

Browse files
t-8chgregkh
authored andcommitted
powerpc/powernv/opal: 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]> Link: https://lore.kernel.org/r/20241216-sysfs-const-bin_attr-powerpc-v1-4-bbed8906f476@weissschuh.net Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f629576 commit f2b62c0

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

arch/powerpc/platforms/powernv/opal-core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static Elf64_Word *__init auxv_to_elf64_notes(Elf64_Word *buf,
159159
* Returns number of bytes read on success, -errno on failure.
160160
*/
161161
static ssize_t read_opalcore(struct file *file, struct kobject *kobj,
162-
struct bin_attribute *bin_attr, char *to,
162+
const struct bin_attribute *bin_attr, char *to,
163163
loff_t pos, size_t count)
164164
{
165165
struct opalcore *m;
@@ -206,9 +206,9 @@ static ssize_t read_opalcore(struct file *file, struct kobject *kobj,
206206
return (tpos - pos);
207207
}
208208

209-
static struct bin_attribute opal_core_attr = {
209+
static struct bin_attribute opal_core_attr __ro_after_init = {
210210
.attr = {.name = "core", .mode = 0400},
211-
.read = read_opalcore
211+
.read_new = read_opalcore
212212
};
213213

214214
/*
@@ -599,15 +599,15 @@ static struct attribute *mpipl_attr[] = {
599599
NULL,
600600
};
601601

602-
static struct bin_attribute *mpipl_bin_attr[] = {
602+
static const struct bin_attribute *const mpipl_bin_attr[] = {
603603
&opal_core_attr,
604604
NULL,
605605

606606
};
607607

608608
static const struct attribute_group mpipl_group = {
609609
.attrs = mpipl_attr,
610-
.bin_attrs = mpipl_bin_attr,
610+
.bin_attrs_new = mpipl_bin_attr,
611611
};
612612

613613
static int __init opalcore_init(void)

arch/powerpc/platforms/powernv/opal-dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int64_t dump_read_data(struct dump_obj *dump)
286286
}
287287

288288
static ssize_t dump_attr_read(struct file *filep, struct kobject *kobj,
289-
struct bin_attribute *bin_attr,
289+
const struct bin_attribute *bin_attr,
290290
char *buffer, loff_t pos, size_t count)
291291
{
292292
ssize_t rc;
@@ -342,7 +342,7 @@ static void create_dump_obj(uint32_t id, size_t size, uint32_t type)
342342
dump->dump_attr.attr.name = "dump";
343343
dump->dump_attr.attr.mode = 0400;
344344
dump->dump_attr.size = size;
345-
dump->dump_attr.read = dump_attr_read;
345+
dump->dump_attr.read_new = dump_attr_read;
346346

347347
dump->id = id;
348348
dump->size = size;

arch/powerpc/platforms/powernv/opal-elog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static const struct kobj_type elog_ktype = {
156156
#define OPAL_MAX_ERRLOG_SIZE 16384
157157

158158
static ssize_t raw_attr_read(struct file *filep, struct kobject *kobj,
159-
struct bin_attribute *bin_attr,
159+
const struct bin_attribute *bin_attr,
160160
char *buffer, loff_t pos, size_t count)
161161
{
162162
int opal_rc;
@@ -203,7 +203,7 @@ static void create_elog_obj(uint64_t id, size_t size, uint64_t type)
203203
elog->raw_attr.attr.name = "raw";
204204
elog->raw_attr.attr.mode = 0400;
205205
elog->raw_attr.size = size;
206-
elog->raw_attr.read = raw_attr_read;
206+
elog->raw_attr.read_new = raw_attr_read;
207207

208208
elog->id = id;
209209
elog->size = size;

arch/powerpc/platforms/powernv/opal-flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static int alloc_image_buf(char *buffer, size_t count)
432432
* and pre-allocate required memory.
433433
*/
434434
static ssize_t image_data_write(struct file *filp, struct kobject *kobj,
435-
struct bin_attribute *bin_attr,
435+
const struct bin_attribute *bin_attr,
436436
char *buffer, loff_t pos, size_t count)
437437
{
438438
int rc;
@@ -493,7 +493,7 @@ static ssize_t image_data_write(struct file *filp, struct kobject *kobj,
493493
static const struct bin_attribute image_data_attr = {
494494
.attr = {.name = "image", .mode = 0200},
495495
.size = MAX_IMAGE_SIZE, /* Limit image size */
496-
.write = image_data_write,
496+
.write_new = image_data_write,
497497
};
498498

499499
static struct kobj_attribute validate_attribute =

arch/powerpc/platforms/powernv/opal-msglog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count)
9494
}
9595

9696
static ssize_t opal_msglog_read(struct file *file, struct kobject *kobj,
97-
struct bin_attribute *bin_attr, char *to,
97+
const struct bin_attribute *bin_attr, char *to,
9898
loff_t pos, size_t count)
9999
{
100100
return opal_msglog_copy(to, pos, count);
101101
}
102102

103-
static struct bin_attribute opal_msglog_attr = {
103+
static struct bin_attribute opal_msglog_attr __ro_after_init = {
104104
.attr = {.name = "msglog", .mode = 0400},
105-
.read = opal_msglog_read
105+
.read_new = opal_msglog_read
106106
};
107107

108108
struct memcons *__init memcons_init(struct device_node *node, const char *mc_prop_name)

0 commit comments

Comments
 (0)