Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6136826iog; Thu, 23 Jun 2022 12:07:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbfVkc4a6+622LUhnOjyY/Ed9HBetfYREWOkHsw4k2BpeYjgQzI/d3pwkqrhu5Gi0aFOOn X-Received: by 2002:a63:751b:0:b0:40c:9c39:c890 with SMTP id q27-20020a63751b000000b0040c9c39c890mr8733344pgc.302.1656011220871; Thu, 23 Jun 2022 12:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011220; cv=none; d=google.com; s=arc-20160816; b=nZveezJruFXm72UJWkCvgTyBIjLlTqo6I/I2zJIbXmXwXnlmsV8G1jl9C0lzqV+C6Q qVhFbN2Edm5b5v/928OzJ1a9kHbuvQjBd0Hhez857tInTmBFATbCpqCCCxMSqlNtHdKM j9bXm+M6kyJa/ibcSIyro1C7LYj03nopKcqpRXjBsvT29O0ExhEndSpH5yjdH20Mj5iV CGoEWihpO53/xcIABZ2Ccx6wIIv6Fe7r5+RrKq5B2Av26u+3pFTaRuR68G+Vwbns1QGI 1zNC2IgZyjCXNNUEuqiX9V1S63KnE3iWhWLKLn2pvSPBnpJlsWCqo+UNFQ22vF8Ms291 LBFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=w5Geu4NEKHioKGLiuoH+a34jHdEYzLx0+BrXm7Rqjj0=; b=WIsd202Y/KYBz3/b6qOuM7nDDvjaczB8newSmY5k73TyU43oBMX58c2+1eSNkr/tyu ZmiDGhx0QIAIyjJZc/DCQrEhGN1PQ7JduyoVU9dYh5zfJrQBqLTeSFNrzKurQd2PoEn9 nUvyG9R0Cc13bI0nMT/H/pW+Cz34695Ux/mzAuKIBuNc54eeJD+37Eck/cg7fDoE+5PH M9U1Z7aRtPq7+53K1nQQAaumf7aFJvtZmLapzXXH631MN6IkT9AG3HFXA7/JHsiiS5O+ mxorZQPhnkjVY/PYZWT49uFWwVu2mN3YIsgwBfK9wJHf600n8RCcBjN+fmZco4GpMKjX H2oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xWljqgrB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a6-20020a1709027e4600b00168f7b5a84csi353176pln.242.2022.06.23.12.06.49; Thu, 23 Jun 2022 12:07:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xWljqgrB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236608AbiFWSSh (ORCPT + 99 others); Thu, 23 Jun 2022 14:18:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236800AbiFWSQm (ORCPT ); Thu, 23 Jun 2022 14:16:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB64A25C8; Thu, 23 Jun 2022 10:22:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 801B6B824B8; Thu, 23 Jun 2022 17:22:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFE24C3411B; Thu, 23 Jun 2022 17:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004973; bh=nzwuek6JrM5Ji7ebOsPCu6wngize4JUw2lsWueUaao4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xWljqgrBTLCdbRtTfIr0z6jQfvQlNA7Q1DBhYxJFjPpjOfpP4i6Q8s4xwl9sSgDh0 qnsaJ7shRPlPG/PVo2N7c39zrXpZ70eZS31yy/QtsNPJx1/YF4bbnBQavazoaUUBoW tz1nQdlLzkPkItWB1/Gu7RJIA9zbPegg7C0k+XpQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Zijlstra , Josh Poimboeuf , Sasha Levin Subject: [PATCH 4.19 208/234] faddr2line: Fix overlapping text section failures, the sequel Date: Thu, 23 Jun 2022 18:44:35 +0200 Message-Id: <20220623164348.937181280@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josh Poimboeuf [ Upstream commit dcea997beed694cbd8705100ca1a6eb0d886de69 ] If a function lives in a section other than .text, but .text also exists in the object, faddr2line may wrongly assume .text. This can result in comically wrong output. For example: $ scripts/faddr2line vmlinux.o enter_from_user_mode+0x1c enter_from_user_mode+0x1c/0x30: find_next_bit at /home/jpoimboe/git/linux/./include/linux/find.h:40 (inlined by) perf_clear_dirty_counters at /home/jpoimboe/git/linux/arch/x86/events/core.c:2504 Fix it by passing the section name to addr2line, unless the object file is vmlinux, in which case the symbol table uses absolute addresses. Fixes: 1d1a0e7c5100 ("scripts/faddr2line: Fix overlapping text section failures") Reported-by: Peter Zijlstra Signed-off-by: Josh Poimboeuf Link: https://lore.kernel.org/r/7d25bc1408bd3a750ac26e60d2f2815a5f4a8363.1654130536.git.jpoimboe@kernel.org Signed-off-by: Sasha Levin --- scripts/faddr2line | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/scripts/faddr2line b/scripts/faddr2line index 226c3f559dc5..2571caac3156 100755 --- a/scripts/faddr2line +++ b/scripts/faddr2line @@ -95,17 +95,25 @@ __faddr2line() { local print_warnings=$4 local sym_name=${func_addr%+*} - local offset=${func_addr#*+} - offset=${offset%/*} + local func_offset=${func_addr#*+} + func_offset=${func_offset%/*} local user_size= + local file_type + local is_vmlinux=0 [[ $func_addr =~ "/" ]] && user_size=${func_addr#*/} - if [[ -z $sym_name ]] || [[ -z $offset ]] || [[ $sym_name = $func_addr ]]; then + if [[ -z $sym_name ]] || [[ -z $func_offset ]] || [[ $sym_name = $func_addr ]]; then warn "bad func+offset $func_addr" DONE=1 return fi + # vmlinux uses absolute addresses in the section table rather than + # section offsets. + local file_type=$(${READELF} --file-header $objfile | + ${AWK} '$1 == "Type:" { print $2; exit }') + [[ $file_type = "EXEC" ]] && is_vmlinux=1 + # Go through each of the object's symbols which match the func name. # In rare cases there might be duplicates, in which case we print all # matches. @@ -114,9 +122,11 @@ __faddr2line() { local sym_addr=0x${fields[1]} local sym_elf_size=${fields[2]} local sym_sec=${fields[6]} + local sec_size + local sec_name # Get the section size: - local sec_size=$(${READELF} --section-headers --wide $objfile | + sec_size=$(${READELF} --section-headers --wide $objfile | sed 's/\[ /\[/' | ${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print "0x" $6; exit }') @@ -126,6 +136,17 @@ __faddr2line() { return fi + # Get the section name: + sec_name=$(${READELF} --section-headers --wide $objfile | + sed 's/\[ /\[/' | + ${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print $2; exit }') + + if [[ -z $sec_name ]]; then + warn "bad section name: section: $sym_sec" + DONE=1 + return + fi + # Calculate the symbol size. # # Unfortunately we can't use the ELF size, because kallsyms @@ -174,10 +195,10 @@ __faddr2line() { sym_size=0x$(printf %x $sym_size) - # Calculate the section address from user-supplied offset: - local addr=$(($sym_addr + $offset)) + # Calculate the address from user-supplied offset: + local addr=$(($sym_addr + $func_offset)) if [[ -z $addr ]] || [[ $addr = 0 ]]; then - warn "bad address: $sym_addr + $offset" + warn "bad address: $sym_addr + $func_offset" DONE=1 return fi @@ -191,9 +212,9 @@ __faddr2line() { fi # Make sure the provided offset is within the symbol's range: - if [[ $offset -gt $sym_size ]]; then + if [[ $func_offset -gt $sym_size ]]; then [[ $print_warnings = 1 ]] && - echo "skipping $sym_name address at $addr due to size mismatch ($offset > $sym_size)" + echo "skipping $sym_name address at $addr due to size mismatch ($func_offset > $sym_size)" continue fi @@ -202,11 +223,13 @@ __faddr2line() { [[ $FIRST = 0 ]] && echo FIRST=0 - echo "$sym_name+$offset/$sym_size:" + echo "$sym_name+$func_offset/$sym_size:" # Pass section address to addr2line and strip absolute paths # from the output: - local output=$(${ADDR2LINE} -fpie $objfile $addr | sed "s; $dir_prefix\(\./\)*; ;") + local args="--functions --pretty-print --inlines --exe=$objfile" + [[ $is_vmlinux = 0 ]] && args="$args --section=$sec_name" + local output=$(${ADDR2LINE} $args $addr | sed "s; $dir_prefix\(\./\)*; ;") [[ -z $output ]] && continue # Default output (non --list): -- 2.35.1