Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1915378ybh; Fri, 13 Mar 2020 09:35:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtRGKvSCF4APmVxhIAlZI1ueXGWNlYLnNG2F0aA3mC2M2zcJF3AwwQ9jBN1Ww1jVFwCkOeh X-Received: by 2002:aca:fcd8:: with SMTP id a207mr8007426oii.56.1584117319968; Fri, 13 Mar 2020 09:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584117319; cv=none; d=google.com; s=arc-20160816; b=byl2WkBU8dnC+UTZy69PkUAaljdwVJZHq6P05tXjnb6KYvHF3Um0LxBuz/glHG/K7F Dr3RNsh6fnQsLbCrA+vFcOmzGUnVaEq7G3WPlgnbLY850GQ+M4VQvi8DsOC1Q735eHra FcCufqkE7Sm7FrO7VQCWJzPzV2cP1e8tPUaDk5duDq4YQKDCfsE/lLLsUCwwHIDtBQ/2 yx1PBIim5tx4COCJvtbSqSip1f8/h0l63PCW9NJLc26wgsycfNVptVmcCQi1uTpsA3RG D0MTTcascfAegv97tCzNCkzAr9JVYukd0fsSWpGGUkfMSqdllLT3RfHp9b0I6rki+/o4 H75g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:subject:cc:to:from :date; bh=lSF2/ukm9AoON0EoBtDdag3Dz9XtFz6LYjn6FaVSbjc=; b=mqGmEGePOAx+XwL9LwGDfZcbtDsgqkw8dBJyhL6TeET4PY28WT9mPY2ESitOVT9rdj mS6+zmFmDcWnRf0S1WyYCfOUIZSC72nuQ/7WPT5LLHFkolKS4nRXad3ey7UtLtIcNKvX bQIbnizXSCly+5iISJXZbL9G5K74iEM67jS1K9GFAfDdg3uxItJB4KQbSbkH5WsIQQmc /EE6Euk5+BLu8eAF/ktUfgMB7/ADnrXPY1Qs72OnnfYbL2VSpPmEEZiroaL5jTc9dO91 crzq/CED61xJ2dILnpqdBC5XPjW5OywHvgqpVzLflcQbQTsDNUeIwoMetMmEjiS0bxjD k/Pw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 l11si5145992otk.207.2020.03.13.09.35.06; Fri, 13 Mar 2020 09:35:19 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbgCMQeM (ORCPT + 99 others); Fri, 13 Mar 2020 12:34:12 -0400 Received: from foss.arm.com ([217.140.110.172]:60874 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgCMQeL (ORCPT ); Fri, 13 Mar 2020 12:34:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A7B231B; Fri, 13 Mar 2020 09:34:11 -0700 (PDT) Received: from localhost (unknown [10.37.6.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F22D53F6CF; Fri, 13 Mar 2020 09:34:10 -0700 (PDT) Date: Fri, 13 Mar 2020 16:34:09 +0000 From: Mark Brown To: Peng Fan Cc: broonie@kernel.org, gregkh@linuxfoundation.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, Mark Brown , rafael@kernel.org Subject: Applied "regmap: debugfs: check count when read regmap file" to the regmap tree In-Reply-To: <1584064687-12964-1-git-send-email-peng.fan@nxp.com> Message-Id: X-Patchwork-Hint: ignore Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch regmap: debugfs: check count when read regmap file has been applied to the regmap tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 74edd08a4fbf51d65fd8f4c7d8289cd0f392bd91 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Fri, 13 Mar 2020 09:58:07 +0800 Subject: [PATCH] regmap: debugfs: check count when read regmap file When executing the following command, we met kernel dump. dmesg -c > /dev/null; cd /sys; for i in `ls /sys/kernel/debug/regmap/* -d`; do echo "Checking regmap in $i"; cat $i/registers; done && grep -ri "0x02d0" *; It is because the count value is too big, and kmalloc fails. So add an upper bound check to allow max size `PAGE_SIZE << (MAX_ORDER - 1)`. Signed-off-by: Peng Fan Link: https://lore.kernel.org/r/1584064687-12964-1-git-send-email-peng.fan@nxp.com Signed-off-by: Mark Brown --- drivers/base/regmap/regmap-debugfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index e72843fe41df..089e5dc7144a 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -227,6 +227,9 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, if (*ppos < 0 || !count) return -EINVAL; + if (count > (PAGE_SIZE << (MAX_ORDER - 1))) + count = PAGE_SIZE << (MAX_ORDER - 1); + buf = kmalloc(count, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -371,6 +374,9 @@ static ssize_t regmap_reg_ranges_read_file(struct file *file, if (*ppos < 0 || !count) return -EINVAL; + if (count > (PAGE_SIZE << (MAX_ORDER - 1))) + count = PAGE_SIZE << (MAX_ORDER - 1); + buf = kmalloc(count, GFP_KERNEL); if (!buf) return -ENOMEM; -- 2.20.1