All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH v4 4/7] selftests/landlock: Add UDP bind/connect tests
Date: Fri, 30 Oct 2026 04:53:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-190352@kernel.org> (raw)
In-Reply-To: <20260502124306.3975990-5-matthieu@buffet.re>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] The `SO_RCVTIMEO` and `SO_SNDTIMEO` socket timeouts added in `socket_variant()` are set to an aggressively short 100 milliseconds.
- [Medium] The patch introduces a file descriptor leak in `TEST_F(port_specific, bind_connect_1023)` by overwriting `connect_fd` without closing the previously allocated socket.
- [Low] The 64-bit Landlock access rights bitmasks are assigned to signed 32-bit `const int` variables, which discards the upper 32 bits.
--

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

selftests/landlock: Add UDP bind/connect tests
    
Make basic changes to the existing bind() and connect() test suite to
cover UDP restriction.

> diff --git a/tools/testing/selftests/landlock/net_test.c b/tools/testing/selftests/landlock/net_test.c
> index 016c7277e370..568a6ed7139c 100644
> --- a/tools/testing/selftests/landlock/net_test.c
> +++ b/tools/testing/selftests/landlock/net_test.c

[ ... ]

>  static int socket_variant(const struct service_fixture *const srv)
>  {
> +	/* Arbitrary value just to not block other tests indefinitely. */
> +	const struct timeval timeout = {
> +		.tv_sec = 0,
> +		.tv_usec = 100000,
> +	};

Could this 100 millisecond timeout cause false-positive test failures in heavily
loaded CI environments or nested VMs?

In test_bind_and_connect(), the parent process calls accept() or read() and
waits for an unsynchronized forked child process to execute socket(), connect(),
and write(). If process scheduling delays the child, the parent's blocking
operations might time out and return -EAGAIN.

[ ... ]

> @@ -737,16 +895,20 @@ TEST_F(protocol, connect)
>  
>  TEST_F(protocol, bind_unspec)
>  {
> +	const int bind_access = (variant->sandbox == TCP_SANDBOX ?
> +					 LANDLOCK_ACCESS_NET_BIND_TCP :
> +					 LANDLOCK_ACCESS_NET_BIND_UDP);

Should bind_access use __u64 instead of int?

The 64-bit Landlock access rights bitmasks are assigned to signed 32-bit int
variables here and in several other tests, which discards the upper 32 bits.
While current flags use only the lower bits, this type mismatch might risk
future sign-extension or truncation bugs if Landlock introduces flags using
higher bits.

[ ... ]

> @@ -1815,23 +2035,35 @@ TEST_F(port_specific, bind_connect_1023)
>  	int bind_fd, connect_fd, ret;
>  
>  	/* Adds a rule layer with bind and connect actions. */
> -	if (variant->sandbox == TCP_SANDBOX) {
> +	if (variant->sandbox == TCP_SANDBOX ||
> +	    variant->sandbox == UDP_SANDBOX) {
> +		const int bind_right = (variant->sandbox == TCP_SANDBOX ?
> +						LANDLOCK_ACCESS_NET_BIND_TCP :
> +						LANDLOCK_ACCESS_NET_BIND_UDP);
> +		const int access_rights =
> +			(variant->sandbox == TCP_SANDBOX ?
> +				 (LANDLOCK_ACCESS_NET_BIND_TCP |
> +				  LANDLOCK_ACCESS_NET_CONNECT_TCP) :
> +				 (LANDLOCK_ACCESS_NET_BIND_UDP |
> +				  LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP));

Similar to the above, should bind_right and access_rights be defined as __u64
to match struct landlock_ruleset_attr.handled_access_net?

[ ... ]

> @@ -1867,8 +2104,19 @@ TEST_F(port_specific, bind_connect_1023)
>  	ret = bind_variant(bind_fd, &self->srv0);
>  	clear_cap(_metadata, CAP_NET_BIND_SERVICE);
>  	EXPECT_EQ(0, ret);
> -	EXPECT_EQ(0, listen(bind_fd, backlog));
> +	if (variant->prot.type == SOCK_STREAM)
> +		EXPECT_EQ(0, listen(bind_fd, backlog));
>  
> +	connect_fd = socket_variant(&self->srv0);
> +	ASSERT_LE(0, connect_fd);

Does this overwrite the connect_fd variable and leak the previously allocated
socket file descriptor without calling close()?

connect_fd appears to be allocated via socket_variant() earlier at the start
of TEST_F(port_specific, bind_connect_1023).

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

  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 [this message]
2026-05-02 12:43 ` [PATCH v4 5/7] selftests/landlock: Add tests for sendmsg() Matthieu Buffet
2026-10-30  4:53   ` sashiko-bot
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-190352@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 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.