Skip to contentSkip to conversation

fs/stat.c: avoid harmless garbage value problem in vfs_statx()

PATCH New Petr Vaganov 1 participant 1 message Nov 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/stat.c: avoid harmless garbage value problem in vfs_statx()

From: Su Hui <[email protected]>

commit 0fac3ed473dd2955053be6671cdd747807f5e488 upstream.

Clang static checker(scan-build) warning:
fs/stat.c:287:21: warning: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage.

  287 |                 stat->result_mask |= STATX_MNT_ID_UNIQUE;
      |                 ~~~~~~~~~~~~~~~~~ ^

fs/stat.c:290:21: warning: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage.
290 | stat->result_mask |= STATX_MNT_ID;

When vfs_getattr() failed because of security_inode_getattr(), 'stat' is uninitialized. In this case, there is a harmless garbage problem in vfs_statx_path(). It's better to return error directly when vfs_getattr() failed, avoiding garbage value and more clearly.

[ Petr: There is no vfs_statx_path() in this tree. The fix is applied
directly in vfs_statx() by jumping to path_put() via a new out_path label, preserving the reference drop and the ESTALE retry. ]

Fixes fa2fcf4f1df1 ("statx: add mount ID")
---
 fs/stat.c | 3 +++
 1 file changed, 3 insertions(+)
fs/stat.c +3 -0
index 5375be5f97cc..9d3f1b276c86 100644
@@ -246,6 +246,8 @@ static int vfs_statx(int dfd, struct filename *filename, int flags,
 		goto out;
 
 	error = vfs_getattr(&path, stat, request_mask, flags);
+	if (error)
+		goto out_path;
 
 	stat->mnt_id = real_mount(path.mnt)->mnt_id;
 	stat->result_mask |= STATX_MNT_ID;
@@ -262,6 +264,7 @@ static int vfs_statx(int dfd, struct filename *filename, int flags,
 			bdev_statx_dioalign(inode, stat);
 	}
 
+out_path:
 	path_put(&path);
 	if (retry_estale(error, lookup_flags)) {
 		lookup_flags |= LOOKUP_REVAL;
Signature · 1 line
2.55.0