Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2714638imj; Mon, 11 Feb 2019 07:23:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IZjGaOnrMDxFsTjigu6KYuigSdrz5Hr/qVOXQsui9GgHyP/W98ol/fAY+Xl/fn5n/RmTqMK X-Received: by 2002:a63:7f46:: with SMTP id p6mr33974225pgn.54.1549898637299; Mon, 11 Feb 2019 07:23:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549898637; cv=none; d=google.com; s=arc-20160816; b=zerhJlE00KEalpFFQXk6lZA3kgBXZmZYltcZmjQJTR9h36tpVUIREhmbkuzALqmnjc Hh7LzOxurNCtCJ/zqzWCuDlcMgEjQQ7blFujxumPeNXWj6RpCget6qw64sugtmmnj6nK if/uUIInXRQTy9Lq2q4+gmSIoPpCyF0I42yKqS/ed3XEHhainA9qBUqC9S38jYbnEJRB OO580heRpXCc3eIpvcvxz2AAQH/8FhQR6Upf4HFYNqfCmgff1xEu88iwnhlN71uExoqa KE6OlYD65TCr6KVFWLMSAkPVRkPGEjzjhTpicmibLDre/8K011Xml68bCZf0AZYT/XlY f8BA== 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=ckhknLRfL+YgFqty7LOxFa7yRhNChvgD/YMJsE8XjhI=; b=dfr8axfRLan0ZxZqoq3/VKGGn2V3hbmBmElO5ZP88oLBzxkU82yv++gPoT5JO46eZp AZ3l3LISMvb0PqnYxw23UAcmaUuJU0Vq+greoRnIvQ3MpkOOU38IIKV4NgKRQC7iP7u1 2I8Ss4jbFurGQkGetwLBdmG/fbCRIZR0mUy3cDAtEW9yJDkA6/FTrF7TkAD0KvrRAbix +0dp6Q/icjf+rd2MeEqzL6VqXBNRRqDQ5TKDz1txozVNyFQe2LA2Z16XTn7cQr8EUXxr YDIk7ehaIVxW8VaBFcAsmzCQcN6FpXzXGCisvDDO2mQkCArVzUZf/KdYPWJT1ey6oa/H 3kHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mOBovhpT; 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 189si10846696pfd.142.2019.02.11.07.23.40; Mon, 11 Feb 2019 07:23:57 -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=mOBovhpT; 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 S2391843AbfBKPWp (ORCPT + 99 others); Mon, 11 Feb 2019 10:22:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:52410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390136AbfBKPDl (ORCPT ); Mon, 11 Feb 2019 10:03:41 -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 1099F222B8; Mon, 11 Feb 2019 15:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897420; bh=btuaW8UpzRjJlmbELzsiIRTC3u6uNxgDNK277ikfV5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mOBovhpTf9QaY33SCRKJg7JOsYC0EhzE1ruvc2WsHPSZycGdMmg01HzExQKqAlOfC OBMlf0WHwO5a2n/9ksay+mI0n/DAX0Eg8dnZbjGz+noC+1VLuPGcmPmIoNpzQE3UuL zb1LqPC/hNE4TgDlStJr9E7/281adV+GZz4wahbA= 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.14 198/205] perf/core: Dont WARN() for impossible ring-buffer sizes Date: Mon, 11 Feb 2019 15:19:56 +0100 Message-Id: <20190211141841.367111122@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 @@ -719,6 +719,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;