Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2248105rwn; Fri, 9 Sep 2022 10:33:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tR03/jdN/W9M5YelGlxkskFIqBBL2/XuKVukiO5AUGKJ9fb3CoPX3ehEKCrOESksVpeiZ X-Received: by 2002:aa7:d703:0:b0:44e:a7b9:d5bd with SMTP id t3-20020aa7d703000000b0044ea7b9d5bdmr12472863edq.425.1662744782138; Fri, 09 Sep 2022 10:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662744782; cv=none; d=google.com; s=arc-20160816; b=qEsnSQBZi1IQDVO/7OCATnw928vy/4Wh/FpFaJG7nSW4mIe2K3+H5QL7Aq11HSBaVt ptzUH2Jz7p7w7C1ipNK86zidU62SvjbkreVOPvpUq5LHUTD+uikeo3FKCcAydjYWLO2r +h5gEBOs8o8Ovm/cdpRja3iePDrcb8sp8LRKfjQNb5sgXdiIwx05toWVUA3aDgVP4h9S EEOBHraZA3BKNfE9vfU6ZhZY5QdGG3UZ0cW5M/9JEfG+4GnnZEdB87tsvgt/jiXalbAu wl/jHI54GVuou0Yt8hmTr8PFehjAgg3wjhzyw2l7xZv9Y6yEy/y94LYlk0iw98HBzqp7 Gn4g== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=y+S5AbIHCrepBfZ2rw1p2j+yX8LnWjY6X4hW/K5B26E=; b=KF2ROj6w8olrtqt3WEGISoGE0sFKDbEh1l4anLMYjHesIWT4Ru6c8KkNfYNnq00QGy bIPwZDWmkkLG1aCvel/59GOg9UggfqUz+fKuYau2pXqCm/zdxfOom0qaKs1cX1wAeRnf TBUEi4UICUtQ0EoaMpYzFrMTzBe6ziUCQVNsCSiQ+mQrKlfM9AUvymhLQTOLUhwqG9RA wwdqjKGRUd1U6SGp7o1oFMuNHJGQizDc26cj2cTefCf3x3jUWsGeXK2MpumK550knFAf 9jYnG7JFPhyCYHj++NsbqWUpQEAAWiUQLkIRddW5aGzyqT51b59QJK6tEvHuG1ebPF3u tgTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FBPCZrVg; 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 h1-20020a50c381000000b0044e87bd5f9esi857028edf.406.2022.09.09.10.32.36; Fri, 09 Sep 2022 10:33:02 -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=FBPCZrVg; 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 S229622AbiIIRTs (ORCPT + 99 others); Fri, 9 Sep 2022 13:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbiIIRTo (ORCPT ); Fri, 9 Sep 2022 13:19:44 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A2425C53 for ; Fri, 9 Sep 2022 10:19:41 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id x25-20020aa79199000000b005358eeebf49so1382956pfa.17 for ; Fri, 09 Sep 2022 10:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=y+S5AbIHCrepBfZ2rw1p2j+yX8LnWjY6X4hW/K5B26E=; b=FBPCZrVg3A5xkX2OTUS/Lt5/hDbXEhiQzndmF1GMlIGtCP4Bd8a13tQ+23xzbZ0ced v4ss1uefZSpho+Io18qZ+Q7r9x2x9Ef9TtZDBqgdSJT71TiOHKxQ/E5cuNX5/e0ytcrZ 6hVEESy8F2bpVXFdLh9X3uCCGCdxvW6hZeK58BRWrYrlp/4dEwNxq/KN+sUvaAEY/pXI CaDnNMgVJzv6jcv674hbQp69SmAcCHSU4Wg615K+yZaI3vOsYdNVNtZGFstnWjB2YnFF wrg7EdS6+aH++GFOG0YRUFiWMFi48S1xF1bfJ9aIvTpirymw0rb4fI/mwkCtE1SNIS8U JMpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=y+S5AbIHCrepBfZ2rw1p2j+yX8LnWjY6X4hW/K5B26E=; b=Cxh5N6YUP3X/lXGa8tgpRYsJgXV5akHGDb54PbbSiBytif2g48xhzj3eaLQN0Ti2pZ NyXksDLjL5H4wzKB6hZoNIMEDuQv9SgrK4jyNXw8ZAokfZhuMOLnVN5n2wgTmK3q05zL s/pDKK0Q48LMblI2xMRaKsDuJ/+HTrFseEwFtDcfCY5rs82xmwL5ujwNAKu3UHuvbSvJ sj1rDFmxuaDeRvJ0u552aj0eLgFH3Mrk4mP/kd+Zs8eUHVOpf1pD3btSMHDw+QqXF0u0 yvHDo5ft/UeqdyFXXhtS1ZxNWwYzvglIdIzpaeCfmKwWtXtoQpTUjbqDyo09LL4uWBS5 +I8g== X-Gm-Message-State: ACgBeo0nxNj/OfJqC0uu9G58jNqTZB1M/uPwVAek2s9liC6BNXuEnyXc MWopM6JbF4EOn2WwklE9gDOFo6g= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:90b:10a:b0:200:2849:235f with SMTP id p10-20020a17090b010a00b002002849235fmr202016pjz.1.1662743980876; Fri, 09 Sep 2022 10:19:40 -0700 (PDT) Date: Fri, 9 Sep 2022 10:19:39 -0700 In-Reply-To: <20220909092107.3035-1-oss@lmb.io> Mime-Version: 1.0 References: <20220909092107.3035-1-oss@lmb.io> Message-ID: Subject: Re: [PATCH bpf] bpf: btf: fix truncated last_member_type_id in btf_struct_resolve From: sdf@google.com To: Lorenz Bauer Cc: Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes 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 On 09/09, Lorenz Bauer wrote: > When trying to finish resolving a struct member, btf_struct_resolve > saves the member type id in a u16 temporary variable. This truncates > the 32 bit type id value if it exceeds UINT16_MAX. > As a result, structs that have members with type ids > UINT16_MAX and > which need resolution will fail with a message like this: > [67414] STRUCT ff_device size=120 vlen=12 > effect_owners type_id=67434 bits_offset=960 Member exceeds > struct_size > Fix this by changing the type of last_member_type_id to u32. Makes sense to me; I'm surprised the compiler isn't raising a warning on line: last_member_type_id = last_member->type; Reviewed-by: Stanislav Fomichev > Fixes: eb3f595dab40 ("bpf: btf: Validate type reference") > Signed-off-by: Lorenz Bauer > --- > kernel/bpf/btf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > index 7e64447659f3..36fd4b509294 100644 > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -3128,7 +3128,7 @@ static int btf_struct_resolve(struct > btf_verifier_env *env, > if (v->next_member) { > const struct btf_type *last_member_type; > const struct btf_member *last_member; > - u16 last_member_type_id; > + u32 last_member_type_id; > last_member = btf_type_member(v->t) + v->next_member - 1; > last_member_type_id = last_member->type; > -- > 2.34.1