All of lore.kernel.org
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Casey Schaufler <casey@schaufler-ca.com>
Cc: Jiang Wang <jiang.wang@bytedance.com>, bpf <bpf@vger.kernel.org>,
	"Cong Wang" <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 Lau" <kafai@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" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf v1] unix: fix an issue in unix_shutdown causing the other end read/write failures
Date: Tue, 5 Oct 2021 22:17:37 +0000	[thread overview]
Message-ID: <774AADB0-5AF7-413E-8046-B863826565CB@fb.com> (raw)
In-Reply-To: <f7338e3e-8798-478f-bac9-a86e247e3a13@schaufler-ca.com>



> On Oct 4, 2021, at 5:04 PM, Casey Schaufler <casey@schaufler-ca.com> wrote:
> 
> 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>

Acked-by: Song Liu <songliubraving@fb.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 22:18 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
2021-10-05 22:17   ` Song Liu [this message]
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=774AADB0-5AF7-413E-8046-B863826565CB@fb.com \
    --to=songliubraving@fb.com \
    --cc=Rao.Shoaib@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=casey@schaufler-ca.com \
    --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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.