Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp437534pxb; Wed, 24 Feb 2021 06:17:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwu5hk4tds4V+9RxsKXfS8imCk0PIYP+o3c1GRxLVNLd3YDLzRU4WGGsHLQRZ2ZAHFwdWp+ X-Received: by 2002:a17:906:b082:: with SMTP id x2mr30241585ejy.100.1614176276175; Wed, 24 Feb 2021 06:17:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614176276; cv=none; d=google.com; s=arc-20160816; b=jnT9itqGU9vVtWi5amzLDxC3HKkNspxxSzs7b3Dq0XaFfRCAg6Rh6pVvTJiz4dGorN f6JFnQL/iCUgEjJyfJdIZu+taLITmpEzc3BBfc+RJYJKN2PlZf7mghdoz0iwuD9BQX1n VqDRc9vG6B6jGXtDHRv91g+nzBAaTVwdDia168fH6IBxXO4qOWMbmGd6jI9kjqs6bY/d Opg2LEZX5BDymRyKe5SNW7cny55Nn3Hy8Mr8dIBkJu16T30vuZ/7QO+7d3YBtpZa61/d S3OOev/M0op3Xqll1BxDHgh6fRfDw1B3KkSWcxT4mivJYD9eKg6pni1yrr9/OHlSOnZj WUHA== 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=nUF2uDXU0kig4Aci17Kp46rXrg79/mPYsUNa1wqZeC0=; b=PbE2pIQYzA/TuG0an+JekyWdfBy06EsIke5CihcyOvVxWboxklCDo19cQUz2LAEPRi P8sYFUCMMyVKhPFZdKQ3Sk6jtCQx0czg6LwYOZjc3I7behiNDS+xWi2fkvZuIyoJ5I+d IZt5zhbskwHa0jdvjHFie5KnAHk2ommnHvB1VuAhD4kXvNDqLSlHWHdhHIVOffbQspPO FVKpN2e7Ia4GjIYtvAV6wNaZOh/Jvk3tsxV1dMY6jTldGaJlCiW8sKERV5c+yiK8Egk6 z75MhbS951FWfnMlTPWUuABnG7i4OOmYvr7XkD+gk85owp11uhq6sogI2b4hyefZ1IBU lz0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ix82ElRv; 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 h28si1214674edj.309.2021.02.24.06.17.16; Wed, 24 Feb 2021 06:17:56 -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=ix82ElRv; 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 S235572AbhBXONm (ORCPT + 99 others); Wed, 24 Feb 2021 09:13:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:59130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233136AbhBXNKj (ORCPT ); Wed, 24 Feb 2021 08:10:39 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD2DD64F11; Wed, 24 Feb 2021 12:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614171302; bh=8vUotaZ9PS8Rw6qxPntNdQtu1ucj2oPPA0Ltl1E0x7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ix82ElRvHjEgkpeDWflNuItG1cxHOPihLPRJMtwfrLzqOj1HlTQ5xmQi8xR4/a9Ny 8RJBg7PiH77AzZdRf9Q8+6m7kl5lhcAkBAki3uF6pgnxvJSeMAkMfGCWT9xal9BHDb 6rcOLTrwVHIdKS4jd+FVRRSMRZiY/kllNxnUicve87roADKT1digO81P5W4gtbhslU SshuyDB3YSITgoUNlU57Prmwew29z+ZFCCHPxxFoJ8lZOlJcTBoEGCBppboCV+F1pD asTC6QNxL3q5la5kPbvIoA/OJpIbaIpm2QsBriKGGGiGKSLRhZBNWuNmjFQUJrMmwF WlBnLEJlOdbMA== 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 4.19 21/26] Drivers: hv: vmbus: Resolve race condition in vmbus_onoffer_rescind() Date: Wed, 24 Feb 2021 07:54:29 -0500 Message-Id: <20210224125435.483539-21-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210224125435.483539-1-sashal@kernel.org> References: <20210224125435.483539-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 7920b0d7e35a7..1322e799938af 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -954,6 +954,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 35461d49d3aee..59525fe25abde 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -736,6 +736,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