From patchwork Tue Nov 13 05:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3031F13B5 for ; Tue, 13 Nov 2018 05:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FD5D2A3E3 for ; Tue, 13 Nov 2018 05:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13AFA2A3EA; Tue, 13 Nov 2018 05:52:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68E3F2A401 for ; Tue, 13 Nov 2018 05:52:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 503646B0296; Tue, 13 Nov 2018 00:52:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4B25F6B0298; Tue, 13 Nov 2018 00:52:53 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A19B6B0299; Tue, 13 Nov 2018 00:52:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id ECE496B0296 for ; Tue, 13 Nov 2018 00:52:52 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id d3so2093892pgv.23 for ; Mon, 12 Nov 2018 21:52:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=bqZ54MBmrjmMNgDCtGXCmvDrjmlFifdcLxSRPiMR838=; b=WV+jM3HZah05vAXONDQ7kqTNMEi4b2qdgsfclOMrGl9EEDs5oji9oKdABCO5CZ+fJs IvMB2eDdxhf67OB1qV5pn4+Vc2jfHuOsSsxeduVIKVpN45rtMeyhIQy6kC4LPsHpjdEw PATmlQa5Abuh2MuW9gmeY2LMm9fU29ZqVKin6MxukZ8MK93wnzLQNX2BSf1Col5Ecdlc ES2VDvysMItDdiETJLYWN4XfPNLl0Kg7KoeAAQ99UlBO1H0Y2bSbC/5oMk5zOBsWaXk4 9FGyRkAib7V+JyWiaNBsbqaBoeJPfkeHTf8HTe835iBkf/G5dbDQDxTKM1f/kMwo49FO L5ZQ== X-Gm-Message-State: AGRZ1gKaunrDBkOkLqO9xHS+t3sVE1TIx/1MJkrcFzvoz19kdZXSSXB8 fhE43cOYe6wqsBZdFkwtAm67JsM6w4jfuW7BrtfXoj17yBE+xOEFUISYLiEy1q+5t4ZkiPgEgEZ Wq8oDMDE7KZXsVxaTC1kXE5pSAwhiB0Q7eMv3kp3/MyeCK2RAaKkr0HC1qXEnC18s5Q== X-Received: by 2002:a63:f111:: with SMTP id f17mr3538427pgi.236.1542088372662; Mon, 12 Nov 2018 21:52:52 -0800 (PST) X-Google-Smtp-Source: AJdET5edVgXzpGpuMhxfVci9mWEtuNVk6jpDNkceuc1IOyoe5s8h22RDgYFqFpjDJTAcyX48UkJJ X-Received: by 2002:a63:f111:: with SMTP id f17mr3538403pgi.236.1542088372075; Mon, 12 Nov 2018 21:52:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088372; cv=none; d=google.com; s=arc-20160816; b=o6V3QEZQDucTLCj3Ne0oXz029ZceI5BH0BKaoJgU4Br0FFz9emii8rxXF77/bCBEGB t8f+d39/WbeSEc6MsUf+rFS7g3Z3TnsvQsnSkoixMGx4ohBYFE0L6HsiqdRHfRgkbsMh SuL05IuEVu1kAbQ2FqSmsxrxwAm1jWIvVdwgUgLOaxSEkiMs2eJGA/GPQL2InpfohnOm zAxVUR+i6RH6xTnoQmZdjsu4w/nICDiyLIhmF3RTMyhqewoXsjw701rC94VOzNC5JZK6 BIqwLBt7lKfFb0j0FNW6xKs8Y31uB2PucRlEWEVuo18pSYhvOAotVww1j56mjXUFcS+F 1QIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bqZ54MBmrjmMNgDCtGXCmvDrjmlFifdcLxSRPiMR838=; b=JSnx4qSBxDRK3XXcSXBafilNp7RyKH/fnfEqguHqxeAj/RYYujoZzoxzHZLf4sDqKs ybqLgcFoas8Y/ugdqqZUmsWn5ux7EvKSFjoAVfJ91qitLB2a1WW05MdsMoeNuGWqL8Z7 bP1Jd9Q/MH5QQFOrCeL0cobDARW7DM9AiGsgVkZk4tqx6xpyXIpuWVjQPykw2x4iWtKK uUqI64gyktF8dLxYJNOdGd3PzICBrniC2ingOiJ5aV1McfXp9yEEFAV5LX02PdfkrSeV GGSwyCJo8Zv5xH5PO86tzCju2K4Z3e9gQUt8yz5eNcHUJ0tPThrrMpSCNsaMTpRUPTNe A/kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w6LLOJWa; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id b72-v6si20985872pfm.100.2018.11.12.21.52.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:52 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w6LLOJWa; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (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 9C04B22510; Tue, 13 Nov 2018 05:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088371; bh=Ny8zzV0yk8eMNO5DqbjgBZY3F+sPJt2FCVYCP8c6wys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w6LLOJWaocTY/wVHWwSNRmRZ9OMruNZ16hu6V8eWdGDQD3WHBL45QluN7Tkmu5zcO 3HDAgJnBet/KRODoenmeLMT+6fc6WiUQDHwiKsFZM/P3lvJav6pLLiwOkMMJMDRGMC ypc10Wtqu6+p4jSqQIRUwu8Wa9qRnRnumLOd/O9g= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jann Horn , Davidlohr Bueso , Oleg Nesterov , Christoph Lameter , Kemi Wang , Andy Lutomirski , Ingo Molnar , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.4 10/11] mm/vmstat.c: assert that vmstat_text is in sync with stat_items_size Date: Tue, 13 Nov 2018 00:52:41 -0500 Message-Id: <20181113055242.79261-10-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055242.79261-1-sashal@kernel.org> References: <20181113055242.79261-1-sashal@kernel.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Jann Horn [ Upstream commit f0ecf25a093fc0589f0a6bc4c1ea068bbb67d220 ] Having two gigantic arrays that must manually be kept in sync, including ifdefs, isn't exactly robust. To make it easier to catch such issues in the future, add a BUILD_BUG_ON(). Link: http://lkml.kernel.org/r/20181001143138.95119-3-jannh@google.com Signed-off-by: Jann Horn Reviewed-by: Kees Cook Reviewed-by: Andrew Morton Acked-by: Roman Gushchin Acked-by: Michal Hocko Cc: Davidlohr Bueso Cc: Oleg Nesterov Cc: Christoph Lameter Cc: Kemi Wang Cc: Andy Lutomirski Cc: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/vmstat.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/vmstat.c b/mm/vmstat.c index a2d70ef74db7..a32a92c0f218 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1320,6 +1320,8 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) stat_items_size += sizeof(struct vm_event_state); #endif + BUILD_BUG_ON(stat_items_size != + ARRAY_SIZE(vmstat_text) * sizeof(unsigned long)); v = kmalloc(stat_items_size, GFP_KERNEL); m->private = v; if (!v) From patchwork Tue Nov 13 05:52:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86DC5109C for ; Tue, 13 Nov 2018 05:56:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73F2A29FAC for ; Tue, 13 Nov 2018 05:56:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67E682A264; Tue, 13 Nov 2018 05:56:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDEA929FAC for ; Tue, 13 Nov 2018 05:56:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF48A6B02A2; Tue, 13 Nov 2018 00:56:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AA3616B02A4; Tue, 13 Nov 2018 00:56:54 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96CD06B02A5; Tue, 13 Nov 2018 00:56:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 4F9916B02A2 for ; Tue, 13 Nov 2018 00:56:54 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id 3-v6so8728742plc.18 for ; Mon, 12 Nov 2018 21:56:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=yyRhDkVHnLPir3MLuVerX8QaqXfZg1SH6fYdNJBVLYU=; b=aYrDpkYso9bt+FsImkZQTT8NfqpNPOpJyZxKm0Qm/Pzai8UwEPrt3cosnSKn0ST8Gn nglD2+x+wAIo0VakDXqdSudeOsSiem8Oa8sGnXMtwT9+6NAfy3rUEOxVYWtM9YKkIzJN XSsgnf0QbVl23563lKU9O9MjxCdbrICKTi3J2u0uh9Xb5sQ3FPUdLjFj07OuDkjw7Lxq eu7M5YjoFUuwNmsMeLQk8gMUBh3WGSC7XHLP134nGvVG14v2JJPAASNOSlE2jJiAbU0M /uSOksglGPZ+7IfOskaml1yrLQyx0q3RND5Wq3nl+STTchxk0t2iZEgxhWS2ET1sRx/7 HQcA== X-Gm-Message-State: AGRZ1gIwxn13Jzx1JbZmO2nS1KMpP7YEE5xHtNc4RSZgrUiZFngmtdCq xN1YO9suFSiOsv5240fEE8NGETX7pht0tEwKozesV72ozW9Z2Gpq3dq1a5AlhCG9c6proths/in rUbdzcGavqehvRu+KyyyXbcf4B3zV2WcEkL8wICwEC+D7t26+6vIoS/TtgSE3IrvquMlZpJMRx8 sSPdJFrQ8VbxJBNiGVWOb/0poyQVzpQoVRMTCgietI2Ekz2rE0VG1aW3OoL2J9pJGf6TqanDHb6 1af67MwM7Y0UUYrOAsoZPFem8Df7wAT5LhXBA6RTuY1/xgNmejuTDydta1+ShYOaEwDxdwn69bw zMkDt80IyC9AWrVVYB727VjNGBl9vTWTecqurR/Wm6Pe5GFGQuPcXKVO6n2AOi/WxOq0gU6b68m m X-Received: by 2002:a62:1954:: with SMTP id 81-v6mr3771420pfz.237.1542088373828; Mon, 12 Nov 2018 21:52:53 -0800 (PST) X-Received: by 2002:a62:1954:: with SMTP id 81-v6mr3771417pfz.237.1542088373716; Mon, 12 Nov 2018 21:52:53 -0800 (PST) X-Google-Smtp-Source: AJdET5d5abZ/gkUtIufwS+WAWTgdemvX8ubMGJyYmeO2eF7yQzAJ9uUstfo10RZYWT1ceLUf5veG X-Received: by 2002:a62:1954:: with SMTP id 81-v6mr3771360pfz.237.1542088372451; Mon, 12 Nov 2018 21:52:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088372; cv=none; d=google.com; s=arc-20160816; b=lLWMzm/7ZxHcS8nftsvytpA9nKpdXwt+/rrUx7UauLDxmst5WvT3qBoJCLpDDlA83p Zjlf6kjeW9TTlIQfgLQQyrGaxisFrNyGg8dOJer5CS7sD4xOHNBK9qypBXerXBmr3Qep CilhnnSHs9hqCRBQhmhACPMExl/Di0U14HzTNZpXFRYh3gcHuZaTlvKoywTu//59lHTQ 7BJzz1Q5fTwuV0PZokrpXbc2/JdK2ni4JfQp0F5x5vZZMujMls1QMzX5VFEF8QKpzPaU NGbURNnuvEzBSIxnF6rMR9uIJaba5p4ojNWY+TOOFfZRi5uIJwoH5wYsZ9BFPYsPRAL4 f34w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yyRhDkVHnLPir3MLuVerX8QaqXfZg1SH6fYdNJBVLYU=; b=AKx/PRI5d7l37SvoR1SEGU9V70FZotviBTVw/pN7FyumrqDbW0j1XcvaK9EpAxaGo9 xMa8Nj5FyaoYARN4Y8zsy1MAe3kMhQSOWiQlIKJ7m3iR1QO0GkEliXWmuWduHm7S+7Sa aWJkZlbgnJSaRcKsZlcJg+7CixMrqeq0HzOxwnQEfp2HKPI+RL2ySSjjFX1UhZASnL+s b5fkvQYVbe3Dwb0Sx/aeFsCj3RpekDUfneuZjZtzA0acwxBeVk4nQMkBbyeyDhcQhNZ8 OhY3mT1RggTMasLRd9tI4BuWGgjNc+2VJJiEzmRuzepnzAAgSyk8RzXZf00H9Vr4t5Te aCPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="w/I/KyFZ"; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id z16-v6si17497770pgu.525.2018.11.12.21.52.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:52 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="w/I/KyFZ"; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (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 0564422520; Tue, 13 Nov 2018 05:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088372; bh=4yz+H6yCMY6hvEdFnbqCuw5Yp9MXp7hlNfxn1OGqh5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w/I/KyFZ8jzAaIwAX/48sS9mp2LZjgp7CBUgNTUNpFjIKhcJJpqmExMxds8JoHLNI gdxZ7dovNgdK7edsDVfRjE0wNRVC2S7v685cwq6qGDyZikHl6Ua8w6zYyVQf+Q6z1V HPQ4DQLyKLvrBu4xLfhiyg4tJy2SbHPOh0W5zJDw= 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 , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.4 11/11] mm: don't warn about large allocations for slab Date: Tue, 13 Nov 2018 00:52:42 -0500 Message-Id: <20181113055242.79261-11-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055242.79261-1-sashal@kernel.org> References: <20181113055242.79261-1-sashal@kernel.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 fa49c01225a7..49a64b8c3606 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3488,6 +3488,8 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) { struct kmem_cache *cachep; + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) + return NULL; cachep = kmalloc_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; @@ -3520,6 +3522,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 01e7246de8df..2e7c960d6a06 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -852,18 +852,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)))