]> www.infradead.org Git - users/willy/linux.git/commitdiff
mshare: Attach an mm_struct to the file descriptor
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 10 Aug 2020 13:29:31 +0000 (09:29 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 10 Aug 2020 13:29:31 +0000 (09:29 -0400)
Allocate and free the mm_struct.  Still can't do anything with it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
mm/mshare.c

index 72af82683fdb285a5fdb85ce805892626aba5455..525f624adedec5eb1ef0189295afd26710af91c5 100644 (file)
@@ -1,19 +1,35 @@
 #include <linux/anon_inodes.h>
 #include <linux/fs.h>
+#include <linux/sched/mm.h>
 #include <linux/syscalls.h>
 
+int mshare_release(struct inode *inode, struct file *file)
+{
+       struct mm_struct *mm = file->private_data;
+
+       mmput(mm);
+
+       return 0;
+}
+
 static const struct file_operations mshare_fops = {
+       .release = mshare_release,
 };
 
 SYSCALL_DEFINE3(mshare, unsigned long, addr, unsigned long, len,
                unsigned long, flags)
 {
+       struct mm_struct *mm;
        int fd;
 
        if ((addr | len) & (PGDIR_SIZE - 1))
                return -EINVAL;
 
-       fd = anon_inode_getfd("mshare", &mshare_fops, NULL, O_RDWR);
+       mm = mm_alloc();
+       if (!mm)
+               return -ENOMEM;
+
+       fd = anon_inode_getfd("mshare", &mshare_fops, mm, O_RDWR);
 
        return fd;
 }