Skip to contentSkip to conversation

mkfs: fix libxfs_iget return value sign inversion

PATCH In review Darrick J. Wong 2 participants 5 messages Sep 23, 2025 – Sep 24, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mkfs: fix libxfs_iget return value sign inversion

From: Darrick J. Wong <[email protected]>

libxfs functions return negative errno, so utilities must invert the return values from such functions. Caught by xfs/437.

Fixes 8a4ea72724930c ("proto: add ability to populate a filesystem from a directory")
---
 mkfs/proto.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/proto.c +1 -1
index bfeeb5ac638185..2b29240db95f74 100644
@@ -1425,7 +1425,7 @@ handle_hardlink(
 	if (dst_ino == 0)
 		return false;
 
-	error = libxfs_iget(mp, NULL, dst_ino, 0, &ip);
+	error = -libxfs_iget(mp, NULL, dst_ino, 0, &ip);
 	if (error)
 		fail(_("failed to get inode"), error);
 
#1 lore raw

PATCH 2/2 libfrog: pass mode to xfrog_file_setattr

From: Darrick J. Wong <[email protected]>

xfs/633 crashes rdump_fileattrs_path passes a NULL struct stat pointer and then the fallback code dereferences it to get the file mode. Instead, let's just pass the stat mode directly to it, because that's the only piece of information that it needs.

Fixes 128ac4dadbd633 ("xfs_db: use file_setattr to copy attributes on special files with rdump")
---
 libfrog/file_attr.h |    9 ++-------
 db/rdump.c          |    4 ++--
 io/attr.c           |    4 ++--
 libfrog/file_attr.c |    4 ++--
 quota/project.c     |    6 ++++--
 5 files changed, 12 insertions(+), 15 deletions(-)
libfrog/file_attr.h +2 -7
index df9b6181d52cf9..2a1c0d42d0a771 100644
@@ -24,12 +24,7 @@ xfrog_file_getattr(
 	struct file_attr	*fa,
 	const unsigned int	at_flags);
 
-int
-xfrog_file_setattr(
-	const int		dfd,
-	const char		*path,
-	const struct stat	*stat,
-	struct file_attr	*fa,
-	const unsigned int	at_flags);
+int xfrog_file_setattr(const int dfd, const char *path, const mode_t mode,
+		struct file_attr *fa, const unsigned int at_flags);
 
 #endif /* __LIBFROG_FILE_ATTR_H__ */
db/rdump.c +2 -2
index 84ca3156d60598..26f9babad62be1 100644
@@ -188,8 +188,8 @@ rdump_fileattrs_path(
 			return 1;
 	}
 
-	ret = xfrog_file_setattr(destdir->fd, pbuf->path, NULL, &fa,
-			AT_SYMLINK_NOFOLLOW);
+	ret = xfrog_file_setattr(destdir->fd, pbuf->path, VFS_I(ip)->i_mode,
+			&fa, AT_SYMLINK_NOFOLLOW);
 	if (ret) {
 		if (errno == EOPNOTSUPP || errno == EPERM || errno == ENOTTY)
 			lost_mask |= LOST_FSXATTR;
io/attr.c +2 -2
index 022ca5f1df1b7c..9563ff74e44777 100644
@@ -261,7 +261,7 @@ chattr_callback(
 
 	attr.fa_xflags |= orflags;
 	attr.fa_xflags &= ~andflags;
-	error = xfrog_file_setattr(AT_FDCWD, path, stat, &attr,
+	error = xfrog_file_setattr(AT_FDCWD, path, stat->st_mode, &attr,
 				   AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
@@ -357,7 +357,7 @@ chattr_f(
 
 	attr.fa_xflags |= orflags;
 	attr.fa_xflags &= ~andflags;
-	error = xfrog_file_setattr(AT_FDCWD, name, &st, &attr,
+	error = xfrog_file_setattr(AT_FDCWD, name, st.st_mode, &attr,
 				   AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
libfrog/file_attr.c +2 -2
index bb51ac6eb2ef95..c2cbcb4e14659c 100644
@@ -85,7 +85,7 @@ int
 xfrog_file_setattr(
 	const int		dfd,
 	const char		*path,
-	const struct stat	*stat,
+	const mode_t		mode,
 	struct file_attr	*fa,
 	const unsigned int	at_flags)
 {
@@ -103,7 +103,7 @@ xfrog_file_setattr(
 		return error;
 #endif
 
-	if (SPECIAL_FILE(stat->st_mode)) {
+	if (SPECIAL_FILE(mode)) {
 		errno = EOPNOTSUPP;
 		return -1;
 	}
quota/project.c +4 -2
index 5832e1474e2549..33449e01ef4dbb 100644
@@ -157,7 +157,8 @@ clear_project(
 	fa.fa_projid = 0;
 	fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT;
 
-	error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+	error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+			AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot clear project on %s: %s\n"),
 			progname, path, strerror(errno));
@@ -205,7 +206,8 @@ setup_project(
 	if (S_ISDIR(stat->st_mode))
 		fa.fa_xflags |= FS_XFLAG_PROJINHERIT;
 
-	error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+	error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+			AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set project on %s: %s\n"),
 			progname, path, strerror(errno));
Reviewed-by on v1 1/2
#4 lore raw
In reply to Darrick J. Wong
Quoted 7 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

libxfs functions return negative errno, so utilities must invert the return values from such functions. Caught by xfs/437.

Fixes 8a4ea72724930c ("proto: add ability to populate a filesystem from a directory")

lgtm

Quoted 18 lines
---
 mkfs/proto.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/proto.c +1 -1
index bfeeb5ac638185..2b29240db95f74 100644
@@ -1425,7 +1425,7 @@ handle_hardlink(
 	if (dst_ino == 0)
 		return false;
 
-	error = libxfs_iget(mp, NULL, dst_ino, 0, &ip);
+	error = -libxfs_iget(mp, NULL, dst_ino, 0, &ip);
 	if (error)
 		fail(_("failed to get inode"), error);
 
Signature · 1 line
- Andrey
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] libfrog: pass mode to xfrog_file_setattr

In reply to Darrick J. Wong
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

xfs/633 crashes rdump_fileattrs_path passes a NULL struct stat pointer and then the fallback code dereferences it to get the file mode.

Oh is it latest xfsprogs with older kernel (without file_[g]etattr)?

(I see this on 6.16)

Quoted 20 lines

Instead, let's just pass the stat mode directly to it, because that's the only piece of information that it needs.

Fixes 128ac4dadbd633 ("xfs_db: use file_setattr to copy attributes on special files with rdump")
---
 libfrog/file_attr.h |    9 ++-------
 db/rdump.c          |    4 ++--
 io/attr.c           |    4 ++--
 libfrog/file_attr.c |    4 ++--
 quota/project.c     |    6 ++++--
 5 files changed, 12 insertions(+), 15 deletions(-)
libfrog/file_attr.h +0 -0
index df9b6181d52cf9..2a1c0d42d0a771 100644
@@ -24,12 +24,7 @@ xfrog_file_getattr(
 	struct file_attr	*fa,
 	const unsigned int	at_flags);

libfrog/file_attr.h xfrog_file_getattr( · line 28

Quoted 10 lines
libfrog/file_attr.h +2 -7
 
-int
-xfrog_file_setattr(
-	const int		dfd,
-	const char		*path,
-	const struct stat	*stat,
-	struct file_attr	*fa,
-	const unsigned int	at_flags);
+int xfrog_file_setattr(const int dfd, const char *path, const mode_t mode,
+		struct file_attr *fa, const unsigned int at_flags);

Is this formatting change intentional? (maybe then the xfrog_file_getattr also)

otherwise lgtm

Quoted 86 lines
libfrog/file_attr.h +0 -0
 #endif /* __LIBFROG_FILE_ATTR_H__ */
db/rdump.c +2 -2
index 84ca3156d60598..26f9babad62be1 100644
@@ -188,8 +188,8 @@ rdump_fileattrs_path(
 			return 1;
 	}
 
-	ret = xfrog_file_setattr(destdir->fd, pbuf->path, NULL, &fa,
-			AT_SYMLINK_NOFOLLOW);
+	ret = xfrog_file_setattr(destdir->fd, pbuf->path, VFS_I(ip)->i_mode,
+			&fa, AT_SYMLINK_NOFOLLOW);
 	if (ret) {
 		if (errno == EOPNOTSUPP || errno == EPERM || errno == ENOTTY)
 			lost_mask |= LOST_FSXATTR;
io/attr.c +2 -2
index 022ca5f1df1b7c..9563ff74e44777 100644
@@ -261,7 +261,7 @@ chattr_callback(
 
 	attr.fa_xflags |= orflags;
 	attr.fa_xflags &= ~andflags;
-	error = xfrog_file_setattr(AT_FDCWD, path, stat, &attr,
+	error = xfrog_file_setattr(AT_FDCWD, path, stat->st_mode, &attr,
 				   AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
@@ -357,7 +357,7 @@ chattr_f(
 
 	attr.fa_xflags |= orflags;
 	attr.fa_xflags &= ~andflags;
-	error = xfrog_file_setattr(AT_FDCWD, name, &st, &attr,
+	error = xfrog_file_setattr(AT_FDCWD, name, st.st_mode, &attr,
 				   AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
libfrog/file_attr.c +2 -2
index bb51ac6eb2ef95..c2cbcb4e14659c 100644
@@ -85,7 +85,7 @@ int
 xfrog_file_setattr(
 	const int		dfd,
 	const char		*path,
-	const struct stat	*stat,
+	const mode_t		mode,
 	struct file_attr	*fa,
 	const unsigned int	at_flags)
 {
@@ -103,7 +103,7 @@ xfrog_file_setattr(
 		return error;
 #endif
 
-	if (SPECIAL_FILE(stat->st_mode)) {
+	if (SPECIAL_FILE(mode)) {
 		errno = EOPNOTSUPP;
 		return -1;
 	}
quota/project.c +4 -2
index 5832e1474e2549..33449e01ef4dbb 100644
@@ -157,7 +157,8 @@ clear_project(
 	fa.fa_projid = 0;
 	fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT;
 
-	error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+	error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+			AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot clear project on %s: %s\n"),
 			progname, path, strerror(errno));
@@ -205,7 +206,8 @@ setup_project(
 	if (S_ISDIR(stat->st_mode))
 		fa.fa_xflags |= FS_XFLAG_PROJINHERIT;
 
-	error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+	error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+			AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set project on %s: %s\n"),
 			progname, path, strerror(errno));
Signature · 1 line
- Andrey
#3 lore raw

Re: [PATCH 2/2] libfrog: pass mode to xfrog_file_setattr

Quoted 9 lines · Andrey Albershteyn
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

xfs/633 crashes rdump_fileattrs_path passes a NULL struct stat pointer and then the fallback code dereferences it to get the file mode.

Oh is it latest xfsprogs with older kernel (without file_[g]etattr)?

(I see this on 6.16)

Yes, the crash happens on 6.16-rc7 where there is no file_setattr call, and does not happen on for-next where file_setattr does exist.

Quoted 21 lines
Quoted 21 lines

Instead, let's just pass the stat mode directly to it, because that's the only piece of information that it needs.

Fixes 128ac4dadbd633 ("xfs_db: use file_setattr to copy attributes on special files with rdump")
---
 libfrog/file_attr.h |    9 ++-------
 db/rdump.c          |    4 ++--
 io/attr.c           |    4 ++--
 libfrog/file_attr.c |    4 ++--
 quota/project.c     |    6 ++++--
 5 files changed, 12 insertions(+), 15 deletions(-)
libfrog/file_attr.h +0 -0
index df9b6181d52cf9..2a1c0d42d0a771 100644
@@ -24,12 +24,7 @@ xfrog_file_getattr(
 	struct file_attr	*fa,
 	const unsigned int	at_flags);
 
Quoted 12 lines

libfrog/file_attr.h xfrog_file_getattr( · line 28

Quoted 9 lines
libfrog/file_attr.h +2 -7
-int
-xfrog_file_setattr(
-	const int		dfd,
-	const char		*path,
-	const struct stat	*stat,
-	struct file_attr	*fa,
-	const unsigned int	at_flags);
+int xfrog_file_setattr(const int dfd, const char *path, const mode_t mode,
+		struct file_attr *fa, const unsigned int at_flags);

Is this formatting change intentional? (maybe then the xfrog_file_getattr also)

Yes, compressed is the usual style for function declarations. It's only the definition that gets the expanded format.

(I didn't hassle you about it when you submitted the original patch because I'm trying to stop doing that to people ;))

Quoted 2 lines

otherwise lgtm

Thanks!

--D

Quoted 91 lines
Quoted 86 lines
libfrog/file_attr.h +0 -0
 #endif /* __LIBFROG_FILE_ATTR_H__ */
db/rdump.c +2 -2
index 84ca3156d60598..26f9babad62be1 100644
@@ -188,8 +188,8 @@ rdump_fileattrs_path(
 			return 1;
 	}
 
-	ret = xfrog_file_setattr(destdir->fd, pbuf->path, NULL, &fa,
-			AT_SYMLINK_NOFOLLOW);
+	ret = xfrog_file_setattr(destdir->fd, pbuf->path, VFS_I(ip)->i_mode,
+			&fa, AT_SYMLINK_NOFOLLOW);
 	if (ret) {
 		if (errno == EOPNOTSUPP || errno == EPERM || errno == ENOTTY)
 			lost_mask |= LOST_FSXATTR;
io/attr.c +2 -2
index 022ca5f1df1b7c..9563ff74e44777 100644
@@ -261,7 +261,7 @@ chattr_callback(
 
 	attr.fa_xflags |= orflags;
 	attr.fa_xflags &= ~andflags;
-	error = xfrog_file_setattr(AT_FDCWD, path, stat, &attr,
+	error = xfrog_file_setattr(AT_FDCWD, path, stat->st_mode, &attr,
 				   AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
@@ -357,7 +357,7 @@ chattr_f(
 
 	attr.fa_xflags |= orflags;
 	attr.fa_xflags &= ~andflags;
-	error = xfrog_file_setattr(AT_FDCWD, name, &st, &attr,
+	error = xfrog_file_setattr(AT_FDCWD, name, st.st_mode, &attr,
 				   AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
libfrog/file_attr.c +2 -2
index bb51ac6eb2ef95..c2cbcb4e14659c 100644
@@ -85,7 +85,7 @@ int
 xfrog_file_setattr(
 	const int		dfd,
 	const char		*path,
-	const struct stat	*stat,
+	const mode_t		mode,
 	struct file_attr	*fa,
 	const unsigned int	at_flags)
 {
@@ -103,7 +103,7 @@ xfrog_file_setattr(
 		return error;
 #endif
 
-	if (SPECIAL_FILE(stat->st_mode)) {
+	if (SPECIAL_FILE(mode)) {
 		errno = EOPNOTSUPP;
 		return -1;
 	}
quota/project.c +4 -2
index 5832e1474e2549..33449e01ef4dbb 100644
@@ -157,7 +157,8 @@ clear_project(
 	fa.fa_projid = 0;
 	fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT;
 
-	error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+	error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+			AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot clear project on %s: %s\n"),
 			progname, path, strerror(errno));
@@ -205,7 +206,8 @@ setup_project(
 	if (S_ISDIR(stat->st_mode))
 		fa.fa_xflags |= FS_XFLAG_PROJINHERIT;
 
-	error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+	error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+			AT_SYMLINK_NOFOLLOW);
 	if (error) {
 		fprintf(stderr, _("%s: cannot set project on %s: %s\n"),
 			progname, path, strerror(errno));
Signature · 1 line
- Andrey