mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: muralikrishna2444b@gmail.com
Cc: mani@kernel.org, shuah@kernel.org, hangbin.liu@linux.dev,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v3] selftests: net: add tests for the QRTR socket family
Date: Thu, 03 Dec 2026 12:48:22 +0000	[thread overview]
Message-ID: <179630210271.3146.11727363632224442979@kernel.org> (raw)
In-Reply-To: <20261202120303.257866-1-muralikrishna2444b@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] qrtr_endpoint.c gives the fake /dev/qrtr-tun endpoint the
  fixed node id TEST_SRC_NODE = 5.
- [Medium] qrtr.sh passes on only the binaries' failure status, so it
  exits 0 (PASS) whenever nothing actually runs: - CONFIG_QRTR is not…
- [Medium] The commit message says the suite covers the CAP_NET_ADMIN
  boundary, but bind_privileged_port in qrtr_sock.c does not test it…
- [Medium] The qrtr_endpoint.c header comment (lines 11-12) and the
  commit message say each frame is malformed in exactly one way, so a…
- [Low] Since commit 3b536db8fb32, qrtr_create() in net/qrtr/af_qrtr.c
  returns -EAFNOSUPPORT for any network namespace other than init_net…

--

selftests: net: add tests for the QRTR socket family

This adds tools/testing/selftests/net/qrtr with two programs. qrtr_sock
tests the AF_QIPCRTR bind, port and send rules on the local node.
qrtr_endpoint writes crafted frames to /dev/qrtr-tun to test the frame
validation in qrtr_endpoint_post(), and a qrtr.sh wrapper loads the
modules and runs both.

Link: https://lore.kernel.org/r/20261201104515.45339-1-muralikrishna2444b@gmail.com [v2]
Link: https://lore.kernel.org/r/20261124150753.115914-1-muralikrishna2444b@gmail.com [v1]

> diff --git a/tools/testing/selftests/net/qrtr/qrtr.sh b/tools/testing/selftests/net/qrtr/qrtr.sh
> new file mode 100755
> index 0000000000000..031cadd842a1f
> --- /dev/null
> +++ b/tools/testing/selftests/net/qrtr/qrtr.sh
> @@ -0,0 +1,26 @@

[ ... ]

> +# Only failure is propagated. kselftest_harness exits KSFT_PASS even when
> +# every test skipped, so a skip cannot be detected from the exit status here.
> +
> +modprobe -q qrtr 2>/dev/null
> +modprobe -q qrtr-tun 2>/dev/null
> +
> +ret=0
> +
> +for t in qrtr_sock qrtr_endpoint; do
> +	echo "# $t"
> +	./"$t" || ret=$?
> +done
> +
> +exit $ret

[Severity: Medium]
Doesn't this script still report PASS whenever nothing actually ran?

The modprobe results are ignored, and only a non-zero exit from the
binaries is passed on. kselftest_harness ends with ksft_exit(ret == 0),
which exits KSFT_PASS even when every test skipped.

So the suite reports PASS when:

- CONFIG_QRTR is not set and every test skips.
- The script runs as non-root. modprobe then fails silently, and all 13
  qrtr_endpoint tests skip with "/dev/qrtr-tun needs root" because the
  node is mode 0600.
- The run is outside init_net (see the qrtr_sock.c comment below).

The v3 notes say qrtr.sh was added so the suite does not report skips
as passes. As written, it only handles the case where the module exists
but is not loaded.

A skip can't be seen in the binaries' exit status. Could the script
check its own prerequisites first instead, and exit with ksft_skip (4)
as other net selftest wrappers do? It could check for root, run
[ -c /dev/qrtr-tun ], and confirm that modprobe succeeded.

> diff --git a/tools/testing/selftests/net/qrtr/qrtr_endpoint.c b/tools/testing/selftests/net/qrtr/qrtr_endpoint.c
> new file mode 100644
> index 0000000000000..c38bc69cb4ce9
> --- /dev/null
> +++ b/tools/testing/selftests/net/qrtr/qrtr_endpoint.c
> @@ -0,0 +1,350 @@

[ ... ]

> + * The frames below are deliberately malformed in one way each, so a failure
> + * names the specific check that regressed.

[Severity: Medium]
The commit message makes the same claim:

  Each test malforms a frame in exactly one way, so a failure names the
  check that regressed.

Does that hold for every test here? qrtr_endpoint_post() ends with:

net/qrtr/af_qrtr.c:qrtr_endpoint_post() {
    ...
	if (!size || size > len || len != ALIGN(size, 4) + hdrlen)
		goto err;
    ...
}

The final length check rejects several of these frames by itself. Those
tests would still pass if the check they are named after were removed.
For reference, sizeof(struct qrtr_hdr_v1) is 32 and
sizeof(struct v1_frame) is 52:

- unaligned_length writes 51 bytes with size=20. Without the len & 3
  check, 51 != ALIGN(20, 4) + 32 still rejects it.

- truncated_v1_header and truncated_v2_header use len < hdrlen, which
  can never equal ALIGN(size, 4) + hdrlen. Without the len < sizeof(*v1)
  and len < sizeof(*v2) guards, the kernel would read past the
  kzalloc(len) buffer from qrtr_tun_write_iter() and still return
  -EINVAL. Only KASAN would notice.

- zero_size sends 52 bytes with size=0. Without the !size check,
  52 != 0 + 32 still rejects it. Only a 32-byte header-only frame would
  test that check alone.

- size_exceeds_frame uses size=116 and len=52. Without the size > len
  check, 52 != 116 + 32 still rejects it.

Could these frames be built so that the named check is the only one
that fails? Otherwise, could the comment and changelog be changed?

[ ... ]

> +/* A node id for the test endpoint, distinct from the local node (1). */
> +#define TEST_SRC_NODE		5

[Severity: Medium]
Is node 5 safe to use on Qualcomm hardware? The only reason given is
that it differs from the local node. On many Qualcomm SoCs, 5 is a real
remote processor's QRTR node id, commonly the ADSP. Since net/qrtr is
added to the default TARGETS, this suite will also run on Qualcomm
boards.

Suppose the real node already owns nid 5. valid_hello,
legacy_control_port and valid_v2_hello send HELLO frames with
src_node 5 to QRTR_PORT_CTRL. qrtr_node_assign() ignores the
radix_tree_insert() failure, but still sets the tun node's nid to 5:

net/qrtr/af_qrtr.c:qrtr_node_assign() {
    ...
	radix_tree_insert(&qrtr_nodes, nid, node);
	if (node->nid == QRTR_EP_NID_AUTO)
		WRITE_ONCE(node->nid, nid);
    ...
}

The HELLO then reaches the name server:

qrtr_endpoint_post()
  HELLO queued to the name server socket
ctrl_cmd_hello()
  announce_servers()
    NEW_SERVER for every local service sent to node 5 by kernel_sendmsg()

Node 5 resolves to the real remote processor, so the selftest sends
unsolicited control traffic to live firmware.

Now suppose the tun node takes nid 5 first, for example while the ADSP
boots or restarts during the test. Traffic for node 5 is then routed to
/dev/qrtr-tun. When the fd closes, qrtr_endpoint_unregister() sends a
BYE for node 5 to the name server. ctrl_cmd_bye() then deletes every
server registered under node 5.

The changelog only says "the suite is harmless on non-Qualcomm
configs". Would a node id that Qualcomm firmware does not use avoid
both cases? It would need to be a high value that still fits in the
16-bit v2 header.

[ ... ]

> diff --git a/tools/testing/selftests/net/qrtr/qrtr_sock.c b/tools/testing/selftests/net/qrtr/qrtr_sock.c
> new file mode 100644
> index 0000000000000..592e4e429b975
> --- /dev/null
> +++ b/tools/testing/selftests/net/qrtr/qrtr_sock.c
> @@ -0,0 +1,298 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Tests for the AF_QIPCRTR socket address family.
> + *
> + * These exercise the port assignment contract documented above
> + * qrtr_port_assign() in net/qrtr/af_qrtr.c, the bind() address rules in
> + * qrtr_bind(), and local datagram delivery between two sockets on the local
> + * node. No QRTR endpoint and no Qualcomm hardware is required: the local
> + * node always exists.
> + */

[ ... ]

> +FIXTURE_SETUP(qrtr)
> +{
> +	struct sockaddr_qrtr sq = {};
> +	socklen_t len = sizeof(sq);
> +
> +	self->fd = socket(AF_QIPCRTR, SOCK_DGRAM, 0);
> +	if (self->fd < 0 &&
> +	    (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT))
> +		SKIP(return, "AF_QIPCRTR not supported (CONFIG_QRTR=n?)");

[Severity: Low]
The header comment and the commit message both say "the local node
always exists". Is that still true outside init_net? Since commit
3b536db8fb32, qrtr_create() returns -EAFNOSUPPORT for any namespace
other than init_net:

net/qrtr/af_qrtr.c:qrtr_create() {
    ...
	if (!net_eq(net, &init_net))
		return -EAFNOSUPPORT;
    ...
}

run_kselftest.sh -n/--netns runs each test in its own namespace. In
that mode, this fixture skips all 12 qrtr_sock tests with "AF_QIPCRTR
not supported (CONFIG_QRTR=n?)". data_to_normal_port and
control_type_to_normal_port in qrtr_endpoint.c skip with "cannot bind
AF_QIPCRTR port (CONFIG_QRTR=n?)". qrtr.sh still exits PASS.

The tests were run on a 7.0.0-44-generic distro kernel, which may be
older than this restriction.

Could the skip messages name the init_net restriction? Could qrtr.sh
also detect and report a run outside init_net?

[ ... ]

> +/* A port at or above the ephemeral range may be claimed by any user. */
> +TEST_F(qrtr, bind_unprivileged_port)
> +{
> +	const __u32 want = QRTR_MIN_EPH_SOCKET + 0x1000;
> +
> +	ASSERT_EQ(0, qrtr_bind_port(self->fd, self->node, want));
> +	EXPECT_EQ(want, qrtr_port(_metadata, self->fd));
> +}
> +
> +/*
> + * A port below the ephemeral range requires CAP_NET_ADMIN. As a normal user
> + * this must fail with EACCES; as root it must succeed. Both directions are
> + * checked so the test says something either way.
> + */
> +TEST_F(qrtr, bind_privileged_port)
> +{
> +	int ret = qrtr_bind_port(self->fd, self->node, 0x100);
> +
> +	if (geteuid() == 0) {
> +		EXPECT_EQ(0, ret);
> +	} else {
> +		EXPECT_EQ(-1, ret);
> +		EXPECT_EQ(EACCES, errno);
> +	}
> +}

[Severity: Medium]
The changelog says qrtr_sock covers "the CAP_NET_ADMIN boundary
documented above qrtr_port_assign()". Do these two tests actually cover
it?

The kernel checks a capability, not the uid:

net/qrtr/af_qrtr.c:qrtr_port_assign() {
    ...
	} else if (*port < QRTR_MIN_EPH_SOCKET && !capable(CAP_NET_ADMIN)) {
		rc = -EACCES;
    ...
}

qrtr_create() only requires init_net, not init_user_ns, so the result
of geteuid() == 0 and capable(CAP_NET_ADMIN) can differ:

- A uid 0 process without CAP_NET_ADMIN gets EACCES, but the test
  expects 0. This includes a host-network container with default caps,
  unshare -U -r without a new netns, and capsh --drop=cap_net_admin.
- A non-root process with CAP_NET_ADMIN from file or ambient caps
  succeeds, but the test expects EACCES.

qrtr.sh needs root for modprobe and /dev/qrtr-tun, and it does not
drop privileges for qrtr_sock. Under the intended runner, the EACCES
branch never runs. bind_unprivileged_port likewise cannot show that the
range is open to non-root users.

If the capable() check were removed, would anything in this suite fail?

The tests also never probe the edge of the range. They use 0x100 and
QRTR_MIN_EPH_SOCKET + 0x1000, but not QRTR_MIN_EPH_SOCKET - 1 or
QRTR_MIN_EPH_SOCKET, so changing < to <= would go unnoticed.

This part is pre-existing and was not introduced by this patch, but the
boundary is also unclear in the kernel. The comment above
qrtr_port_assign() says:

 *   >QRTR_MIN_EPH_SOCKET: Specified; available to all

while the code treats >= QRTR_MIN_EPH_SOCKET as unprivileged.

Could the test check CAP_NET_ADMIN directly, for example with capget()?
It could then drop the capability for the deny case and probe both
QRTR_MIN_EPH_SOCKET - 1 and QRTR_MIN_EPH_SOCKET.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202120303.257866-1-muralikrishna2444b%40gmail.com

  parent reply	other threads:[~2026-12-03 12:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:03 Murali Krishna
2026-12-03  2:01 ` Hangbin Liu
2026-12-03 12:48 ` netdev-bot+sashiko [this message]
2026-12-03 14:20   ` Murali Krishna

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=179630210271.3146.11727363632224442979@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hangbin.liu@linux.dev \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=muralikrishna2444b@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /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®