Re: [PATCH 2/2] revoke: break cow for private mappings

From: Nick Piggin
Date: Wed Mar 28 2007 - 04:05:06 EST


Pekka J Enberg wrote:
From: Pekka Enberg <penberg@xxxxxxxxxxxxxx>

We need to break COW for private mappings to make sure a process cannot
read new data after an inode has been revoked.

Seems OK.


Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxxxxxx>
---
fs/revoke.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 73 insertions(+), 12 deletions(-)

Index: uml-2.6/fs/revoke.c
===================================================================
--- uml-2.6.orig/fs/revoke.c 2007-03-26 18:10:24.000000000 +0300
+++ uml-2.6/fs/revoke.c 2007-03-26 18:27:25.000000000 +0300
@@ -174,12 +174,58 @@ static inline bool need_revoke(struct vm
if (file->f_path.dentry->d_inode != inode)
return false;
- if (!(vma->vm_flags & VM_SHARED))
- return false;
-
return file != to_exclude;
}
+static int __revoke_break_cow(struct task_struct *tsk, struct inode *inode,
+ struct file *to_exclude)
+{
+ struct mm_struct *mm = tsk->mm;
+ struct vm_area_struct *vma;
+ int err = 0;
+
+ down_write(&mm->mmap_sem);
+ for (vma = mm->mmap; vma != NULL; vma = vma->vm_next) {
+ int ret;
+
+ if (vma->vm_flags & VM_SHARED)
+ continue;
+
+ if (!need_revoke(vma, inode, to_exclude))
+ continue;
+
+ ret = get_user_pages(tsk, tsk->mm, vma->vm_start,
+ vma->vm_end-vma->vm_start, 1, 1, NULL,
+ NULL);

get_user_pages length argument is in # of pages, rather than address range,
I think. vma_pages is what you want?

+ if (ret < 0) {
+ err = ret;
+ break;
+ }
+ }
+ up_write(&mm->mmap_sem);

I think you just need down_read of mmap_sem here?

--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com -
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/