dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: simpledrm: fix a potential NULL dereference
@ 2021-05-15  9:53 Dan Carpenter
  2021-05-15 12:08 ` Thomas Zimmermann
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-05-15  9:53 UTC (permalink / raw)
  To: David Airlie; +Cc: dri-devel, kernel-janitors, Thomas Zimmermann, Maxime Ripard

The drm_format_info() function returns NULL if the format is
unsupported, but the simplefb_get_validated_format() is expected to
return error pointers.  If we propagate teh NULL return then it will
lead to a NULL dereference in the callers.  Swap the NULL and trade it
in for an ERR_PTR(-EINVAL).

Fixes: 11e8f5fd223b ("drm: Add simpledrm driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/gpu/drm/tiny/simpledrm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c
index f72ca3a1c2d4..4f605c5fe856 100644
--- a/drivers/gpu/drm/tiny/simpledrm.c
+++ b/drivers/gpu/drm/tiny/simpledrm.c
@@ -72,6 +72,7 @@ simplefb_get_validated_format(struct drm_device *dev, const char *format_name)
 	static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
 	const struct simplefb_format *fmt = formats;
 	const struct simplefb_format *end = fmt + ARRAY_SIZE(formats);
+	const struct drm_format_info *info;
 
 	if (!format_name) {
 		drm_err(dev, "simplefb: missing framebuffer format\n");
@@ -79,8 +80,12 @@ simplefb_get_validated_format(struct drm_device *dev, const char *format_name)
 	}
 
 	while (fmt < end) {
-		if (!strcmp(format_name, fmt->name))
-			return drm_format_info(fmt->fourcc);
+		if (!strcmp(format_name, fmt->name)) {
+			info = drm_format_info(fmt->fourcc);
+			if (!info)
+				return ERR_PTR(-EINVAL);
+			return info;
+		}
 		++fmt;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm: simpledrm: fix a potential NULL dereference
  2021-05-15  9:53 [PATCH] drm: simpledrm: fix a potential NULL dereference Dan Carpenter
@ 2021-05-15 12:08 ` Thomas Zimmermann
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Zimmermann @ 2021-05-15 12:08 UTC (permalink / raw)
  To: Dan Carpenter, David Airlie; +Cc: dri-devel, kernel-janitors, Maxime Ripard


[-- Attachment #1.1: Type: text/plain, Size: 1941 bytes --]



Am 15.05.21 um 11:53 schrieb Dan Carpenter:
> The drm_format_info() function returns NULL if the format is
> unsupported, but the simplefb_get_validated_format() is expected to
> return error pointers.  If we propagate teh NULL return then it will
> lead to a NULL dereference in the callers.  Swap the NULL and trade it
> in for an ERR_PTR(-EINVAL).

Thank you. I've added the patch to drm-misc-next.

Best regards
Thomas

> 
> Fixes: 11e8f5fd223b ("drm: Add simpledrm driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>   drivers/gpu/drm/tiny/simpledrm.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c
> index f72ca3a1c2d4..4f605c5fe856 100644
> --- a/drivers/gpu/drm/tiny/simpledrm.c
> +++ b/drivers/gpu/drm/tiny/simpledrm.c
> @@ -72,6 +72,7 @@ simplefb_get_validated_format(struct drm_device *dev, 
const char *format_name)
>   	static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
>   	const struct simplefb_format *fmt = formats;
>   	const struct simplefb_format *end = fmt + ARRAY_SIZE(formats);
> +	const struct drm_format_info *info;
>   
>   	if (!format_name) {
>   		drm_err(dev, "simplefb: missing framebuffer format\n");
> @@ -79,8 +80,12 @@ simplefb_get_validated_format(struct drm_device *dev, const char *format_name)
>   	}
>   
>   	while (fmt < end) {
> -		if (!strcmp(format_name, fmt->name))
> -			return drm_format_info(fmt->fourcc);
> +		if (!strcmp(format_name, fmt->name)) {
> +			info = drm_format_info(fmt->fourcc);
> +			if (!info)
> +				return ERR_PTR(-EINVAL);
> +			return info;
> +		}
>   		++fmt;
>   	}
>   
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-15 12:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-15  9:53 [PATCH] drm: simpledrm: fix a potential NULL dereference Dan Carpenter
2021-05-15 12:08 ` Thomas Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).