Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230227194654.61114-1-izbyshev@ispras.ru>
Date: Mon, 27 Feb 2023 22:46:54 +0300
From: Alexey Izbyshev <izbyshev@...ras.ru>
To: musl@...ts.openwall.com
Subject: [PATCH] accept4: don't fall back to accept if we got unknown flags

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

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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.