Skip to content

Commit

Permalink
mm/page_idle: constify 'struct bin_attribute'
Browse files Browse the repository at this point in the history
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.

Link: https://lkml.kernel.org/r/20241216-sysfs-const-bin_attr-page_idle-v1-1-cc01ecc55196@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Thomas Weißschuh authored and Andrew Morton committed Jan 26, 2025
1 parent 1fc1065 commit e2c9e61
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mm/page_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void page_idle_clear_pte_refs(struct folio *folio)
}

static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
const struct bin_attribute *attr, char *buf,
loff_t pos, size_t count)
{
u64 *out = (u64 *)buf;
Expand Down Expand Up @@ -157,7 +157,7 @@ static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj,
}

static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
const struct bin_attribute *attr, char *buf,
loff_t pos, size_t count)
{
const u64 *in = (u64 *)buf;
Expand Down Expand Up @@ -193,17 +193,17 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj,
return (char *)in - buf;
}

static struct bin_attribute page_idle_bitmap_attr =
static const struct bin_attribute page_idle_bitmap_attr =
__BIN_ATTR(bitmap, 0600,
page_idle_bitmap_read, page_idle_bitmap_write, 0);

static struct bin_attribute *page_idle_bin_attrs[] = {
static const struct bin_attribute *const page_idle_bin_attrs[] = {
&page_idle_bitmap_attr,
NULL,
};

static const struct attribute_group page_idle_attr_group = {
.bin_attrs = page_idle_bin_attrs,
.bin_attrs_new = page_idle_bin_attrs,
.name = "page_idle",
};

Expand Down

0 comments on commit e2c9e61

Please sign in to comment.