3.4.101-stable review
Greg Kroah-Hartman
maintainercover 3.4.101-stable review
This is the start of the stable review cycle for the 3.4.101 release. There are 10 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri Aug 1 01:47:50 UTC 2014. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
kernel.org/pub/linux/kernel/v3.0/stable-review/patch-3.4.101-rc1.gz
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <[email protected]>
Linux 3.4.101-rc1
Catalin Marinas <[email protected]>
mm: kmemleak: avoid false negatives on vmalloc'ed objects
Xi Wang <[email protected]>
introduce SIZE_MAX
Martin Schwidefsky <[email protected]>
s390/ptrace: fix PSW mask check
Linus Torvalds <[email protected]>
Fix gcc-4.9.0 miscompilation of load_balance() in scheduler
Naoya Horiguchi <[email protected]>
mm: hugetlb: fix copy_hugetlb_page_range()
Sven Wegener <[email protected]>
x86_32, entry: Store badsys error code in %eax
Romain Degez <[email protected]>
ahci: add support for the Promise FastTrak TX8660 SATA HBA (ahci mode)
Tejun Heo <[email protected]>
libata: introduce ata_host->n_tags to avoid oops on SAS controllers
Kevin Hao <[email protected]>
libata: support the ata host which implements a queue depth less than 32
Christoph Hellwig <[email protected]>
block: don't assume last put of shared tags is for the host
-------------
Diffstat:
Makefile | 6 ++++-- arch/s390/kernel/ptrace.c | 9 +++++++-- arch/x86/kernel/entry_32.S | 9 +++++---- block/blk-tag.c | 33 +++++++-------------------------- drivers/ata/ahci.c | 1 + drivers/ata/libata-core.c | 12 ++++++++++-- fs/ceph/snap.c | 2 +- include/drm/drm_mem_util.h | 4 ++-- include/linux/kernel.h | 1 + include/linux/libata.h | 1 + include/linux/slab.h | 2 +- mm/hugetlb.c | 1 + mm/kmemleak.c | 4 +++- mm/vmalloc.c | 14 ++++++++++---- 14 files changed, 54 insertions(+), 45 deletions(-)
Greg Kroah-Hartman
maintainerPATCH 1/10 block: dont assume last put of shared tags is for the host
3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
commit d45b3279a5a2252cafcd665bbf2db8c9b31ef783 upstream.
There is no inherent reason why the last put of a tag structure must be the one for the Scsi_Host, as device model objects can be held for arbitrary periods. Merge blk_free_tags and __blk_free_tags into a single funtion that just release a references and get rid of the BUG() when the host reference wasn't the last.
--- block/blk-tag.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-)
block/blk-tag.c +7 -26
@@ -27,18 +27,15 @@ struct request *blk_queue_find_tag(strucEXPORT_SYMBOL (blk_queue_find_tag);/** -* __blk_free_tags - release a given set of tag maintenance info +* blk_free_tags - release a given set of tag maintenance info * @bqt: the tag map to free * -* Tries to free the specified @bqt. Returns true if it was -* actually freed and false if there are still references using it +* Drop the reference count on @bqt and frees it when the last reference +* is dropped. */ -static int __blk_free_tags (struct blk_queue_tag *bqt) +void blk_free_tags (struct blk_queue_tag *bqt) { -int retval; - - retval =atomic_dec_and_test (&bqt->refcnt); -if (retval) { +if (atomic_dec_and_test (&bqt->refcnt)) {BUG_ON (find_first_bit (bqt->tag_map, bqt->max_depth) < bqt->max_depth);
@@ -50,9 +47,8 @@ static int __blk_free_tags(struct blk_qukfree (bqt); } - -return retval; } +EXPORT_SYMBOL (blk_free_tags);/** * __blk_queue_free_tags - release tag maintenance info
@@ -69,28 +65,13 @@ void __blk_queue_free_tags(struct requesif (!bqt)return ; -__blk_free_tags (bqt); +blk_free_tags (bqt); q->queue_tags =NULL ;queue_flag_clear_unlocked (QUEUE_FLAG_QUEUED , q); }/** -* blk_free_tags - release a given set of tag maintenance info -* @bqt: the tag map to free -* -* For externally managed @bqt frees the map. Callers of this -* function must guarantee to have released all the queues that -* might have been using this tag map. -*/ -void blk_free_tags (struct blk_queue_tag *bqt) -{ -if (unlikely (!__blk_free_tags (bqt))) -BUG (); -} -EXPORT_SYMBOL (blk_free_tags); - -/** * blk_queue_free_tags - release tag maintenance info * @q: the request queue for the device *
Greg Kroah-Hartman
maintainerPATCH 2/10 libata: support the ata host which implements a queue depth less than 32
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Hao <[email protected]>
commit 1871ee134b73fb4cadab75752a7152ed2813c751 upstream.
The sata on fsl mpc8315e is broken after the commit 8a4aeec8d2d6 ("libata/ahci: accommodate tag ordered controllers"). The reason is that the ata controller on this SoC only implement a queue depth of
16. When issuing the commands in tag order, all the commands in tag 16 ~ 31 are mapped to tag 0 unconditionally and then causes the sata malfunction. It makes no senses to use a 32 queue in software while the hardware has less queue depth. So consider the queue depth implemented by the hardware when requesting a command tag.
--- drivers/ata/libata-core.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +19 -3
@@ -4693,6 +4693,10 @@ void swap_buf_le16(u16 *buf, unsigned in* ata_qc_new - Request an available ATA command, for queueing * @ap: target port * +* Some ATA host controllers may implement a queue depth which is less +* than ATA_MAX_QUEUE. So we shouldn't allocate a tag which is beyond +* the hardware limitation. +* * LOCKING: * None. */
@@ -4700,14 +4704,16 @@ void swap_buf_le16(u16 *buf, unsigned instatic struct ata_queued_cmd *ata_qc_new (struct ata_port *ap) {struct ata_queued_cmd *qc =NULL ; -unsigned int i, tag; +unsigned int i, tag, max_queue; + + max_queue = ap->scsi_host->can_queue;/* no command while frozen */ if (unlikely (ap->pflags &ATA_PFLAG_FROZEN ))return NULL ; -for (i =0 ; i <ATA_MAX_QUEUE ; i++) { - tag = (i + ap->last_tag +1 ) %ATA_MAX_QUEUE ; +for (i =0 , tag = ap->last_tag +1 ; i < max_queue; i++, tag++) { + tag = tag < max_queue ? tag :0 ;/* the last tag is reserved for internal command. */ if (tag ==ATA_TAG_INTERNAL )
@@ -6041,6 +6047,16 @@ int ata_host_register(struct ata_host *h {int i, rc; +/* +* The max queue supported by hardware must not be greater than +* ATA_MAX_QUEUE. +*/ +if (sht->can_queue >ATA_MAX_QUEUE ) { +dev_err (host->dev,"BUG: the hardware max queue is too large\n" ); +WARN_ON (1 ); +return -EINVAL ; + } +/* host must have been started */ if (!(host->flags &ATA_HOST_STARTED )) {dev_err (host->dev,"BUG: trying to register unstarted host\n" );
Greg Kroah-Hartman
maintainerPATCH 3/10 libata: introduce ata_host->n_tags to avoid oops on SAS controllers
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
commit 1a112d10f03e83fb3a2fdc4c9165865dec8a3ca6 upstream.
1871ee134b73 ("libata: support the ata host which implements a queue depth less than 32") directly used ata_port->scsi_host->can_queue from ata_qc_new() to determine the number of tags supported by the host; unfortunately, SAS controllers doing SATA don't initialize ->scsi_host leading to the following oops.
BUG: unable to handle kernel NULL pointer dereference at 0000000000000058 IP: [<ffffffff814e0618>] ata_qc_new_init+0x188/0x1b0 PGD 0 Oops: 0002 [#1] SMP Modules linked in: isci libsas scsi_transport_sas mgag200 drm_kms_helper ttm CPU: 1 PID: 518 Comm: udevd Not tainted 3.16.0-rc6+ #62 Hardware name: Intel Corporation S2600CO/S2600CO, BIOS SE5C600.86B.02.02.0002.122320131210 12/23/2013 task: ffff880c1a00b280 ti: ffff88061a000000 task.ti: ffff88061a000000 RIP: 0010:[<ffffffff814e0618>] [<ffffffff814e0618>] ata_qc_new_init+0x188/0x1b0 RSP: 0018:ffff88061a003ae8 EFLAGS: 00010012 RAX: 0000000000000001 RBX: ffff88000241ca80 RCX: 00000000000000fa RDX: 0000000000000020 RSI: 0000000000000020 RDI: ffff8806194aa298 RBP: ffff88061a003ae8 R08: ffff8806194a8000 R09: 0000000000000000 R10: 0000000000000000 R11: ffff88000241ca80 R12: ffff88061ad58200 R13: ffff8806194aa298 R14: ffffffff814e67a0 R15: ffff8806194a8000 FS: 00007f3ad7fe3840(0000) GS:ffff880627620000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000058 CR3: 000000061a118000 CR4: 00000000001407e0 Stack: ffff88061a003b20 ffffffff814e96e1 ffff88000241ca80 ffff88061ad58200 ffff8800b6bf6000 ffff880c1c988000 ffff880619903850 ffff88061a003b68 ffffffffa0056ce1 ffff88061a003b48 0000000013d6e6f8 ffff88000241ca80 Call Trace: [<ffffffff814e96e1>] ata_sas_queuecmd+0xa1/0x430 [<ffffffffa0056ce1>] sas_queuecommand+0x191/0x220 [libsas] [<ffffffff8149afee>] scsi_dispatch_cmd+0x10e/0x300 [<ffffffff814a3bc5>] scsi_request_fn+0x2f5/0x550 [<ffffffff81317613>] __blk_run_queue+0x33/0x40 [<ffffffff8131781a>] queue_unplugged+0x2a/0x90 [<ffffffff8131ceb4>] blk_flush_plug_list+0x1b4/0x210 [<ffffffff8131d274>] blk_finish_plug+0x14/0x50 [<ffffffff8117eaa8>] __do_page_cache_readahead+0x198/0x1f0 [<ffffffff8117ee21>] force_page_cache_readahead+0x31/0x50 [<ffffffff8117ee7e>] page_cache_sync_readahead+0x3e/0x50 [<ffffffff81172ac6>] generic_file_read_iter+0x496/0x5a0 [<ffffffff81219897>] blkdev_read_iter+0x37/0x40 [<ffffffff811e307e>] new_sync_read+0x7e/0xb0 [<ffffffff811e3734>] vfs_read+0x94/0x170 [<ffffffff811e43c6>] SyS_read+0x46/0xb0 [<ffffffff811e33d1>] ? SyS_lseek+0x91/0xb0 [<ffffffff8171ee29>] system_call_fastpath+0x16/0x1b Code: 00 00 00 88 50 29 83 7f 08 01 19 d2 83 e2 f0 83 ea 50 88 50 34 c6 81 1d 02 00 00 40 c6 81 17 02 00 00 00 5d c3 66 0f 1f 44 00 00 <89> 14 25 58 00 00 00
Fix it by introducing ata_host->n_tags which is initialized to ATA_MAX_QUEUE - 1 in ata_host_init() for SAS controllers and set to scsi_host_template->can_queue in ata_host_register() for !SAS ones. As SAS hosts are never registered, this will give them the same ATA_MAX_QUEUE - 1 as before. Note that we can't use scsi_host->can_queue directly for SAS hosts anyway as they can go higher than the libata maximum.
--- drivers/ata/libata-core.c | 16 ++++------------ include/linux/libata.h | 1 + 2 files changed, 5 insertions(+), 12 deletions(-)
drivers/ata/libata-core.c +4 -12
@@ -4704,9 +4704,8 @@ void swap_buf_le16(u16 *buf, unsigned instatic struct ata_queued_cmd *ata_qc_new (struct ata_port *ap) {struct ata_queued_cmd *qc =NULL ; -unsigned int i, tag, max_queue; - - max_queue = ap->scsi_host->can_queue; +unsigned int max_queue = ap->host->n_tags; +unsigned int i, tag;/* no command while frozen */ if (unlikely (ap->pflags &ATA_PFLAG_FROZEN ))
@@ -5965,6 +5964,7 @@ void ata_host_init(struct ata_host *host {spin_lock_init (&host->lock);mutex_init (&host->eh_mutex); + host->n_tags =ATA_MAX_QUEUE -1 ; host->dev = dev; host->flags = flags; host->ops = ops;
@@ -6047,15 +6047,7 @@ int ata_host_register(struct ata_host *h {int i, rc; -/* -* The max queue supported by hardware must not be greater than -* ATA_MAX_QUEUE. -*/ -if (sht->can_queue >ATA_MAX_QUEUE ) { -dev_err (host->dev,"BUG: the hardware max queue is too large\n" ); -WARN_ON (1 ); -return -EINVAL ; - } + host->n_tags =clamp (sht->can_queue,1 ,ATA_MAX_QUEUE -1 );/* host must have been started */ if (!(host->flags &ATA_HOST_STARTED )) {
include/linux/libata.h +1 -0
@@ -539,6 +539,7 @@ struct ata_host {struct device *dev;void __iomem *const *iomap;unsigned int n_ports; +unsigned int n_tags;/* nr of NCQ tags */ void *private_data;struct ata_port_operations *ops;unsigned long flags;
Greg Kroah-Hartman
maintainerPATCH 4/10 ahci: add support for the Promise FastTrak TX8660 SATA HBA (ahci mode)
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Romain Degez <[email protected]>
commit b32bfc06aefab61acc872dec3222624e6cd867ed upstream.
Add support of the Promise FastTrak TX8660 SATA HBA in ahci mode by registering the board in the ahci_pci_tbl[].
Note: this HBA also provide a hardware RAID mode when activated in BIOS but specific drivers from the manufacturer are required in this case.
--- drivers/ata/ahci.c | 1 + 1 file changed, 1 insertion(+)
drivers/ata/ahci.c +1 -0
@@ -446,6 +446,7 @@ static const struct pci_device_id ahci_p/* Promise */ { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */ + { PCI_VDEVICE(PROMISE, 0x3781), board_ahci }, /* FastTrak TX8660 ahci-mode *//* Asmedia */ { PCI_VDEVICE(ASMEDIA, 0x0601), board_ahci }, /* ASM1060 */
Greg Kroah-Hartman
maintainerPATCH 5/10 x86_32, entry: Store badsys error code in %eax
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Wegener <[email protected]>
commit 8142b215501f8b291a108a202b3a053a265b03dd upstream.
Commit 554086d ("x86_32, entry: Do syscall exit work on badsys (CVE-2014-4508)") introduced a regression in the x86_32 syscall entry code, resulting in syscall() not returning proper errors for undefined syscalls on CPUs supporting the sysenter feature.
The following code:
Quoted 2 lines
int result = syscall(666);
printf("result=%d errno=%d error=%s\n", result, errno, strerror(errno));
results in:
Quoted 1 line
result=666 errno=0 error=Success
Obviously, the syscall return value is the called syscall number, but it should have been an ENOSYS error. When run under ptrace it behaves correctly, which makes it hard to debug in the wild:
Quoted 1 line
result=-1 errno=38 error=Function not implemented
The %eax register is the return value register. For debugging via ptrace the syscall entry code stores the complete register context on the stack. The badsys handlers only store the ENOSYS error code in the ptrace register set and do not set %eax like a regular syscall handler would. The old resume_userspace call chain contains code that clobbers %eax and it restores %eax from the ptrace registers afterwards. The same goes for the ptrace-enabled call chain. When ptrace is not used, the syscall return value is the passed-in syscall number from the untouched %eax register.
Use %eax as the return value register in syscall_badsys and sysenter_badsys, like a real syscall handler does, and have the caller push the value onto the stack for ptrace access.
--- arch/x86/kernel/entry_32.S | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
arch/x86/kernel/entry_32.S +5 -4
@@ -428,8 +428,8 @@ sysenter_do_call: cmpl $(NR_syscalls), %eax jae sysenter_badsys call *sys_call_table(,%eax,4) - movl %eax,PT_EAX(%esp) sysenter_after_call: + movl %eax,PT_EAX(%esp) LOCKDEP_SYS_EXIT DISABLE_INTERRUPTS(CLBR_ANY) TRACE_IRQS_OFF
@@ -510,6 +510,7 @@ ENTRY(system_call) jae syscall_badsys syscall_call: call *sys_call_table(,%eax,4) +syscall_after_call: movl %eax,PT_EAX(%esp) # store the return value syscall_exit: LOCKDEP_SYS_EXIT
@@ -678,12 +679,12 @@ syscall_fault: END(syscall_fault) syscall_badsys: - movl $-ENOSYS,PT_EAX(%esp) - jmp syscall_exit + movl $-ENOSYS,%eax + jmp syscall_after_call END(syscall_badsys) sysenter_badsys: - movl $-ENOSYS,PT_EAX(%esp) + movl $-ENOSYS,%eax jmp sysenter_after_call END(syscall_badsys) CFI_ENDPROC
Greg Kroah-Hartman
maintainerPATCH 6/10 mm: hugetlb: fix copy_hugetlb_page_range()
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naoya Horiguchi <[email protected]>
commit 0253d634e0803a8376a0d88efee0bf523d8673f9 upstream.
Commit 4a705fef9862 ("hugetlb: fix copy_hugetlb_page_range() to handle migration/hwpoisoned entry") changed the order of huge_ptep_set_wrprotect() and huge_ptep_get(), which leads to breakage in some workloads like hugepage-backed heap allocation via libhugetlbfs. This patch fixes it.
The test program for the problem is shown below:
$ cat heap.c #include <unistd.h> #include <stdlib.h> #include <string.h>
#define HPS 0x200000
int main() {
int i;
char *p = malloc(HPS);
memset(p, '1', HPS);
for (i = 0; i < 5; i++) {
if (!fork()) {
memset(p, '2', HPS);
p = malloc(HPS);
memset(p, '3', HPS);
free(p);
return 0;
}
}
sleep(1);
free(p);
return 0;
}
$ export HUGETLB_MORECORE=yes ; export HUGETLB_NO_PREFAULT= ; hugectl --heap ./heapFixes 4a705fef9862 ("hugetlb: fix copy_hugetlb_page_range() to handle migration/hwpoisoned entry"), so is applicable to -stable kernels which include it.
--- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+)
mm/hugetlb.c +1 -0
@@ -2348,6 +2348,7 @@ int copy_hugetlb_page_range(struct mm_st }else {if (cow)huge_ptep_set_wrprotect (src, addr, src_pte); + entry =huge_ptep_get (src_pte); ptepage =pte_page (entry);get_page (ptepage);page_dup_rmap (ptepage);
Greg Kroah-Hartman
maintainerPATCH 8/10 s390/ptrace: fix PSW mask check
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Schwidefsky <[email protected]>
commit dab6cf55f81a6e16b8147aed9a843e1691dcd318 upstream.
The PSW mask check of the PTRACE_POKEUSR_AREA command is incorrect. The PSW_MASK_USER define contains the PSW_MASK_ASC bits, the ptrace interface accepts all combinations for the address-space-control bits. To protect the kernel space the PSW mask check in ptrace needs to reject the address-space-control bit combination for home space.
Fixes CVE-2014-3534
--- arch/s390/kernel/ptrace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/s390/kernel/ptrace.c +7 -2
@@ -292,7 +292,9 @@ static int __poke_user(struct task_struc* psw and gprs are stored on the stack */ if (addr == (addr_t) &dummy->regs.psw.mask && - ((data & ~PSW_MASK_USER ) != psw_user_bits || + (((data^psw_user_bits) & ~PSW_MASK_USER ) || + (((data^psw_user_bits) &PSW_MASK_ASC ) && + ((data|psw_user_bits) &PSW_MASK_ASC ) ==PSW_MASK_ASC ) || ((data &PSW_MASK_EA ) && !(data &PSW_MASK_BA ))))/* Invalid psw mask. */ return -EINVAL ;
@@ -595,7 +597,10 @@ static int __poke_user_compat(struct tas*/ if (addr == (addr_t) &dummy32->regs.psw.mask) {/* Build a 64 bit psw mask from 31 bit mask. */ -if ((tmp & ~PSW32_MASK_USER ) != psw32_user_bits) +if (((tmp^psw32_user_bits) & ~PSW32_MASK_USER ) || + (((tmp^psw32_user_bits) &PSW32_MASK_ASC ) && + ((tmp|psw32_user_bits) &PSW32_MASK_ASC ) + ==PSW32_MASK_ASC ))/* Invalid psw mask. */ return -EINVAL ; regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
Greg Kroah-Hartman
maintainerPATCH 9/10 introduce SIZE_MAX
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xi Wang <[email protected]>
commit a3860c1c5dd1137db23d7786d284939c5761d517 upstream.
ULONG_MAX is often used to check for integer overflow when calculating allocation size. While ULONG_MAX happens to work on most systems, there is no guarantee that size_t' must be the same size as long'.
This patch introduces SIZE_MAX, the maximum value of `size_t', to improve portability and readability for allocation size validation.
--- fs/ceph/snap.c | 2 +- include/drm/drm_mem_util.h | 4 ++-- include/linux/kernel.h | 1 + include/linux/slab.h | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-)
fs/ceph/snap.c +1 -1
@@ -331,7 +331,7 @@ static int build_snap_context(struct cep/* alloc new snap context */ err = -ENOMEM ; -if (num > (ULONG_MAX -sizeof (*snapc)) /sizeof (u64)) +if (num > (SIZE_MAX -sizeof (*snapc)) /sizeof (u64)) goto fail; snapc =kzalloc (sizeof (*snapc) + num*sizeof (u64),GFP_NOFS );if (!snapc)
include/drm/drm_mem_util.h +2 -2
@@ -31,7 +31,7 @@static __inline__void *drm_calloc_large (size_t nmemb,size_t size) { -if (size !=0 && nmemb >ULONG_MAX / size) +if (size !=0 && nmemb >SIZE_MAX / size)return NULL ;if (size * nmemb <=PAGE_SIZE )
@@ -44,7 +44,7 @@ static __inline__ void *drm_calloc_large/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */ static __inline__void *drm_malloc_ab (size_t nmemb,size_t size) { -if (size !=0 && nmemb >ULONG_MAX / size) +if (size !=0 && nmemb >SIZE_MAX / size)return NULL ;if (size * nmemb <=PAGE_SIZE )
include/linux/kernel.h +1 -0
@@ -35,6 +35,7 @@#define LLONG_MAX ((long long)(~0ULL>>1))#define LLONG_MIN (-LLONG_MAX - 1)#define ULLONG_MAX (~0ULL) +#define SIZE_MAX (~(size_t)0)#define STACK_MAGIC 0xdeadbeef
include/linux/slab.h +1 -1
@@ -242,7 +242,7 @@ size_t ksize(const void *);*/ static inline void *kmalloc_array (size_t n,size_t size,gfp_t flags) { -if (size !=0 && n >ULONG_MAX / size) +if (size !=0 && n >SIZE_MAX / size)return NULL ;return __kmalloc (n * size, flags); }
Greg Kroah-Hartman
maintainerPATCH 10/10 mm: kmemleak: avoid false negatives on vmalloced objects
In reply to Greg Kroah-Hartman3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catalin Marinas <[email protected]>
commit 7f88f88f83ed609650a01b18572e605ea50cd163 upstream.
Commit 248ac0e1943a ("mm/vmalloc: remove guard page from between vmap blocks") had the side effect of making vmap_area.va_end member point to the next vmap_area.va_start. This was creating an artificial reference to vmalloc'ed objects and kmemleak was rarely reporting vmalloc() leaks.
This patch marks the vmap_area containing pointers explicitly and reduces the min ref_count to 2 as vm_struct still contains a reference to the vmalloc'ed object. The kmemleak add_scan_area() function has been improved to allow a SIZE_MAX argument covering the rest of the object (for simpler calling sites).
--- mm/kmemleak.c | 4 +++- mm/vmalloc.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-)
mm/kmemleak.c +3 -1
@@ -750,7 +750,9 @@ static void add_scan_area(unsigned long }spin_lock_irqsave (&object->lock, flags); -if (ptr + size > object->pointer + object->size) { +if (size ==SIZE_MAX ) { + size = object->pointer + object->size - ptr; + }else if (ptr + size > object->pointer + object->size) {kmemleak_warn ("Scan area larger than object 0x%08lx\n" , ptr);dump_object_info (object);kmem_cache_free (scan_area_cache, area);
mm/vmalloc.c +10 -4
@@ -349,6 +349,12 @@ static struct vmap_area *alloc_vmap_areaif (unlikely (!va))return ERR_PTR (-ENOMEM ); +/* +* Only scan the relevant parts containing pointers to other objects +* to avoid false negatives. +*/ +kmemleak_scan_area (&va->rb_node,SIZE_MAX , gfp_mask &GFP_RECLAIM_MASK ); + retry:spin_lock (&vmap_area_lock);/*
@@ -1669,11 +1675,11 @@ void *__vmalloc_node_range(unsigned longinsert_vmalloc_vmlist (area);/* -* A ref_count = 3 is needed because the vm_struct and vmap_area -* structures allocated in the __get_vm_area_node() function contain -* references to the virtual address of the vmalloc'ed block. +* A ref_count = 2 is needed because vm_struct allocated in +* __get_vm_area_node() contains a reference to the virtual address of +* the vmalloc'ed block. */ -kmemleak_alloc (addr, real_size,3 , gfp_mask); +kmemleak_alloc (addr, real_size,2 , gfp_mask);return addr;
Quoted 8 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 3.4.101 release. There are 10 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri Aug 1 01:47:50 UTC 2014. Anything received after that time might be too late.
Build results:
total: 119 pass: 113 fail: 6
Failed builds:
alpha:allmodconfig
arm:spear6xx_defconfig
score:defconfig
sparc64:allmodconfig
unicore32:defconfig
xtensa:allmodconfig
Qemu tests all passed.
Results are as expected.
Details are available at http://server.roeck-us.net:8010/builders.
Guenter