diff options
author | guido <guido@FreeBSD.org> | 1997-03-23 20:08:22 +0000 |
---|---|---|
committer | guido <guido@FreeBSD.org> | 1997-03-23 20:08:22 +0000 |
commit | c337c37259502bbcb3efde45ca7db82f927ff512 (patch) | |
tree | e2f5aeaa60774a851df745574651915a33ccf5a1 /sys | |
parent | 8e15480d4907712b453456ae3366cfe75ea7b804 (diff) | |
download | FreeBSD-src-c337c37259502bbcb3efde45ca7db82f927ff512.zip FreeBSD-src-c337c37259502bbcb3efde45ca7db82f927ff512.tar.gz |
Add generation number randomization. Newly created filesystems wil now
automatically have random generation numbers. The kenel way of handling those
also changed. Further it is advised to run fsirand on all your nfs exported
filesystems. the code is mostly copied from OpenBSD, with the randomization
chanegd to use /dev/urandom
Reviewed by: Garrett
Obtained from: OpenBSD
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/vfs_extattr.c | 14 | ||||
-rw-r--r-- | sys/kern/vfs_syscalls.c | 14 | ||||
-rw-r--r-- | sys/ufs/ffs/ffs_alloc.c | 9 | ||||
-rw-r--r-- | sys/ufs/ffs/ffs_vfsops.c | 13 | ||||
-rw-r--r-- | sys/ufs/ffs/fs.h | 5 |
5 files changed, 37 insertions, 18 deletions
diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c index 6404a8c..2997fe5 100644 --- a/sys/kern/vfs_extattr.c +++ b/sys/kern/vfs_extattr.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94 - * $Id: vfs_syscalls.c,v 1.59 1997/03/05 01:42:14 msmith Exp $ + * $Id: vfs_syscalls.c,v 1.60 1997/03/23 03:36:35 bde Exp $ */ /* @@ -558,6 +558,7 @@ statfs(p, uap, retval) register struct statfs *sp; int error; struct nameidata nd; + struct statfs sb; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); if (error = namei(&nd)) @@ -569,6 +570,11 @@ statfs(p, uap, retval) if (error) return (error); sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + if (p->p_ucred->cr_uid != 0) { + bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb)); + sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0; + sp = &sb; + } return (copyout((caddr_t)sp, (caddr_t)SCARG(uap, buf), sizeof(*sp))); } @@ -595,6 +601,7 @@ fstatfs(p, uap, retval) struct mount *mp; register struct statfs *sp; int error; + struct statfs sb; if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) return (error); @@ -604,6 +611,11 @@ fstatfs(p, uap, retval) if (error) return (error); sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + if (p->p_ucred->cr_uid != 0) { + bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb)); + sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0; + sp = &sb; + } return (copyout((caddr_t)sp, (caddr_t)SCARG(uap, buf), sizeof(*sp))); } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 6404a8c..2997fe5 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94 - * $Id: vfs_syscalls.c,v 1.59 1997/03/05 01:42:14 msmith Exp $ + * $Id: vfs_syscalls.c,v 1.60 1997/03/23 03:36:35 bde Exp $ */ /* @@ -558,6 +558,7 @@ statfs(p, uap, retval) register struct statfs *sp; int error; struct nameidata nd; + struct statfs sb; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); if (error = namei(&nd)) @@ -569,6 +570,11 @@ statfs(p, uap, retval) if (error) return (error); sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + if (p->p_ucred->cr_uid != 0) { + bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb)); + sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0; + sp = &sb; + } return (copyout((caddr_t)sp, (caddr_t)SCARG(uap, buf), sizeof(*sp))); } @@ -595,6 +601,7 @@ fstatfs(p, uap, retval) struct mount *mp; register struct statfs *sp; int error; + struct statfs sb; if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) return (error); @@ -604,6 +611,11 @@ fstatfs(p, uap, retval) if (error) return (error); sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + if (p->p_ucred->cr_uid != 0) { + bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb)); + sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0; + sp = &sb; + } return (copyout((caddr_t)sp, (caddr_t)SCARG(uap, buf), sizeof(*sp))); } diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index 3be3f2f..3483b56 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ffs_alloc.c 8.18 (Berkeley) 5/26/95 - * $Id: ffs_alloc.c,v 1.31 1997/03/09 06:00:40 mpp Exp $ + * $Id: ffs_alloc.c,v 1.32 1997/03/22 06:53:28 bde Exp $ */ #include "opt_quota.h" @@ -55,8 +55,6 @@ #include <ufs/ffs/fs.h> #include <ufs/ffs/ffs_extern.h> -extern u_long nextgennumber; - typedef ufs_daddr_t allocfcn_t __P((struct inode *ip, int cg, ufs_daddr_t bpref, int size)); @@ -601,9 +599,8 @@ ffs_valloc(ap) /* * Set up a new generation number for this inode. */ - if (++nextgennumber < (u_long)time.tv_sec) - nextgennumber = time.tv_sec; - ip->i_gen = nextgennumber; + if (ip->i_gen == 0 || ++(ip->i_gen) == 0) + ip->i_gen = random() / 2 + 1; return (0); noinodes: ffs_fserr(fs, ap->a_cred->cr_uid, "out of inodes"); diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 6250975..31c5486 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95 - * $Id: ffs_vfsops.c,v 1.49 1997/03/22 06:53:30 bde Exp $ + * $Id: ffs_vfsops.c,v 1.50 1997/03/23 03:37:34 bde Exp $ */ #include "opt_quota.h" @@ -92,8 +92,6 @@ struct vfsops ufs_vfsops = { VFS_SET(ufs_vfsops, ufs, MOUNT_UFS, 0); -extern u_long nextgennumber; - /* * ffs_mount * @@ -585,7 +583,10 @@ ffs_mountfs(devvp, mp, p) } mp->mnt_data = (qaddr_t)ump; mp->mnt_stat.f_fsid.val[0] = (long)dev; - mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; + if (fs->fs_id[0] != 0 && fs->fs_id[1] != 0) + mp->mnt_stat.f_fsid.val[1] = fs->fs_id[1]; + else + mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen; mp->mnt_flag |= MNT_LOCAL; ump->um_mountp = mp; @@ -1015,9 +1016,7 @@ restart: * already have one. This should only happen on old filesystems. */ if (ip->i_gen == 0) { - if (++nextgennumber < (u_long)time.tv_sec) - nextgennumber = time.tv_sec; - ip->i_gen = nextgennumber; + ip->i_gen = random() / 2 + 1; if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) ip->i_flag |= IN_MODIFIED; } diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h index df9f95a..9c9debe 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)fs.h 8.13 (Berkeley) 3/21/95 - * $Id$ + * $Id: fs.h,v 1.10 1997/02/22 09:47:11 peter Exp $ */ #ifndef _UFS_FFS_FS_H_ @@ -200,8 +200,7 @@ struct fs { int32_t fs_npsect; /* # sectors/track including spares */ int32_t fs_interleave; /* hardware sector interleave */ int32_t fs_trackskew; /* sector 0 skew, per track */ - int32_t fs_headswitch; /* head switch time, usec */ - int32_t fs_trkseek; /* track-to-track seek, usec */ +/* fs_id takes the space of the unused fs_headswitch and fs_trkseek fields */ int32_t fs_id[2]; /* unique filesystem id */ /* sizes determined by number of cylinder groups and their sizes */ ufs_daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ int32_t fs_cssize; /* size of cyl grp summary area */ |