From bbf221e3e822d15dafb37bd8e200a9864f2636b4 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Mon, 25 Dec 2023 20:43:06 -0500 Subject: [PATCH] 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;