hfsplus: fix bug causing custom uid and gid being unable to be assigned with mount
authorAditya Garg <gargaditya08@live.com>
Wed, 7 Dec 2022 03:05:40 +0000 (03:05 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jan 2023 11:07:35 +0000 (12:07 +0100)
commit 9f2b5debc07073e6dfdd774e3594d0224b991927 upstream.

Despite specifying UID and GID in mount command, the specified UID and GID
were not being assigned. This patch fixes this issue.

Link: https://lkml.kernel.org/r/C0264BF5-059C-45CF-B8DA-3A3BD2C803A2@live.com
Signed-off-by: Aditya Garg <gargaditya08@live.com>
Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/hfsplus/hfsplus_fs.h
fs/hfsplus/inode.c
fs/hfsplus/options.c

index 35cd703c66045c4f6c114e314f02ce4ac97f1726..bbc72087dd4c54d2a19b97419c6fa7e6d5c6552c 100644 (file)
@@ -198,6 +198,8 @@ struct hfsplus_sb_info {
 #define HFSPLUS_SB_HFSX                3
 #define HFSPLUS_SB_CASEFOLD    4
 #define HFSPLUS_SB_NOBARRIER   5
+#define HFSPLUS_SB_UID         6
+#define HFSPLUS_SB_GID         7
 
 static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
 {
index cfd380e2743d124daf18850bd97a56574d09689f..f5ed9269c276a5a67809ca8052e378f8dc1b1321 100644 (file)
@@ -186,11 +186,11 @@ static void hfsplus_get_perms(struct inode *inode,
        mode = be16_to_cpu(perms->mode);
 
        i_uid_write(inode, be32_to_cpu(perms->owner));
-       if (!i_uid_read(inode) && !mode)
+       if ((test_bit(HFSPLUS_SB_UID, &sbi->flags)) || (!i_uid_read(inode) && !mode))
                inode->i_uid = sbi->uid;
 
        i_gid_write(inode, be32_to_cpu(perms->group));
-       if (!i_gid_read(inode) && !mode)
+       if ((test_bit(HFSPLUS_SB_GID, &sbi->flags)) || (!i_gid_read(inode) && !mode))
                inode->i_gid = sbi->gid;
 
        if (dir) {
index bb806e58c9770ec5491235bb8ac5fcdcd2e5574b..f7465e0a9247f5e35db1c10f927b0d34bcb14abf 100644 (file)
@@ -139,6 +139,8 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
                        if (!uid_valid(sbi->uid)) {
                                pr_err("invalid uid specified\n");
                                return 0;
+                       } else {
+                               set_bit(HFSPLUS_SB_UID, &sbi->flags);
                        }
                        break;
                case opt_gid:
@@ -150,6 +152,8 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
                        if (!gid_valid(sbi->gid)) {
                                pr_err("invalid gid specified\n");
                                return 0;
+                       } else {
+                               set_bit(HFSPLUS_SB_GID, &sbi->flags);
                        }
                        break;
                case opt_part: