summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-09-04 00:41:29 +0000
committerdelphij <delphij@FreeBSD.org>2015-09-04 00:41:29 +0000
commit1d0f985306b429f64562d12bf55e3c4628d68c3d (patch)
treebf08ab77f2d90114743f0517b6d9d7ed9c1a09ab /usr.bin
parent77c678cefa321efe0b0ba5931b16190960784b28 (diff)
downloadFreeBSD-src-1d0f985306b429f64562d12bf55e3c4628d68c3d.zip
FreeBSD-src-1d0f985306b429f64562d12bf55e3c4628d68c3d.tar.gz
MFC r287345:
Drop group privileges after opening the kvm descriptor, otherwise, the code would not drop privileges as expected. While there also add checks for the drop and bail out immediately if we failed.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/bluetooth/btsockstat/btsockstat.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/usr.bin/bluetooth/btsockstat/btsockstat.c b/usr.bin/bluetooth/btsockstat/btsockstat.c
index f63ee1f..95a1680 100644
--- a/usr.bin/bluetooth/btsockstat/btsockstat.c
+++ b/usr.bin/bluetooth/btsockstat/btsockstat.c
@@ -154,9 +154,9 @@ main(int argc, char *argv[])
* Discard setgid privileges if not the running kernel so that
* bad guys can't print interesting stuff from kernel memory.
*/
-
if (memf != NULL)
- setgid(getgid());
+ if (setgid(getgid()) != 0)
+ err(1, "setgid");
kvmd = kopen(memf);
if (kvmd == NULL)
@@ -583,15 +583,9 @@ kopen(char const *memf)
kvm_t *kvmd = NULL;
char errbuf[_POSIX2_LINE_MAX];
- /*
- * Discard setgid privileges if not the running kernel so that
- * bad guys can't print interesting stuff from kernel memory.
- */
-
- if (memf != NULL)
- setgid(getgid());
-
kvmd = kvm_openfiles(NULL, memf, NULL, O_RDONLY, errbuf);
+ if (setgid(getgid()) != 0)
+ err(1, "setgid");
if (kvmd == NULL) {
warnx("kvm_openfiles: %s", errbuf);
return (NULL);
OpenPOWER on IntegriCloud