Re: [PATCH] net/qlcnic: fix possible use-after-free bugs in qlcnic_alloc_rx_skb()

From: Simon Horman
Date: Fri Sep 15 2023 - 01:45:50 EST


On Wed, Sep 13, 2023 at 06:41:19PM +0800, Ma Ke wrote:
> In qlcnic_alloc_rx_skb(), when dma_map_single() fails, skb is freed
> immediately. And skb could be freed again. This issue could allow a
> local attacker to crash the system due to a use-after-free flaw.
>
> Signed-off-by: Ma Ke <make_ruc2021@xxxxxxx>
> ---
> drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
> index 41894d154013..6501aaf2b5ce 100644
> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
> @@ -832,6 +832,7 @@ static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
> if (dma_mapping_error(&pdev->dev, dma)) {
> adapter->stats.rx_dma_map_error++;
> dev_kfree_skb_any(skb);
> + skb = NULL;
> return -ENOMEM;

Hi Ma Ke,

I am a unclear on how skb could be freed a second time.
skb is a local variable which goes out of scope when
the function returns.