From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_RED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16FE1C43461 for ; Mon, 26 Apr 2021 07:49:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D88BA60FF1 for ; Mon, 26 Apr 2021 07:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232964AbhDZHuF (ORCPT ); Mon, 26 Apr 2021 03:50:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:56422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233385AbhDZHlr (ORCPT ); Mon, 26 Apr 2021 03:41:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4BBCE61364; Mon, 26 Apr 2021 07:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1619422739; bh=KRszy/i013GujNJoflbqZBSQ6qHoXX96rklqcJo6ZDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jGzP20nyos22I1IQa8yU6lqDlN4HKH2ijPqlR2bo1qP6PfqpqtPucQ9k3/rhU9Inp 1EpCHVEI+3jLOLsJANxPDKjAyIv3BxaNzfaqfoJb+WRC+J3vwf5PVlF/n9Rh8HT1K4 76ot2GAYxhdUSljFi3LlWR9NjNXQdy4d6jhcfuqE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xie Yongji , Jason Wang , Stefano Garzarella , "Michael S. Tsirkin" Subject: [PATCH 5.10 01/36] vhost-vdpa: protect concurrent access to vhost device iotlb Date: Mon, 26 Apr 2021 09:29:43 +0200 Message-Id: <20210426072818.838649279@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210426072818.777662399@linuxfoundation.org> References: <20210426072818.777662399@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie Yongji commit a9d064524fc3cf463b3bb14fa63de78aafb40dab upstream. Protect vhost device iotlb by vhost_dev->mutex. Otherwise, it might cause corruption of the list and interval tree in struct vhost_iotlb if userspace sends the VHOST_IOTLB_MSG_V2 message concurrently. Fixes: 4c8cf318("vhost: introduce vDPA-based backend") Cc: stable@vger.kernel.org Signed-off-by: Xie Yongji Acked-by: Jason Wang Reviewed-by: Stefano Garzarella Link: https://lore.kernel.org/r/20210412095512.178-1-xieyongji@bytedance.com Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vdpa.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -749,9 +749,11 @@ static int vhost_vdpa_process_iotlb_msg( const struct vdpa_config_ops *ops = vdpa->config; int r = 0; + mutex_lock(&dev->mutex); + r = vhost_dev_check_owner(dev); if (r) - return r; + goto unlock; switch (msg->type) { case VHOST_IOTLB_UPDATE: @@ -772,6 +774,8 @@ static int vhost_vdpa_process_iotlb_msg( r = -EINVAL; break; } +unlock: + mutex_unlock(&dev->mutex); return r; }