Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp271172img; Mon, 18 Mar 2019 02:46:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPfFbM+pogwE88ONSNfG7J2PY6sasO9vQhwkw2DAQnPFelDEhMWRw/87/V8b8LdA69yRLG X-Received: by 2002:a17:902:d715:: with SMTP id w21mr18354325ply.14.1552902401416; Mon, 18 Mar 2019 02:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552902401; cv=none; d=google.com; s=arc-20160816; b=p9ameJED2VaAHtnomGCBFU5aDvsH8m11Q8YJyzlPJUBQM94fwyi17iRSoMRqf5HnBr gWswONvShIJqOM2XwywPmcyi20zMTvOvhUyBMSrtWgV8gQ59KxWADO8yF44caVuYfFif Iiy+bolJmpXaffR+BGrhOr36+X+bJLpyu8PFNaEnakVAHliHMEwsTiM9LkwIEPq30Krf OanFr4W+d5k/I24TScQ7txNumvi6iTbE+tKwwYFSrb2FRogyF66uKh8i+6nfc16nRUSp EaDLSOyykgynOn/Wkm91M3PZSIKOLqZtvmZ0NhSNxi8kTuc9D8cG6tVG/MNhYr2+3BID wF1g== 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=ebFIDKtea/vvXOm7sfxkV2T+Nf2yIHXJL26Vxb3pqvE=; b=bDCbFlVGL6VVQflz/VRIEHvzI9XOUdbV/mDjD3za6sSuVPaeoRoT9FDibaYAxNGg8P uAG7t1iHP0uQfQBZwXWgEFp1GRW0WL0P0xA8tuDoqem9jeZFXhawEdRxdFuwj5Ph914W Q+1buzs48dVVEcwIxDei8+7+fjsvpP45hIlC14B3s/3la8dvwBecqAdEHsE5fd6CAJlq cvOY7ceV9UUQKWWNYxOr1RA29FIKb/Wg8K6K4XYibOrYa2avy9xY/ep5t0zEsw56XYa0 TQLJsLh1sFxulVkzTc8guVpLF/TeGGLfzAPo+Czl7zhZp2GyKqUjXMvl00a+ias2rsIE 3Bhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qkJq17kC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o7si8683388pgh.273.2019.03.18.02.46.26; Mon, 18 Mar 2019 02:46:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qkJq17kC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728028AbfCRJb0 (ORCPT + 99 others); Mon, 18 Mar 2019 05:31:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:38946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728168AbfCRJbW (ORCPT ); Mon, 18 Mar 2019 05:31:22 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 A24EB2087C; Mon, 18 Mar 2019 09:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901482; bh=+6+pyXTVuDkzZV0Q0wQADuekcAeHexVsRIAXln6cTn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qkJq17kCnWttQ/A9soMn9bkTClvNIeloKxdrq0gfQrmT02uIPGhYoiusWBM9QvzdI /+7OygsAiLRfyAw2mD0MCmwZZNXgNmXAw6A4qebUBs7s8FC+rObgjnsfnvfICT0AFh 5/MNWMFMFDaQqJ0xkPmHRfN7U7oRKeFJRVPssB0w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zha Bin , Liu Jiang , Stefan Hajnoczi , Jason Wang , "David S. Miller" , Shengjing Zhu Subject: [PATCH 4.20 52/52] vhost/vsock: fix vhost vsock cid hashing inconsistent Date: Mon, 18 Mar 2019 10:25:39 +0100 Message-Id: <20190318083849.999692539@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318083843.398913295@linuxfoundation.org> References: <20190318083843.398913295@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zha Bin commit 7fbe078c37aba3088359c9256c1a1d0c3e39ee81 upstream. The vsock core only supports 32bit CID, but the Virtio-vsock spec define CID (dst_cid and src_cid) as u64 and the upper 32bits is reserved as zero. This inconsistency causes one bug in vhost vsock driver. The scenarios is: 0. A hash table (vhost_vsock_hash) is used to map an CID to a vsock object. And hash_min() is used to compute the hash key. hash_min() is defined as: (sizeof(val) <= 4 ? hash_32(val, bits) : hash_long(val, bits)). That means the hash algorithm has dependency on the size of macro argument 'val'. 0. In function vhost_vsock_set_cid(), a 64bit CID is passed to hash_min() to compute the hash key when inserting a vsock object into the hash table. 0. In function vhost_vsock_get(), a 32bit CID is passed to hash_min() to compute the hash key when looking up a vsock for an CID. Because the different size of the CID, hash_min() returns different hash key, thus fails to look up the vsock object for an CID. To fix this bug, we keep CID as u64 in the IOCTLs and virtio message headers, but explicitly convert u64 to u32 when deal with the hash table and vsock core. Fixes: 834e772c8db0 ("vhost/vsock: fix use-after-free in network stack callers") Link: https://github.com/stefanha/virtio/blob/vsock/trunk/content.tex Signed-off-by: Zha Bin Reviewed-by: Liu Jiang Reviewed-by: Stefan Hajnoczi Acked-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Shengjing Zhu Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vsock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -642,7 +642,7 @@ static int vhost_vsock_set_cid(struct vh hash_del_rcu(&vsock->hash); vsock->guest_cid = guest_cid; - hash_add_rcu(vhost_vsock_hash, &vsock->hash, guest_cid); + hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid); spin_unlock_bh(&vhost_vsock_lock); return 0;