Skip to contentSkip to conversation

af_unix: Clear stale u->oob_skb.

PATCH Kuniyuki Iwashima 2 participants 2 messages Apr 5, 2024 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

From: Rao Shoaib <[email protected]>
Date: Fri, 5 Apr 2024 15:43:26 -0700
[...]

Quoted 9 lines
Quoted 9 lines
net/unix/af_unix.c +0 -1
index 5b41e2321209..d032eb5fa6df 100644
@@ -2665,7 +2665,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
 				}
 			} else if (!(flags & MSG_PEEK)) {
 				skb_unlink(skb, &sk->sk_receive_queue);
-				consume_skb(skb);
Quoted 8 lines

net/unix/af_unix.c static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk, · line 2673

Quoted 6 lines
net/unix/af_unix.c +3 -0
+				WRITE_ONCE(u->oob_skb, NULL);
+				if (!WARN_ON_ONCE(skb_unref(skb)))
+					kfree_skb(skb);
 				skb = skb_peek(&sk->sk_receive_queue);
 			}
 		}

Isn't consume_skb doing the same thing() ? .

Only if you disable CONFIG_TRACEPOINTS, otherwise each function uses different tracepoints, trace_consume_skb() vs trace_kfree_skb().

Here, we clearly drop the skb that's not received by user, so kfree_skb() should be used.

Quoted 1 line

The only action needed is to clear out u->oob_skb -- No?

Also, queue_oob() now calls skb_get() and holds another refcnt, so skb_unref() is needed.

BTW, do you know if MSG_OOB is actually used in production ? I don't know any real user other than syzbot.

P.S.
Please send mail in plain text format as mailing list drops HTML.

Reviewed-by
#2 lore raw
Quoted 21 lines · Kuniyuki Iwashima

From: Rao Shoaib <[email protected]>
Date: Fri, 5 Apr 2024 15:43:26 -0700
[...]

Quoted 9 lines
Quoted 9 lines
net/unix/af_unix.c +0 -1
index 5b41e2321209..d032eb5fa6df 100644
@@ -2665,7 +2665,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
  				}
  			} else if (!(flags & MSG_PEEK)) {
  				skb_unlink(skb, &sk->sk_receive_queue);
-				consume_skb(skb);
Quoted 8 lines

net/unix/af_unix.c static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk, · line 2673

Quoted 6 lines
net/unix/af_unix.c +3 -0
+				WRITE_ONCE(u->oob_skb, NULL);
+				if (!WARN_ON_ONCE(skb_unref(skb)))
+					kfree_skb(skb);
  				skb = skb_peek(&sk->sk_receive_queue);
  			}
  		}

Isn't consume_skb doing the same thing() ? .

Quoted 5 lines

Only if you disable CONFIG_TRACEPOINTS, otherwise each function uses different tracepoints, trace_consume_skb() vs trace_kfree_skb().

Here, we clearly drop the skb that's not received by user, so kfree_skb() should be used.

I won't get into the semantics of freed or consumed. So fine go with it. However if I was tracing I would just trace kfree_skb.

Quoted 6 lines
Quoted 3 lines

The only action needed is to clear out u->oob_skb -- No?

Also, queue_oob() now calls skb_get() and holds another refcnt, so skb_unref() is needed.

A quick look, does not show me that the proposed fix does anything different wrt to the refcnt. consume_skb() also calls skb_unref() and kfree_skb().

I am fine with this.

Shoaib

Quoted 6 lines

BTW, do you know if MSG_OOB is actually used in production ? I don't know any real user other than syzbot.

P.S.
Please send mail in plain text format as mailing list drops HTML.