Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp772350pxp; Fri, 11 Mar 2022 14:44:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2rDsihBwzjsR94BwphODbVdVXNPvYu/sI76t6+m39XuppD7nLEoVXr+uj9AYdwiY8Ns8g X-Received: by 2002:a63:4f43:0:b0:378:8ec6:7936 with SMTP id p3-20020a634f43000000b003788ec67936mr10082345pgl.329.1647038657063; Fri, 11 Mar 2022 14:44:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647038657; cv=none; d=google.com; s=arc-20160816; b=ai54PM0LpMXeCJjhXWWZHbd1T7HauBR6DIlIO+mVJC6MO4pjED0UcAezG9WYxXLM5j MQbf6Ah4aLpvM4MZ+VLp303h5eSsw6IXiANiQDOQ8w6TFhshG+/ahSFD6bm7mqEMs0WB R4K34VwLtOmd8y8pqb+nMbm/7kdcuRvbPQ2Dh+G8VhaodFse2BT7DfoD/71xm1IjyNqd Z1gm+5Qcb/pcLYQ7FvzBV2B88AIYxICHufY/Tt7LuCu2Ff42y1Scj4XnpYtVzTDy/AdN H4vjGdiW9bLt7TZwTkoWahj1mmMX3wAIqkQJ2MoQRDnoTcTqrstvx8Tp86FRuIhsz4u7 kwIQ== 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=ubvH5aNpCiKR+Z2FAzssPhkcG8G/fXSokOdBUI5XXZA=; b=Dnwao7pSN00zKXZXVEh+8jPE3xpUjUPiNMnQJNK+ySdb5Ak49s7uOVFZLJ9gFL4Nlw eyndG7jldccr89QZUeqdskpC6vXT9LV2FyjCQ93v/WN7jJRMvpUmHqPphajyMvGqbJhW 4fQTTR9pF06IN6dVXNbk3QfYIAJOkOvbc/R0PnKkBfjto5psq9ZdrqobzNMR+oihVbCI YJuiqJDo0eR5U+dbT8rJMp1ZbAxwwnewXaPJsNy6y7yKbeQvRgKAZ0edxT+iLDaPak9+ WMBC20E2EFkuMiQHtkd2ScxCsNVvjviuXZbPv6ELJejY0Txomddhg/cO1vjgfJZ3fbaT xR0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o+LTthpB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id p5-20020a637405000000b00362b90cd1e9si9018770pgc.738.2022.03.11.14.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:44:17 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o+LTthpB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 2B4B536F976; Fri, 11 Mar 2022 13:55:35 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346796AbiCKGo6 (ORCPT + 99 others); Fri, 11 Mar 2022 01:44:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232738AbiCKGo5 (ORCPT ); Fri, 11 Mar 2022 01:44:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87EE319CCCA; Thu, 10 Mar 2022 22:43:54 -0800 (PST) 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 3534FB8299A; Fri, 11 Mar 2022 06:43:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8722C340EC; Fri, 11 Mar 2022 06:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646981032; bh=TAmKSWfM8MT8+nWEF/VhEG/ZJrPdgq10gXaV9KWbhGY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o+LTthpBiwXFgN2AXoXR3dkBllQINaKMB1MVLJ9fNYGsc33egvUleMos9C/Ers5Xy 0aEsi7MyMo1LTO9pReh2ngHcWv3tBkSMJs7arcNj5FfwvhZHpBeAcF2ucLoONOjTwm lzB2WbNkenxYx1bvG4vVTVW8w6wx1VAlmaBnFX58= Date: Fri, 11 Mar 2022 07:43:48 +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: <20220311032035.2037962-1-jiasheng@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220311032035.2037962-1-jiasheng@iscas.ac.cn> X-Spam-Status: No, score=-2.4 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 Fri, Mar 11, 2022 at 11:20:35AM +0800, Jiasheng Jiang 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, greg k-h