Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp423847pxb; Wed, 24 Feb 2021 06:01:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwREuV3zmzESBeESfI5gOPn8+XYco6FzITnVE77x3eLGnvHyJvM7GoIuKUN7YXODm1vnUdA X-Received: by 2002:aa7:cb49:: with SMTP id w9mr29705418edt.375.1614175315314; Wed, 24 Feb 2021 06:01:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614175315; cv=none; d=google.com; s=arc-20160816; b=inpA9iPHsNVQ6qG/uvtzgpAZVDUomPZxjdFAbnT6julSQX0vrGGq2ucJXygdwdZL/+ AlKXIWP4vjtiVDsNc+gU430GjoJWS5wcJjiKGiAv5YX3Sh6xM0fVE7AYxUfZcPPvAYGp ECbjdOeiDVUcIcBQyeaIMnk8ONzXvkrhARW7QREQrPRxnEN63mi1ZlsPB/9CM743BgX1 tbFzvyaFVKnrSAMpTQSoMSSKSO1aEaPlXMhEqfNfRpARdt8jj/hgXG5fFdE0QICckEGf 73Qv50YAjJO27XwRFFke867trMv9V1qBVzm3HyB9PTTemBKsY2UAE77m9V7V1aiDhlT3 TtpA== 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=YXajf/5s7nXYP85MOkekLW9kWuIKxhTE/FZ92otEBYc=; b=qHQW6pN8SZnyC/qxx3ze6IiTAMb43cFIBzBS2tvXM++UF5MNFjA4MQ3UDsVDkYyMFS AJnWLx5F8mWQgPc7e8kRIoUogurCX/XfpDdOOZ/sTbU5Xki6ifU5FpJZm48Ms+OAm74O 5Avn/VU5XZ5vNP8g8Yr9aR+ieGzNQv4IjE6f2cEPVuP82I2XNT5p4LAtphNqI/SypR9C gvRA5V3ozYIjaJoe1M6awBy9eLlgy3umluW+MUEuAgWh+2XXvHIpi378iRtJn89URrSJ t97DWHCTrKzRSatbmxBSwytd+OJkLz+2OGh7HhZ5eaemXBPjfZpWHUhvKC2E89Thvvcd hkqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BD3BoEIg; 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 a36si1187606edf.419.2021.02.24.06.00.57; Wed, 24 Feb 2021 06:01:55 -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=BD3BoEIg; 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 S238100AbhBXN62 (ORCPT + 99 others); Wed, 24 Feb 2021 08:58:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:58410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235787AbhBXNGw (ORCPT ); Wed, 24 Feb 2021 08:06:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AF2B664F7D; Wed, 24 Feb 2021 12:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614171260; bh=nKJ8bs6eZo5oG6d+iNK2SZm+nxCIR0ubWf8VjELzdZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BD3BoEIgeLEFYAkU70PLYHqrNC4P7B+eKLepezLTSBXoLWiaTE7sEuE0tvl1U2F2g EbwPJxQ7iUey5XufcWzm2jC6DUcxs98/h9n/mjWNSdT31dD2d/6OfsujDXL5gFSopm jzEtSKcg9B0ud40kQ5DNjUKdN8NOzatu1jfwu5+ZsSXT7m2VPgZnllOReZ5yfrZvQE 97j5HenfT1XcaHHUNCbD5mT8gWpjija4Xsr+2ZhOWVtMWHJxdcqzX7Ojfen8OJvsT6 uxHOnbSh3zpVpO70bI6/+sfnPf3vErtwzdNSL4OMUmLsgXg7Henfu4TdJ7+b3X09I4 wA56TY4Jrvh2w== 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.4 30/40] Drivers: hv: vmbus: Resolve race condition in vmbus_onoffer_rescind() Date: Wed, 24 Feb 2021 07:53:30 -0500 Message-Id: <20210224125340.483162-30-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210224125340.483162-1-sashal@kernel.org> References: <20210224125340.483162-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 452307c79e4b9..dd4e890cf1b1d 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1048,6 +1048,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 67d9b5a374600..51e2134b32a21 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -734,6 +734,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