Re: [PATCH v1 2/2] epoll: Use __user_write_access_begin() and unsafe_put_user() in epoll_put_uevent().

Dave Hansen
2025-10-23T19:41:01Z

On 10/22/25 17:04, Kuniyuki Iwashima wrote:
> --- a/include/linux/eventpoll.h
> +++ b/include/linux/eventpoll.h
> @@ -82,11 +82,14 @@ static inline struct epoll_event __user *
> epoll_put_uevent(__poll_t revents, __u64 data,
> struct epoll_event __user *uevent)
> {
> - if (__put_user(revents, &uevent->events) ||
> - __put_user(data, &uevent->data))
> - return NULL;
> -
> - return uevent+1;
> + __user_write_access_begin(uevent, sizeof(*uevent));
> + unsafe_put_user(revents, &uevent->events, efault);
> + unsafe_put_user(data, &uevent->data, efault);
> + user_access_end();
> + return uevent + 1;
> +efault:
> + user_access_end();
> + return NULL;
> }
> #endif

This makes me nervous. The access_ok() check is quite a distance away.
I'd kinda want to see some performance numbers before doing this. Is
removing a single access_ok() even measurable?

Also, even if we go do this, shouldn't __user_write_access_begin() be
called something more like unsafe_user_write_access_begin()?