From: Peng Liu <liupeng256@huawei.com>
To: <bhelgaas@google.com>, <tglx@linutronix.de>, <mingo@redhat.com>,
<bp@alien8.de>, <dave.hansen@linux.intel.com>, <x86@kernel.org>,
<hpa@zytor.com>, <lorenzo.pieralisi@arm.com>,
<guohanjun@huawei.com>, <sudeep.holla@arm.com>,
<rafael@kernel.org>, <lenb@kernel.org>,
<akpm@linux-foundation.org>, <logang@deltatee.com>,
<martin.oliveira@eideticom.com>, <thunder.leizhen@huawei.com>,
<axboe@kernel.dk>, <kch@nvidia.com>, <ming.lei@redhat.com>,
<shinichiro.kawasaki@wdc.com>, <mcgrof@kernel.org>,
<jiangguoqing@kylinos.cn>, <jpittman@redhat.com>,
<dave@stgolabs.net>, <liupeng256@huawei.com>,
<wangkefeng.wang@huawei.com>, <linux-block@vger.kernel.org>,
<linux-ia64@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-pci@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>, <linux-mm@kvack.org>
Subject: [PATCH 2/2] null_blk: fix wrong use of nr_online_nodes
Date: Fri, 6 May 2022 01:58:01 +0000 [thread overview]
Message-ID: <20220506015801.757918-3-liupeng256@huawei.com> (raw)
In-Reply-To: <20220506015801.757918-1-liupeng256@huawei.com>
Certain systems are designed to have sparse/discontiguous nodes,
a valid node may be greater than nr_online_nodes. So, the use of
"nid >= nr_online_nodes" to judge if a node is online is wrong.
Node id is a basic parameter of the system, a user-configured node
must be checked as early as possible. Otherwise, it may cause panic
when calling some vulnerable functions such as node_online which
will cause panic if a very big node is received.
Check g_home_node once users config it, and use node_available to
make node-checking compatible with sparse/discontiguous nodes.
Fixes: 7ff684a683d7 ("null_blk: prevent crash from bad home_node value")
Signed-off-by: Peng Liu <liupeng256@huawei.com>
Suggested-by: Davidlohr Bueso <dave@stgolabs.net>
---
drivers/block/null_blk/main.c | 45 ++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 05b1120e6623..995348d6e7e7 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -97,7 +97,33 @@ module_param_named(poll_queues, g_poll_queues, int, 0444);
MODULE_PARM_DESC(poll_queues, "Number of IOPOLL submission queues");
static int g_home_node = NUMA_NO_NODE;
-module_param_named(home_node, g_home_node, int, 0444);
+
+static int null_param_store_val(const char *str, int *val, int min, int max)
+{
+ int ret, new_val;
+
+ ret = kstrtoint(str, 10, &new_val);
+ if (ret)
+ return -EINVAL;
+
+ if (new_val < min || new_val > max)
+ return -EINVAL;
+
+ *val = new_val;
+ return 0;
+}
+
+static int null_set_home_node(const char *str, const struct kernel_param *kp)
+{
+ return null_param_store_val(str, &g_home_node, 0, MAX_NUMNODES - 1);
+}
+
+static const struct kernel_param_ops null_home_node_param_ops = {
+ .set = null_set_home_node,
+ .get = param_get_int,
+};
+
+device_param_cb(home_node, &null_home_node_param_ops, &g_home_node, 0444);
MODULE_PARM_DESC(home_node, "Home node for the device");
#ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION
@@ -120,21 +146,6 @@ MODULE_PARM_DESC(init_hctx, "Fault injection to fail hctx init. init_hctx=<inter
static int g_queue_mode = NULL_Q_MQ;
-static int null_param_store_val(const char *str, int *val, int min, int max)
-{
- int ret, new_val;
-
- ret = kstrtoint(str, 10, &new_val);
- if (ret)
- return -EINVAL;
-
- if (new_val < min || new_val > max)
- return -EINVAL;
-
- *val = new_val;
- return 0;
-}
-
static int null_set_queue_mode(const char *str, const struct kernel_param *kp)
{
return null_param_store_val(str, &g_queue_mode, NULL_Q_BIO, NULL_Q_MQ);
@@ -2107,7 +2118,7 @@ static int __init null_init(void)
g_max_sectors = BLK_DEF_MAX_SECTORS;
}
- if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) {
+ if (!node_available(g_home_node)) {
pr_err("invalid home_node value\n");
g_home_node = NUMA_NO_NODE;
}
--
2.25.1
prev parent reply other threads:[~2022-05-06 1:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-06 1:57 [PATCH 0/2] null_blk: fix wrong use of nr_online_nodes Peng Liu
2022-05-06 1:58 ` [PATCH 1/2] include/linux/nodemask.h: create node_available() helper Peng Liu
2022-05-06 17:23 ` Bjorn Helgaas
2022-05-06 1:58 ` Peng Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220506015801.757918-3-liupeng256@huawei.com \
--to=liupeng256@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dave@stgolabs.net \
--cc=guohanjun@huawei.com \
--cc=hpa@zytor.com \
--cc=jiangguoqing@kylinos.cn \
--cc=jpittman@redhat.com \
--cc=kch@nvidia.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=lorenzo.pieralisi@arm.com \
--cc=martin.oliveira@eideticom.com \
--cc=mcgrof@kernel.org \
--cc=ming.lei@redhat.com \
--cc=mingo@redhat.com \
--cc=rafael@kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
--cc=sudeep.holla@arm.com \
--cc=tglx@linutronix.de \
--cc=thunder.leizhen@huawei.com \
--cc=wangkefeng.wang@huawei.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).