Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp908133pxp; Wed, 16 Mar 2022 20:55:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7sqlRCMAcs275tKjSIu9nNgZLNf10C9weYG1glv9/FPOYuL4HLS0GmyURd1rLKcNZTiun X-Received: by 2002:a17:90a:66c3:b0:1bc:cfab:86ec with SMTP id z3-20020a17090a66c300b001bccfab86ecmr13782200pjl.74.1647489341114; Wed, 16 Mar 2022 20:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647489341; cv=none; d=google.com; s=arc-20160816; b=sdp1LJmXw/TSjG5fb3w3W5Ef77p6vDspQpYtXcFxK4wIbykeINKHpCbYk1G9gNGUWM wCSpazdn8cKECesar63C5Xz1MNk2BS0D9VMyTvM6LY3Mf0Ya5K/MSZOmsVWt1qO/7Iur n5AJYMUYTVD4NhWlup3zFURdWPS1HEIES9OjaSqao3DY5p+1EhzGMnqh7G0+jIlawjWA FiMWQsRlW4BjAI23Zit9GrST/6mDEaoSVLGWw7nPhNNNKmAyxeF5fkywcR3K5znE3f0o qx8oOEh0yldr5opDjBszdK0VMAhEJCQC6hUEDxXRJMqGlmD16JH7V6oSUE/GeG7CIzM8 W9MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PF7sphyv3Hk9jdz9n7RUxlyvC5uc3ALQOeDRLHix5jc=; b=cj1/lVjR2spV6c4Y0/iXdP3YkJ4altMte3Di2GC7RbwQP+WWlxNp4nElRkIQIPuCsO kSFJ0D9zWnKuR0Eo7baG9+OIuTvkCQ7Zkb0wmIXOJvEvMcQ30JGeKQX1DH8WtuTl+tRb KrLT3y2YcBdNYH/WKYao13QPw4l/z39fW5GzI8sX3elTzDC5ZcBEaxBFG0jECToyj9oB qH5auzrl7av8Zur4wpF/96LZrH3NPVGicf2oMS0WxriMKDfQDYES7QaR4wW9ih8+VpR0 vuOicmGCu+sBIGFq/9ih1651LnLjrsMaO9+UwTC9xKC7/eGT1X8VLtNOoA0bRlzqiq1o jjHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JGaBr7QE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t30-20020a63445e000000b003816043efa8si912854pgk.413.2022.03.16.20.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:55:41 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JGaBr7QE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D54DA86E0C; Wed, 16 Mar 2022 20:42:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236736AbiCNHkI (ORCPT + 99 others); Mon, 14 Mar 2022 03:40:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232596AbiCNHkH (ORCPT ); Mon, 14 Mar 2022 03:40:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1E1A15A0C; Mon, 14 Mar 2022 00:38:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 59FE3B80D09; Mon, 14 Mar 2022 07:38:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4479BC340F5; Mon, 14 Mar 2022 07:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647243535; bh=kswDHq1yjjDaHfiDPIN10j7tWCwGwvkRsCL4lzFzP4Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JGaBr7QE1wFWt0IqT20RFxIpjPJgq5Zrv4BqB4Zu0n0Ao7CVpuMuvV6vuHpQZgE5g icqC9KxYX6eTBkOsa/PSBKIs9fTDrKrXq/1sJYKRyv6i6pd4VsXV80aSJAHGzOHSsP lEiQYjFzT4q5tTpiHIcfjGrKe7B2LdBF1FJGe7x4= Date: Mon, 14 Mar 2022 08:38:49 +0100 From: Greg KH To: Jiasheng Jiang 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 Subject: Re: [PATCH] hv_netvsc: Add check for kvmalloc_array Message-ID: References: <20220314073349.2501022-1-jiasheng@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220314073349.2501022-1-jiasheng@iscas.ac.cn> X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Mon, Mar 14, 2022 at 03:33:49PM +0800, Jiasheng Jiang wrote: > 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, What is that? > and all the tests are passed. What tests exactly? How did you fail this allocation? thanks, greg k-h