stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] misc: genwqe: check for error from get_user_pages_fast()
@ 2014-11-06 16:23 Ian Abbott
  2014-12-02 12:59 ` Frank Haverkamp
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Abbott @ 2014-11-06 16:23 UTC (permalink / raw)
  To: Frank Haverkamp, Arnd Bergmann, Greg Kroah-Hartman
  Cc: linux-kernel, Ian Abbott, stable

`genwqe_user_vmap()` calls `get_user_pages_fast()` and if the return
value is less than the number of pages requested, it frees the pages and
returns an error (`-EFAULT`).  However, it fails to consider a negative
error return value from `get_user_pages_fast()`.  In that case, the test
`if (rc < m->nr_pages)` will be false (due to promotion of `rc` to a
large `unsigned int`) and the code will continue on to call
`genwqe_map_pages()` with an invalid list of page pointers.  Fix it by
bailing out if `get_user_pages_fast()` returns a negative error value.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: <stable@vger.kernel.org> # 3.14.x # 3.15.x # 3.16.x # 3.17.x
---
 drivers/misc/genwqe/card_utils.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
index 7cb3b7e..1ca94e6 100644
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -590,6 +590,8 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,
 				 m->nr_pages,
 				 1,		/* write by caller */
 				 m->page_list);	/* ptrs to pages */
+	if (rc < 0)
+		goto fail_get_user_pages;
 
 	/* assumption: get_user_pages can be killed by signals. */
 	if (rc < m->nr_pages) {
-- 
2.1.1


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

* Re: [PATCH] misc: genwqe: check for error from get_user_pages_fast()
  2014-11-06 16:23 [PATCH] misc: genwqe: check for error from get_user_pages_fast() Ian Abbott
@ 2014-12-02 12:59 ` Frank Haverkamp
  2014-12-02 13:29   ` Ian Abbott
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Haverkamp @ 2014-12-02 12:59 UTC (permalink / raw)
  To: Ian Abbott
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, stable,
	Thadeu Lima De Souza Cascardo

Hi Ian,

thanks for reviewing our code and sorry for not answering immediately.

Am Donnerstag, den 06.11.2014, 16:23 +0000 schrieb Ian Abbott:
> `genwqe_user_vmap()` calls `get_user_pages_fast()` and if the return
> value is less than the number of pages requested, it frees the pages and
> returns an error (`-EFAULT`).  However, it fails to consider a negative
> error return value from `get_user_pages_fast()`.  In that case, the test
> `if (rc < m->nr_pages)` will be false (due to promotion of `rc` to a
> large `unsigned int`) and the code will continue on to call
> `genwqe_map_pages()` with an invalid list of page pointers.  Fix it by
> bailing out if `get_user_pages_fast()` returns a negative error value.

True. Did you find this by manual inspection of the code or did you use
tools to figure it out?

> 
> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
> Cc: <stable@vger.kernel.org> # 3.14.x # 3.15.x # 3.16.x # 3.17.x
> ---
>  drivers/misc/genwqe/card_utils.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
> index 7cb3b7e..1ca94e6 100644
> --- a/drivers/misc/genwqe/card_utils.c
> +++ b/drivers/misc/genwqe/card_utils.c
> @@ -590,6 +590,8 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,
>  				 m->nr_pages,
>  				 1,		/* write by caller */
>  				 m->page_list);	/* ptrs to pages */
> +	if (rc < 0)
> +		goto fail_get_user_pages;
> 
>  	/* assumption: get_user_pages can be killed by signals. */
>  	if (rc < m->nr_pages) {

Regards

Frank

Acked-by: Frank Haverkamp <haver@linux.vnet.ibm.com>



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

* Re: [PATCH] misc: genwqe: check for error from get_user_pages_fast()
  2014-12-02 12:59 ` Frank Haverkamp
@ 2014-12-02 13:29   ` Ian Abbott
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2014-12-02 13:29 UTC (permalink / raw)
  To: haver
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, stable,
	Thadeu Lima De Souza Cascardo

On 02/12/14 12:59, Frank Haverkamp wrote:
> Hi Ian,
>
> thanks for reviewing our code and sorry for not answering immediately.
>
> Am Donnerstag, den 06.11.2014, 16:23 +0000 schrieb Ian Abbott:
>> `genwqe_user_vmap()` calls `get_user_pages_fast()` and if the return
>> value is less than the number of pages requested, it frees the pages and
>> returns an error (`-EFAULT`).  However, it fails to consider a negative
>> error return value from `get_user_pages_fast()`.  In that case, the test
>> `if (rc < m->nr_pages)` will be false (due to promotion of `rc` to a
>> large `unsigned int`) and the code will continue on to call
>> `genwqe_map_pages()` with an invalid list of page pointers.  Fix it by
>> bailing out if `get_user_pages_fast()` returns a negative error value.
>
> True. Did you find this by manual inspection of the code or did you use
> tools to figure it out?

I just spotted it while grepping for examples of drivers that used 
get_user_pages() or get_user_pages_fast() as I want to use it in a 
driver for some custom hardware.

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

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

end of thread, other threads:[~2014-12-02 13:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-06 16:23 [PATCH] misc: genwqe: check for error from get_user_pages_fast() Ian Abbott
2014-12-02 12:59 ` Frank Haverkamp
2014-12-02 13:29   ` Ian Abbott

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).