linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [syzbot] KASAN: use-after-free Read in tipc_recvmsg
@ 2021-07-18 17:15 syzbot
  2021-07-23 16:36 ` Pavel Skripkin
  0 siblings, 1 reply; 7+ messages in thread
From: syzbot @ 2021-07-18 17:15 UTC (permalink / raw)
  To: davem, devicetree, frowand.list, gregkh, jmaloy, kuba,
	linux-kernel, netdev, rafael, robh+dt, robh, syzkaller-bugs,
	tipc-discussion, ying.xue

Hello,

syzbot found the following issue on:

HEAD commit:    ab0441b4a920 Merge branch 'vmxnet3-version-6'
git tree:       net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=1744ac6a300000
kernel config:  https://syzkaller.appspot.com/x/.config?x=da140227e4f25b17
dashboard link: https://syzkaller.appspot.com/bug?extid=e6741b97d5552f97c24d
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=13973a74300000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17ffc902300000

The issue was bisected to:

commit 67a3156453859ceb40dc4448b7a6a99ea0ad27c7
Author: Rob Herring <robh@kernel.org>
Date:   Thu May 27 19:45:47 2021 +0000

    of: Merge of_address_to_resource() and of_pci_address_to_resource() implementations

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=129b0438300000
final oops:     https://syzkaller.appspot.com/x/report.txt?x=119b0438300000
console output: https://syzkaller.appspot.com/x/log.txt?x=169b0438300000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com
Fixes: 67a315645385 ("of: Merge of_address_to_resource() and of_pci_address_to_resource() implementations")

==================================================================
BUG: KASAN: use-after-free in tipc_recvmsg+0xf77/0xf90 net/tipc/socket.c:1979
Read of size 4 at addr ffff8880328cf1c0 by task kworker/u4:0/8

CPU: 1 PID: 8 Comm: kworker/u4:0 Not tainted 5.14.0-rc1-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: tipc_rcv tipc_conn_recv_work
Call Trace:
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:105
 print_address_description.constprop.0.cold+0x6c/0x309 mm/kasan/report.c:233
 __kasan_report mm/kasan/report.c:419 [inline]
 kasan_report.cold+0x83/0xdf mm/kasan/report.c:436
 tipc_recvmsg+0xf77/0xf90 net/tipc/socket.c:1979
 sock_recvmsg_nosec net/socket.c:943 [inline]
 sock_recvmsg net/socket.c:961 [inline]
 sock_recvmsg+0xca/0x110 net/socket.c:957
 tipc_conn_rcv_from_sock+0x162/0x2f0 net/tipc/topsrv.c:398
 tipc_conn_recv_work+0xeb/0x190 net/tipc/topsrv.c:421
 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
 worker_thread+0x658/0x11f0 kernel/workqueue.c:2422
 kthread+0x3e5/0x4d0 kernel/kthread.c:319
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Allocated by task 8446:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:434 [inline]
 __kasan_slab_alloc+0x84/0xa0 mm/kasan/common.c:467
 kasan_slab_alloc include/linux/kasan.h:253 [inline]
 slab_post_alloc_hook mm/slab.h:512 [inline]
 slab_alloc_node mm/slub.c:2981 [inline]
 kmem_cache_alloc_node+0x266/0x3e0 mm/slub.c:3017
 __alloc_skb+0x20b/0x340 net/core/skbuff.c:414
 alloc_skb_fclone include/linux/skbuff.h:1162 [inline]
 tipc_buf_acquire+0x25/0xe0 net/tipc/msg.c:72
 tipc_msg_build+0xf7/0x10a0 net/tipc/msg.c:386
 __tipc_sendstream+0x6d0/0x1150 net/tipc/socket.c:1610
 tipc_sendstream+0x4c/0x70 net/tipc/socket.c:1541
 sock_sendmsg_nosec net/socket.c:703 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:723
 sock_write_iter+0x289/0x3c0 net/socket.c:1056
 call_write_iter include/linux/fs.h:2114 [inline]
 new_sync_write+0x426/0x650 fs/read_write.c:518
 vfs_write+0x75a/0xa40 fs/read_write.c:605
 ksys_write+0x1ee/0x250 fs/read_write.c:658
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Freed by task 8:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:360
 ____kasan_slab_free mm/kasan/common.c:366 [inline]
 ____kasan_slab_free mm/kasan/common.c:328 [inline]
 __kasan_slab_free+0xfb/0x130 mm/kasan/common.c:374
 kasan_slab_free include/linux/kasan.h:229 [inline]
 slab_free_hook mm/slub.c:1650 [inline]
 slab_free_freelist_hook+0xdf/0x240 mm/slub.c:1675
 slab_free mm/slub.c:3235 [inline]
 kmem_cache_free+0x8e/0x5a0 mm/slub.c:3251
 kfree_skbmem+0x166/0x1b0 net/core/skbuff.c:709
 __kfree_skb net/core/skbuff.c:745 [inline]
 kfree_skb net/core/skbuff.c:762 [inline]
 kfree_skb+0x140/0x3f0 net/core/skbuff.c:756
 tipc_recvmsg+0x70d/0xf90 net/tipc/socket.c:1977
 sock_recvmsg_nosec net/socket.c:943 [inline]
 sock_recvmsg net/socket.c:961 [inline]
 sock_recvmsg+0xca/0x110 net/socket.c:957
 tipc_conn_rcv_from_sock+0x162/0x2f0 net/tipc/topsrv.c:398
 tipc_conn_recv_work+0xeb/0x190 net/tipc/topsrv.c:421
 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
 worker_thread+0x658/0x11f0 kernel/workqueue.c:2422
 kthread+0x3e5/0x4d0 kernel/kthread.c:319
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

The buggy address belongs to the object at ffff8880328cf180
 which belongs to the cache skbuff_fclone_cache of size 472
The buggy address is located 64 bytes inside of
 472-byte region [ffff8880328cf180, ffff8880328cf358)
The buggy address belongs to the page:
page:ffffea0000ca3380 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x328ce
head:ffffea0000ca3380 order:1 compound_mapcount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffffea0000811500 0000000300000003 ffff8881400ee280
raw: 0000000000000000 00000000800c000c 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 8424, ts 65082628156, free_ts 64879784131
 prep_new_page mm/page_alloc.c:2433 [inline]
 get_page_from_freelist+0xa72/0x2f80 mm/page_alloc.c:4166
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5374
 alloc_pages+0x18c/0x2a0 mm/mempolicy.c:2244
 alloc_slab_page mm/slub.c:1713 [inline]
 allocate_slab+0x32b/0x4c0 mm/slub.c:1853
 new_slab mm/slub.c:1916 [inline]
 new_slab_objects mm/slub.c:2662 [inline]
 ___slab_alloc+0x4ba/0x820 mm/slub.c:2825
 __slab_alloc.constprop.0+0xa7/0xf0 mm/slub.c:2865
 slab_alloc_node mm/slub.c:2947 [inline]
 kmem_cache_alloc_node+0x12c/0x3e0 mm/slub.c:3017
 __alloc_skb+0x20b/0x340 net/core/skbuff.c:414
 alloc_skb_fclone include/linux/skbuff.h:1162 [inline]
 sk_stream_alloc_skb+0x109/0xc30 net/ipv4/tcp.c:887
 tcp_sendmsg_locked+0xc78/0x2f10 net/ipv4/tcp.c:1309
 tcp_sendmsg+0x2b/0x40 net/ipv4/tcp.c:1461
 inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:821
 sock_sendmsg_nosec net/socket.c:703 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:723
 sock_write_iter+0x289/0x3c0 net/socket.c:1056
 call_write_iter include/linux/fs.h:2114 [inline]
 new_sync_write+0x426/0x650 fs/read_write.c:518
 vfs_write+0x75a/0xa40 fs/read_write.c:605
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1343 [inline]
 free_pcp_prepare+0x2c5/0x780 mm/page_alloc.c:1394
 free_unref_page_prepare mm/page_alloc.c:3329 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3408
 unfreeze_partials+0x17c/0x1d0 mm/slub.c:2443
 put_cpu_partial+0x13d/0x230 mm/slub.c:2479
 qlink_free mm/kasan/quarantine.c:146 [inline]
 qlist_free_all+0x5a/0xc0 mm/kasan/quarantine.c:165
 kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:272
 __kasan_slab_alloc+0x8e/0xa0 mm/kasan/common.c:444
 kasan_slab_alloc include/linux/kasan.h:253 [inline]
 slab_post_alloc_hook mm/slab.h:512 [inline]
 slab_alloc_node mm/slub.c:2981 [inline]
 slab_alloc mm/slub.c:2989 [inline]
 kmem_cache_alloc+0x216/0x3a0 mm/slub.c:2994
 getname_flags.part.0+0x50/0x4f0 fs/namei.c:138
 getname_flags fs/namei.c:2747 [inline]
 user_path_at_empty+0xa1/0x100 fs/namei.c:2747
 user_path_at include/linux/namei.h:57 [inline]
 vfs_statx+0x142/0x390 fs/stat.c:203
 vfs_fstatat fs/stat.c:225 [inline]
 vfs_lstat include/linux/fs.h:3386 [inline]
 __do_sys_newlstat+0x91/0x110 fs/stat.c:380
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Memory state around the buggy address:
 ffff8880328cf080: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
 ffff8880328cf100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880328cf180: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                           ^
 ffff8880328cf200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880328cf280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

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

* Re: [syzbot] KASAN: use-after-free Read in tipc_recvmsg
  2021-07-18 17:15 [syzbot] KASAN: use-after-free Read in tipc_recvmsg syzbot
@ 2021-07-23 16:36 ` Pavel Skripkin
  2021-07-23 16:41   ` Xin Long
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pavel Skripkin @ 2021-07-23 16:36 UTC (permalink / raw)
  To: syzbot
  Cc: davem, devicetree, frowand.list, gregkh, jmaloy, kuba,
	linux-kernel, netdev, rafael, robh+dt, robh, syzkaller-bugs,
	tipc-discussion, ying.xue

[-- Attachment #1: Type: text/plain, Size: 1885 bytes --]

On Sun, 18 Jul 2021 10:15:19 -0700
syzbot <syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com> wrote:

> Hello,
> 
> syzbot found the following issue on:
> 
> HEAD commit:    ab0441b4a920 Merge branch 'vmxnet3-version-6'
> git tree:       net-next
> console output:
> https://syzkaller.appspot.com/x/log.txt?x=1744ac6a300000 kernel
> config:  https://syzkaller.appspot.com/x/.config?x=da140227e4f25b17
> dashboard link:
> https://syzkaller.appspot.com/bug?extid=e6741b97d5552f97c24d syz
> repro:
> https://syzkaller.appspot.com/x/repro.syz?x=13973a74300000 C
> reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17ffc902300000
> 
> The issue was bisected to:
> 
> commit 67a3156453859ceb40dc4448b7a6a99ea0ad27c7
> Author: Rob Herring <robh@kernel.org>
> Date:   Thu May 27 19:45:47 2021 +0000
> 
>     of: Merge of_address_to_resource() and
> of_pci_address_to_resource() implementations
> 
> bisection log:
> https://syzkaller.appspot.com/x/bisect.txt?x=129b0438300000 final
> oops:     https://syzkaller.appspot.com/x/report.txt?x=119b0438300000
> console output:
> https://syzkaller.appspot.com/x/log.txt?x=169b0438300000
> 
> IMPORTANT: if you fix the issue, please add the following tag to the
> commit: Reported-by:
> syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com Fixes:
> 67a315645385 ("of: Merge of_address_to_resource() and
> of_pci_address_to_resource() implementations")
> 
> ==================================================================
> BUG: KASAN: use-after-free in tipc_recvmsg+0xf77/0xf90
> net/tipc/socket.c:1979 Read of size 4 at addr ffff8880328cf1c0 by
> task kworker/u4:0/8
> 

Since code accesing skb_cb after possible kfree_skb() call let's just
store bytes_read to variable and use it instead of acessing
skb_cb->bytes_read

#syz test
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master



With regards,
Pavel Skripkin

[-- Attachment #2: 0001-tipc-fix-use-after-free-in-tipc_recvmsg.patch --]
[-- Type: text/x-patch, Size: 1230 bytes --]

From 9f81f8574bfc1183209022b405848e01c35b86e6 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin <paskripkin@gmail.com>
Date: Fri, 23 Jul 2021 19:34:06 +0300
Subject: [PATCH] tipc: fix use-after-free in tipc_recvmsg

/* .. */

Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 net/tipc/socket.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 9b0b311c7ec1..0cf2468d209d 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1886,6 +1886,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
 	struct sk_buff *skb;
 	bool grp_evt;
 	long timeout;
+	unsigned int bytes_read;
 
 	/* Catch invalid receive requests */
 	if (unlikely(!buflen))
@@ -1973,10 +1974,13 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
 		tipc_node_distr_xmit(sock_net(sk), &xmitq);
 	}
 
-	if (!skb_cb->bytes_read)
+	/* To avoid accesing skb_cb after tsk_advance_rx_queue */
+	bytes_read = skb_cb->bytes_read;
+
+	if (!bytes_read)
 		tsk_advance_rx_queue(sk);
 
-	if (likely(!connected) || skb_cb->bytes_read)
+	if (likely(!connected) || bytes_read)
 		goto exit;
 
 	/* Send connection flow control advertisement when applicable */
-- 
2.32.0


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

* Re: [syzbot] KASAN: use-after-free Read in tipc_recvmsg
  2021-07-23 16:36 ` Pavel Skripkin
@ 2021-07-23 16:41   ` Xin Long
  2021-07-23 16:52     ` Pavel Skripkin
  2021-07-23 16:49   ` Pavel Skripkin
  2021-07-23 22:51   ` syzbot
  2 siblings, 1 reply; 7+ messages in thread
From: Xin Long @ 2021-07-23 16:41 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: syzbot, davem, devicetree, frowand.list, Greg Kroah-Hartman,
	Jon Maloy, Jakub Kicinski, LKML, network dev, rafael, robh+dt,
	robh, syzkaller-bugs, tipc-discussion, Ying Xue

a fix already posted in tipc-discussion:

diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 9b0b311c7ec1..b0dd183a4dbc 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1973,10 +1973,12 @@ static int tipc_recvmsg(struct socket *sock,
struct msghdr *m,
                tipc_node_distr_xmit(sock_net(sk), &xmitq);
        }

-       if (!skb_cb->bytes_read)
-               tsk_advance_rx_queue(sk);
+       if (skb_cb->bytes_read)
+               goto exit;
+
+       tsk_advance_rx_queue(sk);

-       if (likely(!connected) || skb_cb->bytes_read)
+       if (likely(!connected))
                goto exit;

On Fri, Jul 23, 2021 at 12:38 PM Pavel Skripkin <paskripkin@gmail.com> wrote:
>
> On Sun, 18 Jul 2021 10:15:19 -0700
> syzbot <syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com> wrote:
>
> > Hello,
> >
> > syzbot found the following issue on:
> >
> > HEAD commit:    ab0441b4a920 Merge branch 'vmxnet3-version-6'
> > git tree:       net-next
> > console output:
> > https://syzkaller.appspot.com/x/log.txt?x=1744ac6a300000 kernel
> > config:  https://syzkaller.appspot.com/x/.config?x=da140227e4f25b17
> > dashboard link:
> > https://syzkaller.appspot.com/bug?extid=e6741b97d5552f97c24d syz
> > repro:
> > https://syzkaller.appspot.com/x/repro.syz?x=13973a74300000 C
> > reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17ffc902300000
> >
> > The issue was bisected to:
> >
> > commit 67a3156453859ceb40dc4448b7a6a99ea0ad27c7
> > Author: Rob Herring <robh@kernel.org>
> > Date:   Thu May 27 19:45:47 2021 +0000
> >
> >     of: Merge of_address_to_resource() and
> > of_pci_address_to_resource() implementations
> >
> > bisection log:
> > https://syzkaller.appspot.com/x/bisect.txt?x=129b0438300000 final
> > oops:     https://syzkaller.appspot.com/x/report.txt?x=119b0438300000
> > console output:
> > https://syzkaller.appspot.com/x/log.txt?x=169b0438300000
> >
> > IMPORTANT: if you fix the issue, please add the following tag to the
> > commit: Reported-by:
> > syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com Fixes:
> > 67a315645385 ("of: Merge of_address_to_resource() and
> > of_pci_address_to_resource() implementations")
> >
> > ==================================================================
> > BUG: KASAN: use-after-free in tipc_recvmsg+0xf77/0xf90
> > net/tipc/socket.c:1979 Read of size 4 at addr ffff8880328cf1c0 by
> > task kworker/u4:0/8
> >
>
> Since code accesing skb_cb after possible kfree_skb() call let's just
> store bytes_read to variable and use it instead of acessing
> skb_cb->bytes_read
>
> #syz test
> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>
>
>
> With regards,
> Pavel Skripkin

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

* Re: [syzbot] KASAN: use-after-free Read in tipc_recvmsg
  2021-07-23 16:36 ` Pavel Skripkin
  2021-07-23 16:41   ` Xin Long
@ 2021-07-23 16:49   ` Pavel Skripkin
  2021-07-23 23:10     ` syzbot
  2021-07-23 22:51   ` syzbot
  2 siblings, 1 reply; 7+ messages in thread
From: Pavel Skripkin @ 2021-07-23 16:49 UTC (permalink / raw)
  To: syzbot
  Cc: davem, devicetree, frowand.list, gregkh, jmaloy, kuba,
	linux-kernel, netdev, rafael, robh+dt, robh, syzkaller-bugs,
	tipc-discussion, ying.xue

[-- Attachment #1: Type: text/plain, Size: 2201 bytes --]

On Fri, 23 Jul 2021 19:36:11 +0300
Pavel Skripkin <paskripkin@gmail.com> wrote:

> On Sun, 18 Jul 2021 10:15:19 -0700
> syzbot <syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com> wrote:
> 
> > Hello,
> > 
> > syzbot found the following issue on:
> > 
> > HEAD commit:    ab0441b4a920 Merge branch 'vmxnet3-version-6'
> > git tree:       net-next
> > console output:
> > https://syzkaller.appspot.com/x/log.txt?x=1744ac6a300000 kernel
> > config:  https://syzkaller.appspot.com/x/.config?x=da140227e4f25b17
> > dashboard link:
> > https://syzkaller.appspot.com/bug?extid=e6741b97d5552f97c24d syz
> > repro:
> > https://syzkaller.appspot.com/x/repro.syz?x=13973a74300000 C
> > reproducer:
> > https://syzkaller.appspot.com/x/repro.c?x=17ffc902300000
> > 
> > The issue was bisected to:
> > 
> > commit 67a3156453859ceb40dc4448b7a6a99ea0ad27c7
> > Author: Rob Herring <robh@kernel.org>
> > Date:   Thu May 27 19:45:47 2021 +0000
> > 
> >     of: Merge of_address_to_resource() and
> > of_pci_address_to_resource() implementations
> > 
> > bisection log:
> > https://syzkaller.appspot.com/x/bisect.txt?x=129b0438300000 final
> > oops:
> > https://syzkaller.appspot.com/x/report.txt?x=119b0438300000 console
> > output: https://syzkaller.appspot.com/x/log.txt?x=169b0438300000
> > 
> > IMPORTANT: if you fix the issue, please add the following tag to the
> > commit: Reported-by:
> > syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com Fixes:
> > 67a315645385 ("of: Merge of_address_to_resource() and
> > of_pci_address_to_resource() implementations")
> > 
> > ==================================================================
> > BUG: KASAN: use-after-free in tipc_recvmsg+0xf77/0xf90
> > net/tipc/socket.c:1979 Read of size 4 at addr ffff8880328cf1c0 by
> > task kworker/u4:0/8
> > 
> 
> Since code accesing skb_cb after possible kfree_skb() call let's just
> store bytes_read to variable and use it instead of acessing
> skb_cb->bytes_read
> 
> #syz test
> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> master
> 
> 

Oops... The buggy code is in -next tree.

#syz test
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master 



With regards,
Pavel Skripkin

[-- Attachment #2: 0001-tipc-fix-use-after-free-in-tipc_recvmsg.patch --]
[-- Type: text/x-patch, Size: 1230 bytes --]

From 9f81f8574bfc1183209022b405848e01c35b86e6 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin <paskripkin@gmail.com>
Date: Fri, 23 Jul 2021 19:34:06 +0300
Subject: [PATCH] tipc: fix use-after-free in tipc_recvmsg

/* .. */

Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 net/tipc/socket.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 9b0b311c7ec1..0cf2468d209d 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1886,6 +1886,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
 	struct sk_buff *skb;
 	bool grp_evt;
 	long timeout;
+	unsigned int bytes_read;
 
 	/* Catch invalid receive requests */
 	if (unlikely(!buflen))
@@ -1973,10 +1974,13 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
 		tipc_node_distr_xmit(sock_net(sk), &xmitq);
 	}
 
-	if (!skb_cb->bytes_read)
+	/* To avoid accesing skb_cb after tsk_advance_rx_queue */
+	bytes_read = skb_cb->bytes_read;
+
+	if (!bytes_read)
 		tsk_advance_rx_queue(sk);
 
-	if (likely(!connected) || skb_cb->bytes_read)
+	if (likely(!connected) || bytes_read)
 		goto exit;
 
 	/* Send connection flow control advertisement when applicable */
-- 
2.32.0


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

* Re: [syzbot] KASAN: use-after-free Read in tipc_recvmsg
  2021-07-23 16:41   ` Xin Long
@ 2021-07-23 16:52     ` Pavel Skripkin
  0 siblings, 0 replies; 7+ messages in thread
From: Pavel Skripkin @ 2021-07-23 16:52 UTC (permalink / raw)
  To: Xin Long
  Cc: syzbot, davem, devicetree, frowand.list, Greg Kroah-Hartman,
	Jon Maloy, Jakub Kicinski, LKML, network dev, rafael, robh+dt,
	robh, syzkaller-bugs, tipc-discussion, Ying Xue

On Fri, 23 Jul 2021 12:41:46 -0400
Xin Long <lucien.xin@gmail.com> wrote:

> a fix already posted in tipc-discussion:
> 
> diff --git a/net/tipc/socket.c b/net/tipc/socket.c
> index 9b0b311c7ec1..b0dd183a4dbc 100644
> --- a/net/tipc/socket.c
> +++ b/net/tipc/socket.c
> @@ -1973,10 +1973,12 @@ static int tipc_recvmsg(struct socket *sock,
> struct msghdr *m,
>                 tipc_node_distr_xmit(sock_net(sk), &xmitq);
>         }
> 
> -       if (!skb_cb->bytes_read)
> -               tsk_advance_rx_queue(sk);
> +       if (skb_cb->bytes_read)
> +               goto exit;
> +
> +       tsk_advance_rx_queue(sk);
> 
> -       if (likely(!connected) || skb_cb->bytes_read)
> +       if (likely(!connected))
>                 goto exit;
> 

Ok, thank you for informing


With regards,
Pavel Skripkin



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

* Re: [syzbot] KASAN: use-after-free Read in tipc_recvmsg
  2021-07-23 16:36 ` Pavel Skripkin
  2021-07-23 16:41   ` Xin Long
  2021-07-23 16:49   ` Pavel Skripkin
@ 2021-07-23 22:51   ` syzbot
  2 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2021-07-23 22:51 UTC (permalink / raw)
  To: davem, devicetree, frowand.list, gregkh, jmaloy, kuba,
	linux-kernel, netdev, paskripkin, rafael, robh, syzkaller-bugs,
	tipc-discussion, ying.xue

Hello,

syzbot tried to test the proposed patch but the build/boot failed:

failed to apply patch:
checking file net/tipc/socket.c
Hunk #1 succeeded at 1885 (offset -1 lines).
Hunk #2 FAILED at 1974.
1 out of 2 hunks FAILED



Tested on:

commit:         704f4cba Merge tag 'ceph-for-5.14-rc3' of git://github..
git tree:       upstream
dashboard link: https://syzkaller.appspot.com/bug?extid=e6741b97d5552f97c24d
compiler:       
patch:          https://syzkaller.appspot.com/x/patch.diff?x=11e7d8b2300000


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

* Re: [syzbot] KASAN: use-after-free Read in tipc_recvmsg
  2021-07-23 16:49   ` Pavel Skripkin
@ 2021-07-23 23:10     ` syzbot
  0 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2021-07-23 23:10 UTC (permalink / raw)
  To: davem, devicetree, frowand.list, gregkh, jmaloy, kuba,
	linux-kernel, netdev, paskripkin, rafael, robh, syzkaller-bugs,
	tipc-discussion, ying.xue

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+e6741b97d5552f97c24d@syzkaller.appspotmail.com

Tested on:

commit:         90d856e7 Add linux-next specific files for 20210723
git tree:       linux-next
kernel config:  https://syzkaller.appspot.com/x/.config?x=644211b3d3da598c
dashboard link: https://syzkaller.appspot.com/bug?extid=e6741b97d5552f97c24d
compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.1
patch:          https://syzkaller.appspot.com/x/patch.diff?x=118f857c300000

Note: testing is done by a robot and is best-effort only.

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

end of thread, other threads:[~2021-07-23 23:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18 17:15 [syzbot] KASAN: use-after-free Read in tipc_recvmsg syzbot
2021-07-23 16:36 ` Pavel Skripkin
2021-07-23 16:41   ` Xin Long
2021-07-23 16:52     ` Pavel Skripkin
2021-07-23 16:49   ` Pavel Skripkin
2021-07-23 23:10     ` syzbot
2021-07-23 22:51   ` syzbot

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).