dm: fix AB-BA deadlock in __dm_destroy()
PATCH 1/1 brcmfmac: avoid potential stack overflow in brcmf_cfg80211_start_ap()
In reply to Jiri SlabyFrom: Arend Van Spriel <[email protected]>
This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.
===============
commit ded89912156b1a47d940a0c954c43afbabd0c42c upstream.
User-space can choose to omit NL80211_ATTR_SSID and only provide raw IE TLV data. When doing so it can provide SSID IE with length exceeding the allowed size. The driver further processes this IE copying it into a local variable without checking the length. Hence stack can be corrupted and used as exploit.
--- drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c +1 -1
@@ -3731,7 +3731,7 @@ brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, (u8 *)&settings->beacon.head[ie_offset], settings->beacon.head_len - ie_offset, WLAN_EID_SSID); -if (!ssid_ie) +if (!ssid_ie || ssid_ie->len >IEEE80211_MAX_SSID_LEN )return -EINVAL ;memcpy (ssid_le.SSID, ssid_ie->data, ssid_ie->len);
Signature · 1 line
2.10.1
PATCH 1/1 x86/build: Build compressed x86 kernels as PIE
In reply to Jiri SlabyFrom: "H.J. Lu" <[email protected]>
This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.
===============
commit 6d92bc9d483aa1751755a66fee8fb39dffb088c0 upstream.
The 32-bit x86 assembler in binutils 2.26 will generate R_386_GOT32X relocation to get the symbol address in PIC. When the compressed x86 kernel isn't built as PIC, the linker optimizes R_386_GOT32X relocations to their fixed symbol addresses. However, when the compressed x86 kernel is loaded at a different address, it leads to the following load failure:
Failed to allocate space for phdrs
during the decompression stage.
If the compressed x86 kernel is relocatable at run-time, it should be compiled with -fPIE, instead of -fPIC, if possible and should be built as Position Independent Executable (PIE) so that linker won't optimize R_386_GOT32X relocation to its fixed symbol address.
Older linkers generate R_386_32 relocations against locally defined symbols, _bss, _ebss, _got and _egot, in PIE. It isn't wrong, just less optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle R_386_32 relocations when relocating the kernel. To generate R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as hidden in both 32-bit and 64-bit x86 kernels.
To build a 64-bit compressed x86 kernel as PIE, we need to disable the relocation overflow check to avoid relocation overflow errors. We do this with a new linker command-line option, -z noreloc-overflow, which got added recently:
commit 4c10bbaa0912742322f10d9d5bb630ba4e15dfa7
Author: H.J. Lu <[email protected]>
Date: Tue Mar 15 11:07:06 2016 -0700
Add -z noreloc-overflow option to x86-64 ld
Add -z noreloc-overflow command-line option to the x86-64 ELF linker to disable relocation overflow check. This can be used to avoid relocation overflow check if there will be no dynamic relocation overflow at run-time.
The 64-bit compressed x86 kernel is built as PIE only if the linker supports -z noreloc-overflow. So far 64-bit relocatable compressed x86 kernel boots fine even when it is built as a normal executable.
--- arch/x86/boot/compressed/Makefile | 14 +++++++++++++- arch/x86/boot/compressed/head_32.S | 28 ++++++++++++++++++++++++++++ arch/x86/boot/compressed/head_64.S | 8 ++++++++ 3 files changed, 49 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/Makefile +13 -1
@@ -8,7 +8,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 -KBUILD_CFLAGS += -fno-strict-aliasing -fPIC +KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC) KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING cflags-$(CONFIG_X86_32) := -march=i386 cflags-$(CONFIG_X86_64) := -mcmodel=small
@@ -21,6 +21,18 @@ KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ GCOV_PROFILE := n LDFLAGS := -m elf_$(UTS_MACHINE) +ifeq ($(CONFIG_RELOCATABLE),y) +# If kernel is relocatable, build compressed kernel as PIE. +ifeq ($(CONFIG_X86_32),y) +LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) +else +# To build 64-bit compressed kernel as PIE, we disable relocation +# overflow check to avoid relocation overflow error with a new linker +# command-line option, -z noreloc-overflow. +LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ + && echo "-z noreloc-overflow -pie --no-dynamic-linker") +endif +endif LDFLAGS_vmlinux := -T hostprogs-y := mkpiggy
arch/x86/boot/compressed/head_32.S +28 -0
@@ -30,6 +30,34 @@ #include <asm/boot.h> #include <asm/asm-offsets.h> +/* + * The 32-bit x86 assembler in binutils 2.26 will generate R_386_GOT32X + * relocation to get the symbol address in PIC. When the compressed x86 + * kernel isn't built as PIC, the linker optimizes R_386_GOT32X + * relocations to their fixed symbol addresses. However, when the + * compressed x86 kernel is loaded at a different address, it leads + * to the following load failure: + * + * Failed to allocate space for phdrs + * + * during the decompression stage. + * + * If the compressed x86 kernel is relocatable at run-time, it should be + * compiled with -fPIE, instead of -fPIC, if possible and should be built as + * Position Independent Executable (PIE) so that linker won't optimize + * R_386_GOT32X relocation to its fixed symbol address. Older + * linkers generate R_386_32 relocations against locally defined symbols, + * _bss, _ebss, _got and _egot, in PIE. It isn't wrong, just less + * optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle + * R_386_32 relocations when relocating the kernel. To generate + * R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as + * hidden: + */ + .hidden _bss + .hidden _ebss + .hidden _got + .hidden _egot + __HEAD ENTRY(startup_32) #ifdef CONFIG_EFI_STUB
arch/x86/boot/compressed/head_64.S +8 -0
@@ -32,6 +32,14 @@ #include <asm/processor-flags.h> #include <asm/asm-offsets.h> +/* + * Locally defined symbols should be marked hidden: + */ + .hidden _bss + .hidden _ebss + .hidden _got + .hidden _egot + __HEAD .code32 ENTRY(startup_32)
Signature · 1 line
2.10.1
PATCH 1/1 mm: remove gup_flags FOLL_WRITE games from __get_user_pages()
In reply to Jiri SlabyFrom: Linus Torvalds <[email protected]>
This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.
===============
commit 19be0eaffa3ac7d8eb6784ad9bdbc7d67ed8e619 upstream.
This is an ancient bug that was actually attempted to be fixed once (badly) by me eleven years ago in commit 4ceb5db9757a ("Fix get_user_pages() race for write access") but that was then undone due to problems on s390 by commit f33ea7f404e5 ("fix get_user_pages bug").
In the meantime, the s390 situation has long been fixed, and we can now fix it by checking the pte_dirty() bit properly (and do it better). The s390 dirty bit was implemented in abf09bed3cce ("s390/mm: implement software dirty bits") which made it into v3.9. Earlier kernels will have to look at the page state itself.
Also, the VM has become more scalable, and what used a purely theoretical race back then has become easier to trigger.
To fix it, we introduce a new internal FOLL_COW flag to mark the "yes, we already did a COW" rather than play racy games with FOLL_WRITE that is very fundamental, and then use the pte dirty flag to validate that the FOLL_COW flag is still valid.
--- include/linux/mm.h | 1 + mm/memory.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
include/linux/mm.h +1 -0
@@ -1749,6 +1749,7 @@ static inline struct page *follow_page(struct vm_area_struct *vma,#define FOLL_HWPOISON 0x100/* check page is hwpoisoned */ #define FOLL_NUMA 0x200/* force NUMA hinting page fault */ #define FOLL_MIGRATION 0x400/* wait for page to replace migration entry */ +#define FOLL_COW 0x4000/* internal GUP flag */ typedef int (*pte_fn_t )(pte_t *pte,pgtable_t token,unsigned long addr,void *data);
mm/memory.c +12 -2
@@ -1441,6 +1441,16 @@ int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address, }EXPORT_SYMBOL_GPL (zap_vma_ptes); +/* +* FOLL_FORCE can write to even unwritable pte's, but only +* after we've gone through a COW cycle and they are dirty. +*/ +static inline bool can_follow_write_pte (pte_t pte,unsigned int flags) +{ +return pte_write (pte) || + ((flags &FOLL_FORCE ) && (flags &FOLL_COW ) &&pte_dirty (pte)); +} +/** * follow_page_mask - look up a page descriptor from a user-virtual address * @vma: vm_area_struct mapping @address
@@ -1550,7 +1560,7 @@ split_fallthrough: }if ((flags &FOLL_NUMA ) &&pte_numa (pte)) goto no_page; -if ((flags &FOLL_WRITE ) && !pte_write (pte)) +if ((flags &FOLL_WRITE ) && !can_follow_write_pte (pte, flags)) goto unlock; page =vm_normal_page (vma, address, pte);
@@ -1858,7 +1868,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,*/ if ((ret &VM_FAULT_WRITE ) && !(vma->vm_flags &VM_WRITE )) - foll_flags &= ~FOLL_WRITE ; + foll_flags |=FOLL_COW ;cond_resched (); }
Signature · 1 line
2.10.1
PATCH 1/1 dm: fix AB-BA deadlock in __dm_destroy()
From: Junichi Nomura <[email protected]>
This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.
===============
commit 2a708cff93f1845b9239bc7d6310aef54e716c6a upstream.
__dm_destroy() takes io_barrier SRCU lock (dm_get_live_table) and suspend_lock in reverse order. Doing so can cause AB-BA deadlock:
__dm_destroy dm_swap_table
---------------------------------------------------
mutex_lock(suspend_lock)
dm_get_live_table()
srcu_read_lock(io_barrier)
dm_sync_table()
synchronize_srcu(io_barrier)
.. waiting for dm_put_live_table()
mutex_lock(suspend_lock)
.. waiting for suspend_lock
Fix this by taking the locks in proper order.
--- drivers/md/dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm.c +2 -2
@@ -2444,14 +2444,14 @@ static void __dm_destroy(struct mapped_device *md, bool wait)* do not race with internal suspend. */ mutex_lock (&md->suspend_lock); + map =dm_get_live_table (md, &srcu_idx);if (!dm_suspended_md (md)) {dm_table_presuspend_targets (map);dm_table_postsuspend_targets (map); } -mutex_unlock (&md->suspend_lock); -/* dm_put_live_table must be before msleep, otherwise deadlock is possible */ dm_put_live_table (md, srcu_idx); +mutex_unlock (&md->suspend_lock);/* * Rare, but there may be I/O requests still going to complete,
Signature · 1 line
2.10.1
PATCH 1/1 ratelimit: fix bug in time interval by resetting right begin time
From: Jaewon Kim <[email protected]>
This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.
===============
commit c2594bc37f4464bc74f2c119eb3269a643400aa0 upstream.
rs->begin in ratelimit is set in two cases.
1) when rs->begin was not initialized
2) when rs->interval was passed
For case #2, current ratelimit sets the begin to 0. This incurrs improper suppression. The begin value will be set in the next ratelimit call by 1). Then the time interval check will be always false, and rs->printed will not be initialized. Although enough time passed, ratelimit may return 0 if rs->printed is not less than rs->burst. To reset interval properly, begin should be jiffies rather than 0.
For an example code below:
static DEFINE_RATELIMIT_STATE(mylimit, 1, 1);
for (i = 1; i <= 10; i++) {
if (__ratelimit(&mylimit))
printk("ratelimit test count %d\n", i);
msleep(3000);
}test result in the current code shows suppression even there is 3 seconds sleep.
[ 78.391148] ratelimit test count 1 [ 81.295988] ratelimit test count 2 [ 87.315981] ratelimit test count 4 [ 93.336267] ratelimit test count 6 [ 99.356031] ratelimit test count 8 [ 105.376367] ratelimit test count 10
--- lib/ratelimit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ratelimit.c +1 -1
@@ -49,7 +49,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)if (rs->missed)printk (KERN_WARNING "%s: %d callbacks suppressed\n" , func, rs->missed); - rs->begin =0 ; + rs->begin = jiffies; rs->printed =0 ; rs->missed =0 ; }
Signature · 1 line
2.10.1
Quoted 38 lines · Jiri Slaby
commit
2a708cff93f1845b9239bc7d6310aef54e716c6aupstream.
__dm_destroy()takesio_barrierSRCU lock (dm_get_live_table) andsuspend_lockin reverse order. Doing so can cause AB-BA deadlock:
__dm_destroydm_swap_table
---------------------------------------------------
mutex_lock(suspend_lock)
dm_get_live_table()
srcu_read_lock(io_barrier)
dm_sync_table()
synchronize_srcu(io_barrier)
.. waiting fordm_put_live_table()
mutex_lock(suspend_lock)
.. waiting forsuspend_lockFix this by taking the locks in proper order.
Signed-off-by Jun'ichi Nomura <[email protected]>Fixes ab7c7bb6f4ab ("dm: hold suspend_lock while suspending device during device deletion")Acked-by Mikulas Patocka <[email protected]>Signed-off-by Mike Snitzer <[email protected]>Signed-off-by Jiri Slaby <[email protected]>--- drivers/md/dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/dm.c +1
-0@@ -2444,14 +2444,14 @@ static void __dm_destroy(struct mapped_device *md, bool wait)* do not race with internal suspend. */ mutex_lock (&md->suspend_lock); + map =dm_get_live_table (md, &srcu_idx);if (!dm_suspended_md (md)) {dm_table_presuspend_targets (map);
drivers/md/dm.c static void __dm_destroy(struct mapped_device *md, bool wait) · line 2457
Quoted 10 lines
drivers/md/dm.c +1
-2dm_table_postsuspend_targets (map); } -mutex_unlock (&md->suspend_lock); -/* dm_put_live_table must be before msleep, otherwise deadlock is possible */ dm_put_live_table (md, srcu_idx); +mutex_unlock (&md->suspend_lock);/* * Rare, but there may be I/O requests still going to complete,
I don't have 3.12-stable tree at hand but this patch looks incorrect.
The patch misses the part of upstream patch that removes existing dm_get_live_table(). By just adding dm_get_live_table(), you will have unbalanced numbers of get and put and break refcounting of md.
Signature · 1 line
Jun'ichi Nomura, NEC Corporation / NEC Solution Innovators, Ltd.
Quoted 47 lines · Junichi Nomura
Quoted 46 lines · Jiri Slaby
commit
2a708cff93f1845b9239bc7d6310aef54e716c6aupstream.
__dm_destroy()takesio_barrierSRCU lock (dm_get_live_table) andsuspend_lockin reverse order. Doing so can cause AB-BA deadlock:
__dm_destroydm_swap_table
---------------------------------------------------
mutex_lock(suspend_lock)
dm_get_live_table()
srcu_read_lock(io_barrier)
dm_sync_table()
synchronize_srcu(io_barrier)
.. waiting fordm_put_live_table()
mutex_lock(suspend_lock)
.. waiting forsuspend_lockFix this by taking the locks in proper order.
Signed-off-by Jun'ichi Nomura <[email protected]>Fixes ab7c7bb6f4ab ("dm: hold suspend_lock while suspending device during device deletion")Acked-by Mikulas Patocka <[email protected]>Signed-off-by Mike Snitzer <[email protected]>Signed-off-by Jiri Slaby <[email protected]>--- drivers/md/dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/dm.c +2
-2@@ -2444,14 +2444,14 @@ static void __dm_destroy(struct mapped_device *md, bool wait)* do not race with internal suspend. */ mutex_lock (&md->suspend_lock); + map =dm_get_live_table (md, &srcu_idx);if (!dm_suspended_md (md)) {dm_table_presuspend_targets (map);dm_table_postsuspend_targets (map); } -mutex_unlock (&md->suspend_lock); -/* dm_put_live_table must be before msleep, otherwise deadlock is possible */ dm_put_live_table (md, srcu_idx); +mutex_unlock (&md->suspend_lock);
Quoted 8 lines
drivers/md/dm.c static void __dm_destroy(struct mapped_device *md, bool wait) · line 2457
Quoted 2 lines
drivers/md/dm.c +0
-0/* * Rare, but there may be I/O requests still going to complete, I don't have 3.12-stable tree at hand but this patch looks incorrect.
The patch misses the part of upstream patch that removes existing
dm_get_live_table(). By just addingdm_get_live_table(), you will have unbalanced numbers of get and put and break refcounting of md.
Right! I have no idea, how the hunk could have got lost.
thanks,
Signature · 2 lines
js suse labs
Quoted 5 lines · Jiri Slaby
Quoted 3 lines
The patch misses the part of upstream patch that removes existing
dm_get_live_table(). By just addingdm_get_live_table(), you will have unbalanced numbers of get and put and break refcounting of md.Right! I have no idea, how the hunk could have got lost.
And really:
$ git checkout v3.12.65 $ git cherry-pick 2a708cff93f1845b9239bc7d6310aef54e716c6a lost the hunk. WTF?
thanks,
Signature · 2 lines
js suse labs