Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2639301pxa; Mon, 17 Aug 2020 15:10:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNgTZ0Pw+sWfP5s/+gXhPxII58vrdsvavSOLIXgU28vXbQxXSTgnjsW0/Dxfy1FRyTl2JR X-Received: by 2002:aa7:d3d9:: with SMTP id o25mr17452537edr.362.1597702245372; Mon, 17 Aug 2020 15:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597702245; cv=none; d=google.com; s=arc-20160816; b=kKyrO4mS55t2eAMQebdhYU+UlAEzr+l/4k1MvJBZiBi6CtpWDBPuBAhOwxzFdUVKpK Awt5/DByTdB5tvDLOkhXRNjqN3vlnY2F0d36+ATmXBw9uLdNVojILMBRap4OHQfdX7Bn LqEGoZzVb9Zzc2mbK89mfpISVc+5PQXEM/+VgBitT1WiO45tdyww/SZygvCTeXizgY2m oSRO73ZKCNSdS5FVCH52TlMq5G9dQwRGqSw/F+8DFR9eKGhROu+7b7F9vBdedE/2wIv6 GZgBwlb3pYicAqzVFHKL8BHsCADGM+/X4GTF64KTG8VJ1NV7bgAUQQwQ0gm2WW3dTCS3 pujw== 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=i3AfvF6LmqIqZOFB2gfTn1KElRMUG7Shv/ruwLwG9HmZTC8/9L/TiEEICLPlikZaFE cbzui79xzLMpRttzK3bz4jhjcmz+UlMYm2dW6aL7aOPA9kBt1vaSMXm/ALQfQ7mhtTiD kjbzhp/ej0HtMbvNlesV0DxporGoycn9v1ipUBjfqVOrAPo9nwj4Mf5HhqcQARthKbDK ztQDMQObY3Fa6XY0fjcPIDntb/4HxqD+xWu9pXrfkiMfxBenM3vpETr8sdXVUxZlQyel B0lzwaseM2w3YuwsUpTOjS9NOimWike12uY5Ee8VUEd1sK41DqcAAkDeiWqzYZBKxIIB O8Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ur3/lf9C"; 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 lo3si11821656ejb.219.2020.08.17.15.10.22; Mon, 17 Aug 2020 15:10:45 -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="ur3/lf9C"; 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 S2388572AbgHQQjI (ORCPT + 99 others); Mon, 17 Aug 2020 12:39:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:45160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730789AbgHQP5k (ORCPT ); Mon, 17 Aug 2020 11:57:40 -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 D64532173E; Mon, 17 Aug 2020 15:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679859; bh=/omsBwg8Yyncdrw92Temo+2BdmMOicqXhOUwneH6NX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ur3/lf9CmT+nl0GCru1ad3PFxd+7QPc1tlRTSiMBeGRAO3uXsZsIQqxzv5a0qwzxP RmO+k1WaQgHrPwGDbjuJ4VVI+xKSx5iBZyjYk+TPSJUFlGbSujREVAr5SNUl1rNHLa F4rkBdKIbLBXgLdoUgDUxjmy6sOHfHK8T4KD8SfI= 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.7 328/393] vsock: fix potential null pointer dereference in vsock_poll() Date: Mon, 17 Aug 2020 17:16:18 +0200 Message-Id: <20200817143835.506412482@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@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(