diff mbox series

[net-next] vsock: do not leave dangling sk pointer in vsock_create()

Message ID 20241022134819.1085254-1-edumazet@google.com (mailing list archive)
State Accepted
Commit ba4e469e42fe1a771b5653d179eb12dc4be6b6a8
Delegated to: Netdev Maintainers
Headers show
Series [net-next] vsock: do not leave dangling sk pointer in vsock_create() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: sgarzare@redhat.com virtualization@lists.linux.dev
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch warning WARNING: Possible repeated word: 'Google'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-23--12-00 (tests: 777)

Commit Message

Eric Dumazet Oct. 22, 2024, 1:48 p.m. UTC
syzbot was able to trigger the following warning after recent
core network cleanup.

On error vsock_create() frees the allocated sk object, but sock_init_data()
has already attached it to the provided sock object.

We must clear sock->sk to avoid possible use-after-free later.

WARNING: CPU: 0 PID: 5282 at net/socket.c:1581 __sock_create+0x897/0x950 net/socket.c:1581
Modules linked in:
CPU: 0 UID: 0 PID: 5282 Comm: syz.2.43 Not tainted 6.12.0-rc2-syzkaller-00667-g53bac8330865 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
 RIP: 0010:__sock_create+0x897/0x950 net/socket.c:1581
Code: 7f 06 01 65 48 8b 34 25 00 d8 03 00 48 81 c6 b0 08 00 00 48 c7 c7 60 0b 0d 8d e8 d4 9a 3c 02 e9 11 f8 ff ff e8 0a ab 0d f8 90 <0f> 0b 90 e9 82 fd ff ff 89 e9 80 e1 07 fe c1 38 c1 0f 8c c7 f8 ff
RSP: 0018:ffffc9000394fda8 EFLAGS: 00010293
RAX: ffffffff89873c46 RBX: ffff888079f3c818 RCX: ffff8880314b9e00
RDX: 0000000000000000 RSI: 00000000ffffffed RDI: 0000000000000000
RBP: ffffffff8d3337f0 R08: ffffffff8987384e R09: ffffffff8989473a
R10: dffffc0000000000 R11: fffffbfff203a276 R12: 00000000ffffffed
R13: ffff888079f3c8c0 R14: ffffffff898736e7 R15: dffffc0000000000
FS:  00005555680ab500(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f22b11196d0 CR3: 00000000308c0000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
  sock_create net/socket.c:1632 [inline]
  __sys_socket_create net/socket.c:1669 [inline]
  __sys_socket+0x150/0x3c0 net/socket.c:1716
  __do_sys_socket net/socket.c:1730 [inline]
  __se_sys_socket net/socket.c:1728 [inline]
  __x64_sys_socket+0x7a/0x90 net/socket.c:1728
  do_syscall_x64 arch/x86/entry/common.c:52 [inline]
  do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f22b117dff9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff56aec0e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000029
RAX: ffffffffffffffda RBX: 00007f22b1335f80 RCX: 00007f22b117dff9
RDX: 0000000000000000 RSI: 0000000000000002 RDI: 0000000000000028
RBP: 00007f22b11f0296 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f22b1335f80 R14: 00007f22b1335f80 R15: 00000000000012dd

Fixes: 48156296a08c ("net: warn, if pf->create does not clear sock->sk on error")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Ignat Korchagin <ignat@cloudflare.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/vmw_vsock/af_vsock.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Kuniyuki Iwashima Oct. 22, 2024, 7:39 p.m. UTC | #1
From: Eric Dumazet <edumazet@google.com>
Date: Tue, 22 Oct 2024 13:48:19 +0000
> syzbot was able to trigger the following warning after recent
> core network cleanup.
> 
> On error vsock_create() frees the allocated sk object, but sock_init_data()
> has already attached it to the provided sock object.
> 
> We must clear sock->sk to avoid possible use-after-free later.
> 
> WARNING: CPU: 0 PID: 5282 at net/socket.c:1581 __sock_create+0x897/0x950 net/socket.c:1581
> Modules linked in:
> CPU: 0 UID: 0 PID: 5282 Comm: syz.2.43 Not tainted 6.12.0-rc2-syzkaller-00667-g53bac8330865 #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
>  RIP: 0010:__sock_create+0x897/0x950 net/socket.c:1581
> Code: 7f 06 01 65 48 8b 34 25 00 d8 03 00 48 81 c6 b0 08 00 00 48 c7 c7 60 0b 0d 8d e8 d4 9a 3c 02 e9 11 f8 ff ff e8 0a ab 0d f8 90 <0f> 0b 90 e9 82 fd ff ff 89 e9 80 e1 07 fe c1 38 c1 0f 8c c7 f8 ff
> RSP: 0018:ffffc9000394fda8 EFLAGS: 00010293
> RAX: ffffffff89873c46 RBX: ffff888079f3c818 RCX: ffff8880314b9e00
> RDX: 0000000000000000 RSI: 00000000ffffffed RDI: 0000000000000000
> RBP: ffffffff8d3337f0 R08: ffffffff8987384e R09: ffffffff8989473a
> R10: dffffc0000000000 R11: fffffbfff203a276 R12: 00000000ffffffed
> R13: ffff888079f3c8c0 R14: ffffffff898736e7 R15: dffffc0000000000
> FS:  00005555680ab500(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007f22b11196d0 CR3: 00000000308c0000 CR4: 00000000003526f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
>  <TASK>
>   sock_create net/socket.c:1632 [inline]
>   __sys_socket_create net/socket.c:1669 [inline]
>   __sys_socket+0x150/0x3c0 net/socket.c:1716
>   __do_sys_socket net/socket.c:1730 [inline]
>   __se_sys_socket net/socket.c:1728 [inline]
>   __x64_sys_socket+0x7a/0x90 net/socket.c:1728
>   do_syscall_x64 arch/x86/entry/common.c:52 [inline]
>   do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> RIP: 0033:0x7f22b117dff9
> Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
> RSP: 002b:00007fff56aec0e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000029
> RAX: ffffffffffffffda RBX: 00007f22b1335f80 RCX: 00007f22b117dff9
> RDX: 0000000000000000 RSI: 0000000000000002 RDI: 0000000000000028
> RBP: 00007f22b11f0296 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
> R13: 00007f22b1335f80 R14: 00007f22b1335f80 R15: 00000000000012dd
> 
> Fixes: 48156296a08c ("net: warn, if pf->create does not clear sock->sk on error")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Ignat Korchagin <ignat@cloudflare.com>
> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Thanks!


> ---
>  net/vmw_vsock/af_vsock.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 35681adedd9aaec3565495158f5342b8aa76c9bc..109b7a0bd0714c9a2d5c9dd58421e7e9344a8474 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -2417,6 +2417,7 @@ static int vsock_create(struct net *net, struct socket *sock,
>  	if (sock->type == SOCK_DGRAM) {
>  		ret = vsock_assign_transport(vsk, NULL);
>  		if (ret < 0) {
> +			sock->sk = NULL;
>  			sock_put(sk);
>  			return ret;
>  		}
> -- 
> 2.47.0.105.g07ac214952-goog
Stefano Garzarella Oct. 25, 2024, 8:45 a.m. UTC | #2
On Tue, Oct 22, 2024 at 01:48:19PM +0000, Eric Dumazet wrote:
>syzbot was able to trigger the following warning after recent
>core network cleanup.
>
>On error vsock_create() frees the allocated sk object, but sock_init_data()
>has already attached it to the provided sock object.
>
>We must clear sock->sk to avoid possible use-after-free later.
>
>WARNING: CPU: 0 PID: 5282 at net/socket.c:1581 __sock_create+0x897/0x950 net/socket.c:1581
>Modules linked in:
>CPU: 0 UID: 0 PID: 5282 Comm: syz.2.43 Not tainted 6.12.0-rc2-syzkaller-00667-g53bac8330865 #0
>Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
> RIP: 0010:__sock_create+0x897/0x950 net/socket.c:1581
>Code: 7f 06 01 65 48 8b 34 25 00 d8 03 00 48 81 c6 b0 08 00 00 48 c7 c7 60 0b 0d 8d e8 d4 9a 3c 02 e9 11 f8 ff ff e8 0a ab 0d f8 90 <0f> 0b 90 e9 82 fd ff ff 89 e9 80 e1 07 fe c1 38 c1 0f 8c c7 f8 ff
>RSP: 0018:ffffc9000394fda8 EFLAGS: 00010293
>RAX: ffffffff89873c46 RBX: ffff888079f3c818 RCX: ffff8880314b9e00
>RDX: 0000000000000000 RSI: 00000000ffffffed RDI: 0000000000000000
>RBP: ffffffff8d3337f0 R08: ffffffff8987384e R09: ffffffff8989473a
>R10: dffffc0000000000 R11: fffffbfff203a276 R12: 00000000ffffffed
>R13: ffff888079f3c8c0 R14: ffffffff898736e7 R15: dffffc0000000000
>FS:  00005555680ab500(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
>CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>CR2: 00007f22b11196d0 CR3: 00000000308c0000 CR4: 00000000003526f0
>DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
>DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
>Call Trace:
> <TASK>
>  sock_create net/socket.c:1632 [inline]
>  __sys_socket_create net/socket.c:1669 [inline]
>  __sys_socket+0x150/0x3c0 net/socket.c:1716
>  __do_sys_socket net/socket.c:1730 [inline]
>  __se_sys_socket net/socket.c:1728 [inline]
>  __x64_sys_socket+0x7a/0x90 net/socket.c:1728
>  do_syscall_x64 arch/x86/entry/common.c:52 [inline]
>  do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
>RIP: 0033:0x7f22b117dff9
>Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
>RSP: 002b:00007fff56aec0e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000029
>RAX: ffffffffffffffda RBX: 00007f22b1335f80 RCX: 00007f22b117dff9
>RDX: 0000000000000000 RSI: 0000000000000002 RDI: 0000000000000028
>RBP: 00007f22b11f0296 R08: 0000000000000000 R09: 0000000000000000
>R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
>R13: 00007f22b1335f80 R14: 00007f22b1335f80 R15: 00000000000012dd
>
>Fixes: 48156296a08c ("net: warn, if pf->create does not clear sock->sk on error")
>Reported-by: syzbot <syzkaller@googlegroups.com>
>Signed-off-by: Eric Dumazet <edumazet@google.com>
>Cc: Ignat Korchagin <ignat@cloudflare.com>
>Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
>---
> net/vmw_vsock/af_vsock.c | 1 +
> 1 file changed, 1 insertion(+)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index 35681adedd9aaec3565495158f5342b8aa76c9bc..109b7a0bd0714c9a2d5c9dd58421e7e9344a8474 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -2417,6 +2417,7 @@ static int vsock_create(struct net *net, struct socket *sock,
> 	if (sock->type == SOCK_DGRAM) {
> 		ret = vsock_assign_transport(vsk, NULL);
> 		if (ret < 0) {
>+			sock->sk = NULL;
> 			sock_put(sk);
> 			return ret;
> 		}
>-- 
>2.47.0.105.g07ac214952-goog
>
>
patchwork-bot+netdevbpf@kernel.org Oct. 29, 2024, 2:40 a.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 22 Oct 2024 13:48:19 +0000 you wrote:
> syzbot was able to trigger the following warning after recent
> core network cleanup.
> 
> On error vsock_create() frees the allocated sk object, but sock_init_data()
> has already attached it to the provided sock object.
> 
> We must clear sock->sk to avoid possible use-after-free later.
> 
> [...]

Here is the summary with links:
  - [net-next] vsock: do not leave dangling sk pointer in vsock_create()
    https://git.kernel.org/netdev/net-next/c/ba4e469e42fe

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 35681adedd9aaec3565495158f5342b8aa76c9bc..109b7a0bd0714c9a2d5c9dd58421e7e9344a8474 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2417,6 +2417,7 @@  static int vsock_create(struct net *net, struct socket *sock,
 	if (sock->type == SOCK_DGRAM) {
 		ret = vsock_assign_transport(vsk, NULL);
 		if (ret < 0) {
+			sock->sk = NULL;
 			sock_put(sk);
 			return ret;
 		}