Skip to contentSkip to conversation

statx: don't leak STATX_ATTR_CHANGE_MONOTONIC in stx_attributes_mask

PATCH Superseded Jeff Layton 3 participants 4 messages Oct 29 – Nov 3 VFS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 statx: don't leak STATX_ATTR_CHANGE_MONOTONIC in stx_attributes_mask

STATX_ATTR_CHANGE_MONOTONIC is kernel-internal. cp_statx() strips it from stx_attributes but copies attributes_mask verbatim, so it leaks to userland on filesystems that advertise it (nfs, ceph), e.g. stx_attributes_mask = 0x8000000000b03000 on NFS.

Mask it out of stx_attributes_mask too.

Fixes a1175d6b1bda ("vfs: plumb i_version handling into struct kstat")
---
 fs/stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/stat.c +1 -1
index a2e63c6c45b7..787c13f378ff 100644
@@ -719,7 +719,7 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer)
 	tmp.stx_ino = stat->ino;
 	tmp.stx_size = stat->size;
 	tmp.stx_blocks = stat->blocks;
-	tmp.stx_attributes_mask = stat->attributes_mask;
+	tmp.stx_attributes_mask = stat->attributes_mask & ~STATX_ATTR_CHANGE_MONOTONIC;
 	tmp.stx_atime.tv_sec = stat->atime.tv_sec;
 	tmp.stx_atime.tv_nsec = stat->atime.tv_nsec;
 	tmp.stx_btime.tv_sec = stat->btime.tv_sec;

---
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
change-id: 20261029-statx-3f1d8cd8d877

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jeff Layton

STATX_ATTR_CHANGE_MONOTONIC is kernel-internal. cp_statx() strips it from stx_attributes but copies attributes_mask verbatim, so it leaks to userland on filesystems that advertise it (nfs, ceph), e.g. stx_attributes_mask = 0x8000000000b03000 on NFS.

Mask it out of stx_attributes_mask too.

Fixes a1175d6b1bda ("vfs: plumb i_version handling into struct kstat")

OK, feel free to add:

Honza

Quoted 26 lines
---
 fs/stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/stat.c +1 -2
index a2e63c6c45b7..787c13f378ff 100644
@@ -719,7 +719,7 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer)
 	tmp.stx_ino = stat->ino;
 	tmp.stx_size = stat->size;
 	tmp.stx_blocks = stat->blocks;
-	tmp.stx_attributes_mask = stat->attributes_mask;
+	tmp.stx_attributes_mask = stat->attributes_mask & ~STATX_ATTR_CHANGE_MONOTONIC;
 	tmp.stx_atime.tv_sec = stat->atime.tv_sec;
 	tmp.stx_atime.tv_nsec = stat->atime.tv_nsec;
 	tmp.stx_btime.tv_sec = stat->btime.tv_sec;
 
---

base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
change-id: 20261029-statx-3f1d8cd8d877

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
In reply to Jeff Layton
Quoted 6 lines · Jeff Layton

STATX_ATTR_CHANGE_MONOTONIC is kernel-internal. cp_statx() strips it from stx_attributes but copies attributes_mask verbatim, so it leaks to userland on filesystems that advertise it (nfs, ceph), e.g. stx_attributes_mask = 0x8000000000b03000 on NFS.

Mask it out of stx_attributes_mask too.

This actually seems like useful information, any reason it is not reported? We'd probably want to renumber if for that, though.

fs/stat.c cp_statx(const struct kstat *stat, struct statx __user *buffer) · line 722

Quoted 3 lines
fs/stat.c +1 -1
 	tmp.stx_blocks = stat->blocks;
-	tmp.stx_attributes_mask = stat->attributes_mask;
+	tmp.stx_attributes_mask = stat->attributes_mask & ~STATX_ATTR_CHANGE_MONOTONIC;

But if we want to keep internal only flags, they should have a mask defined next to the attributes intead of open coding specific ones here.

And please avoid the overly long line as well.

#3 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Jeff Layton

STATX_ATTR_CHANGE_MONOTONIC is kernel-internal. cp_statx() strips it from stx_attributes but copies attributes_mask verbatim, so it leaks to userland on filesystems that advertise it (nfs, ceph), e.g. stx_attributes_mask = 0x8000000000b03000 on NFS.

Quoted 6 lines
Quoted 1 line

Mask it out of stx_attributes_mask too.

This actually seems like useful information, any reason it is not reported? We'd probably want to renumber if for that, though.

Because we don't report the change attribute itself. There's no reason to report whether it's monotonic if userspace can't get to it in the first place.

Quoted 8 lines

fs/stat.c cp_statx(const struct kstat *stat, struct statx __user *buffer) · line 722

Quoted 3 lines
fs/stat.c +1 -1
 	tmp.stx_blocks = stat->blocks;
-	tmp.stx_attributes_mask = stat->attributes_mask;
+	tmp.stx_attributes_mask = stat->attributes_mask & ~STATX_ATTR_CHANGE_MONOTONIC;

But if we want to keep internal only flags, they should have a mask defined next to the attributes intead of open coding specific ones here.

And please avoid the overly long line as well.

Alrighty, I'll post a v2.

Signature · 1 line
Jeff Layton <[email protected]>