Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp290182pxp; Fri, 11 Mar 2022 04:32:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDu/lXEXauMB8sbmJc8wueBbcEtiaRqhB0+HCXRyuEC8FnTTBLd/wMrNMItHCLBOFx8qvH X-Received: by 2002:a17:906:9741:b0:6da:c274:6b18 with SMTP id o1-20020a170906974100b006dac2746b18mr8213854ejy.207.1647001959680; Fri, 11 Mar 2022 04:32:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647001959; cv=none; d=google.com; s=arc-20160816; b=ucKe0BDlre+ZCTl8QsHAJe7LYtIg6rBet2TcZFBLBbqSgiEg2rviTpxs9C624pjh5Q 0PEHrEmlOMtEuQDmWGrmO/PObEZgwezFVPDUCPU2mjgUJmbQX4E5BEuZLQ4LGsqRB2vf wIJiJwk98MajExpvdapbEt+7bV9O2Q6XzTwkmbjg3Fcwi7hdnFusO54BdyreiMJZj0H9 us2NO2FN7B6K6ioCsR+2AQI4ux2jT2BXrsrzYmzcQWgJkXbUL7EOSuoDHsf7P1jOqgeX 5ioOIExamgez8DJXD+HKl3jCiRyMJFZt19C/eHOFXZldyY/RQ8ynVywknoYJW42LvAPr GG9w== 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=qWcvznqbB5c2Dib2E/VPr1TmAVwSHDaB+NDYJPXOtRSCRQ3Z5UN48aKHDAVw2T41Y5 A1CHKtCELWfOiB5NznedQtQculacJ1Uwg+unzLQyuz3G/REiQkh6L3xgjWbdLwRH3/xl 1cy5WfZfXxZ5Jr6PCIXRZtXNQiOS3+BWPplwUF7KBfrkcgzFpPrWemi8bzkn8HLF/4Yh cU5bdwubLukRQoECnX6bY3j50FTnD7VHFzsr+Pc+6az7+K2NI6V+G6ub2dhdLOSj4fOz HeLBXBopT929+VwggzcWdJf3s3WmgGz0eWt+eIcL2vdV3BapSab3QU8G8WyTjU6cbCbo 1uLg== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cq1-20020a056402220100b0041330bfd964si5020063edb.494.2022.03.11.04.31.58; Fri, 11 Mar 2022 04:32:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345732AbiCKCpQ (ORCPT + 99 others); Thu, 10 Mar 2022 21:45:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345718AbiCKCpN (ORCPT ); Thu, 10 Mar 2022 21:45:13 -0500 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB9151A41C8; Thu, 10 Mar 2022 18:44:09 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-05 (Coremail) with SMTP id zQCowAD3_dlitypih4nkAg--.38403S2; Fri, 11 Mar 2022 10:43:47 +0800 (CST) From: Jiasheng Jiang To: 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 Cc: 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 10:43:44 +0800 Message-Id: <20220311024344.2037906-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowAD3_dlitypih4nkAg--.38403S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKFW3Jw4xCrW3Wr15tr1fJFb_yoWDCrX_ur 48urnxZr4UCryrKF47tFy7Zr9Yyw4vqF1fZFW2qrZ3JFy8ArW7W3WrZrnrXrWfur4Y9F9x C3ZrAF4Yv39FgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbxAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVWxJr 0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5 MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v2 6r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0J UQvtAUUUUU= X-Originating-IP: [124.16.138.126] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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