[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ux7jzkh4qcnldneer26gbajssjfeyqhcz7t26d7otri357xpa5@srgguo7dloqq>
Date: Fri, 18 Oct 2024 13:55:42 +0300
From: "Kirill A. Shutemov" <kirill@...temov.name>
To: Roberto Sassu <roberto.sassu@...weicloud.com>
Cc: Paul Moore <paul@...l-moore.com>, ebpqwerty472123@...il.com,
kirill.shutemov@...ux.intel.com, zohar@...ux.ibm.com, dmitry.kasatkin@...il.com,
eric.snowberg@...cle.com, jmorris@...ei.org, serge@...lyn.com,
linux-integrity@...r.kernel.org, linux-security-module@...r.kernel.org,
linux-kernel@...r.kernel.org, bpf@...r.kernel.org, Roberto Sassu <roberto.sassu@...wei.com>,
linux-mm@...ck.org, akpm@...ux-foundation.org, vbabka@...e.cz,
lorenzo.stoakes@...cle.com, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH 1/3] ima: Remove inode lock
On Fri, Oct 18, 2024 at 01:53:03PM +0300, Kirill A. Shutemov wrote:
> > + mmap_read_unlock(mm);
> > +
> > + ret = security_mmap_file(vma->vm_file, prot, flags);
> > + if (ret) {
> > + fput(file);
> > + return ret;
> > + }
> > +
>
> Emm. We need to restore 'ret' to -EINVAL here:
>
> +
> + ret = -EINVAL;
> +
>
> > if (mmap_write_lock_killable(mm))
> > return -EINTR;
> >
And fput() here on error.
Updated patch:
diff --git a/mm/mmap.c b/mm/mmap.c
index dd4b35a25aeb..7c1b73a79937 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1646,14 +1646,41 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
if (pgoff + (size >> PAGE_SHIFT) < pgoff)
return ret;
- if (mmap_write_lock_killable(mm))
+ if (mmap_read_lock_killable(mm))
return -EINTR;
vma = vma_lookup(mm, start);
+ if (!vma || !(vma->vm_flags & VM_SHARED)) {
+ mmap_read_unlock(mm);
+ return -EINVAL;
+ }
+
+ file = get_file(vma->vm_file);
+
+ mmap_read_unlock(mm);
+
+ ret = security_mmap_file(vma->vm_file, prot, flags);
+ if (ret) {
+ fput(file);
+ return ret;
+ }
+
+ ret = -EINVAL;
+
+ if (mmap_write_lock_killable(mm)) {
+ fput(file);
+ return -EINTR;
+ }
+
+ vma = vma_lookup(mm, start);
+
if (!vma || !(vma->vm_flags & VM_SHARED))
goto out;
+ if (vma->vm_file != file)
+ goto out;
+
if (start + size > vma->vm_end) {
VMA_ITERATOR(vmi, mm, vma->vm_end);
struct vm_area_struct *next, *prev = vma;
@@ -1688,16 +1715,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
if (vma->vm_flags & VM_LOCKED)
flags |= MAP_LOCKED;
- file = get_file(vma->vm_file);
- ret = security_mmap_file(vma->vm_file, prot, flags);
- if (ret)
- goto out_fput;
ret = do_mmap(vma->vm_file, start, size,
prot, flags, 0, pgoff, &populate, NULL);
-out_fput:
- fput(file);
out:
mmap_write_unlock(mm);
+ fput(file);
if (populate)
mm_populate(ret, populate);
If (!IS_ERR_VALUE(ret))
--
Kiryl Shutsemau / Kirill A. Shutemov
Powered by blists - more mailing lists