From: sashiko-bot@kernel.org
To: "Zhu Ling" <zhuling0805@qq.com>
Cc: "Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
linux-can@vger.kernel.org,
"Oliver Hartkopp" <socketcan@hartkopp.net>
Subject: Re: [PATCH net] can: netlink: fix CAN XL PWM attribute sizing
Date: Fri, 04 Sep 2026 15:40:45 +0000 [thread overview]
Message-ID: <20260904154045.E548A1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <tencent_9A525E0656A4F7D4CA9CFA1AB1A4BFC6D706@qq.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] can_get_size() underestimates the netlink message size by not using nla_total_size() for the IFLA_CAN_BITRATE_MAX attribute.
--
commit 65a98e250b77c16c65b20dbe5d32fe88f1c06e1b
Author: Zhu Ling <zhuling0805@qq.com>
can: netlink: fix CAN XL PWM attribute sizing
can_pwm_fill_info() emits the PWM capability limits whenever pwm_const is
present, regardless of whether TMS is enabled. In contrast,
can_pwm_get_size() currently returns zero when TMS is disabled. It
therefore underestimates the required netlink message size by the nested
attribute header and six u32 attributes.
Always account for the PWM capability attributes when pwm_const is
present, and account for the three runtime PWM values only when TMS is
enabled.
> diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
> index 766d455950f55..0eac5a3f577ec 100644
> --- a/drivers/net/can/dev/netlink.c
> +++ b/drivers/net/can/dev/netlink.c
> @@ -780,7 +780,7 @@ static size_t can_pwm_get_size(const struct can_pwm_const *pwm_const,
> {
> size_t size;
>
> - if (!pwm_const || !pwm_on)
> + if (!pwm_const)
> return 0;
>
> size = nla_total_size(0); /* nest IFLA_CAN_PWM */
[ ... ]
> @@ -792,9 +792,11 @@ static size_t can_pwm_get_size(const struct can_pwm_const *pwm_const,
> size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO_MIN */
> size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO_MAX */
>
> - size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMS */
> - size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWML */
> - size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO */
> + if (pwm_on) {
> + size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMS */
> + size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWML */
> + size += nla_total_size(sizeof(u32)); /* IFLA_CAN_PWM_PWMO */
> + }
>
> return size;
> }
[Severity: High]
This is a pre-existing issue, but while looking at the netlink message size
calculations, I noticed a potential under-allocation in the caller:
drivers/net/can/dev/netlink.c:can_get_size() {
...
if (priv->bitrate_const) /* IFLA_CAN_BITRATE_CONST */
size += nla_total_size(sizeof(*priv->bitrate_const) *
priv->bitrate_const_cnt);
size += sizeof(priv->bitrate_max); /* IFLA_CAN_BITRATE_MAX */
size += can_ctrlmode_ext_get_size(); /* IFLA_CAN_CTRLMODE_EXT */
...
}
Does the IFLA_CAN_BITRATE_MAX size calculation underestimate the required
netlink message size? It appears to add only the payload size instead of
wrapping it in nla_total_size() to account for the NLA header.
If the allocation doesn't happen to have enough slack to cover the calculation
error, couldn't this cause userspace netlink requests (like `ip link show`) to
randomly fail with -EMSGSIZE and truncate the response?
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_9A525E0656A4F7D4CA9CFA1AB1A4BFC6D706@qq.com?part=1
next prev parent reply other threads:[~2026-09-04 15:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 15:26 [PATCH net] can: netlink: fix CAN XL PWM attribute sizing Zhu Ling
2026-09-04 15:40 ` sashiko-bot [this message]
2026-09-04 17:08 ` zhuling0805
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=20260904154045.E548A1F00A3D@smtp.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=zhuling0805@qq.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.