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 396003B2D00; Tue, 21 Jul 2026 20:34:08 +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=1784666049; cv=none; b=bwSeWRyIrAN31Rf8Vi8lHQEJ41vmSsssN2lLDeWrNCIpu0ckh469IL8I1eAL2VUE/Zh74A34GlB8GIugKZO7ThdftHRdZNf3206DGXnRlfcZRAbyY4KiyJY8gX65pGscxcYvPcbmBt8BSyeLfm4FU/qyg3wGu6viqtLGLoH4okQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784666049; c=relaxed/simple; bh=GLsM5RnD3uj20IokXRi2GWpa0r+8y7BepzFSiOkflzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pXBupCMcEH6uDLk+MgBj0XxsLKob3yxAXiQwFyWA9MwaLJ2abC9c37lbGm8m+MX1UnYESpskfEWyYTgNxMEPRlQunwfmqGGQMaPWxRCIPnXowpWWdfnJjk+43prxY95EO67+6eRQ4AraBJ80U3y/PnvK4dIJ2w+x7PSJbP4ylhk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1PFGX3Le; 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="1PFGX3Le" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92E3D1F00A3A; Tue, 21 Jul 2026 20:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784666048; bh=oiwqNk2yd8frZvDraXwE0xOhRZ7RDjroht5JRQXk28Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1PFGX3Le+VsujqnRv94KKzeWeApjeg+ejkoDm4OC6I566GDE8Dnk1izpPu88NRWbY 4iXes8MMGIT8q36GogE05MVKFuQexEm/jy9tOmq3Xrh85QmROl+L4QBhOFwNU6xKas +nyBaRQ/k84Z81wc/qXZJbf9TZky7O54aXSypcWM= 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.6 0534/1266] vduse: hold vduse_lock across IDR lookup in open path Date: Tue, 21 Jul 2026 17:16:11 +0200 Message-ID: <20260721152453.810210123@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@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.6-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 d7bda179ef79f8..96edccd80663e1 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1395,26 +1395,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; @@ -1424,6 +1416,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