All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Tyrel Datwyler <tyreld@linux.ibm.com>
Cc: 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>,
	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
Date: Mon, 18 Oct 2021 16:26:12 -0500	[thread overview]
Message-ID: <20211018212612.GA1237121@embeddedor> (raw)
In-Reply-To: <97c42e43-15b9-5db6-d460-dbb16f31954d@linux.ibm.com>

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

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

WARNING: multiple messages have this Message-ID (diff)
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Tyrel Datwyler <tyreld@linux.ibm.com>
Cc: Haren Myneni <haren@linux.ibm.com>,
	linux-kernel@vger.kernel.org, Nicholas Piggin <npiggin@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	linux-hardening@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH][next] powerpc/vas: Fix potential NULL pointer dereference
Date: Mon, 18 Oct 2021 16:26:12 -0500	[thread overview]
Message-ID: <20211018212612.GA1237121@embeddedor> (raw)
In-Reply-To: <97c42e43-15b9-5db6-d460-dbb16f31954d@linux.ibm.com>

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

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

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

Thread overview: 16+ 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-15  5:03 ` Gustavo A. R. Silva
2021-10-18 21:09 ` Tyrel Datwyler
2021-10-18 21:09   ` Tyrel Datwyler
2021-10-18 21:26   ` Gustavo A. R. Silva [this message]
2021-10-18 21:26     ` Gustavo A. R. Silva
2021-10-26 18:42   ` Gustavo A. R. Silva
2021-10-26 18:42     ` Gustavo A. R. Silva
2021-10-26 22:30     ` Michael Ellerman
2021-10-26 22:30       ` Michael Ellerman
2021-10-26 22:40       ` Gustavo A. R. Silva
2021-10-26 22:40         ` Gustavo A. R. Silva
2021-10-27 11:21         ` Michael Ellerman
2021-10-27 11:21           ` Michael Ellerman
2021-11-02 10:11 ` 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=20211018212612.GA1237121@embeddedor \
    --to=gustavoars@kernel.org \
    --cc=benh@kernel.crashing.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 \
    --cc=tyreld@linux.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.