From 9e02ef474f8caa833d6a1b5e0068d5323a57e8c4 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 13 Feb 2020 13:36:32 +0000 Subject: [PATCH] LU-12198 libcfs: always copy ioctl header back to user lnetctl_get_peer_list fills back the required size in header if the given buffer was too small. Userspace needs the info back to grow the buffer and try again. Note we only replace err on failure if err was previously not set Fixes: fba98579efc4 ("LU-6202 libcfs: replace libcfs_register_ioctl with a blocking notifier_chain") Signed-off-by: Dominique Martinet Change-Id: I2b6e319aceeb00d488572053d27023891afe1928 Reviewed-on: https://review.whamcloud.com/37559 Tested-by: jenkins Reviewed-by: Yang Sheng Reviewed-by: James Simmons Reviewed-by: Neil Brown Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/libcfs/module.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index d925a6c..bb6abb6 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -224,9 +224,8 @@ static int libcfs_ioctl(unsigned long cmd, void __user *uparam) err = -EINVAL; else err = notifier_to_errno(err); - if (!err) - if (copy_to_user(uparam, hdr, hdr->ioc_len)) - err = -EFAULT; + if (copy_to_user(uparam, hdr, hdr->ioc_len) && !err) + err = -EFAULT; break; } out: -- 1.8.3.1