linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: cma: Fix potential null dereference on pointer cma
@ 2021-03-16 10:04 Colin King
  2021-03-16 18:09 ` Minchan Kim
  2021-03-17  7:13 ` John Hubbard
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2021-03-16 10:04 UTC (permalink / raw)
  To: Andrew Morton, Minchan Kim, John Hubbard, Stephen Rothwell,
	Greg Kroah-Hartman, linux-mm
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

At the start of the function there is a null pointer check on cma
and then branch to error handling label 'out'.  The subsequent call
to cma_sysfs_fail_pages_count dereferences cma, hence there is a
potential null pointer deference issue.  Fix this by only calling
cma_sysfs_fail_pages_count if cma is not null.

Addresses-Coverity: ("Dereference after null check")
Fixes: dc4764f7e9ac ("mm: cma: support sysfs")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 mm/cma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/cma.c b/mm/cma.c
index 6d4dbafdb318..90e27458ddb7 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -512,7 +512,8 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
 		cma_sysfs_alloc_pages_count(cma, count);
 	} else {
 		count_vm_event(CMA_ALLOC_FAIL);
-		cma_sysfs_fail_pages_count(cma, count);
+		if (cma)
+			cma_sysfs_fail_pages_count(cma, count);
 	}
 
 	return page;
-- 
2.30.2



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

* Re: [PATCH] mm: cma: Fix potential null dereference on pointer cma
  2021-03-16 10:04 [PATCH] mm: cma: Fix potential null dereference on pointer cma Colin King
@ 2021-03-16 18:09 ` Minchan Kim
  2021-03-17  7:13 ` John Hubbard
  1 sibling, 0 replies; 3+ messages in thread
From: Minchan Kim @ 2021-03-16 18:09 UTC (permalink / raw)
  To: Colin King
  Cc: Andrew Morton, John Hubbard, Stephen Rothwell,
	Greg Kroah-Hartman, linux-mm, kernel-janitors, linux-kernel

On Tue, Mar 16, 2021 at 10:04:33AM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> At the start of the function there is a null pointer check on cma
> and then branch to error handling label 'out'.  The subsequent call
> to cma_sysfs_fail_pages_count dereferences cma, hence there is a
> potential null pointer deference issue.  Fix this by only calling
> cma_sysfs_fail_pages_count if cma is not null.
> 
> Addresses-Coverity: ("Dereference after null check")
> Fixes: dc4764f7e9ac ("mm: cma: support sysfs")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Minchan Kim <minchan@kernel.org>



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

* Re: [PATCH] mm: cma: Fix potential null dereference on pointer cma
  2021-03-16 10:04 [PATCH] mm: cma: Fix potential null dereference on pointer cma Colin King
  2021-03-16 18:09 ` Minchan Kim
@ 2021-03-17  7:13 ` John Hubbard
  1 sibling, 0 replies; 3+ messages in thread
From: John Hubbard @ 2021-03-17  7:13 UTC (permalink / raw)
  To: Colin King, Andrew Morton, Minchan Kim, Stephen Rothwell,
	Greg Kroah-Hartman, linux-mm
  Cc: kernel-janitors, linux-kernel

On 3/16/21 3:04 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> At the start of the function there is a null pointer check on cma
> and then branch to error handling label 'out'.  The subsequent call
> to cma_sysfs_fail_pages_count dereferences cma, hence there is a
> potential null pointer deference issue.  Fix this by only calling

As far as I can tell, it's not possible to actually cause that null
failure with the existing kernel code paths.  *Might* be worth mentioning
that here (unless I'm wrong), but either way, looks good, so:

Reviewed-by: John Hubbard <jhubbard@nvidia.com>

thanks,
-- 
John Hubbard
NVIDIA

> cma_sysfs_fail_pages_count if cma is not null.
> 
> Addresses-Coverity: ("Dereference after null check")
> Fixes: dc4764f7e9ac ("mm: cma: support sysfs")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   mm/cma.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/cma.c b/mm/cma.c
> index 6d4dbafdb318..90e27458ddb7 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -512,7 +512,8 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
>   		cma_sysfs_alloc_pages_count(cma, count);
>   	} else {
>   		count_vm_event(CMA_ALLOC_FAIL);
> -		cma_sysfs_fail_pages_count(cma, count);
> +		if (cma)
> +			cma_sysfs_fail_pages_count(cma, count);
>   	}
>   
>   	return page;
> 



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

end of thread, other threads:[~2021-03-17  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 10:04 [PATCH] mm: cma: Fix potential null dereference on pointer cma Colin King
2021-03-16 18:09 ` Minchan Kim
2021-03-17  7:13 ` John Hubbard

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