From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Zhang Shurong <zhang_shurong@foxmail.com>
Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] firewire: net: fix use after free in fwnet_finish_incoming_packet()
Date: Sat, 24 Jun 2023 14:06:24 +0900 [thread overview]
Message-ID: <20230624050624.GA231724@workstation.local> (raw)
In-Reply-To: <tencent_3B3D24B66ED66A6BB73CC0E63C6A14E45109@qq.com>
Hi,
Thanks for the fix.
On Fri, Jun 23, 2023 at 01:39:35PM +0800, Zhang Shurong wrote:
> The netif_rx() function frees the skb so we can't dereference it to
> save the skb->len.
>
> Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> ---
> drivers/firewire/net.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
> index 538bd677c254..7a4d1a478e33 100644
> --- a/drivers/firewire/net.c
> +++ b/drivers/firewire/net.c
> @@ -479,7 +479,7 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
> struct sk_buff *skb, u16 source_node_id,
> bool is_broadcast, u16 ether_type)
> {
> - int status;
> + int status, len;
>
> switch (ether_type) {
> case ETH_P_ARP:
> @@ -533,13 +533,15 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
> }
> skb->protocol = protocol;
> }
> +
> + len = skb->len;
> status = netif_rx(skb);
> if (status == NET_RX_DROP) {
> net->stats.rx_errors++;
> net->stats.rx_dropped++;
> } else {
> net->stats.rx_packets++;
> - net->stats.rx_bytes += skb->len;
> + net->stats.rx_bytes += len;
> }
>
> return 0;
I'm not good at network subsystem, but as long as reading network core,
I think it better not to access members of sk_buff structure after the
call of netif_rx() since the ownership is already delegated from
firewire-net to the network core to dispatch network protocol. The patch
looks good to me.
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
The most of code in firewire-net comes from old driver
(drivers/ieee1394/eth1394.c), thus the most of linux kernel which
supports ieee1394/firewire subsystem affects the issue, however the
potential issue has never appeared since the skb is released enough later
in the different context. I applied the patch to linux-next branch for
v6.5-rc1.
Thanks
Takashi Sakamoto
prev parent reply other threads:[~2023-06-24 5:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-23 5:39 [PATCH] firewire: net: fix use after free in fwnet_finish_incoming_packet() Zhang Shurong
2023-06-23 15:27 ` [cocci] " Markus Elfring
2023-06-24 5:06 ` Takashi Sakamoto [this message]
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=20230624050624.GA231724@workstation.local \
--to=o-takashi@sakamocchi.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
--cc=zhang_shurong@foxmail.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.