mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] accept4: don't fall back to accept if we got unknown flags
@ 2023-02-27 19:46 Alexey Izbyshev
  2023-02-27 22:38 ` Rich Felker
  0 siblings, 1 reply; 9+ messages in thread
From: Alexey Izbyshev @ 2023-02-27 19:46 UTC (permalink / raw)
  To: musl

accept4 emulation via accept ignores unknown flags, so it can spuriously
succeed instead of failing (or succeed without doing the action implied
by an unknown flag if it's added in a future kernel). Worse, unknown
flags trigger the fallback code even on modern kernels if the real
accept4 syscall returns EINVAL, because this is indistinguishable from
socketcall returning EINVAL due to lack of accept4 support. Fix this by
always propagating the syscall attempt failure if unknown flags are

The behavior is still not ideal on old kernels lacking accept4 on arches
with socketcall, where failing with ENOSYS instead of EINVAL returned by
socketcall would be preferable, but at least modern kernels are now
 src/network/accept4.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/network/accept4.c b/src/network/accept4.c
index 59ab1726..bbb79507 100644
--- a/src/network/accept4.c
+++ b/src/network/accept4.c
@@ -9,6 +9,7 @@ int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int
 	if (!flg) return accept(fd, addr, len);
 	int ret = socketcall_cp(accept4, fd, addr, len, flg, 0, 0);
 	if (ret>=0 || (errno != ENOSYS && errno != EINVAL)) return ret;
+	if (flg & ~(SOCK_CLOEXEC|SOCK_NONBLOCK)) return ret;
 	ret = accept(fd, addr, len);
 	if (ret<0) return ret;
 	if (flg & SOCK_CLOEXEC)

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-02-28 20:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 19:46 [musl] [PATCH] accept4: don't fall back to accept if we got unknown flags Alexey Izbyshev
2023-02-27 22:38 ` Rich Felker
2023-02-27 23:42   ` Alexey Izbyshev
2023-02-27 23:51     ` Alexey Izbyshev
2023-02-27 23:53       ` Rich Felker
2023-02-28 17:21     ` Rich Felker
2023-02-28 17:25       ` Rich Felker
2023-02-28 20:15         ` Alexey Izbyshev
2023-02-28 20:51           ` Rich Felker

Code repositories for project(s) associated with this public inbox

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).