public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Duoming Zhou <duoming@zju.edu.cn>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH 4.9 05/14] net: rose: fix UAF bug caused by rose_t0timer_expiry
Date: Mon, 11 Jul 2022 11:06:24 +0200	[thread overview]
Message-ID: <20220711090535.680197363@linuxfoundation.org> (raw)
In-Reply-To: <20220711090535.517697227@linuxfoundation.org>

From: Duoming Zhou <duoming@zju.edu.cn>

commit 148ca04518070910739dfc4eeda765057856403d upstream.

There are UAF bugs caused by rose_t0timer_expiry(). The
root cause is that del_timer() could not stop the timer
handler that is running and there is no synchronization.
One of the race conditions is shown below:

    (thread 1)             |        (thread 2)
                           | rose_device_event
                           |   rose_rt_device_down
                           |     rose_remove_neigh
rose_t0timer_expiry        |       rose_stop_t0timer(rose_neigh)
  ...                      |         del_timer(&neigh->t0timer)
                           |         kfree(rose_neigh) //[1]FREE
  neigh->dce_mode //[2]USE |

The rose_neigh is deallocated in position [1] and use in
position [2].

The crash trace triggered by POC is like below:

BUG: KASAN: use-after-free in expire_timers+0x144/0x320
Write of size 8 at addr ffff888009b19658 by task swapper/0/0
...
Call Trace:
 <IRQ>
 dump_stack_lvl+0xbf/0xee
 print_address_description+0x7b/0x440
 print_report+0x101/0x230
 ? expire_timers+0x144/0x320
 kasan_report+0xed/0x120
 ? expire_timers+0x144/0x320
 expire_timers+0x144/0x320
 __run_timers+0x3ff/0x4d0
 run_timer_softirq+0x41/0x80
 __do_softirq+0x233/0x544
 ...

This patch changes rose_stop_ftimer() and rose_stop_t0timer()
in rose_remove_neigh() to del_timer_sync() in order that the
timer handler could be finished before the resources such as
rose_neigh and so on are deallocated. As a result, the UAF
bugs could be mitigated.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220705125610.77971-1-duoming@zju.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/rose/rose_route.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/net/rose/rose_route.c
+++ b/net/rose/rose_route.c
@@ -230,8 +230,8 @@ static void rose_remove_neigh(struct ros
 {
 	struct rose_neigh *s;
 
-	rose_stop_ftimer(rose_neigh);
-	rose_stop_t0timer(rose_neigh);
+	del_timer_sync(&rose_neigh->ftimer);
+	del_timer_sync(&rose_neigh->t0timer);
 
 	skb_queue_purge(&rose_neigh->queue);
 



  parent reply	other threads:[~2022-07-11  9:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11  9:06 [PATCH 4.9 00/14] 4.9.323-rc1 review Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 01/14] mm/slub: add missing TID updates on slab deactivation Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 02/14] can: grcan: grcan_probe(): remove extra of_node_get() Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 03/14] can: gs_usb: gs_usb_open/close(): fix memory leak Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 04/14] usbnet: fix memory leak in error case Greg Kroah-Hartman
2022-07-11  9:06 ` Greg Kroah-Hartman [this message]
2022-07-11  9:06 ` [PATCH 4.9 06/14] iommu/vt-d: Fix PCI bus rescan device hot add Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 07/14] video: of_display_timing.h: include errno.h Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 08/14] xfs: remove incorrect ASSERT in xfs_rename Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 09/14] pinctrl: sunxi: a83t: Fix NAND function name for some pins Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 10/14] i2c: cadence: Unregister the clk notifier in error path Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 11/14] ida: dont use BUG_ON() for debugging Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 12/14] dmaengine: at_xdma: handle errors of at_xdmac_alloc_desc() correctly Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 13/14] dmaengine: ti: Fix refcount leak in ti_dra7_xbar_route_allocate Greg Kroah-Hartman
2022-07-11  9:06 ` [PATCH 4.9 14/14] dmaengine: ti: Add missing put_device " Greg Kroah-Hartman
2022-07-11 11:08 ` [PATCH 4.9 00/14] 4.9.323-rc1 review Pavel Machek
2022-07-11 17:55 ` Florian Fainelli
2022-07-12  1:11 ` Guenter Roeck
2022-07-12  2:46 ` Shuah Khan
2022-07-12  8:59 ` Naresh Kamboju
2022-07-12  9:18 ` Jon Hunter

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=20220711090535.680197363@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=duoming@zju.edu.cn \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox