Thread (32 messages) 32 messages, 5 authors, 2023-04-10

Re: [PATCH v2 15/19] md: check for failure when adding pages in alloc_behind_master_bio

From: Song Liu <song@kernel.org>
Date: 2023-03-31 17:54:23
Also in: dm-devel, linux-btrfs, linux-fsdevel, linux-mm, linux-raid

On Thu, Mar 30, 2023 at 3:44 AM Johannes Thumshirn
[off-list ref] wrote:
quoted hunk ↗ jump to hunk
alloc_behind_master_bio() can possibly add multiple pages to a bio, but it
is not checking for the return value of bio_add_page() if adding really
succeeded.

Check if the page adding succeeded and if not bail out.

Signed-off-by: Johannes Thumshirn <redacted>
Reviewed-by: Damien Le Moal <redacted>
---
 drivers/md/raid1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 68a9e2d9985b..bd7c339a84a1 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1147,7 +1147,8 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,
                if (unlikely(!page))
                        goto free_pages;

-               bio_add_page(behind_bio, page, len, 0);
+               if (!bio_add_page(behind_bio, page, len, 0))
+                       goto free_pages;
We will leak page here, no?

Thanks,
Song
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help