Commit 5c1e5018 authored by HardenedBSD Sync Service's avatar HardenedBSD Sync Service
Browse files

Merge branch 'freebsd/current/main' into hardened/current/master

parents 7dda64d6 ce6296ca
...@@ -265,7 +265,7 @@ nfsrpc_access(vnode_t vp, int acmode, struct ucred *cred, ...@@ -265,7 +265,7 @@ nfsrpc_access(vnode_t vp, int acmode, struct ucred *cred,
mode = NFSACCESS_READ; mode = NFSACCESS_READ;
else else
mode = 0; mode = 0;
if (vnode_vtype(vp) == VDIR) { if (vp->v_type == VDIR) {
if (acmode & VWRITE) if (acmode & VWRITE)
mode |= (NFSACCESS_MODIFY | NFSACCESS_EXTEND | mode |= (NFSACCESS_MODIFY | NFSACCESS_EXTEND |
NFSACCESS_DELETE); NFSACCESS_DELETE);
...@@ -370,7 +370,7 @@ nfsrpc_open(vnode_t vp, int amode, struct ucred *cred, NFSPROC_T *p) ...@@ -370,7 +370,7 @@ nfsrpc_open(vnode_t vp, int amode, struct ucred *cred, NFSPROC_T *p)
/* /*
* For NFSv4, Open Ops are only done on Regular Files. * For NFSv4, Open Ops are only done on Regular Files.
*/ */
if (vnode_vtype(vp) != VREG) if (vp->v_type != VREG)
return (0); return (0);
mode = 0; mode = 0;
if (amode & FREAD) if (amode & FREAD)
...@@ -742,7 +742,7 @@ nfsrpc_close(vnode_t vp, int doclose, NFSPROC_T *p) ...@@ -742,7 +742,7 @@ nfsrpc_close(vnode_t vp, int doclose, NFSPROC_T *p)
struct nfsclclient *clp; struct nfsclclient *clp;
int error; int error;
if (vnode_vtype(vp) != VREG) if (vp->v_type != VREG)
return (0); return (0);
if (doclose) if (doclose)
error = nfscl_doclose(vp, &clp, p); error = nfscl_doclose(vp, &clp, p);
...@@ -1288,7 +1288,7 @@ nfsrpc_setattr(vnode_t vp, struct vattr *vap, NFSACL_T *aclp, ...@@ -1288,7 +1288,7 @@ nfsrpc_setattr(vnode_t vp, struct vattr *vap, NFSACL_T *aclp,
nfhp = VTONFS(vp)->n_fhp; nfhp = VTONFS(vp)->n_fhp;
error = nfscl_getstateid(vp, nfhp->nfh_fh, error = nfscl_getstateid(vp, nfhp->nfh_fh,
nfhp->nfh_len, mode, 0, cred, p, &stateid, &lckp); nfhp->nfh_len, mode, 0, cred, p, &stateid, &lckp);
if (error && vnode_vtype(vp) == VREG && if (error && vp->v_type == VREG &&
(mode == NFSV4OPEN_ACCESSWRITE || (mode == NFSV4OPEN_ACCESSWRITE ||
nfstest_openallsetattr)) { nfstest_openallsetattr)) {
/* /*
...@@ -1359,7 +1359,7 @@ nfsrpc_setattrrpc(vnode_t vp, struct vattr *vap, ...@@ -1359,7 +1359,7 @@ nfsrpc_setattrrpc(vnode_t vp, struct vattr *vap,
NFSCL_REQSTART(nd, NFSPROC_SETATTR, vp); NFSCL_REQSTART(nd, NFSPROC_SETATTR, vp);
if (nd->nd_flag & ND_NFSV4) if (nd->nd_flag & ND_NFSV4)
nfsm_stateidtom(nd, stateidp, NFSSTATEID_PUTSTATEID); nfsm_stateidtom(nd, stateidp, NFSSTATEID_PUTSTATEID);
vap->va_type = vnode_vtype(vp); vap->va_type = vp->v_type;
nfscl_fillsattr(nd, vap, vp, NFSSATTR_FULL, 0); nfscl_fillsattr(nd, vap, vp, NFSSATTR_FULL, 0);
if (nd->nd_flag & ND_NFSV3) { if (nd->nd_flag & ND_NFSV3) {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED); NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
...@@ -1407,7 +1407,7 @@ nfsrpc_lookup(vnode_t dvp, char *name, int len, struct ucred *cred, ...@@ -1407,7 +1407,7 @@ nfsrpc_lookup(vnode_t dvp, char *name, int len, struct ucred *cred,
*attrflagp = 0; *attrflagp = 0;
*dattrflagp = 0; *dattrflagp = 0;
if (vnode_vtype(dvp) != VDIR) if (dvp->v_type != VDIR)
return (ENOTDIR); return (ENOTDIR);
nmp = VFSTONFS(dvp->v_mount); nmp = VFSTONFS(dvp->v_mount);
if (len > NFS_MAXNAMLEN) if (len > NFS_MAXNAMLEN)
......
...@@ -543,7 +543,7 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode, ...@@ -543,7 +543,7 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
stateidp->other[1] = 0; stateidp->other[1] = 0;
stateidp->other[2] = 0; stateidp->other[2] = 0;
} }
if (vnode_vtype(vp) != VREG) if (vp->v_type != VREG)
return (EISDIR); return (EISDIR);
np = VTONFS(vp); np = VTONFS(vp);
nmp = VFSTONFS(vp->v_mount); nmp = VFSTONFS(vp->v_mount);
......
...@@ -309,6 +309,23 @@ readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk, ...@@ -309,6 +309,23 @@ readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk,
* Verify the filesystem values. * Verify the filesystem values.
*/ */
#define ILOG2(num) (fls(num) - 1) #define ILOG2(num) (fls(num) - 1)
#undef CHK
#define CHK(lhs, op, rhs, fmt) \
if (lhs op rhs) { \
printf("UFS%d superblock failed: %s (" #fmt ") %s %s (" \
#fmt ")\n", fs->fs_magic == FS_UFS1_MAGIC ? 1 : 2, \
#lhs, (intmax_t)lhs, #op, #rhs, (intmax_t)rhs); \
return (ENOENT); \
}
#define CHK2(lhs1, op1, rhs1, lhs2, op2, rhs2, fmt) \
if (lhs1 op1 rhs1 && lhs2 op2 rhs2) { \
printf("UFS%d superblock failed: %s (" #fmt ") %s %s (" \
#fmt ") && %s (" #fmt ") %s %s (" #fmt ")\n", \
fs->fs_magic == FS_UFS1_MAGIC ? 1 : 2, #lhs1, \
(intmax_t)lhs1, #op1, #rhs1, (intmax_t)rhs1, #lhs2, \
(intmax_t)lhs2, #op2, #rhs2, (intmax_t)rhs2); \
return (ENOENT); \
}
static int static int
validate_sblock(struct fs *fs, int isaltsblk) validate_sblock(struct fs *fs, int isaltsblk)
...@@ -318,91 +335,95 @@ validate_sblock(struct fs *fs, int isaltsblk) ...@@ -318,91 +335,95 @@ validate_sblock(struct fs *fs, int isaltsblk)
sectorsize = dbtob(1); sectorsize = dbtob(1);
if (fs->fs_magic == FS_UFS2_MAGIC) { if (fs->fs_magic == FS_UFS2_MAGIC) {
if ((!isaltsblk && (fs->fs_sblockloc != SBLOCK_UFS2 || if (!isaltsblk) {
!(fs->fs_sblockactualloc == 0 || CHK(fs->fs_sblockloc, !=, SBLOCK_UFS2, %#jx);
fs->fs_sblockactualloc == SBLOCK_UFS2))) || CHK2(fs->fs_sblockactualloc, !=, SBLOCK_UFS2,
fs->fs_maxsymlinklen != ((UFS_NDADDR + UFS_NIADDR) * fs->fs_sblockactualloc, !=, 0, %jd);
sizeof(ufs2_daddr_t)) || }
fs->fs_nindir != fs->fs_bsize / sizeof(ufs2_daddr_t) || CHK(fs->fs_maxsymlinklen, !=, ((UFS_NDADDR + UFS_NIADDR) *
fs->fs_inopb != fs->fs_bsize / sizeof(struct ufs2_dinode)) sizeof(ufs2_daddr_t)), %jd);
return (ENOENT); CHK(fs->fs_nindir, !=, fs->fs_bsize / sizeof(ufs2_daddr_t),
%jd);
CHK(fs->fs_inopb, !=, fs->fs_bsize / sizeof(struct ufs2_dinode),
%jd);
} else if (fs->fs_magic == FS_UFS1_MAGIC) { } else if (fs->fs_magic == FS_UFS1_MAGIC) {
if ((!isaltsblk && (fs->fs_sblockloc > SBLOCK_UFS1 || if (!isaltsblk) {
!(fs->fs_sblockactualloc == SBLOCK_UFS1 || CHK(fs->fs_sblockloc, >, SBLOCK_UFS1, %#jx);
fs->fs_sblockactualloc == 0))) || CHK2(fs->fs_sblockactualloc, !=, SBLOCK_UFS1,
fs->fs_nindir != fs->fs_bsize / sizeof(ufs1_daddr_t) || fs->fs_sblockactualloc, !=, 0, %jd);
fs->fs_inopb != fs->fs_bsize / sizeof(struct ufs1_dinode) || }
fs->fs_maxsymlinklen != ((UFS_NDADDR + UFS_NIADDR) * CHK(fs->fs_nindir, !=, fs->fs_bsize / sizeof(ufs1_daddr_t),
sizeof(ufs1_daddr_t)) || %jd);
fs->fs_old_inodefmt != FS_44INODEFMT || CHK(fs->fs_inopb, !=, fs->fs_bsize / sizeof(struct ufs1_dinode),
fs->fs_old_cgoffset != 0 || %jd);
fs->fs_old_cgmask != 0xffffffff || CHK(fs->fs_maxsymlinklen, !=, ((UFS_NDADDR + UFS_NIADDR) *
fs->fs_old_size != fs->fs_size || sizeof(ufs1_daddr_t)), %jd);
fs->fs_old_rotdelay != 0 || CHK(fs->fs_old_inodefmt, !=, FS_44INODEFMT, %jd);
fs->fs_old_rps != 60 || CHK(fs->fs_old_cgoffset, !=, 0, %jd);
fs->fs_old_nspf != fs->fs_fsize / sectorsize || CHK(fs->fs_old_cgmask, !=, 0xffffffff, %#jx);
fs->fs_old_cpg != 1 || CHK(fs->fs_old_rotdelay, !=, 0, %jd);
fs->fs_old_interleave != 1 || CHK(fs->fs_old_rps, !=, 60, %jd);
fs->fs_old_trackskew != 0 || CHK(fs->fs_old_nspf, !=, fs->fs_fsize / sectorsize, %jd);
fs->fs_old_cpc != 0 || CHK(fs->fs_old_cpg, !=, 1, %jd);
fs->fs_old_postblformat != 1 || CHK(fs->fs_old_interleave, !=, 1, %jd);
fs->fs_old_nrpos != 1 || CHK(fs->fs_old_trackskew, !=, 0, %jd);
fs->fs_old_spc != fs->fs_fpg * fs->fs_old_nspf || CHK(fs->fs_old_cpc, !=, 0, %jd);
fs->fs_old_nsect != fs->fs_old_spc || CHK(fs->fs_old_postblformat, !=, 1, %jd);
fs->fs_old_npsect != fs->fs_old_spc || CHK(fs->fs_old_nrpos, !=, 1, %jd);
fs->fs_old_dsize != fs->fs_dsize || CHK(fs->fs_old_spc, !=, fs->fs_fpg * fs->fs_old_nspf, %jd);
fs->fs_old_ncyl != fs->fs_ncg) CHK(fs->fs_old_nsect, !=, fs->fs_old_spc, %jd);
return (ENOENT); CHK(fs->fs_old_npsect, !=, fs->fs_old_spc, %jd);
CHK(fs->fs_old_ncyl, !=, fs->fs_ncg, %jd);
} else { } else {
/* Bad magic number, so assume not a superblock */
return (ENOENT); return (ENOENT);
} }
if (fs->fs_bsize < MINBSIZE || fs->fs_bsize > MAXBSIZE || CHK(fs->fs_bsize, <, MINBSIZE, %jd);
fs->fs_bsize < roundup(sizeof(struct fs), DEV_BSIZE) || CHK(fs->fs_bsize, >, MAXBSIZE, %jd);
fs->fs_sbsize > SBLOCKSIZE || fs->fs_sbsize < fs->fs_fsize || CHK(fs->fs_bsize, <, roundup(sizeof(struct fs), DEV_BSIZE), %jd);
!powerof2(fs->fs_bsize)) CHK(fs->fs_sbsize, >, SBLOCKSIZE, %jd);
return (ENOENT); CHK(fs->fs_sbsize, <, fs->fs_fsize, %jd);
if (fs->fs_fsize < sectorsize || fs->fs_fsize > fs->fs_bsize || CHK(powerof2(fs->fs_bsize), ==, 0, %jd);
fs->fs_fsize * MAXFRAG < fs->fs_bsize || !powerof2(fs->fs_fsize)) CHK(fs->fs_fsize, <, sectorsize, %jd);
return (ENOENT); CHK(fs->fs_fsize, >, fs->fs_bsize, %jd);
if (fs->fs_maxbsize < fs->fs_bsize || !powerof2(fs->fs_maxbsize) || CHK(fs->fs_fsize * MAXFRAG, <, fs->fs_bsize, %jd);
fs->fs_maxbsize > FS_MAXCONTIG * fs->fs_bsize) CHK(powerof2(fs->fs_fsize), ==, 0, %jd);
return (ENOENT); CHK(fs->fs_maxbsize, <, fs->fs_bsize, %jd);
if (fs->fs_bmask != ~(fs->fs_bsize - 1) || CHK(powerof2(fs->fs_maxbsize), ==, 0, %jd);
fs->fs_fmask != ~(fs->fs_fsize - 1) || CHK(fs->fs_maxbsize, >, FS_MAXCONTIG * fs->fs_bsize, %jd);
fs->fs_qbmask != ~fs->fs_bmask || CHK(fs->fs_bmask, !=, ~(fs->fs_bsize - 1), %#jx);
fs->fs_qfmask != ~fs->fs_fmask || CHK(fs->fs_fmask, !=, ~(fs->fs_fsize - 1), %#jx);
fs->fs_bshift != ILOG2(fs->fs_bsize) || CHK(fs->fs_qbmask, !=, ~fs->fs_bmask, %#jx);
fs->fs_fshift != ILOG2(fs->fs_fsize) || CHK(fs->fs_qfmask, !=, ~fs->fs_fmask, %#jx);
fs->fs_frag != numfrags(fs, fs->fs_bsize) || CHK(fs->fs_bshift, !=, ILOG2(fs->fs_bsize), %jd);
fs->fs_fragshift != ILOG2(fs->fs_frag) || CHK(fs->fs_fshift, !=, ILOG2(fs->fs_fsize), %jd);
fs->fs_frag > MAXFRAG || CHK(fs->fs_frag, !=, numfrags(fs, fs->fs_bsize), %jd);
fs->fs_fsbtodb != ILOG2(fs->fs_fsize / sectorsize)) CHK(fs->fs_fragshift, !=, ILOG2(fs->fs_frag), %jd);
return (ENOENT); CHK(fs->fs_frag, >, MAXFRAG, %jd);
if (fs->fs_sblkno != CHK(fs->fs_fsbtodb, !=, ILOG2(fs->fs_fsize / sectorsize), %jd);
roundup(howmany(fs->fs_sblockloc + SBLOCKSIZE, fs->fs_fsize), CHK(fs->fs_sblkno, !=, roundup(
fs->fs_frag) || howmany(fs->fs_sblockloc + SBLOCKSIZE, fs->fs_fsize),
fs->fs_cblkno != fs->fs_sblkno + fs->fs_frag), %jd);
roundup(howmany(SBLOCKSIZE, fs->fs_fsize), fs->fs_frag) || CHK(fs->fs_cblkno, !=, fs->fs_sblkno +
fs->fs_iblkno != fs->fs_cblkno + fs->fs_frag || roundup(howmany(SBLOCKSIZE, fs->fs_fsize), fs->fs_frag), %jd);
fs->fs_dblkno != fs->fs_iblkno + fs->fs_ipg / INOPF(fs) || CHK(fs->fs_iblkno, !=, fs->fs_cblkno + fs->fs_frag, %jd);
fs->fs_cgsize > fs->fs_bsize) CHK(fs->fs_dblkno, !=, fs->fs_iblkno + fs->fs_ipg / INOPF(fs), %jd);
return (ENOENT); CHK(fs->fs_cgsize, >, fs->fs_bsize, %jd);
if (fs->fs_csaddr != cgdmin(fs, 0) || CHK(fs->fs_csaddr, !=, cgdmin(fs, 0), %jd);
fs->fs_cssize != CHK(fs->fs_cssize, !=,
fragroundup(fs, fs->fs_ncg * sizeof(struct csum)) || fragroundup(fs, fs->fs_ncg * sizeof(struct csum)), %jd);
fs->fs_dsize != fs->fs_size - fs->fs_sblkno - CHK(fs->fs_dsize, !=, fs->fs_size - fs->fs_sblkno -
fs->fs_ncg * (fs->fs_dblkno - fs->fs_sblkno) - fs->fs_ncg * (fs->fs_dblkno - fs->fs_sblkno) -
howmany(fs->fs_cssize, fs->fs_fsize) || howmany(fs->fs_cssize, fs->fs_fsize), %jd);
fs->fs_metaspace < 0 || fs->fs_metaspace > fs->fs_fpg / 2 || CHK(fs->fs_metaspace, <, 0, %jd);
fs->fs_minfree > 99) CHK(fs->fs_metaspace, >, fs->fs_fpg / 2, %jd);
return (ENOENT); CHK(fs->fs_minfree, >, 99, %jd%%);
maxfilesize = fs->fs_bsize * UFS_NDADDR - 1; maxfilesize = fs->fs_bsize * UFS_NDADDR - 1;
for (sizepb = fs->fs_bsize, i = 0; i < UFS_NIADDR; i++) { for (sizepb = fs->fs_bsize, i = 0; i < UFS_NIADDR; i++) {
sizepb *= NINDIR(fs); sizepb *= NINDIR(fs);
maxfilesize += sizepb; maxfilesize += sizepb;
} }
if (fs->fs_maxfilesize != maxfilesize) CHK(fs->fs_maxfilesize, !=, maxfilesize, %jd);
return (ENOENT);
/* /*
* These values have a tight interaction with each other that * These values have a tight interaction with each other that
* makes it hard to tightly bound them. So we can only check * makes it hard to tightly bound them. So we can only check
...@@ -416,14 +437,16 @@ validate_sblock(struct fs *fs, int isaltsblk) ...@@ -416,14 +437,16 @@ validate_sblock(struct fs *fs, int isaltsblk)
* since newfs(8) strives to have at least four cylinder groups. * since newfs(8) strives to have at least four cylinder groups.
*/ */
minfpg = MIN(12289, fs->fs_size / 4); minfpg = MIN(12289, fs->fs_size / 4);
if (fs->fs_ncg < 1 || fs->fs_ncg > (fs->fs_size / minfpg) + 1 || CHK(fs->fs_ncg, <, 1, %jd);
fs->fs_fpg < minfpg || fs->fs_fpg > fs->fs_size || CHK(fs->fs_ncg, >, (fs->fs_size / minfpg) + 1, %jd);
fs->fs_ipg * fs->fs_ncg > (((int64_t)(1)) << 32) - INOPB(fs) || CHK(fs->fs_fpg, <, minfpg, %jd);
fs->fs_ipg > fs->fs_fpg || fs->fs_size < 8 * fs->fs_frag) CHK(fs->fs_fpg, >, fs->fs_size, %jd);
return (ENOENT); CHK(fs->fs_ipg * fs->fs_ncg, >, (((int64_t)(1)) << 32) - INOPB(fs),
if (fs->fs_size <= (fs->fs_ncg - 1) * fs->fs_fpg || %jd);
fs->fs_size > fs->fs_ncg * fs->fs_fpg) CHK(fs->fs_ipg, >, fs->fs_fpg, %jd);
return (ENOENT); CHK(fs->fs_size, <, 8 * fs->fs_frag, %jd);
CHK(fs->fs_size, <=, (fs->fs_ncg - 1) * fs->fs_fpg, %jd);
CHK(fs->fs_size, >, fs->fs_ncg * fs->fs_fpg, %jd);
/* /*
* With file system clustering it is possible to allocate * With file system clustering it is possible to allocate
* many contiguous blocks. The kernel variable maxphys defines * many contiguous blocks. The kernel variable maxphys defines
...@@ -443,14 +466,12 @@ validate_sblock(struct fs *fs, int isaltsblk) ...@@ -443,14 +466,12 @@ validate_sblock(struct fs *fs, int isaltsblk)
* those (mostly 32-bit machines) can (very slowly) handle I/O * those (mostly 32-bit machines) can (very slowly) handle I/O
* requests that exceed maxphys. * requests that exceed maxphys.
*/ */
if (fs->fs_maxcontig < 1 || CHK(fs->fs_maxcontig, <, 1, %jd);
fs->fs_maxcontig > MAX(256, maxphys / fs->fs_bsize)) CHK(fs->fs_maxcontig, >, MAX(256, maxphys / fs->fs_bsize), %jd);
return (ENOENT); CHK(fs->fs_maxcontig, <, 0, %jd);
if (fs->fs_maxcontig < 0 || CHK2(fs->fs_maxcontig, ==, 0, fs->fs_contigsumsize, !=, 0, %jd);
(fs->fs_maxcontig == 0 && fs->fs_contigsumsize != 0) || CHK2(fs->fs_maxcontig, >, 1, fs->fs_contigsumsize, !=,
(fs->fs_maxcontig > 1 && MIN(fs->fs_maxcontig, FS_MAXCONTIG), %jd);
fs->fs_contigsumsize != MIN(fs->fs_maxcontig, FS_MAXCONTIG)))
return (ENOENT);
return (0); return (0);
} }
......
...@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); ...@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcib_private.h> #include <dev/pci/pcib_private.h>
#endif #endif
#include <x86/apicreg.h> #include <x86/apicreg.h>
#include <x86/legacyvar.h>
#include <x86/mptable.h> #include <x86/mptable.h>
#include <machine/frame.h> #include <machine/frame.h>
#include <machine/intr_machdep.h> #include <machine/intr_machdep.h>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment