From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
To: Daniil Tatianin <d-tatianin@yandex-team.ru>
Cc: Shahed Shaikh <shshaikh@marvell.com>,
Manish Chopra <manishc@marvell.com>,
GR-Linux-NIC-Dev@marvell.com,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] qlcnic: prevent ->dcb use-after-free on qlcnic_dcb_enable() failure
Date: Thu, 22 Dec 2022 10:57:32 +0100 [thread overview]
Message-ID: <Y6QqDLoqCXHG8KVl@localhost.localdomain> (raw)
In-Reply-To: <20221222074223.1746072-1-d-tatianin@yandex-team.ru>
On Thu, Dec 22, 2022 at 10:42:23AM +0300, Daniil Tatianin wrote:
> adapter->dcb would get silently freed inside qlcnic_dcb_enable() in
> case qlcnic_dcb_attach() would return an error, which always happens
> under OOM conditions. This would lead to use-after-free because both
> of the existing callers invoke qlcnic_dcb_get_info() on the obtained
> pointer, which is potentially freed at that point.
>
> Propagate errors from qlcnic_dcb_enable(), and instead free the dcb
> pointer at callsite using qlcnic_dcb_free(). This also removes the now
> unused qlcnic_clear_dcb_ops() helper, which was a simple wrapper around
> kfree() also causing memory leaks for partially initialized dcb.
>
> Found by Linux Verification Center (linuxtesting.org) with the SVACE
> static analysis tool.
>
> Fixes: 3c44bba1d270 ("qlcnic: Disable DCB operations from SR-IOV VFs")
> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> ---
> Changes since v1:
> - Add a fixes tag + net as a target
> - Remove qlcnic_clear_dcb_ops entirely & use qlcnic_dcb_free instead
> ---
> drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c | 9 ++++++++-
> drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h | 10 ++--------
> drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 9 ++++++++-
> 3 files changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
> index dbb800769cb6..774f2c6875ec 100644
> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
> @@ -2505,7 +2505,14 @@ int qlcnic_83xx_init(struct qlcnic_adapter *adapter)
> goto disable_mbx_intr;
>
> qlcnic_83xx_clear_function_resources(adapter);
> - qlcnic_dcb_enable(adapter->dcb);
> +
> + err = qlcnic_dcb_enable(adapter->dcb);
> + if (err) {
> + qlcnic_dcb_free(adapter->dcb);
> + adapter->dcb = NULL;
Small nit, I think qlcnic_dcb_free() already set adapter->dcb to NULL.
Otherwise, thanks for changing:
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Thanks,
Michal
[...]
> --
> 2.25.1
next prev parent reply other threads:[~2022-12-22 9:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 7:42 [PATCH net v2] qlcnic: prevent ->dcb use-after-free on qlcnic_dcb_enable() failure Daniil Tatianin
2022-12-22 9:57 ` Michal Swiatkowski [this message]
2022-12-22 11:46 ` Daniil Tatianin
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=Y6QqDLoqCXHG8KVl@localhost.localdomain \
--to=michal.swiatkowski@linux.intel.com \
--cc=GR-Linux-NIC-Dev@marvell.com \
--cc=d-tatianin@yandex-team.ru \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manishc@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shshaikh@marvell.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