Skip to content

Commit

Permalink
Merge branch 'af_unix-fix-bunch-of-msg_oob-bugs-and-add-new-tests'
Browse files Browse the repository at this point in the history
Kuniyuki Iwashima says:

====================
af_unix: Fix bunch of MSG_OOB bugs and add new tests.

This series rewrites the selftest for AF_UNIX MSG_OOB and fixes
bunch of bugs that AF_UNIX behaves differently compared to TCP.

Note that the test discovered few more bugs in TCP side, which
will be fixed in another series.
====================

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
Paolo Abeni committed Jun 27, 2024
2 parents bab4923 + 91b7186 commit 3f4d9e4
Show file tree
Hide file tree
Showing 5 changed files with 766 additions and 444 deletions.
37 changes: 31 additions & 6 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -2613,10 +2613,24 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
{
struct unix_sock *u = unix_sk(sk);

if (!unix_skb_len(skb) && !(flags & MSG_PEEK)) {
skb_unlink(skb, &sk->sk_receive_queue);
consume_skb(skb);
skb = NULL;
if (!unix_skb_len(skb)) {
struct sk_buff *unlinked_skb = NULL;

spin_lock(&sk->sk_receive_queue.lock);

if (copied && (!u->oob_skb || skb == u->oob_skb)) {
skb = NULL;
} else if (flags & MSG_PEEK) {
skb = skb_peek_next(skb, &sk->sk_receive_queue);
} else {
unlinked_skb = skb;
skb = skb_peek_next(skb, &sk->sk_receive_queue);
__skb_unlink(unlinked_skb, &sk->sk_receive_queue);
}

spin_unlock(&sk->sk_receive_queue.lock);

consume_skb(unlinked_skb);
} else {
struct sk_buff *unlinked_skb = NULL;

Expand Down Expand Up @@ -3093,12 +3107,23 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
case SIOCATMARK:
{
struct unix_sock *u = unix_sk(sk);
struct sk_buff *skb;
int answ = 0;

mutex_lock(&u->iolock);

skb = skb_peek(&sk->sk_receive_queue);
if (skb && skb == READ_ONCE(unix_sk(sk)->oob_skb))
answ = 1;
if (skb) {
struct sk_buff *oob_skb = READ_ONCE(u->oob_skb);

if (skb == oob_skb ||
(!oob_skb && !unix_skb_len(skb)))
answ = 1;
}

mutex_unlock(&u->iolock);

err = put_user(answ, (int __user *)arg);
}
break;
Expand Down
1 change: 0 additions & 1 deletion tools/testing/selftests/net/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ tap
tcp_fastopen_backup_key
tcp_inq
tcp_mmap
test_unix_oob
timestamping
tls
toeplitz
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/net/af_unix/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CFLAGS += $(KHDR_INCLUDES)
TEST_GEN_PROGS := diag_uid test_unix_oob unix_connect scm_pidfd scm_rights
TEST_GEN_PROGS := diag_uid msg_oob scm_pidfd scm_rights unix_connect

include ../../lib.mk
Loading

0 comments on commit 3f4d9e4

Please sign in to comment.