From patchwork Thu Mar 16 19:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 70955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp674209wrt; Thu, 16 Mar 2023 12:56:08 -0700 (PDT) X-Google-Smtp-Source: AK7set/xiaUdPowkDuLJjoMypOFpbruMwJmZwmBlpar9RFZykLBH9zJLPLTwOowz7kOmAJhjvxzx X-Received: by 2002:a62:1749:0:b0:625:9426:d60b with SMTP id 70-20020a621749000000b006259426d60bmr4434406pfx.15.1678996568678; Thu, 16 Mar 2023 12:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678996568; cv=none; d=google.com; s=arc-20160816; b=h+IAZ7oDKrAHO2v3eyWpt5mpPaHwWvmW/fvvN6dn1dL0aKuWf2biZBSqOSK4m5PeRT 4gXT95RlJubaHPCeUh0G7lgQbmqDBswV4GJsIX6LFCh+/ZIVVikEwFETnnIEh2UKk/zC BX9GCqQ9BUKANl1E6pbu07LujEmFoU01nFm5/y0ooF10B3aZhoU1+xxFJpmh3eNQuNhD 5QqtudVlRIHSkY+rW6zWGOsVszzvd/TQneNHIRLeWInqALJYNDF2WAeaY8YDu/+d1mO6 0YAXT6gJWSuJxoZyDPdlNTM6MxuoLIJacqji6eZnDp5jS6OR9Q96kNiC/qcworDRlXFz 2spw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nUD+ZGYrRbDW1z2HEEm4V97hi9yje2DoL7z+f5bhaPY=; b=RyyDhHkiaqYfbGDYw+iWUJ0xouhQsKd83Y3exRsTbCdxeVjHz64kcn2YGKWyjJgR9P A0NiAptj5VFzhAoZyka040eB72Aq56G8+PuCen+J1yHHPT+C0hZgxnuhcq/nX5cconno HRjO7jEGApV+neLVcT+Sz86fdd85trK2lxDD2hIZa+aahSf/RAjvGCrexF/W4oX97kYO inf1EBpgnUPfUfFr6vMlVzEZ0CnlqLbHEb8ZCjGHZVfwfFVwQhdnPw3NONPXAvcJt/kC Q2GQ/3OnkcsFv0XUp5K/VRhtIAiIjrXnVuly+1rFQiINijVET2FF0qzSm0CgHAzTX3PX 7gxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ji6AjRdV; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b29-20020a631b1d000000b00507249cdbb4si119362pgb.296.2023.03.16.12.55.55; Thu, 16 Mar 2023 12:56:08 -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=@intel.com header.s=Intel header.b=ji6AjRdV; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbjCPTmW (ORCPT + 99 others); Thu, 16 Mar 2023 15:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbjCPTmR (ORCPT ); Thu, 16 Mar 2023 15:42:17 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6536974B1; Thu, 16 Mar 2023 12:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678995737; x=1710531737; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HNjn4+Xoz1pdCG0Q0z/t1kpbDRFkSjxY3sgAwJC83HU=; b=ji6AjRdV9ev5qZdK66A+pYsvKUyE0ftSEVE05t67icFF/ywOe0zE+/MT k/+f7t5WskF9y79XbnjxYvdpZPyYhLazD0WMQw+yUhOmmbwIk2v+2rHXl 34ZyDy3ZMeuMePEDRaDiXldInKTxMq/x0YhypvuB1Qo5F3yIK9ugNOX84 4qK23KT5GD3EphAEmILmtKPJtRYngVhd8zdtV360/xZ6CVuUJL440jEQm PbS1tUxFiO/ZHqpOXgi+A3cSL7YynvPqJkB1kl3VmRcFB0Kds/mHXfOZP RrZjEkit1Pz3qa4KiNW7Su8czPAEtZge8qmT3yiMFtR70cl9V06yNC26J g==; X-IronPort-AV: E=McAfee;i="6600,9927,10651"; a="326465414" X-IronPort-AV: E=Sophos;i="5.98,265,1673942400"; d="scan'208";a="326465414" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2023 12:42:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10651"; a="823392397" X-IronPort-AV: E=Sophos;i="5.98,265,1673942400"; d="scan'208";a="823392397" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.251.221.172]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2023 12:42:14 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 2/3] perf symbols: Fix unaligned access in get_x86_64_plt_disp() Date: Thu, 16 Mar 2023 21:41:55 +0200 Message-Id: <20230316194156.8320-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316194156.8320-1-adrian.hunter@intel.com> References: <20230316194156.8320-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760555506220819416?= X-GMAIL-MSGID: =?utf-8?q?1760555506220819416?= Use memcpy() to avoid unaligned access. Discovered using EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address". Reported-by: kernel test robot Link: https://lore.kernel.org/oe-lkp/202303061424.6ad43294-yujie.liu@intel.com Fixes: ce4c8e7966f3 ("perf symbols: Get symbols for .plt.got for x86-64") Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 7ef5f6d7d415..ae810d4cf3cd 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -542,9 +542,12 @@ static u32 get_x86_64_plt_disp(const u8 *p) n += 1; /* jmp with 4-byte displacement */ if (p[n] == 0xff && p[n + 1] == 0x25) { + u32 disp; + n += 2; /* Also add offset from start of entry to end of instruction */ - return n + 4 + le32toh(*(const u32 *)(p + n)); + memcpy(&disp, p + n, sizeof(disp)); + return n + 4 + le32toh(disp); } return 0; }