From: Simon Horman <simon.horman@corigine.com>
To: Denis Arefev <arefev@swemel.ru>
Cc: Simon Horman <simon.horman@netronome.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
oss-drivers@netronome.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org,
trufanov@swemel.ru, vfh@swemel.ru
Subject: Re: [PATCH] lag_conf: Added pointer check
Date: Tue, 15 Nov 2022 10:22:32 +0100 [thread overview]
Message-ID: <Y3NaWM91RLUKFrLg@corigine.com> (raw)
In-Reply-To: <20221115085637.72193-1-arefev@swemel.ru>
On Tue, Nov 15, 2022 at 11:56:37AM +0300, Denis Arefev wrote:
> [You don't often get email from arefev@swemel.ru. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Return value of a function 'kmalloc_array' is dereferenced at lag_conf.c:347
> without checking for null, but it is usually checked for this function.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
Hi Denis,
thanks for highlighting this problem.
> ---
> drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> index 63907aeb3884..95ba6e92197d 100644
> --- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> +++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> @@ -276,7 +276,7 @@ static void nfp_fl_lag_do_work(struct work_struct *work)
>
> mutex_lock(&lag->lock);
> list_for_each_entry_safe(entry, storage, &lag->group_list, list) {
> - struct net_device *iter_netdev, **acti_netdevs;
> + struct net_device *iter_netdev, **acti_netdevs = NULL;
I don't think it's necessary to set acti_netdevs here as
it is always set before use by the call to kmalloc_array().
> struct nfp_flower_repr_priv *repr_priv;
> int active_count = 0, slaves = 0;
> struct nfp_repr *repr;
> @@ -308,6 +308,8 @@ static void nfp_fl_lag_do_work(struct work_struct *work)
>
> acti_netdevs = kmalloc_array(entry->slave_cnt,
> sizeof(*acti_netdevs), GFP_KERNEL);
> + if (!acti_netdevs)
> + break;
The indentation here doesn't look right.
Regarding the problem at hand, yes, I agree that it seems
that kmalloc_array() should be checked. But I am concerned that
simply break'ing here may lead to a bad state. And I'd like to ask
for some time to examine this more closely.
> /* Include sanity check in the loop. It may be that a bond has
> * changed between processing the last notification and the
> --
> 2.25.1
>
next prev parent reply other threads:[~2022-11-15 9:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 8:56 [PATCH] lag_conf: Added pointer check Denis Arefev
2022-11-15 9:22 ` Simon Horman [this message]
2022-11-16 1:55 ` [PATCH] lag_conf: Added pointer Yinjun Zhang
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=Y3NaWM91RLUKFrLg@corigine.com \
--to=simon.horman@corigine.com \
--cc=arefev@swemel.ru \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=ldv-project@linuxtesting.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
--cc=simon.horman@netronome.com \
--cc=trufanov@swemel.ru \
--cc=vfh@swemel.ru \
/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).