diff --git a/sys/amd64/linux32/syscalls.master b/sys/amd64/linux32/syscalls.master index 99c9cb238053..4fa88e5289ac 100644 --- a/sys/amd64/linux32/syscalls.master +++ b/sys/amd64/linux32/syscalls.master @@ -113,7 +113,7 @@ 51 AUE_ACCT MNOPROTO { int acct(char *path); } 52 AUE_UMOUNT MSTD { int linux_umount(char *path, l_int flags); } 53 AUE_NULL UNIMPL lock -54 AUE_IOCTL STD { int linux_ioctl(l_uint fd, l_uint cmd, \ +54 AUE_IOCTL MSTD { int linux_ioctl(l_uint fd, l_uint cmd, \ uintptr_t arg); } 55 AUE_FCNTL MSTD { int linux_fcntl(l_uint fd, l_uint cmd, \ uintptr_t arg); } diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c index 96ebcc57aae5..09e1cc0366b7 100644 --- a/sys/compat/linux/linux_ioctl.c +++ b/sys/compat/linux/linux_ioctl.c @@ -43,7 +43,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include +#include #include #include #include @@ -51,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -126,6 +129,8 @@ struct handler_element static TAILQ_HEAD(, handler_element) handlers = TAILQ_HEAD_INITIALIZER(handlers); +static struct sx linux_ioctl_sx; +SX_SYSINIT(linux_ioctl, &linux_ioctl_sx, "linux ioctl handlers"); /* * hdio related ioctls for VMWare support @@ -2571,15 +2576,21 @@ linux_ioctl(struct thread *td, struct linux_ioctl_args *args) /* Iterate over the ioctl handlers */ cmd = args->cmd & 0xffff; + sx_slock(&linux_ioctl_sx); + mtx_lock(&Giant); TAILQ_FOREACH(he, &handlers, list) { if (cmd >= he->low && cmd <= he->high) { error = (*he->func)(td, args); if (error != ENOIOCTL) { + mtx_unlock(&Giant); + sx_sunlock(&linux_ioctl_sx); fdrop(fp, td); return (error); } } } + mtx_unlock(&Giant); + sx_sunlock(&linux_ioctl_sx); fdrop(fp, td); linux_msg(td, "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented", @@ -2601,6 +2612,7 @@ linux_ioctl_register_handler(struct linux_ioctl_handler *h) * Reuse the element if the handler is already on the list, otherwise * create a new element. */ + sx_xlock(&linux_ioctl_sx); TAILQ_FOREACH(he, &handlers, list) { if (he->func == h->func) break; @@ -2621,10 +2633,12 @@ linux_ioctl_register_handler(struct linux_ioctl_handler *h) TAILQ_FOREACH(cur, &handlers, list) { if (cur->span > he->span) { TAILQ_INSERT_BEFORE(cur, he, list); + sx_xunlock(&linux_ioctl_sx); return (0); } } TAILQ_INSERT_TAIL(&handlers, he, list); + sx_xunlock(&linux_ioctl_sx); return (0); } @@ -2637,13 +2651,16 @@ linux_ioctl_unregister_handler(struct linux_ioctl_handler *h) if (h == NULL || h->func == NULL) return (EINVAL); + sx_xlock(&linux_ioctl_sx); TAILQ_FOREACH(he, &handlers, list) { if (he->func == h->func) { TAILQ_REMOVE(&handlers, he, list); + sx_xunlock(&linux_ioctl_sx); FREE(he, M_LINUX); return (0); } } + sx_xunlock(&linux_ioctl_sx); return (EINVAL); } diff --git a/sys/i386/linux/syscalls.master b/sys/i386/linux/syscalls.master index 1855e98f56fd..6d30f68b5ea3 100644 --- a/sys/i386/linux/syscalls.master +++ b/sys/i386/linux/syscalls.master @@ -113,7 +113,7 @@ 51 AUE_ACCT MNOPROTO { int acct(char *path); } 52 AUE_UMOUNT MSTD { int linux_umount(char *path, l_int flags); } 53 AUE_NULL UNIMPL lock -54 AUE_IOCTL STD { int linux_ioctl(l_uint fd, l_uint cmd, \ +54 AUE_IOCTL MSTD { int linux_ioctl(l_uint fd, l_uint cmd, \ l_ulong arg); } 55 AUE_FCNTL MSTD { int linux_fcntl(l_uint fd, l_uint cmd, \ l_ulong arg); }