Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp794533pxp; Fri, 11 Mar 2022 15:19:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxv2lfHW2HhGFVm+5sbAyPeMWWIfKiBSURgRxVfEWv4kkETogHAKEcA68XpCFGU7PqVx7lk X-Received: by 2002:a17:902:e807:b0:151:e079:e945 with SMTP id u7-20020a170902e80700b00151e079e945mr12417267plg.172.1647040766519; Fri, 11 Mar 2022 15:19:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647040766; cv=none; d=google.com; s=arc-20160816; b=hVqpAdtlroObT4OAl4FgYADHAeAW8e3fwB+aHrogjOCvLZvTt+daPAcNeuphKcVOcI OwsC3mgu5V+icmJwLUqZGI9PpqLUPf5wy2jA71iHau0bs9qJ2QL2r7K7qTzyIriMSlwd lkQ6NfC1hiAS1+9Q42gQrFN4gt4hG02TFXRfJciA900aarLArNiz9fqWNEcFezG6nIqu ygLbJsWUioABSDzQgHAbmcu2T6TeKJzGPbFvGVKfYB39y8CQmxYAsgSdFq1MIL/czRFO E+keiCDa+o7zTCW6uKQNwn5Ag+YglPYw1UMA/2u1PcNlrgDVOBAV9tigmgDaVTjVpfJe fB2Q== 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 :message-id:date:subject:cc:to:from; bh=05Lm79gpP1IFxl+fPHMsx1M0oWtCVXQBqyGultGg+uc=; b=yggLawAOP6tsmVWwvFUm8NItvSgO0vY/56+QWi2Fs9Lvs5/pGK0Iixvfd5KXF8qSb0 HA5tSIPez/mHHgHVxfSLLb+NbPOdCH+NvtLmJK+X1dBGUm4/45+0NM/aZEWipq1r8fiV 94qyvodxCNo7x0Jjz/g4PhO+Fu5wh4Le9F9fy6dMM2gpZpJ51XqSUt9nNiNHt8vLKx/A 74fa52rfLu8GDBOGXBECs/l3Jv0ioyK+Me1YFctOIJ+UHANUtUDUPmZgVsJqNdZJLv6l VM0+ImqJAo3LGn9vcA6tgEjMBrii5JNuZl23oNWRlv3s2OhoI0vg6cUd086eybvdNfpI gGBg== 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s5-20020a056a00194500b004f797e2b926si2148965pfk.219.2022.03.11.15.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 15:19:26 -0800 (PST) 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C27EC39CC0B; Fri, 11 Mar 2022 14:05:55 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345744AbiCKDWL (ORCPT + 99 others); Thu, 10 Mar 2022 22:22:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232062AbiCKDWK (ORCPT ); Thu, 10 Mar 2022 22:22:10 -0500 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4F195DD463; Thu, 10 Mar 2022 19:21:03 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-01 (Coremail) with SMTP id qwCowADn7_sEwCpi2aYEAw--.16627S2; Fri, 11 Mar 2022 11:20:37 +0800 (CST) From: Jiasheng Jiang To: stephen@networkplumber.org Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, kpsingh@kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] hv_netvsc: Add check for kvmalloc_array Date: Fri, 11 Mar 2022 11:20:35 +0800 Message-Id: <20220311032035.2037962-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowADn7_sEwCpi2aYEAw--.16627S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKFW3Jw4xCrW3Wr15tr1fJFb_yoWDCrX_ur 48urnxZr4UCryrKF47tFy7Zr9Yyw4vqF1fZFW2qrZ3JFy8ArW7W3WrZrnrXrWfur4Y9F9x C3ZrAF4Yv39FgjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbaAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_ Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr 1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E 8cxan2IY04v7MxkF7I0En4kS14v26r4a6rW5MxAIw28IcxkI7VAKI48JMxC20s026xCaFV Cjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWl x4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r 1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Wr1j 6rW3Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8Jr UvcSsGvfC2KfnxnUUI43ZEXa7sRidbbtUUUUU== X-Originating-IP: [124.16.138.126] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ 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 As the potential failure of the kvmalloc_array(), it should be better to check and restore the 'data' if fails in order to avoid the dereference of the NULL pointer. Fixes: 6ae746711263 ("hv_netvsc: Add per-cpu ethtool stats for netvsc") Signed-off-by: Jiasheng Jiang --- drivers/net/hyperv/netvsc_drv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 3646469433b1..018c4a5f6f44 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1587,6 +1587,12 @@ static void netvsc_get_ethtool_stats(struct net_device *dev, pcpu_sum = kvmalloc_array(num_possible_cpus(), sizeof(struct netvsc_ethtool_pcpu_stats), GFP_KERNEL); + if (!pcpu_sum) { + for (j = 0; j < i; j++) + data[j] = 0; + return; + } + netvsc_get_pcpu_stats(dev, pcpu_sum); for_each_present_cpu(cpu) { struct netvsc_ethtool_pcpu_stats *this_sum = &pcpu_sum[cpu]; -- 2.25.1