[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f0bfde4a89ab4550be05473411aed1d2@AcuMS.aculab.com>
Date: Tue, 28 May 2024 10:43:45 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Paolo Abeni' <pabeni@...hat.com>, 'Eric Dumazet' <edumazet@...gle.com>,
"David S . Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>
CC: Neal Cardwell <ncardwell@...gle.com>, "netdev@...r.kernel.org"
<netdev@...r.kernel.org>, "eric.dumazet@...il.com" <eric.dumazet@...il.com>
Subject: RE: [PATCH net 2/4] tcp: fix race in tcp_write_err()
From: Paolo Abeni
> Sent: 28 May 2024 11:36
>
> On Tue, 2024-05-28 at 09:19 +0000, David Laight wrote:
> > From: Eric Dumazet
> > > Sent: 24 May 2024 20:36
> > >
> > > I noticed flakes in a packetdrill test, expecting an epoll_wait()
> > > to return EPOLLERR | EPOLLHUP on a failed connect() attempt,
> > > after multiple SYN retransmits. It sometimes return EPOLLERR only.
> > >
> > > The issue is that tcp_write_err():
> > > 1) writes an error in sk->sk_err,
> > > 2) calls sk_error_report(),
> > > 3) then calls tcp_done().
> > >
> > > tcp_done() is writing SHUTDOWN_MASK into sk->sk_shutdown,
> > > among other things.
> > >
> > > Problem is that the awaken user thread (from 2) sk_error_report())
> > > might call tcp_poll() before tcp_done() has written sk->sk_shutdown.
> > >
> > > tcp_poll() only sees a non zero sk->sk_err and returns EPOLLERR.
> > >
> > > This patch fixes the issue by making sure to call sk_error_report()
> > > after tcp_done().
> >
> > Isn't there still the potential for a program to call poll() at
> > 'just the wrong time' and still see an unexpected status?
> >
> > ...
> > > WRITE_ONCE(sk->sk_err, READ_ONCE(sk->sk_err_soft) ? : ETIMEDOUT);
> > > - sk_error_report(sk);
> > >
> > > - tcp_write_queue_purge(sk);
> > > - tcp_done(sk);
> > > + tcp_done_with_error(sk);
> >
> > Is there scope for moving the write to sk->sk_err inside the function?
>
> Do you mean that the compiler or the CPU can reorder the WRITE_ONCE wrt
> tcp_done_with_error()? I think the function call prevents that.
No, just that the code would be easier to read with (say):
tcp_done_with_error(sk, ETIMEDOUT);
rather than requiring the caller do a WRITE_ONCE() prior to the call.
This might also be needed in order to ensure that both POLLERR and POLLHUP
always get reported.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists