Re: [PATCH 2/3] lsm: add the security_mmap_backing_file() hook
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 | <CAHC9VhTiB73F9fB1o3K4NfJ-Fa50MsVA_=79kn6X34L62J_TwA@mail.gmail.com> |
On Mon, Mar 16, 2026 at 5:36 PM Paul Moore <[email protected]> wrote: > > Add the security_mmap_backing_file() hook to allow LSMs to properly > enforce access controls on mmap() operations on stacked filesystems > such as overlayfs. > > The existing security_mmap_file() hook exists as an access control point > for mmap() but on stacked filesystems it only provides a way to enforce > access controls on the user visible file. In order to enforce access > controls on the underlying backing file, the new > security_mmap_backing_file() hook is needed. > > In addition the LSM hook additions, this patch also constifies the file > struct field in the LSM common_audit_data struct to better support LSMs > that will likely need to pass a const file struct pointer from the new > backing_file_user_path_file() API into the common LSM audit code. > > Reviewed-by: Amir Goldstein <[email protected]> > Signed-off-by: Paul Moore <[email protected]> > --- > fs/backing-file.c | 8 +++++++- > fs/erofs/ishare.c | 6 ++++++ > include/linux/lsm_audit.h | 2 +- > include/linux/lsm_hook_defs.h | 2 ++ > include/linux/security.h | 10 ++++++++++ > security/security.c | 25 +++++++++++++++++++++++++ > 6 files changed, 51 insertions(+), 2 deletions(-) ... > diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c > index 17a4941d4518..d66c3a935d83 100644 > --- a/fs/erofs/ishare.c > +++ b/fs/erofs/ishare.c > @@ -150,8 +150,14 @@ static ssize_t erofs_ishare_file_read_iter(struct kiocb *iocb, > static int erofs_ishare_mmap(struct file *file, struct vm_area_struct *vma) > { > struct file *realfile = file->private_data; > + int err; > > vma_set_file(vma, realfile); > + > + err = security_mmap_backing_file(vma, realfile, file); > + if (err) > + return err; > + > return generic_file_readonly_mmap(file, vma); > } The kernel test robot helpfully pointed out that this patch was missing a security.h include for the newly added LSM hook. The fixup below has been applied to the patch in lsm/stable-7.0. diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c index d66c3a935d83..f80925b66599 100644 --- a/fs/erofs/ishare.c +++ b/fs/erofs/ishare.c @@ -4,6 +4,7 @@ */ #include <linux/xxhash.h> #include <linux/mount.h> +#include <linux/security.h> #include "internal.h" #include "xattr.h" -- paul-moore.com