lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1474430180-130916-1-git-send-email-wangnan0@huawei.com>
Date:   Wed, 21 Sep 2016 03:56:20 +0000
From:   Wang Nan <wangnan0@...wei.com>
To:     <acme@...nel.org>
CC:     <linux-kernel@...r.kernel.org>, <lizefan@...wei.com>,
        <pi3orama@....com>, Wang Nan <wangnan0@...wei.com>,
        Arnaldo Carvalho de Melo <acme@...hat.com>
Subject: [PATCH] perf record: Fix segfault when running with suid and kptr_restrict is 1

Before this patch perf panic if kptr_restrict set to 1 and perf is owned
by root with suid set:

 $ whoami
 wangnan
 $ ls -l ./perf
 -rwsr-xr-x 1 root root 19781908 Sep 21 19:29 /home/wangnan/perf
 $ cat /proc/sys/kernel/kptr_restrict
 1
 $ cat /proc/sys/kernel/perf_event_paranoid
 -1
 $ ./perf record -a
 Segmentation fault (core dumped)

The reason is perf assumes it is allowed to read kptr from /proc/kallsyms
when euid is root, but in fact kernel doesn't allow it reading kptr when
euid and uid are not match with each other:

 $ cp /bin/cat .
 $ sudo chown root:root ./cat
 $ sudo chmod u+s ./cat
 $ cat /proc/kallsyms | grep do_fork
 0000000000000000 T _do_fork          <--- kptr is hidden even euid is root
 $ sudo cat /proc/kallsyms | grep do_fork
 ffffffff81080230 T _do_fork

See lib/vsprintf.c for kernel side code.

This patch fixes this problem by checking both uid and euid.

Signed-off-by: Wang Nan <wangnan0@...wei.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
---

Resend with a meanless blank like removed.

---
 tools/perf/util/symbol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 19c9c55..c55e781 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1947,7 +1947,7 @@ static bool symbol__read_kptr_restrict(void)
 		char line[8];
 
 		if (fgets(line, sizeof(line), fp) != NULL)
-			value = (geteuid() != 0) ?
+			value = ((geteuid() != 0) || (getuid() != 0)) ?
 					(atoi(line) != 0) :
 					(atoi(line) == 2);
 
-- 
1.8.3.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ