Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756765AbdLOPLL (ORCPT ); Fri, 15 Dec 2017 10:11:11 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58600 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756619AbdLOPLJ (ORCPT ); Fri, 15 Dec 2017 10:11:09 -0500 Subject: Re: Linux 4.15.0-rc3 perf probe/uprobe issue with address randomization To: Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Linux Kernel Mailing List , Ingo Molnar , Martin Schwidefsky , Heiko Carstens , Linus Torvalds , mhiramat@kernel.org References: <8402bed0-bb40-53dc-faf8-bd26f6997de5@linux.vnet.ibm.com> <20171215142153.nty3ymz2r2exawes@hirez.programming.kicks-ass.net> From: Thomas-Mich Richter Organization: IBM LTC Date: Fri, 15 Dec 2017 16:11:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171215142153.nty3ymz2r2exawes@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-IE Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 17121515-0040-0000-0000-0000041A98AA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121515-0041-0000-0000-000020BDB323 Message-Id: <391855e0-fc0e-7e72-67cb-595242878666@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-15_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712150213 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2371 Lines: 63 On 12/15/2017 03:21 PM, Peter Zijlstra wrote: > On Fri, Dec 15, 2017 at 03:14:37PM +0100, Thomas-Mich Richter wrote: >> During debugging of perf probe tool I discovered an issue with >> uprobes and address randomization. >> >> To set a uprobe on a function named inet_pton in libc library, you >> obtain the address of the symbol inet_pton using command nm and >> then use the following command to set the uprobe: >> >> # echo "p:probe_libc/inet_pton /usr/lib64/libc-2.26.so:0x142060" >> > /sys/kernel/debug/tracing/uprobe_events >> >> 0x142060 is the address of inet_pton on my system. >> This works nicely and the uprobe is usable. >> >> The issue is with the output: >> # cat /sys/kernel/debug/tracing/uprobe_events >> p:probe_libc/inet_pton /usr/lib64/libc-2.26.so:0x000000002d0f8952 >> # >> >> The displayed address 0x000000002d0f8952 is wrong, probably >> randomized and post processing of this output with the perf >> probe tool fails due to this random address: >> >> # linux/tools/perf/perf probe -l >> Failed to find debug information for address 2d0f8952 >> probe_libc:inet_pton (on 0x2d0f8952 in /usr/lib64/libc-2.26.so) >> # >> >> So how to fix this (if at all)? >> Is replacing %p by %llx in line 612 of file kernel/trace/trace_uprobe.c >> seq_printf(m, "0x%p", (void *)tu->offset) >> an option? >> Or is this broken by design and intention? > > So recently %p got changed to hash pointers in order to avoid leaking > kernel addresses. > > ad67b74d2469 ("printk: hash addresses printed with %p") > > I'm not sure what privilidges are required for reading that kprobe > state, but I suspect its root only, so changing this to %px might be > what is needed. > Thanks for the hint. The %px printk format string fixes the issue: # echo "p:probe_libc/inet_pton /usr/lib64/libc-2.26.so:0x142060" > /sys/kernel/debug/tracing/uprobe_events # cat /sys/kernel/debug/tracing/uprobe_events p:probe_libc/inet_pton /usr/lib64/libc-2.26.so:0x0000000000142060 # ./tools/perf/perf probe -l probe_libc:inet_pton (on __inet_pton@resolv/inet_pton.c in /usr/lib64/libc-2.26.so) # I will send a patch to fix this. -- Thomas Richter, Dept 3303, IBM LTC Boeblingen Germany -- Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294