Skip to content

Commit d1aa46c

Browse files
t-8chAlexander Gordeev
authored andcommitted
s390/pkey: 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: Holger Dengler <[email protected]> Reviewed-by: Holger Dengler <[email protected]> Link: https://lore.kernel.org/r/20241211-sysfs-const-bin_attr-s390-v1-5-be01f66bfcf7@weissschuh.net Signed-off-by: Alexander Gordeev <[email protected]>
1 parent 81ad38a commit d1aa46c

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

drivers/s390/crypto/pkey_sysfs.c

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static ssize_t pkey_protkey_hmac_attr_read(u32 keytype, char *buf,
184184

185185
static ssize_t protkey_aes_128_read(struct file *filp,
186186
struct kobject *kobj,
187-
struct bin_attribute *attr,
187+
const struct bin_attribute *attr,
188188
char *buf, loff_t off,
189189
size_t count)
190190
{
@@ -194,7 +194,7 @@ static ssize_t protkey_aes_128_read(struct file *filp,
194194

195195
static ssize_t protkey_aes_192_read(struct file *filp,
196196
struct kobject *kobj,
197-
struct bin_attribute *attr,
197+
const struct bin_attribute *attr,
198198
char *buf, loff_t off,
199199
size_t count)
200200
{
@@ -204,7 +204,7 @@ static ssize_t protkey_aes_192_read(struct file *filp,
204204

205205
static ssize_t protkey_aes_256_read(struct file *filp,
206206
struct kobject *kobj,
207-
struct bin_attribute *attr,
207+
const struct bin_attribute *attr,
208208
char *buf, loff_t off,
209209
size_t count)
210210
{
@@ -214,7 +214,7 @@ static ssize_t protkey_aes_256_read(struct file *filp,
214214

215215
static ssize_t protkey_aes_128_xts_read(struct file *filp,
216216
struct kobject *kobj,
217-
struct bin_attribute *attr,
217+
const struct bin_attribute *attr,
218218
char *buf, loff_t off,
219219
size_t count)
220220
{
@@ -224,7 +224,7 @@ static ssize_t protkey_aes_128_xts_read(struct file *filp,
224224

225225
static ssize_t protkey_aes_256_xts_read(struct file *filp,
226226
struct kobject *kobj,
227-
struct bin_attribute *attr,
227+
const struct bin_attribute *attr,
228228
char *buf, loff_t off,
229229
size_t count)
230230
{
@@ -234,7 +234,7 @@ static ssize_t protkey_aes_256_xts_read(struct file *filp,
234234

235235
static ssize_t protkey_aes_xts_128_read(struct file *filp,
236236
struct kobject *kobj,
237-
struct bin_attribute *attr,
237+
const struct bin_attribute *attr,
238238
char *buf, loff_t off,
239239
size_t count)
240240
{
@@ -244,7 +244,7 @@ static ssize_t protkey_aes_xts_128_read(struct file *filp,
244244

245245
static ssize_t protkey_aes_xts_256_read(struct file *filp,
246246
struct kobject *kobj,
247-
struct bin_attribute *attr,
247+
const struct bin_attribute *attr,
248248
char *buf, loff_t off,
249249
size_t count)
250250
{
@@ -254,7 +254,7 @@ static ssize_t protkey_aes_xts_256_read(struct file *filp,
254254

255255
static ssize_t protkey_hmac_512_read(struct file *filp,
256256
struct kobject *kobj,
257-
struct bin_attribute *attr,
257+
const struct bin_attribute *attr,
258258
char *buf, loff_t off,
259259
size_t count)
260260
{
@@ -264,25 +264,25 @@ static ssize_t protkey_hmac_512_read(struct file *filp,
264264

265265
static ssize_t protkey_hmac_1024_read(struct file *filp,
266266
struct kobject *kobj,
267-
struct bin_attribute *attr,
267+
const struct bin_attribute *attr,
268268
char *buf, loff_t off,
269269
size_t count)
270270
{
271271
return pkey_protkey_hmac_attr_read(PKEY_KEYTYPE_HMAC_1024,
272272
buf, off, count);
273273
}
274274

275-
static BIN_ATTR_RO(protkey_aes_128, sizeof(struct protaeskeytoken));
276-
static BIN_ATTR_RO(protkey_aes_192, sizeof(struct protaeskeytoken));
277-
static BIN_ATTR_RO(protkey_aes_256, sizeof(struct protaeskeytoken));
278-
static BIN_ATTR_RO(protkey_aes_128_xts, 2 * sizeof(struct protaeskeytoken));
279-
static BIN_ATTR_RO(protkey_aes_256_xts, 2 * sizeof(struct protaeskeytoken));
280-
static BIN_ATTR_RO(protkey_aes_xts_128, sizeof(struct protkeytoken) + 64);
281-
static BIN_ATTR_RO(protkey_aes_xts_256, sizeof(struct protkeytoken) + 96);
282-
static BIN_ATTR_RO(protkey_hmac_512, sizeof(struct protkeytoken) + 96);
283-
static BIN_ATTR_RO(protkey_hmac_1024, sizeof(struct protkeytoken) + 160);
284-
285-
static struct bin_attribute *protkey_attrs[] = {
275+
static const BIN_ATTR_RO(protkey_aes_128, sizeof(struct protaeskeytoken));
276+
static const BIN_ATTR_RO(protkey_aes_192, sizeof(struct protaeskeytoken));
277+
static const BIN_ATTR_RO(protkey_aes_256, sizeof(struct protaeskeytoken));
278+
static const BIN_ATTR_RO(protkey_aes_128_xts, 2 * sizeof(struct protaeskeytoken));
279+
static const BIN_ATTR_RO(protkey_aes_256_xts, 2 * sizeof(struct protaeskeytoken));
280+
static const BIN_ATTR_RO(protkey_aes_xts_128, sizeof(struct protkeytoken) + 64);
281+
static const BIN_ATTR_RO(protkey_aes_xts_256, sizeof(struct protkeytoken) + 96);
282+
static const BIN_ATTR_RO(protkey_hmac_512, sizeof(struct protkeytoken) + 96);
283+
static const BIN_ATTR_RO(protkey_hmac_1024, sizeof(struct protkeytoken) + 160);
284+
285+
static const struct bin_attribute *const protkey_attrs[] = {
286286
&bin_attr_protkey_aes_128,
287287
&bin_attr_protkey_aes_192,
288288
&bin_attr_protkey_aes_256,
@@ -295,9 +295,9 @@ static struct bin_attribute *protkey_attrs[] = {
295295
NULL
296296
};
297297

298-
static struct attribute_group protkey_attr_group = {
299-
.name = "protkey",
300-
.bin_attrs = protkey_attrs,
298+
static const struct attribute_group protkey_attr_group = {
299+
.name = "protkey",
300+
.bin_attrs_new = protkey_attrs,
301301
};
302302

303303
/*
@@ -341,7 +341,7 @@ static ssize_t pkey_ccadata_aes_attr_read(u32 keytype, bool is_xts, char *buf,
341341

342342
static ssize_t ccadata_aes_128_read(struct file *filp,
343343
struct kobject *kobj,
344-
struct bin_attribute *attr,
344+
const struct bin_attribute *attr,
345345
char *buf, loff_t off,
346346
size_t count)
347347
{
@@ -351,7 +351,7 @@ static ssize_t ccadata_aes_128_read(struct file *filp,
351351

352352
static ssize_t ccadata_aes_192_read(struct file *filp,
353353
struct kobject *kobj,
354-
struct bin_attribute *attr,
354+
const struct bin_attribute *attr,
355355
char *buf, loff_t off,
356356
size_t count)
357357
{
@@ -361,7 +361,7 @@ static ssize_t ccadata_aes_192_read(struct file *filp,
361361

362362
static ssize_t ccadata_aes_256_read(struct file *filp,
363363
struct kobject *kobj,
364-
struct bin_attribute *attr,
364+
const struct bin_attribute *attr,
365365
char *buf, loff_t off,
366366
size_t count)
367367
{
@@ -371,7 +371,7 @@ static ssize_t ccadata_aes_256_read(struct file *filp,
371371

372372
static ssize_t ccadata_aes_128_xts_read(struct file *filp,
373373
struct kobject *kobj,
374-
struct bin_attribute *attr,
374+
const struct bin_attribute *attr,
375375
char *buf, loff_t off,
376376
size_t count)
377377
{
@@ -381,21 +381,21 @@ static ssize_t ccadata_aes_128_xts_read(struct file *filp,
381381

382382
static ssize_t ccadata_aes_256_xts_read(struct file *filp,
383383
struct kobject *kobj,
384-
struct bin_attribute *attr,
384+
const struct bin_attribute *attr,
385385
char *buf, loff_t off,
386386
size_t count)
387387
{
388388
return pkey_ccadata_aes_attr_read(PKEY_KEYTYPE_AES_256, true, buf,
389389
off, count);
390390
}
391391

392-
static BIN_ATTR_RO(ccadata_aes_128, sizeof(struct secaeskeytoken));
393-
static BIN_ATTR_RO(ccadata_aes_192, sizeof(struct secaeskeytoken));
394-
static BIN_ATTR_RO(ccadata_aes_256, sizeof(struct secaeskeytoken));
395-
static BIN_ATTR_RO(ccadata_aes_128_xts, 2 * sizeof(struct secaeskeytoken));
396-
static BIN_ATTR_RO(ccadata_aes_256_xts, 2 * sizeof(struct secaeskeytoken));
392+
static const BIN_ATTR_RO(ccadata_aes_128, sizeof(struct secaeskeytoken));
393+
static const BIN_ATTR_RO(ccadata_aes_192, sizeof(struct secaeskeytoken));
394+
static const BIN_ATTR_RO(ccadata_aes_256, sizeof(struct secaeskeytoken));
395+
static const BIN_ATTR_RO(ccadata_aes_128_xts, 2 * sizeof(struct secaeskeytoken));
396+
static const BIN_ATTR_RO(ccadata_aes_256_xts, 2 * sizeof(struct secaeskeytoken));
397397

398-
static struct bin_attribute *ccadata_attrs[] = {
398+
static const struct bin_attribute *const ccadata_attrs[] = {
399399
&bin_attr_ccadata_aes_128,
400400
&bin_attr_ccadata_aes_192,
401401
&bin_attr_ccadata_aes_256,
@@ -404,9 +404,9 @@ static struct bin_attribute *ccadata_attrs[] = {
404404
NULL
405405
};
406406

407-
static struct attribute_group ccadata_attr_group = {
408-
.name = "ccadata",
409-
.bin_attrs = ccadata_attrs,
407+
static const struct attribute_group ccadata_attr_group = {
408+
.name = "ccadata",
409+
.bin_attrs_new = ccadata_attrs,
410410
};
411411

412412
#define CCACIPHERTOKENSIZE (sizeof(struct cipherkeytoken) + 80)
@@ -455,7 +455,7 @@ static ssize_t pkey_ccacipher_aes_attr_read(enum pkey_key_size keybits,
455455

456456
static ssize_t ccacipher_aes_128_read(struct file *filp,
457457
struct kobject *kobj,
458-
struct bin_attribute *attr,
458+
const struct bin_attribute *attr,
459459
char *buf, loff_t off,
460460
size_t count)
461461
{
@@ -465,7 +465,7 @@ static ssize_t ccacipher_aes_128_read(struct file *filp,
465465

466466
static ssize_t ccacipher_aes_192_read(struct file *filp,
467467
struct kobject *kobj,
468-
struct bin_attribute *attr,
468+
const struct bin_attribute *attr,
469469
char *buf, loff_t off,
470470
size_t count)
471471
{
@@ -475,7 +475,7 @@ static ssize_t ccacipher_aes_192_read(struct file *filp,
475475

476476
static ssize_t ccacipher_aes_256_read(struct file *filp,
477477
struct kobject *kobj,
478-
struct bin_attribute *attr,
478+
const struct bin_attribute *attr,
479479
char *buf, loff_t off,
480480
size_t count)
481481
{
@@ -485,7 +485,7 @@ static ssize_t ccacipher_aes_256_read(struct file *filp,
485485

486486
static ssize_t ccacipher_aes_128_xts_read(struct file *filp,
487487
struct kobject *kobj,
488-
struct bin_attribute *attr,
488+
const struct bin_attribute *attr,
489489
char *buf, loff_t off,
490490
size_t count)
491491
{
@@ -495,21 +495,21 @@ static ssize_t ccacipher_aes_128_xts_read(struct file *filp,
495495

496496
static ssize_t ccacipher_aes_256_xts_read(struct file *filp,
497497
struct kobject *kobj,
498-
struct bin_attribute *attr,
498+
const struct bin_attribute *attr,
499499
char *buf, loff_t off,
500500
size_t count)
501501
{
502502
return pkey_ccacipher_aes_attr_read(PKEY_SIZE_AES_256, true, buf,
503503
off, count);
504504
}
505505

506-
static BIN_ATTR_RO(ccacipher_aes_128, CCACIPHERTOKENSIZE);
507-
static BIN_ATTR_RO(ccacipher_aes_192, CCACIPHERTOKENSIZE);
508-
static BIN_ATTR_RO(ccacipher_aes_256, CCACIPHERTOKENSIZE);
509-
static BIN_ATTR_RO(ccacipher_aes_128_xts, 2 * CCACIPHERTOKENSIZE);
510-
static BIN_ATTR_RO(ccacipher_aes_256_xts, 2 * CCACIPHERTOKENSIZE);
506+
static const BIN_ATTR_RO(ccacipher_aes_128, CCACIPHERTOKENSIZE);
507+
static const BIN_ATTR_RO(ccacipher_aes_192, CCACIPHERTOKENSIZE);
508+
static const BIN_ATTR_RO(ccacipher_aes_256, CCACIPHERTOKENSIZE);
509+
static const BIN_ATTR_RO(ccacipher_aes_128_xts, 2 * CCACIPHERTOKENSIZE);
510+
static const BIN_ATTR_RO(ccacipher_aes_256_xts, 2 * CCACIPHERTOKENSIZE);
511511

512-
static struct bin_attribute *ccacipher_attrs[] = {
512+
static const struct bin_attribute *const ccacipher_attrs[] = {
513513
&bin_attr_ccacipher_aes_128,
514514
&bin_attr_ccacipher_aes_192,
515515
&bin_attr_ccacipher_aes_256,
@@ -518,9 +518,9 @@ static struct bin_attribute *ccacipher_attrs[] = {
518518
NULL
519519
};
520520

521-
static struct attribute_group ccacipher_attr_group = {
522-
.name = "ccacipher",
523-
.bin_attrs = ccacipher_attrs,
521+
static const struct attribute_group ccacipher_attr_group = {
522+
.name = "ccacipher",
523+
.bin_attrs_new = ccacipher_attrs,
524524
};
525525

526526
/*
@@ -570,7 +570,7 @@ static ssize_t pkey_ep11_aes_attr_read(enum pkey_key_size keybits,
570570

571571
static ssize_t ep11_aes_128_read(struct file *filp,
572572
struct kobject *kobj,
573-
struct bin_attribute *attr,
573+
const struct bin_attribute *attr,
574574
char *buf, loff_t off,
575575
size_t count)
576576
{
@@ -580,7 +580,7 @@ static ssize_t ep11_aes_128_read(struct file *filp,
580580

581581
static ssize_t ep11_aes_192_read(struct file *filp,
582582
struct kobject *kobj,
583-
struct bin_attribute *attr,
583+
const struct bin_attribute *attr,
584584
char *buf, loff_t off,
585585
size_t count)
586586
{
@@ -590,7 +590,7 @@ static ssize_t ep11_aes_192_read(struct file *filp,
590590

591591
static ssize_t ep11_aes_256_read(struct file *filp,
592592
struct kobject *kobj,
593-
struct bin_attribute *attr,
593+
const struct bin_attribute *attr,
594594
char *buf, loff_t off,
595595
size_t count)
596596
{
@@ -600,7 +600,7 @@ static ssize_t ep11_aes_256_read(struct file *filp,
600600

601601
static ssize_t ep11_aes_128_xts_read(struct file *filp,
602602
struct kobject *kobj,
603-
struct bin_attribute *attr,
603+
const struct bin_attribute *attr,
604604
char *buf, loff_t off,
605605
size_t count)
606606
{
@@ -610,21 +610,21 @@ static ssize_t ep11_aes_128_xts_read(struct file *filp,
610610

611611
static ssize_t ep11_aes_256_xts_read(struct file *filp,
612612
struct kobject *kobj,
613-
struct bin_attribute *attr,
613+
const struct bin_attribute *attr,
614614
char *buf, loff_t off,
615615
size_t count)
616616
{
617617
return pkey_ep11_aes_attr_read(PKEY_SIZE_AES_256, true, buf,
618618
off, count);
619619
}
620620

621-
static BIN_ATTR_RO(ep11_aes_128, MAXEP11AESKEYBLOBSIZE);
622-
static BIN_ATTR_RO(ep11_aes_192, MAXEP11AESKEYBLOBSIZE);
623-
static BIN_ATTR_RO(ep11_aes_256, MAXEP11AESKEYBLOBSIZE);
624-
static BIN_ATTR_RO(ep11_aes_128_xts, 2 * MAXEP11AESKEYBLOBSIZE);
625-
static BIN_ATTR_RO(ep11_aes_256_xts, 2 * MAXEP11AESKEYBLOBSIZE);
621+
static const BIN_ATTR_RO(ep11_aes_128, MAXEP11AESKEYBLOBSIZE);
622+
static const BIN_ATTR_RO(ep11_aes_192, MAXEP11AESKEYBLOBSIZE);
623+
static const BIN_ATTR_RO(ep11_aes_256, MAXEP11AESKEYBLOBSIZE);
624+
static const BIN_ATTR_RO(ep11_aes_128_xts, 2 * MAXEP11AESKEYBLOBSIZE);
625+
static const BIN_ATTR_RO(ep11_aes_256_xts, 2 * MAXEP11AESKEYBLOBSIZE);
626626

627-
static struct bin_attribute *ep11_attrs[] = {
627+
static const struct bin_attribute *const ep11_attrs[] = {
628628
&bin_attr_ep11_aes_128,
629629
&bin_attr_ep11_aes_192,
630630
&bin_attr_ep11_aes_256,
@@ -633,9 +633,9 @@ static struct bin_attribute *ep11_attrs[] = {
633633
NULL
634634
};
635635

636-
static struct attribute_group ep11_attr_group = {
636+
static const struct attribute_group ep11_attr_group = {
637637
.name = "ep11",
638-
.bin_attrs = ep11_attrs,
638+
.bin_attrs_new = ep11_attrs,
639639
};
640640

641641
const struct attribute_group *pkey_attr_groups[] = {

0 commit comments

Comments
 (0)