s390/crypto/cpacf: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 11 Dec 2024 17:54:39 +0000 (18:54 +0100)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Tue, 7 Jan 2025 09:05:35 +0000 (10:05 +0100)
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 <linux@weissschuh.net>
Tested-by: Finn Callies <fcallies@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Link: https://lore.kernel.org/r/20241211-sysfs-const-bin_attr-s390-v1-1-be01f66bfcf7@weissschuh.net
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/kernel/cpacf.c

index c8575dbc890d64a5fcdcbd7a1a18215e2158c6e3..4b9b34f95d729806d416279b93ccb5a20e4406a7 100644 (file)
@@ -14,7 +14,7 @@
 #define CPACF_QUERY(name, instruction)                                         \
 static ssize_t name##_query_raw_read(struct file *fp,                          \
                                     struct kobject *kobj,                      \
-                                    struct bin_attribute *attr,                \
+                                    const struct bin_attribute *attr,          \
                                     char *buf, loff_t offs,                    \
                                     size_t count)                              \
 {                                                                              \
@@ -24,7 +24,7 @@ static ssize_t name##_query_raw_read(struct file *fp,                         \
                return -EOPNOTSUPP;                                             \
        return memory_read_from_buffer(buf, count, &offs, &mask, sizeof(mask)); \
 }                                                                              \
-static BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t))
+static const BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t))
 
 CPACF_QUERY(km, KM);
 CPACF_QUERY(kmc, KMC);
@@ -40,20 +40,20 @@ CPACF_QUERY(prno, PRNO);
 CPACF_QUERY(kma, KMA);
 CPACF_QUERY(kdsa, KDSA);
 
-#define CPACF_QAI(name, instruction)                           \
-static ssize_t name##_query_auth_info_raw_read(                        \
-       struct file *fp, struct kobject *kobj,                  \
-       struct bin_attribute *attr, char *buf, loff_t offs,     \
-       size_t count)                                           \
-{                                                              \
-       cpacf_qai_t qai;                                        \
-                                                               \
-       if (!cpacf_qai(CPACF_##instruction, &qai))              \
-               return -EOPNOTSUPP;                             \
-       return memory_read_from_buffer(buf, count, &offs, &qai, \
-                                       sizeof(qai));           \
-}                                                              \
-static BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t))
+#define CPACF_QAI(name, instruction)                                   \
+static ssize_t name##_query_auth_info_raw_read(                                \
+       struct file *fp, struct kobject *kobj,                          \
+       const struct bin_attribute *attr, char *buf, loff_t offs,       \
+       size_t count)                                                   \
+{                                                                      \
+       cpacf_qai_t qai;                                                \
+                                                                       \
+       if (!cpacf_qai(CPACF_##instruction, &qai))                      \
+               return -EOPNOTSUPP;                                     \
+       return memory_read_from_buffer(buf, count, &offs, &qai,         \
+                                       sizeof(qai));                   \
+}                                                                      \
+static const BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t))
 
 CPACF_QAI(km, KM);
 CPACF_QAI(kmc, KMC);
@@ -69,7 +69,7 @@ CPACF_QAI(prno, PRNO);
 CPACF_QAI(kma, KMA);
 CPACF_QAI(kdsa, KDSA);
 
-static struct bin_attribute *cpacf_attrs[] = {
+static const struct bin_attribute *const cpacf_attrs[] = {
        &bin_attr_km_query_raw,
        &bin_attr_kmc_query_raw,
        &bin_attr_kimd_query_raw,
@@ -101,7 +101,7 @@ static struct bin_attribute *cpacf_attrs[] = {
 
 static const struct attribute_group cpacf_attr_grp = {
        .name = "cpacf",
-       .bin_attrs = cpacf_attrs,
+       .bin_attrs_new = cpacf_attrs,
 };
 
 static int __init cpacf_init(void)