Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F171978806
D59591.id186512.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D59591.id186512.diff
View Options
diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c
--- a/sys/geom/geom_ctl.c
+++ b/sys/geom/geom_ctl.c
@@ -39,6 +39,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
+#include <sys/fcntl.h>
#include <sys/malloc.h>
#include <sys/sbuf.h>
#include <sys/stdarg.h>
@@ -552,18 +553,28 @@
g_free(gps);
}
+struct g_ctl_req_args {
+ struct gctl_req *req;
+ int fflag;
+};
+
static void
g_ctl_req(void *arg, int flag __unused)
{
+ struct g_ctl_req_args *args = arg;
+ struct gctl_req *req = args->req;
struct g_class *mp;
- struct gctl_req *req;
char const *verb;
+ int fflag = args->fflag;
g_topology_assert();
- req = arg;
mp = gctl_get_class(req, "class");
if (mp == NULL)
return;
+ if ((fflag & FREAD) == 0) {
+ gctl_error(req, "Permission denied");
+ return;
+ }
verb = gctl_get_param(req, "verb", NULL);
if (verb == NULL) {
gctl_error(req, "Verb missing");
@@ -574,18 +585,22 @@
} else if (mp->ctlreq == NULL) {
gctl_error(req, "Class takes no requests");
} else {
+ if ((fflag & FWRITE) == 0) {
+ gctl_error(req, "Permission denied");
+ return;
+ }
mp->ctlreq(req, mp, verb);
}
g_topology_assert();
}
static int
-g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
+g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, void *data, int fflag, struct thread *td)
{
- struct gctl_req *req;
+ struct g_ctl_req_args args = { .req = data, .fflag = fflag };
+ struct gctl_req *req = data;
int nerror;
- req = (void *)data;
req->nerror = 0;
/* It is an error if we cannot return an error text */
if (req->lerror < 2)
@@ -606,7 +621,7 @@
gctl_dump(req, "request");
if (!req->nerror) {
- g_waitfor_event(g_ctl_req, req, M_WAITOK, NULL);
+ g_waitfor_event(g_ctl_req, &args, M_WAITOK, NULL);
if (g_debugflags & G_F_CTLDUMP)
gctl_dump(req, "result");
@@ -631,9 +646,21 @@
{
int error;
- switch(cmd) {
+#ifdef COMPAT_FREEBSD14
+ /*
+ * Prior to FreeBSD 15, read access to geom.ctl granted full
+ * access to all GEOM verbs, and libgeom opened geom.ctl O_RDONLY.
+ * To avoid putting the user in a situation where their older
+ * binaries cannot configure GEOM on a newer kernel, we set the
+ * FWRITE bit if it was not already set, but only for the
+ * superuser.
+ */
+ if ((fflag & FWRITE) == 0 && priv_check(td, PRIV_IO) == 0)
+ fflag |= FWRITE;
+#endif /* COMPAT_FREEBSD14 */
+ switch (cmd) {
case GEOM_CTL:
- error = g_ctl_ioctl_ctl(dev, cmd, data, fflag, td);
+ error = g_ctl_ioctl_ctl(dev, cmd, (void *)data, fflag, td);
break;
default:
error = ENOIOCTL;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Sep 16, 2:34 AM (2 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38855945
Default Alt Text
D59591.id186512.diff (2 KB)
Attached To
Mode
D59591: geom: Check file flags before handling control request
Attached
Detach File
Event Timeline
Log In to Comment