diff options
author | Willy Tarreau <w@1wt.eu> | 2018-05-11 02:11:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-05-17 12:27:47 -0400 |
commit | 7f7ccc2ccc2e70c6054685f5e3522efa81556830 (patch) | |
tree | 7309cb80e03910053c21d5b003ed1d6b2dcacc16 | |
parent | e6506eb241871d68647c53cb6d0a16299550ae97 (diff) |
proc: do not access cmdline nor environ from file-backed areas
proc_pid_cmdline_read() and environ_read() directly access the target
process' VM to retrieve the command line and environment. If this
process remaps these areas onto a file via mmap(), the requesting
process may experience various issues such as extra delays if the
underlying device is slow to respond.
Let's simply refuse to access file-backed areas in these functions.
For this we add a new FOLL_ANON gup flag that is passed to all calls
to access_remote_vm(). The code already takes care of such failures
(including unmapped areas). Accesses via /proc/pid/mem were not
changed though.
This was assigned CVE-2018-1120.
Note for stable backports: the patch may apply to kernels prior to 4.11
but silently miss one location; it must be checked that no call to
access_remote_vm() keeps zero as the last argument.
Reported-by: Qualys Security Advisory <qsa@qualys.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/proc/base.c | 8 | ||||
-rw-r--r-- | include/linux/mm.h | 1 | ||||
-rw-r--r-- | mm/gup.c | 3 |
3 files changed, 8 insertions, 4 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 1b2ede6abcdf..1a76d751cf3c 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -261,7 +261,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, | |||
261 | * Inherently racy -- command line shares address space | 261 | * Inherently racy -- command line shares address space |
262 | * with code and data. | 262 | * with code and data. |
263 | */ | 263 | */ |
264 | rv = access_remote_vm(mm, arg_end - 1, &c, 1, 0); | 264 | rv = access_remote_vm(mm, arg_end - 1, &c, 1, FOLL_ANON); |
265 | if (rv <= 0) | 265 | if (rv <= 0) |
266 | goto out_free_page; | 266 | goto out_free_page; |
267 | 267 | ||
@@ -279,7 +279,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, | |||
279 | int nr_read; | 279 | int nr_read; |
280 | 280 | ||
281 | _count = min3(count, len, PAGE_SIZE); | 281 | _count = min3(count, len, PAGE_SIZE); |
282 | nr_read = access_remote_vm(mm, p, page, _count, 0); | 282 | nr_read = access_remote_vm(mm, p, page, _count, FOLL_ANON); |
283 | if (nr_read < 0) | 283 | if (nr_read < 0) |
284 | rv = nr_read; | 284 | rv = nr_read; |
285 | if (nr_read <= 0) | 285 | if (nr_read <= 0) |
@@ -325,7 +325,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, | |||
325 | bool final; | 325 | bool final; |
326 | 326 | ||
327 | _count = min3(count, len, PAGE_SIZE); | 327 | _count = min3(count, len, PAGE_SIZE); |
328 | nr_read = access_remote_vm(mm, p, page, _count, 0); | 328 | nr_read = access_remote_vm(mm, p, page, _count, FOLL_ANON); |
329 | if (nr_read < 0) | 329 | if (nr_read < 0) |
330 | rv = nr_read; | 330 | rv = nr_read; |
331 | if (nr_read <= 0) | 331 | if (nr_read <= 0) |
@@ -946,7 +946,7 @@ static ssize_t environ_read(struct file *file, char __user *buf, | |||
946 | max_len = min_t(size_t, PAGE_SIZE, count); | 946 | max_len = min_t(size_t, PAGE_SIZE, count); |
947 | this_len = min(max_len, this_len); | 947 | this_len = min(max_len, this_len); |
948 | 948 | ||
949 | retval = access_remote_vm(mm, (env_start + src), page, this_len, 0); | 949 | retval = access_remote_vm(mm, (env_start + src), page, this_len, FOLL_ANON); |
950 | 950 | ||
951 | if (retval <= 0) { | 951 | if (retval <= 0) { |
952 | ret = retval; | 952 | ret = retval; |
diff --git a/include/linux/mm.h b/include/linux/mm.h index 1ac1f06a4be6..c080af584ddd 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -2493,6 +2493,7 @@ static inline struct page *follow_page(struct vm_area_struct *vma, | |||
2493 | #define FOLL_MLOCK 0x1000 /* lock present pages */ | 2493 | #define FOLL_MLOCK 0x1000 /* lock present pages */ |
2494 | #define FOLL_REMOTE 0x2000 /* we are working on non-current tsk/mm */ | 2494 | #define FOLL_REMOTE 0x2000 /* we are working on non-current tsk/mm */ |
2495 | #define FOLL_COW 0x4000 /* internal GUP flag */ | 2495 | #define FOLL_COW 0x4000 /* internal GUP flag */ |
2496 | #define FOLL_ANON 0x8000 /* don't do file mappings */ | ||
2496 | 2497 | ||
2497 | static inline int vm_fault_to_errno(int vm_fault, int foll_flags) | 2498 | static inline int vm_fault_to_errno(int vm_fault, int foll_flags) |
2498 | { | 2499 | { |
@@ -544,6 +544,9 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) | |||
544 | if (vm_flags & (VM_IO | VM_PFNMAP)) | 544 | if (vm_flags & (VM_IO | VM_PFNMAP)) |
545 | return -EFAULT; | 545 | return -EFAULT; |
546 | 546 | ||
547 | if (gup_flags & FOLL_ANON && !vma_is_anonymous(vma)) | ||
548 | return -EFAULT; | ||
549 | |||
547 | if (write) { | 550 | if (write) { |
548 | if (!(vm_flags & VM_WRITE)) { | 551 | if (!(vm_flags & VM_WRITE)) { |
549 | if (!(gup_flags & FOLL_FORCE)) | 552 | if (!(gup_flags & FOLL_FORCE)) |