Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp69824pxb; Tue, 10 Nov 2020 20:16:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9qkvDH72mBLmEYsPFn1Aptvchri/UVkjbMPyqnEu3Ub75NOwZICS4bU3AoUBBjvhOVVhW X-Received: by 2002:a50:fd8b:: with SMTP id o11mr24859195edt.156.1605068188812; Tue, 10 Nov 2020 20:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605068188; cv=none; d=google.com; s=arc-20160816; b=o3SbzJtBDYmobYAEm2oFCXUKonhZOd15f9aMOd0/sHHRH6gNBfZC/vRXh91rocZX16 Sxy6omU2dQIgO3IhNvvJefnfIbWhdVlfvbqxYiK9hXiB2y4StG5PJuEsnopH2wIE2lPj vH5VQNg0LLXVUvWz+xdcjD5U3YGF+PUi/LGqbDIsbK7EZ1P8Ehl4cK/TNgkO+8aJV+WU 02k5675R7Vy0oK7ZxHZI7iarNWXU8N32zAcNZg7XRwrtiH2+w7A6LgldwtKX5j0tw7Gc 9vUVHvJhPNuvWwPKh1mSZeu3R1VhGjHDeusXRAkapYnAIQgcuiYREAOEOlbUR4TIy/g7 5OVA== 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=JGIhTX1iYBMgF744IBDkziq2Q7vA4MuCaT2yYSxn/kE=; b=xkFg/1LMpP8RbTSWZgQgEMqva/qvlip0r13HdWMOk4BkrVjyUgMGObI+GCkGFcvEfs I0nxH/zJ9jEJlNumEzCeb2Y4M3LouJ7Zm1DLZqUUCbvLHYsfafmx2mtnbG5FfiItqaJN nI3XV+gDgTHe7HKMR8nI4eu94wLunS7YJ9tZ3JeYfLyQ3PZaPcKgzbtifkUnbV9DABDR ysvGN3DJYvwCcHQnDYchlNVBc1crmf0iYdNaTbJ69yAKZqaiLIH+M5yEYK/LpW4zDnEu Xa0a/L+RVUu9Eqhoo3AjawoWpg4OIM+46UkOs5+nDD//3pxSSZPUDtleoCWtal1ncu59 GWVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="afZuz/fE"; 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 f22si466547ejd.707.2020.11.10.20.16.06; Tue, 10 Nov 2020 20:16:28 -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="afZuz/fE"; 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 S1725999AbgKKEOq (ORCPT + 99 others); Tue, 10 Nov 2020 23:14:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725870AbgKKEOp (ORCPT ); Tue, 10 Nov 2020 23:14:45 -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 D7CC1C0613D1; Tue, 10 Nov 2020 20:14:43 -0800 (PST) Received: by mail-yb1-xb41.google.com with SMTP id k65so699348ybk.5; Tue, 10 Nov 2020 20:14:43 -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=JGIhTX1iYBMgF744IBDkziq2Q7vA4MuCaT2yYSxn/kE=; b=afZuz/fEsATObkVGZ+Bdyj20ctN1tN/V4gTs0dyEazHIIuQ6jPQzez7wr+WEz4atmY +t0QsgNpbbUk0dWgGOuxHImRYr1Ru4MuhwuWSEwpsrYIILV023mM+AtPfiwJmwM+tFCi 7nw72CGuZt0KbRRLPXbfVVBDBHQfkawlN9iqzLo7evCak50NXx7qaLKvSBZtalFdr27G eBFMj9kFdWKt8tyIMbjVJYtHvmWJMkIpFLnQjEA862KPJbaPOFnjpXUuq506qmAj1kEF h/512GNHzzcdeqad+yRCkIfWXJRyPk42b1+XMrQ2rcO95xWJV6zOCiYsdnIQDkxeE5lB QbgA== 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=JGIhTX1iYBMgF744IBDkziq2Q7vA4MuCaT2yYSxn/kE=; b=I9cozBk7F5/sDL8Kj5K/sw2ZQOKTsBMX0kT/8izceLWaJOgs26YVPBaqUgE6XSeUad J3EURnYqNY/U1FCmdduvrLZYmL1BsBj/nqbuOzMDZvOfhQKMD1Ry80Nfxu9LqhiMw4sK GO7bABE4xa1IjCgoVfN1OrT8AVMTBML5AG82wNZ+wofST82wAHAK6dVB83z9Ji4VCK9e IaHdVYqy7GM0h9g3uqq3GvHyu1bRuuuM0osnGuYEXsD6VUrcUxi7u6iYhqB7y9d7joFx YbKYCJRmG+6CN0kmQoTQpbmj7+d/GBdP3dJ5dTL5grXFoJ7N2O0CTX1jIcnD2g/FHlna F3SA== X-Gm-Message-State: AOAM530Ta9F8WHTyz2pKJPfsA5WzFgw1SY3yJ07dauOf0r72wvAyydHj t/SExBfM3BVBjJuMgreMLHCZBHYHJcG3iF7Qv3I= X-Received: by 2002:a25:e701:: with SMTP id e1mr6632254ybh.510.1605068083120; Tue, 10 Nov 2020 20:14:43 -0800 (PST) MIME-Version: 1.0 References: <1605063541-25424-1-git-send-email-kaixuxia@tencent.com> In-Reply-To: <1605063541-25424-1-git-send-email-kaixuxia@tencent.com> From: Andrii Nakryiko Date: Tue, 10 Nov 2020 20:14:32 -0800 Message-ID: Subject: Re: [PATCH v2] bpf: Fix unsigned 'datasec_id' compared with zero in check_pseudo_btf_id To: xiakaixu1987@gmail.com Cc: 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 6:59 PM 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 > --- > v2: > -split out datasec_id definition into a separate line. > > kernel/bpf/verifier.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 6200519582a6..3fea4fc04e94 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -9572,7 +9572,8 @@ 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; > + u32 type, id = insn->imm; > const struct btf_var_secinfo *vsi; > const struct btf_type *datasec; > const struct btf_type *t; > -- > 2.20.0 > It would look a bit cleaner if you did it this way: diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 10da26e55130..f674b1403637 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9585,12 +9585,13 @@ 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; const struct btf_var_secinfo *vsi; const struct btf_type *datasec; const struct btf_type *t; const char *sym_name; bool percpu = false; + u32 type, id = insn->imm; + s32 datasec_id; u64 addr; int i;