Pull up following revision(s) (requested by mrg in ticket #1481): sys/compat/ibcs2/ibcs2_exec_coff.c: 1.27-1.29 sys/compat/ibcs2/ibcs2_ioctl.c: 1.46 sys/compat/ibcs2/ibcs2_stat.c: 1.49-1.50 Check for NUL termination within the buffer we have. From Ilja Van Sprundel. -- Make sure we have enough space in the buffer before reading it. From Ilja Van Sprundel. -- Make sure we move forward over the buffer. From Ilja Van Sprundel. -- Zero buffers in ibcs2 ioctl to avoid disclosing stack to userland. From Ilja Van Sprundel. -- Don't drop vnode ref until we're done with mount in ibcs2_stat(v)fs. Nothing else guarantees the mount will stick around. From Ilja Van Sprundel. -- Little happy on the commit trigger. Actually use the out label.diff -r1.25 -r1.25.14.1 src/sys/compat/ibcs2/ibcs2_exec_coff.c
(snj)
--- src/sys/compat/ibcs2/Attic/ibcs2_exec_coff.c 2010/07/22 03:19:02 1.25
+++ src/sys/compat/ibcs2/Attic/ibcs2_exec_coff.c 2017/08/19 04:13:51 1.25.14.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ibcs2_exec_coff.c,v 1.25 2010/07/22 03:19:02 christos Exp $ */ | 1 | /* $NetBSD: ibcs2_exec_coff.c,v 1.25.14.1 2017/08/19 04:13:51 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1994, 1995, 1998 Scott Bartram | 4 | * Copyright (c) 1994, 1995, 1998 Scott Bartram | |
5 | * Copyright (c) 1994 Adam Glass | 5 | * Copyright (c) 1994 Adam Glass | |
6 | * Copyright (c) 1993, 1994 Christopher G. Demetriou | 6 | * Copyright (c) 1993, 1994 Christopher G. Demetriou | |
7 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * originally from kern/exec_ecoff.c | 9 | * originally from kern/exec_ecoff.c | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
26 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 26 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
27 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 27 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
28 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 28 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
34 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 34 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | __KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_coff.c,v 1.25 2010/07/22 03:19:02 christos Exp $"); | 38 | __KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_coff.c,v 1.25.14.1 2017/08/19 04:13:51 snj Exp $"); | |
39 | 39 | |||
40 | #include <sys/param.h> | 40 | #include <sys/param.h> | |
41 | #include <sys/systm.h> | 41 | #include <sys/systm.h> | |
42 | #include <sys/kernel.h> | 42 | #include <sys/kernel.h> | |
43 | #include <sys/proc.h> | 43 | #include <sys/proc.h> | |
44 | #include <sys/malloc.h> | 44 | #include <sys/malloc.h> | |
45 | #include <sys/namei.h> | 45 | #include <sys/namei.h> | |
46 | #include <sys/vnode.h> | 46 | #include <sys/vnode.h> | |
47 | #include <sys/mount.h> | 47 | #include <sys/mount.h> | |
48 | #include <sys/exec.h> | 48 | #include <sys/exec.h> | |
49 | #include <sys/exec_coff.h> | 49 | #include <sys/exec_coff.h> | |
50 | #include <sys/resourcevar.h> | 50 | #include <sys/resourcevar.h> | |
51 | 51 | |||
@@ -444,38 +444,44 @@ exec_ibcs2_coff_prep_zmagic(struct lwp * | @@ -444,38 +444,44 @@ exec_ibcs2_coff_prep_zmagic(struct lwp * | |||
444 | sh.s_size, sh.s_scnptr)); */ | 444 | sh.s_size, sh.s_scnptr)); */ | |
445 | 445 | |||
446 | error = vn_rdwr(UIO_READ, epp->ep_vp, tbuf, | 446 | error = vn_rdwr(UIO_READ, epp->ep_vp, tbuf, | |
447 | len, sh.s_scnptr, | 447 | len, sh.s_scnptr, | |
448 | UIO_SYSSPACE, IO_NODELOCKED, l->l_cred, | 448 | UIO_SYSSPACE, IO_NODELOCKED, l->l_cred, | |
449 | &resid, NULL); | 449 | &resid, NULL); | |
450 | if (error) { | 450 | if (error) { | |
451 | DPRINTF(("shlib section read error %d\n", error)); | 451 | DPRINTF(("shlib section read error %d\n", error)); | |
452 | free(tbuf, M_TEMP); | 452 | free(tbuf, M_TEMP); | |
453 | return ENOEXEC; | 453 | return ENOEXEC; | |
454 | } | 454 | } | |
455 | bufp = tbuf; | 455 | bufp = tbuf; | |
456 | while (len) { | 456 | while (len) { | |
457 | if (len < sizeof(struct coff_slhdr)) { | |||
458 | free(tbuf, M_TEMP); | |||
459 | return ENOEXEC; | |||
460 | } | |||
457 | slhdr = (struct coff_slhdr *)bufp; | 461 | slhdr = (struct coff_slhdr *)bufp; | |
458 | 462 | |||
459 | if (slhdr->path_index > LONG_MAX / sizeof(long) || | 463 | if (slhdr->path_index > LONG_MAX / sizeof(long) || | |
460 | slhdr->entry_len > LONG_MAX / sizeof(long)) { | 464 | slhdr->entry_len > LONG_MAX / sizeof(long)) { | |
461 | free(tbuf, M_TEMP); | 465 | free(tbuf, M_TEMP); | |
462 | return ENOEXEC; | 466 | return ENOEXEC; | |
463 | } | 467 | } | |
464 | 468 | |||
465 | path_index = slhdr->path_index * sizeof(long); | 469 | path_index = slhdr->path_index * sizeof(long); | |
466 | entry_len = slhdr->entry_len * sizeof(long); | 470 | entry_len = slhdr->entry_len * sizeof(long); | |
467 | 471 | |||
468 | if (entry_len > len) { | 472 | if (entry_len < sizeof(struct coff_slhdr) || | |
473 | entry_len > len || | |||
474 | strnlen(slhdr->sl_name, entry_len) == entry_len) { | |||
469 | free(tbuf, M_TEMP); | 475 | free(tbuf, M_TEMP); | |
470 | return ENOEXEC; | 476 | return ENOEXEC; | |
471 | } | 477 | } | |
472 | 478 | |||
473 | /* DPRINTF(("path_index: %d entry_len: %d name: %s\n", | 479 | /* DPRINTF(("path_index: %d entry_len: %d name: %s\n", | |
474 | path_index, entry_len, slhdr->sl_name)); */ | 480 | path_index, entry_len, slhdr->sl_name)); */ | |
475 | 481 | |||
476 | error = coff_load_shlib(l, slhdr->sl_name, epp); | 482 | error = coff_load_shlib(l, slhdr->sl_name, epp); | |
477 | if (error) { | 483 | if (error) { | |
478 | free(tbuf, M_TEMP); | 484 | free(tbuf, M_TEMP); | |
479 | return ENOEXEC; | 485 | return ENOEXEC; | |
480 | } | 486 | } | |
481 | bufp += entry_len; | 487 | bufp += entry_len; |
--- src/sys/compat/ibcs2/Attic/ibcs2_ioctl.c 2008/06/24 10:03:17 1.45
+++ src/sys/compat/ibcs2/Attic/ibcs2_ioctl.c 2017/08/19 04:13:51 1.45.36.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ibcs2_ioctl.c,v 1.45 2008/06/24 10:03:17 gmcgarry Exp $ */ | 1 | /* $NetBSD: ibcs2_ioctl.c,v 1.45.36.1 2017/08/19 04:13:51 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1994, 1995 Scott Bartram | 4 | * Copyright (c) 1994, 1995 Scott Bartram | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * based on compat/sunos/sun_ioctl.c | 7 | * based on compat/sunos/sun_ioctl.c | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. The name of the author may not be used to endorse or promote products | 14 | * 2. The name of the author may not be used to endorse or promote products | |
@@ -17,27 +17,27 @@ | @@ -17,27 +17,27 @@ | |||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | __KERNEL_RCSID(0, "$NetBSD: ibcs2_ioctl.c,v 1.45 2008/06/24 10:03:17 gmcgarry Exp $"); | 30 | __KERNEL_RCSID(0, "$NetBSD: ibcs2_ioctl.c,v 1.45.36.1 2017/08/19 04:13:51 snj Exp $"); | |
31 | 31 | |||
32 | #include <sys/param.h> | 32 | #include <sys/param.h> | |
33 | #include <sys/systm.h> | 33 | #include <sys/systm.h> | |
34 | #include <sys/namei.h> | 34 | #include <sys/namei.h> | |
35 | #include <sys/dirent.h> | 35 | #include <sys/dirent.h> | |
36 | #include <sys/proc.h> | 36 | #include <sys/proc.h> | |
37 | #include <sys/file.h> | 37 | #include <sys/file.h> | |
38 | #include <sys/stat.h> | 38 | #include <sys/stat.h> | |
39 | #include <sys/filedesc.h> | 39 | #include <sys/filedesc.h> | |
40 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> | |
41 | #include <sys/kernel.h> | 41 | #include <sys/kernel.h> | |
42 | #include <sys/mbuf.h> | 42 | #include <sys/mbuf.h> | |
43 | #include <sys/mman.h> | 43 | #include <sys/mman.h> | |
@@ -392,28 +392,30 @@ ibcs2_sys_ioctl(struct lwp *l, const str | @@ -392,28 +392,30 @@ ibcs2_sys_ioctl(struct lwp *l, const str | |||
392 | error = EBADF; | 392 | error = EBADF; | |
393 | goto out; | 393 | goto out; | |
394 | } | 394 | } | |
395 | 395 | |||
396 | ctl = fp->f_ops->fo_ioctl; | 396 | ctl = fp->f_ops->fo_ioctl; | |
397 | 397 | |||
398 | switch ((unsigned long)SCARG(uap, cmd)) { | 398 | switch ((unsigned long)SCARG(uap, cmd)) { | |
399 | case IBCS2_TCGETA: | 399 | case IBCS2_TCGETA: | |
400 | case IBCS2_XCGETA: | 400 | case IBCS2_XCGETA: | |
401 | case IBCS2_OXCGETA: | 401 | case IBCS2_OXCGETA: | |
402 | if ((error = (*ctl)(fp, TIOCGETA, &bts)) != 0) | 402 | if ((error = (*ctl)(fp, TIOCGETA, &bts)) != 0) | |
403 | goto out; | 403 | goto out; | |
404 | 404 | |||
405 | memset(&sts, 0, sizeof(sts)); | |||
405 | btios2stios(&bts, &sts); | 406 | btios2stios(&bts, &sts); | |
406 | if (SCARG(uap, cmd) == IBCS2_TCGETA) { | 407 | if (SCARG(uap, cmd) == IBCS2_TCGETA) { | |
408 | memset(&st, 0, sizeof(st)); | |||
407 | stios2stio(&sts, &st); | 409 | stios2stio(&sts, &st); | |
408 | error = copyout(&st, SCARG(uap, data), sizeof(st)); | 410 | error = copyout(&st, SCARG(uap, data), sizeof(st)); | |
409 | if (error) | 411 | if (error) | |
410 | DPRINTF(("ibcs2_ioctl(%d): copyout failed ", | 412 | DPRINTF(("ibcs2_ioctl(%d): copyout failed ", | |
411 | p->p_pid)); | 413 | p->p_pid)); | |
412 | } else | 414 | } else | |
413 | error = copyout(&sts, SCARG(uap, data), sizeof(sts)); | 415 | error = copyout(&sts, SCARG(uap, data), sizeof(sts)); | |
414 | break; | 416 | break; | |
415 | 417 | |||
416 | case IBCS2_TCSETA: | 418 | case IBCS2_TCSETA: | |
417 | case IBCS2_TCSETAW: | 419 | case IBCS2_TCSETAW: | |
418 | case IBCS2_TCSETAF: | 420 | case IBCS2_TCSETAF: | |
419 | if ((error = copyin(SCARG(uap, data), &st, sizeof(st))) != 0) { | 421 | if ((error = copyin(SCARG(uap, data), &st, sizeof(st))) != 0) { | |
@@ -549,23 +551,24 @@ ibcs2_sys_gtty(struct lwp *l, const stru | @@ -549,23 +551,24 @@ ibcs2_sys_gtty(struct lwp *l, const stru | |||
549 | } | 551 | } | |
550 | if ((fp->f_flag & (FREAD|FWRITE)) == 0) { | 552 | if ((fp->f_flag & (FREAD|FWRITE)) == 0) { | |
551 | DPRINTF(("ibcs2_sys_gtty(%d): bad fp flag ", curproc->p_pid)); | 553 | DPRINTF(("ibcs2_sys_gtty(%d): bad fp flag ", curproc->p_pid)); | |
552 | error = EBADF; | 554 | error = EBADF; | |
553 | goto out; | 555 | goto out; | |
554 | } | 556 | } | |
555 | 557 | |||
556 | error = (*fp->f_ops->fo_ioctl)(fp, TIOCGETP, (void *)&tb); | 558 | error = (*fp->f_ops->fo_ioctl)(fp, TIOCGETP, (void *)&tb); | |
557 | if (error) | 559 | if (error) | |
558 | goto out; | 560 | goto out; | |
559 | 561 | |||
560 | fd_putfile(SCARG(uap, fd)); | 562 | fd_putfile(SCARG(uap, fd)); | |
561 | 563 | |||
564 | memset(&itb, 0, sizeof(itb)); | |||
562 | itb.sg_ispeed = tb.sg_ispeed; | 565 | itb.sg_ispeed = tb.sg_ispeed; | |
563 | itb.sg_ospeed = tb.sg_ospeed; | 566 | itb.sg_ospeed = tb.sg_ospeed; | |
564 | itb.sg_erase = tb.sg_erase; | 567 | itb.sg_erase = tb.sg_erase; | |
565 | itb.sg_kill = tb.sg_kill; | 568 | itb.sg_kill = tb.sg_kill; | |
566 | itb.sg_flags = tb.sg_flags & ~(IBCS2_GHUPCL|IBCS2_GXTABS); | 569 | itb.sg_flags = tb.sg_flags & ~(IBCS2_GHUPCL|IBCS2_GXTABS); | |
567 | return copyout((void *)&itb, SCARG(uap, tb), sizeof(itb)); | 570 | return copyout((void *)&itb, SCARG(uap, tb), sizeof(itb)); | |
568 | out: | 571 | out: | |
569 | fd_putfile(SCARG(uap, fd)); | 572 | fd_putfile(SCARG(uap, fd)); | |
570 | return error; | 573 | return error; | |
571 | } | 574 | } |
--- src/sys/compat/ibcs2/Attic/ibcs2_stat.c 2009/06/29 05:08:16 1.47
+++ src/sys/compat/ibcs2/Attic/ibcs2_stat.c 2017/08/19 04:13:51 1.47.18.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ibcs2_stat.c,v 1.47 2009/06/29 05:08:16 dholland Exp $ */ | 1 | /* $NetBSD: ibcs2_stat.c,v 1.47.18.1 2017/08/19 04:13:51 snj Exp $ */ | |
2 | /* | 2 | /* | |
3 | * Copyright (c) 1995, 1998 Scott Bartram | 3 | * Copyright (c) 1995, 1998 Scott Bartram | |
4 | * All rights reserved. | 4 | * All rights reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * 3. The name of the author may not be used to endorse or promote products | 14 | * 3. The name of the author may not be used to endorse or promote products | |
@@ -17,27 +17,27 @@ | @@ -17,27 +17,27 @@ | |||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | __KERNEL_RCSID(0, "$NetBSD: ibcs2_stat.c,v 1.47 2009/06/29 05:08:16 dholland Exp $"); | 30 | __KERNEL_RCSID(0, "$NetBSD: ibcs2_stat.c,v 1.47.18.1 2017/08/19 04:13:51 snj Exp $"); | |
31 | 31 | |||
32 | #include <sys/param.h> | 32 | #include <sys/param.h> | |
33 | #include <sys/systm.h> | 33 | #include <sys/systm.h> | |
34 | #include <sys/namei.h> | 34 | #include <sys/namei.h> | |
35 | #include <sys/proc.h> | 35 | #include <sys/proc.h> | |
36 | #include <sys/file.h> | 36 | #include <sys/file.h> | |
37 | #include <sys/stat.h> | 37 | #include <sys/stat.h> | |
38 | #include <sys/filedesc.h> | 38 | #include <sys/filedesc.h> | |
39 | #include <sys/ioctl.h> | 39 | #include <sys/ioctl.h> | |
40 | #include <sys/kernel.h> | 40 | #include <sys/kernel.h> | |
41 | #include <sys/mount.h> | 41 | #include <sys/mount.h> | |
42 | #include <sys/vnode.h> | 42 | #include <sys/vnode.h> | |
43 | #include <sys/syscallargs.h> | 43 | #include <sys/syscallargs.h> | |
@@ -137,31 +137,33 @@ ibcs2_sys_statfs(struct lwp *l, const st | @@ -137,31 +137,33 @@ ibcs2_sys_statfs(struct lwp *l, const st | |||
137 | syscallarg(int) fstype; | 137 | syscallarg(int) fstype; | |
138 | } */ | 138 | } */ | |
139 | struct mount *mp; | 139 | struct mount *mp; | |
140 | struct statvfs *sp; | 140 | struct statvfs *sp; | |
141 | int error; | 141 | int error; | |
142 | struct vnode *vp; | 142 | struct vnode *vp; | |
143 | 143 | |||
144 | error = namei_simple_user(SCARG(uap, path), | 144 | error = namei_simple_user(SCARG(uap, path), | |
145 | NSM_FOLLOW_TRYEMULROOT, &vp); | 145 | NSM_FOLLOW_TRYEMULROOT, &vp); | |
146 | if (error != 0) | 146 | if (error != 0) | |
147 | return (error); | 147 | return (error); | |
148 | mp = vp->v_mount; | 148 | mp = vp->v_mount; | |
149 | sp = &mp->mnt_stat; | 149 | sp = &mp->mnt_stat; | |
150 | vrele(vp); | |||
151 | if ((error = VFS_STATVFS(mp, sp)) != 0) | 150 | if ((error = VFS_STATVFS(mp, sp)) != 0) | |
152 | return (error); | 151 | goto out; | |
153 | sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; | 152 | sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; | |
154 | return cvt_statfs(sp, (void *)SCARG(uap, buf), SCARG(uap, len)); | 153 | error = cvt_statfs(sp, (void *)SCARG(uap, buf), SCARG(uap, len)); | |
154 | out: | |||
155 | vrele(vp); | |||
156 | return (error); | |||
155 | } | 157 | } | |
156 | 158 | |||
157 | int | 159 | int | |
158 | ibcs2_sys_fstatfs(struct lwp *l, const struct ibcs2_sys_fstatfs_args *uap, register_t *retval) | 160 | ibcs2_sys_fstatfs(struct lwp *l, const struct ibcs2_sys_fstatfs_args *uap, register_t *retval) | |
159 | { | 161 | { | |
160 | /* { | 162 | /* { | |
161 | syscallarg(int) fd; | 163 | syscallarg(int) fd; | |
162 | syscallarg(struct ibcs2_statfs *) buf; | 164 | syscallarg(struct ibcs2_statfs *) buf; | |
163 | syscallarg(int) len; | 165 | syscallarg(int) len; | |
164 | syscallarg(int) fstype; | 166 | syscallarg(int) fstype; | |
165 | } */ | 167 | } */ | |
166 | file_t *fp; | 168 | file_t *fp; | |
167 | struct mount *mp; | 169 | struct mount *mp; | |
@@ -190,32 +192,34 @@ ibcs2_sys_statvfs(struct lwp *l, const s | @@ -190,32 +192,34 @@ ibcs2_sys_statvfs(struct lwp *l, const s | |||
190 | syscallarg(struct ibcs2_statvfs *) buf; | 192 | syscallarg(struct ibcs2_statvfs *) buf; | |
191 | } */ | 193 | } */ | |
192 | struct mount *mp; | 194 | struct mount *mp; | |
193 | struct statvfs *sp; | 195 | struct statvfs *sp; | |
194 | int error; | 196 | int error; | |
195 | struct vnode *vp; | 197 | struct vnode *vp; | |
196 | 198 | |||
197 | error = namei_simple_user(SCARG(uap, path), | 199 | error = namei_simple_user(SCARG(uap, path), | |
198 | NSM_FOLLOW_TRYEMULROOT, &vp); | 200 | NSM_FOLLOW_TRYEMULROOT, &vp); | |
199 | if (error != 0) | 201 | if (error != 0) | |
200 | return (error); | 202 | return (error); | |
201 | mp = vp->v_mount; | 203 | mp = vp->v_mount; | |
202 | sp = &mp->mnt_stat; | 204 | sp = &mp->mnt_stat; | |
203 | vrele(vp); | |||
204 | if ((error = VFS_STATVFS(mp, sp)) != 0) | 205 | if ((error = VFS_STATVFS(mp, sp)) != 0) | |
205 | return (error); | 206 | goto out; | |
206 | sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; | 207 | sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; | |
207 | return cvt_statvfs(sp, (void *)SCARG(uap, buf), | 208 | error = cvt_statvfs(sp, (void *)SCARG(uap, buf), | |
208 | sizeof(struct ibcs2_statvfs)); | 209 | sizeof(struct ibcs2_statvfs)); | |
210 | out: | |||
211 | vrele(vp); | |||
212 | return error; | |||
209 | } | 213 | } | |
210 | 214 | |||
211 | int | 215 | int | |
212 | ibcs2_sys_fstatvfs(struct lwp *l, const struct ibcs2_sys_fstatvfs_args *uap, register_t *retval) | 216 | ibcs2_sys_fstatvfs(struct lwp *l, const struct ibcs2_sys_fstatvfs_args *uap, register_t *retval) | |
213 | { | 217 | { | |
214 | /* { | 218 | /* { | |
215 | syscallarg(int) fd; | 219 | syscallarg(int) fd; | |
216 | syscallarg(struct ibcs2_statvfs *) buf; | 220 | syscallarg(struct ibcs2_statvfs *) buf; | |
217 | } */ | 221 | } */ | |
218 | file_t *fp; | 222 | file_t *fp; | |
219 | struct mount *mp; | 223 | struct mount *mp; | |
220 | struct statvfs *sp; | 224 | struct statvfs *sp; | |
221 | int error; | 225 | int error; |