Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/compat/common Pull up following revision(s) (requeste...



details:   https://anonhg.NetBSD.org/src/rev/a6dda39c8cba
branches:  netbsd-8
changeset: 985250:a6dda39c8cba
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Aug 15 10:03:46 2021 +0000

description:
Pull up following revision(s) (requested by christos in ticket #1691):

        sys/compat/common/vfs_syscalls_43.c: revision 1.67
        sys/compat/common/vfs_syscalls_50.c: revision 1.26
        sys/compat/common/vfs_syscalls_30.c: revision 1.42

- memset struct stat to avoid kernel memory disclosure of padded fields
  (thanks Trend Micro for the report)
- use do_fhstat
- consistency in argument order of compat functions

diffstat:

 sys/compat/common/vfs_syscalls_30.c |  53 +++++++++---------------------------
 sys/compat/common/vfs_syscalls_43.c |  53 ++++++++++++++++--------------------
 sys/compat/common/vfs_syscalls_50.c |  20 +++++--------
 3 files changed, 45 insertions(+), 81 deletions(-)

diffs (truncated from 349 to 300 lines):

diff -r 996f50e0f6a8 -r a6dda39c8cba sys/compat/common/vfs_syscalls_30.c
--- a/sys/compat/common/vfs_syscalls_30.c       Wed Aug 11 17:25:54 2021 +0000
+++ b/sys/compat/common/vfs_syscalls_30.c       Sun Aug 15 10:03:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls_30.c,v 1.36 2014/10/20 11:58:01 christos Exp $    */
+/*     $NetBSD: vfs_syscalls_30.c,v 1.36.12.1 2021/08/15 10:03:46 martin Exp $ */
 
 /*-
  * Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_30.c,v 1.36 2014/10/20 11:58:01 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_30.c,v 1.36.12.1 2021/08/15 10:03:46 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -55,7 +55,6 @@
 #include <compat/sys/dirent.h>
 #include <compat/sys/mount.h>
 
-static void cvtstat(struct stat13 *, const struct stat *);
 
 /*
  * Convert from a new to an old stat structure.
@@ -64,6 +63,8 @@
 cvtstat(struct stat13 *ost, const struct stat *st)
 {
 
+       /* Handle any padding. */
+       memset(ost, 0, sizeof(*ost));
        ost->st_dev = st->st_dev;
        ost->st_ino = (uint32_t)st->st_ino;
        ost->st_mode = st->st_mode;
@@ -101,8 +102,7 @@
        if (error)
                return error;
        cvtstat(&osb, &sb);
-       error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
-       return error;
+       return copyout(&osb, SCARG(uap, ub), sizeof(osb));
 }
 
 
@@ -125,8 +125,7 @@
        if (error)
                return error;
        cvtstat(&osb, &sb);
-       error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
-       return error;
+       return copyout(&osb, SCARG(uap, ub), sizeof(osb));
 }
 
 /* ARGSUSED */
@@ -140,33 +139,12 @@
        struct stat sb;
        struct stat13 osb;
        int error;
-       struct compat_30_fhandle fh;
-       struct mount *mp;
-       struct vnode *vp;
 
-       /*
-        * Must be super user
-        */
-       if ((error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FILEHANDLE,
-           0, NULL, NULL, NULL)))
-               return (error);
-
-       if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fh))) != 0)
-               return (error);
-
-       if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
-               return (ESTALE);
-       if (mp->mnt_op->vfs_fhtovp == NULL)
-               return EOPNOTSUPP;
-       if ((error = VFS_FHTOVP(mp, (struct fid*)&fh.fh_fid, &vp)))
-               return (error);
-       error = vn_stat(vp, &sb);
-       vput(vp);
+       error = do_fhstat(l, SCARG(uap, fhp), sizeof(*SCARG(uap, fhp)), &sb);
        if (error)
-               return (error);
+               return error;
        cvtstat(&osb, &sb);
-       error = copyout(&osb, SCARG(uap, sb), sizeof(sb));
-       return (error);
+       return copyout(&osb, SCARG(uap, sb), sizeof(osb));
 }
 
 /*
@@ -188,8 +166,7 @@
        if (error)
                return error;
        cvtstat(&osb, &sb);
-       error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
-       return error;
+       return copyout(&osb, SCARG(uap, sb), sizeof(osb));
 }
 
 /*
@@ -265,7 +242,7 @@
                bdp = (struct dirent *)inp;
                reclen = bdp->d_reclen;
                if (reclen & _DIRENT_ALIGN(bdp))
-                       panic("netbsd30_getdents: bad reclen %d", reclen);
+                       panic("%s: bad reclen %d", __func__, reclen);
                if (cookie)
                        off = *cookie++; /* each entry points to the next */
                else
@@ -368,9 +345,8 @@
                error = EINVAL;
        }
        if (error)
-               return (error);
-       error = copyout(&fh, SCARG(uap, fhp), sizeof(struct compat_30_fhandle));
-       return (error);
+               return error;
+       return copyout(&fh, SCARG(uap, fhp), sizeof(fh));
 }
 
 /*
@@ -407,8 +383,7 @@
        if (error)
                return error;
        cvtstat(&osb, &sb);
-       error = copyout(&osb, SCARG(uap_30, sb), sizeof (osb));
-       return error;
+       return copyout(&osb, SCARG(uap_30, sb), sizeof(osb));
 }
 
 /* ARGSUSED */
diff -r 996f50e0f6a8 -r a6dda39c8cba sys/compat/common/vfs_syscalls_43.c
--- a/sys/compat/common/vfs_syscalls_43.c       Wed Aug 11 17:25:54 2021 +0000
+++ b/sys/compat/common/vfs_syscalls_43.c       Sun Aug 15 10:03:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls_43.c,v 1.59.8.2 2017/12/10 09:36:36 snj Exp $     */
+/*     $NetBSD: vfs_syscalls_43.c,v 1.59.8.3 2021/08/15 10:03:46 martin Exp $  */
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.59.8.2 2017/12/10 09:36:36 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.59.8.3 2021/08/15 10:03:46 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -75,14 +75,11 @@
 #include <compat/common/compat_util.h>
 #include <compat/common/compat_mod.h>
 
-static void cvttimespec(struct timespec *, struct timespec50 *);
-static void cvtstat(struct stat *, struct stat43 *);
-
 /*
  * Convert from an old to a new timespec structure.
  */
 static void
-cvttimespec(struct timespec *ts, struct timespec50 *ots)
+cvttimespec(struct timespec50 *ots, const struct timespec *ts)
 {
 
        if (ts->tv_sec > INT_MAX) {
@@ -106,11 +103,11 @@
  * Convert from an old to a new stat structure.
  */
 static void
-cvtstat(struct stat *st, struct stat43 *ost)
+cvtstat(struct stat43 *ost, const struct stat *st)
 {
 
        /* Handle any padding. */
-       memset(ost, 0, sizeof *ost);
+       memset(ost, 0, sizeof(*ost));
        ost->st_dev = st->st_dev;
        ost->st_ino = st->st_ino;
        ost->st_mode = st->st_mode & 0xffff;
@@ -122,9 +119,9 @@
                ost->st_size = st->st_size;
        else
                ost->st_size = -2;
-       cvttimespec(&st->st_atimespec, &ost->st_atimespec);
-       cvttimespec(&st->st_mtimespec, &ost->st_mtimespec);
-       cvttimespec(&st->st_ctimespec, &ost->st_ctimespec);
+       cvttimespec(&ost->st_atimespec, &st->st_atimespec);
+       cvttimespec(&ost->st_mtimespec, &st->st_mtimespec);
+       cvttimespec(&ost->st_ctimespec, &st->st_ctimespec);
        ost->st_blksize = st->st_blksize;
        ost->st_blocks = st->st_blocks;
        ost->st_flags = st->st_flags;
@@ -148,10 +145,9 @@
 
        error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
        if (error)
-               return (error);
-       cvtstat(&sb, &osb);
-       error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
-       return (error);
+               return error;
+       cvtstat(&osb, &sb);
+       return copyout(&osb, SCARG(uap, ub), sizeof(osb));
 }
 
 /*
@@ -163,7 +159,7 @@
 {
        /* {
                syscallarg(char *) path;
-               syscallarg(struct ostat *) ub;
+               syscallarg(struct stat43 *) ub;
        } */
        struct vnode *vp, *dvp;
        struct stat sb, sb1;
@@ -228,9 +224,8 @@
                sb.st_size = sb1.st_size;
                sb.st_blocks = sb1.st_blocks;
        }
-       cvtstat(&sb, &osb);
-       error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
-       return (error);
+       cvtstat(&osb, &sb);
+       return copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
 }
 
 /*
@@ -244,18 +239,16 @@
                syscallarg(int) fd;
                syscallarg(struct stat43 *) sb;
        } */
-       struct stat ub;
-       struct stat43 oub;
+       struct stat sb;
+       struct stat43 osb;
        int error;
 
-       error = do_sys_fstat(SCARG(uap, fd), &ub);
-       if (error == 0) {
-               cvtstat(&ub, &oub);
-               error = copyout((void *)&oub, (void *)SCARG(uap, sb),
-                   sizeof (oub));
-       }
+       error = do_sys_fstat(SCARG(uap, fd), &sb);
+       if (error)
+               return error;
 
-       return (error);
+       cvtstat(&osb, &sb);
+       return copyout(&osb, SCARG(uap, sb), sizeof(osb));
 }
 
 
@@ -278,7 +271,7 @@
 
        SCARG(&nuap, fd) = SCARG(uap, fd);
        SCARG(&nuap, length) = SCARG(uap, length);
-       return (sys_ftruncate(l, &nuap, retval));
+       return sys_ftruncate(l, &nuap, retval);
 }
 
 /*
@@ -517,7 +510,7 @@
        fd_putfile(SCARG(uap, fd));
        if (error)
                return error;
-       return copyout(&loff, SCARG(uap, basep), sizeof(long));
+       return copyout(&loff, SCARG(uap, basep), sizeof(loff));
 }
 
 /*
diff -r 996f50e0f6a8 -r a6dda39c8cba sys/compat/common/vfs_syscalls_50.c
--- a/sys/compat/common/vfs_syscalls_50.c       Wed Aug 11 17:25:54 2021 +0000
+++ b/sys/compat/common/vfs_syscalls_50.c       Sun Aug 15 10:03:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls_50.c,v 1.18 2014/09/05 09:21:54 matt Exp $        */
+/*     $NetBSD: vfs_syscalls_50.c,v 1.18.12.1 2021/08/15 10:03:46 martin Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.18 2014/09/05 09:21:54 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.18.12.1 2021/08/15 10:03:46 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -71,8 +71,6 @@
 #include <compat/sys/dirent.h>
 #include <compat/sys/mount.h>
 
-static void cvtstat(struct stat30 *, const struct stat *);
-
 /*
  * Convert from a new to an old stat structure.
  */



Home | Main Index | Thread Index | Old Index