From: sashiko-bot@kernel.org
To: "Zihan Xi" <zihanx@nebusec.ai>, linux-can@vger.kernel.org
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH net 1/1] can: bcm: limit RX operation resource usage per socket
Date: Tue, 27 Oct 2026 11:29:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-186443@kernel.org> (raw)
In-Reply-To: <92fe9d7fe3a7daa2cc7de740b15ec7eaa0638b98.1793089479.git.zihanx@nebusec.ai>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] can: bcm: bcm_rx_setup() returns 0 on frame array allocation failure
--
commit 3aff0eb4ba8d41c989dbd64aa48ab75c3eecec89
Author: Zihan Xi <zihanx@nebusec.ai>
can: bcm: limit RX operation resource usage per socket
This commit bounds the per-socket number and total memory allocation size of
CAN BCM RX operations, as well as the number of pending RCU receiver
callbacks. When a socket reaches either limit, creating a new RX operation
fails with -ENOBUFS.
Link: https://bugtracker.nebusec.ai/f/11134
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 3d637a1e0ac1a..96d3f050dec54 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
[ ... ]
> @@ -1425,26 +1518,22 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
> op->nframes = msg_head->nframes;
> op->cfsiz = CFSIZ(msg_head->flags);
> op->flags = msg_head->flags;
> + op->rx_mem = rx_mem;
>
> if (msg_head->nframes > 1) {
> /* create array for CAN frames and copy the data */
> op->frames = kmalloc_array(msg_head->nframes,
> op->cfsiz,
> GFP_KERNEL);
> - if (!op->frames) {
> - kfree(op);
> - return -ENOMEM;
> - }
> + if (!op->frames)
> + goto free_op;
>
> /* create and init array for received CAN frames */
> op->last_frames = kcalloc(msg_head->nframes,
> op->cfsiz,
> GFP_KERNEL);
> - if (!op->last_frames) {
> - kfree(op->frames);
> - kfree(op);
> - return -ENOMEM;
> - }
> + if (!op->last_frames)
> + goto free_op;
[Severity: Medium]
In net/can/bcm.c:bcm_rx_setup(), when creating a new RX operation with
msg_head->nframes > 1, err is initialized to 0 at the start of the function:
int new_op = 0;
int err = 0;
If kmalloc_array() for op->frames or kcalloc() for op->last_frames fails,
jumping to free_op without setting err = -ENOMEM executes:
free_op:
if (op->frames != &op->sframe)
kfree(op->frames);
if (op->last_frames != &op->last_sframe)
kfree(op->last_frames);
kfree(op);
bcm_rx_op_uncharge(bo, rx_mem);
return err;
Doesn't this cause bcm_rx_setup() (and bcm_sendmsg()) to return 0 to
userspace instead of -ENOMEM when either frame array allocation fails?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1793089479.git.zihanx@nebusec.ai?part=1
next prev parent reply other threads:[~2026-10-27 11:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 11:18 [PATCH net 0/1] can: bcm: bound per-socket RX operation resources Zihan Xi
2026-10-27 11:18 ` [PATCH net 1/1] can: bcm: limit RX operation resource usage per socket Zihan Xi
2026-10-27 11:29 ` sashiko-bot [this message]
2026-10-27 13:08 ` zihan xi
2026-10-27 13:11 ` Marc Kleine-Budde
2026-10-27 13:22 ` Oliver Hartkopp
2026-10-28 13:43 ` [PATCH net v2 0/1] can: bcm: bound per-socket RX operation resources Zihan Xi
2026-10-28 13:43 ` [PATCH net v2 1/1] can: bcm: limit RX operation resource usage per socket Zihan Xi
2026-10-28 13:53 ` sashiko-bot
2026-10-28 14:14 ` zihan xi
2026-10-28 15:04 ` Oliver Hartkopp
2026-10-28 15:36 ` zihan xi
2026-10-28 16:04 ` 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=sashiko-outbox-186443@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
--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