Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1043329iog; Mon, 13 Jun 2022 19:57:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tcEgijhuGXUWTUEGP679SIajETjm/1V/i/Z1K/76k8tIKXdVV1KUw8qFo2ZYML0MKeq5Jt X-Received: by 2002:a17:902:d0cb:b0:167:8f4d:92e6 with SMTP id n11-20020a170902d0cb00b001678f4d92e6mr2385826pln.83.1655175439690; Mon, 13 Jun 2022 19:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655175439; cv=none; d=google.com; s=arc-20160816; b=sSYF5v9gDizUqu/Xy7PoCLI7ZgwIp4YDWk9HY85HK0lMReVAlmPs6iGFwWdSQQ1YG3 I8EQiH4tfIcbnDCDVY9OpxXfxvHVaKnEouOMUf0MyXJv6s0374tQaltSe0EDIXufcylg ECc4lJ4pgGo01OKiBJo54MdFrYUR4pmrPq9Oz+WhqOqxJ7cOf/kQpg6Q7FSmPoZf0fEN gXO25kQ8/9/4VOH+uXIStmY8CaCrDTvdpe8OSFRiMtfgSwce6ELrpsU9P2gNEtAuEzmW TSxpZv8brDUFeFxrf04ui8xT/kxIfR0zf2ZSf436CHP+Ssl29mGjupeQTriHDJ4XXTtn +i+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=l4PjIvONm1IQKFepEMuDqPyve0EvuaStAKHleWOI5U4=; b=qj7+hnYo2f6tPB/AilVcDwDh8OHz+yLctArJeqG5AEIgujB+p0ix5WIE+NzgAO4S9e FMYkWeNDHjyY772w6NYfY9w+EtXBmkBpGlynnKjt4a+yk8cKJBKYV59zqt5+N1NwfBqA b6/FlTOl7qZLtPW+qMkAXBMnqgzdOmr4qZv5wd42Iw+Hwl77MsatX52sHVYeNByW+sfO G4xeZGFMbDr4yGaw37YFelooga9mJ5aa+aBRNAT4kSYX/1Ztu4a82gsD3zD/I8pzcYwo h66cWSH/tLdfESeMQtZRwOJEFXOhmT98hACYuAxzeIFmgNPQXI/yfGAuod3ZaT6hHLpG I39g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=keMrD0lK; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020aa78006000000b00518984386ebsi10937783pfi.37.2022.06.13.19.57.07; Mon, 13 Jun 2022 19:57:19 -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=@google.com header.s=20210112 header.b=keMrD0lK; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344027AbiFNBri (ORCPT + 99 others); Mon, 13 Jun 2022 21:47:38 -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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 bpil data is accessed assuming 64-bit alignment resulting in undefined behavior as the data is just byte aligned. With an -fsanitize=undefined build the following errors are observed: $ sudo perf record -a sleep 1 util/bpf-event.c:310:22: runtime error: load of misaligned address 0x55f61084520f 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 0x55f61084522f 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 address 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 --- 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 = bpf_prog_info_read_offset_u32(&info, desc->count_offset); size = bpf_prog_info_read_offset_u32(&info, desc->size_offset); - data_len += count * size; + data_len += roundup(count * size, sizeof(__u64)); } /* step 3: allocate continuous memory */ - data_len = roundup(data_len, sizeof(__u64)); info_linear = 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 += count * size; + ptr += roundup(count * size, sizeof(__u64)); } /* step 5: call syscall again to get required arrays */ -- 2.36.1.476.g0c4daa206d-goog