Skip to contentSkip to conversation

dma-debug: Avoid NULL dereference when checking sync

PATCH In review Maarten ter Huurne 2 participants 2 messages Oct 31, 2016 – Nov 8, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-debug: Avoid NULL dereference when checking sync

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

---
 lib/dma-debug.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/dma-debug.c +5 -0
index 8971370..84c6e88 100644
@@ -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);
Signature · 1 line
2.6.6
maintainer
#1 lore raw
Quoted 9 lines · On Mon, 31 Oct 2016 16:11:41 +0100 Maarten ter Huurne <[email protected]>…

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

...

lib/dma-debug.c +0 -0
@@ -1223,6 +1223,11 @@ static void check_sync(struct device *dev,
 	struct hash_bucket *bucket;

lib/dma-debug.c static void check_sync(struct device *dev, · line 1233

Quoted 10 lines
lib/dma-debug.c +5 -0
 	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?