Skip to contentSkip to conversation

block: avoid null pointer dereference on null disk

PATCH Applied Colin King 3 participants 3 messages Nov 6, 2017 – Nov 10, 2017

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 block: avoid null pointer dereference on null disk

From: Colin Ian King <[email protected]>

It is possible that the pointer disk can be null and hence we can get a null pointer deference when accessing disk->flags. Add a null pointer check to avoid the dereference.

Detected by CoverityScan, CID#1461133 ("Explicit null dereferenced")

Fixes 8ddcd653257c ("block: introduce GENHD_FL_HIDDEN")
---
 block/genhd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/genhd.c +1 -1
index d85dcc701d76..42908a7186cd 100644
@@ -798,7 +798,7 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
 		spin_unlock_bh(&ext_devt_lock);
 	}
 
-	if (unlikely(disk->flags & GENHD_FL_HIDDEN)) {
+	if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) {
 		put_disk(disk);
 		disk = NULL;
 	}
Signature · 1 line
2.14.1
maintainer Applied
#2 lore raw
In reply to Colin King
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

It is possible that the pointer disk can be null and hence we can get a null pointer deference when accessing disk->flags. Add a null pointer check to avoid the dereference.

Applied, thanks.

Signature · 1 line
Jens Axboe