* [PATCH] tee: shm: Potential NULL dereference calling tee_shm_register()
@ 2018-01-06 9:22 Dan Carpenter
2018-01-09 13:35 ` Jens Wiklander
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2018-01-06 9:22 UTC (permalink / raw)
To: Jens Wiklander; +Cc: linux-kernel, kernel-janitors
get_user_pages_fast() can return zero in certain error paths. We should
handle that or else it means we accidentally return ERR_PTR(0) which is
NULL instead of an error pointer. The callers are not expecting that
and will crash with a NULL dereference.
Fixes: 033ddf12bcf5 ("tee: add register user memory")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index 04e1b8b37046..cdeb4156acda 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -283,7 +283,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
if (rc > 0)
shm->num_pages = rc;
if (rc != num_pages) {
- if (rc > 0)
+ if (rc >= 0)
rc = -ENOMEM;
ret = ERR_PTR(rc);
goto err;
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] tee: shm: Potential NULL dereference calling tee_shm_register()
2018-01-06 9:22 [PATCH] tee: shm: Potential NULL dereference calling tee_shm_register() Dan Carpenter
@ 2018-01-09 13:35 ` Jens Wiklander
0 siblings, 0 replies; 2+ messages in thread
From: Jens Wiklander @ 2018-01-09 13:35 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Linux Kernel Mailing List, kernel-janitors
On Sat, Jan 6, 2018 at 10:22 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> get_user_pages_fast() can return zero in certain error paths. We should
> handle that or else it means we accidentally return ERR_PTR(0) which is
> NULL instead of an error pointer. The callers are not expecting that
> and will crash with a NULL dereference.
>
> Fixes: 033ddf12bcf5 ("tee: add register user memory")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
> index 04e1b8b37046..cdeb4156acda 100644
> --- a/drivers/tee/tee_shm.c
> +++ b/drivers/tee/tee_shm.c
> @@ -283,7 +283,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
> if (rc > 0)
> shm->num_pages = rc;
> if (rc != num_pages) {
> - if (rc > 0)
> + if (rc >= 0)
> rc = -ENOMEM;
> ret = ERR_PTR(rc);
> goto err;
Looks good. Thanks.
/Jens
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-09 13:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-06 9:22 [PATCH] tee: shm: Potential NULL dereference calling tee_shm_register() Dan Carpenter
2018-01-09 13:35 ` Jens Wiklander
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®