Received: by 10.213.65.68 with SMTP id h4csp2109806imn; Sun, 8 Apr 2018 19:58:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx49nJEncbP7yC+Z4Z77B0hKZ5RfzfOIZn6MPM3cYzHpZa+sgia1t6WNi4VfU7cT3pX0UXfP8 X-Received: by 2002:a17:902:a985:: with SMTP id bh5-v6mr2870677plb.0.1523242714603; Sun, 08 Apr 2018 19:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523242714; cv=none; d=google.com; s=arc-20160816; b=tAtiylk/KfV+M5yBXGC5UpcLiXAVVu/E5kgt16qSDzoW76lE5ETaNiEmJ1oYPtFbPB kvN+obNnNPv3Sp3YKUBD/tj6J4YHitTMwbZLGfr7VYOENCZuy9mMyC8hT59VpYmxqefS 5NlBboIXuCjW1C1Io8mAuyqESBy7AtCwn3blQREbgCaquvk2ANSzrmtl579bIKzSYe7y wkj4DWkcvh84soUC7gdFPVFT+8ldUtUq6Xs55vGhMYjHBknMGYv9UKldhpOCdT70mh0a 0NirQ/Yy5+aG7QSd7E9EVFek5Wgu0oqrERfpsZNWbwXHta8V+cN2TeZXji6wSmQ6HuNC P8Lg== 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=axaJSs4JA3fO2HkT/wYbmjMmzuTL6x6Ygt5O4Jz/yKw=; b=C9Zpm9hb0Htm+BAsr1Y/TSxcebHFxKcLVwBh1VC9k+X+YgUgZLCEtQR/R3NXVmSN3n AtPUoZMjOaQ/vR0zYkPCla8MAuFnbKiWfRBnEPFyooFNTxeyrA2V1rqmmiy2CeCn0N4V 8dR4XlZfooaoXS7+pwPN2HyKYXNpkC7hdfvEVZTBqKokTwqUeovTf9ie/H+AJOrPCucX y3J9VN785s/Ra8mLr6Ufnqm0f1jHhzx87bBF/j6VD/udKPtuLctyMNxOiAUHFIrFqn50 u1wiGXHVY7FHAaTGpUa190QmbJ2e1+M4BYTgsZqDV5euWRGu1zsaeKGt9CCUpYgLbslS 0Bbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=n0CNfij2; 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 h9si10417030pgf.362.2018.04.08.19.57.28; Sun, 08 Apr 2018 19:58:34 -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=n0CNfij2; 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 S1758007AbeDICwg (ORCPT + 98 others); Sun, 8 Apr 2018 22:52:36 -0400 Received: from mail-by2nam03on0131.outbound.protection.outlook.com ([104.47.42.131]:4960 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755337AbeDIA0a (ORCPT ); Sun, 8 Apr 2018 20:26:30 -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=axaJSs4JA3fO2HkT/wYbmjMmzuTL6x6Ygt5O4Jz/yKw=; b=n0CNfij2IoIrSvqdRWfPFMOwiZvJM5aV4rpv/+H/I9G3mqPSQz/sB8g4pPs9dcvcM7btGGap27tNfpcopQPRrmyscYqByXWlaXdvkRHqhddsxoOSycuvwFOmxuueUkIv4jH07a8y69VYWjCuociG/otcrHaZkMFLgVFACkkHbtw= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0725.namprd21.prod.outlook.com (10.167.107.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:26:18 +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:26:18 +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.14 146/161] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Topic: [PATCH AUTOSEL for 4.14 146/161] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Thread-Index: AQHTz5jCSdTubh2rb0KcnFVcSec9/w== Date: Mon, 9 Apr 2018 00:21:52 +0000 Message-ID: <20180409001936.162706-146-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-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;DM5PR2101MB0725;7:ZvuhHy5VG8pDupRmr2oM9zE7P6M3kGmB7ofGLq5GVUxScx0YNdeb7HYaLFKN+0oz5huxxy8aM3ebVe3Plf+eo7JZFe1Lw+mdTFa75lw/IcivUA1ydSVuY9ivvz0DqgIljEzF3qeduRyeAxN5RgHJXjRQYXdySr9ivRd7zrDhkhaaDD1ENJFzId+6D83zlgU7WUiQZMjPhrFi0zUNgiPEhItnqp2epIxeyXyDFSB0+SAGGidaxeDbvVA1z36Q48JR;20:zjFl5nZnCu+o4SpoFMtIPM6786ua5p4ZxzXPFcPs6xC75/eB75DOU/EBYdxLXM0wAs222aZfCJRDX/p1Ms8XdfN+hRiPgGd/d7FjCi1hV+uMt7lQSGJBkENHRv5RKZTLM+iakrm5vnGvYg+LHknOO/GFTfLdlVd3Ra5635CXsUU= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: ffc9e790-249a-494e-479f-08d59db082fa x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0725; x-ms-traffictypediagnostic: DM5PR2101MB0725: 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)(5005006)(8121501046)(10201501046)(3231221)(944501327)(52105095)(93006095)(93001095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0725;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0725; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(366004)(376002)(396003)(39860400002)(199004)(189003)(6486002)(81166006)(26005)(6512007)(4326008)(6666003)(6436002)(81156014)(8676002)(97736004)(186003)(36756003)(72206003)(53936002)(107886003)(2906002)(86362001)(76176011)(110136005)(305945005)(10090500001)(486006)(3660700001)(102836004)(5660300001)(14454004)(476003)(575784001)(86612001)(446003)(99286004)(68736007)(66066001)(11346002)(54906003)(2616005)(1076002)(7736002)(5250100002)(25786009)(8936002)(478600001)(2900100001)(2501003)(3280700002)(105586002)(59450400001)(316002)(106356001)(22452003)(6506007)(3846002)(10290500003)(6116002)(22906009)(142923001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0725;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: Q0WtFA1bWQQnTB5/7fHDWuRXTYduDEELRBWDYIl9pLss24swELwCfAG55RZP21gOL3fPSaLfBRuGXo1PsOwdLCeaCWQM/CnXCHOkv8ILTWqDMkkaOn6pkG1yIp+0zRVjzh5ZkoW/IMWyoWpEV6Knib15FsTWe40nhvhORJZU2S9a1iGFZ17ky6NqIMS7/U64YlOA/cU2zi9WrrgOqqMRhjuo5MrDO7rfrSugVvs6DX1HtBWbo67NqdY3TM30NzO892qtLcv0y3AKs4jk72h4rjYe/LsWh8/m8AgIeBDxaVBXPt9v0/LWhyeVYtRKxAHQ3i0JKvWliJ072qMryovnCHQC3/gblMWpOZsOS4ZQBGwi8evGHoeFn1wLWzRB1P1BcLB7mxsiFd8s3471ewDwqNHcnGfG9TYsgH4dk2lmxK8= 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: ffc9e790-249a-494e-479f-08d59db082fa X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:52.7998 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0725 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 35f6dfcdc565..701d29c8364f 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -661,6 +661,24 @@ bpf_object__init_maps(struct bpf_object *obj) return bpf_object__validate_maps(obj); } =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; @@ -742,6 +760,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