git: 4dc5ef514432 - main - linux(4): compare xattr namespace names with strcmp()

From: Nick Price <nprice_at_FreeBSD.org>
Date: Wed, 25 Nov 2026 04:37:10 UTC
The branch main has been updated by nprice:

URL: https://cgit.FreeBSD.org/src/commit/?id=4dc5ef514432c068229c50d8146730830845df14

commit 4dc5ef514432c068229c50d8146730830845df14
Author:     Nick Price <nprice@FreeBSD.org>
AuthorDate: 2026-11-25 04:36:16 +0000
Commit:     Nick Price <nprice@FreeBSD.org>
CommitDate: 2026-11-25 04:36:16 +0000

    linux(4): compare xattr namespace names with strcmp()
    
    xattr_to_extattr() compared each namespace over the length of the
    caller's prefix and would read past the end of any shorter name
    
    the values are already null-terminated so we can just use strcmp()
    here
    
    Reviewed by:    rmoeller
    Differential Revision:  https://reviews.freebsd.org/D60954
---
 sys/compat/linux/linux_xattr.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/sys/compat/linux/linux_xattr.c b/sys/compat/linux/linux_xattr.c
index 6bba5346c748..5e8728c9667d 100644
--- a/sys/compat/linux/linux_xattr.c
+++ b/sys/compat/linux/linux_xattr.c
@@ -106,7 +106,7 @@ static int
 xattr_to_extattr(const char *uattrname, int *attrnamespace, char *attrname)
 {
 	char uname[LINUX_XATTR_NAME_MAX + 1], *dot;
-	size_t len, cplen;
+	size_t cplen;
 	int error;
 
 	error = copyinstr(uattrname, uname, sizeof(uname), &cplen);
@@ -121,11 +121,9 @@ xattr_to_extattr(const char *uattrname, int *attrnamespace, char *attrname)
 	for (*attrnamespace = EXTATTR_NAMESPACE_USER;
 	    *attrnamespace < nitems(extattr_namespace_names);
 	    (*attrnamespace)++) {
-		if (bcmp(uname, extattr_namespace_names[*attrnamespace],
-		    dot - uname + 1) == 0) {
-			dot++;
-			len = strlen(dot) + 1;
-			bcopy(dot, attrname, len);
+		if (strcmp(uname,
+		    extattr_namespace_names[*attrnamespace]) == 0) {
+			strlcpy(attrname, dot + 1, LINUX_XATTR_NAME_MAX + 1);
 			return (0);
 		}
 	}