From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24CA23B3BE9; Wed, 23 Sep 2026 14:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790173862; cv=none; b=adJkD8LEoMEACyd9BalbYAecjaPpH9APuosjyLQOvxyocvO0STDwKf8asCQfR4+0w0wPMFCm7mdY8/aDnQTgwVpZT8PWrxkJLpALyt4V+oiwNWZAnpqFYvmIX2Omd3hz09VXzAZA5NGFAIqNMu8JBGPmC3DQVDKXr1k7DLyF8jw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790173862; c=relaxed/simple; bh=nnqgcpEmBz5ZuYFXqpAa8iU763LPJgndw7FtkrgfFqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ll17PF5v+DyMMbrYQYeXJGJA6IrTjkJgKgdl8iShxiTl1WonfFWRqnHcnKI/HG5VUv3Tt5sBIQRhm+2GgUcNlPtvRuBQYJ2R8wdfJV1qmLj1Cuwof/pmyUZa7cMpHj4XsZJlVeg6UGPRVGDeaPJ2HzXzQ5UUIszeE47HYC7rwVA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eleZ4lz0; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="eleZ4lz0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A509A1F000FF; Wed, 23 Sep 2026 14:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790173861; bh=8BukgdFaa1GXJosxOdcCdZ4nAySZ4gTgHeFxNRIKgUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eleZ4lz0TYWlJQYUDkPVey0GfB8zUCwIjjLDns/i/8pLSVKwqTYoVaAYm78tz6qMH SdT4C7ASNTBSC+g006mkShmq8xZ5sCysq6r6ffNyttU9J/RN7KlxYTGfZjCh/UIC5H mc8nDUa0n9K+ATAzTqujVPfnQgyVVef5SX3bPX9M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Karl Mehltretter , Amir Goldstein , Stephen Smalley , Paul Moore Subject: [PATCH 7.2 333/438] selinux: preserve user SID across nested backing files Date: Wed, 23 Sep 2026 16:05:54 +0200 Message-ID: <20260923140653.441680814@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260923140644.756254324@linuxfoundation.org> References: <20260923140644.756254324@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Karl Mehltretter commit 8c0c602202b9a4909b00bc3354e3c0355bc69e65 upstream. SELinux saves the user file SID in a backing-file security blob so it remains available after mmap() replaces vma->vm_file with a backing file. For nested backing files (overlayfs over overlayfs, or FUSE passthrough backed by overlayfs), user_file may itself be a backing file. Its fsec->sid is the SID of the mounter that opened it, rather than the user that opened the top-level file. mprotect() then checks fd { use } against the mounter SID. This can incorrectly deny access without a domain transition, or check the wrong target SID after one. Copy the saved user SID when user_file is a backing file. Keep using the regular file SID for the first backing layer. With two nested overlayfs mounts and SELinux enforcing, mprotect(PROT_READ) returns EACCES with an fd { use } denial against the mounter SID. With this change, mprotect() succeeds. Tested on arm64 QEMU with a small BusyBox initramfs and a purpose-built SELinux policy. The original test was also repeated with Fedora Cloud Base 44 userspace and gave the same result. Cc: stable@vger.kernel.org Fixes: 82544d36b172 ("selinux: fix overlayfs mmap() and mprotect() access checks") Assisted-by: LLM Signed-off-by: Karl Mehltretter Reviewed-by: Amir Goldstein Reviewed-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/hooks.c | 9 ++++++++- security/selinux/include/objsec.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3841,13 +3841,20 @@ static int selinux_file_alloc_security(s return 0; } +static inline u32 selinux_file_user_sid(const struct file *file) +{ + if (unlikely(file->f_mode & FMODE_BACKING)) + return selinux_backing_file(file)->uf_sid; + return selinux_file(file)->sid; +} + static int selinux_backing_file_alloc(struct file *backing_file, const struct file *user_file) { struct backing_file_security_struct *bfsec; bfsec = selinux_backing_file(backing_file); - bfsec->uf_sid = selinux_file(user_file)->sid; + bfsec->uf_sid = selinux_file_user_sid(user_file); return 0; } --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -87,7 +87,7 @@ struct file_security_struct { }; struct backing_file_security_struct { - u32 uf_sid; /* associated user file fsec->sid */ + u32 uf_sid; /* top-level user file fsec->sid */ }; struct superblock_security_struct {