Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Apr 2022 02:45:17 GMT
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: be6abdb25956 - stable/13 - GEOM: Skip copyin() for GCTL_PARAM_WR parameters.
Message-ID:  <202204060245.2362jHAQ006439@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by mav:

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

commit be6abdb259564d9a8d3d91d486b7ed2331c3bec4
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-03-07 15:57:56 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-04-06 02:07:39 +0000

    GEOM: Skip copyin() for GCTL_PARAM_WR parameters.
    
    Kernel does not read those parameters, so copyin is pointless.
    
    While there, replace some KASSERT()s with CTASSERT()s.
    
    MFC after:      1 month
    
    (cherry picked from commit 01b9c48b5dec8d4a1161e0592f04b3301c81a1f8)
---
 sys/geom/geom_ctl.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c
index b0e2673bdc42..5690b857a639 100644
--- a/sys/geom/geom_ctl.c
+++ b/sys/geom/geom_ctl.c
@@ -63,16 +63,15 @@ static struct cdevsw g_ctl_cdevsw = {
 	.d_name =	"g_ctl",
 };
 
+CTASSERT(GCTL_PARAM_RD == VM_PROT_READ);
+CTASSERT(GCTL_PARAM_WR == VM_PROT_WRITE);
+
 void
 g_ctl_init(void)
 {
 
 	make_dev_credf(MAKEDEV_ETERNAL, &g_ctl_cdevsw, 0, NULL,
 	    UID_ROOT, GID_OPERATOR, 0640, PATH_GEOM_CTL);
-	KASSERT(GCTL_PARAM_RD == VM_PROT_READ,
-		("GCTL_PARAM_RD != VM_PROT_READ"));
-	KASSERT(GCTL_PARAM_WR == VM_PROT_WRITE,
-		("GCTL_PARAM_WR != VM_PROT_WRITE"));
 }
 
 /*
@@ -169,14 +168,18 @@ gctl_copyin(struct gctl_req *req)
 			gctl_error(req, "negative param length");
 			break;
 		}
-		p = geom_alloc_copyin(req, ap[i].value, ap[i].len);
-		if (p == NULL)
-			break;
-		if ((ap[i].flag & GCTL_PARAM_ASCII) &&
-		    p[ap[i].len - 1] != '\0') {
-			gctl_error(req, "unterminated param value");
-			g_free(p);
-			break;
+		if (ap[i].flag & GCTL_PARAM_RD) {
+			p = geom_alloc_copyin(req, ap[i].value, ap[i].len);
+			if (p == NULL)
+				break;
+			if ((ap[i].flag & GCTL_PARAM_ASCII) &&
+			    p[ap[i].len - 1] != '\0') {
+				gctl_error(req, "unterminated param value");
+				g_free(p);
+				break;
+			}
+		} else {
+			p = g_malloc(ap[i].len, M_WAITOK | M_ZERO);
 		}
 		ap[i].kvalue = p;
 		ap[i].flag |= GCTL_PARAM_VALUEKERNEL;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202204060245.2362jHAQ006439>