Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp821719pxu; Wed, 2 Dec 2020 04:27:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxL7vohltoqx89aGLd8ZI7IeL8lTmpbg7Y6B3nGR+ugqOYqTJ14C3sWr87p7zTRSAHzwcDk X-Received: by 2002:a17:906:bc9b:: with SMTP id lv27mr1951697ejb.505.1606912079232; Wed, 02 Dec 2020 04:27:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606912079; cv=none; d=google.com; s=arc-20160816; b=cjyJQIzze9dRlJP23Hv4qqJ8NDFL4rHqGyUyvrbV/+464p2paCzYn046icubGefOdt Op5lsr3mdFbH8gDm+Z/FbdiCzFxgN4NMGGWjnfQKsah5EPdCCHvrefSXDh5pX/JdvUgk NDIkQ0bJ2/zKtgBvf3MytHw3m3r4mM0Yu7rutmiyrrmS59LDQfHUu53GKVPDF70XGLfx PEjrHbEAzQ5WpgQ1pdz0G2GxT9wMLzgriN5h2ZmDO7DVqG89YlvWWAYeAXMQOjTm/Tq8 QxR1gWo4rtQ6C9U0V6JkmM2iMi8d3S5kay3qHJBISMBGaz8kveb/BbqutksIzHtNM9UQ g/xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=p9yZnJwUyGYJWXufZN6mWISbIVmm/nLFQLYOSV6Egd8=; b=JZDBCxE5GsFQVEEsjMginSEKMhIMnDUchCyE0SNBBlOQkiISpw95Dh7m/NpKq5Xi6z S1S+kChBb8QVIU5XI6b8nTR7haj5wNHumy75rcH5T86jJzyGy8RF0A8pr6+S9NzMtoFp Vz7Xo8ZU7WhhRLC1MWFUPe7p84fYoJAiyf/wOYW/fSfYv8xKnmkBPhdYdXqcn/LbIPFu 0S4kbtfuBlkDNjsziHmdxOQm2sqCji3uNQwnGNtoKYfeDIo1ry7cBj3PfTcsza2ZNcNw p6XTJOOt1zG+0Xxmioxj/IGmIQqBJwA9x3fbTjed37QFne7foXQz5bY8tX5ERG7IRrxc Cp1A== ARC-Authentication-Results: i=1; mx.google.com; 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 k23si828678ejk.626.2020.12.02.04.27.35; Wed, 02 Dec 2020 04:27:59 -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; 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 S1727614AbgLBMXp (ORCPT + 99 others); Wed, 2 Dec 2020 07:23:45 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33755 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbgLBMXo (ORCPT ); Wed, 2 Dec 2020 07:23:44 -0500 Received: by mail-wr1-f68.google.com with SMTP id u12so3723039wrt.0; Wed, 02 Dec 2020 04:23:22 -0800 (PST) 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:user-agent; bh=p9yZnJwUyGYJWXufZN6mWISbIVmm/nLFQLYOSV6Egd8=; b=JW7PUlZXGi8+MUpZeRe6f4wkIqyvrAbgO5iNVIP5Ozg3qZb0vK/XrZupLF7hm1moPD Cg7QoLlRNkXOh6CWrOOnoUy88mjnEvift6LhN6svRkDVKse+A+JLY9IbN+UhuaXemPNk JGDfNB19T3uebZ1w32Cn7buhU6E9qR+RxV+/5yoTKxuDMdhoJra9hJLZXPMNvXmxekrU DDcxohc0swI8qkeUI5qsMUv86YreEE8+aHR0XzW5Op3AqINElJR2fGUc51a9GesQc4Fg C001R+NNjBQN2b8LdwTbKEBHYpbG8whY7GdoKEsazh/+GAhZJ7K1dakRncezF/DS3Jz2 RoiA== X-Gm-Message-State: AOAM531fILkcvtZKufd3/tzugW3KULCaCpUiCenrGnWwRkDiOupmC9uT 1ZVuaGufhLLJclTcp2GAbD8= X-Received: by 2002:adf:e787:: with SMTP id n7mr3176959wrm.153.1606911776720; Wed, 02 Dec 2020 04:22:56 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id g78sm1814572wme.33.2020.12.02.04.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 04:22:56 -0800 (PST) Date: Wed, 2 Dec 2020 12:22:54 +0000 From: Wei Liu To: "Andrea Parri (Microsoft)" Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Michael Kelley , Juan Vazquez , Saruhan Karademir Subject: Re: [PATCH v2 2/7] Drivers: hv: vmbus: Avoid double fetch of msgtype in vmbus_on_msg_dpc() Message-ID: <20201202122254.zjhu3cfcq3zwvmvu@liuwe-devbox-debian-v2> References: <20201202092214.13520-1-parri.andrea@gmail.com> <20201202092214.13520-3-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201202092214.13520-3-parri.andrea@gmail.com> User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 02, 2020 at 10:22:09AM +0100, Andrea Parri (Microsoft) wrote: > vmbus_on_msg_dpc() double fetches from msgtype. The double fetch can > lead to an out-of-bound access when accessing the channel_message_table > array. In turn, the use of the out-of-bound entry could lead to code > execution primitive (entry->message_handler()). Avoid the double fetch > by saving the value of msgtype into a local variable. > > Reported-by: Juan Vazquez > Signed-off-by: Andrea Parri (Microsoft) > --- > drivers/hv/vmbus_drv.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c > index 0a2711aa63a15..82b23baa446d7 100644 > --- a/drivers/hv/vmbus_drv.c > +++ b/drivers/hv/vmbus_drv.c > @@ -1057,6 +1057,7 @@ void vmbus_on_msg_dpc(unsigned long data) > struct hv_message *msg = (struct hv_message *)page_addr + > VMBUS_MESSAGE_SINT; > struct vmbus_channel_message_header *hdr; > + enum vmbus_channel_message_type msgtype; > const struct vmbus_channel_message_table_entry *entry; > struct onmessage_work_context *ctx; > u32 message_type = msg->header.message_type; > @@ -1072,12 +1073,19 @@ void vmbus_on_msg_dpc(unsigned long data) > /* no msg */ > return; > > + /* > + * The hv_message object is in memory shared with the host. The host > + * could erroneously or maliciously modify such object. Make sure to > + * validate its fields and avoid double fetches whenever feasible. > + */ > + > hdr = (struct vmbus_channel_message_header *)msg->u.payload; > + msgtype = hdr->msgtype; Should READ_ONCE be used here? Wei.