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
Subject: Re: [PATCH can-next v4 03/23] can: enable memcg accounting for user triggered allocations
Date: Thu, 03 Dec 2026 06:15:26 +0000 [thread overview]
Message-ID: <179627852655.3142.2481551623355948404@kernel.org> (raw)
In-Reply-To: <20261201-getsockopt-memcg-isotp-v4-3-97261be8e38e@hartkopp.net>
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
next prev parent reply other threads:[~2026-12-03 6:15 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 16:51 [PATCH can-next v4 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 01/23] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 02/23] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 03/23] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
2026-12-03 6:15 ` netdev-bot+sashiko [this message]
2026-12-01 16:51 ` [PATCH can-next v4 04/23] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 05/23] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 06/23] can: isotp: add the frame transmission time to the CF broadcast gap Oliver Hartkopp
2026-12-03 6:15 ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 07/23] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
2026-12-03 6:15 ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 08/23] can: isotp: use the N_As timeout for the local echo Oliver Hartkopp
2026-12-03 6:15 ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
2026-12-03 6:15 ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 10/23] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 11/23] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 12/23] can: isotp: drop frames without N_PCI Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 13/23] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 14/23] can: isotp: check the minimum FF_DL Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 15/23] can: isotp: check the data length of the last CF Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 16/23] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 17/23] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
2026-12-03 6:15 ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 18/23] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 19/23] can: isotp: rename variable for the required content length Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 20/23] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 21/23] can: isotp: change return type of functions to void Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 22/23] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 23/23] can: isotp: introduce CAN_ISOTP_MIN_TX_DL Oliver Hartkopp
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=179627852655.3142.2481551623355948404@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-bot@kernel.org \
--cc=socketcan@hartkopp.net \
--cc=yewentian395@gmail.com \
--cc=zihanx@nebusec.ai \
/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