* [PATCH net 0/2] vsock: fix null pointer dereference and cleanup in vsock_poll()
@ 2020-08-11 9:55 Stefano Garzarella
2020-08-11 9:55 ` [PATCH net 1/2] vsock: fix potential null pointer dereference " Stefano Garzarella
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Stefano Garzarella @ 2020-08-11 9:55 UTC (permalink / raw)
To: davem
Cc: Jorgen Hansen, Stefano Garzarella, netdev, Jakub Kicinski,
Dexuan Cui, linux-kernel, Stefan Hajnoczi
The first patch fixes a potential null pointer dereference in vsock_poll()
reported by syzbot.
The second patch is a simple cleanup in the same block code. I put this later,
to make it easier to backport the first patch in the stable branches.
Thanks,
Stefano
Stefano Garzarella (2):
vsock: fix potential null pointer dereference in vsock_poll()
vsock: small cleanup in vsock_poll()
net/vmw_vsock/af_vsock.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 1/2] vsock: fix potential null pointer dereference in vsock_poll()
2020-08-11 9:55 [PATCH net 0/2] vsock: fix null pointer dereference and cleanup in vsock_poll() Stefano Garzarella
@ 2020-08-11 9:55 ` Stefano Garzarella
2020-08-11 9:55 ` [PATCH net 2/2] vsock: small cleanup " Stefano Garzarella
2020-08-11 17:24 ` [PATCH net 0/2] vsock: fix null pointer dereference and " David Miller
2 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2020-08-11 9:55 UTC (permalink / raw)
To: davem
Cc: Jorgen Hansen, Stefano Garzarella, netdev, Jakub Kicinski,
Dexuan Cui, linux-kernel, Stefan Hajnoczi
syzbot reported this issue where in the vsock_poll() we find the
socket state at TCP_ESTABLISHED, but 'transport' is null:
general protection fault, probably for non-canonical address 0xdffffc0000000012: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000090-0x0000000000000097]
CPU: 0 PID: 8227 Comm: syz-executor.2 Not tainted 5.8.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:vsock_poll+0x75a/0x8e0 net/vmw_vsock/af_vsock.c:1038
Call Trace:
sock_poll+0x159/0x460 net/socket.c:1266
vfs_poll include/linux/poll.h:90 [inline]
do_pollfd fs/select.c:869 [inline]
do_poll fs/select.c:917 [inline]
do_sys_poll+0x607/0xd40 fs/select.c:1011
__do_sys_poll fs/select.c:1069 [inline]
__se_sys_poll fs/select.c:1057 [inline]
__x64_sys_poll+0x18c/0x440 fs/select.c:1057
do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:384
entry_SYSCALL_64_after_hwframe+0x44/0xa9
This issue can happen if the TCP_ESTABLISHED state is set after we read
the vsk->transport in the vsock_poll().
We could put barriers to synchronize, but this can only happen during
connection setup, so we can simply check that 'transport' is valid.
Fixes: c0cfa2d8a788 ("vsock: add multi-transports support")
Reported-and-tested-by: syzbot+a61bac2fcc1a7c6623fe@syzkaller.appspotmail.com
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
net/vmw_vsock/af_vsock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 27bbcfad9c17..9e93bc201cc0 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1032,7 +1032,7 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock,
}
/* Connected sockets that can produce data can be written. */
- if (sk->sk_state == TCP_ESTABLISHED) {
+ if (transport && sk->sk_state == TCP_ESTABLISHED) {
if (!(sk->sk_shutdown & SEND_SHUTDOWN)) {
bool space_avail_now = false;
int ret = transport->notify_poll_out(
--
2.26.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 2/2] vsock: small cleanup in vsock_poll()
2020-08-11 9:55 [PATCH net 0/2] vsock: fix null pointer dereference and cleanup in vsock_poll() Stefano Garzarella
2020-08-11 9:55 ` [PATCH net 1/2] vsock: fix potential null pointer dereference " Stefano Garzarella
@ 2020-08-11 9:55 ` Stefano Garzarella
2020-08-11 17:24 ` [PATCH net 0/2] vsock: fix null pointer dereference and " David Miller
2 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2020-08-11 9:55 UTC (permalink / raw)
To: davem
Cc: Jorgen Hansen, Stefano Garzarella, netdev, Jakub Kicinski,
Dexuan Cui, linux-kernel, Stefan Hajnoczi
This patch combines nested if statements in a single one to reduce
the indentation in vsock_poll().
It also combines an if nested in the else branch.
The behavior isn't changed.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
net/vmw_vsock/af_vsock.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 9e93bc201cc0..2c80dc14fa60 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1032,21 +1032,18 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock,
}
/* Connected sockets that can produce data can be written. */
- if (transport && sk->sk_state == TCP_ESTABLISHED) {
- if (!(sk->sk_shutdown & SEND_SHUTDOWN)) {
- bool space_avail_now = false;
- int ret = transport->notify_poll_out(
- vsk, 1, &space_avail_now);
- if (ret < 0) {
- mask |= EPOLLERR;
- } else {
- if (space_avail_now)
- /* Remove EPOLLWRBAND since INET
- * sockets are not setting it.
- */
- mask |= EPOLLOUT | EPOLLWRNORM;
-
- }
+ if (transport && sk->sk_state == TCP_ESTABLISHED &&
+ !(sk->sk_shutdown & SEND_SHUTDOWN)) {
+ bool space_avail_now = false;
+ int ret = transport->notify_poll_out(vsk, 1,
+ &space_avail_now);
+ if (ret < 0) {
+ mask |= EPOLLERR;
+ } else if (space_avail_now) {
+ /* Remove EPOLLWRBAND since INET
+ * sockets are not setting it.
+ */
+ mask |= EPOLLOUT | EPOLLWRNORM;
}
}
--
2.26.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 0/2] vsock: fix null pointer dereference and cleanup in vsock_poll()
2020-08-11 9:55 [PATCH net 0/2] vsock: fix null pointer dereference and cleanup in vsock_poll() Stefano Garzarella
2020-08-11 9:55 ` [PATCH net 1/2] vsock: fix potential null pointer dereference " Stefano Garzarella
2020-08-11 9:55 ` [PATCH net 2/2] vsock: small cleanup " Stefano Garzarella
@ 2020-08-11 17:24 ` David Miller
2020-08-12 7:17 ` Stefano Garzarella
2 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2020-08-11 17:24 UTC (permalink / raw)
To: sgarzare; +Cc: jhansen, netdev, kuba, decui, linux-kernel, stefanha
From: Stefano Garzarella <sgarzare@redhat.com>
Date: Tue, 11 Aug 2020 11:55:02 +0200
> The first patch fixes a potential null pointer dereference in vsock_poll()
> reported by syzbot.
> The second patch is a simple cleanup in the same block code. I put this later,
> to make it easier to backport the first patch in the stable branches.
Please do not mix cleanups and bug fixes into the same patch series.
net-next is closed, so you should not be submitting non-bugfixes at
this time.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net 0/2] vsock: fix null pointer dereference and cleanup in vsock_poll()
2020-08-11 17:24 ` [PATCH net 0/2] vsock: fix null pointer dereference and " David Miller
@ 2020-08-12 7:17 ` Stefano Garzarella
0 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2020-08-12 7:17 UTC (permalink / raw)
To: David Miller; +Cc: jhansen, netdev, kuba, decui, linux-kernel, stefanha
On Tue, Aug 11, 2020 at 10:24:18AM -0700, David Miller wrote:
> From: Stefano Garzarella <sgarzare@redhat.com>
> Date: Tue, 11 Aug 2020 11:55:02 +0200
>
> > The first patch fixes a potential null pointer dereference in vsock_poll()
> > reported by syzbot.
> > The second patch is a simple cleanup in the same block code. I put this later,
> > to make it easier to backport the first patch in the stable branches.
>
> Please do not mix cleanups and bug fixes into the same patch series.
I did it because I was going through the same part of the code,
but I won't do it again!
>
> net-next is closed, so you should not be submitting non-bugfixes at
> this time.
>
I'll resend only the first patch, sorry for the noise.
Thanks,
Stefano
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-12 7:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-11 9:55 [PATCH net 0/2] vsock: fix null pointer dereference and cleanup in vsock_poll() Stefano Garzarella
2020-08-11 9:55 ` [PATCH net 1/2] vsock: fix potential null pointer dereference " Stefano Garzarella
2020-08-11 9:55 ` [PATCH net 2/2] vsock: small cleanup " Stefano Garzarella
2020-08-11 17:24 ` [PATCH net 0/2] vsock: fix null pointer dereference and " David Miller
2020-08-12 7:17 ` Stefano Garzarella
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).