[PATCH] loop: prevent get_user pages call from kernel thread(v2) | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
Yes... everybody know that it is bad to write from kernel thread, and it is
madness to do it with O_DIRECT. But occasionly file with O_DIRECT flag
may be passed to loop device via LOOP_SET_FD. So if file-system has't
address_space ops, or simply hide it like GFS, it is possible to kill kernel
via two lines program. In fact we can't effectively guard kernel space by
deny O_DIRECT in loop's code, because user space can set it via
fcntl(,F_SETFL,). Let's simply add sanity check mm related logic.
Signed-off-by: Dmitri Monakhov <dmonakhov@xxxxxxxxxx>
---
drivers/block/loop.c | 5 +++++
fs/direct-io.c | 4 ++++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d3a25b0..01e2133 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -789,6 +789,11 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
if (!(lo_file->f_mode & FMODE_WRITE))
lo_flags |= LO_FLAGS_READ_ONLY;
+ /* We can't use f_op->write with O_DIRECT from kernel thread. */
+ if (!(lo_flags & (LO_FLAGS_USE_AOPS | LO_FLAGS_READ_ONLY)) &&
+ file->f_mode & O_DIRECT)
+ goto out_putf;
+
set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0);
lo->lo_blocksize = lo_blocksize;
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 9606ee8..c383766 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -149,6 +149,10 @@ static int dio_refill_pages(struct dio *dio)
int ret;
int nr_pages;
+ if (unlikely(!current->mm)) {
+ WARN_ON_ONCE(1);
+ return -EINVAL;
+ }
nr_pages = min(dio->total_pages - dio->curr_page, DIO_PAGES);
ret = get_user_pages_fast(
dio->curr_user_address, /* Where from? */
--
1.5.4.rc4
--
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/
[Site Home] [Other Archives] [Linux Kernel Newbies] [Linux Kernel Testers] [Linux SH] [Linux Omap] [Linux Kbuild] [Linux Tape] [Linux Input] [Linux Kernel Janitors] [Linux Doc] [Linux Man Pages] [Linux Standards] [Kernel Announce] [Memory] [Netdev] [Git] [Linux PCI] [NUMA] [Netfilter] [Netfilter Devel] [SELinux] [Bugtraq] [Writing Drivers] [Linux Serial] [Linux PPP] [Kernel MM Commits] [Linux Security Module] [Ext4] [Linux BTRFS] [Linux NFS] [Linux Cachefs] [Reiser FS] [Fastboot] [Linux RT Users] [Linux Virtualization] [LVS Devel] [KVM] [KVM PPC] [KVM ia64] [Linux Containers] [Util Linux NG] [Sk Drivers] [Wireless] [Linux Bluetooth] [Ethernet Bridging] [Embedded Linux] [Sparse] [Linux Arch] [Linux ACPI] [Linux IBM ACPI] [Linux OpenGL] [Linux Power Management] [Linux DCCP] [ALSA Devel] [Linux USB] [Large Format Photos] [DVD Store] [Tux] [Gimp] [Yosemite News] [Linux PA RISC] [MIPS Linux] [S390 Linux] [ARM Linux] [ARM Kernel] [Sparc Linux] [Linux Security] [Linux Sound] [Video 4 Linux] [Linux for the blind] [Linux IDE] [Linux RAID] [Linux SCSI] [Linux SMP] [Linux AXP] [Linux Alpha] [Linux M68K] [Linux ia64] [Linux 8086] [Linux x86_64] [Linux Apps] [Linux X.25] [Linux Crypto] [DM Crypt] [LInux Btrace] [Utrace Devel] [Yosemite Photos] [Linux Resources] [Older Kernel Mail]
![]() |
![]() |