Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3394411pxb; Mon, 18 Oct 2021 14:23:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGjX9MmVj/sbDgXxEUch7qVve2b+pqHgKkNfYmvINJKlmzT2vXmzCdm7O9ghugAeypl3uy X-Received: by 2002:aa7:9258:0:b0:44d:4f03:6a7a with SMTP id 24-20020aa79258000000b0044d4f036a7amr31372507pfp.33.1634592236583; Mon, 18 Oct 2021 14:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634592236; cv=none; d=google.com; s=arc-20160816; b=HmdJ36+ilDixCKlzitwk7KelNbl3tFvpFv6bg8kLFBUnO95xfhRkmxD6nV98Y5+CHA LQErgcUUSr4fhFVxLsUOzEqLJzqo+KStJ7TLxzoPOyGhcoZCQoljnUseFhwgxen5nL4K Px10vBme5rUALn1efuSRtU/TAXUkfuIpj+3k+QNsJZELCLQT0+wsbkfca0ENkJzkYG5u uHQP+zKzHiH9ZlBZSjrTLDMPkn72a+EP+U3GTmkdvBeDlcI1xdESac9H25D7wAtdnET2 gmt+72VWD3/Y0a1rC5f0re1OGL7BaOB/4sA/BpW0JGMQP/L8GqlTA9AUoudSum3JbzSj ciow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=X7fF2Y9f6mbUCojNLVu5QyXTrZ5eO/dH2YiMSSOozSE=; b=VrBvril0YbGsdFUCLgq9wH3lFYWUXNmF9FvEfDQdCNSoVjMqQv+70KUVoNvaH2Iaed YfEEQbW6wQrm74dWMoeW16NtR1tCc9tV7GrgACS4MdZv8wFevhy6DjjQpoCmYGVZL4Z/ L3lDp1KE5cQCWqiN+J1UOnpiMqHk76V+0t58t7eMUIO4aROepQ/M6XnAPjJml0VTjqxF u98NZMgP0dTuJWzeAF4LI2zmn/op2vxCYu8I0lFPQRtegPZePYfJ+GAUHXXkcyWNpSbP Sg8Bp5dAYmMM7I9j1bipMUI//vkvRVab43NnO2hTCTC3VLEdf5Mg2zNajWIzRr74qwYJ Fs2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jkM+1QBL; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f2si1669278plr.323.2021.10.18.14.23.44; Mon, 18 Oct 2021 14:23:56 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jkM+1QBL; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232070AbhJRVXu (ORCPT + 99 others); Mon, 18 Oct 2021 17:23:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:38906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbhJRVXt (ORCPT ); Mon, 18 Oct 2021 17:23:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 08D676113D; Mon, 18 Oct 2021 21:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634592097; bh=r+U+HRVQuA0YbQnhsffBIKTPjNzgnGyVqS2dVQNn2D0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jkM+1QBLNmmr2PR2zw2SC8iGjREGbYOVerrkSYv8jxLrqA9IIHJg+L/VcMTBqG8hh huAmTTF47wai2Ksr+eiVkQgaVJXGZASCP0F/JIkO4EM9DVuXLchxXbF41zo1naYbNx JXYUgmJ4QuUfYnGD1HBMdVuKulpF4MuJYhKj+SnFw6F5O7dycf75FOu5OcnxlFnQa6 X6UGocjlHew9R39KPk3JbWDddBMFKJjbBmWHhC3MtkXTIaOFGvkPtDXgZtmY5vsV3D tdZyp1/wtkTwabinzQahybxs1JiXRYZCtYO/3jbIGJPAk5B/pbC/dw+sGQSlhMVzB0 rj/96f25tNgvA== Date: Mon, 18 Oct 2021 16:26:12 -0500 From: "Gustavo A. R. Silva" To: Tyrel Datwyler Cc: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Nicholas Piggin , Haren Myneni , linux-hardening@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] powerpc/vas: Fix potential NULL pointer dereference Message-ID: <20211018212612.GA1237121@embeddedor> References: <20211015050345.GA1161918@embeddedor> <97c42e43-15b9-5db6-d460-dbb16f31954d@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <97c42e43-15b9-5db6-d460-dbb16f31954d@linux.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 18, 2021 at 02:09:31PM -0700, Tyrel Datwyler wrote: > On 10/14/21 10:03 PM, Gustavo A. R. Silva wrote: > > (!ptr && !ptr->foo) strikes again. :) > > > > The expression (!ptr && !ptr->foo) is bogus and in case ptr is NULL, > > it leads to a NULL pointer dereference: ptr->foo. > > > > Fix this by converting && to || > > > > This issue was detected with the help of Coccinelle, and audited and > > fixed manually. > > > > Fixes: 1a0d0d5ed5e3 ("powerpc/vas: Add platform specific user window operations") > > Cc: stable@vger.kernel.org > > Signed-off-by: Gustavo A. R. Silva > Looking at the usage pattern it is obvious that if we determine !ptr attempting > to also confirm !ptr->ops is going to blow up. > > LGTM. > > Reviewed-by: Tyrel Datwyler Thanks, Tyrel. -- Gustavo > > > --- > > arch/powerpc/platforms/book3s/vas-api.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/powerpc/platforms/book3s/vas-api.c b/arch/powerpc/platforms/book3s/vas-api.c > > index 30172e52e16b..4d82c92ddd52 100644 > > --- a/arch/powerpc/platforms/book3s/vas-api.c > > +++ b/arch/powerpc/platforms/book3s/vas-api.c > > @@ -303,7 +303,7 @@ static int coproc_ioc_tx_win_open(struct file *fp, unsigned long arg) > > return -EINVAL; > > } > > > > - if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->open_win) { > > + if (!cp_inst->coproc->vops || !cp_inst->coproc->vops->open_win) { > > pr_err("VAS API is not registered\n"); > > return -EACCES; > > } > > @@ -373,7 +373,7 @@ static int coproc_mmap(struct file *fp, struct vm_area_struct *vma) > > return -EINVAL; > > } > > > > - if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->paste_addr) { > > + if (!cp_inst->coproc->vops || !cp_inst->coproc->vops->paste_addr) { > > pr_err("%s(): VAS API is not registered\n", __func__); > > return -EACCES; > > } > > >