From: Greg Kroah-Hartman Date: Tue, 18 Apr 2023 13:47:15 +0000 (+0200) Subject: zram: fix up permission for the hot_add sysfs file X-Git-Tag: v6.6.17~5001^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca9d081b49cc225627aa73feb9284b7ffc190df5;p=platform%2Fkernel%2Flinux-rpi.git zram: fix up permission for the hot_add sysfs file Commit 75a2d4226b53 ("driver core: class: mark the struct class for sysfs callbacks as constant") changed the attribute to use CLASS_ATTR_RO() which changed the permission from 0400 to 0444. But this atribute is "special" in that reading it modifies the system state, so it MUST be set to 0400 so that only root processes can muck around with it. Fix this all up, AND document this so that I don't change it again in 3-4 years when I stumble across it and wonder why it's an open-coded _ATTR() macro. Reported-by: Denis Efremov Fixes: 75a2d4226b53 ("driver core: class: mark the struct class for sysfs callbacks as constant") Link: https://lore.kernel.org/r/2023041810-angelic-conical-52d8@gregkh Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 3feadfb..d821752 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -2438,7 +2438,9 @@ static ssize_t hot_add_show(const struct class *class, return ret; return scnprintf(buf, PAGE_SIZE, "%d\n", ret); } -static CLASS_ATTR_RO(hot_add); +/* This attribute must be set to 0400, so CLASS_ATTR_RO() can not be used */ +static struct class_attribute class_attr_hot_add = + __ATTR(hot_add, 0400, hot_add_show, NULL); static ssize_t hot_remove_store(const struct class *class, const struct class_attribute *attr,