Hello, p9_client_write() loops until the input iterator is drained. It rejects a reply count larger than the request, but accepts a zero count for a non-empty TWRITE. With written == 0 the revert is a no-op, total and offset do not change, and the loop sends the same TWRITE again. A 9p server that keeps returning RWRITE.count = 0 therefore keeps the caller in the kernel without making progress. The same zero-count reply is also accepted by p9_client_write_subreq(). There it reaches netfs_write_subrequest_terminated() as a successful zero-byte transfer, which can make netfs reissue the write instead of failing it. The trigger is a userland 9p2000.L server plus a mount and a single write(2). It is transport independent: the loop is in the generic client, so trans=fd, trans=tcp, trans=unix and virtio-9p all reach it. This is a client-side denial of service. No memory corruption or privilege escalation is demonstrated. While the server keeps returning zero, the write syscall does not return and the task stays runnable; signal delivery is delayed by the p9_client_rpc() signal window, but the task is not claimed to be unconditionally unkillable. Reject a zero count with -EIO in both RWRITE consumers. -EIO matches the existing oversize-reply handling, and the iterator is reverted by the same amount used on the existing error path. The subreq helper also gets the matching check, plus a corrected format specifier and debug argument. The existing oversize guard is from 0f1db7dee200, but that change did not add a zero-progress check to the write loop. HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7 source version: Linux 7.4.0-rc4 compiler: gcc 11.4.0, GNU ld 2.38 QEMU: 6.2.0, x86-64 TCG Console output: https://gist.githubusercontent.com/ForestHYS/70035ab30ea46b90730d6e0e3be0e7d0/raw/95c18276df3c9f7da92fa86e1033c6ca5d110a21/console-output.txt Kernel config: https://gist.githubusercontent.com/ForestHYS/70035ab30ea46b90730d6e0e3be0e7d0/raw/95c18276df3c9f7da92fa86e1033c6ca5d110a21/kernel-config.txt PoC source: https://gist.githubusercontent.com/ForestHYS/70035ab30ea46b90730d6e0e3be0e7d0/raw/95c18276df3c9f7da92fa86e1033c6ca5d110a21/poc.c Init harness: https://gist.githubusercontent.com/ForestHYS/70035ab30ea46b90730d6e0e3be0e7d0/raw/95c18276df3c9f7da92fa86e1033c6ca5d110a21/init.c Fixed-kernel console: https://gist.githubusercontent.com/ForestHYS/70035ab30ea46b90730d6e0e3be0e7d0/raw/95c18276df3c9f7da92fa86e1033c6ca5d110a21/fixed-console-output.txt To reproduce, build the test kernel from the commit above with the attached config: mkdir -p build cp kernel-config.txt build/.config make O=build olddefconfig make O=build -j"$(nproc)" bzImage Compile the PoC and the init harness, then create an initramfs: gcc -static -O2 -Wall -Wextra -Werror -o verify9p poc.c gcc -static -O2 -Wall -Wextra -o init init.c mkdir -p rootfs/bin rootfs/dev rootfs/proc rootfs/sys rootfs/tmp \ rootfs/mnt/a rootfs/mnt/b rootfs/mnt/c rootfs/mnt/d cp verify9p init rootfs/ chmod 0755 rootfs/init rootfs/verify9p (cd rootfs && find . -print0 | cpio --null -o -H newc | \ gzip -9) > initramfs.cpio.gz Boot the guest: qemu-system-x86_64 -machine q35 -cpu max -smp 2 -m 2048 \ -kernel build/arch/x86/boot/bzImage \ -initrd initramfs.cpio.gz \ -append 'console=ttyS0 loglevel=7 rdinit=/init panic=1 oops=panic' \ -nographic -no-reboot -monitor none -display none The init harness runs zero-kill, zero-fix, exact-count control and oversize control. The attached config enables CONFIG_NET_9P, CONFIG_NET_9P_FD and CONFIG_9P_FS. On the unmodified kernel the zero-kill run established 36 identical TWRITEs and kept issuing them after SIGKILL: the log shows SIGKILL_PENDING with the writer still alive and twrites growing from 38 to 4562. The exact-count control completed with one TWRITE and a 4096-byte write; the oversize control returned EIO after one TWRITE. With this patch the zero-count scenarios return EIO immediately ("bogus RWRITE count 0 for non-empty TWRITE"), while the exact-count and oversize controls keep their previous results. Fixes: 070b3656cf22 ("9p: switch p9_client_write() to passing it struct iov_iter *") Fixes: 5fb70e7275a6 ("netfs, 9p: Implement helpers for new write code") Cc: stable@vger.kernel.org Signed-off-by: ForestHYS --- Validation: scripts/checkpatch.pl --no-tree --strict reports no errors or warnings, and git apply --check succeeds. The patched kernel was built and booted in QEMU; zero-kill and zero-fix returned EIO, and the exact-count and oversize controls passed. diff --git a/net/9p/client.c b/net/9p/client.c index e63e8c2a8..dd90490f8 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1551,6 +1551,13 @@ p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err) p9_req_put(clnt, req); break; } + if (!written) { + pr_err("bogus RWRITE count 0 for non-empty TWRITE\n"); + *err = -EIO; + iov_iter_revert(from, count - iov_iter_count(from)); + p9_req_put(clnt, req); + break; + } p9_debug(P9_DEBUG_9P, "<<< RWRITE count %u\n", written); @@ -1600,11 +1607,14 @@ p9_client_write_subreq(struct netfs_io_subrequest *subreq) } if (written > len) { - pr_err("bogus RWRITE count (%d > %u)\n", written, len); + pr_err("bogus RWRITE count (%d > %d)\n", written, len); + written = -EIO; + } else if (len > 0 && written <= 0) { + pr_err("bogus RWRITE count %d for non-empty TWRITE\n", written); written = -EIO; } - p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", len); + p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", written); p9_req_put(clnt, req); netfs_write_subrequest_terminated(subreq, written); Thanks, Forest Huang