Skip to content

Commit 60d360a

Browse files
djbwstellarhopper
authored andcommitted
driver-core: Introduce DEVICE_ATTR_ADMIN_{RO,RW}
A common pattern for using plain DEVICE_ATTR() instead of DEVICE_ATTR_RO() and DEVICE_ATTR_RW() is for attributes that want to limit read to only root. I.e. many users of DEVICE_ATTR() are specifying 0400 or 0600 for permissions. Given the expectation that CAP_SYS_ADMIN is needed to access these sensitive attributes add an explicit helper with the _ADMIN_ identifier for DEVICE_ATTR_ADMIN_{RO,RW}. Cc: "Rafael J. Wysocki" <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Dan Williams <[email protected]> Signed-off-by: Vishal Verma <[email protected]>
1 parent 916566a commit 60d360a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

include/linux/device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
128128
__ATTR_PREALLOC(_name, _mode, _show, _store)
129129
#define DEVICE_ATTR_RW(_name) \
130130
struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
131+
#define DEVICE_ATTR_ADMIN_RW(_name) \
132+
struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600)
131133
#define DEVICE_ATTR_RO(_name) \
132134
struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
135+
#define DEVICE_ATTR_ADMIN_RO(_name) \
136+
struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400)
133137
#define DEVICE_ATTR_WO(_name) \
134138
struct device_attribute dev_attr_##_name = __ATTR_WO(_name)
135139
#define DEVICE_ULONG_ATTR(_name, _mode, _var) \

include/linux/sysfs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ struct attribute_group {
123123
.show = _name##_show, \
124124
}
125125

126+
#define __ATTR_RW_MODE(_name, _mode) { \
127+
.attr = { .name = __stringify(_name), \
128+
.mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
129+
.show = _name##_show, \
130+
.store = _name##_store, \
131+
}
132+
126133
#define __ATTR_WO(_name) { \
127134
.attr = { .name = __stringify(_name), .mode = 0200 }, \
128135
.store = _name##_store, \

0 commit comments

Comments
 (0)