From: David Howells <dhowells@redhat.com>
To: torvalds@osdl.org, akpm@linux-foundation.org
Cc: viro@ZenIV.linux.org.uk, vapier@gentoo.org, lethal@linux-sh.org,
dhowells@redhat.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/6] NOMMU: Fix race between ramfs truncation and shared mmap
Date: Thu, 14 Jan 2010 13:58:51 +0000 [thread overview]
Message-ID: <20100114135850.10482.6205.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20100114135830.10482.54124.stgit@warthog.procyon.org.uk>
Fix the race between the truncation of a ramfs file and an attempt to make a
shared mmap of region of that file.
The problem is that do_mmap_pgoff() calls f_op->get_unmapped_area() to verify
that the file region is made of contiguous pages and to find its base address -
but there isn't any locking to guarantee this region until
vma_prio_tree_insert() is called by add_vma_to_mm().
Note that moving the functionality into f_op->mmap() doesn't help as that is
also called before vma_prio_tree_insert().
Instead make ramfs_nommu_check_mappings() grab nommu_region_sem whilst it does
its checks. This means that this function will wait whilst mmaps take place.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/ramfs/file-nommu.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index 2efc571..2665313 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -131,6 +131,8 @@ static int ramfs_nommu_check_mappings(struct inode *inode,
struct vm_area_struct *vma;
struct prio_tree_iter iter;
+ down_write(&nommu_region_sem);
+
/* search for VMAs that fall within the dead zone */
vma_prio_tree_foreach(vma, &iter, &inode->i_mapping->i_mmap,
newsize >> PAGE_SHIFT,
@@ -138,10 +140,13 @@ static int ramfs_nommu_check_mappings(struct inode *inode,
) {
/* found one - only interested if it's shared out of the page
* cache */
- if (vma->vm_flags & VM_SHARED)
+ if (vma->vm_flags & VM_SHARED) {
+ up_write(&nommu_region_sem);
return -ETXTBSY; /* not quite true, but near enough */
+ }
}
+ up_write(&nommu_region_sem);
return 0;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-01-14 13:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-14 13:58 [PATCH 1/6] NOMMU: Fix SYSV SHM for NOMMU David Howells
2010-01-14 13:58 ` [PATCH 2/6] NOMMU: struct vm_region's vm_usage count need not be atomic David Howells
2010-01-14 13:58 ` [PATCH 3/6] NOMMU: Remove a superfluous check of vm_region::vm_usage David Howells
2010-01-14 13:58 ` [PATCH 4/6] NOMMU: Don't need get_unmapped_area() for NOMMU David Howells
2010-01-14 13:58 ` David Howells [this message]
2010-01-14 13:58 ` [PATCH 6/6] NOMMU: Fix shared mmap after truncate shrinkage problems David Howells
-- strict thread matches above, loose matches on Subject: below --
2010-01-08 22:05 [PATCH 1/6] NOMMU: Fix SYSV SHM for NOMMU David Howells
2010-01-08 22:05 ` [PATCH 5/6] NOMMU: Fix race between ramfs truncation and shared mmap David Howells
2010-01-09 0:57 ` Mike Frysinger
2010-01-09 0:57 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100114135850.10482.6205.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=lethal@linux-sh.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=torvalds@osdl.org \
--cc=vapier@gentoo.org \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox