Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp792354ybi; Wed, 3 Jul 2019 04:47:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCQIwTXmMRJ6rgqQJuBMtry1f8jILf/W52J5ESudNrCQiJ7wTm9KyoPASf5M1M2zTu7QVh X-Received: by 2002:a63:f14:: with SMTP id e20mr36874187pgl.227.1562154439288; Wed, 03 Jul 2019 04:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562154439; cv=none; d=google.com; s=arc-20160816; b=ajNxufZT5br73AdTXSphFX3uRuguU4zbpruUJrwsp6GIvfyJb2ukKZaRMCE0qyirax jEZA8fNAq7RfrI+pZrVO2b2HAEtHi8RXvQrD+I6i6vSZd+44UEOzg1QXxZ+G6DNkPMIx 5utC+N5hCP56XQOSQxSlGW2W+dkMjTXc2MRhrNdrnP8XurtkEqcMh6J26V1R7D2XlBWg BJ/b88VmwoA8CR04hk1TUgbx7B6abC7pyepKdb78mWOultD6Cp6xftxt4vpxoKKQj6Iy lgIxjiDr1YAm0lIY/O/t4RRX3AuZjlByXHHFpU4+6whcZABdc8CHR3+PTp/JA3YoG99T MjZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mYCFppVyTLYn4jIWsRodglihiRKb1A76Dy+J8v19wzc=; b=tqTPiLLKZ1AMJlVbkgXpvB4F4fmAmXaizBBfUWz2n6bcZETYolUkMSgM8+kqGuCg9m QQ6koGTLJDg02yhcEsQwQQuGVle7PE2C+4zMivg6zR+YYYsNweFk34t7KF260yYSSZa/ WPwvstF9kZK4lMhadVMxkOzziLYHR1ysQQK8di0Pp46AGZS4/+DaVs3RerGm1HCJyJ4v 1Dx6FjmGKohlmXoDuQ9j2+AsaGpdTIZ9QSzEfrVAu1rgyEO6GgTqGUN4R08DEFT0au2D 7XrjN4GtRswlNc70JVEqhqD9wtcsbY7C177lxY+f3++w+M/Dfo0ze6NHEKMb3xQVCCY/ wNtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="D/9AaR+4"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si2047171pgv.195.2019.07.03.04.47.04; Wed, 03 Jul 2019 04:47:19 -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; dkim=pass header.i=@linaro.org header.s=google header.b="D/9AaR+4"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727110AbfGCLqd (ORCPT + 99 others); Wed, 3 Jul 2019 07:46:33 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:39691 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbfGCLqd (ORCPT ); Wed, 3 Jul 2019 07:46:33 -0400 Received: by mail-oi1-f195.google.com with SMTP id m202so1797891oig.6 for ; Wed, 03 Jul 2019 04:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mYCFppVyTLYn4jIWsRodglihiRKb1A76Dy+J8v19wzc=; b=D/9AaR+4ugUBBoe5/1T1+ZEwBrg3e3P4WhtXCOVCc7lRsXoCa76A7XhNR0j7h1SCJU ZhQ8En4MthdgoIQtVTcxsKV/bApkPtLlwcJ7GYSPzh9P2IRq9NzjA7PEu9sC7TNSCddQ FVvPmsxBtpYPwOsdA74BIXEpzq0OmWT1vx6C7YBcT8fF7hzaXA0Evginy/jJI1uJ9zbC zL14fynQYfCMydKMRLXIb73eCcvdkGE1i8pa7xeIfaAn1Do9Z6Lx7tGQms0O637oz/Ix yU+KnN7NhgWUn+dUA/5/VSg5HNp4LXLUkLG4jEQupWEZuDvgWX9pjdSSX8PdvbNW8/Hq xwqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mYCFppVyTLYn4jIWsRodglihiRKb1A76Dy+J8v19wzc=; b=ml49HlF5sCdwUBuXHEpAUZgoLylyB5xfH/Cp1NmfZmeRWRcQ/PLKJlfDdsj5/ubJfW soo7gjBSjdXq88SjpOT+wMQf4jdL9IHF1MxwVw5SbRZXdJ9QlU5KdnWwIKnqHP/SD1VR ngrverAAM2WYNbqp0/Ocv2EkTGXViO0t8lWw4YuKXTTfQrNZgGhV3kqfLyi+w60+SUEy tuzwS43gXWgaEdi+QawGJWwLXM3MlZt0neeJcsBLzH12gp+H6Kw0+ZxTBU1/CCSJoNVE GH5PYTPcYThn28EqykY4+NvHfRyivUEXZACbK8BrFyEOvEw/+Bg3IVjw0FuXAh6UF6u/ PzSQ== X-Gm-Message-State: APjAAAVanB+VYHblnZoyT3RBHBxaVLPTFPdpbmL1E9VbSD6t9RfQl7Ek yilwe1MB8CtVncWb1iJ3xz7PaBnWQy/Q0w== X-Received: by 2002:aca:c715:: with SMTP id x21mr3307037oif.142.1562154392368; Wed, 03 Jul 2019 04:46:32 -0700 (PDT) Received: from leoy-ThinkPad-X240s (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id 198sm692180oie.13.2019.07.03.04.46.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Jul 2019 04:46:31 -0700 (PDT) Date: Wed, 3 Jul 2019 19:46:25 +0800 From: Leo Yan To: Daniel Borkmann Cc: Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Carpenter Subject: Re: [PATCH] bpf, libbpf: Smatch: Fix potential NULL pointer dereference Message-ID: <20190703114625.GG6852@leoy-ThinkPad-X240s> References: <20190702102531.23512-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 03, 2019 at 12:23:05PM +0200, Daniel Borkmann wrote: > 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(). Thanks for the info, Daniel. I checked the link [1] and thanks for the improvement when applied this patch. Thanks, Leo Yan [1] https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=33bae185f74d49a0d7b1bfaafb8e959efce0f243