# \[PATCH\] video: hgafb: correctly handle card detect failure during probe

- Subsystems: FRAMEBUFFER LAYER, THE REST
- Maintainers: Helge Deller, Linus Torvalds
- Status: LANDED (02625c965239 · 2021-05-21 13:04)
- Landed in mainline as 02625c965239 on 2021-05-21.
- List: linux-fbdev
- 4 messages, 3 authors
- Page: https://ratatoskr.run/linux-fbdev/2021/05/1378902/t

## \[PATCH\] video: hgafb: correctly handle card detect failure during probe

- From: Anirudh Rayabharam \<hidden\>
- Date: 2021-05-16 19:27:52 
- Message: https://ratatoskr.run/linux-fbdev/2021/05/1378902.md

```text
The return value of hga_card_detect() is not properly handled causing
the probe to succeed even though hga_card_detect() failed. Since probe
succeeds, hgafb_open() can be called which will end up operating on an
unmapped hga_vram. This results in an out-of-bounds access as reported
by kernel test robot [1].

To fix this, correctly detect failure of hga_card_detect() by checking
for a non-zero error code.

[1]: https://lore.kernel.org/lkml/20210516150019.GB25903@xsang-OptiPlex-9020/

Reported-by: kernel test robot <redacted>
Fixes: dc13cac4862c ("video: hgafb: fix potential NULL pointer dereference")
Cc: stable <redacted>
Signed-off-by: Anirudh Rayabharam <redacted>
---
 drivers/video/fbdev/hgafb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/hgafb.c b/drivers/video/fbdev/hgafb.c
index cc8e62ae93f6..bd3d07aa4f0e 100644
--- a/drivers/video/fbdev/hgafb.c
+++ b/drivers/video/fbdev/hgafb.c
@@ -558,7 +558,7 @@ static int hgafb_probe(struct platform_device *pdev)
 	int ret;
 
 	ret = hga_card_detect();
-	if (!ret)
+	if (ret)
 		return ret;
 
 	printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n",
-- 
2.26.2

```

## Re: \[PATCH\] video: hgafb: correctly handle card detect failure during probe

- From: Igor Torrente \<hidden\>
- Date: 2021-05-17 12:27:50 
- Message: https://ratatoskr.run/linux-fbdev/2021/05/1379570.md

```text
Hi,

On 5/16/21 4:27 PM, Anirudh Rayabharam wrote:
> The return value of hga_card_detect() is not properly handled causing
> the probe to succeed even though hga_card_detect() failed. Since probe
> succeeds, hgafb_open() can be called which will end up operating on an
> unmapped hga_vram. This results in an out-of-bounds access as reported
> by kernel test robot [1].
>
> To fix this, correctly detect failure of hga_card_detect() by checking
> for a non-zero error code.
>
> [1]: https://lore.kernel.org/lkml/20210516150019.GB25903@xsang-OptiPlex-9020/
>
> Reported-by: kernel test robot <redacted>
> Fixes: dc13cac4862c ("video: hgafb: fix potential NULL pointer dereference")
> Cc: stable <redacted>
> Signed-off-by: Anirudh Rayabharam <redacted>
> ---
>   drivers/video/fbdev/hgafb.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/hgafb.c b/drivers/video/fbdev/hgafb.c
> index cc8e62ae93f6..bd3d07aa4f0e 100644
> --- a/drivers/video/fbdev/hgafb.c
> +++ b/drivers/video/fbdev/hgafb.c
> @@ -558,7 +558,7 @@ static int hgafb_probe(struct platform_device *pdev)
>   	int ret;
>   
>   	ret = hga_card_detect();
> -	if (!ret)
> +	if (ret)
>   		return ret;
>   
>   	printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n",
>

In fact, this return isn't being properly handled. Thanks for fix it!

Reviewed-by: Igor Matheus Andrade Torrente <redacted>
```

## Re: \[PATCH\] video: hgafb: correctly handle card detect failure during probe

- From: Anirudh Rayabharam \<hidden\>
- Date: 2021-05-20 13:42:02 
- Message: https://ratatoskr.run/linux-fbdev/2021/05/1386152.md

```text
On Mon, May 17, 2021 at 12:57:14AM +0530, Anirudh Rayabharam wrote:
> The return value of hga_card_detect() is not properly handled causing
> the probe to succeed even though hga_card_detect() failed. Since probe
> succeeds, hgafb_open() can be called which will end up operating on an
> unmapped hga_vram. This results in an out-of-bounds access as reported
> by kernel test robot [1].
> 
> To fix this, correctly detect failure of hga_card_detect() by checking
> for a non-zero error code.
> 
> [1]: https://lore.kernel.org/lkml/20210516150019.GB25903@xsang-OptiPlex-9020/
> 
> Reported-by: kernel test robot <redacted>
> Fixes: dc13cac4862c ("video: hgafb: fix potential NULL pointer dereference")

Greg, this is one of the UMN fixes we did. So, do you want to take this
patch into your tree?

thanks!

	- Anirudh.

> Cc: stable <redacted>
> Signed-off-by: Anirudh Rayabharam <redacted>
> ---
>  drivers/video/fbdev/hgafb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/video/fbdev/hgafb.c b/drivers/video/fbdev/hgafb.c
> index cc8e62ae93f6..bd3d07aa4f0e 100644
> --- a/drivers/video/fbdev/hgafb.c
> +++ b/drivers/video/fbdev/hgafb.c
> @@ -558,7 +558,7 @@ static int hgafb_probe(struct platform_device *pdev)
>  	int ret;
>  
>  	ret = hga_card_detect();
> -	if (!ret)
> +	if (ret)
>  		return ret;
>  
>  	printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n",
> -- 
> 2.26.2
> 
```

## Re: \[PATCH\] video: hgafb: correctly handle card detect failure during probe

- From: Greg Kroah-Hartman \<gregkh@linuxfoundation.org\>
- Date: 2021-05-20 14:00:02 
- Message: https://ratatoskr.run/linux-fbdev/2021/05/1386187.md

```text
On Thu, May 20, 2021 at 07:10:39PM +0530, Anirudh Rayabharam wrote:
> On Mon, May 17, 2021 at 12:57:14AM +0530, Anirudh Rayabharam wrote:
> > The return value of hga_card_detect() is not properly handled causing
> > the probe to succeed even though hga_card_detect() failed. Since probe
> > succeeds, hgafb_open() can be called which will end up operating on an
> > unmapped hga_vram. This results in an out-of-bounds access as reported
> > by kernel test robot [1].
> > 
> > To fix this, correctly detect failure of hga_card_detect() by checking
> > for a non-zero error code.
> > 
> > [1]: https://lore.kernel.org/lkml/20210516150019.GB25903@xsang-OptiPlex-9020/
> > 
> > Reported-by: kernel test robot <redacted>
> > Fixes: dc13cac4862c ("video: hgafb: fix potential NULL pointer dereference")
> 
> Greg, this is one of the UMN fixes we did. So, do you want to take this
> patch into your tree?

Yes, will queue it up in a few days after Linus takes the current pull
request I sent him for this.

thanks,

greg k-h
```
