[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240623051906.79744-1-kuniyu@amazon.com>
Date: Sat, 22 Jun 2024 22:19:06 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <mhal@...x.co>
CC: <cong.wang@...edance.com>, <davem@...emloft.net>, <edumazet@...gle.com>,
<kuba@...nel.org>, <kuni1840@...il.com>, <kuniyu@...zon.com>,
<netdev@...r.kernel.org>, <pabeni@...hat.com>
Subject: Re: [PATCH v2 net 01/15] af_unix: Set sk->sk_state under unix_state_lock() for truly disconencted peer.
From: Michal Luczaj <mhal@...x.co>
Date: Sun, 23 Jun 2024 00:43:27 +0200
> On 6/20/24 23:56, Kuniyuki Iwashima wrote:
> > From: Michal Luczaj <mhal@...x.co>
> > Date: Thu, 20 Jun 2024 22:35:55 +0200
> >> In fact, should I try to document those not-so-obvious OOB/sockmap
> >> interaction? And speaking of documentation, an astute reader noted that
> >> `man unix` is lying:
> >
> > At least I wouldn't update man until we can say AF_UNIX MSG_OOB handling
> > is stable enough; the behaviour is not compliant with TCP now.
>
> Sure, I get it.
>
> > (...)
> > And we need
> >
> > ---8<---
> > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> > index 5e695a9a609c..2875a7ce1887 100644
> > --- a/net/unix/af_unix.c
> > +++ b/net/unix/af_unix.c
> > @@ -2614,9 +2614,20 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
> > struct unix_sock *u = unix_sk(sk);
> >
> > if (!unix_skb_len(skb) && !(flags & MSG_PEEK)) {
> > - skb_unlink(skb, &sk->sk_receive_queue);
> > - consume_skb(skb);
> > - skb = NULL;
> > + struct sk_buff *unlinked_skb = skb;
> > +
> > + spin_lock(&sk->sk_receive_queue.lock);
> > +
> > + __skb_unlink(skb, &sk->sk_receive_queue);
> > +
> > + if (copied)
> > + skb = NULL;
> > + else
> > + skb = skb_peek(&sk->sk_receive_queue);
> > +
> > + spin_unlock(&sk->sk_receive_queue.lock);
> > +
> > + consume_skb(unlinked_skb);
> > } else {
> > struct sk_buff *unlinked_skb = NULL;
> >
> > ---8<---
>
> I gotta ask, is there a reason for unlinking an already consumed
> ('consumed' as in 'unix_skb_len(skb) == 0') skb so late, in manage_oob()?
> IOW, can't it be unlinked immediately once it's consumed in
> unix_stream_recv_urg()? I suppose that would simplify things.
I also thought that before, but we can't do that.
Even after reading OOB data, we need to remember the position
and break recv() at that point. That's why the skb is unlinked
in manage_oob() rather than unix_stream_recv_urg().
Powered by blists - more mailing lists