Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp923456pxp; Wed, 16 Mar 2022 21:27:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjc4fF2n0p2/CKsGHy+GJDdzowIbI+MxOBo1wacXSmn99RHJI0IcIA8/Mnf4tSrOz3QnGX X-Received: by 2002:a63:1e52:0:b0:380:ae84:256e with SMTP id p18-20020a631e52000000b00380ae84256emr2285616pgm.84.1647491275641; Wed, 16 Mar 2022 21:27:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647491275; cv=none; d=google.com; s=arc-20160816; b=wnqRBKV1f+kkk9p+xLZ3+91PX+oPDd5+i3P0SUXK18eawVcQ/ov+MUVyZB0MZJrBSl cT4PlvOilhiIiUAxzg9z4K4E23dGP4LiuPPrKcMGzkqo2ACwPheg3fJeohgtsYfXJ+h8 7Z+sOan0YrlvSRnXPMVT0oRkyTFwbHt0KIfrh+5GkAQDGl3DhI0uqDdWpgJhX6LkE2Dw 7GJ0A2gX+UJoyStKI1dDAcPcnJDchH784GQpbTDp1WWQv4FJNIgUpOOllW+LL8p5UrHQ PeD5ghAxRiGPN23xgIVPL1NOaJkdfk1yy3CBm25pb5iXc5B4+C0XINBbPcawn7w6xxcf TxAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JKCi7Su9vnsmUw/t9IHlylpTsFhsnuAWupOqKFBulF0=; b=ECXq2anHd2ZdoBRLW8DnTtroWnzdp7kJDbhmhgBXK3ddDp9O2qWQHfkDDBISAZniAt 8qaPeKFNg6wsrvb4cYW/qCMY5aLPAiLoKH0OQjxP/Uhr2HGVDnbNW9TtQsZPSb1dDIZI i8POws/n1DcwShL8VGEBRfHO3Mxovsw2dT3TJJkXXaOy6ISgBbejMpJSZE96ZKPhdhEB BXWA0VtZleemuZdg78jHd20BFjSxz0dRW1jzdRQgeEVMaIHTXD78vmHfxsyjVYKaTcUR eP65LqctXsG00Q06RBVLYIrzl8jDp3RTDezlJv607N2V2wfoEvlKUBI1dS04bF8VSSXE AL4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lCSV2spD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a14-20020a62e20e000000b004fa1128efb8si3657903pfi.217.2022.03.16.21.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:27:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lCSV2spD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA29AEF79A; Wed, 16 Mar 2022 20:58:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356900AbiCPOyQ (ORCPT + 99 others); Wed, 16 Mar 2022 10:54:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356899AbiCPOyM (ORCPT ); Wed, 16 Mar 2022 10:54:12 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DF6913E36; Wed, 16 Mar 2022 07:52:58 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id z12-20020a17090ad78c00b001bf022b69d6so2635287pju.2; Wed, 16 Mar 2022 07:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JKCi7Su9vnsmUw/t9IHlylpTsFhsnuAWupOqKFBulF0=; b=lCSV2spDvHv9GvZYRwqzrDNf8h7uO/G8Oz+wQmgvz9b9U0Pap2otnjQ9PG/bsJQGUz hNz0R5dFAk2IYEdpxb6WDLRc9fpmE/TbLNS5toackiN4zLX35TBGLl0X4WATG3F8fzzf 8IpSoMY+ehovP4fHEn7aLhEv87PDNdpWzC0u6vDv76gZDRHInyC4salkA/JTVezkmvzN vFYiXozOG/PEHlx73ms9VpDTUlF/IQdCt0Fbcs7Z+4B3k+h3wl/kiPgwaqGxFsPnE7aA vFaGLNI3K5qVn8qM3TFNe/DkcGV97tShvjHVwPcgRE/fqvglThBbrUQjjwyINLwxO8iY cLdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JKCi7Su9vnsmUw/t9IHlylpTsFhsnuAWupOqKFBulF0=; b=doe4GoSHyjB0LL+Jf6VDsgtit0ofKe3AfLnw1GPY+4CaIwEmqscAlTwwLBFnbTGfzq rXeaONun7xx4oFM/9ztEJIp+awI7SSwyBamwgRhQfqlQMofq4zlyL6sLjM/rbKWy21xS m8lw1QTZTOq/nRFvj73BC0+xMcumaguMtjhP/ubOQ4McDDZYlbE9o3gcohoNvRgUIYwk MZQRMuSjyLT8EhNpbCMWSz4rVtBeHAHHoaXgzMTE8jmYWCCsWCnV4NajWobX6VzCteNI V05VEx6b6ltrD2tYHAT+ffmV5aSZYTdpmI+e1YBk5MqTW2Eu0ADt7EjVCtJvolcccbqJ Bb/Q== X-Gm-Message-State: AOAM531z9TICJmP3gdMPlWElAz9lcGVi9vtJYWP0YzWbxqf2TvXcvkGM XCSVOafhuulSU3LPLIX4NUtzbVzFTFfABg== X-Received: by 2002:a17:902:e944:b0:14e:dc4f:f099 with SMTP id b4-20020a170902e94400b0014edc4ff099mr290909pll.161.1647442377709; Wed, 16 Mar 2022 07:52:57 -0700 (PDT) Received: from localhost.localdomain ([223.212.58.71]) by smtp.gmail.com with ESMTPSA id p10-20020a056a0026ca00b004fa06fa407asm3659915pfw.91.2022.03.16.07.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 07:52:57 -0700 (PDT) From: Yuntao Wang To: andrii.nakryiko@gmail.com Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, kafai@fb.com, kpsingh@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, songliubraving@fb.com, yhs@fb.com, ytcoode@gmail.com, toke@redhat.com Subject: [PATCH bpf-next v2] libbpf: Don't return -EINVAL if hdr_len < offsetofend(core_relo_len) Date: Wed, 16 Mar 2022 22:52:13 +0800 Message-Id: <20220316145213.868746-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Since core relos is an optional part of the .BTF.ext ELF section, we should skip parsing it instead of returning -EINVAL if header size is less than offsetofend(struct btf_ext_header, core_relo_len). Fixes: e9fc3ce99b34 ("libbpf: Streamline error reporting for high-level APIs") Signed-off-by: Yuntao Wang --- v1 -> v2: skip core relos if hdr_len < offsetofend(core_relo_len) tools/lib/bpf/btf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 1383e26c5d1f..9b7196b21498 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -2826,10 +2826,8 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size) if (err) goto done; - if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) { - err = -EINVAL; - goto done; - } + if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) + goto done; // skip core relos parsing err = btf_ext_setup_core_relos(btf_ext); if (err) -- 2.35.1