From nobody Mon Apr 27 13:19:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7779CCA47E for ; Tue, 14 Jun 2022 01:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347395AbiFNBrk (ORCPT ); Mon, 13 Jun 2022 21:47:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241377AbiFNBre (ORCPT ); Mon, 13 Jun 2022 21:47:34 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4236EF70 for ; Mon, 13 Jun 2022 18:47:28 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id a68-20020a25ca47000000b006605f788ff1so6378769ybg.16 for ; Mon, 13 Jun 2022 18:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=l4PjIvONm1IQKFepEMuDqPyve0EvuaStAKHleWOI5U4=; b=keMrD0lK99MmEmZqNHED9SqQIvx29ap+MgANfW658dwlfZvJrsoNWlI9FXDBxqa+za VARGdXXoJmn5KryQWZj+8ScXKK6VXqNwAmxBq3WrvJtTYqyF49pPQeabsvoQ33dd7Zm9 GUdC5cio7eBOfzPKl6VgquXY1jLeMHFBa0mblXnksXxjh9ZBheHBbS2YBLkmyB2cnv0z RODtwrbl065MJcM4aR2i0vB2oIgwB4RMKqps974SsAItXpR+hUM9whwp/5wZxzkdRDOz ZEJKu26kcTh5Mj7t2oGlCPJPuLSeewLtsuZoU0kfm6Fy8cQ92KsRwUtE31ZwuEw4o661 pfTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=l4PjIvONm1IQKFepEMuDqPyve0EvuaStAKHleWOI5U4=; b=JFOiZTMYRytOVrT7ANR0h0HlFzP0Y1OZjzoPSNFthlYWxO1zYhDCX5pMxZl9fQ84uf qdXbBJhwLxfbMPSY527dsFJLwi12UvrqVCAid849KbLar9KXNQwwYtN1x9DEtFwMsxuQ 7C0ChSx2M2nkICcWKz2wRBgrNEFyu8wgq97n/k+9477lHXfGjcKkqdTKFY4MzMiMkB6g WMfogIIHdi/xlCJQtzqbTF1K64ECM9L3+hQqNHn43rMrGitckLvrtsADPkidLvKQ7J/t PiQ8tCzB1JDIHnaP8215/HqLKDI5SJ4vWqIAVaTCoxYzxzc7UybOrbMcTZFXwGD5q3j/ 7VIw== X-Gm-Message-State: AJIora+TMiXBH6nUIdGznKhL7x66xdEkMILmljj5e35lbqGpv+DCN9JD RDQ6uTWSxuY09w36I8Afs+zQ1CP3nUnQ X-Google-Smtp-Source: AGRyM1subzJdwRtf+vAOstyD6tqNevSviIR17aL9d/daU5mnA6A1DY7dA9Gj0iqv9t7BAYwDQeVntF57tsLy X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:e4b4:1d0c:1c56:a7ed]) (user=irogers job=sendgmr) by 2002:a25:3c45:0:b0:664:cf75:c2d6 with SMTP id j66-20020a253c45000000b00664cf75c2d6mr2520288yba.446.1655171248020; Mon, 13 Jun 2022 18:47:28 -0700 (PDT) Date: Mon, 13 Jun 2022 18:47:14 -0700 Message-Id: <20220614014714.1407239-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH] perf bpf: 8 byte align bpil data From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Dave Marchevsky , Quentin Monnet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" bpil data is accessed assuming 64-bit alignment resulting in undefined behavior as the data is just byte aligned. With an -fsanitize=3Dundefined build the following errors are observed: $ sudo perf record -a sleep 1 util/bpf-event.c:310:22: runtime error: load of misaligned address 0x55f610= 84520f for type '__u64', which requires 8 byte alignment 0x55f61084520f: note: pointer points here a8 fe ff ff 3c 51 d3 c0 ff ff ff ff 04 84 d3 c0 ff ff ff ff d8 aa d3 c0= ff ff ff ff a4 c0 d3 c0 ^ util/bpf-event.c:311:20: runtime error: load of misaligned address 0x55f610= 84522f for type '__u32', which requires 4 byte alignment 0x55f61084522f: note: pointer points here ff ff ff ff c7 17 00 00 f1 02 00 00 1f 04 00 00 58 04 00 00 00 00 00 00= 0f 00 00 00 63 02 00 00 ^ util/bpf-event.c:198:33: runtime error: member access within misaligned add= ress 0x55f61084523f for type 'const struct bpf_func_info', which requires 4= byte alignment 0x55f61084523f: note: pointer points here 58 04 00 00 00 00 00 00 0f 00 00 00 63 02 00 00 3b 00 00 00 ab 02 00 00= 44 00 00 00 14 03 00 00 Correct this by rouding up the data sizes and aligning the pointers. Signed-off-by: Ian Rogers Acked-by: Andrii Nakryiko --- tools/perf/util/bpf-utils.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/bpf-utils.c b/tools/perf/util/bpf-utils.c index e271e05e51bc..80b1d2b3729b 100644 --- a/tools/perf/util/bpf-utils.c +++ b/tools/perf/util/bpf-utils.c @@ -149,11 +149,10 @@ get_bpf_prog_info_linear(int fd, __u64 arrays) count =3D bpf_prog_info_read_offset_u32(&info, desc->count_offset); size =3D bpf_prog_info_read_offset_u32(&info, desc->size_offset); =20 - data_len +=3D count * size; + data_len +=3D roundup(count * size, sizeof(__u64)); } =20 /* step 3: allocate continuous memory */ - data_len =3D roundup(data_len, sizeof(__u64)); info_linear =3D malloc(sizeof(struct perf_bpil) + data_len); if (!info_linear) return ERR_PTR(-ENOMEM); @@ -180,7 +179,7 @@ get_bpf_prog_info_linear(int fd, __u64 arrays) bpf_prog_info_set_offset_u64(&info_linear->info, desc->array_offset, ptr_to_u64(ptr)); - ptr +=3D count * size; + ptr +=3D roundup(count * size, sizeof(__u64)); } =20 /* step 5: call syscall again to get required arrays */ --=20 2.36.1.476.g0c4daa206d-goog