Linux Security Modules development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH v4 5/7] selftests/landlock: Add tests for sendmsg()
Date: Fri, 30 Oct 2026 04:53:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-190353@kernel.org> (raw)
In-Reply-To: <20260502124306.3975990-6-matthieu@buffet.re>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Test Hang Vulnerability due to EXPECT_EQ before blocking socket reads
- [Medium] Stale Data Validation due to missing audit_count_records() call
- [Low] File descriptor and resource leaks in test paths
--

commit a3c5aefc4ced3649cf0e1efaac53d8674cff7d76
Author: Matthieu Buffet <matthieu@buffet.re>

selftests/landlock: Add tests for sendmsg()

This commit adds tests specific to UDP sendmsg() in the protocol_* variants
to ensure behaviour is consistent across AF_INET, AF_INET6 and AF_UNIX.

> diff --git a/tools/testing/selftests/landlock/net_test.c b/tools/testing/selftests/landlock/net_test.c
> --- a/tools/testing/selftests/landlock/net_test.c
> +++ b/tools/testing/selftests/landlock/net_test.c

[ ... ]

> @@ -1119,6 +1274,441 @@ TEST_F(protocol, connect_unspec)
> +TEST_F(protocol, sendmsg_stream)
> +{

[ ... ]

> +	/* Send to a truncated (invalid) address. */
> +	res = sendto_variant_addrlen(client_fd, &self->srv0,
> +				     get_addrlen(&self->srv0, true) - 1, "D", 1,
> +				     0);
> +	if (variant->prot.domain == AF_UNIX) {
> +		EXPECT_EQ(-EISCONN, res);
> +	} else {
> +		EXPECT_EQ(0, res);
> +		EXPECT_EQ(1, recv(srv0_fd, read_buf, 1, 0))

If the send operation fails, EXPECT_EQ logs the failure but allows the test
to continue. Will the subsequent recv() block indefinitely since no data was
sent, causing the test suite to hang until a timeout occurs?

Should this be ASSERT_EQ instead?

[ ... ]

> +TEST_F(protocol, sendmsg_unspec)
> +{

[ ... ]

> +	res = sendto_variant(client_fd, &self->unspec_srv0, "B", 1, 0);
> +	if (variant->prot.domain == AF_INET6) {

[ ... ]

> +	} else if (variant->prot.domain == AF_INET) {
> +		EXPECT_EQ(0, res);
> +		EXPECT_EQ(1, read(srv0_fd, read_buf, 1))

Could this read() also block indefinitely if the sendto_variant() above fails,
similar to the recv() in sendmsg_stream?

[ ... ]

> @@ -2342,4 +2938,58 @@ TEST_F(audit, connect)
> +TEST_F(audit, sendmsg)
> +{
> +	const struct landlock_ruleset_attr ruleset_attr = {
> +		.handled_access_net = LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP |
> +				      LANDLOCK_ACCESS_NET_BIND_UDP,
> +	};
> +	const struct landlock_net_port_attr rule = {
> +		.allowed_access = LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP,
> +		.port = self->srv1.port,
> +	};
> +	const int ruleset_fd =
> +		landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
> +	struct audit_records records;
> +	int sock_fd;
> +
> +	/* Sendmsg on stream sockets is never denied. */
> +	if (variant->prot.type != SOCK_DGRAM)
> +		return;

Does this early return leak the ruleset_fd created just above it?

Could the check for SOCK_DGRAM be moved before creating the ruleset?

[ ... ]

> +	EXPECT_EQ(0, audit_count_records(self->audit_fd, &records));
> +	EXPECT_EQ(0, records.access);
> +	EXPECT_EQ(1, records.domain);
> +
> +	/* Check that autobind generates a denied bind event. */
> +	EXPECT_EQ(-EACCES, sendto_variant(sock_fd, &self->srv1, "A", 1, 0));
> +	EXPECT_EQ(0, matches_auditlog(self->audit_fd, "net\\.bind_udp", NULL,
> +				      NULL, NULL));
> +	EXPECT_EQ(0, records.access);
> +	EXPECT_EQ(1, records.domain);

Are we checking stale data here? It looks like a call to
audit_count_records(self->audit_fd, &records) is missing before checking
records.access and records.domain for this second event.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260502124306.3975990-1-matthieu@buffet.re?part=5

  reply	other threads:[~2026-10-30  4:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-02 12:42 [PATCH v4 0/7] landlock: Add UDP access control support Matthieu Buffet
2026-05-02 12:43 ` [PATCH v4 1/7] landlock: Add UDP bind() access control Matthieu Buffet
2026-10-30  4:53   ` sashiko-bot
2026-05-02 12:43 ` [PATCH v4 2/7] landlock: Add UDP connect() " Matthieu Buffet
2026-05-22 21:10   ` Mickaël Salaün
2026-06-06 17:11     ` Matthieu Buffet
2026-06-09 21:15       ` [PATCH 1/2] landlock: Fix unmarked concurrent access to socket family Matthieu Buffet
2026-06-09 21:15         ` [PATCH 2/2] landlock: replace __sk_common struct sock field accesses Matthieu Buffet
2026-06-10 13:41           ` Mickaël Salaün
2026-06-10 13:48             ` Mickaël Salaün
2026-05-22 21:18   ` [PATCH v4 2/7] landlock: Add UDP connect() access control Mickaël Salaün
2026-06-06 17:04     ` Matthieu Buffet
2026-10-30  4:53   ` sashiko-bot
2026-05-02 12:43 ` [PATCH v4 3/7] landlock: Add UDP send " Matthieu Buffet
2026-05-22 21:10   ` Mickaël Salaün
2026-10-30  4:53   ` sashiko-bot
2026-05-02 12:43 ` [PATCH v4 4/7] selftests/landlock: Add UDP bind/connect tests Matthieu Buffet
2026-10-30  4:53   ` sashiko-bot
2026-05-02 12:43 ` [PATCH v4 5/7] selftests/landlock: Add tests for sendmsg() Matthieu Buffet
2026-10-30  4:53   ` sashiko-bot [this message]
2026-05-02 12:43 ` [PATCH v4 6/7] samples/landlock: Add sandboxer UDP access control Matthieu Buffet
2026-05-02 12:43 ` [PATCH v4 7/7] landlock: Add documentation for UDP support Matthieu Buffet
2026-05-22 21:11   ` Mickaël Salaün
2026-05-06 15:33 ` [PATCH v4 0/7] landlock: Add UDP access control support Günther Noack
2026-05-07 22:11   ` Matthieu Buffet
2026-05-22 21:08 ` Mickaël Salaün
2026-06-06 17:01   ` Matthieu Buffet
2026-06-10 13:44     ` Mickaël Salaün
2026-05-25 20:28 ` Mickaël Salaün
2026-06-11  0:27   ` Matthieu Buffet

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=sashiko-outbox-190353@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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