floppy: don't write kernel-only members to FDRAWCMD ioctl output
authorMatthew Daley <mattd@bugfuzz.com>
Mon, 28 Apr 2014 07:05:21 +0000 (19:05 +1200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 May 2014 05:54:39 +0000 (07:54 +0200)
Do not leak kernel-only floppy_raw_cmd structure members to userspace.
This includes the linked-list pointer and the pointer to the allocated
DMA space.

Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 2145e15e0557a01b9195d1c7199a1b92cb9be81f)
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/block/floppy.c

index 19d45e6c2b9b001447a9a1be8fe8c1e3c67051d6..f959aad30ca1e1785a5571b3abab8673644df79c 100644 (file)
@@ -3162,7 +3162,12 @@ static inline int raw_cmd_copyout(int cmd, char __user *param,
        int ret;
 
        while (ptr) {
-               COPYOUT(*ptr);
+               struct floppy_raw_cmd cmd = *ptr;
+               cmd.next = NULL;
+               cmd.kernel_data = NULL;
+               ret = copy_to_user((void __user *)param, &cmd, sizeof(cmd));
+               if (ret)
+                       return -EFAULT;
                param += sizeof(struct floppy_raw_cmd);
                if ((ptr->flags & FD_RAW_READ) && ptr->buffer_length) {
                        if (ptr->length >= 0