Skip to contentSkip to conversation

bcachefs: fix smatch data leak warning in fs usage ioctl

PATCH Applied Brian Foster 2 participants 2 messages Jun 6, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: fix smatch data leak warning in fs usage ioctl

smatch warns that the copy of arg to userspace is a potential data leak by virtue of arg.pad not being checked or zeroed. This was introduced by the commit referenced below that switched arg from being a zeroed runtime allocation to living on the stack. Fix by simply zero initializing the structure.

Fixes cde738a61e65 ("bcachefs: Convert bch2_ioctl_fs_usage() to new accounting")
---
 fs/bcachefs/chardev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bcachefs/chardev.c +1 -1
index 70db3a737d71..4248c251fce5 100644
@@ -515,7 +515,7 @@ static long bch2_ioctl_data(struct bch_fs *c,
 static long bch2_ioctl_fs_usage(struct bch_fs *c,
 				struct bch_ioctl_fs_usage __user *user_arg)
 {
-	struct bch_ioctl_fs_usage arg;
+	struct bch_ioctl_fs_usage arg = {};
 	darray_char replicas = {};
 	u32 replica_entries_bytes;
 	int ret = 0;
Signature · 1 line
2.44.0
#1 lore raw
Quoted 9 lines · Brian Foster

smatch warns that the copy of arg to userspace is a potential data leak by virtue of arg.pad not being checked or zeroed. This was introduced by the commit referenced below that switched arg from being a zeroed runtime allocation to living on the stack. Fix by simply zero initializing the structure.

Fixes cde738a61e65 ("bcachefs: Convert bch2_ioctl_fs_usage() to new accounting")

Applied