Received: by 10.213.65.68 with SMTP id h4csp2117740imn; Sun, 8 Apr 2018 20:08:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/DWwelStEC4BEIbMXujktFfyrkwf7Z7SJV0wKmb4Y6FSa7i11Jhc5zF1kqDuDpsfsANTy0 X-Received: by 10.98.210.7 with SMTP id c7mr27472848pfg.92.1523243330638; Sun, 08 Apr 2018 20:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243330; cv=none; d=google.com; s=arc-20160816; b=JU4ZlS9bEm3aFVw1ehSmRnxdybVPshrl5rjY3UyrArrbCn5+00PbB7kzRLMmdK1XAt ffEXDswmCyPWl+QnabCMVTSMrSYQgMTwTk7dnhtnCckDSxxsZ77WTUnvS3Zm4Wqv3Wqf B/jD82t+X/iXreYCjeQ2xYH8hJjZ80/iNTH0XDVr6uOo5ubUfi00TkHh1dN6bCP5d86F H5YObaXTryFKMVXUMj4iJ/nZ0tErPY15RI9nW9QjadVIcZFdQaixocw55PTp/Qvqfca/ d5zKiv8QctrgjPHm//kQDMihcPWatRb59L44+OreZKf4mrLufNG+QDVHOHMHUMeuIe4Y m6kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Q5FpLzo3LmOutSjM3CmweJVoPYLa/1F7xpU7VQVkW1c=; b=DcffU7nRCSJEZKNxgKB5R5KAlA7PEa0GhEi5Cv2qYWNrWJvBYDro6kp582t248S9Ck kVoKljKC8nlZahNgYpObJXyqtucuIoUKLy6hUs0GBYz+iol4nJ4scv/UCj78a1MEWU7Z 58lZLTQ2IRHrUEeFIhCX8bgX9sO/VvPU/89SI5rw8tNsmaFD/zevWew/5BngKSiTSRJk pmdDnyEtU5/V2T6kpVV0MPqrQ65RQecrjNL9w2bjyBK4du7Ks2ZAt9tCE6sPyJKGqR3X dJRezRMcknnh8QdTJk6ESMGuNr7VWYvc+K3ZrGrw3J+SOiV8CiwQMGdt9X9VGw2DxYDX Etkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=n9LgQQY1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si13483862plo.421.2018.04.08.20.08.13; Sun, 08 Apr 2018 20:08:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=n9LgQQY1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755776AbeDIBmG (ORCPT + 99 others); Sun, 8 Apr 2018 21:42:06 -0400 Received: from mail-by2nam01on0123.outbound.protection.outlook.com ([104.47.34.123]:51296 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754614AbeDIAet (ORCPT ); Sun, 8 Apr 2018 20:34:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Q5FpLzo3LmOutSjM3CmweJVoPYLa/1F7xpU7VQVkW1c=; b=n9LgQQY1wuXWXPy5sjn+SqBvZxij8C87C2pi/c2pfb+4i6S2DE8R+rjECo//R7CB8Y5S3VNn0HfhIc0YisMMd0i1eG1BjWcZ2ao/XOlcyJqpaeyGbwT8qqx6ZEX6/0Q1uEl1zCdzW5LTwX9ZrBCy6xEwe6EbE35VPmn+LPefhdM= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0806.namprd21.prod.outlook.com (10.167.107.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:34:44 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:34:44 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jesper Dangaard Brouer , Daniel Borkmann , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 287/293] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Topic: [PATCH AUTOSEL for 4.9 287/293] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Index: AQHTz5ltKgVysFsd/0WOcOFfRjj0Jw== Date: Mon, 9 Apr 2018 00:26:40 +0000 Message-ID: <20180409002239.163177-287-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0806;7:hMMRd+kfh/af6oFg74SiYd+9OtmKxWEm//R32J8/1X02Me+C8JHAxDxhU2MkLTucIE8HljE59l5Ler/QSRwFJnSDJk+Ow2KfmuCmHWvSW6HiKkCGxhURVqYC4NsQwM+QnytL7yO8OM2wz5TLzs5INjzDnAkjS41Xd2Jk967KFMq5rD3woXrS8FV4AAOIrFgL+A8+W5ZU9T4eec+kygByeLrBjD28u4jJhokIx+4En2krlPzpvigcfQsaESzgl40j;20:0gfTrNUp8R0iD+Eur/XSPmYqifMLrfRLyNlSF7rIB+r78WVhh8tkEa3x6IbmBNJRgfpB11QeXc3k6zhX4fI1ieaQsSGPCs/jvB/4l96iZSYT15ULRCStZoNBuWz80QbcK706Uw3J0zceFnCw/ytSSuQ3iRZRVvlDLZQWLRsuC/4= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 4e4df9ac-a164-478a-bde7-08d59db1b0fe x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0806; x-ms-traffictypediagnostic: DM5PR2101MB0806: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0806;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0806; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(376002)(396003)(366004)(39380400002)(199004)(189003)(2906002)(25786009)(2501003)(10290500003)(476003)(11346002)(446003)(97736004)(5250100002)(68736007)(2616005)(102836004)(6506007)(3846002)(3660700001)(486006)(3280700002)(305945005)(6666003)(99286004)(5660300001)(76176011)(1076002)(186003)(26005)(7736002)(6116002)(81156014)(81166006)(86612001)(4326008)(105586002)(10090500001)(2900100001)(54906003)(22452003)(316002)(36756003)(110136005)(107886003)(8676002)(6436002)(478600001)(53936002)(66066001)(6486002)(6512007)(575784001)(86362001)(14454004)(72206003)(8936002)(106356001)(22906009)(142923001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0806;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: WepUSlmNgBER1OJ5EdqLAZfTO9h85t5y+z2jA/GQRKHMqpWpWgli+TFpND0SJWPSJ6UjnH1PJWsIhukPSJKEOrvSSNdMRQxKuWIgiD1xNf1J6GFgH4nTuZwFP1hBOBhT7etTHu+YRNNs83GHK/hhfs/XIIVwLSoN8SfNPL8KyIZt0t2VagOFV0btUlBnq3r9XR+KPB0kISswhpHrCovqPnFJDwduHqUUNYNIiDMQGY3HPEyDvcA/VkEhxBpRkzgajDsDkqrJXTNpYukdPVmOzCB+ycq6lQpJD6kKuELaHM4XAaXvRVuMQ7RFCgD77qPqZ0qGpRPNoxBajzuIVq/O6xohGIIMcX3qRC17prTs/G3U/oYlpGM/A3caCGlxtbkBgyX+f3YdHAmo7LzC3zla7Zx7rHitlmUuPMqIhAOVruo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e4df9ac-a164-478a-bde7-08d59db1b0fe X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:40.7071 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0806 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jesper Dangaard Brouer [ Upstream commit e3d91b0ca523d53158f435a3e13df7f0cb360ea2 ] V3: More generic skipping of relo-section (suggested by Daniel) If clang >=3D 4.0.1 is missing the option '-target bpf', it will cause llc/llvm to create two ELF sections for "Exception Frames", with section names '.eh_frame' and '.rel.eh_frame'. The BPF ELF loader library libbpf fails when loading files with these sections. The other in-kernel BPF ELF loader in samples/bpf/bpf_load.c, handle this gracefully. And iproute2 loader also seems to work with these "eh" sections. The issue in libbpf is caused by bpf_object__elf_collect() skipping some sections, and later when performing relocation it will be pointing to a skipped section, as these sections cannot be found by bpf_object__find_prog_by_idx() in bpf_object__collect_reloc(). This is a general issue that also occurs for other sections, like debug sections which are also skipped and can have relo section. As suggested by Daniel. To avoid keeping state about all skipped sections, instead perform a direct qlookup in the ELF object. Lookup the section that the relo-section points to and check if it contains executable machine instructions (denoted by the sh_flags SHF_EXECINSTR). Use this check to also skip irrelevant relo-sections. Note, for samples/bpf/ the '-target bpf' parameter to clang cannot be used due to incompatibility with asm embedded headers, that some of the samples include. This is explained in more details by Yonghong Song in bpf_devel_QA= . Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index b699aea9a025..7788cfb7cd7e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -590,6 +590,24 @@ bpf_object__init_maps_name(struct bpf_object *obj) return 0; } =20 +static bool section_have_execinstr(struct bpf_object *obj, int idx) +{ + Elf_Scn *scn; + GElf_Shdr sh; + + scn =3D elf_getscn(obj->efile.elf, idx); + if (!scn) + return false; + + if (gelf_getshdr(scn, &sh) !=3D &sh) + return false; + + if (sh.sh_flags & SHF_EXECINSTR) + return true; + + return false; +} + static int bpf_object__elf_collect(struct bpf_object *obj) { Elf *elf =3D obj->efile.elf; @@ -673,6 +691,14 @@ static int bpf_object__elf_collect(struct bpf_object *= obj) } else if (sh.sh_type =3D=3D SHT_REL) { void *reloc =3D obj->efile.reloc; int nr_reloc =3D obj->efile.nr_reloc + 1; + int sec =3D sh.sh_info; /* points to other section */ + + /* Only do relo for section with exec instructions */ + if (!section_have_execinstr(obj, sec)) { + pr_debug("skip relo %s(%d) for section(%d)\n", + name, idx, sec); + continue; + } =20 reloc =3D realloc(reloc, sizeof(*obj->efile.reloc) * nr_reloc); --=20 2.15.1