From: sashiko-bot@kernel.org
To: "Filippo Storniolo" <fstornio@redhat.com>
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
linux-can@vger.kernel.org
Subject: Re: [PATCH can-next v3 3/3] can: add can diag interface
Date: Fri, 04 Sep 2026 14:26:05 +0000 [thread overview]
Message-ID: <20260904142606.6FB371F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904-feat-can-diag-v3-3-bdcebf07b373@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Index-based resumption in can_diag_dump() causes skipped or repeated sockets without notifying userspace via NLM_F_DUMP_INTR.
--
commit 8ae9bc3a24d9d75317a64a778b0ca0dc88c6a32a
Author: Filippo Storniolo <fstornio@redhat.com>
can: add can diag interface
Add the can_diag interface for querying sockets from userspace. The ss(8)
tool can use this interface to list open sockets. The userspace ABI includes
netlink request and response structs with socket information fields.
> diff --git a/net/can/diag.c b/net/can/diag.c
> new file mode 100644
> index 0000000000000..647a94636a548
> --- /dev/null
> +++ b/net/can/diag.c
[ ... ]
> +static int can_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
> +{
> + int num = 0, s_num = cb->args[0];
> + struct can_diag_req *req;
> + struct net *net;
> + struct sock *sk;
> +
> + net = sock_net(skb->sk);
> + req = nlmsg_data(cb->nlh);
> +
> + lock_can_diag_mutex(net);
> + sk_for_each(sk, &net->can.sklist) {
> + if (num < s_num)
> + goto next;
> +
> + if (sk_diag_fill(sk, skb, req,
[Severity: Medium]
Will this simple index-based resumption (num < s_num) cause skipped or
repeated sockets without notifying userspace if the list is modified between
dump iterations?
A netlink dump of CAN sockets can require multiple messages, forcing
can_diag_dump() to return and resume later. If a concurrent thread creates
or destroys a CAN socket, altering the layout of net->can.sklist while the
mutex is dropped, iteration by index becomes inaccurate.
According to the Netlink uAPI guidelines, if iteration during a dump may skip
or repeat objects, NLM_F_DUMP_INTR must be set on the affected messages. This
is normally implemented by maintaining a generation counter and recording it
in cb->seq to detect list modifications.
> + sk_user_ns(NETLINK_CB(cb->skb).sk),
> + NETLINK_CB(cb->skb).portid,
> + cb->nlh->nlmsg_seq, NLM_F_MULTI,
> + sock_i_ino(sk)) < 0)
> + goto done;
> +next:
> + num++;
> + }
> +done:
> + unlock_can_diag_mutex(net);
> + cb->args[0] = num;
> +
> + return skb->len;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904-feat-can-diag-v3-0-bdcebf07b373@redhat.com?part=3
prev parent reply other threads:[~2026-09-04 14:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 14:12 [PATCH can-next v3 0/3] Introduce diag support for CAN Filippo Storniolo
2026-09-04 14:12 ` [PATCH can-next v3 1/3] af_can: ensure sk_protocol is always set on socket creation Filippo Storniolo
2026-09-04 14:12 ` [PATCH can-next v3 2/3] af_can: store socket pointers in struct netns_can Filippo Storniolo
2026-09-04 14:12 ` [PATCH can-next v3 3/3] can: add can diag interface Filippo Storniolo
2026-09-04 14:26 ` sashiko-bot [this message]
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=20260904142606.6FB371F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fstornio@redhat.com \
--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 \
/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