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=1796384564; b=4rfJ3+s4o3gSsSsv4X5MhlC6jeYeZl3yZFYeekMQeSm8dhCsrBtIF42DmDeqkfmkxajZ ssKlfFjPHFd1Cf1U3p4r+IOf1s6ggRrD6j3ppfYOfRlTwT6oowL1AZ/fTnQDcK2oAi875 cOnzNkTMuxy8/HbsCVZD4ySoBIfEUrSp3iK12ga+BvBmqbtXTc/oZJYoIbywBTADHlO63 oCU2ZMC1ZlDTTYqewc74pdPby0teEuFKfk1iJJl+tOMzoGwmN1bRuFmnMciq4rkwMmgKD NXnqedgaVLkVmlS6T/rBEtdECxWkaTL+IryT8a1rCHBLbdSIZD+2sFOt9nY4/CHhGYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384564; 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=vujU2q7dG1MwSk/ELAtvxaHVQtpSsgIZUDJwf+D7kWE=; b=YNH+S6OD+16dFybRtJ94dHiBehyOnjDrXjUmTiEFD9uIJiKRhyA504ch5BBkI1ZB/rSC XsUn7HCRutm2GcpDAO+7VXgDSju/psx9FzBWoWKkZid+NQfe7dCRAS0jjR0DXU8GC3JWi aTwIqSHUTE4KoWNTnKiUActZ5KdhCnJ4V7JmY5w9JYvAMuA1pYg65DKa7lZkWfYKKS18M oqZSilBYlZeNbaesHAsAsiTZ8DykpQYLx2YheuoMWvyYfltqpyNgjqaRjIwilIXRg1o/W dwXkmz/ZzMkuZLhDBZaSu/DnajGbWufa1I5tzieLnTxiHurN8hy/f8QQDbWXmTQJLnw== 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="rQE/nL0H"; 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 44C95606A32F; Fri, 4 Dec 2026 11:42:44 +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=rQE/nL0H Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4E461F000CE; Fri, 4 Dec 2026 11:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384564; bh=vujU2q7dG1MwSk/ELAtvxaHVQtpSsgIZUDJwf+D7kWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rQE/nL0H3TMUPh/u45vXCjmODNzc0FPVE8HMkwsMNmO5w9w6Nz27D3cL1XpXHKfq1 4gceS/uqrHFj32hPum9XsBkbAgcIlnHfvortuwt/O7oWrhMfqIoVZ6ivH7MMncvXHe pqyGoJT6jzuWkJMRq4qj8acUwCMPzE2CxXPBOGhw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Eric Dumazet , Kuniyuki Iwashima , Paul Moore , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0204/1167] calipso: do not charge request socket options to the listener Date: Fri, 4 Dec 2026 18:53:51 +0900 Message-ID: <20261204100707.380866636@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit b4a2cc6d748d3056a25812dcf5f5377a59afd02f ] calipso_req_setattr() and calipso_req_delattr() allocate ireq->ipv6_opt with ipv6_renew_options(), which charges the listener sk_omem_alloc through sock_kmalloc(). tcp_v6_reqsk_destructor() frees ireq->ipv6_opt without uncharging it, so each request socket leaks its options size from the listener budget. Once sysctl_optmem_max is reached, sock_kmalloc() fails, calipso_req_setattr() returns -ENOBUFS, and tcp_v6_route_req() drops all subsequent SYN packets. __sk_destruct() also reports an optmem leakage when the listener is destroyed. Uncharging in tcp_v6_reqsk_destructor() would not be correct: after a migration, req->rsk_listener is no longer the socket that was charged. These options belong to the request socket, there is no reason to charge them to the listener. Change ipv6_renew_options() to use kmalloc() when its sk argument is NULL, and use this from calipso_req_setattr() and calipso_req_delattr(), like cipso_v4_req_setattr() which uses kzalloc(). Note: After this patch, calipso_req_setattr() and calipso_req_delattr() no longer need the listener. Commit 10876da918fa ("calipso: Fix null-ptr-deref in calipso_req_{set,del}attr().") could be reverted in net-next (also removing the then unused sk variables), so that CALIPSO works with SYN cookies. Fixes: e1adea927080 ("calipso: Allow request sockets to be relabelled by the lsm.") Reported-by: Sashiko Closes: https://lore.kernel.org/netdev/179378292255.488856.6917577451813010963@kernel.org/ Signed-off-by: Eric Dumazet Cc: Kuniyuki Iwashima Cc: Paul Moore Reviewed-by: Kuniyuki Iwashima Acked-by: Paul Moore Link: https://patch.msgid.link/20261104150318.1156620-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv6/calipso.c | 12 ++++-------- net/ipv6/exthdrs.c | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c index 60f921edbc71b..3a994a0331805 100644 --- a/net/ipv6/calipso.c +++ b/net/ipv6/calipso.c @@ -1223,7 +1223,7 @@ static int calipso_req_setattr(struct request_sock *req, if (IS_ERR(new)) return PTR_ERR(new); - txopts = ipv6_renew_options(sk, req_inet->ipv6_opt, IPV6_HOPOPTS, new); + txopts = ipv6_renew_options(NULL, req_inet->ipv6_opt, IPV6_HOPOPTS, new); kfree(new); @@ -1231,10 +1231,8 @@ static int calipso_req_setattr(struct request_sock *req, return PTR_ERR(txopts); txopts = xchg(&req_inet->ipv6_opt, txopts); - if (txopts) { - atomic_sub(txopts->tot_len, &sk->sk_omem_alloc); + if (txopts) txopt_put(txopts); - } return 0; } @@ -1264,14 +1262,12 @@ static void calipso_req_delattr(struct request_sock *req) if (calipso_opt_del(req_inet->ipv6_opt->hopopt, &new)) return; /* Nothing to do */ - txopts = ipv6_renew_options(sk, req_inet->ipv6_opt, IPV6_HOPOPTS, new); + txopts = ipv6_renew_options(NULL, req_inet->ipv6_opt, IPV6_HOPOPTS, new); if (!IS_ERR(txopts)) { txopts = xchg(&req_inet->ipv6_opt, txopts); - if (txopts) { - atomic_sub(txopts->tot_len, &sk->sk_omem_alloc); + if (txopts) txopt_put(txopts); - } } kfree(new); } diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 0f9d8119b34c6..7b679c8fa3650 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -1286,7 +1286,7 @@ static void ipv6_renew_option(int renewtype, * not copied into the new set of options. * * The new set of options is allocated from the socket option memory - * buffer of @sk. + * buffer of @sk, or with kmalloc() if @sk is NULL. */ struct ipv6_txoptions * ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt, @@ -1314,7 +1314,8 @@ ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt, return NULL; tot_len += sizeof(*opt2); - opt2 = sock_kmalloc(sk, tot_len, GFP_ATOMIC); + opt2 = sk ? sock_kmalloc(sk, tot_len, GFP_ATOMIC) : + kmalloc(tot_len, GFP_ATOMIC); if (!opt2) return ERR_PTR(-ENOBUFS); -- 2.53.0