netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jorgen Hansen <jhansen@vmware.com>
To: 'Stefano Garzarella' <sgarzare@redhat.com>,
	"davem@davemloft.net" <davem@davemloft.net>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Dexuan Cui <decui@microsoft.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Jakub Kicinski <kuba@kernel.org>
Subject: RE: [PATCH net v2] vsock: fix potential null pointer dereference in vsock_poll()
Date: Wed, 12 Aug 2020 13:33:08 +0000	[thread overview]
Message-ID: <DM5PR05MB3452B24F729BD183C4297614DA420@DM5PR05MB3452.namprd05.prod.outlook.com> (raw)
In-Reply-To: <20200812125602.96598-1-sgarzare@redhat.com>

> From: Stefano Garzarella <sgarzare@redhat.com>
> Sent: Wednesday, August 12, 2020 2:56 PM
> To: davem@davemloft.net
> Cc: linux-kernel@vger.kernel.org; Dexuan Cui <decui@microsoft.com>;
> netdev@vger.kernel.org; Stefan Hajnoczi <stefanha@redhat.com>; Jakub
> Kicinski <kuba@kernel.org>; Jorgen Hansen <jhansen@vmware.com>;
> Stefano Garzarella <sgarzare@redhat.com>
> Subject: [PATCH net v2] vsock: fix potential null pointer dereference in
> vsock_poll()
> 
> 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>
> ---
> v2:
>  - removed cleanups patch from the series [David]
> 
> v1:
> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatc
> hwork.ozlabs.org%2Fproject%2Fnetdev%2Fcover%2F20200811095504.25051-
> 1-
> sgarzare%40redhat.com%2F&amp;data=02%7C01%7Cjhansen%40vmware.co
> m%7C32b3919883a448f56a8708d83ebf1dce%7Cb39138ca3cee4b4aa4d6cd83d
> 9dd62f0%7C0%7C0%7C637328337851992525&amp;sdata=CSo8PEJJwyDE75Qz
> n3lmasJFSNaNChiRXjoy%2FfoJ8Vs%3D&amp;reserved=0
> ---
>  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

Thanks for fixing this!

Reviewed-by: Jorgen Hansen <jhansen@vmware.com>

  reply	other threads:[~2020-08-12 13:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12 12:56 [PATCH net v2] vsock: fix potential null pointer dereference in vsock_poll() Stefano Garzarella
2020-08-12 13:33 ` Jorgen Hansen [this message]
2020-08-12 20:08 ` David Miller

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=DM5PR05MB3452B24F729BD183C4297614DA420@DM5PR05MB3452.namprd05.prod.outlook.com \
    --to=jhansen@vmware.com \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).