Skip to contentSkip to conversation

md: fix refcount problem on mddev when stopping array.

PATCH Applied NeilBrown 3 participants 3 messages Dec 5, 2016 – Dec 6, 2016 MD RAID

lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 md: fix refcount problem on mddev when stopping array.

md_open() gets a counted reference on an mddev using mddev_find(). If it ends up returning an error, it must drop this reference.

There are two error paths where the reference is not dropped. One only happens if the process is signalled and an awkward time, which is quite unlikely.
The other was introduced recently in commit af8d8e6f0.

Change the code to ensure the drop the reference when returning an error, and make it harded to re-introduce this sort of bug in the future.

Fixes af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")

---

Hi Shaohua,
as this bug was introduced in v4.9-rc1, it would be great if this patch could get to Linus before v4.9-final comes out (on Sunday?).

Thanks,
NeilBrown

 drivers/md/md.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/md.c +4 -1
index 2089d46b0eb8..d1a291ac2a75 100644
@@ -7092,7 +7092,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
 	if (test_bit(MD_CLOSING, &mddev->flags)) {
 		mutex_unlock(&mddev->open_mutex);
-		return -ENODEV;
+		err = -ENODEV;
+		goto out;
 	}
 
 	err = 0;
@@ -7101,6 +7102,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
 	check_disk_change(bdev);
  out:
+	if (err)
+		mddev_put(mddev);
 	return err;
 }
 
Signature · 1 line
2.10.2
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · NeilBrown

md_open() gets a counted reference on an mddev using mddev_find(). If it ends up returning an error, it must drop this reference.

There are two error paths where the reference is not dropped. One only happens if the process is signalled and an awkward time, which is quite unlikely.
The other was introduced recently in commit af8d8e6f0.

Change the code to ensure the drop the reference when returning an error, and make it harded to re-introduce this sort of bug in the future.

Yes, thanks for fix it.

Best Regards,
Guoqing

Quoted 40 lines
Fixes af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")

---

Hi Shaohua,
as this bug was introduced in v4.9-rc1, it would be great if this patch could get to Linus before v4.9-final comes out (on Sunday?).

Thanks,
NeilBrown

  drivers/md/md.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/md.c +4 -1
index 2089d46b0eb8..d1a291ac2a75 100644
@@ -7092,7 +7092,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
  	if (test_bit(MD_CLOSING, &mddev->flags)) {
  		mutex_unlock(&mddev->open_mutex);
-		return -ENODEV;
+		err = -ENODEV;
+		goto out;
  	}
 
  	err = 0;
@@ -7101,6 +7102,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
  	check_disk_change(bdev);
   out:
+	if (err)
+		mddev_put(mddev);
  	return err;
  }
 
Applied
#2 lore raw
In reply to NeilBrown
Quoted 12 lines · Neil Brown

md_open() gets a counted reference on an mddev using mddev_find(). If it ends up returning an error, it must drop this reference.

There are two error paths where the reference is not dropped. One only happens if the process is signalled and an awkward time, which is quite unlikely.
The other was introduced recently in commit af8d8e6f0.

Change the code to ensure the drop the reference when returning an error, and make it harded to re-introduce this sort of bug in the future.

Quoted 8 lines
Fixes af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")

---

Hi Shaohua,
as this bug was introduced in v4.9-rc1, it would be great if this patch could get to Linus before v4.9-final comes out (on Sunday?).

Applied to the for-next tree. This sounds not significant enough, so I'll push it to 4.10.

Thanks,
Shaohua

Quoted 33 lines

Thanks,
NeilBrown

 drivers/md/md.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/md.c +4 -1
index 2089d46b0eb8..d1a291ac2a75 100644
@@ -7092,7 +7092,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
 	if (test_bit(MD_CLOSING, &mddev->flags)) {
 		mutex_unlock(&mddev->open_mutex);
-		return -ENODEV;
+		err = -ENODEV;
+		goto out;
 	}
 
 	err = 0;
@@ -7101,6 +7102,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
 	check_disk_change(bdev);
  out:
+	if (err)
+		mddev_put(mddev);
 	return err;
 }
 
Signature · 1 line
2.10.2