2021-01-15 13:12:47

by Colin King

[permalink] [raw]
Subject: [PATCH][next] drm/vkms: Fix missing kmalloc allocation failure check

From: Colin Ian King <[email protected]>

Currently the kmalloc allocation for config is not being null
checked and could potentially lead to a null pointer dereference.
Fix this by adding the missing null check.

Addresses-Coverity: ("Dereference null return value")
Fixes: 2df7af93fdad ("drm/vkms: Add vkms_config type")
Signed-off-by: Colin Ian King <[email protected]>
---
drivers/gpu/drm/vkms/vkms_drv.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index 708f7f54001d..2173b82606f6 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -188,7 +188,11 @@ static int vkms_create(struct vkms_config *config)

static int __init vkms_init(void)
{
- struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
+ struct vkms_config *config;
+
+ config = kmalloc(sizeof(*config), GFP_KERNEL);
+ if (!config)
+ return -ENOMEM;

default_config = config;

--
2.29.2


2021-01-15 14:13:10

by Sumera Priyadarsini

[permalink] [raw]
Subject: Re: [PATCH][next] drm/vkms: Fix missing kmalloc allocation failure check

On Fri, Jan 15, 2021 at 6:39 PM Colin King <[email protected]> wrote:
>
> From: Colin Ian King <[email protected]>
>
> Currently the kmalloc allocation for config is not being null
> checked and could potentially lead to a null pointer dereference.
> Fix this by adding the missing null check.
>
> Addresses-Coverity: ("Dereference null return value")
> Fixes: 2df7af93fdad ("drm/vkms: Add vkms_config type")
> Signed-off-by: Colin Ian King <[email protected]>

Good catch, thank you!

Reviewed-by: Sumera Priyadarsini <[email protected]>
> ---
> drivers/gpu/drm/vkms/vkms_drv.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
> index 708f7f54001d..2173b82606f6 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.c
> +++ b/drivers/gpu/drm/vkms/vkms_drv.c
> @@ -188,7 +188,11 @@ static int vkms_create(struct vkms_config *config)
>
> static int __init vkms_init(void)
> {
> - struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
> + struct vkms_config *config;
> +
> + config = kmalloc(sizeof(*config), GFP_KERNEL);
> + if (!config)
> + return -ENOMEM;
>
> default_config = config;
>
> --
> 2.29.2
>
regards,
Sumera

2021-01-15 21:01:42

by Melissa Wen

[permalink] [raw]
Subject: Re: [PATCH][next] drm/vkms: Fix missing kmalloc allocation failure check

On 01/15, Sumera Priyadarsini wrote:
> On Fri, Jan 15, 2021 at 6:39 PM Colin King <[email protected]> wrote:
> >
> > From: Colin Ian King <[email protected]>
> >
> > Currently the kmalloc allocation for config is not being null
> > checked and could potentially lead to a null pointer dereference.
> > Fix this by adding the missing null check.
> >
> > Addresses-Coverity: ("Dereference null return value")
> > Fixes: 2df7af93fdad ("drm/vkms: Add vkms_config type")
> > Signed-off-by: Colin Ian King <[email protected]>
>
> Good catch, thank you!
>
> Reviewed-by: Sumera Priyadarsini <[email protected]>

Applied to drm-misc-next.

Thanks,
Melissa Wen
> > ---
> > drivers/gpu/drm/vkms/vkms_drv.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
> > index 708f7f54001d..2173b82606f6 100644
> > --- a/drivers/gpu/drm/vkms/vkms_drv.c
> > +++ b/drivers/gpu/drm/vkms/vkms_drv.c
> > @@ -188,7 +188,11 @@ static int vkms_create(struct vkms_config *config)
> >
> > static int __init vkms_init(void)
> > {
> > - struct vkms_config *config = kmalloc(sizeof(*config), GFP_KERNEL);
> > + struct vkms_config *config;
> > +
> > + config = kmalloc(sizeof(*config), GFP_KERNEL);
> > + if (!config)
> > + return -ENOMEM;
> >
> > default_config = config;
> >
> > --
> > 2.29.2
> >
> regards,
> Sumera