From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388087; b=rXZ7JyggqLI9GeSZpmaoSma9U1CNyzlHJzSk8qhkZmgPx6LizueZvoZ9qZp7m9tuKCzO 30gXyv4Wyv1Uxhv53fYrziwaH+wUdKDjahYsfAcNrgV0K9IzKXoRk0Ms6R40TloJdkosR zPfDN+yB88e96MrC80pXfdh4EhwR/rrcHYHlXGWYbxmYsiaLw9K27ih+aaaUa4qoOqJwZ j2AFhidVzdefY3XQxYfyz7CYmgfhZqGjYmYSmfBT52cY3q1VqwrGvcYlVpmMOYMwPWw3s KnVBmOpzb45dZCBS5vbQVEgCsRXoefljLD3gIpueIl7206pRu14XqkxL14UcxGc4NaA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388087; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=6Jddmcc1bMh7AR/32Cymew/5Ni5DxKGRNR0e2ZRDmyE=; b=0Bia4tZARR7Yq0IPwm0GGPZGos0kemG6uYx1/WekdB60yHbO7S537luMKhivHrsJ8UIb NaRaXJsEB66XWPjZf9n9Fpy6D9XHXK8J12YO8kvy/wHEwvQkUJIROfrGC9Mwckxe0vC28 RGaXVJoAQ1KC9u1nQ3ROpCDcbNzS2VyN3iJ2IUI9OKsjWRtfnJUkE8i1Z/IYi/NdsfddB hlbBQwk8DHdRB1pmBZZZv4dry3sH27JIcDYA5gDqqA274T5ou3VolxkKSKuaSUSLezjpx Htprf8N89cv0but60gyjv1o/lwbKfst7ZUc6BNDmO6M8Wv6MKh3yfB/RsRvIZdIDUtg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=AgUHjTQl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE389606A322; Fri, 4 Dec 2026 12:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=AgUHjTQl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FAD31F0092C; Fri, 4 Dec 2026 12:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388086; bh=6Jddmcc1bMh7AR/32Cymew/5Ni5DxKGRNR0e2ZRDmyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AgUHjTQlp4u/FLy6uyj4DqATuBo1e7e7Z9j5FLdEMUNv9jOwlHB9N4nx/MS8+7xQP jtfPyVmT3yu3bOlpxRhyVwF1JIYla7OxKeEtqGBIX5HX9PkFkX+xfHzvW0HfLOelbo 4bRJaui/qlw68SjtiiRTHout9pBuTSYkJz/IOdG0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dominik Maier , "Christian Brauner (Amutable)" , Sasha Levin Subject: [PATCH 6.1 0451/1059] xattr: always invoke cap_convert_nscap() for security.capability writes Date: Fri, 4 Dec 2026 18:59:42 +0900 Message-ID: <20261204100655.974153141@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dominik Maier [ Upstream commit 0f4a9e682f7fa5becc3af7204606d9bf4780e425 ] Commit 8db6c34f1dbc ("Introduce v3 namespaced file capabilities") changed cap_inode_setxattr() to return 0 unconditionally for XATTR_NAME_CAPS ("security.capability") and moved capability validation into cap_convert_nscap(), but placed the call inside the "if (size)" block in setxattr(). Commit 7c03e2cda4a5 ("vfs: move cap_convert_nscap() call into vfs_setxattr()") preserved that "size &&" condition in vfs_setxattr(): if (size && strcmp(name, XATTR_NAME_CAPS) == 0) { error = cap_convert_nscap(idmap, dentry, &value, size); ... } For security.* extended attributes, xattr_permission() skips inode_permission(MAY_WRITE) and leaves permission checks to the security module, while cap_inode_setxattr() returns 0 for XATTR_NAME_CAPS assuming cap_convert_nscap() has already validated the write. Because __vfs_setxattr() treats size == 0 as an empty attribute write (setting value = "") rather than a removal, calling setxattr(2) on "security.capability" with size == 0 bypasses cap_convert_nscap() and allows an unprivileged caller without CAP_SETFCAP or write permission on the target inode to write a 0-byte security.capability xattr (or overwrite an existing one). When that binary is subsequently executed, get_vfs_caps_from_disk() reads the 0-byte security.capability xattr and fails the size < sizeof(magic_etc) check with -EINVAL, causing execve(2) to fail with -EINVAL. Always invoke cap_convert_nscap() when strcmp(name, XATTR_NAME_CAPS) == 0 regardless of size, so that 0-byte writes hit the existing !*ivalue / !validheader() checks in cap_convert_nscap() and are rejected with -EINVAL. Fixes: 8db6c34f1dbc ("Introduce v3 namespaced file capabilities") Signed-off-by: Dominik Maier Link: https://patch.msgid.link/20261022232119.2537209-1-dmnk@google.com Signed-off-by: Christian Brauner (Amutable) [ sashal: Adjusted the context lines to use struct user_namespace *mnt_userns instead of const struct mnt_idmap *idmap in the cap_convert_nscap() call. ] Signed-off-by: Sasha Levin --- fs/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xattr.c b/fs/xattr.c index 427b8cea1f968..deae26650abda 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -297,7 +297,7 @@ vfs_setxattr(struct user_namespace *mnt_userns, struct dentry *dentry, const void *orig_value = value; int error; - if (size && strcmp(name, XATTR_NAME_CAPS) == 0) { + if (strcmp(name, XATTR_NAME_CAPS) == 0) { error = cap_convert_nscap(mnt_userns, dentry, &value, size); if (error < 0) return error; -- 2.53.0