Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2270113pxp; Mon, 21 Mar 2022 15:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1F1lYmHxfJgrRuHEbfSNav/6aL8naYvBOKG5tXiTD/Pqcn8FahTHNxu2hUh/FejQEoe5L X-Received: by 2002:a17:90b:4f8d:b0:1c6:408b:6b0d with SMTP id qe13-20020a17090b4f8d00b001c6408b6b0dmr1423473pjb.90.1647901725278; Mon, 21 Mar 2022 15:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647901725; cv=none; d=google.com; s=arc-20160816; b=DT/Ue2JZLRDQjSvU7VtTBCJ39uLbie3ESFhuzXu5T9+gou/oBoTYYadADojrQVx3/L 4Ul8deL4lOpsvel/8qlKoRovkuDRy6tSR5Ebibeymc4mZR1KnjZ4EDXOUYNlcJfv0X56 bg4RZCurlhmkPQfggQbXDjq9nlOxg82iyw93pD3XqoxWCjWCzPVA9rc4paf+5pcObWjB vfGAgHteLoB9SsGu1210/meZPRKdLeLm+p0V2Leniy61aHPY9keoz3+Si/9vd/TNeTuF EgeBs8ME0Z1GFEyEt5bxOqTBEXxcMqRdcWkx4AAeLaKyCk61c/wL4qruv/7/ThpuIsmH laGA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0tXm86CT8h3nwSL/IEil9g2P+dury9i0rfK44cs48hQ=; b=ZLh92wRrQojWo1idhTZdqoAK2oXh8bqEFhmifFjhS8Wr9AauXCxRnhPcK3aspWJ1Sy FmYv9JXCqkzIvKeg667Flahad/QASWzhSrZ+LAnNH8O3kERF8EjzfKq8erTz9leZP5tJ djKpsPKr9IYDlLyiiEixzVm3eUPTxoGAv7qzfROhgTYdV4y5LaaKu3K6ESby4rkXcbEm aHGcjNhPgztsBXLPCuUfYnFAKklseIgOwt6J3F0ubHbUgsWGbDXSZ0nW0oT8o6AjBfjI OzF77JpkIK5R6HyfuR2ZtWCc7l7K9X/NehPDS95Rgtfv6EKl9CyVa8YghiLIlnHfNj33 RXZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mkR6W28n; 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 m6-20020a17090a4d8600b001bd14e01fc0si480714pjh.174.2022.03.21.15.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:28:45 -0700 (PDT) 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=mkR6W28n; 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 8D33D2A12B8; Mon, 21 Mar 2022 14:43:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239567AbiCUOGE (ORCPT + 99 others); Mon, 21 Mar 2022 10:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349200AbiCUN7q (ORCPT ); Mon, 21 Mar 2022 09:59:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CE982529B; Mon, 21 Mar 2022 06:58:20 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2A8216126A; Mon, 21 Mar 2022 13:58:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35929C340E8; Mon, 21 Mar 2022 13:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647871099; bh=piknHTfz8IlmjbVBR/wSKw2KHljvoIVt9GWTNwsHhUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mkR6W28nRXiMS0PZ/Mh8GkGyfOz3MZjsKkMmAbcNFsRZZvvugadXjr9Lej85gN5qq Z0HEeDILBwlxB3jfUSgp3CaSBgGzloKJoPbpORB+vWXM8FUFeANtbvgxkgy4+UJJn0 PFZFcgNqai5ATwr/ZO92CGBPkXNdwd8W92RPXJdg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.4 07/17] hv_netvsc: Add check for kvmalloc_array Date: Mon, 21 Mar 2022 14:52:43 +0100 Message-Id: <20220321133217.369659883@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321133217.148831184@linuxfoundation.org> References: <20220321133217.148831184@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 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 From: Jiasheng Jiang [ Upstream commit 886e44c9298a6b428ae046e2fa092ca52e822e6a ] 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 Link: https://lore.kernel.org/r/20220314020125.2365084-1-jiasheng@iscas.ac.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/hyperv/netvsc_drv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 362b7ca6f3b2..57e92c5bfcc9 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1445,6 +1445,9 @@ 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) + return; + netvsc_get_pcpu_stats(dev, pcpu_sum); for_each_present_cpu(cpu) { struct netvsc_ethtool_pcpu_stats *this_sum = &pcpu_sum[cpu]; -- 2.34.1