diff options
author | brueffer <brueffer@FreeBSD.org> | 2014-12-19 23:18:22 +0000 |
---|---|---|
committer | brueffer <brueffer@FreeBSD.org> | 2014-12-19 23:18:22 +0000 |
commit | f419d174a96322ddec019d8b2521e821d2733502 (patch) | |
tree | 0adb30ff27d5f37e05dbda38886ffc00d5989ff3 /usr.bin | |
parent | 98ddab22ac7576a562b8f17dddc00faa1c5d9a19 (diff) | |
download | FreeBSD-src-f419d174a96322ddec019d8b2521e821d2733502.zip FreeBSD-src-f419d174a96322ddec019d8b2521e821d2733502.tar.gz |
MFC: r274960 (slightly modified)
Limit descriptors and enter capability mode. Since the header was renamed in HEAD, this
commit includes sys/capability.h.
Differential: D1009
Reviewed by: jonathan, pjd
Relnotes: yes
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/elfdump/elfdump.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/usr.bin/elfdump/elfdump.c b/usr.bin/elfdump/elfdump.c index bf9b718..9640dd5 100644 --- a/usr.bin/elfdump/elfdump.c +++ b/usr.bin/elfdump/elfdump.c @@ -29,12 +29,15 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> + +#include <sys/capability.h> #include <sys/elf32.h> #include <sys/elf64.h> #include <sys/endian.h> #include <sys/mman.h> #include <sys/stat.h> #include <err.h> +#include <errno.h> #include <fcntl.h> #include <inttypes.h> #include <stddef.h> @@ -467,6 +470,7 @@ elf_get_shstrndx(Elf32_Ehdr *e, void *sh) int main(int ac, char **av) { + cap_rights_t rights; u_int64_t phoff; u_int64_t shoff; u_int64_t phentsize; @@ -527,6 +531,9 @@ main(int ac, char **av) case 'w': if ((out = fopen(optarg, "w")) == NULL) err(1, "%s", optarg); + cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE); + if (cap_rights_limit(fileno(out), &rights) < 0 && errno != ENOSYS) + err(1, "unable to limit rights for %s", optarg); break; case '?': default: @@ -539,6 +546,17 @@ main(int ac, char **av) if ((fd = open(*av, O_RDONLY)) < 0 || fstat(fd, &sb) < 0) err(1, "%s", *av); + cap_rights_init(&rights, CAP_MMAP_R); + if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS) + err(1, "unable to limit rights for %s", *av); + close(STDIN_FILENO); + cap_rights_init(&rights, CAP_WRITE); + if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS) + err(1, "unable to limit rights for stdout"); + if (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS) + err(1, "unable to limit rights for stderr"); + if (cap_enter() < 0 && errno != ENOSYS) + err(1, "unable to enter capability mode"); e = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); if (e == MAP_FAILED) err(1, NULL); |