Index: usr.bin/elfdump/elfdump.c =================================================================== --- usr.bin/elfdump/elfdump.c +++ usr.bin/elfdump/elfdump.c @@ -28,6 +28,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -486,6 +488,7 @@ int fd; int ch; int i; + cap_rights_t rights; out = stdout; flags = 0; @@ -527,6 +530,9 @@ 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 +545,13 @@ 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); + + 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);