Skip to contentSkip to conversation

powerpc/vas: Fix potential NULL pointer dereference

PATCH Applied Gustavo A. R. Silva 4 participants 8 messages Oct 15, 2021 – Nov 2, 2021 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/vas: Fix potential NULL pointer dereference

(!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")
---
 arch/powerpc/platforms/book3s/vas-api.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/book3s/vas-api.c +2 -2
index 30172e52e16b..4d82c92ddd52 100644
@@ -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;
 	}
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Gustavo A. R. Silva

(!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.

Quoted 8 lines

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

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.

Quoted 27 lines
---
 arch/powerpc/platforms/book3s/vas-api.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/book3s/vas-api.c +2 -2
index 30172e52e16b..4d82c92ddd52 100644
@@ -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;
 	}
#2 lore raw
Quoted 14 lines · Tyrel Datwyler
Quoted 5 lines · Gustavo A. R. Silva

(!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.

Quoted 8 lines

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")
Quoted 6 lines

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.

Thanks, Tyrel.
--
Gustavo

Quoted 29 lines
Quoted 28 lines
---
 arch/powerpc/platforms/book3s/vas-api.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/book3s/vas-api.c +2 -2
index 30172e52e16b..4d82c92ddd52 100644
@@ -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;
 	}
#3 lore raw
In reply to Tyrel Datwyler
Quoted 14 lines · Tyrel Datwyler
Quoted 5 lines · Gustavo A. R. Silva

(!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.

Quoted 8 lines

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")
Quoted 6 lines

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.

I think I'll take this in my tree.

Thanks, Tyrel.
--
Gustavo

#4 lore raw
Quoted 15 lines · Gustavo A. R. Silva
Quoted 14 lines · Tyrel Datwyler
Quoted 13 lines · Gustavo A. R. Silva

(!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")
Quoted 8 lines
Quoted 6 lines

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.

I think I'll take this in my tree.

I've already put it in powerpc/next:

https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=61cb9ac66b30374c7fd8a8b2a3c4f8f432c72e36

If you need to pick it up as well for some reason that's fine.

cheers

#5 lore raw

On Wed, Oct 27, 2021 at 09:30:53AM +1100, Michael Ellerman wrote:
[..]

Quoted 5 lines
Quoted 1 line

I think I'll take this in my tree.

I've already put it in powerpc/next:

https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=61cb9ac66b30374c7fd8a8b2a3c4f8f432c72e36

Oh, great. :)

Quoted 1 line

If you need to pick it up as well for some reason that's fine.

I just didn't want it to get lost somehow. I'll drop it from tree now.

Thanks
--
Gustavo

#6 lore raw
Quoted 6 lines · Gustavo A. R. Silva

On Wed, Oct 27, 2021 at 09:30:53AM +1100, Michael Ellerman wrote:
[..]

Quoted 4 lines
Quoted 1 line

I think I'll take this in my tree.

I've already put it in powerpc/next:

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=61cb9ac66b30374c7fd8a8b2a3c4f8f432c72e36

Oh, great. :)

Quoted 1 line

If you need to pick it up as well for some reason that's fine.

I just didn't want it to get lost somehow. I'll drop it from tree now.

No worries, sorry I've been so slow lately.

cheers