From: Jens Axboe Date: Wed, 7 Dec 2022 16:23:06 +0000 (-0700) Subject: eventpoll: ensure we pass back -EBADF for a bad file descriptor X-Git-Tag: epoll-min_ts-2022-12-08^0 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=refs%2Fheads%2Fepoll-min_ts;p=linux-2.6-block.git eventpoll: ensure we pass back -EBADF for a bad file descriptor A previous commit moved file checking earlier in epoll_ctl(), and as a result, we now have error == -EINVAL going into the test case for whether or not the passed in target file is valid or not. This should be -EBADF as per earlier, assign it correctly, otherwise epoll_ctl02 from LTP correctly identifies this bad return value: epoll_ctl02.c:87: TFAIL: epoll_clt(...) if fd is an invalid fd expected EBADF: EINVAL (22) Fixes: 3fe64a3a96d4 ("eventpoll: move file checking earlier for epoll_ctl()") Reported-by: Linux Kernel Functional Testing Tested-by: Anders Roxell Signed-off-by: Jens Axboe --- diff --git a/fs/eventpoll.c b/fs/eventpoll.c index ec7ffce8265a..de9c551e1993 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -2195,6 +2195,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, } /* Get the "struct file *" for the target file */ + error = -EBADF; tf = fdget(fd); if (!tf.file) goto error_fput;