From nobody Sat Sep 26 14:40:04 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4668A47607E; Mon, 31 Aug 2026 16:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788192311; cv=none; b=QItj34F/OdpiI+b0GhF/i0c7xb1CR+O7Wj9DFVmEzNTKFevkjZ9UI/yV7JXQgqaksjfcBIhNOIGyjd/EvxO1538sXSkE3pN058TWVHN5IKFqBYusQMURVx3DU1RpqNgeHgyqTJTxG+JmtACYqMAp26waFCpyuhLEVIpVP4Go07o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788192311; c=relaxed/simple; bh=O8cMM23LUCpDyw5jvN20SoyoVKc1CUjKyifWs4b5PZk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q9Rb0cQ+L8CasS8Mu3ApIev1qAJxpWGlQUEuGp+HKsd7SzTpMzHmlg/lgC4QEnuQKS6RVnKGcx0ou9xmYeMlZapU4EoySA2JozIEi55Lqy1s9+LPaKsqGTrlQxCIKHsRTgrA9tgoOVvfhN4hoLS7jIlHd35b8Iq/+X484rhhYxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=m3lJQdsr; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="m3lJQdsr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1788192307; bh=O8cMM23LUCpDyw5jvN20SoyoVKc1CUjKyifWs4b5PZk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m3lJQdsr52/yHKBBu8R8T7u8IYgFKO8cHUQTt9bw9/vjmCNtMm1D7h10HaaCYb4P9 xRsJID7t0/evMtd6M3mvVrc25zrFCdoq2D9b+40M5eY2kne8tguYaY6Ay6BSyYPqfe m79AS5RwMTMGYocEuj008bMy7ylPwtdWWX7q3dUY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 31 Aug 2026 18:04:59 +0200 Subject: [PATCH 1/3] tools/nolibc: verify that a directory is opened Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260831-nolibc-fdopendir-enotdir-v1-1-8cf0e79c4e6f@weissschuh.net> References: <20260831-nolibc-fdopendir-enotdir-v1-0-8cf0e79c4e6f@weissschuh.net> In-Reply-To: <20260831-nolibc-fdopendir-enotdir-v1-0-8cf0e79c4e6f@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788192306; l=917; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=O8cMM23LUCpDyw5jvN20SoyoVKc1CUjKyifWs4b5PZk=; b=olH/8BpnS/ea9JeZY1PzE82CK9W7rHLTnkev3lvU8hBoLnLPGsu+Omk6RJhApsHHyaUJx0qn0 t4E1qhpZwwGDZboZEzdJ+ESuEqWvPxhrwOrT29vqlIRhQduU9YzZ2y5 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= If a non-directory is opened, ENODIR should be returned from opendir()/fdopendir() right away and not only during readdir_r(). Validate the type of opened file during open. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Willy Tarreau --- tools/include/nolibc/dirent.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h index 4e02ef25e72d..25fbff208998 100644 --- a/tools/include/nolibc/dirent.h +++ b/tools/include/nolibc/dirent.h @@ -30,10 +30,23 @@ typedef struct { static __attribute__((unused)) DIR *fdopendir(int fd) { + struct stat buf; + int ret; + if (fd < 0) { SET_ERRNO(EBADF); return NULL; } + + ret =3D fstat(fd, &buf); + if (ret < 0) + return NULL; + + if (!S_ISDIR(buf.st_mode)) { + SET_ERRNO(ENOTDIR); + return NULL; + } + return (DIR *)(intptr_t)~fd; } =20 --=20 2.55.0 From nobody Sat Sep 26 14:40:04 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F11A476684; Mon, 31 Aug 2026 16:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788192310; cv=none; b=b/agVBD8L26nh6SehvfGwILw9oRoO9LFRukD55z1IA6aC4PcUghK154nMwmBpB8sy6h5m4izyfkw//04JSdyTX30nmGQ+i3IwZp42mGJkWPtXW1erPmFW3vg8b3lN6rNMPSwmCKdl0wdZqgwN2Nc8KfHyrnnUG1qs1vvC2AErTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788192310; c=relaxed/simple; bh=csydGn/7BD/hARHg0LOa5fdhTb/AEwCDcfkYU2foV64=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dNQAz+9fG9KMDe+IUoBUB5enl4fVoCGdSaFLJzWDgyDJU5qF5l46mCyASxROrya0FZgc9zyjuRHDCL6FE8i1RYXgVnLIDEKAc1v2i3++S/HOkBugrz0PGT+YG6DaA1BlEAfsIJdmD1GxxN9xYOZeY4uaQT50RCyvtFAHj775rSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=XrSEttDP; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="XrSEttDP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1788192307; bh=csydGn/7BD/hARHg0LOa5fdhTb/AEwCDcfkYU2foV64=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XrSEttDP9cKf4lUDrLe1BpD3/j6oEBVZLxnfs1MiuTnKgqXdwyQ7o/YIBBn37RSuA gbD3HGvwJmUrzTP21wLdIGQFx0ycwJnDIUtTYcLINs0lccvOXs6r0B88eK9ZdWIIzD d7+BA/bNUmLcDDhrxbaBzqX6ksRyA/Fyb5vbSzS4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 31 Aug 2026 18:05:00 +0200 Subject: [PATCH 2/3] selftests/nolibc: validate ENOTDIR return values from opendir()/fdopendir() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260831-nolibc-fdopendir-enotdir-v1-2-8cf0e79c4e6f@weissschuh.net> References: <20260831-nolibc-fdopendir-enotdir-v1-0-8cf0e79c4e6f@weissschuh.net> In-Reply-To: <20260831-nolibc-fdopendir-enotdir-v1-0-8cf0e79c4e6f@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788192306; l=1955; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=csydGn/7BD/hARHg0LOa5fdhTb/AEwCDcfkYU2foV64=; b=Wy/IFc6G1MHqNxXW0zXuiHZ8F6SR4plymt6rK/IhXTn1MvVLtv5avY8zlrcx5MV0pfT8E5zVR fPytW+LA/F2DjIrf2U6dd8xA5uqM7zkWwJ/Q/xIGBI14CabImKujq/0 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Make sure that ENOTDIR is detected already during directory opening. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 0a8fe5100b7f..7091f63f3b25 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1711,6 +1711,7 @@ int run_syscall(int min, int max) CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0]= =3D (char []){"/"}, [1] =3D NULL }, NULL), -1, EACCES); break; CASE_TEST(fchdir_stdin); EXPECT_SYSER(1, fchdir(STDIN_FILENO), -1, = ENOTDIR); break; CASE_TEST(fchdir_badfd); EXPECT_SYSER(1, fchdir(-1), -1, EBADF); br= eak; + CASE_TEST(fdopendir_notdir); EXPECT_SYSER(1, (uintptr_t)fdopendir(STDIN= _FILENO), (uintptr_t)NULL, ENOTDIR); break; CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break; CASE_TEST(file_stream_wsr); EXPECT_SYSZR(1, test_file_stream_wsr()); b= reak; CASE_TEST(fork); EXPECT_SYSZR(1, test_fork(FORK_STANDARD));= break; @@ -1739,6 +1740,7 @@ int run_syscall(int min, int max) CASE_TEST(open_blah); EXPECT_SYSER(1, tmp =3D open("/proc/self/b= lah", O_RDONLY), -1, ENOENT); if (tmp !=3D -1) close(tmp); break; CASE_TEST(openat_dir); EXPECT_SYSZR(1, test_openat()); break; CASE_TEST(open_mode); EXPECT_SYSZR(1, test_open_mode()); break; + CASE_TEST(opendir_notdir); EXPECT_SYSER(1, (uintptr_t)opendir("/dev/s= tdin"), (uintptr_t)NULL, ENOTDIR); break; CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break; CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds =3D {= 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break; --=20 2.55.0 From nobody Sat Sep 26 14:40:04 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46726476682; Mon, 31 Aug 2026 16:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788192310; cv=none; b=NQtJb/KlXMnlZAuRAWlYwYb6X/xLXhFrFCuwwRTH27DgqxYcwOW+izC3lpfZ4T91ark8E0NA/sDBz0+cEH4Nny5CFMxx0Wn6YsyV95uxlUnq+8Lo3lj9sr7SpOLJUX3r0bezz0Enctge0/0C5rEc1eN6FYbAfAT2tbsK2CBpSSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788192310; c=relaxed/simple; bh=ZYmXFyHdd5TM6cOUG7845M3ywPJUvD+s+gdsFx1U5ZY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ULsLWhZxssOKBK3cqvf6N9KOhNZhOJIoWare5nGupTRWvc/jHQcL1qUzYhD8HjQAvibWeHTpWt9v3CZzln5PHakSjvI240S3zWBvE/49llKD+qzN2iE5kSqdh6ALGq2ym9uKwQV5YfpiF3kxH5you2Lt4lPGHMbIMV+L83VfOEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=D0Z51uHR; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="D0Z51uHR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1788192307; bh=ZYmXFyHdd5TM6cOUG7845M3ywPJUvD+s+gdsFx1U5ZY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=D0Z51uHR9bTCyFQspuODpdXwN66AyhECdKiiM22O+Qo7TnTcSFnQtNnI/NCEGWco9 feZY5/d3ogKQ3pm0f8Hhu38LoO5jVOw9SXkWD31oFmlGLFuwm9Kj/eyaX2aLRzxKIO VuJNBKvwEJjU6I4U4QTPk+7mhECE7FJ9kIkX05Ns= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 31 Aug 2026 18:05:01 +0200 Subject: [PATCH 3/3] tools/nolibc: validate directory with O_DIRECTORY in opendir() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260831-nolibc-fdopendir-enotdir-v1-3-8cf0e79c4e6f@weissschuh.net> References: <20260831-nolibc-fdopendir-enotdir-v1-0-8cf0e79c4e6f@weissschuh.net> In-Reply-To: <20260831-nolibc-fdopendir-enotdir-v1-0-8cf0e79c4e6f@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788192306; l=896; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=ZYmXFyHdd5TM6cOUG7845M3ywPJUvD+s+gdsFx1U5ZY=; b=WSMM0vmDTPqJO9nSR9MkfqUXuyO9aJ+5CVOfUbLF9UrM4ylOyXVucqpZbgNhJZRczZNsHisFI JlGOZ8wmqbLC9Yn1ykJh3Zdj8M32EsfoBurAGJwRtJg8gXMIGS4yoej X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= fdopendir() requires a call to fstat() to determine if the opened file is a directory. Currently opendir() inherits this extra syscall. Switch to O_DIRECTORY and remove the call to fdopendir() in opendir() to make the directory type check cheaper. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Willy Tarreau --- tools/include/nolibc/dirent.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h index 25fbff208998..2dbf4052b85a 100644 --- a/tools/include/nolibc/dirent.h +++ b/tools/include/nolibc/dirent.h @@ -55,10 +55,11 @@ DIR *opendir(const char *name) { int fd; =20 - fd =3D open(name, O_RDONLY); + fd =3D open(name, O_RDONLY | O_DIRECTORY); if (fd =3D=3D -1) return NULL; - return fdopendir(fd); + + return (DIR *)(intptr_t)~fd; } =20 static __attribute__((unused)) --=20 2.55.0