Skip to content

Commit 36893ef

Browse files
q2venPaolo Abeni
authored andcommitted
af_unix: Don't stop recv() at consumed ex-OOB skb.
Currently, recv() is stopped at a consumed OOB skb even if a new OOB skb is queued and we can ignore the old OOB skb. >>> from socket import * >>> c1, c2 = socket(AF_UNIX, SOCK_STREAM) >>> c1.send(b'hellowor', MSG_OOB) 8 >>> c2.recv(1, MSG_OOB) # consume OOB data stays at middle of recvq. b'r' >>> c1.send(b'ld', MSG_OOB) 2 >>> c2.recv(10) # recv() stops at the old consumed OOB b'hellowo' # should be 'hellowol' manage_oob() should not stop recv() at the old consumed OOB skb if there is a new OOB data queued. Note that TCP behaviour is apparently wrong in this test case because we can recv() the same OOB data twice. Without fix: # RUN msg_oob.no_peek.ex_oob_ahead_break ... # msg_oob.c:138:ex_oob_ahead_break:AF_UNIX :hellowo # msg_oob.c:139:ex_oob_ahead_break:Expected:hellowol # msg_oob.c:141:ex_oob_ahead_break:Expected ret[0] (7) == expected_len (8) # ex_oob_ahead_break: Test terminated by assertion # FAIL msg_oob.no_peek.ex_oob_ahead_break not ok 11 msg_oob.no_peek.ex_oob_ahead_break With fix: # RUN msg_oob.no_peek.ex_oob_ahead_break ... # msg_oob.c:146:ex_oob_ahead_break:AF_UNIX :hellowol # msg_oob.c:147:ex_oob_ahead_break:TCP :helloworl # OK msg_oob.no_peek.ex_oob_ahead_break ok 11 msg_oob.no_peek.ex_oob_ahead_break Fixes: 314001f ("af_unix: Add OOB support") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent f5ea076 commit 36893ef

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

net/unix/af_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
26182618

26192619
spin_lock(&sk->sk_receive_queue.lock);
26202620

2621-
if (copied) {
2621+
if (copied && (!u->oob_skb || skb == u->oob_skb)) {
26222622
skb = NULL;
26232623
} else if (flags & MSG_PEEK) {
26242624
skb = skb_peek_next(skb, &sk->sk_receive_queue);

tools/testing/selftests/net/af_unix/msg_oob.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,20 @@ TEST_F(msg_oob, ex_oob_drop_2)
288288
}
289289
}
290290

291+
TEST_F(msg_oob, ex_oob_ahead_break)
292+
{
293+
sendpair("hello", 5, MSG_OOB);
294+
sendpair("wor", 3, MSG_OOB);
295+
296+
recvpair("r", 1, 1, MSG_OOB);
297+
298+
sendpair("ld", 2, MSG_OOB);
299+
300+
tcp_incompliant {
301+
recvpair("hellowol", 8, 10, 0); /* TCP recv()s "helloworl", why "r" ?? */
302+
}
303+
304+
recvpair("d", 1, 1, MSG_OOB);
305+
}
306+
291307
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)