From: Stephen Hemminger <stephen@networkplumber.org>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: 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
Date: Fri, 11 Mar 2022 09:25:38 -0800 [thread overview]
Message-ID: <20220311092538.0cb478cf@hermes.local> (raw)
In-Reply-To: <20220311032035.2037962-1-jiasheng@iscas.ac.cn>
On Fri, 11 Mar 2022 11:20:35 +0800
Jiasheng Jiang <jiasheng@iscas.ac.cn> 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 <jiasheng@iscas.ac.cn>
> ---
> 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;
> + }
I don't think you understood what my comment was.
The zeroing here is not necessary. Just do:
if (!pcpu_sum)
return;
The data pointer is to buffer allocated here:
static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
{
...
if (n_stats) {
data = vzalloc(array_size(n_stats, sizeof(u64))); <<<<< is already zeroed.
if (!data)
return -ENOMEM;
ops->get_ethtool_stats(dev, &stats, data);
next prev parent reply other threads:[~2022-03-11 17:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 3:20 [PATCH] hv_netvsc: Add check for kvmalloc_array Jiasheng Jiang
2022-03-11 6:43 ` Greg KH
2022-03-11 17:25 ` Stephen Hemminger [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-03-14 8:35 Jiasheng Jiang
2022-03-14 17:12 ` Jakub Kicinski
2022-03-14 8:05 Jiasheng Jiang
2022-03-14 8:13 ` Greg KH
2022-03-14 7:33 Jiasheng Jiang
2022-03-14 7:38 ` Greg KH
2022-03-14 1:56 Jiasheng Jiang
2022-03-11 3:20 Jiasheng Jiang
2022-03-11 2:43 Jiasheng Jiang
2022-03-11 3:00 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220311092538.0cb478cf@hermes.local \
--to=stephen@networkplumber.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=hawk@kernel.org \
--cc=jiasheng@iscas.ac.cn \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=sthemmin@microsoft.com \
--cc=wei.liu@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).