Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1751972imd; Sun, 4 Nov 2018 08:44:22 -0800 (PST) X-Google-Smtp-Source: AJdET5cwD11oDyAjeGl1A/uzMP5phXpR6YFXU2gRf+POV+MpOd1PTlOiI05MV7eSaY6LcC+TyTMH X-Received: by 2002:a63:1e5c:: with SMTP id p28mr17522949pgm.376.1541349862232; Sun, 04 Nov 2018 08:44:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541349862; cv=none; d=google.com; s=arc-20160816; b=XzJzfvA98FjxwjlzuRTwWRpchmCn7YdVXZywtlGVz7YvH9AytIuWVKKocWfpjsjQ+T JFP4QvSh92wb4tBw7PrpLfe9VlPJvNPn8ydhONDgOze3h/27a9Q1+O/KqJ1v5xoiI2uA rlko5nU6rtEdAE1g7iydxvU0dr8/I+ZOeZFE/6Zm1nsfRFOEIAXVCL2E7RMCiLHoQqMj h5mjwZEtd2B8yayjtX7zI4CjnLZ0RfT4+2I4TXhQ4UIsWbJQ+IerCfA0GpZ2mtbT3bZj BNVlstCg3Byfq91OoEWxjzR/aw9lFjVBR3Srj0fdyP/NM+J3xZXX24BvGT6ztdXohr39 jQFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=QIvKUw06n8Jw1tPXgvlWbpq7rNpI7b9HD6USl64l0qQ=; b=MChGjy1sEXCFfcFuuN7gLdZAhcq94HQsld0FfXlhy3C/l/0P9ofy1MUyi6wjFHGb/o cMBDbeY6i6FsjNIcbw/UprvNfq5YOlsFSo9IpnlC1rdorpHQrKk+PbP/LPsG2LVfHqcD HHtnZcT95aMNXD8QXCmkyLFilAA+Lz48GH8pQ+ZyxUxfZocW1rKSzhC0zdLng/uyqB5Q mbhepEfPQbfyRRN0wEianOBpThL/p/+Ef0GUfXndEZlloRP+svgEfeqiekPzA/9aR0fM 2goPaWCJxD0dMWE9586FpWDW1Z5DokQlJats4+UQCwDNuaGpJ+WqBdcsxbC3rJ41sfWY ZSJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rJuq7RXo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j193si20127597pge.332.2018.11.04.08.44.05; Sun, 04 Nov 2018 08:44:22 -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=rJuq7RXo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731193AbeKDXIh (ORCPT + 99 others); Sun, 4 Nov 2018 18:08:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:47426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731131AbeKDXIg (ORCPT ); Sun, 4 Nov 2018 18:08:36 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C82E42086D; Sun, 4 Nov 2018 13:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541339611; bh=g4oRi6iD6jYnZXzqC9XJfHAoZ363ncG3WwRFG+WbXic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rJuq7RXoBhvqWiWWYUDvrRwcqC2gdLq+M0SznFClxKvP4bNPp7/NnbH6ZBtjEYXaP olXePR0gGw4yVolQpE8ecaQynBZsNTsIa/OVaEEawaaLCEAnF5cFxkVhpwJHbNGC/s I7i6c7Czzyy/0Z3sq6UeMnW9vveYXYob+uIEulfA= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL 4.14 04/30] mm: don't warn about large allocations for slab Date: Sun, 4 Nov 2018 08:52:59 -0500 Message-Id: <20181104135325.88524-4-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181104135325.88524-1-sashal@kernel.org> References: <20181104135325.88524-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Vyukov [ Upstream commit 61448479a9f2c954cde0cfe778cb6bec5d0a748d ] 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: Sasha Levin --- mm/slab.c | 4 ++++ mm/slab_common.c | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 198c1e2c5358..68ab88e2920e 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3670,6 +3670,8 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) 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; @@ -3705,6 +3707,8 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, 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; diff --git a/mm/slab_common.c b/mm/slab_common.c index 91d271b90600..f6764cf162b8 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -971,18 +971,18 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) { 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))) -- 2.17.1