powerpc/vas: Fix potential NULL pointer dereference
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.
--- arch/powerpc/platforms/book3s/vas-api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/book3s/vas-api.c +2 -2
@@ -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
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")Signed-off-by Gustavo A. R. Silva <[email protected]>
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@@ -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 ; }
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")Signed-off-by Gustavo A. R. Silva <[email protected]>
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.
Reviewed-by Tyrel Datwyler <[email protected]>
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@@ -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 ; }
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")Signed-off-by Gustavo A. R. Silva <[email protected]>
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.
Reviewed-by Tyrel Datwyler <[email protected]>
I think I'll take this in my tree.
Thanks, Tyrel.
--
Gustavo
Michael Ellerman
reviewerQuoted 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")Signed-off-by Gustavo A. R. Silva <[email protected]>
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.
Reviewed-by Tyrel Datwyler <[email protected]>I think I'll take this in my tree.
I've already put it in powerpc/next:
If you need to pick it up as well for some reason that's fine.
cheers
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:
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
Michael Ellerman
reviewerQuoted 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
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
Michael Ellerman
AppliedQuoted 8 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 ||
[...]
Applied to powerpc/next.
[1/1] powerpc/vas: Fix potential NULL pointer dereference
https://git.kernel.org/powerpc/c/61cb9ac66b30374c7fd8a8b2a3c4f8f432c72e36
cheers