Commit 27f58f7f authored by Jakub Kicinski's avatar Jakub Kicinski

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/20240409225209.58102-1-kuniyu@amazon.com/
====================

Link: https://lore.kernel.org/r/20240410171016.7621-1-kuniyu@amazon.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 90be7a5c 22dd70eb
...@@ -2663,7 +2663,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk, ...@@ -2663,7 +2663,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
WRITE_ONCE(u->oob_skb, NULL); WRITE_ONCE(u->oob_skb, NULL);
consume_skb(skb); consume_skb(skb);
} }
} else if (!(flags & MSG_PEEK)) { } else if (flags & MSG_PEEK) {
skb = NULL;
} else {
skb_unlink(skb, &sk->sk_receive_queue); skb_unlink(skb, &sk->sk_receive_queue);
WRITE_ONCE(u->oob_skb, NULL); WRITE_ONCE(u->oob_skb, NULL);
if (!WARN_ON_ONCE(skb_unref(skb))) if (!WARN_ON_ONCE(skb_unref(skb)))
...@@ -2741,18 +2743,16 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state, ...@@ -2741,18 +2743,16 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
last = skb = skb_peek(&sk->sk_receive_queue); last = skb = skb_peek(&sk->sk_receive_queue);
last_len = last ? last->len : 0; last_len = last ? last->len : 0;
again:
#if IS_ENABLED(CONFIG_AF_UNIX_OOB) #if IS_ENABLED(CONFIG_AF_UNIX_OOB)
if (skb) { if (skb) {
skb = manage_oob(skb, sk, flags, copied); skb = manage_oob(skb, sk, flags, copied);
if (!skb) { if (!skb && copied) {
unix_state_unlock(sk); unix_state_unlock(sk);
if (copied) break;
break;
goto redo;
} }
} }
#endif #endif
again:
if (skb == NULL) { if (skb == NULL) {
if (copied >= target) if (copied >= target)
goto unlock; goto unlock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment