public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Zijian Zhang <zijianzhang@bytedance.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6 07/86] tcp_bpf: Add sk_rmem_alloc related logic for tcp_bpf ingress redirection
Date: Mon, 30 Dec 2024 16:42:15 +0100	[thread overview]
Message-ID: <20241230154211.995525816@linuxfoundation.org> (raw)
In-Reply-To: <20241230154211.711515682@linuxfoundation.org>

6.6-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Zijian Zhang <zijianzhang@bytedance.com>

[ Upstream commit d888b7af7c149c115dd6ac772cc11c375da3e17c ]

When we do sk_psock_verdict_apply->sk_psock_skb_ingress, an sk_msg will
be created out of the skb, and the rmem accounting of the sk_msg will be
handled by the skb.

For skmsgs in __SK_REDIRECT case of tcp_bpf_send_verdict, when redirecting
to the ingress of a socket, although we sk_rmem_schedule and add sk_msg to
the ingress_msg of sk_redir, we do not update sk_rmem_alloc. As a result,
except for the global memory limit, the rmem of sk_redir is nearly
unlimited. Thus, add sk_rmem_alloc related logic to limit the recv buffer.

Since the function sk_msg_recvmsg and __sk_psock_purge_ingress_msg are
used in these two paths. We use "msg->skb" to test whether the sk_msg is
skb backed up. If it's not, we shall do the memory accounting explicitly.

Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Zijian Zhang <zijianzhang@bytedance.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20241210012039.1669389-3-zijianzhang@bytedance.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 include/linux/skmsg.h | 11 ++++++++---
 net/core/skmsg.c      |  6 +++++-
 net/ipv4/tcp_bpf.c    |  4 +++-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h
index 062fe440f5d0..6ccfd9236387 100644
--- a/include/linux/skmsg.h
+++ b/include/linux/skmsg.h
@@ -308,17 +308,22 @@ static inline void sock_drop(struct sock *sk, struct sk_buff *skb)
 	kfree_skb(skb);
 }
 
-static inline void sk_psock_queue_msg(struct sk_psock *psock,
+static inline bool sk_psock_queue_msg(struct sk_psock *psock,
 				      struct sk_msg *msg)
 {
+	bool ret;
+
 	spin_lock_bh(&psock->ingress_lock);
-	if (sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED))
+	if (sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED)) {
 		list_add_tail(&msg->list, &psock->ingress_msg);
-	else {
+		ret = true;
+	} else {
 		sk_msg_free(psock->sk, msg);
 		kfree(msg);
+		ret = false;
 	}
 	spin_unlock_bh(&psock->ingress_lock);
+	return ret;
 }
 
 static inline struct sk_msg *sk_psock_dequeue_msg(struct sk_psock *psock)
diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index 846fd672f0e5..902098e221b3 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -445,8 +445,10 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
 			if (likely(!peek)) {
 				sge->offset += copy;
 				sge->length -= copy;
-				if (!msg_rx->skb)
+				if (!msg_rx->skb) {
 					sk_mem_uncharge(sk, copy);
+					atomic_sub(copy, &sk->sk_rmem_alloc);
+				}
 				msg_rx->sg.size -= copy;
 
 				if (!sge->length) {
@@ -772,6 +774,8 @@ static void __sk_psock_purge_ingress_msg(struct sk_psock *psock)
 
 	list_for_each_entry_safe(msg, tmp, &psock->ingress_msg, list) {
 		list_del(&msg->list);
+		if (!msg->skb)
+			atomic_sub(msg->sg.size, &psock->sk->sk_rmem_alloc);
 		sk_msg_free(psock->sk, msg);
 		kfree(msg);
 	}
diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index a7b5b160d107..f882054fae5e 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -56,6 +56,7 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,
 		}
 
 		sk_mem_charge(sk, size);
+		atomic_add(size, &sk->sk_rmem_alloc);
 		sk_msg_xfer(tmp, msg, i, size);
 		copied += size;
 		if (sge->length)
@@ -74,7 +75,8 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,
 
 	if (!ret) {
 		msg->sg.start = i;
-		sk_psock_queue_msg(psock, tmp);
+		if (!sk_psock_queue_msg(psock, tmp))
+			atomic_sub(copied, &sk->sk_rmem_alloc);
 		sk_psock_data_ready(sk, psock);
 	} else {
 		sk_msg_free(sk, tmp);
-- 
2.39.5




  parent reply	other threads:[~2024-12-30 15:49 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-30 15:42 [PATCH 6.6 00/86] 6.6.69-rc1 review Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 01/86] media: dvb-frontends: dib3000mb: fix uninit-value in dib3000_write_reg Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 02/86] ceph: try to allocate a smaller extent map for sparse read Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 03/86] ceph: fix memory leak in ceph_direct_read_write() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 04/86] ceph: allocate sparse_ext map only for sparse reads Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 05/86] mm/vmstat: fix a W=1 clang compiler warning Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 06/86] tcp_bpf: Charge receive socket buffer in bpf_tcp_ingress() Greg Kroah-Hartman
2024-12-30 15:42 ` Greg Kroah-Hartman [this message]
2024-12-30 15:42 ` [PATCH 6.6 08/86] bpf: Check negative offsets in __bpf_skb_min_len() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 09/86] nfsd: Revert "nfsd: release svc_expkey/svc_export with rcu_work" Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 10/86] nfsd: restore callback functionality for NFSv4.0 Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 11/86] mtd: diskonchip: Cast an operand to prevent potential overflow Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 12/86] mtd: rawnand: arasan: Fix double assertion of chip-select Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 13/86] mtd: rawnand: arasan: Fix missing de-registration of NAND Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 14/86] phy: qcom-qmp: Fix register name in RX Lane config of SC8280XP Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 15/86] phy: core: Fix an OF node refcount leakage in _of_phy_get() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 16/86] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 17/86] phy: core: Fix that API devm_phy_put() fails to release the phy Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 18/86] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 19/86] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 20/86] phy: usb: Toggle the PHY power during init Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 21/86] phy: rockchip: naneng-combphy: fix phy reset Greg Kroah-Hartman
2025-01-29 13:27   ` [REGRESSION] USB 3 and PCIe broken on rk356x due to missing " Jan Čermák
2025-01-29 13:36     ` Greg Kroah-Hartman
2025-01-29 13:50       ` Jan Čermák
2025-01-29 13:55       ` Heiko Stübner
2025-01-29 18:41         ` Vinod Koul
2025-01-29 21:06           ` Heiko Stübner
2024-12-30 15:42 ` [PATCH 6.6 22/86] dmaengine: mv_xor: fix child node refcount handling in early exit Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 23/86] dmaengine: dw: Select only supported masters for ACPI devices Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 24/86] dmaengine: tegra: Return correct DMA status when paused Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 25/86] dmaengine: fsl-edma: implement the cleanup path of fsl_edma3_attach_pd() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 26/86] dmaengine: apple-admac: Avoid accessing registers in probe Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 27/86] dmaengine: at_xdmac: avoid null_prt_deref in at_xdmac_prep_dma_memset Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 28/86] mtd: rawnand: fix double free in atmel_pmecc_create_user() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 29/86] powerpc/pseries/vas: Add close() callback in vas_vm_ops struct Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 30/86] stddef: make __struct_group() UAPI C++-friendly Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 31/86] tracing/kprobe: Make trace_kprobes module callback called after jump_label update Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 32/86] watchdog: it87_wdt: add PWRGD enable quirk for Qotom QCML04 Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 33/86] watchdog: mediatek: Add support for MT6735 TOPRGU/WDT Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 34/86] scsi: qla1280: Fix hw revision numbering for ISP1020/1040 Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 35/86] scsi: megaraid_sas: Fix for a potential deadlock Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 36/86] udf: Skip parent dir link count update if corrupted Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 37/86] ALSA: hda/conexant: fix Z60MR100 startup pop issue Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 38/86] ALSA: sh: Use standard helper for buffer accesses Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 39/86] smb: server: Fix building with GCC 15 Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 40/86] regmap: Use correct format specifier for logging range errors Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 41/86] LoongArch: Fix reserving screen info memory for above-4G firmware Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 42/86] LoongArch: BPF: Adjust the parameter of emit_jirl() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 43/86] platform/x86: asus-nb-wmi: Ignore unknown event 0xCF Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 44/86] spi: intel: Add Panther Lake SPI controller support Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 45/86] scsi: mpt3sas: Diag-Reset when Doorbell-In-Use bit is set during driver load time Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 46/86] scsi: storvsc: Do not flag MAINTENANCE_IN return of SRB_STATUS_DATA_OVERRUN as an error Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 47/86] spi: omap2-mcspi: Fix the IS_ERR() bug for devm_clk_get_optional_enabled() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 48/86] drm/dp_mst: Ensure mst_primary pointer is valid in drm_dp_mst_handle_up_req() Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 49/86] virtio-blk: dont keep queue frozen during system suspend Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 50/86] blk-mq: register cpuhp callback after hctx is added to xarray table Greg Kroah-Hartman
2024-12-30 15:42 ` [PATCH 6.6 51/86] blk-mq: move cpuhp callback registering out of q->sysfs_lock Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 52/86] MIPS: Probe toolchain support of -msym32 Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 53/86] MIPS: mipsregs: Set proper ISA level for virt extensions Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 54/86] sched/task_stack: fix object_is_on_stack() for KASAN tagged pointers Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 55/86] ALSA: hda/realtek: fix mute/micmute LEDs dont work for EliteBook X G1i Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 56/86] ALSA: hda/realtek: fix micmute LEDs dont work on HP Laptops Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 57/86] pmdomain: core: Add missing put_device() Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 58/86] drm/amd/amdgpu: allow use kiq to do hdp flush under sriov Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 59/86] drm/amdgpu/hdp4.0: do a posting read when flushing HDP Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 60/86] drm/amdgpu/hdp5.0: " Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 61/86] drm/amdgpu/hdp6.0: " Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 62/86] x86/cpu: Add model number for Intel Clearwater Forest processor Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 63/86] x86/cpu: Add model number for another Intel Arrow Lake mobile processor Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 64/86] x86/cpu/vfm: Add/initialize x86_vfm field to struct cpuinfo_x86 Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 65/86] x86/cpu/vfm: Update arch/x86/include/asm/intel-family.h Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 66/86] x86/cpu/intel: Switch to new Intel CPU model defines Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 67/86] x86/cpu: Add Lunar Lake to list of CPUs with a broken MONITOR implementation Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 68/86] drm/amdkfd: reduce stack size in kfd_topology_add_device() Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 69/86] drm/amdkfd: drop struct kfd_cu_info Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 70/86] drm/amdkfd: Use device based logging for errors Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 71/86] drm/amdkfd: pause autosuspend when creating pdd Greg Kroah-Hartman
2024-12-30 16:04   ` Li, Yunxiang (Teddy)
2025-01-02  9:32     ` Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 72/86] freezer, sched: Report frozen tasks as D instead of R Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 73/86] tracing: Constify string literal data member in struct trace_event_call Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 74/86] tracing: Prevent bad count for tracing_cpumask_write Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 75/86] io_uring/sqpoll: fix sqpoll error handling races Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 76/86] i2c: microchip-core: actually use repeated sends Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 77/86] PCI/MSI: Handle lack of irqdomain gracefully Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 78/86] i2c: imx: add imx7d compatible string for applying erratum ERR007805 Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 79/86] i2c: microchip-core: fix "ghost" detections Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 80/86] power: supply: gpio-charger: Fix set charge current limits Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 81/86] btrfs: avoid monopolizing a core when activating a swap file Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 82/86] btrfs: sysfs: fix direct super block member reads Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 83/86] ALSA: sh: Fix wrong argument order for copy_from_iter() Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 84/86] x86/cpu/intel: Drop stray FAM6 check with new Intel CPU model defines Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 85/86] ALSA: hda/realtek: Fix spelling mistake "Firelfy" -> "Firefly" Greg Kroah-Hartman
2024-12-30 15:43 ` [PATCH 6.6 86/86] block: avoid to reuse `hctx` not removed from cpuhp callback list Greg Kroah-Hartman
2024-12-30 17:51 ` [PATCH 6.6 00/86] 6.6.69-rc1 review Florian Fainelli
2024-12-30 20:58 ` Shuah Khan
2024-12-31  8:12 ` Muhammad Usama Anjum
2024-12-31  9:39 ` Naresh Kamboju
2024-12-31 13:03 ` Harshit Mogalapalli
2024-12-31 22:35 ` [PATCH 6.6] " Hardik Garg
2024-12-31 22:54 ` [PATCH 6.6 00/86] " Ron Economos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241230154211.995525816@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=patches@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zijianzhang@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox