]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.160/floppy-do-not-copy-a-kernel-pointer-to-user-memory-in-fdgetprm-ioctl.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.160 / floppy-do-not-copy-a-kernel-pointer-to-user-memory-in-fdgetprm-ioctl.patch
CommitLineData
a6e7b84f
GKH
1From 65eea8edc315589d6c993cf12dbb5d0e9ef1fe4e Mon Sep 17 00:00:00 2001
2From: Andy Whitcroft <apw@canonical.com>
3Date: Thu, 20 Sep 2018 09:09:48 -0600
4Subject: floppy: Do not copy a kernel pointer to user memory in FDGETPRM ioctl
5
6From: Andy Whitcroft <apw@canonical.com>
7
8commit 65eea8edc315589d6c993cf12dbb5d0e9ef1fe4e upstream.
9
10The final field of a floppy_struct is the field "name", which is a pointer
11to a string in kernel memory. The kernel pointer should not be copied to
12user memory. The FDGETPRM ioctl copies a floppy_struct to user memory,
13including this "name" field. This pointer cannot be used by the user
14and it will leak a kernel address to user-space, which will reveal the
15location of kernel code and data and undermine KASLR protection.
16
17Model this code after the compat ioctl which copies the returned data
18to a previously cleared temporary structure on the stack (excluding the
19name pointer) and copy out to userspace from there. As we already have
20an inparam union with an appropriate member and that memory is already
21cleared even for read only calls make use of that as a temporary store.
22
23Based on an initial patch by Brian Belleville.
24
25CVE-2018-7755
26Signed-off-by: Andy Whitcroft <apw@canonical.com>
27Broke up long line.
28Signed-off-by: Jens Axboe <axboe@kernel.dk>
29Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30
31---
32 drivers/block/floppy.c | 3 +++
33 1 file changed, 3 insertions(+)
34
35--- a/drivers/block/floppy.c
36+++ b/drivers/block/floppy.c
37@@ -3459,6 +3459,9 @@ static int fd_locked_ioctl(struct block_
38 (struct floppy_struct **)&outparam);
39 if (ret)
40 return ret;
41+ memcpy(&inparam.g, outparam,
42+ offsetof(struct floppy_struct, name));
43+ outparam = &inparam.g;
44 break;
45 case FDMSGON:
46 UDP->flags |= FTD_MSG;