Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp456707pxb; Wed, 24 Feb 2021 06:43:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbSHtBjFHI9unmEEx0XuHZ3NlB5TOvtjGmepzNd2KiKUq3gw45rgwMfWWBjcfPbQlPuMRX X-Received: by 2002:a17:906:681a:: with SMTP id k26mr17666299ejr.450.1614177833352; Wed, 24 Feb 2021 06:43:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614177833; cv=none; d=google.com; s=arc-20160816; b=j59BUl8uv+GwAWvYtIaLs9HOoWrY9rH0xqsriObB3FbMPsBMBPClEh3haO6SLjnDw8 95M8a2Uoedwdyr0iWyAnljbVj51sCuPEP9nU767IGOUUzVD7rPCwNHcAkzprmEbHUXJs 5+dtKHxwqsTZawmVV1OTpq+7o2FXDZmlWjOYdMfSiA0C5Rj/5A6SoGrszUgzGepgG/B7 9GJYQSPEry0U24htflPChYYF3QPgu34AHyEl2FK7ilbQm7XWfn4kEQhyUYirLdGkqscf 83UR9yhDWzLDNSlN8hpm5VBauX7JEN8hqgDBiQipykHUYyAJaJurNPpY1G1+1tgISqw2 GnLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WDf8bNlXwDREMw2fYtgvyNKs51Rez3p9DgY25iabkKk=; b=sCz8x31ENhMhHszDmMsoFeRCkRjtFydF1ajm4/kkqeFsP5nhuqTGZPe96koROE7woT eWCdMW92OKZX+tefY11wyxcfs6vhC9Qu3kNz/1GKnvphznUztjXgCbUaYb4KhqKKUCJw Su6S7yTXzBKADLiHLd2axxLl0gv+AcSwrSuVQKUxLLhAVA6m8N4xgIYoeC0qcgPMcsQo WqIwym25oSgWzUsR5AwgOxxS18AF5UBO7lZpH3/ujdGcFkF3nlfg0m4igy6pZ/xlOJux Jt/18+y9EreKOafTclIhejT3ctbM5v9T+9kU2oox2V+BkHYElyfcXEKFvsgxevFoOmMo MVXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UbthsDrf; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g21si1269655edb.12.2021.02.24.06.42.45; Wed, 24 Feb 2021 06:43:53 -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=@gmail.com header.s=20161025 header.b=UbthsDrf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237644AbhBXOjY (ORCPT + 99 others); Wed, 24 Feb 2021 09:39:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbhBXNWX (ORCPT ); Wed, 24 Feb 2021 08:22:23 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B918BC06174A; Wed, 24 Feb 2021 05:21:41 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id r17so2968924ejy.13; Wed, 24 Feb 2021 05:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WDf8bNlXwDREMw2fYtgvyNKs51Rez3p9DgY25iabkKk=; b=UbthsDrfAXxLG0Ih3qnLP3LLslxy/TACKjN/AnLLlOGJ1SlJbUB1a9xL6k9bKHtbeZ sK19xPjppJcRJYixSaTO7tDYKpxSmIzNM1m4GSQaVFCeLj7nupAC2zQLMQs9K5l5xL5R ZEdxS9/4hzM1pY5vKZ5rhfFmY42RK/aMCTucRM8LSksEXXT2gGEvI9Jobl2ssXs8OnVc hU3LBJpTbFwpUT4fpgwDzIFsU76GOX5kFxigh0LboXTyRIdX8IYpXevZsTxUzySfkbue DGcwKUFo9nlYtEmPXOHHju3kV/sFI85nfbxLoR+C5dCGPCK/WoOwyfBfbyj+g0g+wb/m IcUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WDf8bNlXwDREMw2fYtgvyNKs51Rez3p9DgY25iabkKk=; b=OCfmXr3lFGRisgCZpkoLaUyzyX7x5hczau4vW8IDaVanWTMuJHakwSUMF3WPfcO1aT xa2qLhXKfjfEecb3fEhCfT4zrLIlh8ORBxyJylECtwIgAysoLjlDiCqCrINCeCM17cgD 6ubcG5Tbk9097CReBVU9Fx1R6N6+Ea6EYjX5Nf2Q3sJf2AASh76kIvdFIT0Nfs42ubgp zmF9PDfxNRzT9rRuxHctNxr8YWpqze835DhOKuzQoge0qek+E8brDdZybLAkHgxbDFcJ wg0mRTC//YZ+gcIUhAkck+eLfZ0l8V8vNcWnCyrk7hvBQFbvTM8r9L4TqyUJnDv48djP 85lw== X-Gm-Message-State: AOAM532kPWnJohtJAV6LUKanea8dYXUdCU1mlP23CmOZyVA58dRqr6Wz KdLrWbtx9EyNYzOnCDodZpY= X-Received: by 2002:a17:906:e0cb:: with SMTP id gl11mr19837093ejb.87.1614172900384; Wed, 24 Feb 2021 05:21:40 -0800 (PST) Received: from anparri (host-82-59-6-76.retail.telecomitalia.it. [82.59.6.76]) by smtp.gmail.com with ESMTPSA id fi5sm1290151ejc.43.2021.02.24.05.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 05:21:40 -0800 (PST) Date: Wed, 24 Feb 2021 14:21:33 +0100 From: Andrea Parri To: Sasha Levin Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Juan Vazquez , Michael Kelley , Wei Liu , linux-hyperv@vger.kernel.org Subject: Re: [PATCH AUTOSEL 4.19 21/26] Drivers: hv: vmbus: Resolve race condition in vmbus_onoffer_rescind() Message-ID: <20210224132133.GA2031@anparri> References: <20210224125435.483539-1-sashal@kernel.org> <20210224125435.483539-21-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210224125435.483539-21-sashal@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 24, 2021 at 07:54:29AM -0500, Sasha Levin wrote: > 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 Same here. Andrea > --- > 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 >