md-cluster: Fix potential error pointer dereference in resize_bitmaps()
Subsystems (2)
PATCH 1/1 md-cluster: Fix potential error pointer dereference in resize_bitmaps()
The error handling calls md_bitmap_free(bitmap) which checks for NULL but will Oops if we pass an error pointer. Let's set "bitmap" to NULL on this error path.
--- drivers/md/md-cluster.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/md-cluster.c +1 -0
@@ -1139,6 +1139,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz bitmap =get_bitmap_from_slot (mddev, i);if (IS_ERR (bitmap)) {pr_err ("can't get bitmap from slot %d\n" , i); + bitmap =NULL ; goto out; } counts = &bitmap->counts;
Signature · 1 line
2.27.0
Quoted 15 lines · Dan Carpenter
The error handling calls
md_bitmap_free(bitmap)which checks for NULL but will Oops if we pass an error pointer. Let's set "bitmap" to NULL on this error path.Fixes afd756286083 ("md-cluster/raid10: resize all the bitmaps before start reshape")Signed-off-by Dan Carpenter <[email protected]>--- drivers/md/md-cluster.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md-cluster.c +0
-0
drivers/md/md-cluster.c static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz · line 1145
Quoted 7 lines
drivers/md/md-cluster.c +1
-0@@ -1139,6 +1139,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz bitmap =get_bitmap_from_slot (mddev, i);if (IS_ERR (bitmap)) {pr_err ("can't get bitmap from slot %d\n" , i); + bitmap =NULL ; goto out; } counts = &bitmap->counts;
Thanks for the catch, Reviewed-by: Guoqing Jiang
<[email protected]>
BTW, seems there could be memory leak in the function since it keeps allocate bitmap
in the loop ..., will send a format patch.
drivers/md/md-cluster.c +0 -0
@@ -1165,6 +1165,8 @@ static int resize_bitmaps(struct mddev *mddev,
sector_t newsize, sector_t oldsiz
* can't resize bitmap
*/
goto out;
+
+ md_bitmap_free(bitmap);
}
return 0;
Thanks,
Guoqing
Quoted 39 lines · Guoqing Jiang
Quoted 15 lines · Dan Carpenter
The error handling calls
md_bitmap_free(bitmap)which checks for NULL but will Oops if we pass an error pointer. Let's set "bitmap" to NULL on this error path.Fixes afd756286083 ("md-cluster/raid10: resize all the bitmaps before start reshape")Signed-off-by Dan Carpenter <[email protected]>--- drivers/md/md-cluster.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md-cluster.c +0
-0drivers/md/md-cluster.c static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz · line 1145
Quoted 7 lines
drivers/md/md-cluster.c +1
-0@@ -1139,6 +1139,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz bitmap =get_bitmap_from_slot (mddev, i);if (IS_ERR (bitmap)) {pr_err ("can't get bitmap from slot %d\n" , i); + bitmap =NULL ; goto out; } counts = &bitmap->counts;Thanks for the catch, Reviewed-by: Guoqing Jiang
<[email protected]>BTW, seems there could be memory leak in the function since it keeps allocate bitmap
in the loop ..., will send a format patch.drivers/md/md-cluster.c +0
-0@@ -1165,6 +1165,8 @@ static int resize_bitmaps(struct mddev *mddev,
Quoted 6 lines
sector_tnewsize,sector_toldsiz
* can't resize bitmap
*/
goto out;
+
+md_bitmap_free(bitmap);
Hm... I'm now not at all certain my patch is correct. Although it's obviously harmless and fixes an Oops. I had thought that that the call to update_bitmap_size(mddev, oldsize) would free the rest of the loop.
I really suspect adding a free like you're suggesting will break the success path.
I'm not familiar with this code at all.
regards,
dan carpenter
Song Liu
maintainerQuoted 52 lines · Dan Carpenter
Quoted 43 lines · Guoqing Jiang
Quoted 15 lines · Dan Carpenter
The error handling calls
md_bitmap_free(bitmap)which checks for NULL but will Oops if we pass an error pointer. Let's set "bitmap" to NULL on this error path.Fixes afd756286083 ("md-cluster/raid10: resize all the bitmaps before start reshape")Signed-off-by Dan Carpenter <[email protected]>--- drivers/md/md-cluster.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md-cluster.c +0
-0drivers/md/md-cluster.c static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz · line 1145
Quoted 7 lines
drivers/md/md-cluster.c +1
-0@@ -1139,6 +1139,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz bitmap =get_bitmap_from_slot (mddev, i);if (IS_ERR (bitmap)) {pr_err ("can't get bitmap from slot %d\n" , i); + bitmap =NULL ; goto out; } counts = &bitmap->counts;Thanks for the catch, Reviewed-by: Guoqing Jiang
<[email protected]>BTW, seems there could be memory leak in the function since it keeps allocate bitmap
in the loop ..., will send a format patch.drivers/md/md-cluster.c +0
-0@@ -1165,6 +1165,8 @@ static int resize_bitmaps(struct mddev *mddev,
sector_tnewsize,sector_toldsiz* can't resize bitmap */ goto out;drivers/md/md-cluster.c
Quoted 2 lines
drivers/md/md-cluster.c +2
-0+ +md_bitmap_free (bitmap);Hm... I'm now not at all certain my patch is correct. Although it's obviously harmless and fixes an Oops. I had thought that that the call to
update_bitmap_size(mddev, oldsize)would free the rest of the loop.
Quoted 4 lines
I really suspect adding a free like you're suggesting will break the success path.
I'm not familiar with this code at all.
Thanks Dan and Guoqing. I applied Dans' patch to md-next.
I think we are leaking bitmap in resize_bitmaps(). But we gonna need more complex fix than the md_bitmap_free() above.
Thanks,
Song
Hello Song,
I just found this mail, and I send a similar patch on 2020-9-27. From my thinking, Guoqing's patch for fixing memory leak is enough.
the resize_bitmaps() work flow:
- first use update_bitmap_size() to broadcast BITMAP_RESIZE to all nodes, and waiting for the other nodes ack.
- then in for loop, by holding bitmap00x lock to update not booted slot's bitmap info.
the bitmap in for() is temporary, it should be safely freed on every time of end for().
Thanks.
Quoted 66 lines · Song Liu
Quoted 52 lines · Dan Carpenter
Quoted 43 lines · Guoqing Jiang
Quoted 15 lines · Dan Carpenter
The error handling calls
md_bitmap_free(bitmap)which checks for NULL but will Oops if we pass an error pointer. Let's set "bitmap" to NULL on this error path.Fixes afd756286083 ("md-cluster/raid10: resize all the bitmaps before start reshape")Signed-off-by Dan Carpenter <[email protected]>--- drivers/md/md-cluster.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md-cluster.c +0
-0drivers/md/md-cluster.c static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz · line 1145
Quoted 7 lines
drivers/md/md-cluster.c +1
-0@@ -1139,6 +1139,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz bitmap =get_bitmap_from_slot (mddev, i);if (IS_ERR (bitmap)) {pr_err ("can't get bitmap from slot %d\n" , i); + bitmap =NULL ; goto out; } counts = &bitmap->counts;Thanks for the catch, Reviewed-by: Guoqing Jiang
<[email protected]>BTW, seems there could be memory leak in the function since it keeps allocate bitmap
in the loop ..., will send a format patch.drivers/md/md-cluster.c +0
-0@@ -1165,6 +1165,8 @@ static int resize_bitmaps(struct mddev *mddev,
sector_tnewsize,sector_toldsiz* can't resize bitmap */ goto out;drivers/md/md-cluster.c
Quoted 2 lines
drivers/md/md-cluster.c +2
-0+ +md_bitmap_free (bitmap);Hm... I'm now not at all certain my patch is correct. Although it's obviously harmless and fixes an Oops. I had thought that that the call to
update_bitmap_size(mddev, oldsize)would free the rest of the loop.Quoted 4 lines
I really suspect adding a free like you're suggesting will break the success path.
I'm not familiar with this code at all.
Thanks Dan and Guoqing. I applied Dans' patch to md-next.
I think we are leaking bitmap in
resize_bitmaps(). But we gonna need more complex fix than themd_bitmap_free()above.Thanks,
Song