Skip to contentSkip to conversation

ext2: fix improper assignment for e_value_offs

PATCH In review Chengguang Xu 2 participants 2 messages Jun 3, 2020 – Jun 5, 2020 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: fix improper assignment for e_value_offs

In the process of changing value for existing EA, there is an improper assignment of e_value_offs(setting to 0), because it will be reset to incorrect value in the following loop(shifting EA values before target). Delayed assignment can avoid this issue.

---
 fs/ext2/xattr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext2/xattr.c +2 -1
index 943cc469f42f..c802ea682e7f 100644
@@ -588,7 +588,6 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
 			/* Remove the old value. */
 			memmove(first_val + size, first_val, val - first_val);
 			memset(first_val, 0, size);
-			here->e_value_offs = 0;
 			min_offs += size;
 
 			/* Adjust all value offsets. */
@@ -600,6 +599,8 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
 						cpu_to_le16(o + size);
 				last = EXT2_XATTR_NEXT(last);
 			}
+
+			here->e_value_offs = 0;
 		}
 		if (value == NULL) {
 			/* Remove the old name. */
Signature · 1 line
2.20.1
#1 lore raw
Quoted 7 lines · Chengguang Xu

In the process of changing value for existing EA, there is an improper assignment of e_value_offs(setting to 0), because it will be reset to incorrect value in the following loop(shifting EA values before target). Delayed assignment can avoid this issue.

Thanks. I've added the patch to my tree.

Honza

Quoted 29 lines
---
 fs/ext2/xattr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext2/xattr.c +2 -1
index 943cc469f42f..c802ea682e7f 100644
@@ -588,7 +588,6 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
 			/* Remove the old value. */
 			memmove(first_val + size, first_val, val - first_val);
 			memset(first_val, 0, size);
-			here->e_value_offs = 0;
 			min_offs += size;
 
 			/* Adjust all value offsets. */
@@ -600,6 +599,8 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
 						cpu_to_le16(o + size);
 				last = EXT2_XATTR_NEXT(last);
 			}
+
+			here->e_value_offs = 0;
 		}
 		if (value == NULL) {
 			/* Remove the old name. */
Signature · 1 line
2.20.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR