Re: [PATCH 0/3] Fix incorrect overlayfs mmap() and mprotect() LSM access controls
Paul Moore <[email protected]>
| Newsgroups | org.kernel.vger.linux-unionfs,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-security-module,org.kernel.vger.selinux,org.ozlabs.lists.linux-erofs |
|---|---|
| Message-ID | <CAHC9VhTEX-sRjyVi2p9j_jFjyWbzy54b=iteiTKGq-mnBaHkrg@mail.gmail.com> |
On Mon, Mar 16, 2026 at 5:36 PM Paul Moore <[email protected]> wrote: > > The existing mmap() and mprotect() LSM access control points for the > overlayfs filesystem are incomplete in that they do not cover both the > user and backing files. This patchset corrects this through the addition > of a new backing file specific LSM hook, security_mmap_backing_file(), > a new user path file associated with a backing file that can be used by > LSMs in the security_file_mprotect() code path, and the associated > SELinux code changes. > > The security_mmap_backing_file() hook is intended to allow LSMs to apply > access controls on mmap() operations accessing a backing file, similar to > the security_mmap_file() for user files. Due to the details around the > accesses and the desire to distinguish between the two types of accesses, > a new LSM hook was needed. More information on this new hook can be > found in the associated patch. > > The new user path file replaces the existing user path stored in the > backing file. This change was necessary to support LSM based access > controls in the mprotect() code path where only one file is accessible > via the vma->vm_file field. Unfortunately, storing a reference to the > user file inside the backing file does not work due to the cyclic > ref counting so a stand-in was necessary, the new user O_PATH file. > This new O_PATH file is intended to be representative of the original > user file and can be used by LSMs to make access control decisions based > on both the backing and user files. > > The SELinux changes in this patchset involve making use of the new > security_mmap_backing_file() hook and updating the existing mprotect() > access controls to take into account both the backing and user files. > These changes preserve the existing SELinux approach of allowing access > on overlayfs files if the current task has the necessary rights to the > user file and the mounting process has the necessary rights to the > underlying backing file. > > -- > Amir Goldstein (1): > backing_file: store user_path_file > > Paul Moore (2): > lsm: add the security_mmap_backing_file() hook > selinux: fix overlayfs mmap() and mprotect() access checks > > fs/backing-file.c | 28 +++++--- > fs/erofs/ishare.c | 12 ++- > fs/file_table.c | 53 +++++++++++++--- > fs/fuse/passthrough.c | 3 > fs/internal.h | 5 - > fs/overlayfs/dir.c | 3 > fs/overlayfs/file.c | 1 > include/linux/backing-file.h | 29 ++++++++- > include/linux/file_ref.h | 10 --- > include/linux/lsm_audit.h | 2 > include/linux/lsm_hook_defs.h | 2 > include/linux/security.h | 10 +++ > security/security.c | 25 +++++++ > security/selinux/hooks.c | 108 ++++++++++++++++++++++++++++------ > 14 files changed, 231 insertions(+), 60 deletions(-) Due to the nature of the issue, I'm going to merge this into lsm/stable-7.0 in a few moments so the changes can get some testing in linux-next with the idea of sending this up to Linus' later in the week. If anyone has any concerns over this patchset, please let me know as soon as possible. -- paul-moore.com