lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <willemdebruijn.kernel.f1685fbda48c@gmail.com>
Date: Thu, 22 Jan 2026 16:33:31 -0500
From: Willem de Bruijn <willemdebruijn.kernel@...il.com>
To: Soichiro Ueda <the.latticeheart@...il.com>, 
 Kuniyuki Iwashima <kuniyu@...gle.com>, 
 "David S. Miller" <davem@...emloft.net>, 
 Eric Dumazet <edumazet@...gle.com>, 
 Jakub Kicinski <kuba@...nel.org>, 
 netdev@...r.kernel.org
Cc: Simon Horman <horms@...nel.org>, 
 Soichiro Ueda <the.latticeheart@...il.com>, 
 Miao Wang <shankerwangmiao@...il.com>
Subject: Re: [PATCH v1 net] selftests: af_unix: drain after peek and verify
 SO_PEEK_OFF reset

Soichiro Ueda wrote:
> Extend the so_peek_off selftest to validate behavior after MSG_PEEK.
> 
> After exercising SO_PEEK_OFF via MSG_PEEK, drain the receive queue with a
> non-peek recv() and verify that it can receive all the content in the
> buffer and SO_PEEK_OFF returns back to 0.
> 
> This improvement is suggested by Miao Wang when the so_peek_off selftest
> was added.
> 
> Link: https://lore.kernel.org/all/7B657CC7-B5CA-46D2-8A4B-8AB5FB83C6DA@gmail.com/
> Suggested-by: Miao Wang <shankerwangmiao@...il.com>
> Signed-off-by: Soichiro Ueda <the.latticeheart@...il.com>
> ---
>  .../selftests/net/af_unix/so_peek_off.c       | 49 +++++++++++++++++++
>  1 file changed, 49 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/af_unix/so_peek_off.c b/tools/testing/selftests/net/af_unix/so_peek_off.c
> index 86e7b0fb522d..813e3b3655d3 100644
> --- a/tools/testing/selftests/net/af_unix/so_peek_off.c
> +++ b/tools/testing/selftests/net/af_unix/so_peek_off.c
> @@ -76,6 +76,19 @@ FIXTURE_TEARDOWN(so_peek_off)
>  		ASSERT_STREQ(str, buf);				\
>  	} while (0)
>  
> +#define peekoffeq(fd, expected)					\
> +	do {							\
> +		int off = -1;					\
> +		socklen_t optlen = sizeof(off);		\
> +		int ret;					\
> +								\
> +		ret = getsockopt(fd, SOL_SOCKET, SO_PEEK_OFF,	\
> +				 &off, &optlen);		\
> +		ASSERT_EQ(0, ret);				\
> +		ASSERT_EQ((socklen_t)sizeof(off), optlen);	\
> +		ASSERT_EQ(expected, off);			\
> +	} while (0)
> +
>  #define async							\
>  	for (pid_t pid = (pid = fork(),				\
>  			  pid < 0 ?				\
> @@ -92,6 +105,14 @@ TEST_F(so_peek_off, single_chunk)
>  
>  	recveq(self->fd[1], "aaaa", 4, MSG_PEEK);
>  	recveq(self->fd[1], "bbbb", 100, MSG_PEEK);
> +
> +	if (variant->type == SOCK_STREAM) {
> +		recveq(self->fd[1], "aaaa", 4, 0);
> +		recveq(self->fd[1], "bbbb", 100, 0);
> +	} else {
> +		recveq(self->fd[1], "aaaabbbb", 100, 0);
> +	}
> +	peekoffeq(self->fd[1], 0);

Do you want to test peekoffeq before the non-peek read too?

>  }
>  
>  TEST_F(so_peek_off, two_chunks)
> @@ -101,6 +122,13 @@ TEST_F(so_peek_off, two_chunks)
>  
>  	recveq(self->fd[1], "aaaa", 4, MSG_PEEK);
>  	recveq(self->fd[1], "bbbb", 100, MSG_PEEK);
> +
> +	if (variant->type == SOCK_STREAM)
> +		recveq(self->fd[1], "aaaa", 4, 0);
> +	else
> +		recveq(self->fd[1], "aaaa", 100, 0);

Why this difference in length?

Because stream read will block if > 4, while datagram does not?

If so, can perhaps use 4 for both or explicitly use non-blocking read.

> +	recveq(self->fd[1], "bbbb", 100, 0);
> +	peekoffeq(self->fd[1], 0);
>  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ