Skip to content

Commit 77977da

Browse files
t-8chAlexander Gordeev
authored andcommitted
s390/ipl: 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]> Acked-by: Alexander Gordeev <[email protected]> Link: https://lore.kernel.org/r/20241211-sysfs-const-bin_attr-s390-v1-2-be01f66bfcf7@weissschuh.net Signed-off-by: Alexander Gordeev <[email protected]>
1 parent 221ce94 commit 77977da

File tree

1 file changed

+71
-71
lines changed

1 file changed

+71
-71
lines changed

arch/s390/kernel/ipl.c

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -280,58 +280,58 @@ static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
280280
sys_##_prefix##_##_name##_show, \
281281
sys_##_prefix##_##_name##_store)
282282

283-
#define IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \
284-
static ssize_t sys_##_prefix##_scp_data_show(struct file *filp, \
285-
struct kobject *kobj, \
286-
struct bin_attribute *attr, \
287-
char *buf, loff_t off, \
288-
size_t count) \
289-
{ \
290-
size_t size = _ipl_block.scp_data_len; \
291-
void *scp_data = _ipl_block.scp_data; \
292-
\
293-
return memory_read_from_buffer(buf, count, &off, \
294-
scp_data, size); \
283+
#define IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \
284+
static ssize_t sys_##_prefix##_scp_data_show(struct file *filp, \
285+
struct kobject *kobj, \
286+
const struct bin_attribute *attr, \
287+
char *buf, loff_t off, \
288+
size_t count) \
289+
{ \
290+
size_t size = _ipl_block.scp_data_len; \
291+
void *scp_data = _ipl_block.scp_data; \
292+
\
293+
return memory_read_from_buffer(buf, count, &off, \
294+
scp_data, size); \
295295
}
296296

297297
#define IPL_ATTR_SCP_DATA_STORE_FN(_prefix, _ipl_block_hdr, _ipl_block, _ipl_bp_len, _ipl_bp0_len)\
298-
static ssize_t sys_##_prefix##_scp_data_store(struct file *filp, \
299-
struct kobject *kobj, \
300-
struct bin_attribute *attr, \
301-
char *buf, loff_t off, \
302-
size_t count) \
303-
{ \
304-
size_t scpdata_len = count; \
305-
size_t padding; \
306-
\
307-
if (off) \
308-
return -EINVAL; \
309-
\
310-
memcpy(_ipl_block.scp_data, buf, count); \
311-
if (scpdata_len % 8) { \
312-
padding = 8 - (scpdata_len % 8); \
313-
memset(_ipl_block.scp_data + scpdata_len, \
314-
0, padding); \
315-
scpdata_len += padding; \
316-
} \
317-
\
318-
_ipl_block_hdr.len = _ipl_bp_len + scpdata_len; \
319-
_ipl_block.len = _ipl_bp0_len + scpdata_len; \
320-
_ipl_block.scp_data_len = scpdata_len; \
321-
\
322-
return count; \
298+
static ssize_t sys_##_prefix##_scp_data_store(struct file *filp, \
299+
struct kobject *kobj, \
300+
const struct bin_attribute *attr, \
301+
char *buf, loff_t off, \
302+
size_t count) \
303+
{ \
304+
size_t scpdata_len = count; \
305+
size_t padding; \
306+
\
307+
if (off) \
308+
return -EINVAL; \
309+
\
310+
memcpy(_ipl_block.scp_data, buf, count); \
311+
if (scpdata_len % 8) { \
312+
padding = 8 - (scpdata_len % 8); \
313+
memset(_ipl_block.scp_data + scpdata_len, \
314+
0, padding); \
315+
scpdata_len += padding; \
316+
} \
317+
\
318+
_ipl_block_hdr.len = _ipl_bp_len + scpdata_len; \
319+
_ipl_block.len = _ipl_bp0_len + scpdata_len; \
320+
_ipl_block.scp_data_len = scpdata_len; \
321+
\
322+
return count; \
323323
}
324324

325325
#define DEFINE_IPL_ATTR_SCP_DATA_RO(_prefix, _ipl_block, _size) \
326326
IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \
327-
static struct bin_attribute sys_##_prefix##_scp_data_attr = \
327+
static const struct bin_attribute sys_##_prefix##_scp_data_attr = \
328328
__BIN_ATTR(scp_data, 0444, sys_##_prefix##_scp_data_show, \
329329
NULL, _size)
330330

331331
#define DEFINE_IPL_ATTR_SCP_DATA_RW(_prefix, _ipl_block_hdr, _ipl_block, _ipl_bp_len, _ipl_bp0_len, _size)\
332332
IPL_ATTR_SCP_DATA_SHOW_FN(_prefix, _ipl_block) \
333333
IPL_ATTR_SCP_DATA_STORE_FN(_prefix, _ipl_block_hdr, _ipl_block, _ipl_bp_len, _ipl_bp0_len)\
334-
static struct bin_attribute sys_##_prefix##_scp_data_attr = \
334+
static const struct bin_attribute sys_##_prefix##_scp_data_attr = \
335335
__BIN_ATTR(scp_data, 0644, sys_##_prefix##_scp_data_show, \
336336
sys_##_prefix##_scp_data_store, _size)
337337

@@ -434,35 +434,35 @@ static struct kobj_attribute sys_ipl_device_attr =
434434
__ATTR(device, 0444, sys_ipl_device_show, NULL);
435435

436436
static ssize_t sys_ipl_parameter_read(struct file *filp, struct kobject *kobj,
437-
struct bin_attribute *attr, char *buf,
437+
const struct bin_attribute *attr, char *buf,
438438
loff_t off, size_t count)
439439
{
440440
return memory_read_from_buffer(buf, count, &off, &ipl_block,
441441
ipl_block.hdr.len);
442442
}
443-
static struct bin_attribute sys_ipl_parameter_attr =
443+
static const struct bin_attribute sys_ipl_parameter_attr =
444444
__BIN_ATTR(binary_parameter, 0444, sys_ipl_parameter_read, NULL,
445445
PAGE_SIZE);
446446

447447
DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_fcp, ipl_block.fcp, PAGE_SIZE);
448448

449-
static struct bin_attribute *ipl_fcp_bin_attrs[] = {
449+
static const struct bin_attribute *const ipl_fcp_bin_attrs[] = {
450450
&sys_ipl_parameter_attr,
451451
&sys_ipl_fcp_scp_data_attr,
452452
NULL,
453453
};
454454

455455
DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_nvme, ipl_block.nvme, PAGE_SIZE);
456456

457-
static struct bin_attribute *ipl_nvme_bin_attrs[] = {
457+
static const struct bin_attribute *const ipl_nvme_bin_attrs[] = {
458458
&sys_ipl_parameter_attr,
459459
&sys_ipl_nvme_scp_data_attr,
460460
NULL,
461461
};
462462

463463
DEFINE_IPL_ATTR_SCP_DATA_RO(ipl_eckd, ipl_block.eckd, PAGE_SIZE);
464464

465-
static struct bin_attribute *ipl_eckd_bin_attrs[] = {
465+
static const struct bin_attribute *const ipl_eckd_bin_attrs[] = {
466466
&sys_ipl_parameter_attr,
467467
&sys_ipl_eckd_scp_data_attr,
468468
NULL,
@@ -593,9 +593,9 @@ static struct attribute *ipl_fcp_attrs[] = {
593593
NULL,
594594
};
595595

596-
static struct attribute_group ipl_fcp_attr_group = {
596+
static const struct attribute_group ipl_fcp_attr_group = {
597597
.attrs = ipl_fcp_attrs,
598-
.bin_attrs = ipl_fcp_bin_attrs,
598+
.bin_attrs_new = ipl_fcp_bin_attrs,
599599
};
600600

601601
static struct attribute *ipl_nvme_attrs[] = {
@@ -607,9 +607,9 @@ static struct attribute *ipl_nvme_attrs[] = {
607607
NULL,
608608
};
609609

610-
static struct attribute_group ipl_nvme_attr_group = {
610+
static const struct attribute_group ipl_nvme_attr_group = {
611611
.attrs = ipl_nvme_attrs,
612-
.bin_attrs = ipl_nvme_bin_attrs,
612+
.bin_attrs_new = ipl_nvme_bin_attrs,
613613
};
614614

615615
static struct attribute *ipl_eckd_attrs[] = {
@@ -620,9 +620,9 @@ static struct attribute *ipl_eckd_attrs[] = {
620620
NULL,
621621
};
622622

623-
static struct attribute_group ipl_eckd_attr_group = {
623+
static const struct attribute_group ipl_eckd_attr_group = {
624624
.attrs = ipl_eckd_attrs,
625-
.bin_attrs = ipl_eckd_bin_attrs,
625+
.bin_attrs_new = ipl_eckd_bin_attrs,
626626
};
627627

628628
/* CCW ipl device attributes */
@@ -640,11 +640,11 @@ static struct attribute *ipl_ccw_attrs_lpar[] = {
640640
NULL,
641641
};
642642

643-
static struct attribute_group ipl_ccw_attr_group_vm = {
643+
static const struct attribute_group ipl_ccw_attr_group_vm = {
644644
.attrs = ipl_ccw_attrs_vm,
645645
};
646646

647-
static struct attribute_group ipl_ccw_attr_group_lpar = {
647+
static const struct attribute_group ipl_ccw_attr_group_lpar = {
648648
.attrs = ipl_ccw_attrs_lpar
649649
};
650650

@@ -655,7 +655,7 @@ static struct attribute *ipl_common_attrs[] = {
655655
NULL,
656656
};
657657

658-
static struct attribute_group ipl_common_attr_group = {
658+
static const struct attribute_group ipl_common_attr_group = {
659659
.attrs = ipl_common_attrs,
660660
};
661661

@@ -808,7 +808,7 @@ DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_fcp, reipl_block_fcp->hdr,
808808
IPL_BP_FCP_LEN, IPL_BP0_FCP_LEN,
809809
DIAG308_SCPDATA_SIZE);
810810

811-
static struct bin_attribute *reipl_fcp_bin_attrs[] = {
811+
static const struct bin_attribute *const reipl_fcp_bin_attrs[] = {
812812
&sys_reipl_fcp_scp_data_attr,
813813
NULL,
814814
};
@@ -917,9 +917,9 @@ static struct attribute *reipl_fcp_attrs[] = {
917917
NULL,
918918
};
919919

920-
static struct attribute_group reipl_fcp_attr_group = {
920+
static const struct attribute_group reipl_fcp_attr_group = {
921921
.attrs = reipl_fcp_attrs,
922-
.bin_attrs = reipl_fcp_bin_attrs,
922+
.bin_attrs_new = reipl_fcp_bin_attrs,
923923
};
924924

925925
static struct kobj_attribute sys_reipl_fcp_clear_attr =
@@ -932,7 +932,7 @@ DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_nvme, reipl_block_nvme->hdr,
932932
IPL_BP_NVME_LEN, IPL_BP0_NVME_LEN,
933933
DIAG308_SCPDATA_SIZE);
934934

935-
static struct bin_attribute *reipl_nvme_bin_attrs[] = {
935+
static const struct bin_attribute *const reipl_nvme_bin_attrs[] = {
936936
&sys_reipl_nvme_scp_data_attr,
937937
NULL,
938938
};
@@ -955,9 +955,9 @@ static struct attribute *reipl_nvme_attrs[] = {
955955
NULL,
956956
};
957957

958-
static struct attribute_group reipl_nvme_attr_group = {
958+
static const struct attribute_group reipl_nvme_attr_group = {
959959
.attrs = reipl_nvme_attrs,
960-
.bin_attrs = reipl_nvme_bin_attrs
960+
.bin_attrs_new = reipl_nvme_bin_attrs
961961
};
962962

963963
static ssize_t reipl_nvme_clear_show(struct kobject *kobj,
@@ -1031,7 +1031,7 @@ DEFINE_IPL_ATTR_SCP_DATA_RW(reipl_eckd, reipl_block_eckd->hdr,
10311031
IPL_BP_ECKD_LEN, IPL_BP0_ECKD_LEN,
10321032
DIAG308_SCPDATA_SIZE);
10331033

1034-
static struct bin_attribute *reipl_eckd_bin_attrs[] = {
1034+
static const struct bin_attribute *const reipl_eckd_bin_attrs[] = {
10351035
&sys_reipl_eckd_scp_data_attr,
10361036
NULL,
10371037
};
@@ -1048,9 +1048,9 @@ static struct attribute *reipl_eckd_attrs[] = {
10481048
NULL,
10491049
};
10501050

1051-
static struct attribute_group reipl_eckd_attr_group = {
1051+
static const struct attribute_group reipl_eckd_attr_group = {
10521052
.attrs = reipl_eckd_attrs,
1053-
.bin_attrs = reipl_eckd_bin_attrs
1053+
.bin_attrs_new = reipl_eckd_bin_attrs
10541054
};
10551055

10561056
static ssize_t reipl_eckd_clear_show(struct kobject *kobj,
@@ -1587,15 +1587,15 @@ static struct attribute *dump_fcp_attrs[] = {
15871587
NULL,
15881588
};
15891589

1590-
static struct bin_attribute *dump_fcp_bin_attrs[] = {
1590+
static const struct bin_attribute *const dump_fcp_bin_attrs[] = {
15911591
&sys_dump_fcp_scp_data_attr,
15921592
NULL,
15931593
};
15941594

1595-
static struct attribute_group dump_fcp_attr_group = {
1595+
static const struct attribute_group dump_fcp_attr_group = {
15961596
.name = IPL_FCP_STR,
15971597
.attrs = dump_fcp_attrs,
1598-
.bin_attrs = dump_fcp_bin_attrs,
1598+
.bin_attrs_new = dump_fcp_bin_attrs,
15991599
};
16001600

16011601
/* NVME dump device attributes */
@@ -1621,15 +1621,15 @@ static struct attribute *dump_nvme_attrs[] = {
16211621
NULL,
16221622
};
16231623

1624-
static struct bin_attribute *dump_nvme_bin_attrs[] = {
1624+
static const struct bin_attribute *const dump_nvme_bin_attrs[] = {
16251625
&sys_dump_nvme_scp_data_attr,
16261626
NULL,
16271627
};
16281628

1629-
static struct attribute_group dump_nvme_attr_group = {
1629+
static const struct attribute_group dump_nvme_attr_group = {
16301630
.name = IPL_NVME_STR,
16311631
.attrs = dump_nvme_attrs,
1632-
.bin_attrs = dump_nvme_bin_attrs,
1632+
.bin_attrs_new = dump_nvme_bin_attrs,
16331633
};
16341634

16351635
/* ECKD dump device attributes */
@@ -1655,15 +1655,15 @@ static struct attribute *dump_eckd_attrs[] = {
16551655
NULL,
16561656
};
16571657

1658-
static struct bin_attribute *dump_eckd_bin_attrs[] = {
1658+
static const struct bin_attribute *const dump_eckd_bin_attrs[] = {
16591659
&sys_dump_eckd_scp_data_attr,
16601660
NULL,
16611661
};
16621662

1663-
static struct attribute_group dump_eckd_attr_group = {
1663+
static const struct attribute_group dump_eckd_attr_group = {
16641664
.name = IPL_ECKD_STR,
16651665
.attrs = dump_eckd_attrs,
1666-
.bin_attrs = dump_eckd_bin_attrs,
1666+
.bin_attrs_new = dump_eckd_bin_attrs,
16671667
};
16681668

16691669
/* CCW dump device attributes */

0 commit comments

Comments
 (0)