2020-05-01 15:55:41

by Oscar Carter

[permalink] [raw]
Subject: [PATCH] staging: gasket: Check the return value of gasket_get_bar_index()

Check the return value of gasket_get_bar_index function as it can return
a negative one (-EINVAL). If this happens, a negative index is used in
the "gasket_dev->bar_data" array.

Addresses-Coverity-ID: 1438542 ("Negative array index read")
Fixes: 9a69f5087ccc2 ("drivers/staging: Gasket driver framework + Apex driver")
Signed-off-by: Oscar Carter <[email protected]>
---
drivers/staging/gasket/gasket_core.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c
index 8e0575fcb4c8..67325fbaf760 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -925,6 +925,10 @@ do_map_region(const struct gasket_dev *gasket_dev, struct vm_area_struct *vma,
gasket_get_bar_index(gasket_dev,
(vma->vm_pgoff << PAGE_SHIFT) +
driver_desc->legacy_mmap_address_offset);
+
+ if (bar_index < 0)
+ return DO_MAP_REGION_INVALID;
+
phys_base = gasket_dev->bar_data[bar_index].phys_base + phys_offset;
while (mapped_bytes < map_length) {
/*
--
2.20.1


2020-05-03 07:50:52

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] staging: gasket: Check the return value of gasket_get_bar_index()

On Sat, May 02, 2020 at 05:59:18PM -0400, Richard Yeh wrote:
> Hi, as a new maintainer, I thought I would try to handle this one.

Great, as a start:

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

> This patch looks good to me. This new check properly protects against using
> a negative return value from gasket_get_bar_index() to index into a
> pointer. The gasket_get_bar_index function is called in two other places
> (old lines 845 and 1044) and both other places check the bar_index return
> value for negative values and return error values.
>
> What is the next step in the process? How do I test the patch? Does Greg
> K-H take these patches directly, or is there something else I should do
> (looking at
> https://github.com/gregkh/presentation-linux-maintainer/blob/master/maintainer.pdf
> page
> 5: clone from
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git, ...)?

Just send a "Reviewed-by:" to the patch and I can take it from there.
Also, I strongly suggest going and talking to your co-maintainers for
exactly how to do this, normally at this point in the process you
already know this as it is usually an experienced developer doing the
maintaining.

thanks,

greg k-h

2020-05-04 17:52:27

by Richard Yeh

[permalink] [raw]
Subject: Re: [PATCH] staging: gasket: Check the return value of gasket_get_bar_index()

On Fri, May 01, 2020 at 05:51:18PM +0200, Oscar Carter wrote:
> Check the return value of gasket_get_bar_index function as it can return
> a negative one (-EINVAL). If this happens, a negative index is used in
> the "gasket_dev->bar_data" array.
>
> Addresses-Coverity-ID: 1438542 ("Negative array index read")
> Fixes: 9a69f5087ccc2 ("drivers/staging: Gasket driver framework + Apex driver")
> Signed-off-by: Oscar Carter <[email protected]>
> ---
> drivers/staging/gasket/gasket_core.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c
> index 8e0575fcb4c8..67325fbaf760 100644
> --- a/drivers/staging/gasket/gasket_core.c
> +++ b/drivers/staging/gasket/gasket_core.c
> @@ -925,6 +925,10 @@ do_map_region(const struct gasket_dev *gasket_dev, struct vm_area_struct *vma,
> gasket_get_bar_index(gasket_dev,
> (vma->vm_pgoff << PAGE_SHIFT) +
> driver_desc->legacy_mmap_address_offset);
> +
> + if (bar_index < 0)
> + return DO_MAP_REGION_INVALID;
> +
> phys_base = gasket_dev->bar_data[bar_index].phys_base + phys_offset;
> while (mapped_bytes < map_length) {
> /*
> --
> 2.20.1
>

Reviewed-by: Richard Yeh <[email protected]>