diff options
| author | Nick Price <nprice@FreeBSD.org> | 2026-11-08 01:32:08 +0000 |
|---|---|---|
| committer | Mark Johnston <markj@FreeBSD.org> | 2026-11-16 01:38:09 +0000 |
| commit | 52fe4ad71f4b36a477d89a7fb0c6da6f2f1e164a (patch) | |
| tree | 3d179502d1425d38a09fa11d76f39c24a8a004cc | |
| parent | 5163206d9fe95980c52195eb266d93da15f3513d (diff) | |
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.
Approved by: so
Security: FreeBSD-SA-26:75.linux
Security: CVE-2026-101314
Reviewed by: adrian, markj
Approved by: adrian (mentor)
Differential Revision: https://reviews.freebsd.org/D61006
Signed-off-by: Nick Price <nprice@FreeBSD.org>
(cherry picked from commit fbe4835e6b1eec36103a5ce97efbab11b3b5fc72)
(cherry picked from commit a46d6ae4c0b6f6e8eb74b13da6f607d2ead74be7)
| -rw-r--r-- | sys/compat/linux/linux_xattr.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/compat/linux/linux_xattr.c b/sys/compat/linux/linux_xattr.c index 2eec33f8ef93..267cadedb986 100644 --- a/sys/compat/linux/linux_xattr.c +++ b/sys/compat/linux/linux_xattr.c @@ -139,7 +139,7 @@ listxattr(struct thread *td, struct listxattr_args *args) int attrnamespace, error; 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; @@ -189,6 +189,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); @@ -201,6 +208,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); |
