Skip to content

Commit 221ce94

Browse files
t-8chAlexander Gordeev
authored andcommitted
s390/crypto/cpacf: 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]> Tested-by: Finn Callies <[email protected]> Reviewed-by: Holger Dengler <[email protected]> Link: https://lore.kernel.org/r/20241211-sysfs-const-bin_attr-s390-v1-1-be01f66bfcf7@weissschuh.net Signed-off-by: Alexander Gordeev <[email protected]>
1 parent 30e037a commit 221ce94

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

arch/s390/kernel/cpacf.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define CPACF_QUERY(name, instruction) \
1515
static ssize_t name##_query_raw_read(struct file *fp, \
1616
struct kobject *kobj, \
17-
struct bin_attribute *attr, \
17+
const struct bin_attribute *attr, \
1818
char *buf, loff_t offs, \
1919
size_t count) \
2020
{ \
@@ -24,7 +24,7 @@ static ssize_t name##_query_raw_read(struct file *fp, \
2424
return -EOPNOTSUPP; \
2525
return memory_read_from_buffer(buf, count, &offs, &mask, sizeof(mask)); \
2626
} \
27-
static BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t))
27+
static const BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t))
2828

2929
CPACF_QUERY(km, KM);
3030
CPACF_QUERY(kmc, KMC);
@@ -40,20 +40,20 @@ CPACF_QUERY(prno, PRNO);
4040
CPACF_QUERY(kma, KMA);
4141
CPACF_QUERY(kdsa, KDSA);
4242

43-
#define CPACF_QAI(name, instruction) \
44-
static ssize_t name##_query_auth_info_raw_read( \
45-
struct file *fp, struct kobject *kobj, \
46-
struct bin_attribute *attr, char *buf, loff_t offs, \
47-
size_t count) \
48-
{ \
49-
cpacf_qai_t qai; \
50-
\
51-
if (!cpacf_qai(CPACF_##instruction, &qai)) \
52-
return -EOPNOTSUPP; \
53-
return memory_read_from_buffer(buf, count, &offs, &qai, \
54-
sizeof(qai)); \
55-
} \
56-
static BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t))
43+
#define CPACF_QAI(name, instruction) \
44+
static ssize_t name##_query_auth_info_raw_read( \
45+
struct file *fp, struct kobject *kobj, \
46+
const struct bin_attribute *attr, char *buf, loff_t offs, \
47+
size_t count) \
48+
{ \
49+
cpacf_qai_t qai; \
50+
\
51+
if (!cpacf_qai(CPACF_##instruction, &qai)) \
52+
return -EOPNOTSUPP; \
53+
return memory_read_from_buffer(buf, count, &offs, &qai, \
54+
sizeof(qai)); \
55+
} \
56+
static const BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t))
5757

5858
CPACF_QAI(km, KM);
5959
CPACF_QAI(kmc, KMC);
@@ -69,7 +69,7 @@ CPACF_QAI(prno, PRNO);
6969
CPACF_QAI(kma, KMA);
7070
CPACF_QAI(kdsa, KDSA);
7171

72-
static struct bin_attribute *cpacf_attrs[] = {
72+
static const struct bin_attribute *const cpacf_attrs[] = {
7373
&bin_attr_km_query_raw,
7474
&bin_attr_kmc_query_raw,
7575
&bin_attr_kimd_query_raw,
@@ -101,7 +101,7 @@ static struct bin_attribute *cpacf_attrs[] = {
101101

102102
static const struct attribute_group cpacf_attr_grp = {
103103
.name = "cpacf",
104-
.bin_attrs = cpacf_attrs,
104+
.bin_attrs_new = cpacf_attrs,
105105
};
106106

107107
static int __init cpacf_init(void)

0 commit comments

Comments
 (0)