Skip to content

Commit ae3f9e1

Browse files
q2vengregkh
authored andcommitted
af_unix: Don't peek OOB data without MSG_OOB.
[ Upstream commit 22dd70e ] Currently, we can read OOB data without MSG_OOB by using MSG_PEEK when OOB data is sitting on the front row, which is apparently wrong. >>> from socket import * >>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM) >>> c1.send(b'a', MSG_OOB) 1 >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) b'a' If manage_oob() is called when no data has been copied, we only check if the socket enables SO_OOBINLINE or MSG_PEEK is not used. Otherwise, the skb is returned as is. However, here we should return NULL if MSG_PEEK is set and no data has been copied. Also, in such a case, we should not jump to the redo label because we will be caught in the loop and hog the CPU until normal data comes in. Then, we need to handle skb == NULL case with the if-clause below the manage_oob() block. With this patch: >>> from socket import * >>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM) >>> c1.send(b'a', MSG_OOB) 1 >>> c2.recv(1, MSG_PEEK | MSG_DONTWAIT) Traceback (most recent call last): File "<stdin>", line 1, in <module> BlockingIOError: [Errno 11] Resource temporarily unavailable Fixes: 314001f ("af_unix: Add OOB support") Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 1738dfe commit ae3f9e1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/unix/af_unix.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
25652565
WRITE_ONCE(u->oob_skb, NULL);
25662566
consume_skb(skb);
25672567
}
2568-
} else if (!(flags & MSG_PEEK)) {
2568+
} else if (flags & MSG_PEEK) {
2569+
skb = NULL;
2570+
} else {
25692571
skb_unlink(skb, &sk->sk_receive_queue);
25702572
WRITE_ONCE(u->oob_skb, NULL);
25712573
if (!WARN_ON_ONCE(skb_unref(skb)))
@@ -2648,11 +2650,9 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
26482650
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
26492651
if (skb) {
26502652
skb = manage_oob(skb, sk, flags, copied);
2651-
if (!skb) {
2653+
if (!skb && copied) {
26522654
unix_state_unlock(sk);
2653-
if (copied)
2654-
break;
2655-
goto redo;
2655+
break;
26562656
}
26572657
}
26582658
#endif

0 commit comments

Comments
 (0)