From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C85CD44AB60; Tue, 21 Jul 2026 21:24:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669067; cv=none; b=R0nRBRFBLEet1H6Ga9Jf3SbEgAzxB2dc/LvpiBomYjs05z0WFyXNIu10OUTgvY/5XytmTETu9fxqf43nEzt7D3lOWsKmNvBHJOEUV5WiqsxyYhrq03+mVyvq6lddi6O24KRpE6tzki5yJDcstiZTLF44ONTaxEQOyXw0SSPx8fQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669067; c=relaxed/simple; bh=Yrx7rceoxQR0CPEQORrfnGRX5w29ljHG7Dex71uXuJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UOw6DWcBkXnwVLd+TMbCJvNUZr/1VTSe2ZY43CGKInQNPUnJt/lXBay0FnD27Hr8iIRyrvCSCTTSmflMRc+Nwxjwaojcz+BYtco0fANR8b01aon8K5aWVlwOWuriY6jhP/ia61ZczcKX446IuMZTVWeBriGLf8+KSzTk7MJqHwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RqQKcsUy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="RqQKcsUy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDCA51F000E9; Tue, 21 Jul 2026 21:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784669066; bh=MD6PY5XdL4efNbrt/0rdGw+c3lzm6VHC6ZozSj4Rfss=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RqQKcsUyJPW2KhJqikISur88h3u2e9x7fXA4PtzeaSKt/Eyt8CoBkipzJWsxjaym7 HGoMHNdBcpzXFr5AHwLLZiGhxFhnAbhOnnzSCCMQfkwkJHtaaazCM01x6DZaQi3Z+A eXPhaUqVDfc+shz/fAHmIKjfJBrlT/eBqCO/TP0c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qihang Tang , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 6.1 0413/1067] vduse: hold vduse_lock across IDR lookup in open path Date: Tue, 21 Jul 2026 17:16:54 +0200 Message-ID: <20260721152433.866127227@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qihang Tang [ Upstream commit e440e077748939839d9f76e24383b76b785f80ce ] vduse_dev_open() looks up struct vduse_dev through the IDR and then acquires dev->lock only after vduse_lock has been dropped. This leaves a window where a concurrent VDUSE_DESTROY_DEV can remove the same object from the IDR and free it before the open path locks the device, leading to a use-after-free. Close this race by keeping vduse_lock held until dev->lock has been acquired in the open path, matching the lock ordering already used by the destroy path. Fixes: c8a6153b6c59 ("vduse: Introduce VDUSE - vDPA Device in Userspace") Signed-off-by: Qihang Tang Signed-off-by: Michael S. Tsirkin Message-ID: <20260508094659.94647-1-q.h.hack.winter@gmail.com> Signed-off-by: Sasha Levin --- drivers/vdpa/vdpa_user/vduse_dev.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 0ccece3f4f7da8..abc35be6e0df9e 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1296,26 +1296,18 @@ static int vduse_dev_release(struct inode *inode, struct file *file) return 0; } -static struct vduse_dev *vduse_dev_get_from_minor(int minor) +static int vduse_dev_open(struct inode *inode, struct file *file) { + int ret = -EBUSY; struct vduse_dev *dev; mutex_lock(&vduse_lock); - dev = idr_find(&vduse_idr, minor); - mutex_unlock(&vduse_lock); - - return dev; -} - -static int vduse_dev_open(struct inode *inode, struct file *file) -{ - int ret; - struct vduse_dev *dev = vduse_dev_get_from_minor(iminor(inode)); - - if (!dev) + dev = idr_find(&vduse_idr, iminor(inode)); + if (!dev) { + mutex_unlock(&vduse_lock); return -ENODEV; + } - ret = -EBUSY; mutex_lock(&dev->lock); if (dev->connected) goto unlock; @@ -1325,6 +1317,7 @@ static int vduse_dev_open(struct inode *inode, struct file *file) file->private_data = dev; unlock: mutex_unlock(&dev->lock); + mutex_unlock(&vduse_lock); return ret; } -- 2.53.0