Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp405871pxb; Wed, 24 Feb 2021 05:33:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1XjgzWlM936uLTF07uc6vWb/srz8aEkOHeYQTNmI0Ws3HG9OuO/GfD733w6tZ21tvvZyh X-Received: by 2002:a17:906:584e:: with SMTP id h14mr14836281ejs.332.1614173596894; Wed, 24 Feb 2021 05:33:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614173596; cv=none; d=google.com; s=arc-20160816; b=a8ZYIiejsG5OjIHSzActxvGZKSPEMF9VXsrXXbSdBcDu9v8fvauNnBig8rhJ5KtYgN YOsGI/l4kxddCCXJS068gcGw01N2cRH0Bx+7hz1kmjyjRo7Lf7eweSRktUjHCGSMEVjI xU2XcUizoE2mLDvrCvJlFcj2NiIxBiDJZSc0vxWss24jdoMEu/ntFxdCr1VJqy2yx23g PLP97gC/XuhT31ubS3IuDQenqZGZcgOl9S8Ml3RDRdsu78XOCzEsCsz5IaENynCXH1My hOwE5aFkFrAE4upVB4cKWnHJt/QqGSBzilZKB3z6Y0c3kwa5h6mQL9iAhFi+rX8LP2JC gpMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ICe1wBhwy3qLW9tUKOvLHee+KfIwPp1t17nJyvvbM+s=; b=X53maViJ1lvF7qbfgiN1A4NkSpBD6FkcV2hMoptpvwBLHAd5+I3iS7oNWkPZm+wvuf sQrLuGd/iDRzqRMKA672fU7I7OXoFeJAfLDAT5sqJUn06zejinEomBciHTf6UJhrCceE Vq9VZ3mGTmOFWezISXUWokglsKqC0KgylCA5nf9Bc4VnnKk+ZFxs3Y2fJL5/q8fUprMJ GKfRDaUqhVdlp6aBMWx9WcA23do4IVFzPRr35HCmtPR503yG9pJpNUqhzBFjxE8vpS2+ qYOOIz6urOghQOJ7OrJmblQ3jV1zLhT3Kao7uAerYz0uzMVVeATAKUjxC6sBZqqdwRKv J9XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D+8ViXWF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si1366453ejd.325.2021.02.24.05.32.38; Wed, 24 Feb 2021 05:33:16 -0800 (PST) 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=k20201202 header.b=D+8ViXWF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236395AbhBXNPd (ORCPT + 99 others); Wed, 24 Feb 2021 08:15:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:50964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235383AbhBXMzP (ORCPT ); Wed, 24 Feb 2021 07:55:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 53EBE64F28; Wed, 24 Feb 2021 12:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614171095; bh=Fn6YAi8zgAWN+WkPtNaPdtHJ1LXY07YIlxsNSmf1YlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D+8ViXWFzX8uRLInr0VDzSrIiILEthzEIPbyzRuqOQHMLBPepAEXgHftGYhcHzc9U 8kIIuyIIm7i3ZlDmedMHkVacJyijiafbFuxMmBaDD9HWW6Zt4L/x5WZAQ/M+gFriDY D1uvlNbBkIftgr3S5PNfyK2YTHG63AyFq0O1HXQffKr8bdR7phPfBy7UmJlBDN8ZWX Z78Iw9py7xWjvGaTB+bW/H6H+jN1/iZRYiqTCjPj+tGI5PAVeT5F5BvHog0nD3u6tv tiIffUvYRkbJ/wDaatw384UbS69P+ar2+ENnbg2y6ICMLjyRNiIKDOaFUzmblHYrtd 66XfctZelZRpA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Andrea Parri (Microsoft)" , Juan Vazquez , Michael Kelley , Wei Liu , Sasha Levin , linux-hyperv@vger.kernel.org Subject: [PATCH AUTOSEL 5.11 51/67] Drivers: hv: vmbus: Resolve race condition in vmbus_onoffer_rescind() Date: Wed, 24 Feb 2021 07:50:09 -0500 Message-Id: <20210224125026.481804-51-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210224125026.481804-1-sashal@kernel.org> References: <20210224125026.481804-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Andrea Parri (Microsoft)" [ Upstream commit e4d221b42354b2e2ddb9187a806afb651eee2cda ] An erroneous or malicious host could send multiple rescind messages for a same channel. In vmbus_onoffer_rescind(), the guest maps the channel ID to obtain a pointer to the channel object and it eventually releases such object and associated data. The host could time rescind messages and lead to an use-after-free. Add a new flag to the channel structure to make sure that only one instance of vmbus_onoffer_rescind() can get the reference to the channel object. Reported-by: Juan Vazquez Signed-off-by: Andrea Parri (Microsoft) Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/20201209070827.29335-6-parri.andrea@gmail.com Signed-off-by: Wei Liu Signed-off-by: Sasha Levin --- drivers/hv/channel_mgmt.c | 12 ++++++++++++ include/linux/hyperv.h | 1 + 2 files changed, 13 insertions(+) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 1d44bb635bb84..a9f58840f85dc 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1049,6 +1049,18 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) mutex_lock(&vmbus_connection.channel_mutex); channel = relid2channel(rescind->child_relid); + if (channel != NULL) { + /* + * Guarantee that no other instance of vmbus_onoffer_rescind() + * has got a reference to the channel object. Synchronize on + * &vmbus_connection.channel_mutex. + */ + if (channel->rescind_ref) { + mutex_unlock(&vmbus_connection.channel_mutex); + return; + } + channel->rescind_ref = true; + } mutex_unlock(&vmbus_connection.channel_mutex); if (channel == NULL) { diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 5ddb479c4d4cb..ef3573e99d989 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -803,6 +803,7 @@ struct vmbus_channel { u8 monitor_bit; bool rescind; /* got rescind msg */ + bool rescind_ref; /* got rescind msg, got channel reference */ struct completion rescind_event; u32 ringbuffer_gpadlhandle; -- 2.27.0