All of lore.kernel.org
 help / color / mirror / Atom feed
From: isdn@linux-pingi.de
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net] mISDN: hfcpci: Fix a use after free in hfcmulti_tx()
Date: Thu, 22 Oct 2020 16:24:00 +0200	[thread overview]
Message-ID: <0ee243a9-9937-ad26-0684-44b18e772662@linux-pingi.de> (raw)
In-Reply-To: <20201022070739.GB2817762@mwanda>

Hi Dan,

that looks wrong to me and never was a use after free.

sp is set either to the address containing the pointer to the actual
D-channel SKB or to the actual B-channel SKB. This address is not freed
and will not change in this context. The dev_kfree(*sp) will delete the
old SKB and the call to  get_next_[bd]frame(), if returning true, will
place a new SKB into this address, so (*sp) point to this new SKB.
The len of course need to be the length of the new SKB, not the old one,
which would be the result of this patch.

Best regards
Karsten

On 10/22/20 9:07 AM, Dan Carpenter wrote:
> This frees "*sp" before dereferencing it to get "len = (*sp)->len;".
> 
> Fixes: af69fb3a8ffa ("Add mISDN HFC multiport driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/isdn/hardware/mISDN/hfcmulti.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/isdn/hardware/mISDN/hfcmulti.c b/drivers/isdn/hardware/mISDN/hfcmulti.c
> index 7013a3f08429..ce6c160e0df4 100644
> --- a/drivers/isdn/hardware/mISDN/hfcmulti.c
> +++ b/drivers/isdn/hardware/mISDN/hfcmulti.c
> @@ -2152,16 +2152,14 @@ hfcmulti_tx(struct hfc_multi *hc, int ch)
>  		HFC_wait_nodebug(hc);
>  	}
>  
> +	len = (*sp)->len;
>  	dev_kfree_skb(*sp);
>  	/* check for next frame */
> -	if (bch && get_next_bframe(bch)) {
> -		len = (*sp)->len;
> +	if (bch && get_next_bframe(bch))
>  		goto next_frame;
> -	}
> -	if (dch && get_next_dframe(dch)) {
> -		len = (*sp)->len;
> +
> +	if (dch && get_next_dframe(dch))
>  		goto next_frame;
> -	}
>  
>  	/*
>  	 * now we have no more data, so in case of transparent,
> 


WARNING: multiple messages have this Message-ID (diff)
From: isdn@linux-pingi.de
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net] mISDN: hfcpci: Fix a use after free in hfcmulti_tx()
Date: Thu, 22 Oct 2020 14:24:00 +0000	[thread overview]
Message-ID: <0ee243a9-9937-ad26-0684-44b18e772662@linux-pingi.de> (raw)
In-Reply-To: <20201022070739.GB2817762@mwanda>

Hi Dan,

that looks wrong to me and never was a use after free.

sp is set either to the address containing the pointer to the actual
D-channel SKB or to the actual B-channel SKB. This address is not freed
and will not change in this context. The dev_kfree(*sp) will delete the
old SKB and the call to  get_next_[bd]frame(), if returning true, will
place a new SKB into this address, so (*sp) point to this new SKB.
The len of course need to be the length of the new SKB, not the old one,
which would be the result of this patch.

Best regards
Karsten

On 10/22/20 9:07 AM, Dan Carpenter wrote:
> This frees "*sp" before dereferencing it to get "len = (*sp)->len;".
> 
> Fixes: af69fb3a8ffa ("Add mISDN HFC multiport driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/isdn/hardware/mISDN/hfcmulti.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/isdn/hardware/mISDN/hfcmulti.c b/drivers/isdn/hardware/mISDN/hfcmulti.c
> index 7013a3f08429..ce6c160e0df4 100644
> --- a/drivers/isdn/hardware/mISDN/hfcmulti.c
> +++ b/drivers/isdn/hardware/mISDN/hfcmulti.c
> @@ -2152,16 +2152,14 @@ hfcmulti_tx(struct hfc_multi *hc, int ch)
>  		HFC_wait_nodebug(hc);
>  	}
>  
> +	len = (*sp)->len;
>  	dev_kfree_skb(*sp);
>  	/* check for next frame */
> -	if (bch && get_next_bframe(bch)) {
> -		len = (*sp)->len;
> +	if (bch && get_next_bframe(bch))
>  		goto next_frame;
> -	}
> -	if (dch && get_next_dframe(dch)) {
> -		len = (*sp)->len;
> +
> +	if (dch && get_next_dframe(dch))
>  		goto next_frame;
> -	}
>  
>  	/*
>  	 * now we have no more data, so in case of transparent,
> 

  reply	other threads:[~2020-10-22 14:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22  7:07 [PATCH net] mISDN: hfcpci: Fix a use after free in hfcmulti_tx() Dan Carpenter
2020-10-22  7:07 ` Dan Carpenter
2020-10-22 14:24 ` isdn [this message]
2020-10-22 14:24   ` isdn
2020-10-22 14:44   ` Dan Carpenter
2020-10-22 14:44     ` Dan Carpenter

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=0ee243a9-9937-ad26-0684-44b18e772662@linux-pingi.de \
    --to=isdn@linux-pingi.de \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=wangkefeng.wang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.