Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932872AbcKYRWM (ORCPT ); Fri, 25 Nov 2016 12:22:12 -0500 Received: from terminus.zytor.com ([198.137.202.10]:49976 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932789AbcKYRVf (ORCPT ); Fri, 25 Nov 2016 12:21:35 -0500 Date: Fri, 25 Nov 2016 09:21:18 -0800 From: tip-bot for Wang Nan Message-ID: Cc: lizefan@huawei.com, hekuang@huawei.com, ast@fb.com, acme@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de, wangnan0@huawei.com Reply-To: lizefan@huawei.com, hekuang@huawei.com, ast@fb.com, hpa@zytor.com, acme@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, wangnan0@huawei.com In-Reply-To: <20161115040617.69788-3-wangnan0@huawei.com> References: <20161115040617.69788-3-wangnan0@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf record: Fix segfault when running with suid and kptr_restrict is 1 Git-Commit-ID: 3dbe46c5245f61328797738c6a0a6cd4bf921f61 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2182 Lines: 65 Commit-ID: 3dbe46c5245f61328797738c6a0a6cd4bf921f61 Gitweb: http://git.kernel.org/tip/3dbe46c5245f61328797738c6a0a6cd4bf921f61 Author: Wang Nan AuthorDate: Tue, 15 Nov 2016 04:05:45 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 25 Nov 2016 11:11:10 -0300 perf record: Fix segfault when running with suid and kptr_restrict is 1 Before this patch perf panics if kptr_restrict is 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 that perf assumes it is allowed to read kptr from /proc/kallsyms when euid is root, but in fact the kernel doesn't allow reading kptr when euid and uid do 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 Tested-by: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: He Kuang Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/20161115040617.69788-3-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- 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 aecff69..420ada9 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1962,7 +1962,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);