git: fbe4835e6b1e - main - linux: do not truncate the listxattr() size
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 08 Nov 2026 01:32:14 UTC
The branch main has been updated by nprice:
URL: https://cgit.FreeBSD.org/src/commit/?id=fbe4835e6b1eec36103a5ce97efbab11b3b5fc72
commit fbe4835e6b1eec36103a5ce97efbab11b3b5fc72
Author: Nick Price <nprice@FreeBSD.org>
AuthorDate: 2026-11-08 01:32:08 +0000
Commit: Nick Price <nprice@FreeBSD.org>
CommitDate: 2026-11-08 01:32:08 +0000
linux: do not truncate the listxattr() size
listxattr() sized its buffer with min(), which truncates the 64-bit
size to 32 bits, so a size of 2^32 + k allocated k bytes while the
copy-out guard used the full size. The walk then read record lengths
past the buffer and copied kernel heap out to the caller, and could
panic the kernel. Any user can reach it through a user.* attribute on
a file it owns.
Use MIN(), and fail with EIO if a record runs past the data returned.
Reviewed by: adrian, markj
Approved by: adrian (mentor)
Differential Revision: https://reviews.freebsd.org/D61006
Signed-off-by: Nick Price <nprice@FreeBSD.org>
---
sys/compat/linux/linux_xattr.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/sys/compat/linux/linux_xattr.c b/sys/compat/linux/linux_xattr.c
index 9a206089ada1..6bba5346c748 100644
--- a/sys/compat/linux/linux_xattr.c
+++ b/sys/compat/linux/linux_xattr.c
@@ -153,7 +153,7 @@ listxattr(struct thread *td, struct listxattr_args *args)
}
if (args->size != 0)
- sz = min(LINUX_XATTR_LIST_MAX, args->size);
+ sz = MIN(LINUX_XATTR_LIST_MAX, args->size);
else
sz = LINUX_XATTR_LIST_MAX;
@@ -203,6 +203,13 @@ listxattr(struct thread *td, struct listxattr_args *args)
error = ERANGE;
break;
}
+ KASSERT(keylen + 1 <= rs,
+ ("%s: truncated record", __func__));
+ if (keylen + 1 > rs) {
+ printf("%s: truncated record\n", __func__);
+ error = EIO;
+ goto out;
+ }
++key;
if (args->list != NULL && args->size > 0) {
sprintf(attrname, "%s.%.*s", prefix, keylen, key);
@@ -215,6 +222,7 @@ listxattr(struct thread *td, struct listxattr_args *args)
rs -= (keylen + 1);
}
}
+out:
if (error == 0)
td->td_retval[0] = cnt;
free(data, M_LINUX);