lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iJikmmxMVs5oYT=ZV0ae_tydYHpft99mkNWEhyWkjMM0g@mail.gmail.com>
Date: Tue, 28 May 2024 13:27:42 +0200
From: Eric Dumazet <edumazet@...gle.com>
To: David Laight <David.Laight@...lab.com>
Cc: "David S . Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>, 
	Paolo Abeni <pabeni@...hat.com>, 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()

On Tue, May 28, 2024 at 11:20 AM David Laight <David.Laight@...lab.com> 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?

This patch does not cope with poll() results being volatile.

Only epoll, because epoll logic intercepts sk_error_report() and wakes
up a thread,
this thread is calling back tcp_poll() shortly after.

The 'after' starts really at sk_error_report().

>
> ...
> >       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?
> Looks like it'll need a larger change to tcp_reset().

This seems feasible, yes.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ