Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658766pxa; Mon, 17 Aug 2020 15:45:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1qiRSI8S/4t3e5jv8ZhQMkTRVWhJr6mHjH/SCd3fWFvPg602XuFfEgxqQFKmXhcymfeJM X-Received: by 2002:a17:906:da19:: with SMTP id fi25mr16994515ejb.405.1597704355761; Mon, 17 Aug 2020 15:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704355; cv=none; d=google.com; s=arc-20160816; b=Pm/ZAdyVFLuu2SKf752AMyG8fD6Ri/0yQAKL9C9DTYdhkbOn34wQJ6aMyN17fgVm8Q c4DwhvDeWYBpLB4WLQUxB5bkILhL+j4t81aHmIy9o45zYIxpD0ygyT6yDgoR2LWslv5x rvhTgTjmbPYQiHPcn73Qa7UKwNi0spZG04OkzxOwMkl1RPN3d4CdGS6PYnA475PwspMW 8iwPYrXvLasmRr54KkI81lXktLs1A3Q9yKWoMMn3PNG2deFdzMaUZaiymggnAFhIQ4Bf G7fflkzYN7CBHFeZhCPLuLfvovyOvuGaKX7EpBVU7v0n0xm/d15KRNHXPyHrzo493Keq gNQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OuMqxtJk6z4AWm6qXHrjawhGQyGAsO78Ne9o3E5g0tU=; b=Be1YjB5MkcqmYU8G+I4vT7pONa1WCEvkGZuK8e4m3qbT1kNS+GflsZIDm478912UjH 1acC67k7llatDyMId1sSCG/g4lzYlZFwemRg9lSejMChjuacdc6po2/NiWIHRJe/J3OG 6/0jJXqEFH0p/jgSsjiISctgw6NwFp0ed9zGKDdcmc7aOgfrdcmg/PGd/eLL+VXLF2QL SWT/wAQd3JXNijbkNsYG3kxaUTlP9IEVkAxFxzcHGetyu3HDJ13rjPowrZBFT8Jo6guI k3/5uWxFY/PCFiW1NtDnq2xB0aWMiiuBRpQIlmYcNkvLsUkVqKr5aB/q8iyui229QMgi xL4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ykN/sySL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w15si14874816edl.118.2020.08.17.15.45.32; Mon, 17 Aug 2020 15:45:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ykN/sySL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392311AbgHQTUR (ORCPT + 99 others); Mon, 17 Aug 2020 15:20:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:44338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730517AbgHQPgu (ORCPT ); Mon, 17 Aug 2020 11:36:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7DC32310F; Mon, 17 Aug 2020 15:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678609; bh=/omsBwg8Yyncdrw92Temo+2BdmMOicqXhOUwneH6NX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ykN/sySLLZISY9YpjYMmxlU7V6ak5oMxO+LvzOUvTwRqSo9CUfL7QteL7SbZDJitx SqSXI60uojad3G/Ss+IoqtAxQumDjvSmm0pMe8pkzadQ6t44UbtOOTVzNjLqesB+sj /aBhOiiXFpPl44r6u7OWiivkGkGFQNT319QRo1vs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Garzarella , Jorgen Hansen , "David S. Miller" , syzbot+a61bac2fcc1a7c6623fe@syzkaller.appspotmail.com Subject: [PATCH 5.8 394/464] vsock: fix potential null pointer dereference in vsock_poll() Date: Mon, 17 Aug 2020 17:15:47 +0200 Message-Id: <20200817143852.652250005@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefano Garzarella [ Upstream commit 1980c05844830a44708c98c96d600833aa3fae08 ] 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 Reviewed-by: Jorgen Hansen Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/vmw_vsock/af_vsock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- 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 * } /* 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(