diff options
-rw-r--r-- | sbin/disklabel/disklabel.c | 29 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 27 | ||||
-rw-r--r-- | sbin/dumpfs/dumpfs.c | 5 | ||||
-rw-r--r-- | sbin/fsck/fsck.c | 5 | ||||
-rw-r--r-- | sbin/fsck_ext2fs/main.c | 7 | ||||
-rw-r--r-- | sbin/fsck_ffs/main.c | 7 | ||||
-rw-r--r-- | sbin/fsck_msdos/main.c | 6 | ||||
-rw-r--r-- | sbin/fsirand/fsirand.c | 5 | ||||
-rw-r--r-- | sbin/ncheck_ffs/ncheck_ffs.c | 5 | ||||
-rw-r--r-- | sbin/newfs/mkfs.c | 16 | ||||
-rw-r--r-- | sbin/newfs/newfs.c | 18 | ||||
-rw-r--r-- | sbin/newfs_ext2fs/newfs_ext2fs.c | 5 | ||||
-rw-r--r-- | sbin/newfs_msdos/newfs_msdos.c | 5 | ||||
-rw-r--r-- | sbin/scan_ffs/scan_ffs.c | 5 | ||||
-rw-r--r-- | sbin/tunefs/tunefs.c | 10 |
15 files changed, 110 insertions, 45 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 9cbfd114934..5e5d5b31b2e 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.211 2015/10/17 13:27:08 krw Exp $ */ +/* $OpenBSD: disklabel.c,v 1.212 2015/11/23 19:19:29 deraadt Exp $ */ /* * Copyright (c) 1987, 1993 @@ -33,6 +33,7 @@ */ #include <sys/param.h> /* DEV_BSIZE */ +#include <sys/sysctl.h> #include <sys/ioctl.h> #include <sys/dkio.h> #include <sys/stat.h> @@ -100,6 +101,18 @@ int cmplabel(struct disklabel *, struct disklabel *); void usage(void); u_int64_t getnum(char *, u_int64_t, u_int64_t, const char **); +int64_t physmem; + +void +getphysmem(void) +{ + size_t sz = sizeof(physmem); + int mib[] = { CTL_HW, HW_PHYSMEM64 }; + + if (sysctl(mib, 2, &physmem, &sz, NULL, (size_t)0) == -1) + errx(4, "can't get mem size"); +} + int main(int argc, char *argv[]) { @@ -107,6 +120,8 @@ main(int argc, char *argv[]) FILE *t; char *autotable = NULL; + getphysmem(); + while ((ch = getopt(argc, argv, "AEf:F:hRcdenp:tT:vw")) != -1) switch (ch) { case 'A': @@ -176,6 +191,18 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + if (op == EDIT) { + if (pledge("stdio rpath wpath cpath disklabel proc exec", NULL) == -1) + err(1, "pledge"); + } else if (op == EDITOR) { + /* "proc exec" for man page in editor */ + if (pledge("stdio rpath wpath disklabel proc exec", NULL) == -1) + err(1, "pledge"); + } else { + if (pledge("stdio rpath wpath disklabel", NULL) == -1) + err(1, "pledge"); + } + if (op == UNSPEC) op = READ; diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 69bc57b461a..75e6df45f33 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.298 2015/10/17 13:27:08 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.299 2015/11/23 19:19:29 deraadt Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -155,7 +155,6 @@ void set_geometry(struct disklabel *, struct disklabel *, struct disklabel *, void zero_partitions(struct disklabel *); u_int64_t max_partition_size(struct disklabel *, int); void display_edit(struct disklabel *, char, u_int64_t); -int64_t getphysmem(void); void psize(u_int64_t sz, char unit, struct disklabel *lp); char *get_token(char **, size_t *); int apply_unit(double, u_char, u_int64_t *); @@ -516,18 +515,6 @@ done: return(error); } -int64_t -getphysmem(void) -{ - int64_t physmem; - size_t sz = sizeof(physmem); - int mib[] = { CTL_HW, HW_PHYSMEM64 }; - - if (sysctl(mib, 2, &physmem, &sz, NULL, (size_t)0) == -1) - errx(4, "can't get mem size"); - return physmem; -} - /* * Allocate all disk space according to standard recommendations for a * root disk. @@ -543,7 +530,7 @@ editor_allocspace(struct disklabel *lp_org) u_int64_t chunkstart, chunksize, cylsecs, secs, totsecs, xtrasecs; char **partmp; int i, j, lastalloc, index = 0, fragsize, partno; - int64_t physmem; + extern int64_t physmem; /* How big is the OpenBSD portion of the disk? */ find_bounds(lp_org); @@ -564,8 +551,6 @@ editor_allocspace(struct disklabel *lp_org) } } - physmem = getphysmem() / DEV_BSIZE; /* Blocks not sectors here! */ - cylsecs = lp_org->d_secpercyl; again: lp = &label; @@ -584,12 +569,12 @@ again: /* bump max swap based on phys mem, little physmem gets 2x swap */ if (index == 0 && alloc_table == alloc_table_default) { - if (physmem < MEG(256)) - alloc[1].minsz = alloc[1].maxsz = 2 * physmem; + if (physmem / DEV_BSIZE < MEG(256)) + alloc[1].minsz = alloc[1].maxsz = 2 * (physmem / DEV_BSIZE); else - alloc[1].maxsz += physmem; + alloc[1].maxsz += (physmem / DEV_BSIZE); /* bump max /var to make room for 2 crash dumps */ - alloc[3].maxsz += 2 * physmem; + alloc[3].maxsz += 2 * (physmem / DEV_BSIZE); } xtrasecs = totsecs = editor_countfree(lp); diff --git a/sbin/dumpfs/dumpfs.c b/sbin/dumpfs/dumpfs.c index 894290a559b..8f16d2c99fd 100644 --- a/sbin/dumpfs/dumpfs.c +++ b/sbin/dumpfs/dumpfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dumpfs.c,v 1.32 2015/01/20 18:22:21 deraadt Exp $ */ +/* $OpenBSD: dumpfs.c,v 1.33 2015/11/23 19:19:29 deraadt Exp $ */ /* * Copyright (c) 2002 Networks Associates Technology, Inc. @@ -100,6 +100,9 @@ main(int argc, char *argv[]) if (argc < 1) usage(); + if (pledge("stdio rpath disklabel", NULL) == -1) + err(1, "pledge"); + for (; *argv != NULL; argv++) { if ((fs = getfsfile(*argv)) != NULL) name = fs->fs_spec; diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c index 51bb4b3d41c..ec7224e085b 100644 --- a/sbin/fsck/fsck.c +++ b/sbin/fsck/fsck.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsck.c,v 1.37 2015/05/29 15:57:36 deraadt Exp $ */ +/* $OpenBSD: fsck.c,v 1.38 2015/11/23 19:19:29 deraadt Exp $ */ /* $NetBSD: fsck.c,v 1.7 1996/10/03 20:06:30 christos Exp $ */ /* @@ -106,6 +106,9 @@ main(int argc, char *argv[]) } else warn("Can't get resource limit for data size"); + if (pledge("stdio rpath wpath disklabel proc exec", NULL) == -1) + err(1, "pledge"); + globopt[0] = '-'; globopt[2] = '\0'; diff --git a/sbin/fsck_ext2fs/main.c b/sbin/fsck_ext2fs/main.c index 90406108f7b..2c2ecefdca3 100644 --- a/sbin/fsck_ext2fs/main.c +++ b/sbin/fsck_ext2fs/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.23 2015/10/14 14:33:45 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.24 2015/11/23 19:19:30 deraadt Exp $ */ /* $NetBSD: main.c,v 1.1 1997/06/11 11:21:50 bouyer Exp $ */ /* @@ -44,6 +44,7 @@ #include <stdio.h> #include <time.h> #include <unistd.h> +#include <err.h> #include "fsck.h" #include "extern.h" @@ -156,6 +157,10 @@ checkfilesys(char *filesys, char *mntpt, long auxdata, int child) setcdevname(filesys, NULL, preen); if (debug && preen) pwarn("starting\n"); + + if (pledge("stdio rpath wpath getpw disklabel", NULL) == -1) + err(1, "pledge"); + switch (setup(filesys)) { case 0: if (preen) diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c index 24043a10e93..c373b416bc4 100644 --- a/sbin/fsck_ffs/main.c +++ b/sbin/fsck_ffs/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.46 2015/10/15 03:10:05 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.47 2015/11/23 19:19:30 deraadt Exp $ */ /* $NetBSD: main.c,v 1.22 1996/10/11 20:15:48 thorpej Exp $ */ /* @@ -40,6 +40,7 @@ #include <ctype.h> #include <stdio.h> #include <unistd.h> +#include <err.h> #include "fsck.h" #include "extern.h" @@ -168,6 +169,10 @@ checkfilesys(char *filesys, char *mntpt, long auxdata, int child) setcdevname(filesys, NULL, preen); if (debug && preen) pwarn("starting\n"); + + if (pledge("stdio rpath wpath getpw disklabel", NULL) == -1) + err(1, "pledge"); + switch (setup(filesys)) { case 0: if (preen) diff --git a/sbin/fsck_msdos/main.c b/sbin/fsck_msdos/main.c index acd61846b22..8ea0f2e7c34 100644 --- a/sbin/fsck_msdos/main.c +++ b/sbin/fsck_msdos/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.21 2015/10/14 14:33:45 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.22 2015/11/23 19:19:30 deraadt Exp $ */ /* $NetBSD: main.c,v 1.8 1996/10/17 20:29:53 cgd Exp $ */ /* @@ -34,6 +34,7 @@ #include <unistd.h> #include <errno.h> #include <stdarg.h> +#include <err.h> #include "ext.h" @@ -56,6 +57,9 @@ main(int argc, char *argv[]) { int ch; + if (pledge("stdio rpath wpath disklabel", NULL) == -1) + err(1, "pledge"); + while ((ch = getopt(argc, argv, "pynf")) != -1) { switch (ch) { case 'f': diff --git a/sbin/fsirand/fsirand.c b/sbin/fsirand/fsirand.c index 24475d40719..e39b0b1ee47 100644 --- a/sbin/fsirand/fsirand.c +++ b/sbin/fsirand/fsirand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsirand.c,v 1.36 2015/11/18 15:36:32 deraadt Exp $ */ +/* $OpenBSD: fsirand.c,v 1.37 2015/11/23 19:19:30 deraadt Exp $ */ /* * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> @@ -106,6 +106,9 @@ fsirand(char *device) u_int32_t bsize = DEV_BSIZE; struct disklabel label; + if (pledge("stdio rpath wpath disklabel", NULL) == -1) + err(1, "pledge"); + if ((devfd = opendev(device, printonly ? O_RDONLY : O_RDWR, 0, &devpath)) < 0) { warn("Can't open %s", devpath); diff --git a/sbin/ncheck_ffs/ncheck_ffs.c b/sbin/ncheck_ffs/ncheck_ffs.c index e299eb767da..45c3a0b484e 100644 --- a/sbin/ncheck_ffs/ncheck_ffs.c +++ b/sbin/ncheck_ffs/ncheck_ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ncheck_ffs.c,v 1.51 2015/10/11 19:00:40 doug Exp $ */ +/* $OpenBSD: ncheck_ffs.c,v 1.52 2015/11/23 19:19:30 deraadt Exp $ */ /*- * Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> @@ -510,6 +510,9 @@ main(int argc, char *argv[]) char *ep; int c, i; + if (pledge("stdio rpath disklabel", NULL) == -1) + err(1, "pledge"); + while ((c = getopt(argc, argv, "af:i:ms")) != -1) switch (c) { case 'a': diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 6ab3b55bfc8..6d75732459d 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs.c,v 1.93 2015/10/11 00:20:29 guenther Exp $ */ +/* $OpenBSD: mkfs.c,v 1.94 2015/11/23 19:19:30 deraadt Exp $ */ /* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */ /* @@ -1181,19 +1181,13 @@ static void checksz(void) { unsigned long long allocate, maxino, maxfsblock, ndir, bound; - int mib[2]; + extern int64_t physmem; struct rlimit datasz; - size_t len; - - mib[0] = CTL_HW; - mib[1] = HW_PHYSMEM64; - len = sizeof(bound); - - if (sysctl(mib, 2, &bound, &len, NULL, 0) != 0) - err(1, "can't get physmem"); + if (getrlimit(RLIMIT_DATA, &datasz) != 0) err(1, "can't get rlimit"); - bound = MINIMUM(datasz.rlim_max, bound); + + bound = MINIMUM(datasz.rlim_max, physmem); allocate = 0; maxino = sblock.fs_ncg * (unsigned long long)sblock.fs_ipg; diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index db050624b5e..ef8ac625652 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs.c,v 1.101 2015/11/10 07:38:19 deraadt Exp $ */ +/* $OpenBSD: newfs.c,v 1.102 2015/11/23 19:19:30 deraadt Exp $ */ /* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */ /* @@ -88,6 +88,7 @@ void fatal(const char *fmt, ...) __attribute__((__nonnull__ (1))); __dead void usage(void); void mkfs(struct partition *, char *, int, int, mode_t, uid_t, gid_t); +void getphysmem(void); void rewritelabel(char *, int, struct disklabel *); u_short dkcksum(struct disklabel *); @@ -147,6 +148,18 @@ static void copy(char *, char *, struct mfs_args *); static int gettmpmnt(char *, size_t); #endif +int64_t physmem; + +void +getphysmem(void) +{ + int mib[] = { CTL_HW, HW_PHYSMEM64 }; + size_t len = sizeof(physmem); + + if (sysctl(mib, 2, &physmem, &len, NULL, 0) != 0) + err(1, "can't get physmem"); +} + int main(int argc, char *argv[]) { @@ -182,6 +195,7 @@ main(int argc, char *argv[]) if (strstr(__progname, "mfs")) mfs = Nflag = quiet = 1; + getphysmem(); maxpartitions = getmaxpartitions(); if (maxpartitions > 26) fatal("insane maxpartitions value %d", maxpartitions); @@ -416,6 +430,8 @@ main(int argc, char *argv[]) fatal("%s: can't figure out file system partition", argv[0]); lp = getdisklabel(special, fsi); + if (pledge("stdio disklabel tty", NULL) == -1) + err(1, "pledge"); if (isdigit((unsigned char)*cp)) pp = &lp->d_partitions[0]; else diff --git a/sbin/newfs_ext2fs/newfs_ext2fs.c b/sbin/newfs_ext2fs/newfs_ext2fs.c index 0cb76195c45..862581ca180 100644 --- a/sbin/newfs_ext2fs/newfs_ext2fs.c +++ b/sbin/newfs_ext2fs/newfs_ext2fs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs_ext2fs.c,v 1.17 2015/10/14 15:54:49 deraadt Exp $ */ +/* $OpenBSD: newfs_ext2fs.c,v 1.18 2015/11/23 19:19:30 deraadt Exp $ */ /* $NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $ */ /* @@ -122,6 +122,9 @@ main(int argc, char *argv[]) struct partition *pp = NULL; struct disklabel *lp; + if (pledge("stdio rpath wpath disklabel", NULL) == -1) + err(1, "pledge"); + cp = NULL; fsi = fso = -1; Fflag = Iflag = Zflag = 0; diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c index 78495ebac99..4959808a72e 100644 --- a/sbin/newfs_msdos/newfs_msdos.c +++ b/sbin/newfs_msdos/newfs_msdos.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs_msdos.c,v 1.26 2015/04/18 18:28:37 deraadt Exp $ */ +/* $OpenBSD: newfs_msdos.c,v 1.27 2015/11/23 19:19:30 deraadt Exp $ */ /* * Copyright (c) 1998 Robert Nordier @@ -251,6 +251,9 @@ main(int argc, char *argv[]) u_int fat, bss, rds, cls, dir, lsn, x, x1, x2; int ch, fd, fd1; + if (pledge("stdio rpath wpath disklabel", NULL) == -1) + err(1, "pledge"); + while ((ch = getopt(argc, argv, opts)) != -1) switch (ch) { case 'N': diff --git a/sbin/scan_ffs/scan_ffs.c b/sbin/scan_ffs/scan_ffs.c index 8c8e6bfcaf5..83d330160d1 100644 --- a/sbin/scan_ffs/scan_ffs.c +++ b/sbin/scan_ffs/scan_ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scan_ffs.c,v 1.20 2015/10/11 04:33:17 deraadt Exp $ */ +/* $OpenBSD: scan_ffs.c,v 1.21 2015/11/23 19:19:30 deraadt Exp $ */ /* * Copyright (c) 1998 Niklas Hallqvist, Tobias Weingartner @@ -138,6 +138,9 @@ main(int argc, char *argv[]) daddr_t beg = 0, end = -1; const char *errstr; + if (pledge("stdio rpath disklabel", NULL) == -1) + err(1, "pledge"); + while ((ch = getopt(argc, argv, "lsvb:e:")) != -1) switch(ch) { case 'b': diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c index e363ff97afb..283450b44d7 100644 --- a/sbin/tunefs/tunefs.c +++ b/sbin/tunefs/tunefs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tunefs.c,v 1.38 2015/10/12 02:01:15 deraadt Exp $ */ +/* $OpenBSD: tunefs.c,v 1.39 2015/11/23 19:19:30 deraadt Exp $ */ /* $NetBSD: tunefs.c,v 1.33 2005/01/19 20:46:16 xtraeme Exp $ */ /* @@ -147,6 +147,14 @@ main(int argc, char *argv[]) if (argc != 1) usage(); + if (Nflag) + if (pledge("stdio rpath disklabel", NULL) == -1) + err(1, "pledge"); + else { + if (pledge("stdio rpath wpath disklabel", NULL) == -1) + err(1, "pledge"); + } + special = argv[0]; openflags = Nflag ? O_RDONLY : O_RDWR; if (Fflag) |