hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/hfsplus/inode.c
....@@ -187,11 +187,11 @@
187187 mode = be16_to_cpu(perms->mode);
188188
189189 i_uid_write(inode, be32_to_cpu(perms->owner));
190
- if (!i_uid_read(inode) && !mode)
190
+ if ((test_bit(HFSPLUS_SB_UID, &sbi->flags)) || (!i_uid_read(inode) && !mode))
191191 inode->i_uid = sbi->uid;
192192
193193 i_gid_write(inode, be32_to_cpu(perms->group));
194
- if (!i_gid_read(inode) && !mode)
194
+ if ((test_bit(HFSPLUS_SB_GID, &sbi->flags)) || (!i_gid_read(inode) && !mode))
195195 inode->i_gid = sbi->gid;
196196
197197 if (dir) {
....@@ -497,8 +497,11 @@
497497 if (type == HFSPLUS_FOLDER) {
498498 struct hfsplus_cat_folder *folder = &entry.folder;
499499
500
- if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
501
- /* panic? */;
500
+ if (fd->entrylength < sizeof(struct hfsplus_cat_folder)) {
501
+ pr_err("bad catalog folder entry\n");
502
+ res = -EIO;
503
+ goto out;
504
+ }
502505 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
503506 sizeof(struct hfsplus_cat_folder));
504507 hfsplus_get_perms(inode, &folder->permissions, 1);
....@@ -518,8 +521,11 @@
518521 } else if (type == HFSPLUS_FILE) {
519522 struct hfsplus_cat_file *file = &entry.file;
520523
521
- if (fd->entrylength < sizeof(struct hfsplus_cat_file))
522
- /* panic? */;
524
+ if (fd->entrylength < sizeof(struct hfsplus_cat_file)) {
525
+ pr_err("bad catalog file entry\n");
526
+ res = -EIO;
527
+ goto out;
528
+ }
523529 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
524530 sizeof(struct hfsplus_cat_file));
525531
....@@ -550,6 +556,7 @@
550556 pr_err("bad catalog entry used to create inode\n");
551557 res = -EIO;
552558 }
559
+out:
553560 return res;
554561 }
555562
....@@ -558,6 +565,7 @@
558565 struct inode *main_inode = inode;
559566 struct hfs_find_data fd;
560567 hfsplus_cat_entry entry;
568
+ int res = 0;
561569
562570 if (HFSPLUS_IS_RSRC(inode))
563571 main_inode = HFSPLUS_I(inode)->rsrc_inode;
....@@ -576,8 +584,11 @@
576584 if (S_ISDIR(main_inode->i_mode)) {
577585 struct hfsplus_cat_folder *folder = &entry.folder;
578586
579
- if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
580
- /* panic? */;
587
+ if (fd.entrylength < sizeof(struct hfsplus_cat_folder)) {
588
+ pr_err("bad catalog folder entry\n");
589
+ res = -EIO;
590
+ goto out;
591
+ }
581592 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
582593 sizeof(struct hfsplus_cat_folder));
583594 /* simple node checks? */
....@@ -602,8 +613,11 @@
602613 } else {
603614 struct hfsplus_cat_file *file = &entry.file;
604615
605
- if (fd.entrylength < sizeof(struct hfsplus_cat_file))
606
- /* panic? */;
616
+ if (fd.entrylength < sizeof(struct hfsplus_cat_file)) {
617
+ pr_err("bad catalog file entry\n");
618
+ res = -EIO;
619
+ goto out;
620
+ }
607621 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
608622 sizeof(struct hfsplus_cat_file));
609623 hfsplus_inode_write_fork(inode, &file->data_fork);
....@@ -624,5 +638,5 @@
624638 set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
625639 out:
626640 hfs_find_exit(&fd);
627
- return 0;
641
+ return res;
628642 }