Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2746727imj; Mon, 11 Feb 2019 07:53:46 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibw7Y7xhKSsJwNauDMTn3zTzQNrb+/Dhi3y4dUl8eXow2VxJx/VGeN3RJOdUAKY9uID7Nt4 X-Received: by 2002:a63:a11:: with SMTP id 17mr6311927pgk.310.1549900426776; Mon, 11 Feb 2019 07:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900426; cv=none; d=google.com; s=arc-20160816; b=0YG8jtDTEzdBZgaRZGrUZsytLLgjeiCqRHaDecuJYAFM8FRyuVedfiEcvQUZMRFMsp BsewHp1Pdxw6mL0iGKj6+Ck/gU9PBbzKltQPqEkjYXHhWvMXPoztzSaSuOgOV6EwzxAx o1Kd5Sf5dZwwmZ9oAPPS9HSlrx6MfhK0Y7WCzrOBGXeRCqVyCE+ErnS/wNIFF416P34P aXw0UUMAA3MZvENRkRe4AmNNqHEAnAWMX9rh/k+P5tCGoywflZVswKQG7KgMMwM9DT3T rF42wKpdeja3SpIsLZk45W0K9uj+YVkOHuLZlwlqbIeqYhAkmQom5l4Bmox8M5WW99n5 OBJA== 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=FzPEhyplwl8YA3QS7LwJlGGSwxCSqYgUbrsX8zFkNA0=; b=hb/ZRh9dMdVetTbMyDteE5WnWQff/OBHzQFu97c8f5Dn1O5WPjRGBUTWOKcxKTxTWp WsMdX6Mwa1KGg3R9rHbRfPGqh4ZG1c1ES1X4K1NL09PpNRxppzU9BoT4HLyt8MLNtLKB EOpkERTSZ0+b+kOoHIhTj+7QYazrCyU5kRl73gr1p1FDHWT3+7XksDY4I45aj+2cV9YR 0IKmYm+wzLyBwkgfuSlRkTbOLHdgKl1hrbwkelQdWier314bQlvFM1HipEGMm8wwRxrs a4vzpMxdeNIRRhAs9NwxcmpX+NHKo4jZ3X99AZUS/5dvU6o3WUBlprFHzp37/dfdbwcd YDSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X2zU8Lc5; 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 c10si1056925pls.271.2019.02.11.07.53.29; Mon, 11 Feb 2019 07:53:46 -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=X2zU8Lc5; 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 S1731627AbfBKOiO (ORCPT + 99 others); Mon, 11 Feb 2019 09:38:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:47874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731614AbfBKOiM (ORCPT ); Mon, 11 Feb 2019 09:38: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 1EC03222A1; Mon, 11 Feb 2019 14:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895891; bh=buwIrzeTtNxuDndP9yFI8r5S4TeNuCDP2K/6GxA0j70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X2zU8Lc5QoOFR4RKEpv0UTdd0Yb5iHKtfjelnF+6p2Sx3P+YgEMqWk+oYF/ZoIYCL 3+cbZaU1LWkmcyMkcoJNSvzoGU0nkjBb7VtlbMRnC4+boh2kUvW/iArcB54sa+F33N /KKPXgGEZdel9PFbpH5gCgy4KRkJREzgGQK9gYeI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julien Thierry , Mark Rutland , "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Namhyung Kim , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.20 346/352] perf/core: Dont WARN() for impossible ring-buffer sizes Date: Mon, 11 Feb 2019 15:19:33 +0100 Message-Id: <20190211141909.196297884@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mark Rutland commit 9dff0aa95a324e262ffb03f425d00e4751f3294e upstream. The perf tool uses /proc/sys/kernel/perf_event_mlock_kb to determine how large its ringbuffer mmap should be. This can be configured to arbitrary values, which can be larger than the maximum possible allocation from kmalloc. When this is configured to a suitably large value (e.g. thanks to the perf fuzzer), attempting to use perf record triggers a WARN_ON_ONCE() in __alloc_pages_nodemask(): WARNING: CPU: 2 PID: 5666 at mm/page_alloc.c:4511 __alloc_pages_nodemask+0x3f8/0xbc8 Let's avoid this by checking that the requested allocation is possible before calling kzalloc. Reported-by: Julien Thierry Signed-off-by: Mark Rutland Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Julien Thierry Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Link: https://lkml.kernel.org/r/20190110142745.25495-1-mark.rutland@arm.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- kernel/events/ring_buffer.c | 3 +++ 1 file changed, 3 insertions(+) --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -734,6 +734,9 @@ struct ring_buffer *rb_alloc(int nr_page size = sizeof(struct ring_buffer); size += nr_pages * sizeof(void *); + if (order_base_2(size) >= MAX_ORDER) + goto fail; + rb = kzalloc(size, GFP_KERNEL); if (!rb) goto fail;