On Sun, 09 Jul 2023 14:54:51 +0800, wenyang.linux@xxxxxxxxxxx wrote: > For eventfd with flag EFD_SEMAPHORE, when its ctx->count is 0, calling > eventfd_ctx_do_read will cause ctx->count to overflow to ULLONG_MAX. > > I've tweaked the commit message to explain how an underflow can happen. And for now I dropped that bit: diff --git a/fs/eventfd.c b/fs/eventfd.c index 10a101df19cd..33a918f9566c 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c @@ -269,8 +269,6 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c return -EFAULT; if (ucnt == ULLONG_MAX) return -EINVAL; - if ((ctx->flags & EFD_SEMAPHORE) && !ucnt) - return -EINVAL; spin_lock_irq(&ctx->wqh.lock); res = -EAGAIN; if (ULLONG_MAX - ctx->count > ucnt) because I don't yet understand why that should be forbidden. Please explain the reason for wanting that check in there and I can add it back. I might just be missing the obvious. --- Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon. Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it. It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated. Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch. tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.misc [1/1] eventfd: prevent underflow for eventfd semaphores https://git.kernel.org/vfs/vfs/c/7b2edd278691