Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4221750pxb; Tue, 10 Nov 2020 10:45:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdTnktolJuAtxdtQTfDgmNOAgXFlRNDqDSy1w6Rm8j5zggpWAgsMK7U1IXAoVXZURkYCZ1 X-Received: by 2002:a17:907:411b:: with SMTP id nw19mr20786426ejb.150.1605033922721; Tue, 10 Nov 2020 10:45:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605033922; cv=none; d=google.com; s=arc-20160816; b=BASG+0CUKue0LO/6TJfoHBNlTSC43A1b/pA/MpFZdj8Ne8Q0xQgWUIHzZJm6Shrwc3 ipa+EexRM7FOP6P2uz2/T5NBpzRPNskBMVr5QPuqyM8cc4l8C2T40NJz0oLwfX5U0SJ3 o42/K9lgjpJZ+LLON3/nZlKbVAezyktLRENaA8ChsNo+9da6T/+CSuL66csfK3j21K2e DKGn0vAku+mHTcleTqTE2/twb4vyEMzdMb+f0bbPX/3cQML8sC14dVvWE/UkvEgw4Oq0 6Kh0mY8y6P0WmVn2XxrxzvUOxq0SobvSDsaD4OB0yUzbVCXZoDuZ2oi1MdYjwD3kuvEM VyqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oOeFUNM4jhGqbawcUIauzPQF7fQF7Oz58AeNbXhLGQQ=; b=a3A6qg04fECSj5P7NEn6wSSgosFXZ0rTJpjvkwSYKCI7D2KD2NEX3Cj7RrjpmuonGr Nk7pbzmy5fPG6asYDyEgR6tc3sxNkYhV88IBMb38KyWBicZo+5x7/8UigU/wAi9baG3h X4fI4lUTWaLpr3erVOydtzOb6uU2sz9+nHU/sA25w3L2dzWq7bGdJG9wMmZWOfEChGmw AgKPNzTI2UeSsGKyfH4yvpyo+MATmK9fMyw0r2I8zgAPY8zre5CybQTZK5BPSE//D1cU WkWsHh1+D9zwT5lBlOaucOACktnkB7x0i+tZoW5vnXDpo85UPjQua3o37JCKIJAMQCLt 466w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Akbtt04u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w6si6515014edj.604.2020.11.10.10.44.58; Tue, 10 Nov 2020 10:45:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Akbtt04u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731323AbgKJSnI (ORCPT + 99 others); Tue, 10 Nov 2020 13:43:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbgKJSnE (ORCPT ); Tue, 10 Nov 2020 13:43:04 -0500 Received: from mail-yb1-xb41.google.com (mail-yb1-xb41.google.com [IPv6:2607:f8b0:4864:20::b41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7007FC0613D1; Tue, 10 Nov 2020 10:43:04 -0800 (PST) Received: by mail-yb1-xb41.google.com with SMTP id s8so12576563yba.13; Tue, 10 Nov 2020 10:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oOeFUNM4jhGqbawcUIauzPQF7fQF7Oz58AeNbXhLGQQ=; b=Akbtt04ubbIMlw8fPNnZFiGcd4HWgJ85/0qMrauXJB+xPCHlzIzo/DMDO63ktPEWG3 T0YZYD8KL589ofpUbK+liXUChLeA1fd/XDiK0Sra29yQlrJ6JANNalpXv5i0woB6M4lL Bb5pOL/VypPyQiwO5MbjWHMyWlbz7n6gGIi+8fI+yYWQrBuEAReL+cYGQK77O8u8T4mS Ca7KGRYQs5/1+cj5iwrizjM6iGkXJ5t9yrQDqyVbQvFmYDdinYhGAJOGudc6dfJFa846 RxnRZWxZ0C2mvxlo78l1DPU2mBTNvYGJ1SW0e2sLGXArEgfSQxo48zAfRzkTYuCVfJUm Kb6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oOeFUNM4jhGqbawcUIauzPQF7fQF7Oz58AeNbXhLGQQ=; b=fALw/d3X2FiUEPUT6cbasbWeh9Q7QVI34s+CBLCWCD3BrF0BrsuUxCUGsJClMhpToV Fowzj46fRtaY/kObZ+IRWQCcbnGAaceheFzU681E1L5X+XPmDDCJ44AR74rg9ei14F/6 Zr4anCKwuRVK9HzASFVYHcIU0tcmm5SG5LvXaM6C6G68cAFfpz4/au32nRd2WasCuBDJ huRZz5wcdn+1m409XhNkz/uD3XGXcH41ljrlckgmRooYs20btmT23xP1X7yqrKcL7o4l 96Kx1wuMUNj8HM06Wr4Xx7tyob9hf3wWIBVxZdJpyyJUcUwtKyKIjEeq/2nNuIT7mn8z dWGg== X-Gm-Message-State: AOAM5337+It4BJ69wqp9Kt3p0ucHRG9ulRtX3VYIi70fTWOoij1jiq+H JdLHouwoWyjdmWuPNHYWCTEXtybnx1don9bGQJc= X-Received: by 2002:a25:585:: with SMTP id 127mr17284941ybf.425.1605033783761; Tue, 10 Nov 2020 10:43:03 -0800 (PST) MIME-Version: 1.0 References: <1605009019-22310-1-git-send-email-kaixuxia@tencent.com> In-Reply-To: From: Andrii Nakryiko Date: Tue, 10 Nov 2020 10:42:53 -0800 Message-ID: Subject: Re: [PATCH] bpf: Fix unsigned 'datasec_id' compared with zero in check_pseudo_btf_id To: Denis Kirjanov Cc: xiakaixu1987@gmail.com, Alexei Starovoitov , Daniel Borkmann , Martin Lau , Song Liu , Yonghong Song , Andrii Nakryiko , john fastabend , KP Singh , Networking , bpf , open list , Kaixu Xia Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 10, 2020 at 5:02 AM Denis Kirjanov wrote: > > On 11/10/20, xiakaixu1987@gmail.com wrote: > > From: Kaixu Xia > > > > The unsigned variable datasec_id is assigned a return value from the call > > to check_pseudo_btf_id(), which may return negative error code. > > > > Fixes coccicheck warning: > > > > ./kernel/bpf/verifier.c:9616:5-15: WARNING: Unsigned expression compared > > with zero: datasec_id > 0 > > > > Reported-by: Tosk Robot > > Signed-off-by: Kaixu Xia > > --- > > kernel/bpf/verifier.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 6200519582a6..e9d8d4309bb4 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -9572,7 +9572,7 @@ static int check_pseudo_btf_id(struct bpf_verifier_env > > *env, > > struct bpf_insn *insn, > > struct bpf_insn_aux_data *aux) > > { > > - u32 datasec_id, type, id = insn->imm; > > + s32 datasec_id, type, id = insn->imm; > > but the value is passed as u32 to btf_type_by_id()... > > btf_find_by_name_kind() returns s32 Right, valid range of BTF type IDs are >= 0 and (significantly) less than INT_MAX. So s32 is used to signal valid BTF ID or negative error, but all the APIs accepting BTF ID accept it as just u32. > > > > const struct btf_var_secinfo *vsi; > > const struct btf_type *datasec; > > const struct btf_type *t; > > -- > > 2.20.0 > > > >