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=1796278527; b=YrP+oNM0CDuncpX77Tqqctg/vqyzQCar4Rkr9YWUEQNFErk13PJ1e5SRs7VEApUii3LG nNIWquxp1rB88CvIhbYM/dbXS9fvtr0R9D58kd/wLQ/g7t/2cH3W0317KYWIZ7Id9SJbF rAf3SL9P7YNQpovjluj4ZHL7sWg3ykj1Gc0wd6axMGkYnT4vZxQC469WzDQaZWyiuibUC tpg8ONieoTTVQr2d8LIMBEFn+GsQ425D0QxAPw7LtysdFjX0YAGCxCKEapoGsPs/Lw6cn 1xoa2ZqKDZoS1V1DREk83E6+XgeIbgxawrYlYcVIzoKr1iQycCxuFUQFN7nZ0np/kAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796278527; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=a1nPd9ZRva+rjib7vw1U3iEdGRNv1bbFOd1hROljaqc=; b=KKb3GmoYaBzr/uvYXKaVQmnn8DiB/TYZ2b0Yo8s1y61n5FdQiFN377TN/cOaPFbFOy4K 451G0Gdqhw6qjofANswLkuzS0nRZ/T6WTJ+tosHi8/LDUiEpl5bq/5MRFQ3lAr+hMMeBg zIxtkJKvnGVnpRnvQTyhh0Gv0mIFX2Awnaz62FgdNNv0xjOK02cJTUuAXNEtK1eeYUbSG QIagO4Qr7//uf9jrYR2/BiikeY62Si6Kaqd0cWj0mP93Dez80PhZycYHw7xUHZLQMC5uB oYI24uLYIQvvRNg2yYCarQlWgq+302s230K3qK4/0rZj/s13ng39Ozm3tlHwQBudILg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S7NlZbgG; 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 CA430606A322 for ; Thu, 3 Dec 2026 06:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S7NlZbgG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 006921F000C1; Thu, 3 Dec 2026 06:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796278527; bh=a1nPd9ZRva+rjib7vw1U3iEdGRNv1bbFOd1hROljaqc=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=S7NlZbgGbYNGByUZRl8eIB/EGq3GlnCLmyD4Fba14UDKMbmRrSGDdOD9/AsTtheWj lkR15YvYMyMsOjB051fHSQTOdbvX7j3Rd274uhzG9Ft7qJcNq5z9IrNy4x6fTOJ3Vw TgUnwMoS/IqP7uoH0ZRZFC7uUM+Dob8xYkRQ84xDtBiB89qdp1nsGXGHUPqTsws/yY eU4uQg1/ZFgSJYX/a4AGCXc5a1NpsXIBV0BAKM5/F7kAnL7+U+WUIDzvCE6f7G2XLT 6mMDHpMTN/NshGgNYdNRzdcjqORhWd9nd+eBpgTLff2i0oW/j4IHfOD5dMj48QD5GF 43ErBbNxgFA5w== Subject: Re: [PATCH can-next v4 03/23] can: enable memcg accounting for user triggered allocations From: netdev-bot+sashiko@kernel.org To: socketcan@hartkopp.net Cc: linux-can@vger.kernel.org, mkl@pengutronix.de, sashiko-bot@kernel.org, zihanx@nebusec.ai, o.rempel@pengutronix.de, yewentian395@gmail.com, kuba@kernel.org Date: Thu, 03 Dec 2026 06:15:26 +0000 Message-ID: <179627852655.3142.2481551623355948404@kernel.org> In-Reply-To: <20261201-getsockopt-memcg-isotp-v4-3-97261be8e38e@hartkopp.net> References: <20261201-getsockopt-memcg-isotp-v4-3-97261be8e38e@hartkopp.net> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The patch says it stops unprivileged users from getting around their cgroup memory limit through CAN allocations, but the j1939… - [Medium] The isotp RX buffer for PDUs larger than DEFAULT_MAX_PDU_SIZE is deliberately left without a memcg charge, and that leaves a large… -- can: enable memcg accounting for user triggered allocations This commit charges CAN allocations that unprivileged users can trigger to the memory cgroup of the allocating process. These are the socket structures, receivers, BCM ops and frame arrays, raw and j1939 filters, the isotp TX buffer and j1939_priv. The isotp RX buffer and the j1939 RX sessions, which are allocated in softirq context, are deliberately left unaccounted. Link: https://lore.kernel.org/linux-can/350df96b-5f69-490e-b39e-ed6e9bca4754@hartkopp.net/ > The j1939 RX sessions are allocated in softirq context and > can not be attributed to a single process, as their data is delivered > to all matching sockets. [Severity: High] Is this accurate for the receive path that creates these sessions? j1939_xtp_rx_rts_session_new() in net/can/j1939/transport.c only creates a session for an RTS sent to a locally bound address. j1939_can_recv() sets J1939_ECU_LOCAL_DST when priv->ents[da].nusers is non-zero, and ETP sessions are point-to-point to that address. So could the buffer be charged to the memcg of the matching local socket, the same way socket receive memory is charged? As things stand, can a user still bypass the cgroup limit through j1939? The announced length is only checked against the protocol limits: net/can/j1939/transport.c:j1939_xtp_rx_rts_session_new() { ... len = j1939_etp_ctl_to_size(dat); if (len > J1939_MAX_ETP_PACKET_SIZE) abort = J1939_XTP_ABORT_FAULT; else if (len > priv->tp_max_packet_size) abort = J1939_XTP_ABORT_RESOURCE; ... } tp_max_packet_size defaults to J1939_MAX_ETP_PACKET_SIZE (7 * 0xffffff, about 112 MiB). j1939_session_fresh_new() then allocates and zero fills the whole buffer with no memcg charge: net/can/j1939/transport.c:j1939_session_fresh_new() { ... skb = alloc_skb(size, GFP_ATOMIC); ... skb_put_zero(skb, size); ... } Nothing limits the number of concurrent RX sessions per socket or per cgroup. j1939_session_activate() only rejects a second session with the same address tuple. That means each (sa, da) pair can hold its own buffer: up to about 254 sources times every locally bound destination address. Consider an unprivileged user with a user and network namespace and a vcan device: 1. Bind one small accounted j1939 socket per local address. 2. Send ETP RTS frames from many source addresses over CAN_RAW. 3. Keep the sessions alive with periodic DPO/DT frames. Would this pin large amounts of uncharged GFP_ATOMIC memory, including __GFP_HIGH reserves? Would it then cause the host-wide OOM kills of unrelated processes that this commit is meant to prevent? This code is unchanged at the end of the series. > diff --git a/net/can/isotp.c b/net/can/isotp.c > index 98a7e489ca3e5..3b83507a8c21b 100644 > --- a/net/can/isotp.c > +++ b/net/can/isotp.c > @@ -609,7 +609,12 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae) > if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl) > return 1; > > - /* PDU size > default => try max_pdu_size */ > + /* PDU size > default => try max_pdu_size > + * > + * This buffer is not accounted to a memory cgroup: In softirq > + * context the charge would either have to be forced beyond the > + * limit of the cgroup or the reception would fail at the limit. > + */ > if (so->rx.len > so->rx.buflen && so->rx.buflen < max_pdu_size) { > u8 *newbuf = kmalloc(max_pdu_size, GFP_ATOMIC); > [Severity: Medium] Once an administrator has raised max_pdu_size, can each isotp socket pin far more uncharged memory than its cgroup is charged for? isotp_module_init() clamps max_pdu_size to MAX_PDU_SIZE (1025 * 1024). This buffer stays attached to the socket until the socket is destroyed. Each socket is now charged about 17 KiB through sk_alloc(GFP_KERNEL_ACCOUNT): struct isotp_sock plus its two DEFAULT_MAX_PDU_SIZE buffers. A single First Frame announcing rx.len > rx.buflen pins about 1 MiB of uncharged atomic memory in isotp_rcv_ff(). That is roughly 60 times what the cgroup can see. An unprivileged user on a self-created vcan could open N isotp sockets and send one such First Frame to each. About the forced charge trade-off: even if a GFP_ATOMIC charge pushes the cgroup over its limit, the overshoot is bounded. The next accounted allocation in process context in that cgroup, such as creating another socket, would reclaim or OOM inside the cgroup. Would it be better to charge this buffer to the socket's memcg with set_active_memcg()? Left uncharged, it is invisible to the cgroup limit and to the OOM killer. By default max_pdu_size equals DEFAULT_MAX_PDU_SIZE, so this path is not taken. The code is unchanged at the end of the series. [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-getsockopt-memcg-isotp-v4-0-97261be8e38e%40hartkopp.net