linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: Jiang Wang <jiang.wang@bytedance.com>, bpf@vger.kernel.org
Cc: cong.wang@bytedance.com, "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>,
	Eric Dumazet <edumazet@google.com>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	Rao Shoaib <Rao.Shoaib@oracle.com>,
	Kuniyuki Iwashima <kuniyu@amazon.co.jp>,
	Jakub Sitnicki <jakub@cloudflare.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: [PATCH bpf v1] unix: fix an issue in unix_shutdown causing the other end read/write failures
Date: Mon, 4 Oct 2021 17:04:24 -0700	[thread overview]
Message-ID: <f7338e3e-8798-478f-bac9-a86e247e3a13@schaufler-ca.com> (raw)
In-Reply-To: <20211004232530.2377085-1-jiang.wang@bytedance.com>

On 10/4/2021 4:25 PM, Jiang Wang wrote:
> Commit 94531cfcbe79 ("af_unix: Add unix_stream_proto for sockmap")
> sets unix domain socket peer state to TCP_CLOSE
> in unix_shutdown. This could happen when the local end is shutdown
> but the other end is not. Then the other end will get read or write
> failures which is not expected.
>
> Fix the issue by setting the local state to shutdown.
>
> Fixes: 94531cfcbe79 (af_unix: Add unix_stream_proto for sockmap)
> Suggested-by: Cong Wang <cong.wang@bytedance.com>
> Reported-by: Casey Schaufler <casey@schaufler-ca.com>
> Signed-off-by: Jiang Wang <jiang.wang@bytedance.com>

This patch looks like it has fixed the problem. My test cases
are now getting expected results consistently. Please add any
or all of:

Tested-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>

> ---
>  net/unix/af_unix.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index efac5989edb5..0878ab86597b 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -2882,6 +2882,9 @@ static int unix_shutdown(struct socket *sock, int mode)
>  
>  	unix_state_lock(sk);
>  	sk->sk_shutdown |= mode;
> +	if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
> +	    mode == SHUTDOWN_MASK)
> +		sk->sk_state = TCP_CLOSE;
>  	other = unix_peer(sk);
>  	if (other)
>  		sock_hold(other);
> @@ -2904,12 +2907,10 @@ static int unix_shutdown(struct socket *sock, int mode)
>  		other->sk_shutdown |= peer_mode;
>  		unix_state_unlock(other);
>  		other->sk_state_change(other);
> -		if (peer_mode == SHUTDOWN_MASK) {
> +		if (peer_mode == SHUTDOWN_MASK)
>  			sk_wake_async(other, SOCK_WAKE_WAITD, POLL_HUP);
> -			other->sk_state = TCP_CLOSE;
> -		} else if (peer_mode & RCV_SHUTDOWN) {
> +		else if (peer_mode & RCV_SHUTDOWN)
>  			sk_wake_async(other, SOCK_WAKE_WAITD, POLL_IN);
> -		}
>  	}
>  	if (other)
>  		sock_put(other);

  reply	other threads:[~2021-10-05  0:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-04 23:25 [PATCH bpf v1] unix: fix an issue in unix_shutdown causing the other end read/write failures Jiang Wang
2021-10-05  0:04 ` Casey Schaufler [this message]
2021-10-05 22:17   ` Song Liu
2021-10-06 12:50 ` patchwork-bot+netdevbpf
2021-11-11 14:00 ` Vincent Whitchurch
2021-11-19 14:14   ` Jakub Kicinski
2021-11-19 14:28     ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7338e3e-8798-478f-bac9-a86e247e3a13@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=Rao.Shoaib@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=christian.brauner@ubuntu.com \
    --cc=cong.wang@bytedance.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jakub@cloudflare.com \
    --cc=jiang.wang@bytedance.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).