git: bbf221e3e822 - main - geom: Report copyout() errors in g_ctl_ioctl_ctl()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 26 Dec 2023 02:04:31 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=bbf221e3e822d15dafb37bd8e200a9864f2636b4

commit bbf221e3e822d15dafb37bd8e200a9864f2636b4
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-26 01:43:06 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-26 02:04:01 +0000

    geom: Report copyout() errors in g_ctl_ioctl_ctl()
    
    Despite the name, req->serror is used in some cases to copy non-error
    messages to userspace.  So, report errors when copying out so long as
    they don't clobber an earlier error.
    
    Reviewed by:    mav, imp
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43146
---
 sys/geom/geom_ctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c
index ebfde5697eeb..5536bd6b7110 100644
--- a/sys/geom/geom_ctl.c
+++ b/sys/geom/geom_ctl.c
@@ -616,8 +616,10 @@ g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct th
 		}
 	}
 	if (sbuf_done(req->serror)) {
-		copyout(sbuf_data(req->serror), req->error,
+		nerror = copyout(sbuf_data(req->serror), req->error,
 		    imin(req->lerror, sbuf_len(req->serror) + 1));
+		if (nerror != 0 && req->nerror == 0)
+			req->nerror = nerror;
 	}
 
 	nerror = req->nerror;