Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2533123imu; Thu, 29 Nov 2018 06:30:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/X6YidfAj1kCjm0+ee1+hhxCYr9ShJQg6MnvSKzGcOZStNBVBEu8Y+0+qNpL+5TPwYojFkU X-Received: by 2002:a62:5fc4:: with SMTP id t187mr1631471pfb.66.1543501851667; Thu, 29 Nov 2018 06:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501851; cv=none; d=google.com; s=arc-20160816; b=wCuF1s3VlS55PB+SGpfwAYz2RIbHNQITgJ6XnPY+bMV6x5lEqFZ6+lBGrSOkmIeYGy oKRH8LFnfJ4mVYdidJfYchzI7Hro2gafOEJckWKKyq2hhoZaRg8TpEnokQdQHYZMiJqH xQZaLfBKIzTAZH4ssZ6itWrkE2Q1dxR56QtHiojtkzoOF+NYU1iB1AfMCfc35B0o3SDn mS413UIHH/lHrGRKghzyOprUdxdVMEwSOl5WD6LVr96F/sSFilqYxocSYRGH5yUYp6Ji WFqc9t8QcOKDToKzDXX5+7ouZmuOxNrF6Kv/qOkyHGFnUGq0I9SYNrZhHl/sO05TiMiM xatg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GGxAl5qH1lUEueIkhyV+8079FnwNQjCrdX7+C/8Ll6U=; b=lPMhgb4dvSR0h/bBoeBv6e3OuH4ajPyAUoCkS0Kc/vnXSSGx9dYEMKifhz3dIpTq5R og5i76drIfWWP5MXodCeoSqiGV1emmFku+5r0B+W2Wuz5H1xeRsdbte8nVwQ06XxaOYi Rk4NnvG4rRym4k792cLPMPZ1wkkMmwCWuD3vqakhl4KWmiwzmt6GxmJqTO8Cz6I4RNtS jJ96awrS0GIctSOjV/oP1EeHd/J6jMMG9sCzIEfAdXJ/RULFMFVy/u4L7h9bWJy8OhKT e4YnIIvyW+4l3xNLxB2JNtfiO25P2iT2SzGzg4Jy+tmSTfwMm9q0D4Dh8iwGpG7Hpt7B Wl8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0vCmaCMz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a34si2048163pgb.458.2018.11.29.06.30.35; Thu, 29 Nov 2018 06:30:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0vCmaCMz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388511AbeK3BfM (ORCPT + 99 others); Thu, 29 Nov 2018 20:35:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:36918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732084AbeK3BfM (ORCPT ); Thu, 29 Nov 2018 20:35:12 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D96BE2146D; Thu, 29 Nov 2018 14:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501779; bh=JtWjrHzl7TFr+DEMkWhWKpcWjY9nMb8t8Cvac177LnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0vCmaCMzWh9FH+2lSA18Pb35NX73kkoUVKq9BL+UrI5zEOp0WJm3XewbvgSHj7/5J PPRWYhuxUKcC91C5KHLcpVbsUXPY2HLvS+sjJXNYuGiAsvcTy5R4L3pvr6hJnA4dLJ wbyYR7dPdae9un9sc2nOHwsvZ0DSAsLeViymC+sY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , syzbot+87829a10073277282ad1@syzkaller.appspotmail.com, syzbot+ef4e8fc3a06e9019bb40@syzkaller.appspotmail.com, syzbot+6e438f4036df52cbb863@syzkaller.appspotmail.com, syzbot+8574471d8734457d98aa@syzkaller.appspotmail.com, syzbot+af1504df0807a083dbd9@syzkaller.appspotmail.com, Christoph Lameter , Vlastimil Babka , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 037/110] mm: dont warn about large allocations for slab Date: Thu, 29 Nov 2018 15:12:08 +0100 Message-Id: <20181129135922.763081939@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129135921.231283053@linuxfoundation.org> References: <20181129135921.231283053@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Vyukov commit 61448479a9f2c954cde0cfe778cb6bec5d0a748d upstream. Slub does not call kmalloc_slab() for sizes > KMALLOC_MAX_CACHE_SIZE, instead it falls back to kmalloc_large(). For slab KMALLOC_MAX_CACHE_SIZE == KMALLOC_MAX_SIZE and it calls kmalloc_slab() for all allocations relying on NULL return value for over-sized allocations. This inconsistency leads to unwanted warnings from kmalloc_slab() for over-sized allocations for slab. Returning NULL for failed allocations is the expected behavior. Make slub and slab code consistent by checking size > KMALLOC_MAX_CACHE_SIZE in slab before calling kmalloc_slab(). While we are here also fix the check in kmalloc_slab(). We should check against KMALLOC_MAX_CACHE_SIZE rather than KMALLOC_MAX_SIZE. It all kinda worked because for slab the constants are the same, and slub always checks the size against KMALLOC_MAX_CACHE_SIZE before kmalloc_slab(). But if we get there with size > KMALLOC_MAX_CACHE_SIZE anyhow bad things will happen. For example, in case of a newly introduced bug in slub code. Also move the check in kmalloc_slab() from function entry to the size > 192 case. This partially compensates for the additional check in slab code and makes slub code a bit faster (at least theoretically). Also drop __GFP_NOWARN in the warning check. This warning means a bug in slab code itself, user-passed flags have nothing to do with it. Nothing of this affects slob. Link: http://lkml.kernel.org/r/20180927171502.226522-1-dvyukov@gmail.com Signed-off-by: Dmitry Vyukov Reported-by: syzbot+87829a10073277282ad1@syzkaller.appspotmail.com Reported-by: syzbot+ef4e8fc3a06e9019bb40@syzkaller.appspotmail.com Reported-by: syzbot+6e438f4036df52cbb863@syzkaller.appspotmail.com Reported-by: syzbot+8574471d8734457d98aa@syzkaller.appspotmail.com Reported-by: syzbot+af1504df0807a083dbd9@syzkaller.appspotmail.com Acked-by: Christoph Lameter Acked-by: Vlastimil Babka Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/slab.c | 4 ++++ mm/slab_common.c | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) --- a/mm/slab.c +++ b/mm/slab.c @@ -3675,6 +3675,8 @@ __do_kmalloc_node(size_t size, gfp_t fla struct kmem_cache *cachep; void *ret; + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) + return NULL; cachep = kmalloc_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; @@ -3710,6 +3712,8 @@ static __always_inline void *__do_kmallo struct kmem_cache *cachep; void *ret; + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) + return NULL; cachep = kmalloc_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1027,18 +1027,18 @@ struct kmem_cache *kmalloc_slab(size_t s { unsigned int index; - if (unlikely(size > KMALLOC_MAX_SIZE)) { - WARN_ON_ONCE(!(flags & __GFP_NOWARN)); - return NULL; - } - if (size <= 192) { if (!size) return ZERO_SIZE_PTR; index = size_index[size_index_elem(size)]; - } else + } else { + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) { + WARN_ON(1); + return NULL; + } index = fls(size - 1); + } #ifdef CONFIG_ZONE_DMA if (unlikely((flags & GFP_DMA)))