linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Tyrel Datwyler <tyreld@linux.ibm.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Nicholas Piggin <npiggin@gmail.com>,
	Haren Myneni <haren@linux.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org, linux-hardening@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] powerpc/vas: Fix potential NULL pointer dereference
Date: Mon, 18 Oct 2021 14:09:31 -0700	[thread overview]
Message-ID: <97c42e43-15b9-5db6-d460-dbb16f31954d@linux.ibm.com> (raw)
In-Reply-To: <20211015050345.GA1161918@embeddedor>

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 <gustavoars@kernel.org>
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 <tyreld@linux.ibm.com>

> ---
>  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;
>  	}
> 


  reply	other threads:[~2021-10-18 21:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15  5:03 [PATCH][next] powerpc/vas: Fix potential NULL pointer dereference Gustavo A. R. Silva
2021-10-18 21:09 ` Tyrel Datwyler [this message]
2021-10-18 21:26   ` Gustavo A. R. Silva
2021-10-26 18:42   ` Gustavo A. R. Silva
2021-10-26 22:30     ` Michael Ellerman
2021-10-26 22:40       ` Gustavo A. R. Silva
2021-10-27 11:21         ` Michael Ellerman
2021-11-02 10:11 ` Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=97c42e43-15b9-5db6-d460-dbb16f31954d@linux.ibm.com \
    --to=tyreld@linux.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=gustavoars@kernel.org \
    --cc=haren@linux.ibm.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).