3.16.45-rc1 review
cover 3.16.45-rc1 review
This is the start of the stable review cycle for the 3.16.45 release. There are 7 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu Jun 29 11:10:33 UTC 2017. Anything received after that time might be too late.
A combined patch relative to 3.16.44 will be posted as an additional response to this. A shortlog and diffstat can be found below.
Ben.
-------------
David Howells (1):
rxrpc: Fix several cases where a padded len isn't checked in ticket decode
[5f2f97656ada8d811d3c1bef503ced266fcd53a0]
Helge Deller (1):
Allow stack to grow up to address space limit
[bd726c90b6b8ce87602208701b208a208e6d5600]
Hugh Dickins (2):
mm: fix new crash in unmapped_area_topdown()
[f4cb767d76cf7ee72f97dd76f6cfa6c76a5edc89]
mm: larger stack guard gap, between vmas
[1be7107fbe18eed3e319a6c3e83c78254b693acb]
Paolo Bonzini (1):
KVM: x86: fix singlestepping over syscall
[c8401dda2f0a00cd25c0af6a95ed50e478d25de4]
Seung-Woo Kim (1):
regulator: core: Fix regualtor_ena_gpio_free not to access pin after freeing
[60a2362f769cf549dc466134efe71c8bf9fbaaba]
Vladis Dronov (1):
drm/vmwgfx: limit the number of mip levels in vmw_gb_surface_define_ioctl()
[ee9c4e681ec4f58e42a83cb0c22a0289ade1aacf]
Documentation/kernel-parameters.txt | 7 ++ Makefile | 4 +- arch/arc/mm/mmap.c | 2 +- arch/arm/mm/mmap.c | 4 +- arch/frv/mm/elf-fdpic.c | 2 +- arch/mips/mm/mmap.c | 2 +- arch/parisc/kernel/sys_parisc.c | 15 +-- arch/powerpc/mm/slice.c | 2 +- arch/sh/mm/mmap.c | 4 +- arch/sparc/kernel/sys_sparc_64.c | 4 +- arch/sparc/mm/hugetlbpage.c | 2 +- arch/tile/mm/hugetlbpage.c | 2 +- arch/x86/include/asm/kvm_emulate.h | 1 + arch/x86/kernel/sys_x86_64.c | 4 +- arch/x86/kvm/emulate.c | 1 + arch/x86/kvm/x86.c | 53 +++++------ arch/x86/mm/hugetlbpage.c | 2 +- arch/xtensa/kernel/syscall.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 3 + drivers/regulator/core.c | 2 + fs/hugetlbfs/inode.c | 2 +- fs/proc/task_mmu.c | 4 - include/linux/mm.h | 53 +++++------ mm/gup.c | 5 - mm/memory.c | 38 -------- mm/mmap.c | 160 +++++++++++++++++++------------- net/rxrpc/ar-key.c | 64 +++++++------ 27 files changed, 220 insertions(+), 224 deletions(-)
Signature · 2 lines
Ben Hutchings Absolutum obsoletum. (If it works, it's out of date.) - Stafford Beer
PATCH 1/7 mm: larger stack guard gap, between vmas
3.16.45-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hugh Dickins <[email protected]>
commit 1be7107fbe18eed3e319a6c3e83c78254b693acb upstream.
Stack guard page is a useful feature to reduce a risk of stack smashing into a different mapping. We have been using a single page gap which is sufficient to prevent having stack adjacent to a different mapping. But this seems to be insufficient in the light of the stack usage in userspace. E.g. glibc uses as large as 64kB alloca() in many commonly used functions. Others use constructs liks gid_t buffer[NGROUPS_MAX] which is 256kB or stack strings with MAX_ARG_STRLEN.
This will become especially dangerous for suid binaries and the default no limit for the stack size limit because those applications can be tricked to consume a large portion of the stack and a single glibc call could jump over the guard page. These attacks are not theoretical, unfortunatelly.
Make those attacks less probable by increasing the stack guard gap to 1MB (on systems with 4k pages; but make it depend on the page size because systems with larger base pages might cap stack allocations in the PAGE_SIZE units) which should cover larger alloca() and VLA stack allocations. It is obviously not a full fix because the problem is somehow inherent, but it should reduce attack space a lot.
One could argue that the gap size should be configurable from userspace, but that can be done later when somebody finds that the new 1MB is wrong for some special case applications. For now, add a kernel command line option (stack_guard_gap) to specify the stack gap size (in page units).
Implementation wise, first delete all the old code for stack guard page:
because although we could get away with accounting one extra page in a stack vma, accounting a larger gap can break userspace - case in point, a program run with "ulimit -S -v 20000" failed when the 1MB gap was counted for RLIMIT_AS; similar problems could come with RLIMIT_MLOCK and strict non-overcommit mode.
Instead of keeping gap inside the stack vma, maintain the stack guard gap as a gap between vmas: using vm_start_gap() in place of vm_start (or vm_end_gap() in place of vm_end if VM_GROWSUP) in just those few places which need to respect the gap - mainly arch_get_unmapped_area(), and and the vma tree's subtree_gap support for that.
---
Documentation/kernel-parameters.txt +7 -0
@@ -3154,6 +3154,13 @@ bytes respectively. Such letter suffixes spia_pedr= spia_peddr= + stack_guard_gap= [MM] + override the default stack gap protection. The value + is in page units and it defines how many pages prior + to (for stacks growing down) resp. after (for stacks + growing up) the main stack are reserved for no other + mapping. Default value is 256 pages. + stacktrace [FTRACE] Enabled the stack tracer on boot up.
arch/arc/mm/mmap.c +1 -1
@@ -64,7 +64,7 @@ arch_get_unmapped_area(struct file *filp vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
arch/arm/mm/mmap.c +2 -2
@@ -89,7 +89,7 @@ arch_get_unmapped_area(struct file *filp vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
@@ -140,7 +140,7 @@ arch_get_unmapped_area_topdown(struct fi addr =PAGE_ALIGN (addr); vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
arch/frv/mm/elf-fdpic.c +1 -1
@@ -74,7 +74,7 @@ unsigned long arch_get_unmapped_area(str addr =PAGE_ALIGN (addr); vma =find_vma (current->mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma))) goto success; }
arch/mips/mm/mmap.c +1 -1
@@ -92,7 +92,7 @@ static unsigned long arch_get_unmapped_a vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
arch/parisc/kernel/sys_parisc.c +9 -6
@@ -88,7 +88,7 @@ unsigned long arch_get_unmapped_area(str unsigned long len, unsigned long pgoff, unsigned long flags) { struct mm_struct *mm = current->mm; -struct vm_area_struct *vma; +struct vm_area_struct *vma, *prev;unsigned long task_size =TASK_SIZE ;int do_color_align, last_mmap;struct vm_unmapped_area_info info;
@@ -115,9 +115,10 @@ unsigned long arch_get_unmapped_area(strelse addr =PAGE_ALIGN (addr); - vma =find_vma (mm, addr); + vma =find_vma_prev (mm, addr, &prev);if (task_size - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)) && + (!prev || addr >=vm_end_gap (prev))) goto found_addr; }
@@ -141,7 +142,7 @@ arch_get_unmapped_area_topdown(struct fi const unsigned long len, const unsigned long pgoff, const unsigned long flags) { - struct vm_area_struct *vma; + struct vm_area_struct *vma, *prev;struct mm_struct *mm = current->mm;unsigned long addr = addr0;int do_color_align, last_mmap;
@@ -175,9 +176,11 @@ arch_get_unmapped_area_topdown(struct fi addr =COLOR_ALIGN (addr, last_mmap, pgoff); else addr =PAGE_ALIGN (addr); - vma =find_vma (mm, addr); + + vma =find_vma_prev (mm, addr, &prev);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)) && + (!prev || addr >=vm_end_gap (prev))) goto found_addr; }
arch/powerpc/mm/slice.c +1 -1
@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_if ((mm->task_size - len) < addr)return 0 ; vma =find_vma (mm, addr); -return (!vma || (addr + len) <= vma->vm_start); +return (!vma || (addr + len) <=vm_start_gap (vma)); }static int slice_low_has_vma (struct mm_struct *mm,unsigned long slice)
arch/sh/mm/mmap.c +2 -2
@@ -63,7 +63,7 @@ unsigned long arch_get_unmapped_area(str vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
@@ -113,7 +113,7 @@ arch_get_unmapped_area_topdown(struct fi vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
arch/sparc/kernel/sys_sparc_64.c +2 -2
@@ -118,7 +118,7 @@ unsigned long arch_get_unmapped_area(str vma =find_vma (mm, addr);if (task_size - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
@@ -181,7 +181,7 @@ arch_get_unmapped_area_topdown(struct fi vma =find_vma (mm, addr);if (task_size - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
arch/sparc/mm/hugetlbpage.c +1 -1
@@ -115,7 +115,7 @@ hugetlb_get_unmapped_area(struct file *f addr =ALIGN (addr,HPAGE_SIZE ); vma =find_vma (mm, addr);if (task_size - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }if (mm->get_unmapped_area == arch_get_unmapped_area)
arch/tile/mm/hugetlbpage.c +1 -1
@@ -265,7 +265,7 @@ unsigned long hugetlb_get_unmapped_area( addr =ALIGN (addr,huge_page_size (h)); vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }if (current->mm->get_unmapped_area == arch_get_unmapped_area)
arch/x86/kernel/sys_x86_64.c +2 -2
@@ -127,7 +127,7 @@ arch_get_unmapped_area(struct file *filp addr =PAGE_ALIGN (addr); vma =find_vma (mm, addr);if (end - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
@@ -166,7 +166,7 @@ arch_get_unmapped_area_topdown(struct fi addr =PAGE_ALIGN (addr); vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
arch/x86/mm/hugetlbpage.c +1 -1
@@ -156,7 +156,7 @@ hugetlb_get_unmapped_area(struct file *f addr =ALIGN (addr,huge_page_size (h)); vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }if (mm->get_unmapped_area == arch_get_unmapped_area)
arch/xtensa/kernel/syscall.c +1 -1
@@ -86,7 +86,7 @@ unsigned long arch_get_unmapped_area(str/* At this point: (!vmm || addr < vmm->vm_end). */ if (TASK_SIZE - len < addr)return -ENOMEM ; -if (!vmm || addr + len <= vmm->vm_start) +if (!vmm || addr + len <=vm_start_gap (vmm))return addr; addr = vmm->vm_end;if (flags &MAP_SHARED )
fs/hugetlbfs/inode.c +1 -1
@@ -171,7 +171,7 @@ hugetlb_get_unmapped_area(struct file *f addr =ALIGN (addr,huge_page_size (h)); vma =find_vma (mm, addr);if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vma->vm_start)) + (!vma || addr + len <=vm_start_gap (vma)))return addr; }
fs/proc/task_mmu.c +0 -4
@@ -273,11 +273,7 @@ show_map_vma(struct seq_file *m, struct/* We don't show the stack guard page in /proc/maps */ start = vma->vm_start; -if (stack_guard_page_start (vma, start)) - start +=PAGE_SIZE ; end = vma->vm_end; -if (stack_guard_page_end (vma, end)) - end -=PAGE_SIZE ;seq_setwidth (m,25 +sizeof (void *) *6 -1 ); seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
include/linux/mm.h +25 -28
71 lines not on this page · raw message
mm/gup.c +0 -5
@@ -266,11 +266,6 @@ static int faultin_page(struct task_struunsigned int fault_flags =0 ;int ret; -/* For mlock, just skip the stack guard page. */ -if ((*flags &FOLL_MLOCK ) && - (stack_guard_page_start (vma, address) || -stack_guard_page_end (vma, address +PAGE_SIZE ))) -return -ENOENT ;if (*flags &FOLL_WRITE ) fault_flags |=FAULT_FLAG_WRITE ;if (nonblocking)
mm/memory.c +0 -38
@@ -2589,40 +2589,6 @@ out_release: }/* -* This is like a special single-page "expand_{down|up}wards()", -* except we must first make sure that 'address{-|+}PAGE_SIZE' -* doesn't hit another vma. -*/ -static inline int check_stack_guard_page (struct vm_area_struct *vma,unsigned long address) -{ - address &=PAGE_MASK ; -if ((vma->vm_flags &VM_GROWSDOWN ) && address == vma->vm_start) { -struct vm_area_struct *prev = vma->vm_prev; - -/* -* Is there a mapping abutting this one below? -* -* That's only ok if it's the same stack mapping -* that has gotten split.. -*/ -if (prev && prev->vm_end == address) -return prev->vm_flags &VM_GROWSDOWN ?0 : -ENOMEM ; - -return expand_downwards (vma, address -PAGE_SIZE ); - } -if ((vma->vm_flags &VM_GROWSUP ) && address +PAGE_SIZE == vma->vm_end) { -struct vm_area_struct *next = vma->vm_next; - -/* As VM_GROWSDOWN but s/below/above/ */ -if (next && next->vm_start == address +PAGE_SIZE ) -return next->vm_flags &VM_GROWSUP ?0 : -ENOMEM ; - -return expand_upwards (vma, address +PAGE_SIZE ); - } -return 0 ; -} - -/* * We enter with non-exclusive mmap_sem (to exclude vma changes, * but allow concurrent faults), and pte mapped but not yet locked. * We return with mmap_sem still held, but pte unmapped and unlocked.
@@ -2641,10 +2607,6 @@ static int do_anonymous_page(struct mm_sif (vma->vm_flags &VM_SHARED )return VM_FAULT_SIGBUS ; -/* Check if we need to add a guard page to the stack */ -if (check_stack_guard_page (vma, address) <0 ) -return VM_FAULT_SIGSEGV ; -/* Use the zero-page for reads */ if (!(flags &FAULT_FLAG_WRITE )) { entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
mm/mmap.c +89 -60
321 lines not on this page · raw message
PATCH 2/7 mm: fix new crash in unmapped_area_topdown()
In reply to Ben Hutchings3.16.45-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hugh Dickins <[email protected]>
commit f4cb767d76cf7ee72f97dd76f6cfa6c76a5edc89 upstream.
Trinity gets kernel BUG at mm/mmap.c:1963! in about 3 minutes of mmap testing. That's the VM_BUG_ON(gap_end < gap_start) at the end of unmapped_area_topdown(). Linus points out how MAP_FIXED (which does not have to respect our stack guard gap intentions) could result in gap_end below gap_start there. Fix that, and the similar case in its alternative, unmapped_area().
--- mm/mmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/mmap.c +4 -2
@@ -1732,7 +1732,8 @@ check_current:/* Check if current node has a suitable gap */ if (gap_start > high_limit)return -ENOMEM ; -if (gap_end >= low_limit && gap_end - gap_start >= length) +if (gap_end >= low_limit && + gap_end > gap_start && gap_end - gap_start >= length) goto found;/* Visit right subtree if it looks promising */
@@ -1835,7 +1836,8 @@ check_current: gap_end =vm_start_gap (vma);if (gap_end < low_limit)return -ENOMEM ; -if (gap_start <= high_limit && gap_end - gap_start >= length) +if (gap_start <= high_limit && + gap_end > gap_start && gap_end - gap_start >= length) goto found;/* Visit left subtree if it looks promising */
PATCH 3/7 Allow stack to grow up to address space limit
In reply to Ben Hutchings3.16.45-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
commit bd726c90b6b8ce87602208701b208a208e6d5600 upstream.
Fix expand_upwards() on architectures with an upward-growing stack (parisc, metag and partly IA-64) to allow the stack to reliably grow exactly up to the address space limit given by TASK_SIZE.
--- mm/mmap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
mm/mmap.c +8 -5
@@ -2139,16 +2139,19 @@ int expand_upwards(struct vm_area_structif (!(vma->vm_flags &VM_GROWSUP ))return -EFAULT ; -/* Guard against wrapping around to address 0. */ +/* Guard against exceeding limits of the address space. */ address &=PAGE_MASK ; - address +=PAGE_SIZE ; -if (!address) +if (address >=TASK_SIZE )return -ENOMEM ; + address +=PAGE_SIZE ;/* Enforce stack_guard_gap */ gap_addr = address + stack_guard_gap; -if (gap_addr < address) -return -ENOMEM ; + +/* Guard against overflow */ +if (gap_addr < address || gap_addr >TASK_SIZE ) + gap_addr =TASK_SIZE ; + next = vma->vm_next;if (next && next->vm_start < gap_addr) {if (!(next->vm_flags &VM_GROWSUP ))
PATCH 4/7 regulator: core: Fix regualtor_ena_gpio_free not to access pin after freeing
In reply to Ben Hutchings3.16.45-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Seung-Woo Kim <[email protected]>
commit 60a2362f769cf549dc466134efe71c8bf9fbaaba upstream.
After freeing pin from regulator_ena_gpio_free, loop can access the pin. So this patch fixes not to access pin after freeing.
--- drivers/regulator/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/regulator/core.c +2 -0
@@ -1709,6 +1709,8 @@ static void regulator_ena_gpio_free(strugpio_free (pin->gpio);list_del (&pin->list);kfree (pin); + rdev->ena_pin =NULL ; +return ; }else { pin->request_count--; }
PATCH 5/7 drm/vmwgfx: limit the number of mip levels in vmw_gb_surface_define_ioctl()
In reply to Ben Hutchings3.16.45-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Vladis Dronov <[email protected]>
commit ee9c4e681ec4f58e42a83cb0c22a0289ade1aacf upstream.
The 'req->mip_levels' parameter in vmw_gb_surface_define_ioctl() is a user-controlled 'uint32_t' value which is used as a loop count limit. This can lead to a kernel lockup and DoS. Add check for 'req->mip_levels'.
References:
https://bugzilla.redhat.com/show_bug.cgi?id=1437431
--- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +3 -0
@@ -1251,6 +1251,9 @@ int vmw_gb_surface_define_ioctl(struct dconst struct svga3d_surface_desc *desc;uint32_t backup_handle; +if (req->mip_levels >DRM_VMW_MAX_MIP_LEVELS ) +return -EINVAL ; +if (unlikely (vmw_user_surface_size ==0 )) vmw_user_surface_size =ttm_round_pot (sizeof (*user_srf)) +128 ;
PATCH 6/7 rxrpc: Fix several cases where a padded len isn't checked in ticket decode
In reply to Ben Hutchings3.16.45-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
commit 5f2f97656ada8d811d3c1bef503ced266fcd53a0 upstream.
This fixes CVE-2017-7482.
When a kerberos 5 ticket is being decoded so that it can be loaded into an rxrpc-type key, there are several places in which the length of a variable-length field is checked to make sure that it's not going to overrun the available data - but the data is padded to the nearest four-byte boundary and the code doesn't check for this extra. This could lead to the size-remaining variable wrapping and the data pointer going over the end of the buffer.
Fix this by making the various variable-length data checks use the padded length.
--- net/rxrpc/ar-key.c | 64 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 30 deletions(-)
net/rxrpc/ar-key.c +34 -30
@@ -213,7 +213,7 @@ static int rxrpc_krb5_decode_principal(s unsigned int *_toklen) {const __be32 *xdr = *_xdr; -unsigned int toklen = *_toklen, n_parts, loop, tmp; +unsigned int toklen = *_toklen, n_parts, loop, tmp, paddedlen;/* there must be at least one name, and at least #names+1 length * words */
@@ -243,16 +243,16 @@ static int rxrpc_krb5_decode_principal(s toklen -=4 ;if (tmp <=0 || tmp >AFSTOKEN_STRING_MAX )return -EINVAL ; -if (tmp > toklen) + paddedlen = (tmp +3 ) & ~3 ; +if (paddedlen > toklen)return -EINVAL ; princ->name_parts[loop] =kmalloc (tmp +1 ,GFP_KERNEL );if (!princ->name_parts[loop])return -ENOMEM ;memcpy (princ->name_parts[loop], xdr, tmp); princ->name_parts[loop][tmp] =0 ; - tmp = (tmp +3 ) & ~3 ; - toklen -= tmp; - xdr += tmp >>2 ; + toklen -= paddedlen; + xdr += paddedlen >>2 ; }if (toklen <4 )
@@ -261,16 +261,16 @@ static int rxrpc_krb5_decode_principal(s toklen -=4 ;if (tmp <=0 || tmp >AFSTOKEN_K5_REALM_MAX )return -EINVAL ; -if (tmp > toklen) + paddedlen = (tmp +3 ) & ~3 ; +if (paddedlen > toklen)return -EINVAL ; princ->realm =kmalloc (tmp +1 ,GFP_KERNEL );if (!princ->realm)return -ENOMEM ;memcpy (princ->realm, xdr, tmp); princ->realm[tmp] =0 ; - tmp = (tmp +3 ) & ~3 ; - toklen -= tmp; - xdr += tmp >>2 ; + toklen -= paddedlen; + xdr += paddedlen >>2 ;_debug ("%s/...@%s" , princ->name_parts[0 ], princ->realm);
@@ -289,7 +289,7 @@ static int rxrpc_krb5_decode_tagged_data unsigned int *_toklen) {const __be32 *xdr = *_xdr; -unsigned int toklen = *_toklen, len; +unsigned int toklen = *_toklen, len, paddedlen;/* there must be at least one tag and one length word */ if (toklen <=8 )
@@ -303,15 +303,17 @@ static int rxrpc_krb5_decode_tagged_data toklen -=8 ;if (len > max_data_size)return -EINVAL ; + paddedlen = (len +3 ) & ~3 ; +if (paddedlen > toklen) +return -EINVAL ; td->data_len = len;if (len >0 ) { td->data =kmemdup (xdr, len,GFP_KERNEL );if (!td->data)return -ENOMEM ; - len = (len +3 ) & ~3 ; - toklen -= len; - xdr += len >>2 ; + toklen -= paddedlen; + xdr += paddedlen >>2 ; }_debug ("tag %x len %x" , td->tag, td->data_len);
@@ -383,7 +385,7 @@ static int rxrpc_krb5_decode_ticket(u8 * const __be32 **_xdr, unsigned int *_toklen) { const __be32 *xdr = *_xdr; -unsigned int toklen = *_toklen, len; +unsigned int toklen = *_toklen, len, paddedlen;/* there must be at least one length word */ if (toklen <=4 )
@@ -395,6 +397,9 @@ static int rxrpc_krb5_decode_ticket(u8 * toklen -=4 ;if (len >AFSTOKEN_K5_TIX_MAX )return -EINVAL ; + paddedlen = (len +3 ) & ~3 ; +if (paddedlen > toklen) +return -EINVAL ; *_tktlen = len;_debug ("ticket len %u" , len);
@@ -403,9 +408,8 @@ static int rxrpc_krb5_decode_ticket(u8 * *_ticket =kmemdup (xdr, len,GFP_KERNEL );if (!*_ticket)return -ENOMEM ; - len = (len +3 ) & ~3 ; - toklen -= len; - xdr += len >>2 ; + toklen -= paddedlen; + xdr += paddedlen >>2 ; } *_xdr = xdr;
@@ -549,7 +553,7 @@ static int rxrpc_instantiate_xdr(struct {const __be32 *xdr = data, *token;const char *cp; -unsigned int len, tmp, loop, ntoken, toklen, sec_ix; +unsigned int len, paddedlen, loop, ntoken, toklen, sec_ix;int ret; _enter(",{%x,%x,%x,%x},%zu",
@@ -574,22 +578,21 @@ static int rxrpc_instantiate_xdr(structif (len <1 || len >AFSTOKEN_CELL_MAX ) goto not_xdr; datalen -=4 ; - tmp = (len +3 ) & ~3 ; -if (tmp > datalen) + paddedlen = (len +3 ) & ~3 ; +if (paddedlen > datalen) goto not_xdr; cp = (const char *) xdr;for (loop =0 ; loop < len; loop++)if (!isprint (cp[loop])) goto not_xdr; -if (len < tmp) -for (; loop < tmp; loop++) -if (cp[loop]) - goto not_xdr; +for (; loop < paddedlen; loop++) +if (cp[loop]) + goto not_xdr;_debug ("cellname: [%u/%u] '%*.*s'" , - len, tmp, len, len, (const char *) xdr); - datalen -= tmp; - xdr += tmp >>2 ; + len, paddedlen, len, len, (const char *) xdr); + datalen -= paddedlen; + xdr += paddedlen >>2 ;/* get the token count */ if (datalen <12 )
@@ -610,10 +613,11 @@ static int rxrpc_instantiate_xdr(struct sec_ix =ntohl (*xdr); datalen -=4 ;_debug ("token: [%x/%zx] %x" , toklen, datalen, sec_ix); -if (toklen <20 || toklen > datalen) + paddedlen = (toklen +3 ) & ~3 ; +if (toklen <20 || toklen > datalen || paddedlen > datalen) goto not_xdr; - datalen -= (toklen +3 ) & ~3 ; - xdr += (toklen +3 ) >>2 ; + datalen -= paddedlen; + xdr += paddedlen >>2 ; }while (--loop >0 );
PATCH 7/7 KVM: x86: fix singlestepping over syscall
In reply to Ben Hutchings3.16.45-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Bonzini <[email protected]>
commit c8401dda2f0a00cd25c0af6a95ed50e478d25de4 upstream.
TF is handled a bit differently for syscall and sysret, compared to the other instructions: TF is checked after the instruction completes, so that the OS can disable #DB at a syscall by adding TF to FMASK. When the sysret is executed the #DB is taken "as if" the syscall insn just completed.
KVM emulates syscall so that it can trap 32-bit syscall on Intel processors. Fix the behavior, otherwise you could get #DB on a user stack which is not nice. This does not affect Linux guests, as they use an IST or task gate for #DB.
This fixes CVE-2017-7518.
[bwh: Backported to 3.16:
- kvm_vcpu_check_singlestep() did not take an rflags parameter but called get_rflags() itself; delete that code
- kvm_vcpu_check_singlestep() sets some flags differently
- Drop changes to kvm_skip_emulated_instruction()]
---
arch/x86/include/asm/kvm_emulate.h +1 -0
@@ -274,6 +274,7 @@ struct x86_emulate_ctxt {bool guest_mode;/* guest running a nested guest */ bool perm_ok;/* do not check permissions if true */ bool ud;/* inject an #UD if host doesn't support insn */ +bool tf;/* TF value before instruction (after for syscall/sysret) */ bool have_exception;struct x86_exception exception;
arch/x86/kvm/emulate.c +1 -0
@@ -2310,6 +2310,7 @@ static int em_syscall(struct x86_emulate ctxt->eflags &= ~(EFLG_VM |EFLG_IF |EFLG_RF ); } + ctxt->tf = (ctxt->eflags &X86_EFLAGS_TF ) !=0 ;return X86EMUL_CONTINUE ; }
arch/x86/kvm/x86.c +22 -31
74 lines not on this page · raw message
Quoted 8 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.45 release. There are 7 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu Jun 29 11:10:33 UTC 2017. Anything received after that time might be too late.
Build results:
total: 136 pass: 136 fail: 0 Qemu test results: total: 107 pass: 107 fail: 0
Details are available at http://kerneltests.org/builders.
Guenter
Quoted 10 lines · Guenter Roeck
Quoted 8 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.45 release. There are 7 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu Jun 29 11:10:33 UTC 2017. Anything received after that time might be too late.
Quoted 6 lines
Build results:
total: 136 pass: 136 fail: 0 Qemu test results: total: 107 pass: 107 fail: 0Details are available at http://kerneltests.org/builders.
Thanks for checking these.
Ben.
Signature · 2 lines
Ben Hutchings Absolutum obsoletum. (If it works, it's out of date.) - Stafford Beer