mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH v2] accept4: don't fall back to accept if we got unknown flags
@ 2023-02-28  0:11 Alexey Izbyshev
  0 siblings, 0 replies; only message in thread
From: Alexey Izbyshev @ 2023-02-28  0:11 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 failing with EINVAL if unknown flags are present and
the syscall is missing or failed with EINVAL.
Changed per

The explicit errno variant is chosen because the surrounding code
already deals with errno.

 src/network/accept4.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/network/accept4.c b/src/network/accept4.c
index 59ab1726..765a38ed 100644
--- a/src/network/accept4.c
+++ b/src/network/accept4.c
@@ -9,6 +9,10 @@ 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;
+		errno = EINVAL;
+		return -1;
+	}
 	ret = accept(fd, addr, len);
 	if (ret<0) return ret;
 	if (flg & SOCK_CLOEXEC)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-28  0:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-28  0:11 [musl] [PATCH v2] accept4: don't fall back to accept if we got unknown flags Alexey Izbyshev

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