All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] tcp: fix error recovery in tcp_zerocopy_receive()
@ 2020-05-14 20:58 Eric Dumazet
  2020-05-14 21:20 ` Soheil Hassas Yeganeh
  2020-05-14 22:13 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2020-05-14 20:58 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Eric Dumazet, Arjun Roy,
	Soheil Hassas Yeganeh, syzbot

If user provides wrong virtual address in TCP_ZEROCOPY_RECEIVE
operation we want to return -EINVAL error.

But depending on zc->recv_skip_hint content, we might return
-EIO error if the socket has SOCK_DONE set.

Make sure to return -EINVAL in this case.

BUG: KMSAN: uninit-value in tcp_zerocopy_receive net/ipv4/tcp.c:1833 [inline]
BUG: KMSAN: uninit-value in do_tcp_getsockopt+0x4494/0x6320 net/ipv4/tcp.c:3685
CPU: 1 PID: 625 Comm: syz-executor.0 Not tainted 5.7.0-rc4-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x1c9/0x220 lib/dump_stack.c:118
 kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:121
 __msan_warning+0x58/0xa0 mm/kmsan/kmsan_instr.c:215
 tcp_zerocopy_receive net/ipv4/tcp.c:1833 [inline]
 do_tcp_getsockopt+0x4494/0x6320 net/ipv4/tcp.c:3685
 tcp_getsockopt+0xf8/0x1f0 net/ipv4/tcp.c:3728
 sock_common_getsockopt+0x13f/0x180 net/core/sock.c:3131
 __sys_getsockopt+0x533/0x7b0 net/socket.c:2177
 __do_sys_getsockopt net/socket.c:2192 [inline]
 __se_sys_getsockopt+0xe1/0x100 net/socket.c:2189
 __x64_sys_getsockopt+0x62/0x80 net/socket.c:2189
 do_syscall_64+0xb8/0x160 arch/x86/entry/common.c:297
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45c829
Code: 0d b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 0f 83 db b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f1deeb72c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000037
RAX: ffffffffffffffda RBX: 00000000004e01e0 RCX: 000000000045c829
RDX: 0000000000000023 RSI: 0000000000000006 RDI: 0000000000000009
RBP: 000000000078bf00 R08: 0000000020000200 R09: 0000000000000000
R10: 00000000200001c0 R11: 0000000000000246 R12: 00000000ffffffff
R13: 00000000000001d8 R14: 00000000004d3038 R15: 00007f1deeb736d4

Local variable ----zc@do_tcp_getsockopt created at:
 do_tcp_getsockopt+0x1a74/0x6320 net/ipv4/tcp.c:3670
 do_tcp_getsockopt+0x1a74/0x6320 net/ipv4/tcp.c:3670

Fixes: 05255b823a61 ("tcp: add TCP_ZEROCOPY_RECEIVE support for zerocopy receive")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
---
 net/ipv4/tcp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index a385fcaaa03beed9bfeabdebc12371e34e0649de..dd401757eea1f0187b0e547828f794e62eb895b8 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1764,10 +1764,11 @@ static int tcp_zerocopy_receive(struct sock *sk,
 
 	down_read(&current->mm->mmap_sem);
 
-	ret = -EINVAL;
 	vma = find_vma(current->mm, address);
-	if (!vma || vma->vm_start > address || vma->vm_ops != &tcp_vm_ops)
-		goto out;
+	if (!vma || vma->vm_start > address || vma->vm_ops != &tcp_vm_ops) {
+		up_read(&current->mm->mmap_sem);
+		return -EINVAL;
+	}
 	zc->length = min_t(unsigned long, zc->length, vma->vm_end - address);
 
 	tp = tcp_sk(sk);
-- 
2.26.2.761.g0e0b3e54be-goog


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

* Re: [PATCH net] tcp: fix error recovery in tcp_zerocopy_receive()
  2020-05-14 20:58 [PATCH net] tcp: fix error recovery in tcp_zerocopy_receive() Eric Dumazet
@ 2020-05-14 21:20 ` Soheil Hassas Yeganeh
  2020-05-14 22:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Soheil Hassas Yeganeh @ 2020-05-14 21:20 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David S . Miller, netdev, Eric Dumazet, Arjun Roy, syzbot

On Thu, May 14, 2020 at 4:58 PM Eric Dumazet <edumazet@google.com> wrote:
>
> If user provides wrong virtual address in TCP_ZEROCOPY_RECEIVE
> operation we want to return -EINVAL error.
>
> But depending on zc->recv_skip_hint content, we might return
> -EIO error if the socket has SOCK_DONE set.
>
> Make sure to return -EINVAL in this case.
>
> BUG: KMSAN: uninit-value in tcp_zerocopy_receive net/ipv4/tcp.c:1833 [inline]
> BUG: KMSAN: uninit-value in do_tcp_getsockopt+0x4494/0x6320 net/ipv4/tcp.c:3685
> CPU: 1 PID: 625 Comm: syz-executor.0 Not tainted 5.7.0-rc4-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
>  __dump_stack lib/dump_stack.c:77 [inline]
>  dump_stack+0x1c9/0x220 lib/dump_stack.c:118
>  kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:121
>  __msan_warning+0x58/0xa0 mm/kmsan/kmsan_instr.c:215
>  tcp_zerocopy_receive net/ipv4/tcp.c:1833 [inline]
>  do_tcp_getsockopt+0x4494/0x6320 net/ipv4/tcp.c:3685
>  tcp_getsockopt+0xf8/0x1f0 net/ipv4/tcp.c:3728
>  sock_common_getsockopt+0x13f/0x180 net/core/sock.c:3131
>  __sys_getsockopt+0x533/0x7b0 net/socket.c:2177
>  __do_sys_getsockopt net/socket.c:2192 [inline]
>  __se_sys_getsockopt+0xe1/0x100 net/socket.c:2189
>  __x64_sys_getsockopt+0x62/0x80 net/socket.c:2189
>  do_syscall_64+0xb8/0x160 arch/x86/entry/common.c:297
>  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> RIP: 0033:0x45c829
> Code: 0d b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 0f 83 db b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00
> RSP: 002b:00007f1deeb72c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000037
> RAX: ffffffffffffffda RBX: 00000000004e01e0 RCX: 000000000045c829
> RDX: 0000000000000023 RSI: 0000000000000006 RDI: 0000000000000009
> RBP: 000000000078bf00 R08: 0000000020000200 R09: 0000000000000000
> R10: 00000000200001c0 R11: 0000000000000246 R12: 00000000ffffffff
> R13: 00000000000001d8 R14: 00000000004d3038 R15: 00007f1deeb736d4
>
> Local variable ----zc@do_tcp_getsockopt created at:
>  do_tcp_getsockopt+0x1a74/0x6320 net/ipv4/tcp.c:3670
>  do_tcp_getsockopt+0x1a74/0x6320 net/ipv4/tcp.c:3670
>
> Fixes: 05255b823a61 ("tcp: add TCP_ZEROCOPY_RECEIVE support for zerocopy receive")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>

Acked-by: Soheil Hassas Yeganeh <soheil@google.com>

Thanks for the fix!

> ---
>  net/ipv4/tcp.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index a385fcaaa03beed9bfeabdebc12371e34e0649de..dd401757eea1f0187b0e547828f794e62eb895b8 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1764,10 +1764,11 @@ static int tcp_zerocopy_receive(struct sock *sk,
>
>         down_read(&current->mm->mmap_sem);
>
> -       ret = -EINVAL;
>         vma = find_vma(current->mm, address);
> -       if (!vma || vma->vm_start > address || vma->vm_ops != &tcp_vm_ops)
> -               goto out;
> +       if (!vma || vma->vm_start > address || vma->vm_ops != &tcp_vm_ops) {
> +               up_read(&current->mm->mmap_sem);
> +               return -EINVAL;
> +       }
>         zc->length = min_t(unsigned long, zc->length, vma->vm_end - address);
>
>         tp = tcp_sk(sk);
> --
> 2.26.2.761.g0e0b3e54be-goog
>

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

* Re: [PATCH net] tcp: fix error recovery in tcp_zerocopy_receive()
  2020-05-14 20:58 [PATCH net] tcp: fix error recovery in tcp_zerocopy_receive() Eric Dumazet
  2020-05-14 21:20 ` Soheil Hassas Yeganeh
@ 2020-05-14 22:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-05-14 22:13 UTC (permalink / raw)
  To: edumazet; +Cc: netdev, eric.dumazet, arjunroy, soheil, syzkaller

From: Eric Dumazet <edumazet@google.com>
Date: Thu, 14 May 2020 13:58:13 -0700

> If user provides wrong virtual address in TCP_ZEROCOPY_RECEIVE
> operation we want to return -EINVAL error.
> 
> But depending on zc->recv_skip_hint content, we might return
> -EIO error if the socket has SOCK_DONE set.
> 
> Make sure to return -EINVAL in this case.
> 
> BUG: KMSAN: uninit-value in tcp_zerocopy_receive net/ipv4/tcp.c:1833 [inline]
  ...
> Fixes: 05255b823a61 ("tcp: add TCP_ZEROCOPY_RECEIVE support for zerocopy receive")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>

Series applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2020-05-14 22:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 20:58 [PATCH net] tcp: fix error recovery in tcp_zerocopy_receive() Eric Dumazet
2020-05-14 21:20 ` Soheil Hassas Yeganeh
2020-05-14 22:13 ` David Miller

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.