git: 0967b36fe783 - stable/15 - extattr_list*: avoid panic with absurd buffer lengths

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Mon, 16 Nov 2026 10:45:50 UTC
The branch stable/15 has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=0967b36fe7837e4b1727ec1230ef1ee28ea6db8c

commit 0967b36fe7837e4b1727ec1230ef1ee28ea6db8c
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-13 10:06:52 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-16 10:45:15 +0000

    extattr_list*: avoid panic with absurd buffer lengths
    
    Apply a layered defence:
     - Reject nbytes > IOSIZE_MAX in user_extattr_list_fd and
       user_extattr_list_path.
     - In extattr_list_vp require auiop->uio_resid to be non-negative.
    
    Effort:         CHERI upstreaming
    Reviewed by:    markj
    Reported by:    llm-postcr
    MFC after:      3 days
    Sponsored by:   Innovate UK
    Fixes:          6453d4240f6b ("vfs: Export exattr methods to reuse by Linuxulator")
    Differential Revision:  https://reviews.freebsd.org/D61461
    
    (cherry picked from commit 118067f51c111390dbc54760d781cd14a10c499e)
---
 sys/kern/vfs_extattr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c
index 1fe7494f3998..1614b15db553 100644
--- a/sys/kern/vfs_extattr.c
+++ b/sys/kern/vfs_extattr.c
@@ -693,7 +693,7 @@ extattr_list_vp(struct vnode *vp, int attrnamespace, struct uio *auiop,
 	sizep = NULL;
 	cnt = 0;
 	if (auiop != NULL) {
-		if (auiop->uio_resid > IOSIZE_MAX)
+		if (auiop->uio_resid < 0 || auiop->uio_resid > IOSIZE_MAX)
 			return (EINVAL);
 		cnt = auiop->uio_resid;
 	} else
@@ -735,6 +735,9 @@ sys_extattr_list_fd(struct thread *td, struct extattr_list_fd_args *uap)
 	struct uio auio, *auiop;
 	struct iovec aiov;
 
+	if (uap->nbytes > IOSIZE_MAX)
+		return (EINVAL);
+
 	if (uap->data != NULL) {
 		aiov.iov_base = uap->data;
 		aiov.iov_len = uap->nbytes;
@@ -813,6 +816,9 @@ user_extattr_list_path(struct thread *td, const char *path, int attrnamespace,
 	struct uio auio, *auiop;
 	struct iovec aiov;
 
+	if (nbytes > IOSIZE_MAX)
+		return (EINVAL);
+
 	if (data != NULL) {
 		aiov.iov_base = data;
 		aiov.iov_len = nbytes;