Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp706381ybi; Wed, 3 Jul 2019 03:23:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzujd1TbVGd2xNehQE8BROToxyyUXCtXNxTOCMM4ofxrAQ1PmpcNEAmyKpASzBwHjd6Wsn0 X-Received: by 2002:a17:90a:37c8:: with SMTP id v66mr12081520pjb.33.1562149425504; Wed, 03 Jul 2019 03:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562149425; cv=none; d=google.com; s=arc-20160816; b=ZJA1VPqpBDIjwUxu+P4jzCFmpkHZ19MDaaEVfv4XQ7FyXG8O3kqzFAzUQ58z0j3Ioa 8uY3AMXmkohZKBCJi3UGtmVVRbXA/suFJca4HZ/4GnzEA+/RB+2vzjbbSGmfe5ZGNC2d K/bL65dibvECqJDcq7hvUu2EFPTOkny/KQAPfxhI1Blsbtj4q/2TJNpKuyV3TjbJGB8k E/QEi+lwBZHisy2n8zaAjm4MQN0jBUCdSF0EgbY6iQyxVgweGnf/C6vB2MLnxbo+ZXHJ rkPjzg4bBdfyug2Ckq122fiWlrJPyKPncv/lyjLOcbHSWvrSzX5TeMBIQJeS2aC1cgZ6 9FQw== 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:to:subject; bh=fAbeC/+at+eIHqk2VbIS2RIUy0pEGha8lFxfR5r4Bpc=; b=GIQ269kkSTTHDqvoa05ehYcpgTcOLEF+5xzOKPjV5LMtRHzyp1II/S2bvUkVtW1dmt PhbeaqEEwqXKfp8PkOQMQ/rLmutgX8nay2oacxAlz87soCnrkorQLaQO3XkzeRwh7nZg edz4RsQbUiE+TvX5SSzZ7ZXAvzLDE4m2v4+V1fD6wLK6BK/TNrR/JJl1Gbo4R4X3fCw7 1muL/YORy8Rmgc9om9oRQQ0fQzOgLnGRThW78ymijB0B3B3vErpYwEaXCu4yVOqmlVgy BhfbpB88QmpW5casHsG3GhnkLFOnHgVrCPwRIrYgnr7R0KxMVawuib1/ITn8h9HZLvO3 t2Ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si1843204plo.119.2019.07.03.03.23.30; Wed, 03 Jul 2019 03:23:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727045AbfGCKXK (ORCPT + 99 others); Wed, 3 Jul 2019 06:23:10 -0400 Received: from www62.your-server.de ([213.133.104.62]:57778 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfGCKXK (ORCPT ); Wed, 3 Jul 2019 06:23:10 -0400 Received: from [78.46.172.3] (helo=sslproxy06.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1hicPq-0001hf-Lz; Wed, 03 Jul 2019 12:23:06 +0200 Received: from [2a02:1205:5054:6d70:b45c:ec96:516a:e956] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1hicPq-000T17-ES; Wed, 03 Jul 2019 12:23:06 +0200 Subject: Re: [PATCH] bpf, libbpf: Smatch: Fix potential NULL pointer dereference To: Leo Yan , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Carpenter References: <20190702102531.23512-1-leo.yan@linaro.org> From: Daniel Borkmann Message-ID: Date: Wed, 3 Jul 2019 12:23:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20190702102531.23512-1-leo.yan@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.3/25499/Wed Jul 3 10:03:10 2019) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/02/2019 12:25 PM, Leo Yan wrote: > Based on the following report from Smatch, fix the potential > NULL pointer dereference check. > > tools/lib/bpf/libbpf.c:3493 > bpf_prog_load_xattr() warn: variable dereferenced before check 'attr' > (see line 3483) > > 3479 int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, > 3480 struct bpf_object **pobj, int *prog_fd) > 3481 { > 3482 struct bpf_object_open_attr open_attr = { > 3483 .file = attr->file, > 3484 .prog_type = attr->prog_type, > ^^^^^^ > 3485 }; > > At the head of function, it directly access 'attr' without checking if > it's NULL pointer. This patch moves the values assignment after > validating 'attr' and 'attr->file'. > > Signed-off-by: Leo Yan > --- > tools/lib/bpf/libbpf.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 197b574406b3..809b633fa3d9 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -3479,10 +3479,7 @@ int bpf_prog_load(const char *file, enum bpf_prog_type type, > int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, > struct bpf_object **pobj, int *prog_fd) > { > - struct bpf_object_open_attr open_attr = { > - .file = attr->file, > - .prog_type = attr->prog_type, > - }; Applied, thanks! Fyi, I retained the zeroing of open_attr as otherwise if we ever extend struct bpf_object_open_attr in future, we'll easily miss this and pass in garbage to bpf_object__open_xattr().