From owner-svn-src-all@freebsd.org Fri Sep 4 00:41:30 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1E6369C935A; Fri, 4 Sep 2015 00:41:30 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0EF13204; Fri, 4 Sep 2015 00:41:30 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t840fTZN046981; Fri, 4 Sep 2015 00:41:29 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t840fTMS046980; Fri, 4 Sep 2015 00:41:29 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201509040041.t840fTMS046980@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Fri, 4 Sep 2015 00:41:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287446 - stable/10/usr.bin/bluetooth/btsockstat X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Sep 2015 00:41:30 -0000 Author: delphij Date: Fri Sep 4 00:41:29 2015 New Revision: 287446 URL: https://svnweb.freebsd.org/changeset/base/287446 Log: 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. Modified: stable/10/usr.bin/bluetooth/btsockstat/btsockstat.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/bluetooth/btsockstat/btsockstat.c ============================================================================== --- stable/10/usr.bin/bluetooth/btsockstat/btsockstat.c Fri Sep 4 00:14:20 2015 (r287445) +++ stable/10/usr.bin/bluetooth/btsockstat/btsockstat.c Fri Sep 4 00:41:29 2015 (r287446) @@ -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);