diff mbox series

[v2,01/15] pidfs: switch to copy_struct_to_user()

Message ID 20250304-work-pidfs-kill_on_last_close-v2-1-44fdacfaa7b7@kernel.org (mailing list archive)
State New
Headers show
Series pidfs: provide information after task has been reaped | expand

Commit Message

Christian Brauner March 4, 2025, 9:41 a.m. UTC
We have a helper that deals with all the required logic.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/pidfs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Jeff Layton March 4, 2025, 12:42 p.m. UTC | #1
On Tue, 2025-03-04 at 10:41 +0100, Christian Brauner wrote:
> We have a helper that deals with all the required logic.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/pidfs.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/fs/pidfs.c b/fs/pidfs.c
> index 049352f973de..aa8c8bda8c8f 100644
> --- a/fs/pidfs.c
> +++ b/fs/pidfs.c
> @@ -276,10 +276,7 @@ static long pidfd_info(struct task_struct *task, unsigned int cmd, unsigned long
>  	 * userspace knows about will be copied. If userspace provides a new
>  	 * struct, only the bits that the kernel knows about will be copied.
>  	 */
> -	if (copy_to_user(uinfo, &kinfo, min(usize, sizeof(kinfo))))
> -		return -EFAULT;
> -
> -	return 0;
> +	return copy_struct_to_user(uinfo, usize, &kinfo, sizeof(kinfo), NULL);
>  }
>  
>  static bool pidfs_ioctl_valid(unsigned int cmd)
> 

Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/fs/pidfs.c b/fs/pidfs.c
index 049352f973de..aa8c8bda8c8f 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -276,10 +276,7 @@  static long pidfd_info(struct task_struct *task, unsigned int cmd, unsigned long
 	 * userspace knows about will be copied. If userspace provides a new
 	 * struct, only the bits that the kernel knows about will be copied.
 	 */
-	if (copy_to_user(uinfo, &kinfo, min(usize, sizeof(kinfo))))
-		return -EFAULT;
-
-	return 0;
+	return copy_struct_to_user(uinfo, usize, &kinfo, sizeof(kinfo), NULL);
 }
 
 static bool pidfs_ioctl_valid(unsigned int cmd)