Skip to contentSkip to conversation

md/raid5: fix possible NULL pointer dereference in debug routine

PATCH Applied Namhyung Kim 2 participants 2 messages Jun 24, 2011 – Jun 28, 2011 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md/raid5: fix possible NULL pointer dereference in debug routine

When I ran dynamic debug, I encountered a NULL pointer dereference bug in add_stripe_bio(). Prior to second call to pr_debug(), @bi was reused in order to check whether the request is partial write or not, and it could lead to set @bi to NULL.

Since we save original @bi pointer into local variable 'bip', use it instead of NULL-able @bi.

Also changed confusing 'bh' to 'bi' in the first message.

---
 drivers/md/raid5.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/raid5.c +2 -2
index 82c07fb38961..c814a6075c79 100644
@@ -2139,7 +2139,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 	raid5_conf_t *conf = sh->raid_conf;
 	int firstwrite=0;
 
-	pr_debug("adding bh b#%llu to stripe s#%llu\n",
+	pr_debug("adding bi b#%llu to stripe s#%llu\n",
 		(unsigned long long)bi->bi_sector,
 		(unsigned long long)sh->sector);
 
@@ -2181,7 +2181,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 	spin_unlock_irq(&conf->device_lock);
 
 	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
-		(unsigned long long)bi->bi_sector,
+		(unsigned long long)(*bip)->bi_sector,
 		(unsigned long long)sh->sector, dd_idx);
 
 	if (conf->mddev->bitmap && firstwrite) {
Signature · 1 line
1.7.5.2
Applied
#1 lore raw
Quoted 29 lines · On Fri, 24 Jun 2011 14:04:00 +0900 Namhyung Kim <[email protected]> wrote:

When I ran dynamic debug, I encountered a NULL pointer dereference bug in add_stripe_bio(). Prior to second call to pr_debug(), @bi was reused in order to check whether the request is partial write or not, and it could lead to set @bi to NULL.

Since we save original @bi pointer into local variable 'bip', use it instead of NULL-able @bi.

Also changed confusing 'bh' to 'bi' in the first message.

---
 drivers/md/raid5.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/raid5.c +1 -1
index 82c07fb38961..c814a6075c79 100644
@@ -2139,7 +2139,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 	raid5_conf_t *conf = sh->raid_conf;
 	int firstwrite=0;
 
-	pr_debug("adding bh b#%llu to stripe s#%llu\n",
+	pr_debug("adding bi b#%llu to stripe s#%llu\n",
 		(unsigned long long)bi->bi_sector,
 		(unsigned long long)sh->sector);
 

drivers/md/raid5.c static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in · line 2187

Quoted 8 lines
drivers/md/raid5.c +1 -1
@@ -2181,7 +2181,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 	spin_unlock_irq(&conf->device_lock);
 
 	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
-		(unsigned long long)bi->bi_sector,
+		(unsigned long long)(*bip)->bi_sector,
 		(unsigned long long)sh->sector, dd_idx);
 
 	if (conf->mddev->bitmap && firstwrite) {

Applied, thanks.

NeilBrown