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=1796070304; b=MwNGFJ4XNp7sG6vOpHEtD0zaFrxP+bXHpMITYP/wfRSr8Kxma8IOhDXhBGoi8RZR/06N Ca0dTrHs7+OalRfVHquk9D8Culcm0loUsAgoCZI4PAaFKBnBxhsX2TJ/x5NANQ5L1QI3v Lxn+O1okKhfCL1LsKQLse+tE/JUpzj6dcrTRq043fYc/GZIJHstsklyXeVbYa6EWxV5zB mPLJSl8dbeQgor8NaOQ3T4Gvgmtti8WZ+sHfal/IflxsFm5RiLQP08Btz9595xFxDdEAA rlGVvNzFL0dEZX7tI+RWGNnYZhOoBvMoYYnYrIMC11Dgkg3geA9qt8xP/TlX8UW+HHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796070304; 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=e20W0qOIkjwwNSIe0ctdj8w9+q/WvrkfakIdRpXeeAY=; b=a2pihgMGH4LiKvTLQN9OJIXnR0nBzW+s3vopfUxkgSwQg+YODtcs+0WtDYr6/mcwSvyP wPr4NwpQwKXtcgk8DyQR2iLfYuOiRRo+Vwy4VjpDg9aob5+0wnISd74Z0p73iueslDyJe KulMJD4rP8sNb5IP1DxW1av/OaptjYcJXIqGCBTETgbY6qLnS0xIPiz47k/g4yvqL8ozw qjvi8xe2noIcZlHjK6G9fhn+1aAuQH7cdqSs+1gIv/37fXEEWYaDpFtiAnojMKhzXYe1g ar2jXOTjLv1gLTi9XVVkoOxWhiQSt4ulQ8f/JzPzEKSSm0W4ZZo0v0n/ot1SagMRvSA== 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=L7Pr0Sfm; 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 1C7AE606A31A for ; Mon, 30 Nov 2026 20:25:04 +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=L7Pr0Sfm Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1F5C1F000C1; Mon, 30 Nov 2026 20:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796070303; bh=e20W0qOIkjwwNSIe0ctdj8w9+q/WvrkfakIdRpXeeAY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=L7Pr0SfmEgMp6cdoYHku2Ey9g9W2mlIQQs2+RBkcWBPyRX2EGvqW2RKqtSFm9bjCs Mr7e7+JC2ky1qeCVHSeXm4NIAg/yyS9zOrct13Gqn6pNKtI3QrISgO0f1E7U631EoY /zDqRl9IewNizTaodYhE7kDjw9CPmfGc119UfOLMHNH9BFup/wp7hFNlsP8nu9QedY iYqKMPrDlDnAuVf0difi1uVmSQigKuJKjBHthqKsnXF2uUou/ki34OU8MJEJAx1voX P9zuIZsR3tAxX9G/nxtqFNXWIr1gtqmSowlU/eyLWpPxWXS+REM+KaXvwN9L/ImYDp O+eHKGh2FV3vw== Subject: Re: [PATCH can-next v2 03/22] 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, kuba@kernel.org Date: Mon, 30 Nov 2026 20:25:03 +0000 Message-ID: <179607030314.3142.114330154828701454@kernel.org> In-Reply-To: <20261128-getsockopt-memcg-isotp-v2-3-034ba95e17a4@hartkopp.net> References: <20261128-getsockopt-memcg-isotp-v2-3-034ba95e17a4@hartkopp.net> X-sashiko-severity: Medium 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 1 potential issue(s) to consider. Critical: 0 · High: 0 · 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). - [Medium] The patch says it charges user-triggered CAN allocations to the cgroup so a process cannot bypass its memory limit. -- can: enable memcg accounting for user triggered allocations This commit charges user triggered CAN allocations to the memory cgroup of the allocating process. That covers the socket structures, receivers, BCM ops and frame arrays, the raw and j1939 filters, the isotp TX buffer and j1939_priv. The isotp RX buffer, which is allocated in softirq context, is deliberately left unaccounted. Link: https://lore.kernel.org/linux-can/350df96b-5f69-490e-b39e-ed6e9bca4754@hartkopp.net/ > 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] Does leaving this buffer uncharged really avoid the overshoot that the comment describes? isotp_rcv_ff() stores the buffer in so->rx.buf. It is freed only in isotp_sock_destruct(): if (so->rx.buf != so->rx.sbuf) kfree(so->rx.buf); So it stays pinned for the whole life of the socket. This path only runs once the administrator has raised the max_pdu_size module parameter (it can go up to MAX_PDU_SIZE, 1025 * 1024). After that, each isotp socket that receives one large First Frame keeps up to about 1 MiB that the memcg never sees. The socket itself is now charged through sk_alloc(GFP_KERNEL_ACCOUNT), and it is only about 17 KB. The commit message rejects charging because a forced GFP_ATOMIC charge "allows a cgroup to exceed its limit by up to max_pdu_size per socket". Leaving the buffer uncharged allows the same overshoot per socket, and it also hides the memory from the cgroup. try_charge_memcg() forces the charge for __GFP_HIGH, so a forced charge would at least count the memory. Later charges in process context, such as new sk_alloc() calls, would then hit the limit. That would trigger memcg reclaim or OOM against the cgroup responsible for the memory. Can an unprivileged user open many isotp sockets and send large First Frames on the same interface to pin memory well beyond the cgroup limit? Two ways to send them are a CAN_RAW socket with local loopback, or vcan in a user-owned netns. If so, the commit message's own concern ("The OOM killer can not attribute this kernel memory to the responsible process") still applies to this buffer. Would charging it to the socket's memcg with set_active_memcg() and GFP_ATOMIC | __GFP_ACCOUNT be the better choice here? > > @@ -1194,7 +1199,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261128-getsockopt-memcg-isotp-v2-0-034ba95e17a4%40hartkopp.net