Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1649229pxp; Mon, 21 Mar 2022 01:44:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn5JLp/QmZjzbbrOcgRFVki4KrmNpldItjgPfRBgXk/B7b/gAXwo3QgGZim9b+nbx5Fx7B X-Received: by 2002:a17:907:6d9d:b0:6da:7d4c:287f with SMTP id sb29-20020a1709076d9d00b006da7d4c287fmr18742367ejc.741.1647852279788; Mon, 21 Mar 2022 01:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647852279; cv=none; d=google.com; s=arc-20160816; b=HEpO4dD6zcrjaLt+2nF9mTz7ykxR4YcKdYMsNsdD+HGR/n3mkzt7FXwi/r30liKvg2 AJaEGRh5EsFN1IyqLFWvgswgUdFuEA0ba8Z59fD2UuEG1eqF3vAK6+F4o4fiEtLhKe8P fyjX8c8lcqTx3Mct1TCOwqdkTd1w9wNzFgsJKaVaJCaUeIsvcnQzv+PtCUTSLtltmd3S Wne+ZfSfo2PmjerlsAzrF4XjelCF68MNwpEwGLjVmcAWCqT27gV/55AvnvvtUa2nihZ2 EK2534CkjwMzcvUkAKS7XPovb4Z4fvYrFocUcnw7Vn/0cH7AqRXYo5KSJT+tcp8XIYhh UMng== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=YdfDvLiYSkwoveTevrFyxDKIAlT96ozvId3O7lsxmG0=; b=gsUbzB48cA2RrVHmiVUZkw8EhiZM4X+e+3Zz7cBrS58diqxbrHqJag4xFeA5HMtpGh Hy5tR8qM7WYNqx7jc5DBFsXdQcfadGolSR/yCHYFpv+jlHhX4ALH3+4DqC5evc4voPMg jCE2raVPyow0G8q5+BPBSWsKhaTMNHURO6op/zJFmEg6YQzBb8flHl5Zjn7+yOEGUUqt EzDScywLY48YYX3M9eLf9hPtpwk8C6IKs4Q79DCJdKPNSQdT11O4OBkNOcX7UQ4aHyea sp6DqtWs1rmEhZQ/4ppHcuLCm0C9PRCxht8WDzQJMS2SaEwzVmO/CSS6kqxdi0XLY57N ruzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fnIJAOcz; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m10-20020a17090677ca00b006e0201def0esi829899ejn.991.2022.03.21.01.44.07; Mon, 21 Mar 2022 01:44:39 -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=@gmail.com header.s=20210112 header.b=fnIJAOcz; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242184AbiCTHy5 (ORCPT + 99 others); Sun, 20 Mar 2022 03:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241285AbiCTHyx (ORCPT ); Sun, 20 Mar 2022 03:54:53 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99BA538795; Sun, 20 Mar 2022 00:53:30 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id p8so13018611pfh.8; Sun, 20 Mar 2022 00:53:30 -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:mime-version :content-transfer-encoding; bh=YdfDvLiYSkwoveTevrFyxDKIAlT96ozvId3O7lsxmG0=; b=fnIJAOczZfkcMTWxm71ikrU6gEZlqXkgoBp02rK9vmFvGqokGO6q7F4OOi9OF1tIOB YVXJj0ICg/MJxS365Px2eOqE0pGKiu8LWvFL+JZeozosE8v5+rc8u8/edZPB/yq+T5zc 00/E4kRq8N5RKxHfNuI5IVxviXDdK8durx0YX21qoNOELe5fgwOUxZyBvXZm+5l6hRk3 9WwuwwXWXVaqSawbzyHKfiUpClVopJNdmABS9eabkLvZCH2SYizwGtNb/AnNGT+jkeui Z2zP47M3DXSYgzIbsLktAR92RkrFDuaje4FvV5j3pRU0TQ8T1WDOYvqAwHkGpWfIxLqx nLeQ== 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:mime-version :content-transfer-encoding; bh=YdfDvLiYSkwoveTevrFyxDKIAlT96ozvId3O7lsxmG0=; b=UcAmuHFKefDFnyBG/kZHpyp+NUfS86BXUkzAzRtHkKosdaRcoQstjY9DT64cudqgXx SXMep9UqspRROxonRLuCUjbp2t4EM0ND7t2/XZBFoD+a7S1cob82mrH/RDuo4NMY6X78 T/1b2xAKXxFrzcTVG7YXP8ZuzyMo+4WXKguctukTUik1C84onv+CSyPqWJV4yQctmdSs dXgCiT0b8UwFHJFI5rgYXt/KwUV+sTyP0dnimD5DR2PSyb317Ofv7G7Cu5FYXFNhn5Up 5GZY82CWF9EtbLWNjkWyf4DFmJa8AnohUO/TKlkgCEbYB1u8timEmMlEfZir/ubRvHwY wy3Q== X-Gm-Message-State: AOAM533YmDC+sW5OYsyv5IYzsN7rra1L4kFAf3BMEeE/4/bQzrWqQPlq 2OyCe2OXH3PkMVjqsMWDY8Y= X-Received: by 2002:aa7:8c45:0:b0:4f6:bf82:7aba with SMTP id e5-20020aa78c45000000b004f6bf827abamr18350033pfd.20.1647762809470; Sun, 20 Mar 2022 00:53:29 -0700 (PDT) Received: from localhost.localdomain ([223.212.58.71]) by smtp.gmail.com with ESMTPSA id c5-20020a056a00248500b004f6b5ddcc65sm15162247pfv.199.2022.03.20.00.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Mar 2022 00:53:28 -0700 (PDT) From: Yuntao Wang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH bpf-next] bpf: Simplify check in btf_parse_hdr() Date: Sun, 20 Mar 2022 15:52:40 +0800 Message-Id: <20220320075240.1001728-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Replace offsetof(hdr_len) + sizeof(hdr_len) with offsetofend(hdr_len) to simplify the check for correctness of btf_data_size in btf_parse_hdr() Signed-off-by: Yuntao Wang --- kernel/bpf/btf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 6d9e711cb5d4..97fd853db16b 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -4480,8 +4480,7 @@ static int btf_parse_hdr(struct btf_verifier_env *env) btf = env->btf; btf_data_size = btf->data_size; - if (btf_data_size < - offsetof(struct btf_header, hdr_len) + sizeof(hdr->hdr_len)) { + if (btf_data_size < offsetofend(struct btf_header, hdr_len)) { btf_verifier_log(env, "hdr_len not found"); return -EINVAL; } -- 2.35.1