Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3343609pxp; Mon, 14 Mar 2022 17:15:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyd4NKAFs7a3xhQqIkK4Vrvl/YjiAmaFTkBbNf9uaohyt3vz4ZNlxsQrCURsVgTlbnNlErB X-Received: by 2002:a05:6402:183:b0:410:fde:887a with SMTP id r3-20020a056402018300b004100fde887amr22698014edv.243.1647303300473; Mon, 14 Mar 2022 17:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647303300; cv=none; d=google.com; s=arc-20160816; b=B8VM1REP/77T+LWRzc363qU/+j9b5A8eGsoRkUVKNuRwULR9RVVr3zRGGWFNW9Q7xa zVJZxL0EP/93pUldsnfboheoG+sQ7p1R9Ru0m2I6hqZ61xiBQ5RirF8FoIzelDsE/S7L 1JphY5jDdGYN8oPWIu3rVDVlC0GR8MdjuU8KsRXz86Bf4Y3ILKO750vZHLMJhFSGoK2g gLUrwJsT/gbpWZqPf0rkjpHJGzZFJJPSSZ+RgF9fQJvZTSPl/7IzxWQNDvjDCexnUa1M eV36xzdCMDHQ1JKBDlYyMxFe4dMS0sQUWiHOrkrRXBDHARrrqx+GjPN4CGh1SD8dv78L gFVQ== 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=Cz78kmd/UfOr+AwSrw1xV8Ltz+QRXlsRzraepl+wzEU=; b=oUFqKqydkyN56TUBNepVpVjTkccK7XliZ4dQo4kP2XbGBMcDmsEfFi5MrBovaifeWb xLv4JqigPyHqoaAhK7v71J8fanXPecwOgLZhgygqWGkHVBqZsv08zBVM8pPUTPOEhft7 4hffL55ILbUrSlSRsJ9YyQzIjaui4g1rYgeGuZenxqSxQZQXYaS3fQMOpBowKw8aaEuu hcJHZ8QIPQWH7IF0PCeD7B0qb9PT31I5gsTe7ebiY6Z6vcNCvsb+LZd0ECt438oAUJLs 0EN9hww+YqScnw2mHEc/ZhI3GQ+uSanrxGR307DctNMx9qrjIs30SH8U5UISYIGLomYP /tyA== 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 j15-20020a170906430f00b006cf57ac5652si9668297ejm.210.2022.03.14.17.14.35; Mon, 14 Mar 2022 17:15:00 -0700 (PDT) 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 S233869AbiCNHfe (ORCPT + 99 others); Mon, 14 Mar 2022 03:35:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiCNHfc (ORCPT ); Mon, 14 Mar 2022 03:35:32 -0400 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 790B43983B; Mon, 14 Mar 2022 00:34:20 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-01 (Coremail) with SMTP id qwCowACn7sbp7y5iLc9wAw--.29115S2; Mon, 14 Mar 2022 15:34:02 +0800 (CST) From: Jiasheng Jiang To: gregkh@linuxfoundation.org Cc: stephen@networkplumber.org, 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: Re: [PATCH] hv_netvsc: Add check for kvmalloc_array Date: Mon, 14 Mar 2022 15:33:49 +0800 Message-Id: <20220314073349.2501022-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowACn7sbp7y5iLc9wAw--.29115S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKFWUGw43CFWUCr4rAFW5Jrb_yoWkWFg_CF 48urnxuw4UCryrKFW7JFyDZryrtwsFqr1SvFZFqrZ3J34ktrWUXr1rAr1xJr93ur4rurnx CwnrtFWFv3sF9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbxAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_ Gr1UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_Wryl IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_ Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0J UQvtAUUUUU= X-Originating-IP: [124.16.138.126] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 On Fri, Mar 11, 2022 at 02:43:48PM +0800, Greg KH wrote: >> 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; >> + } > >How did you test this to verify it is correct? Thanks, I have tested the patch by kernel_patch_verify, and all the tests are passed. Jiang