All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Stefan Wahren <wahrenst@gmx.net>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH net] net: vertexcom: mse102x: Fix possible double free of TX skb
Date: Tue, 29 Oct 2024 12:10:28 -0700	[thread overview]
Message-ID: <20241029121028.127f89b3@kernel.org> (raw)
In-Reply-To: <20241022155242.33729-1-wahrenst@gmx.net>

On Tue, 22 Oct 2024 17:52:42 +0200 Stefan Wahren wrote:
> -static int mse102x_tx_frame_spi(struct mse102x_net *mse, struct sk_buff *txp,
> +static int mse102x_tx_frame_spi(struct mse102x_net *mse, struct sk_buff **txp,
>  				unsigned int pad)
>  {
>  	struct mse102x_net_spi *mses = to_mse102x_spi(mse);
> @@ -226,29 +226,29 @@ static int mse102x_tx_frame_spi(struct mse102x_net *mse, struct sk_buff *txp,
>  	int ret;
> 
>  	netif_dbg(mse, tx_queued, mse->ndev, "%s: skb %p, %d@%p\n",
> -		  __func__, txp, txp->len, txp->data);
> +		  __func__, *txp, (*txp)->len, (*txp)->data);
> 
> -	if ((skb_headroom(txp) < DET_SOF_LEN) ||
> -	    (skb_tailroom(txp) < DET_DFT_LEN + pad)) {
> -		tskb = skb_copy_expand(txp, DET_SOF_LEN, DET_DFT_LEN + pad,
> +	if ((skb_headroom(*txp) < DET_SOF_LEN) ||
> +	    (skb_tailroom(*txp) < DET_DFT_LEN + pad)) {
> +		tskb = skb_copy_expand(*txp, DET_SOF_LEN, DET_DFT_LEN + pad,
>  				       GFP_KERNEL);
>  		if (!tskb)
>  			return -ENOMEM;
> 
> -		dev_kfree_skb(txp);
> -		txp = tskb;
> +		dev_kfree_skb(*txp);
> +		*txp = tskb;
>  	}
> 
> -	mse102x_push_header(txp);
> +	mse102x_push_header(*txp);
> 
>  	if (pad)
> -		skb_put_zero(txp, pad);
> +		skb_put_zero(*txp, pad);
> 
> -	mse102x_put_footer(txp);
> +	mse102x_put_footer(*txp);
> 
> -	xfer->tx_buf = txp->data;
> +	xfer->tx_buf = (*txp)->data;
>  	xfer->rx_buf = NULL;
> -	xfer->len = txp->len;
> +	xfer->len = (*txp)->len;
> 
>  	ret = spi_sync(mses->spidev, msg);
>  	if (ret < 0) {
> @@ -368,7 +368,7 @@ static void mse102x_rx_pkt_spi(struct mse102x_net *mse)
>  	mse->ndev->stats.rx_bytes += rxlen;

Isn't it easier to change this function to free the copy rather than
the original? That way the original will remain valid for the callers.

  parent reply	other threads:[~2024-10-29 19:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-22 15:52 [PATCH net] net: vertexcom: mse102x: Fix possible double free of TX skb Stefan Wahren
2024-10-24  9:49 ` Simon Horman
2024-10-29 19:10 ` Jakub Kicinski [this message]
2024-10-29 21:15   ` Stefan Wahren
2024-10-29 22:01     ` Jakub Kicinski
2024-10-29 23:06       ` Stefan Wahren
2024-10-30  0:36         ` Jakub Kicinski

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=20241029121028.127f89b3@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=dan.carpenter@linaro.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=wahrenst@gmx.net \
    /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.