Skip to contentSkip to conversation

erofs-utils: fsck: never follow exist symlinks when overwriting

PATCH New Gao Xiang 1 participant 2 messages Jan 26, 2022

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: fsck: never follow exist symlinks when overwriting

Otherwise, we could face potential security issues.

Fixes 412c8f908132 ("erofs-utils: fsck: add --extract=X support to extract to path X")
---
 fsck/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fsck/main.c +2 -2
index 14534b9..f2af609 100644
@@ -496,8 +496,8 @@ static inline int erofs_extract_file(struct erofs_inode *inode)
 
 again:
 	fd = open(fsckcfg.extract_path,
-		  O_WRONLY | O_CREAT | (fsckcfg.overwrite ? O_TRUNC : O_EXCL),
-		  0700);
+		  O_WRONLY | O_CREAT | O_NOFOLLOW |
+			(fsckcfg.overwrite ? O_TRUNC : O_EXCL), 0700);
 	if (fd < 0) {
 		if (fsckcfg.overwrite && tryagain) {
 			if (errno == EISDIR) {
Signature · 1 line
2.24.4
author
#1 lore raw

PATCH 2/2 erofs-utils: fsck: don't set attributes when fscking only

Otherwise, when --extract is specified, it will report:
<W> erofs: erofsfsck_set_attributes() Line[189] failed to set times: (null) <W> erofs: erofsfsck_set_attributes() Line[197] failed to set permissions: (null)
...

Fixes 412c8f908132 ("erofs-utils: fsck: add --extract=X support to extract to path X")
---
 fsck/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck/main.c +1 -1
index f2af609..92e0c76 100644
@@ -665,7 +665,7 @@ verify:
 		ret = erofs_iterate_dir(&ctx, true);
 	}
 
-	if (!ret)
+	if (!ret && fsckcfg.extract_path)
 		erofsfsck_set_attributes(&inode, fsckcfg.extract_path);
 
 out:
Signature · 1 line
2.24.4