mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: o.rempel@pengutronix.de
Cc: robin@protonic.nl, socketcan@hartkopp.net, mkl@pengutronix.de,
	shuah@kernel.org, kernel@pengutronix.de,
	linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, fmaurer@redhat.com,
	mailhol@kernel.org, alexander.hoelzl@gmx.net,
	quchaosheng000406@163.com, penguin-kernel@I-love.SAKURA.ne.jp,
	kuba@kernel.org
Subject: Re: [PATCH can-next v2 4/9] selftests: can: add J1939 socket option and metadata tests
Date: Fri, 06 Nov 2026 05:35:20 +0000	[thread overview]
Message-ID: <179394332064.488853.14819383071528044530@kernel.org> (raw)
In-Reply-To: <20261104-j1939-selftests-v2-4-cf797c83317b@pengutronix.de>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new selftest treats a kernel setsockopt contract violation as
  expected behaviour, so the test can never catch it.

--

selftests: can: add J1939 socket option and metadata tests

This adds a kselftest for J1939 socket options and send metadata. It
covers the SO_J1939_FILTER whitelist, SO_J1939_SEND_PRIO as seen on the
wire via a CAN_RAW peer, unconnected sendto(), a wrong-family bind,
SO_J1939_ERRQUEUE TX completion, and set/getsockopt round-trips of
several options.

> diff --git a/tools/testing/selftests/net/can/j1939_tests.h b/tools/testing/selftests/net/can/j1939_tests.h
> index 78eb35f5b6b06..639e000ac5e86 100644
> --- a/tools/testing/selftests/net/can/j1939_tests.h
> +++ b/tools/testing/selftests/net/can/j1939_tests.h

[ ... ]

> @@ -671,6 +673,71 @@ static inline bool recv_cm_cmd_ok(int raw, uint8_t want_pf, uint8_t want_da,
>  	return frame->data[J1939_CM_CMD_OFF] == want_cmd;
>  }
>  
> +/*
> + * Enable the error queue of s with SOF_TIMESTAMPING_TX_ACK only: a finished
> + * send then queues one TX-completion ACK, or an abort entry if the session
> + * fails (__j1939_sk_errqueue() in net/can/j1939/socket.c). The kernel reads
> + * these flags when the session ends, so this may come after the send.
> + */
> +static inline bool errqueue_enable_ack_ok(int s)
> +{
> +	int tstamp_flags = SOF_TIMESTAMPING_TX_ACK;
> +	int enable = 1;
> +
> +	/* setsockopt(SO_J1939_ERRQUEUE) returns the flag value, not 0 */
> +	if (setsockopt(s, SOL_CAN_J1939, SO_J1939_ERRQUEUE, &enable,
> +		       sizeof(enable)) < 0)
> +		return false;

[Severity: Low]
Should the test accept this as expected behaviour, or is this a kernel bug
the test should catch?

The comment matches what j1939_sk_setsockopt_flag() in
net/can/j1939/socket.c does today:

net/can/j1939/socket.c:j1939_sk_setsockopt_flag() {
    ...
	lock_sock(&jsk->sk);
	if (tmp)
		jsk->state |= flag;
	else
		jsk->state &= ~flag;
	release_sock(&jsk->sk);
	return tmp;
}

It returns the int that userspace passed in, not 0. For SO_J1939_PROMISC
and SO_J1939_ERRQUEUE that value goes back to userspace unchanged, so a
successful setsockopt() returns 1 instead of 0. A caller that checks
if (setsockopt(...)) will treat that success as a failure.

A negative optval such as -1 also sets the flag and then returns -1. The
caller then sees errno EPERM even though the state has changed.

This kernel behaviour dates back to 2018 (9d71dd0c700999), so this patch
did not introduce it. However, the check above only tests for < 0, and the
comment presents the positive return value as normal.

sockopt_roundtrip() in test_j1939_opts.c does the same:

	if (setsockopt(s, SOL_CAN_J1939, optname, &val, sizeof(val)) < 0)
		return -1;

As a result, getsockopt_promisc and getsockopt_errqueue cannot detect the
wrong return value on the set side. The file header still says they cover
"set/getsockopt round-trips" of these options.

The last patch in the series, "selftests: can: check SO_J1939_PROMISC
receive effect", repeats the pattern in promisc_receive. It uses
ASSERT_GE(setsockopt(...), 0) with a comment saying SO_J1939_PROMISC
returns the flag value (1) on success. No patch in the series changes
net/.

Could j1939_sk_setsockopt_flag() return 0 instead, with the tests checking
for == 0? If not, could the commit message at least say this is a known
deviation from the setsockopt() contract?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261104-j1939-selftests-v2-0-cf797c83317b%40pengutronix.de

  reply	other threads:[~2026-11-06  5:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 16:17 [PATCH can-next v2 0/9] selftests: can: add J1939 socket and transport tests Oleksij Rempel
2026-11-04 16:17 ` [PATCH can-next v2 1/9] selftests: can: install net/lib.sh with the CAN tests Oleksij Rempel
2026-11-04 16:17 ` [PATCH can-next v2 2/9] selftests: can: add J1939 test helper header and library Oleksij Rempel
2026-11-06  5:35   ` netdev-bot+sashiko
2026-11-04 16:17 ` [PATCH can-next v2 3/9] selftests: can: add J1939 base functional tests Oleksij Rempel
2026-11-06  5:35   ` netdev-bot+sashiko
2026-11-04 16:17 ` [PATCH can-next v2 4/9] selftests: can: add J1939 socket option and metadata tests Oleksij Rempel
2026-11-06  5:35   ` netdev-bot+sashiko [this message]
2026-11-04 16:17 ` [PATCH can-next v2 5/9] selftests: can: add J1939 addressing and concurrency tests Oleksij Rempel
2026-11-06  5:35   ` netdev-bot+sashiko
2026-11-04 16:17 ` [PATCH can-next v2 6/9] selftests: can: add J1939 wire-format tests against CAN_RAW Oleksij Rempel
2026-11-06  5:35   ` netdev-bot+sashiko
2026-11-04 16:17 ` [PATCH can-next v2 7/9] selftests: can: add J1939 TP/ETP multi-frame " Oleksij Rempel
2026-11-06  5:35   ` netdev-bot+sashiko
2026-11-04 16:17 ` [PATCH can-next v2 8/9] selftests: can: cover J1939 transport abort and timeout paths Oleksij Rempel
2026-11-04 16:17 ` [PATCH can-next v2 9/9] selftests: can: check SO_J1939_PROMISC receive effect Oleksij Rempel
2026-11-06  5:35   ` netdev-bot+sashiko
2026-11-06 10:30 ` [PATCH can-next v2 0/9] selftests: can: add J1939 socket and transport tests Oleksij Rempel

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=179394332064.488853.14819383071528044530@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexander.hoelzl@gmx.net \
    --cc=fmaurer@redhat.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=quchaosheng000406@163.com \
    --cc=robin@protonic.nl \
    --cc=shuah@kernel.org \
    --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

all inboxes | Powered by JetHome®