Skip to contentSkip to conversation

Improve handling of unidentified xattrs

PATCH Applied Sandeep Dhavale via Linux-erofs 2 participants 3 messages Aug 20, 2024 – Aug 21, 2024 Library code

lore
Share & tools
lore
#0 lore raw

cover Improve handling of unidentified xattrs

Hi,
I had a report that when erofs is built from the btrfs filesystem with compression enabled, it would fail to build seemingly with error "failed to build shared xattrs". We tried to fix this by returning 0 (null) instead of error in parse_one_xattr(). However we need to actually skip it else we get a null pointer dereference in erofs_xattr_add() trying to process the same.

Thanks,
Sandeep.

Tested with btrfs with compression enabled.

$ lsattr mtpt/
--------c------------- mtpt/sample.txt

Before:
mkfs.erofs -z lz4hc,9 erofs.img mtpt/
mkfs.erofs 1.8.1-dirty
<W> erofs: parse_one_xattr() Line[285] skipped unidentified xattr: btrfs.compression Segmentation fault

After:
mkfs.erofs -z lz4hc,9 erofs.img mtpt/
mkfs.erofs 1.8.1-dirty
<W> erofs: parse_one_xattr() Line[285] skipped unidentified xattr: btrfs.compression Processing sample.txt ...
<W> erofs: parse_one_xattr() Line[285] skipped unidentified xattr: btrfs.compression Build completed.
------
Filesystem UUID: 9a1bb5a3-077a-40bc-972f-ed141059e7c8
Filesystem total blocks: 5 (of 4096-byte blocks)
Filesystem total inodes: 2
Filesystem total metadata blocks: 1
Filesystem total deduplicated bytes (of source files): 0

Sandeep Dhavale (1):
erofs-utils: lib: actually skip the unidentified xattrs

 lib/xattr.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
2.46.0.184.g6999bdac58-goog
#1 lore raw

PATCH 1/1 erofs-utils: lib: actually skip the unidentified xattrs

parse_one_xattr() will return null if it detects unidentified xattr. In such cases we need to skip this xattr which was our intention than try to add it in erofs_xattr_add() which results in null pointer dereference.

Fixes 3037f8958f3b ("erofs-utils: skip all unidentified xattrs from local paths")
---
 lib/xattr.c | 3 +++
 1 file changed, 3 insertions(+)
lib/xattr.c +3 -0
index 651657f..9f31f2d 100644
@@ -448,6 +448,9 @@ static int read_xattrs_from_file(const char *path, mode_t mode,
 			ret = PTR_ERR(item);
 			goto err;
 		}
+		/* skip unidentified xattrs */
+		if (!item)
+			continue;
 
 		ret = erofs_xattr_add(ixattrs, item);
 		if (ret < 0)
Signature · 1 line
2.46.0.184.g6999bdac58-goog
Applied
#2 lore raw

Re: [PATCH 1/1] erofs-utils: lib: actually skip the unidentified xattrs

Quoted 7 lines · Sandeep Dhavale

parse_one_xattr() will return null if it detects unidentified xattr. In such cases we need to skip this xattr which was our intention than try to add it in erofs_xattr_add() which results in null pointer dereference.

Fixes 3037f8958f3b ("erofs-utils: skip all unidentified xattrs from local paths")

Thanks, applied.

Thanks,
Gao Xiang