[PATCH] qnx6: make directory scans interruptible

From: shaos

Date: Thu Nov 26 2026 - 07:29:04 EST


Hello,

qnx6_iget() copies the on-disk directory size directly to
i_size. qnx6_readdir() uses that value to walk every directory page.
When the entries are empty, the loop does not call dir_emit(), so the
usual readdir signal check is not reached. A crafted image with an
extremely large root directory size can keep getdents64() in the
kernel for an effectively unbounded scan; a pending SIGKILL does not
stop the task.

Check for fatal signals and yield between pages. This lets the syscall
return when the task is killed and lets other tasks run during a long
scan. It does not impose an arbitrary maximum directory size.

The trigger requires mounting a crafted QNX6 block image, which needs
CAP_SYS_ADMIN and access to a block device. The issue is a local
availability problem; no memory corruption or privilege escalation
is demonstrated.

HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
source version: Linux 7.4.0-rc4-g8d7fe9885c62
compiler: gcc 11.4.0, GNU ld 2.38

The Gist contains the complete console output, kernel configuration,
and self-contained userland PoC:
https://gist.githubusercontent.com/shaos26/32f8b37dc46e147d763c0ab8bd52c725/raw/dcf72b32e927cb5ffd34277d7add093a8d77a595/console-output.txt
https://gist.githubusercontent.com/shaos26/32f8b37dc46e147d763c0ab8bd52c725/raw/dcf72b32e927cb5ffd34277d7add093a8d77a595/kernel-config.txt
https://gist.githubusercontent.com/shaos26/32f8b37dc46e147d763c0ab8bd52c725/raw/dcf72b32e927cb5ffd34277d7add093a8d77a595/poc.c

Build the kernel from the HEAD commit above with kernel-config.txt.
Build the static PoC and initramfs, then boot it in QEMU:

mkdir -p root
gcc -O2 -static -Wall -Wextra -o root/init poc.c
chmod 0755 root/init
(cd root && find . -print0 | cpio --null -o -H newc |
gzip -9) > initramfs.cpio.gz
timeout -k 2 30 qemu-system-x86_64 -m 2048 -smp 2 \
-kernel linux/build/arch/x86/boot/bzImage \
-initrd initramfs.cpio.gz \
-append 'console=ttyS0 loglevel=7' \
-display none -serial file:qnx6.log -monitor none -no-reboot

The PoC constructs the filesystem images and runs the normal-size,
small-buffer, and huge-directory cases. The unpatched run leaves the
getdents64 child in state R after SIGKILL, with CPU ticks increasing.
With this patch, the same call returns after SIGKILL and the child
exits; all mount and small-buffer controls still pass.

Fixes: 5d026c724220 ("fs: initial qnx6fs addition")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: shaos <shawnq1@xxxxxxx>
---
fs/qnx6/dir.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/qnx6/dir.c b/fs/qnx6/dir.c
index 56bbaffe4b444..90473375e6ca1 100644
--- a/fs/qnx6/dir.c
+++ b/fs/qnx6/dir.c
@@ -12,6 +12,7 @@
*/

#include <linux/filelock.h>
+#include <linux/sched/signal.h>
#include "qnx6.h"

static unsigned qnx6_lfile_checksum(char *name, unsigned size)
@@ -131,9 +132,15 @@ static int qnx6_readdir(struct file *file, struct dir_context *ctx)
for ( ; !done && n < npages; n++, offset = 0) {
struct qnx6_dir_entry *de;
struct folio *folio;
- char *kaddr = qnx6_get_folio(inode, n, &folio);
+ char *kaddr;
struct qnx6_dir_entry *limit;

+ if (fatal_signal_pending(current))
+ return -EINTR;
+ cond_resched();
+
+ kaddr = qnx6_get_folio(inode, n, &folio);
+
if (IS_ERR(kaddr)) {
pr_err("%s(): read failed\n", __func__);
ctx->pos = (n + 1) << PAGE_SHIFT;
--
2.43.0