Skip to content

Commit a6736a0

Browse files
Rao Shoaibkuba-moo
authored andcommitted
af_unix: Read with MSG_PEEK loops if the first unread byte is OOB
Read with MSG_PEEK flag loops if the first byte to read is an OOB byte. commit 22dd70e ("af_unix: Don't peek OOB data without MSG_OOB.") addresses the loop issue but does not address the issue that no data beyond OOB byte can be read. >>> from socket import * >>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM) >>> c1.send(b'a', MSG_OOB) 1 >>> c1.send(b'b') 1 >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) b'b' >>> from socket import * >>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM) >>> c2.setsockopt(SOL_SOCKET, SO_OOBINLINE, 1) >>> c1.send(b'a', MSG_OOB) 1 >>> c1.send(b'b') 1 >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) b'a' >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) b'a' >>> c2.recv(1, MSG_DONTWAIT) b'a' >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) b'b' >>> Fixes: 314001f ("af_unix: Add OOB support") Signed-off-by: Rao Shoaib <Rao.Shoaib@oracle.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://lore.kernel.org/r/20240611084639.2248934-1-Rao.Shoaib@oracle.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7d9df38 commit a6736a0

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

net/unix/af_unix.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,18 +2625,18 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
26252625
if (skb == u->oob_skb) {
26262626
if (copied) {
26272627
skb = NULL;
2628-
} else if (sock_flag(sk, SOCK_URGINLINE)) {
2629-
if (!(flags & MSG_PEEK)) {
2628+
} else if (!(flags & MSG_PEEK)) {
2629+
if (sock_flag(sk, SOCK_URGINLINE)) {
26302630
WRITE_ONCE(u->oob_skb, NULL);
26312631
consume_skb(skb);
2632+
} else {
2633+
__skb_unlink(skb, &sk->sk_receive_queue);
2634+
WRITE_ONCE(u->oob_skb, NULL);
2635+
unlinked_skb = skb;
2636+
skb = skb_peek(&sk->sk_receive_queue);
26322637
}
2633-
} else if (flags & MSG_PEEK) {
2634-
skb = NULL;
2635-
} else {
2636-
__skb_unlink(skb, &sk->sk_receive_queue);
2637-
WRITE_ONCE(u->oob_skb, NULL);
2638-
unlinked_skb = skb;
2639-
skb = skb_peek(&sk->sk_receive_queue);
2638+
} else if (!sock_flag(sk, SOCK_URGINLINE)) {
2639+
skb = skb_peek_next(skb, &sk->sk_receive_queue);
26402640
}
26412641
}
26422642

0 commit comments

Comments
 (0)