hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/security/tomoyo/file.c
....@@ -214,6 +214,7 @@
214214 const u8 type = r->param.path_number.operation;
215215 u8 radix;
216216 char buffer[64];
217
+
217218 switch (type) {
218219 case TOMOYO_TYPE_CREATE:
219220 case TOMOYO_TYPE_MKDIR:
....@@ -253,6 +254,7 @@
253254 {
254255 const struct tomoyo_path_acl *acl = container_of(ptr, typeof(*acl),
255256 head);
257
+
256258 if (acl->perm & (1 << r->param.path.operation)) {
257259 r->param.path.matched_path =
258260 tomoyo_compare_name_union(r->param.path.filename,
....@@ -275,6 +277,7 @@
275277 {
276278 const struct tomoyo_path_number_acl *acl =
277279 container_of(ptr, typeof(*acl), head);
280
+
278281 return (acl->perm & (1 << r->param.path_number.operation)) &&
279282 tomoyo_compare_number_union(r->param.path_number.number,
280283 &acl->number) &&
....@@ -295,6 +298,7 @@
295298 {
296299 const struct tomoyo_path2_acl *acl =
297300 container_of(ptr, typeof(*acl), head);
301
+
298302 return (acl->perm & (1 << r->param.path2.operation)) &&
299303 tomoyo_compare_name_union(r->param.path2.filename1, &acl->name1)
300304 && tomoyo_compare_name_union(r->param.path2.filename2,
....@@ -314,6 +318,7 @@
314318 {
315319 const struct tomoyo_mkdev_acl *acl =
316320 container_of(ptr, typeof(*acl), head);
321
+
317322 return (acl->perm & (1 << r->param.mkdev.operation)) &&
318323 tomoyo_compare_number_union(r->param.mkdev.mode,
319324 &acl->mode) &&
....@@ -338,6 +343,7 @@
338343 {
339344 const struct tomoyo_path_acl *p1 = container_of(a, typeof(*p1), head);
340345 const struct tomoyo_path_acl *p2 = container_of(b, typeof(*p2), head);
346
+
341347 return tomoyo_same_name_union(&p1->name, &p2->name);
342348 }
343349
....@@ -356,13 +362,14 @@
356362 {
357363 u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head)
358364 ->perm;
359
- u16 perm = *a_perm;
365
+ u16 perm = READ_ONCE(*a_perm);
360366 const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm;
367
+
361368 if (is_delete)
362369 perm &= ~b_perm;
363370 else
364371 perm |= b_perm;
365
- *a_perm = perm;
372
+ WRITE_ONCE(*a_perm, perm);
366373 return !perm;
367374 }
368375
....@@ -384,6 +391,7 @@
384391 .perm = perm
385392 };
386393 int error;
394
+
387395 if (!tomoyo_parse_name_union(param, &e.name))
388396 error = -EINVAL;
389397 else
....@@ -407,6 +415,7 @@
407415 {
408416 const struct tomoyo_mkdev_acl *p1 = container_of(a, typeof(*p1), head);
409417 const struct tomoyo_mkdev_acl *p2 = container_of(b, typeof(*p2), head);
418
+
410419 return tomoyo_same_name_union(&p1->name, &p2->name) &&
411420 tomoyo_same_number_union(&p1->mode, &p2->mode) &&
412421 tomoyo_same_number_union(&p1->major, &p2->major) &&
....@@ -428,14 +437,15 @@
428437 {
429438 u8 *const a_perm = &container_of(a, struct tomoyo_mkdev_acl,
430439 head)->perm;
431
- u8 perm = *a_perm;
440
+ u8 perm = READ_ONCE(*a_perm);
432441 const u8 b_perm = container_of(b, struct tomoyo_mkdev_acl, head)
433442 ->perm;
443
+
434444 if (is_delete)
435445 perm &= ~b_perm;
436446 else
437447 perm |= b_perm;
438
- *a_perm = perm;
448
+ WRITE_ONCE(*a_perm, perm);
439449 return !perm;
440450 }
441451
....@@ -457,6 +467,7 @@
457467 .perm = perm
458468 };
459469 int error;
470
+
460471 if (!tomoyo_parse_name_union(param, &e.name) ||
461472 !tomoyo_parse_number_union(param, &e.mode) ||
462473 !tomoyo_parse_number_union(param, &e.major) ||
....@@ -486,6 +497,7 @@
486497 {
487498 const struct tomoyo_path2_acl *p1 = container_of(a, typeof(*p1), head);
488499 const struct tomoyo_path2_acl *p2 = container_of(b, typeof(*p2), head);
500
+
489501 return tomoyo_same_name_union(&p1->name1, &p2->name1) &&
490502 tomoyo_same_name_union(&p1->name2, &p2->name2);
491503 }
....@@ -505,13 +517,14 @@
505517 {
506518 u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head)
507519 ->perm;
508
- u8 perm = *a_perm;
520
+ u8 perm = READ_ONCE(*a_perm);
509521 const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm;
522
+
510523 if (is_delete)
511524 perm &= ~b_perm;
512525 else
513526 perm |= b_perm;
514
- *a_perm = perm;
527
+ WRITE_ONCE(*a_perm, perm);
515528 return !perm;
516529 }
517530
....@@ -533,6 +546,7 @@
533546 .perm = perm
534547 };
535548 int error;
549
+
536550 if (!tomoyo_parse_name_union(param, &e.name1) ||
537551 !tomoyo_parse_name_union(param, &e.name2))
538552 error = -EINVAL;
....@@ -621,6 +635,7 @@
621635 head);
622636 const struct tomoyo_path_number_acl *p2 = container_of(b, typeof(*p2),
623637 head);
638
+
624639 return tomoyo_same_name_union(&p1->name, &p2->name) &&
625640 tomoyo_same_number_union(&p1->number, &p2->number);
626641 }
....@@ -640,14 +655,15 @@
640655 {
641656 u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl,
642657 head)->perm;
643
- u8 perm = *a_perm;
658
+ u8 perm = READ_ONCE(*a_perm);
644659 const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head)
645660 ->perm;
661
+
646662 if (is_delete)
647663 perm &= ~b_perm;
648664 else
649665 perm |= b_perm;
650
- *a_perm = perm;
666
+ WRITE_ONCE(*a_perm, perm);
651667 return !perm;
652668 }
653669
....@@ -667,6 +683,7 @@
667683 .perm = perm
668684 };
669685 int error;
686
+
670687 if (!tomoyo_parse_name_union(param, &e.name) ||
671688 !tomoyo_parse_number_union(param, &e.number))
672689 error = -EINVAL;
....@@ -910,7 +927,7 @@
910927 case TOMOYO_TYPE_LINK:
911928 if (!d_is_dir(path1->dentry))
912929 break;
913
- /* fall through */
930
+ fallthrough;
914931 case TOMOYO_TYPE_PIVOT_ROOT:
915932 tomoyo_add_slash(&buf1);
916933 tomoyo_add_slash(&buf2);
....@@ -947,6 +964,7 @@
947964 {
948965 const struct tomoyo_mount_acl *p1 = container_of(a, typeof(*p1), head);
949966 const struct tomoyo_mount_acl *p2 = container_of(b, typeof(*p2), head);
967
+
950968 return tomoyo_same_name_union(&p1->dev_name, &p2->dev_name) &&
951969 tomoyo_same_name_union(&p1->dir_name, &p2->dir_name) &&
952970 tomoyo_same_name_union(&p1->fs_type, &p2->fs_type) &&
....@@ -966,6 +984,7 @@
966984 {
967985 struct tomoyo_mount_acl e = { .head.type = TOMOYO_TYPE_MOUNT_ACL };
968986 int error;
987
+
969988 if (!tomoyo_parse_name_union(param, &e.dev_name) ||
970989 !tomoyo_parse_name_union(param, &e.dir_name) ||
971990 !tomoyo_parse_name_union(param, &e.fs_type) ||
....@@ -995,6 +1014,7 @@
9951014 u16 perm = 0;
9961015 u8 type;
9971016 const char *operation = tomoyo_read_token(param);
1017
+
9981018 for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++)
9991019 if (tomoyo_permstr(operation, tomoyo_path_keyword[type]))
10001020 perm |= 1 << type;