Skip to content

Commit 27f58f7

Browse files
committed
Merge branch 'af_unix-fix-msg_oob-bugs-with-msg_peek'
Kuniyuki Iwashima says: ==================== af_unix: Fix MSG_OOB bugs with MSG_PEEK. Currently, OOB data can be read without MSG_OOB accidentally in two cases, and this seris fixes the bugs. v1: https://lore.kernel.org/netdev/[email protected]/ ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 90be7a5 + 22dd70e commit 27f58f7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/unix/af_unix.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
26632663
WRITE_ONCE(u->oob_skb, NULL);
26642664
consume_skb(skb);
26652665
}
2666-
} else if (!(flags & MSG_PEEK)) {
2666+
} else if (flags & MSG_PEEK) {
2667+
skb = NULL;
2668+
} else {
26672669
skb_unlink(skb, &sk->sk_receive_queue);
26682670
WRITE_ONCE(u->oob_skb, NULL);
26692671
if (!WARN_ON_ONCE(skb_unref(skb)))
@@ -2741,18 +2743,16 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
27412743
last = skb = skb_peek(&sk->sk_receive_queue);
27422744
last_len = last ? last->len : 0;
27432745

2746+
again:
27442747
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
27452748
if (skb) {
27462749
skb = manage_oob(skb, sk, flags, copied);
2747-
if (!skb) {
2750+
if (!skb && copied) {
27482751
unix_state_unlock(sk);
2749-
if (copied)
2750-
break;
2751-
goto redo;
2752+
break;
27522753
}
27532754
}
27542755
#endif
2755-
again:
27562756
if (skb == NULL) {
27572757
if (copied >= target)
27582758
goto unlock;

0 commit comments

Comments
 (0)