stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev
@ 2022-04-12  6:39 Xu Jia
  2022-04-12  6:39 ` [PATCH 5.10 2/2] hamradio: remove needs_free_netdev to avoid UAF Xu Jia
  2022-04-12  7:12 ` [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: Xu Jia @ 2022-04-12  6:39 UTC (permalink / raw)
  To: stable, gregkh; +Cc: duoming, linma, davem, kuba

From: Lin Ma <linma@zju.edu.cn>

commit 0b9111922b1f399aba6ed1e1b8f2079c3da1aed8 upstream.

There is a possible race condition (use-after-free) like below

 (USE)                       |  (FREE)
  dev_queue_xmit             |
   __dev_queue_xmit          |
    __dev_xmit_skb           |
     sch_direct_xmit         | ...
      xmit_one               |
       netdev_start_xmit     | tty_ldisc_kill
        __netdev_start_xmit  |  6pack_close
         sp_xmit             |   kfree
          sp_encaps          |
                             |

According to the patch "defer ax25 kfree after unregister_netdev", this
patch reorder the kfree after the unregister_netdev to avoid the possible
UAF as the unregister_netdev() is well synchronized and won't return if
there is a running routine.

Signed-off-by: Lin Ma <linma@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Xu Jia <xujia39@huawei.com>
---
 drivers/net/hamradio/6pack.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 02d6f3a..82507a6 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -679,9 +679,11 @@ static void sixpack_close(struct tty_struct *tty)
 	del_timer_sync(&sp->tx_t);
 	del_timer_sync(&sp->resync_t);
 
-	/* Free all 6pack frame buffers. */
+	/* Free all 6pack frame buffers after unreg. */
 	kfree(sp->rbuff);
 	kfree(sp->xbuff);
+
+	free_netdev(sp->dev);
 }
 
 /* Perform I/O control on an active 6pack channel. */
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 5.10 2/2] hamradio: remove needs_free_netdev to avoid UAF
  2022-04-12  6:39 [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev Xu Jia
@ 2022-04-12  6:39 ` Xu Jia
  2022-04-12  7:12 ` [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: Xu Jia @ 2022-04-12  6:39 UTC (permalink / raw)
  To: stable, gregkh; +Cc: duoming, linma, davem, kuba

From: Lin Ma <linma@zju.edu.cn>

commit 81b1d548d00bcd028303c4f3150fa753b9b8aa71 upstream.

The former patch "defer 6pack kfree after unregister_netdev" reorders
the kfree of two buffer after the unregister_netdev to prevent the race
condition. It also adds free_netdev() function in sixpack_close(), which
is a direct copy from the similar code in mkiss_close().

However, in sixpack driver, the flag needs_free_netdev is set to true in
sp_setup(), hence the unregister_netdev() will free the netdev
automatically. Therefore, as the sp is netdev_priv, use-after-free
occurs.

This patch removes the needs_free_netdev = true and just let the
free_netdev to finish this deallocation task.

Fixes: 0b9111922b1f ("hamradio: defer 6pack kfree after unregister_netdev")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
Link: https://lore.kernel.org/r/20211111141402.7551-1-linma@zju.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Xu Jia <xujia39@huawei.com>
---
 drivers/net/hamradio/6pack.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 82507a6..83dc1c2 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -311,7 +311,6 @@ static void sp_setup(struct net_device *dev)
 {
 	/* Finish setting up the DEVICE info. */
 	dev->netdev_ops		= &sp_netdev_ops;
-	dev->needs_free_netdev	= true;
 	dev->mtu		= SIXP_MTU;
 	dev->hard_header_len	= AX25_MAX_HEADER_LEN;
 	dev->header_ops 	= &ax25_header_ops;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev
  2022-04-12  6:39 [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev Xu Jia
  2022-04-12  6:39 ` [PATCH 5.10 2/2] hamradio: remove needs_free_netdev to avoid UAF Xu Jia
@ 2022-04-12  7:12 ` Greg KH
  2022-04-12  8:50   ` xujia (Q)
  1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2022-04-12  7:12 UTC (permalink / raw)
  To: Xu Jia; +Cc: stable, duoming, linma, davem, kuba

On Tue, Apr 12, 2022 at 02:39:03PM +0800, Xu Jia wrote:
> From: Lin Ma <linma@zju.edu.cn>
> 
> commit 0b9111922b1f399aba6ed1e1b8f2079c3da1aed8 upstream.

Don't these two also need to go into 5.15.y?  You do not want someone
upgrading to a newer kernel and having a regression.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev
  2022-04-12  7:12 ` [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev Greg KH
@ 2022-04-12  8:50   ` xujia (Q)
  2022-04-12  9:54     ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: xujia (Q) @ 2022-04-12  8:50 UTC (permalink / raw)
  To: Greg KH; +Cc: stable, duoming, linma, davem, kuba

Yes, They also need in 5.15.y.

I ignore that.

Thank you, Greg!

在 2022/4/12 15:12, Greg KH 写道:
> On Tue, Apr 12, 2022 at 02:39:03PM +0800, Xu Jia wrote:
>> From: Lin Ma <linma@zju.edu.cn>
>>
>> commit 0b9111922b1f399aba6ed1e1b8f2079c3da1aed8 upstream.
> Don't these two also need to go into 5.15.y?  You do not want someone
> upgrading to a newer kernel and having a regression.
>
> thanks,
>
> greg k-h
> .

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev
  2022-04-12  8:50   ` xujia (Q)
@ 2022-04-12  9:54     ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2022-04-12  9:54 UTC (permalink / raw)
  To: xujia (Q); +Cc: stable, duoming, linma, davem, kuba

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Tue, Apr 12, 2022 at 04:50:23PM +0800, xujia (Q) wrote:
> Yes, They also need in 5.15.y.

Great, please provide backported patches for that series as well so that
we can then take these.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-12 11:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12  6:39 [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev Xu Jia
2022-04-12  6:39 ` [PATCH 5.10 2/2] hamradio: remove needs_free_netdev to avoid UAF Xu Jia
2022-04-12  7:12 ` [PATCH 5.10 1/2] hamradio: defer 6pack kfree after unregister_netdev Greg KH
2022-04-12  8:50   ` xujia (Q)
2022-04-12  9:54     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).