From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383217; b=3uT8gAb6oSX442671IFyINIyNc2Mym86Zy1udC6mKrILWt6lwqshYFme5VlEKg9UEoHP 2a3t9d0k5TMdFF1iuAW7gJIQ4C/JyDB59MCaz47WaJPXd460BfKannqjiEQ4pM3wUI3sj 6YAS/X1aiEH0BE5gYP0G3JUhgIBOY/7zUceO8F6rzN5QIz/craXzWdoB5LiilpTQp37sW vPRsGU/iisPB51YcGMNLX5rkkEUOlbKGaxp0BQVDu8+V3I1rzNAB/ZoAUf6JX9Jygxdyj nQ5x18HmVHkVvKYcA4TpXr+540yR4mSG+9rT2/Vhpy0y0nVDXw14ZBcz8N46o4lXfqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383217; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=6rVQLdsJhrCOLxKeNYW0JwahQucyFdaNAOeRc0YAXrA=; b=xk8xdKcujyiqKZzo56BzWMGV1tUKiSWJUa4qEZqfv322oz8Km02L3+CdcuRR7OTzliuk bWQ0kf/7tLbV/qNJG8xXcT4NPjKAbRbkDRMeANjSvsFfDgs2FFlsiFrOQndFMhM53C8/v oaz8iVuFuaidhu8Xtu4TALuX1XLeqJfz08TbrzHG5qsXMe3eVOurOxEYY0AGwC/oTpzOn SHTJg7MuouSyEwIy5FXr4RPN13vF9T/1jPnFGQQQ6D+inRGOhSb2bwxqVc/kcsCY15YUx Fp3y9utWLbs0fNJ581DgVJEFcZgBn+UlrAzgtumuBgNJYHQg7I/qrZJrQa1+BLtoHGg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="dfN3/cCk"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBC75606A32F; Fri, 4 Dec 2026 11:20:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=dfN3/cCk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 561FA1F000CE; Fri, 4 Dec 2026 11:20:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383217; bh=6rVQLdsJhrCOLxKeNYW0JwahQucyFdaNAOeRc0YAXrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dfN3/cCkS4018AqTEAgMz/7befgAmBsHXFaoMEBId45QAIfRdbGTNgHfPHxv9B5Gl xldQxom/lRpGZspytimhAfUxq0o6/Lh+kkanPwqQbIxr4j9BPDb2JDB02y12AdV8yU qlMybqj8zEwLWWp3B7+lzV/ObvjaudBn48LCYBKM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kuniyuki Iwashima , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12 091/555] socket: Print pf->create() when it does not clear sock->sk on failure. Date: Fri, 4 Dec 2026 19:02:14 +0900 Message-ID: <20261204100610.639364918@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kuniyuki Iwashima [ Upstream commit 4bbd360a5084d8f890f814327e1d9fbb1f0f6fa1 ] I suggested to put DEBUG_NET_WARN_ON_ONCE() in __sock_create() to catch possible use-after-free. But the warning itself was not useful because our interest is in the callee than the caller. Let's define DEBUG_NET_WARN_ONCE() and print the name of pf->create() and the socket identifier. While at it, we enclose DEBUG_NET_WARN_ON_ONCE() in parentheses too to avoid a checkpatch error. Note that %pf or %pF were obsoleted and will be removed later as per comment in lib/vsprintf.c. Link: https://lore.kernel.org/netdev/202410231427.633734b3-lkp@intel.com/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20241024201458.49412-1-kuniyu@amazon.com Signed-off-by: Jakub Kicinski Stable-dep-of: 82052e5b5ec3 ("netfilter: nf_dup: preserve guard across NFQUEUE reinjection") Signed-off-by: Sasha Levin --- include/net/net_debug.h | 4 +++- net/socket.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/net/net_debug.h b/include/net/net_debug.h index 4a79204c8d306..47f7a4a878b9f 100644 --- a/include/net/net_debug.h +++ b/include/net/net_debug.h @@ -149,9 +149,11 @@ do { \ #if defined(CONFIG_DEBUG_NET) -#define DEBUG_NET_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond) +#define DEBUG_NET_WARN_ON_ONCE(cond) ((void)WARN_ON_ONCE(cond)) +#define DEBUG_NET_WARN_ONCE(cond, format...) ((void)WARN_ONCE(cond, format)) #else #define DEBUG_NET_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond) +#define DEBUG_NET_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond) #endif #endif /* _LINUX_NET_DEBUG_H */ diff --git a/net/socket.c b/net/socket.c index b63029bfdee92..63d4acccb5f2c 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1561,7 +1561,9 @@ int __sock_create(struct net *net, int family, int type, int protocol, /* ->create should release the allocated sock->sk object on error * and make sure sock->sk is set to NULL to avoid use-after-free */ - DEBUG_NET_WARN_ON_ONCE(sock->sk); + DEBUG_NET_WARN_ONCE(sock->sk, + "%ps must clear sock->sk on failure, family: %d, type: %d, protocol: %d\n", + pf->create, family, type, protocol); goto out_module_put; } -- 2.53.0