Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3297203lfo; Mon, 23 May 2022 01:01:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa0EXtjKOonO7lR7NmCtsKJneHPFZk1eyMS6SdT+pE2XFsz7+TwEl0xhszQDps5koC/fet X-Received: by 2002:a17:902:c2cf:b0:15f:1396:f54e with SMTP id c15-20020a170902c2cf00b0015f1396f54emr22096882pla.161.1653292872880; Mon, 23 May 2022 01:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653292872; cv=none; d=google.com; s=arc-20160816; b=SNAOneOINqiCoq3tbaFObNezzVZDPbRNS23aFoF4RKQh8olulQe6GvOLuouvmabFzU fRNTcI2Evepzn/G1kLNdhHk/3JXg9zL0jvoIn2mEjH5CWg6Rf5i+Uzq2/S7nqTFmDUd9 hLqbfyR/SR4GF691znCbNSyxn6I3HRnUgBeG3apCg/SNCU1nN3wV2ytY8oNSyxk/j0Ub zYgkfh7xIEJd+nec5MgyM0+QtrB77QwkZUpx1qcRsmN+fNCwGzghx4LB7AYNTFYGDBLN Dd1LvkG81aLrfm67r5POaxI85LdJLaAfLowNa/36rA1udG0aZ+ncbrzjejxASyEjXTdj FhWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=nEiUYsZ+8khJEOccAB6dAVTEN6RutGXDJsbdAydQHRQ=; b=0evDmAWRVixDeb0TkAAfgK6XbZkV2e76zshhue+HgX3Mps+W1BBq0dBGxe3yg1vRs7 5Ao9sntaY6HJ+4OfGvneE91/Q2wZYQUoGqJx9ge7OaLvb5ue63U0+De3o5wOMNZaP0yG Gzz2Ji3FhGk1DXyaREu/Kjs3suMR+EIS/bcLesCsM7/vI8CHY17ZvEKlRjs6ROAx9tFs lmmgHbmXK5o//aUxC1TwpQCIRzvQ3IindKBhNdnVPTjPfH4tCWeY/d6Ut546EBIIgRf8 7UzKUKPR+y1tnaKc/+2b+JUnPl2BJ/ohKQwSwKrXQZH0l4drZfF8csGh426pAEk6Ci6m WBOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v8-20020a63bf08000000b003aa36aa1f45si9530305pgf.754.2022.05.23.01.01.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:01:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A547663BF3; Mon, 23 May 2022 00:00:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346400AbiETHXP (ORCPT + 99 others); Fri, 20 May 2022 03:23:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346348AbiETHXE (ORCPT ); Fri, 20 May 2022 03:23:04 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9213514ACB9; Fri, 20 May 2022 00:23:02 -0700 (PDT) Received: from kwepemi100016.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L4J800KcXzhYR4; Fri, 20 May 2022 15:22:08 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi100016.china.huawei.com (7.221.188.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 20 May 2022 15:23:00 +0800 Received: from localhost.localdomain (10.175.112.125) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 20 May 2022 15:22:58 +0800 From: Peng Liu To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 2/2] null_blk: fix wrong use of nr_online_nodes Date: Fri, 20 May 2022 07:37:47 +0000 Message-ID: <20220520073747.1184091-3-liupeng256@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520073747.1184091-1-liupeng256@huawei.com> References: <20220520073747.1184091-1-liupeng256@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Suggested-by: Davidlohr Bueso --- 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 c441a4972064..312903f3a09e 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= 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