Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp744195ybh; Wed, 15 Jul 2020 14:07:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1Zd0xKNxpYiSyAHRhv51HNUz4jQSu9RJemiN0Ddt1NLYodjPhoIVDVgqZEEWcK/SyTJW7 X-Received: by 2002:aa7:c31a:: with SMTP id l26mr1437033edq.61.1594847279401; Wed, 15 Jul 2020 14:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594847279; cv=none; d=google.com; s=arc-20160816; b=gEiGq1qYJqYg9vQntrUvoCJ4e0K2WHcfXmaKC/AWL+SwNSciH8saYTuSmxSdgXR/Bz qv0pFDkKeX5TZUndymP18jiC9gi6SOuUONxhcojdDhmIKSXWyJJ9RVvXGyhu4Z+1z7ZP dMCnuUtXcl+qr8jeEfga8Fvhgcrl9kh5YFIoGkTnAqrdIIUpBjBUIft3ByAmzXIl4k7p ItilObH9NuMCn7f7iD+2YhxuYZXSdWVLHz42fiXIgljNt49KrqlLk35mM6SGBSchURE7 /6Gl0CijMhngaFb6y0LWr7IkXts8ReI43LL4A0JQLgpjd/eH2wx+kKiSmm8ddco1nadV YHfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=4CA3+FbNyBKeP09ZxsJCS+WiPseOhRLkIdqBJ5s4vNc=; b=ilpWqae0fzLRAZLCaNiESU3vWNQLonilQSOweAaAfE9rnI5SKep9Nu8nblS9Z9P06h 1q+IK5maf9tDt3BL1rg0IbHGhEFpPgJEhi33+IQn3rMceamJJzaEySchoD5RJKhI4x+P r04F5aGI1voSeiBxuTm69i+RADh0xvCNnLQoWJuU4vNpY6Fsp4eQLKGd5dc2t9XjLmPh MZjrAqwC/VNMQhavAbeSLzwzunA5mNnsmyT7C2E3pEvy7DOLsE6jdz3Ev2t2YWDcjW4O YTf4fIxteCBTHIRjBECu5kN36jNt/v+FtW0F/vVZiQUsx08MuiQF0kCC6qWRcl8t4FHA fRpw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z24si1916723eja.705.2020.07.15.14.07.36; Wed, 15 Jul 2020 14:07:59 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726821AbgGOVHZ (ORCPT + 99 others); Wed, 15 Jul 2020 17:07:25 -0400 Received: from www62.your-server.de ([213.133.104.62]:51196 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbgGOVHY (ORCPT ); Wed, 15 Jul 2020 17:07:24 -0400 Received: from sslproxy02.your-server.de ([78.47.166.47]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1jvocY-0003ol-AP; Wed, 15 Jul 2020 23:07:18 +0200 Received: from [178.196.57.75] (helo=pc-9.home) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jvocY-000Rp7-0q; Wed, 15 Jul 2020 23:07:18 +0200 Subject: Re: [Linux-kernel-mentees] [PATCH v3] bpf: Fix NULL pointer dereference in __btf_resolve_helper_id() To: Peilin Ye , Andrii Nakryiko , Alexei Starovoitov Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Greg Kroah-Hartman , netdev@vger.kernel.org, bpf@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com References: <20200714180904.277512-1-yepeilin.cs@gmail.com> From: Daniel Borkmann Message-ID: <3b97c5bf-9f07-0353-ea4d-f90574fbcdc0@iogearbox.net> Date: Wed, 15 Jul 2020 23:07:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20200714180904.277512-1-yepeilin.cs@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.3/25874/Wed Jul 15 16:18:08 2020) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/14/20 8:09 PM, Peilin Ye wrote: > Prevent __btf_resolve_helper_id() from dereferencing `btf_vmlinux` > as NULL. This patch fixes the following syzbot bug: > > https://syzkaller.appspot.com/bug?id=f823224ada908fa5c207902a5a62065e53ca0fcc > > Reported-by: syzbot+ee09bda7017345f1fbe6@syzkaller.appspotmail.com > Signed-off-by: Peilin Ye Looks good, applied, thanks! As far as I can tell all the other occurrences are gated behind btf_parse_vmlinux() where we also init struct_opts, etc. So for bpf-next this would then end up looking like ... int btf_resolve_helper_id(struct bpf_verifier_log *log, const struct bpf_func_proto *fn, int arg) { int id; if (fn->arg_type[arg] != ARG_PTR_TO_BTF_ID) return -EINVAL; id = fn->btf_id[arg]; if (!id || !btf_vmlinux || id > btf_vmlinux->nr_types) return -EINVAL; return id; } > --- > Sorry, I got the link wrong. Thank you for pointing that out. > > Change in v3: > - Fix incorrect syzbot dashboard link. > > Change in v2: > - Split NULL and IS_ERR cases. > > kernel/bpf/btf.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > index 30721f2c2d10..092116a311f4 100644 > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -4088,6 +4088,11 @@ static int __btf_resolve_helper_id(struct bpf_verifier_log *log, void *fn, > const char *tname, *sym; > u32 btf_id, i; > > + if (!btf_vmlinux) { > + bpf_log(log, "btf_vmlinux doesn't exist\n"); > + return -EINVAL; > + } > + > if (IS_ERR(btf_vmlinux)) { > bpf_log(log, "btf_vmlinux is malformed\n"); > return -EINVAL; >