All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-debug: Avoid NULL dereference when checking sync
@ 2016-10-31 15:11 Maarten ter Huurne
  2016-11-08  0:38 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Maarten ter Huurne @ 2016-10-31 15:11 UTC (permalink / raw)
  To: Vinod Koul; +Cc: Andrew Morton, dmaengine, linux-kernel, Maarten ter Huurne

check_sync() calls bucket_find_contain(), which in turn calls
dma_get_max_seg_size(), which dereferences the device pointer.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
---
 lib/dma-debug.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 8971370..84c6e88 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -1223,6 +1223,11 @@ static void check_sync(struct device *dev,
 	struct hash_bucket *bucket;
 	unsigned long flags;
 
+	if (!ref->dev) {
+		err_printk(dev, NULL, "DMA-API: device driver passes NULL for device to DMA sync function; cannot check usage\n");
+		return;
+	}
+
 	bucket = get_hash_bucket(ref, &flags);
 
 	entry = bucket_find_contain(&bucket, ref, &flags);
-- 
2.6.6

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

* Re: [PATCH] dma-debug: Avoid NULL dereference when checking sync
  2016-10-31 15:11 [PATCH] dma-debug: Avoid NULL dereference when checking sync Maarten ter Huurne
@ 2016-11-08  0:38 ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2016-11-08  0:38 UTC (permalink / raw)
  To: Maarten ter Huurne; +Cc: Vinod Koul, dmaengine, linux-kernel

On Mon, 31 Oct 2016 16:11:41 +0100 Maarten ter Huurne <maarten@treewalker.org> wrote:

> check_sync() calls bucket_find_contain(), which in turn calls
> dma_get_max_seg_size(), which dereferences the device pointer.
> 
> ...
>
> --- a/lib/dma-debug.c
> +++ b/lib/dma-debug.c
> @@ -1223,6 +1223,11 @@ static void check_sync(struct device *dev,
>  	struct hash_bucket *bucket;
>  	unsigned long flags;
>  
> +	if (!ref->dev) {
> +		err_printk(dev, NULL, "DMA-API: device driver passes NULL for device to DMA sync function; cannot check usage\n");
> +		return;
> +	}
> +
>  	bucket = get_hash_bucket(ref, &flags);
>  
>  	entry = bucket_find_contain(&bucket, ref, &flags);

Well.

a) who is calling check_sync() without having filled in ref.dev? 
   How does this occur?  Is this a bug in the caller?

b) why does check_sync() have a `dev' argument anyway?  Is there any
   situation in which that will differ from ref.dev?

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

* [PATCH] dma-debug: Avoid NULL dereference when checking sync
@ 2016-02-28 15:20 Maarten ter Huurne
  0 siblings, 0 replies; 3+ messages in thread
From: Maarten ter Huurne @ 2016-02-28 15:20 UTC (permalink / raw)
  To: Dan Williams, Jiri Kosina; +Cc: linux-kernel, Maarten ter Huurne

check_sync() calls bucket_find_contain(), which in turn calls
dma_get_max_seg_size(), which dereferences the device pointer.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
---
 lib/dma-debug.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 4a1515f..4960402 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -1194,6 +1194,13 @@ static void check_sync(struct device *dev,
 	struct hash_bucket *bucket;
 	unsigned long flags;
 
+	if (!ref->dev) {
+		err_printk(dev, NULL, "DMA-API: device driver passes NULL "
+				"for device to DMA sync function; "
+				"cannot check usage\n");
+		return;
+	}
+
 	bucket = get_hash_bucket(ref, &flags);
 
 	entry = bucket_find_contain(&bucket, ref, &flags);
-- 
2.6.2

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

end of thread, other threads:[~2016-11-08  0:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-31 15:11 [PATCH] dma-debug: Avoid NULL dereference when checking sync Maarten ter Huurne
2016-11-08  0:38 ` Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2016-02-28 15:20 Maarten ter Huurne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.