Skip to contentSkip to conversation

erofs-utils: lib: check NULL from erofs_rebuild_get_dentry()

PATCH In review Vansh Choudhary 2 participants 3 messages Apr 20 – Apr 21 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: check NULL from erofs_rebuild_get_dentry()

erofs_rebuild_get_dentry() returns NULL when the input path normalizes to nothing (".", "/", "//", or paths that collapse via ".."). The tar hardlink branch and the S3 import loop only check IS_ERR() and then dereference the result.

Reject a hardlink target that resolves to root with -EISDIR, and treat a root-normalized S3 key as the root inode itself.

Fixes 95d315fd7958 ("erofs-utils: introduce tarerofs")
Fixes 29728ba8f6f6 ("erofs-utils: mkfs: support EROFS meta-only image generation from S3")
---
 lib/remotes/s3.c | 5 ++++-
 lib/tar.c        | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)
lib/remotes/s3.c +4 -1
index e552ed0..d386a32 100644
@@ -1129,7 +1129,10 @@ int s3erofs_build_trees(struct erofs_importer *im, struct erofs_s3 *s3,
 			ret = PTR_ERR(d);
 			goto err_iter;
 		}
-		if (d->type == EROFS_FT_DIR) {
+		if (!d) {
+			inode = root;
+			inode->i_mode = S_IFDIR | 0755;
+		} else if (d->type == EROFS_FT_DIR) {
 			inode = d->inode;
 			inode->i_mode = S_IFDIR | 0755;
 		} else {
lib/tar.c +4 -0
index d2dc141..b08bd77 100644
@@ -1024,6 +1024,10 @@ out_eot:
 			ret = PTR_ERR(d2);
 			goto out;
 		}
+		if (!d2) {
+			ret = -EISDIR;
+			goto out;
+		}
 		if (d2->type == EROFS_FT_UNKNOWN) {
 			ret = -ENOENT;
 			goto out;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 11 lines · Vansh Choudhary

erofs_rebuild_get_dentry() returns NULL when the input path normalizes to nothing (".", "/", "//", or paths that collapse via ".."). The tar hardlink branch and the S3 import loop only check IS_ERR() and then dereference the result.

Reject a hardlink target that resolves to root with -EISDIR, and treat a root-normalized S3 key as the root inode itself.

Fixes 95d315fd7958 ("erofs-utils: introduce tarerofs")
Fixes 29728ba8f6f6 ("erofs-utils: mkfs: support EROFS meta-only image generation from S3")

Need a reproducer to experimental-tests before advancing this.

Thanks,
Gao Xiang

#2 lore raw

PATCH 1/1 erofs-utils: tests: add test for hardlink-to-root tar entries

This is a regression test for "erofs-utils: lib: check NULL from erofs_rebuild_get_dentry()".

---
 tests/Makefile.am   |  3 +++
 tests/erofs/031     | 58 +++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/031.out |  2 ++
 3 files changed, 63 insertions(+)
 create mode 100755 tests/erofs/031
 create mode 100644 tests/erofs/031.out
tests/Makefile.am +3 -0
index d8ac067..e7eacbe 100644
@@ -126,6 +126,9 @@ TESTS += erofs/028
 # 029 - test FUSE daemon and kernel error handling on corrupted inodes
 TESTS += erofs/029
 
+# 031 - regression test for NULL dentry on hardlink-to-root tar entry
+TESTS += erofs/031
+
 # NEW TEST CASE HERE
 # TESTS += erofs/999
 
tests/erofs/031 new file +58 -0

58 lines not on this page · raw message

tests/erofs/031.out new file +2 -0
new file mode 100644
index 0000000..b3d0bb0
@@ -0,0 +1,2 @@
+QA output created by 031
+Silence is golden
Signature · 1 line
2.43.0