From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: Jiang Wang <jiang.wang@bytedance.com>
Cc: <bpf@vger.kernel.org>, <cong.wang@bytedance.com>,
Casey Schaufler <casey@schaufler-ca.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>
Subject: Re: [PATCH bpf v1] unix: fix an issue in unix_shutdown causing the other end read/write failures
Date: Thu, 11 Nov 2021 15:00:02 +0100 [thread overview]
Message-ID: <20211111140000.GA10779@axis.com> (raw)
In-Reply-To: <20211004232530.2377085-1-jiang.wang@bytedance.com>
On Mon, Oct 04, 2021 at 11:25:28PM +0000, 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 changed the behaviour of read(2) after a shutdown(2) on the
local end of a UDS. Before this patch, reading from a UDS after a local
shutdown(SHUT_RDWR) would return the data written or EOF if there is no
data, but now it always returns -EINVAL.
For example, the following test program succeeds with "read 16 bytes" on
v5.14 but fails with "read: Invalid argument" on v5.15 and mainline:
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/unistd.h>
int main(int argc, char *argv[]) {
int sock[2];
int ret;
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
if (ret < 0)
err(1, "socketpair");
char buf[16] = {};
ret = write(sock[1], buf, sizeof(buf));
if (ret < 0)
err(1, "write");
ret = shutdown(sock[0], SHUT_RDWR);
if (ret < 0)
err(1, "shutdown");
ssize_t bytes = read(sock[0], buf, sizeof(buf));
if (bytes < 0)
err(1, "read");
printf("read %zd bytes\n", bytes);
return 0;
}
next prev parent reply other threads:[~2021-11-11 14:00 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
2021-10-06 12:50 ` patchwork-bot+netdevbpf
2021-11-11 14:00 ` Vincent Whitchurch [this message]
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=20211111140000.GA10779@axis.com \
--to=vincent.whitchurch@axis.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=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).