[PATCH v7 13/18] seltests/landlock: add AF_UNSPEC family test

Mickaël Salaün mic at digikod.net
Tue Sep 6 08:09:31 UTC 2022


On 29/08/2022 19:03, Konstantin Meskhidze wrote:
> Adds two selftests for connect() action with AF_UNSPEC family flag.
> The one is with no landlock restrictions allows to disconnect already
> connected socket with connect(..., AF_UNSPEC, ...):
>      - connect_afunspec_no_restictions;

Typo: "restrictions" (everywhere)


> The second one refuses landlocked process to disconnect already
> connected socket:
>      - connect_afunspec_with_restictions;
> 
> Signed-off-by: Konstantin Meskhidze <konstantin.meskhidze at huawei.com>
> ---
> 
> Changes since v6:
> * None.
> 
> Changes since v5:
> * Formats code with clang-format-14.
> 
> Changes since v4:
> * Refactors code with self->port, self->addr4 variables.
> * Adds bind() hook check for with AF_UNSPEC family.
> 
> Changes since v3:
> * Adds connect_afunspec_no_restictions test.
> * Adds connect_afunspec_with_restictions test.
> 
> ---
>   tools/testing/selftests/landlock/net_test.c | 113 ++++++++++++++++++++
>   1 file changed, 113 insertions(+)
> 
> diff --git a/tools/testing/selftests/landlock/net_test.c b/tools/testing/selftests/landlock/net_test.c
> index 9c3d1e425439..40aef7c683af 100644
> --- a/tools/testing/selftests/landlock/net_test.c
> +++ b/tools/testing/selftests/landlock/net_test.c
> @@ -351,4 +351,117 @@ TEST_F(socket, connect_with_restrictions)
>   	ASSERT_EQ(1, WIFEXITED(status));
>   	ASSERT_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
>   }
> +
> +TEST_F(socket, connect_afunspec_no_restictions)
> +{
> +	int sockfd;
> +	pid_t child;
> +	int status;
> +
> +	/* Creates a server socket 1. */
> +	sockfd = create_socket_variant(variant, SOCK_STREAM);
> +	ASSERT_LE(0, sockfd);
> +
> +	/* Binds the socket 1 to address with port[0]. */
> +	ASSERT_EQ(0, bind_variant(variant, sockfd, self, 0));
> +
> +	/* Makes connection to the socket with port[0]. */
> +	ASSERT_EQ(0, connect_variant(variant, sockfd, self, 0));
> +
> +	child = fork();
> +	ASSERT_LE(0, child);
> +	if (child == 0) {
> +		struct sockaddr addr_unspec = { .sa_family = AF_UNSPEC };

You can constify several variable like this one (in all tests).



More information about the Linux-security-module-archive mailing list