All of lore.kernel.org
 help / color / mirror / Atom feed
From: Filippo Storniolo <fstornio@redhat.com>
To: sashiko-reviews@lists.linux.dev
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, 16 Oct 2026 18:00:36 +0200	[thread overview]
Message-ID: <atJHPuFD8dZyoDaj@storniolo-redhat> (raw)
In-Reply-To: <20260904142606.6FB371F00A3D@smtp.kernel.org>

On Fri, Sep 04, 2026 at 02:26:05PM +0000, sashiko-bot@kernel.org wrote:
>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
>

I understand the concern, but as far as I can tell no other diag
handler implements this.  Does it make sense to add it only here rather
than as a follow-up done uniformly across all the diag handlers?

@Marc Kleine-Budde @Oliver Hartkopp what do you think about this?
If you think it could be worth adding this feature, I can do a respin.

Best regards,
Filippo


  reply	other threads:[~2026-10-16 16:00 UTC|newest]

Thread overview: 13+ 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-10-20 15:26   ` Marc Kleine-Budde
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
2026-10-16 16:00     ` Filippo Storniolo [this message]
2026-10-17 10:10       ` Marc Kleine-Budde
2026-10-19 20:45         ` Jakub Kicinski
2026-10-20 12:27           ` Marc Kleine-Budde
2026-10-20 16:33             ` Filippo Storniolo
2026-10-20 15:50 ` [PATCH can-next v3 0/3] Introduce diag support for CAN Marc Kleine-Budde
2026-10-20 16:20   ` 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=atJHPuFD8dZyoDaj@storniolo-redhat \
    --to=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 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.