1 Index: linux-4.18.0-348.2.1.el8_5/fs/ext4/ext4.h
2 ===================================================================
3 --- linux-4.18.0-348.2.1.el8_5.orig/fs/ext4/ext4.h
4 +++ linux-4.18.0-348.2.1.el8_5/fs/ext4/ext4.h
5 @@ -2770,6 +2770,7 @@ extern int ext4_ind_remove_space(handle_
7 extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
8 extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long);
9 +extern int ext4_ioctl_setproject(struct inode *, __u32);
12 extern int ext4_ext_migrate(struct inode *);
13 Index: linux-4.18.0-348.2.1.el8_5/fs/ext4/ioctl.c
14 ===================================================================
15 --- linux-4.18.0-348.2.1.el8_5.orig/fs/ext4/ioctl.c
16 +++ linux-4.18.0-348.2.1.el8_5/fs/ext4/ioctl.c
17 @@ -446,9 +446,8 @@ flags_out:
21 -static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
22 +int ext4_ioctl_setproject(struct inode *inode, __u32 projid)
24 - struct inode *inode = file_inode(filp);
25 struct super_block *sb = inode->i_sb;
26 struct ext4_inode_info *ei = EXT4_I(inode);
28 @@ -532,7 +531,7 @@ out_stop:
32 -static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
33 +static int ext4_ioctl_setproject(struct inode *inode, __u32 projid)
35 if (projid != EXT4_DEF_PROJID)
37 @@ -1184,7 +1183,7 @@ resizefs_out:
38 err = ext4_ioctl_setflags(inode, flags);
41 - err = ext4_ioctl_setproject(filp, fa.fsx_projid);
42 + err = ext4_ioctl_setproject(inode, fa.fsx_projid);
45 mnt_drop_write_file(filp);
46 Index: linux-4.18.0-348.2.1.el8_5/fs/ext4/xattr.c
47 ===================================================================
48 --- linux-4.18.0-348.2.1.el8_5.orig/fs/ext4/xattr.c
49 +++ linux-4.18.0-348.2.1.el8_5/fs/ext4/xattr.c
54 +#define EXT4_XATTR_PROJID "projid"
56 #ifdef EXT4_XATTR_DEBUG
57 # define ea_idebug(inode, fmt, ...) \
58 printk(KERN_DEBUG "inode %s:%lu: " fmt "\n", \
59 @@ -646,11 +648,30 @@ ext4_xattr_get(struct inode *inode, int
62 down_read(&EXT4_I(inode)->xattr_sem);
63 + if (name_index == EXT4_XATTR_INDEX_TRUSTED &&
64 + strncmp(name, EXT4_XATTR_PROJID, strlen(name)) == 0 &&
65 + ext4_has_feature_project(inode->i_sb)) {
66 + /* 10 chars to hold u32 in decimal, plus ending \0 */
68 + __u32 projid = (__u32)from_kprojid(&init_user_ns,
69 + EXT4_I(inode)->i_projid);
70 + error = snprintf(value, sizeof(value), "%u", projid);
72 + if (error > buffer_size) {
76 + memcpy(buffer, value, error);
81 error = ext4_xattr_ibody_get(inode, name_index, name, buffer,
83 if (error == -ENODATA)
84 error = ext4_xattr_block_get(inode, name_index, name, buffer,
87 up_read(&EXT4_I(inode)->xattr_sem);
90 @@ -772,7 +793,33 @@ ext4_listxattr(struct dentry *dentry, ch
91 ret = ext4_xattr_block_list(dentry, buffer, buffer_size);
99 + if (ext4_has_feature_project(dentry->d_sb)) {
100 + size_t prefix_len = strlen(XATTR_TRUSTED_PREFIX);
101 + size_t name_len = strlen(EXT4_XATTR_PROJID);
102 + size_t size = prefix_len + name_len + 1;
104 + if (__kprojid_val(EXT4_I(dentry->d_inode)->i_projid) ==
108 + if (size > buffer_size) {
112 + strncpy(buffer, XATTR_TRUSTED_PREFIX, prefix_len);
113 + buffer += prefix_len;
114 + strncpy(buffer, EXT4_XATTR_PROJID, name_len);
115 + buffer += name_len;
117 + buffer_size -= size;
122 up_read(&EXT4_I(d_inode(dentry))->xattr_sem);
124 @@ -2464,6 +2511,43 @@ ext4_xattr_set(struct inode *inode, int
125 int error, retries = 0;
128 + if (name_index == EXT4_XATTR_INDEX_TRUSTED &&
129 + strncmp(name, EXT4_XATTR_PROJID, strlen(name)) == 0 &&
130 + ext4_has_feature_project(inode->i_sb)) {
131 + /* 10 chars to hold u32 in decimal, plus ending \0 */
136 + * Project Quota ID state is only allowed to change from within
137 + * the init namespace.
139 + if (current_user_ns() != &init_user_ns)
142 + if (value && value_len) {
143 + if (value_len >= sizeof(buffer))
145 + memcpy(buffer, value, value_len);
146 + buffer[value_len] = '\0';
147 + error = kstrtouint(buffer, 0, &projid);
151 + projid = EXT4_DEF_PROJID;
155 + * Caller is allowed to change the project ID. If it is being
156 + * changed, make sure that the new value is valid.
158 + if (!projid_valid(make_kprojid(&init_user_ns, projid)))
161 + error = ext4_ioctl_setproject(inode, projid);
165 error = dquot_initialize(inode);