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 CC5042E7379; Sat, 30 May 2026 17:39:57 +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=1780162798; cv=none; b=QOVu8jBFVV30AorqeOOJAkjFKndPBaXG3y1+9/Gjb4eCA2rcQq+GFmYxumNY8hiJ6athzaQ3VsYnn5XtSu2ZP4q15l68w5dLa2P9gQUV5Gr/yZoH9lQJAuB8wIBTaDIw+N6tUZnuYGMzwjlvD1/2bfN/bi6Lc2pnULrpouMwaJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780162798; c=relaxed/simple; bh=XI4SUBd5fCW65tlNS2iWC4A9SRs12qU2SjQre1B12Gc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q9D2IjvyGBwqg934s9TdtN8Ipve9oqhjQBdPQ+11+RdnUw5ZmE5VpkAs8/o9KspOOWsSiC8wc1bdlqyqvvru2DAs0Rmy5lJZ2EPtPXqOO1qos4wHp+7QF1uUV+woMts8J3Ff9xA4RL/7Ij4jwmQAeUXR/sj++9dJA97IXb7jtyw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YcokFxKh; 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="YcokFxKh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E10E1F00893; Sat, 30 May 2026 17:39:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780162797; bh=k1Uv7XvGkw1fvY1FrOds+Ns8rOwZxscmXwvxaWUuuaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YcokFxKhI0tO+pblWfY4X/XV+CDWfZbsznk3/o2Z2WNvN5Jg3xePXoASRI9p/b3xi 9Qsuq9nvKqB2+NVVHNJmCz7ANbCpGigUYmvaDzeR04aP6NqjqPAtbm9gzOuPvWZcIP W/GC0t1RmxCyAdLufs6TBQfFmvJm5cFZB9CryREA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yifan Wu , Juefei Pu , Yuan Tan , Xin Liu , Ren Wei , Jiexun Wang , Ren Wei , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 037/776] af_unix: read UNIX_DIAG_VFS data under unix_state_lock Date: Sat, 30 May 2026 17:55:51 +0200 Message-ID: <20260530160241.250206106@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160240.228940103@linuxfoundation.org> References: <20260530160240.228940103@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiexun Wang [ Upstream commit 39897df386376912d561d4946499379effa1e7ef ] Exact UNIX diag lookups hold a reference to the socket, but not to u->path. Meanwhile, unix_release_sock() clears u->path under unix_state_lock() and drops the path reference after unlocking. Read the inode and device numbers for UNIX_DIAG_VFS while holding unix_state_lock(), then emit the netlink attribute after dropping the lock. This keeps the VFS data stable while the reply is being built. Fixes: 5f7b0569460b ("unix_diag: Unix inode info NLA") Reported-by: Yifan Wu Reported-by: Juefei Pu Co-developed-by: Yuan Tan Signed-off-by: Yuan Tan Suggested-by: Xin Liu Tested-by: Ren Wei Signed-off-by: Jiexun Wang Signed-off-by: Ren Wei Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260407080015.1744197-1-n05ec@lzu.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/unix/diag.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/unix/diag.c b/net/unix/diag.c index 486276a1782ed..699fba7b7591d 100644 --- a/net/unix/diag.c +++ b/net/unix/diag.c @@ -25,18 +25,23 @@ static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) { - struct dentry *dentry = unix_sk(sk)->path.dentry; + struct unix_diag_vfs uv; + struct dentry *dentry; + bool have_vfs = false; + unix_state_lock(sk); + dentry = unix_sk(sk)->path.dentry; if (dentry) { - struct unix_diag_vfs uv = { - .udiag_vfs_ino = d_backing_inode(dentry)->i_ino, - .udiag_vfs_dev = dentry->d_sb->s_dev, - }; - - return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); + uv.udiag_vfs_ino = d_backing_inode(dentry)->i_ino; + uv.udiag_vfs_dev = dentry->d_sb->s_dev; + have_vfs = true; } + unix_state_unlock(sk); - return 0; + if (!have_vfs) + return 0; + + return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); } static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) -- 2.53.0