Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/netbsd32 Unfortunately all the clockctl ioctls co...



details:   https://anonhg.NetBSD.org/src/rev/d79a1e4b55f0
branches:  trunk
changeset: 745910:d79a1e4b55f0
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Mar 16 01:37:51 2020 +0000

description:
Unfortunately all the clockctl ioctls contain pointers to structs instead
of the structs themselves, so they need special handling. Undo previous
and do the permissions checks explicitly. It would be better to fix the
clockctl ioctls to contain the structs themselves...

diffstat:

 sys/compat/netbsd32/netbsd32_ioctl.c |  85 ++++++++++++++++++++++++++++++++++-
 1 files changed, 81 insertions(+), 4 deletions(-)

diffs (148 lines):

diff -r 4671fb9a7def -r d79a1e4b55f0 sys/compat/netbsd32/netbsd32_ioctl.c
--- a/sys/compat/netbsd32/netbsd32_ioctl.c      Mon Mar 16 00:05:29 2020 +0000
+++ b/sys/compat/netbsd32/netbsd32_ioctl.c      Mon Mar 16 01:37:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_ioctl.c,v 1.111 2020/03/16 00:05:29 christos Exp $    */
+/*     $NetBSD: netbsd32_ioctl.c,v 1.112 2020/03/16 01:37:51 christos Exp $    */
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.111 2020/03/16 00:05:29 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.112 2020/03/16 01:37:51 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ntp.h"
@@ -64,6 +64,10 @@
 #include <sys/drvctlio.h>
 #include <sys/compat_stub.h>
 
+#include <sys/vnode.h>
+#include <sys/conf.h>
+#include <miscfs/specfs/specdev.h>
+
 #ifdef __sparc__
 #include <dev/sun/fbio.h>
 #include <machine/openpromio.h>
@@ -498,6 +502,7 @@
        p->tp = NETBSD32PTR64(s32p->tp);
 }
 
+#ifdef NTP
 static inline void
 netbsd32_to_clockctl_ntp_adjtime(
     const struct netbsd32_clockctl_ntp_adjtime *s32p,
@@ -507,6 +512,7 @@
        p->tp = NETBSD32PTR64(s32p->tp);
        p->retval = s32p->retval;
 }
+#endif
 
 static inline void
 netbsd32_to_ksyms_gsymbol(const struct netbsd32_ksyms_gsymbol *s32p,
@@ -945,6 +951,7 @@
        NETBSD32PTR32(s32p->tp, p->tp);
 }
 
+#ifdef NTP
 static inline void
 netbsd32_from_clockctl_ntp_adjtime(const struct clockctl_ntp_adjtime *p,
     struct netbsd32_clockctl_ntp_adjtime *s32p, u_long cmd)
@@ -953,6 +960,7 @@
        NETBSD32PTR32(s32p->tp, p->tp);
        s32p->retval = p->retval;
 }
+#endif
 
 static inline void
 netbsd32_from_ksyms_gsymbol( const struct ksyms_gsymbol *p,
@@ -1035,6 +1043,51 @@
        s32p->dkwl_ncopied = p->dkwl_ncopied;
 }
 
+#ifdef NTP
+static int
+netbsd32_do_clockctl_ntp_adjtime(struct file *fp,
+    struct clockctl_ntp_adjtime *args)
+{
+       struct vnode *vp;
+       struct specnode *sn;
+       const char *name;
+
+       struct netbsd32_timex ntv32;
+       struct timex ntv;
+       int error;
+
+       /* Verify that the file descriptor is is to the clockctl device */
+       if (fp->f_type != DTYPE_VNODE)
+               return EINVAL;
+
+       vp = fp->f_vnode;
+       if (vp->v_type != VCHR)
+               return EINVAL;
+
+       sn = vp->v_specnode;
+       name = cdevsw_getname(major(sn->sn_rdev));
+       if (name == NULL || strcmp(name, "clockctl") != 0)
+               return EINVAL;
+
+       if (vec_ntp_adjtime1 == NULL)
+               return EINVAL;
+
+       error = copyin(args->tp, &ntv32, sizeof(ntv32));
+       if (error)
+               return error;
+
+       netbsd32_to_timex(&ntv32, &ntv);
+       (*vec_ntp_adjtime1)(&ntv);
+       netbsd32_from_timex(&ntv, &ntv32);
+
+       error = copyout(&ntv32, args->tp, sizeof(ntv32));
+       if (error == 0)
+               args->retval = ntp_timestatus();
+
+       return error;
+}
+#endif
+
 /*
  * main ioctl syscall.
  *
@@ -1425,8 +1478,32 @@
                IOCTL_STRUCT_CONV_TO(CLOCKCTL_CLOCK_SETTIME,
                    clockctl_clock_settime);
        case CLOCKCTL_NTP_ADJTIME32:
-               IOCTL_STRUCT_CONV_TO(CLOCKCTL_NTP_ADJTIME,
-                   clockctl_ntp_adjtime);
+#ifdef NTP
+               {
+                       size = IOCPARM_LEN(CLOCKCTL_NTP_ADJTIME);
+                       if (size > sizeof(stkbuf))
+                               data = memp = kmem_alloc(size, KM_SLEEP);
+                       else
+                               data = (void *)stkbuf;
+
+                       netbsd32_to_clockctl_ntp_adjtime(
+                               (const struct netbsd32_clockctl_ntp_adjtime *)data32,
+                               (struct clockctl_ntp_adjtime *)data,
+                               CLOCKCTL_NTP_ADJTIME);
+                       error = netbsd32_do_clockctl_ntp_adjtime(fp,
+                               (struct clockctl_ntp_adjtime *)data);
+                       netbsd32_from_clockctl_ntp_adjtime(
+                               (const struct clockctl_ntp_adjtime *)data,
+                               (struct netbsd32_clockctl_ntp_adjtime *)data32,
+                               CLOCKCTL_NTP_ADJTIME);
+
+                       break;
+               }
+#else
+               error = ENOTTY;
+               break;
+#endif /* NTP */
+
        case KIOCGSYMBOL32:
                IOCTL_STRUCT_CONV_TO(KIOCGSYMBOL, ksyms_gsymbol);
        case KIOCGVALUE32:



Home | Main Index | Thread Index | Old Index