Skip to content

block: fix memory leak in in bio_map_user_iov()#798

Open
blktests-ci[bot] wants to merge 1 commit intofor-next_basefrom
series/1089764=>for-next
Open

block: fix memory leak in in bio_map_user_iov()#798
blktests-ci[bot] wants to merge 1 commit intofor-next_basefrom
series/1089764=>for-next

Conversation

@blktests-ci
Copy link
Copy Markdown

@blktests-ci blktests-ci Bot commented May 5, 2026

Pull request for series with
subject: block: fix memory leak in in bio_map_user_iov()
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1089764

@blktests-ci
Copy link
Copy Markdown
Author

blktests-ci Bot commented May 5, 2026

Upstream branch: 07dfa98
series: https://patchwork.kernel.org/project/linux-block/list/?series=1089764
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/linux-block/list/?series=1089764
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: block: fix memory leak in in bio_map_user_iov()
Using index info to reconstruct a base tree...
M	block/blk-map.c
Falling back to patching base and 3-way merge...
Auto-merging block/blk-map.c
CONFLICT (content): Merge conflict in block/blk-map.c
Patch failed at 0001 block: fix memory leak in in bio_map_user_iov()
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc block/blk-map.c
index 768549f19f97,8523646054f0..000000000000
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@@ -268,23 -283,77 +268,88 @@@ static int bio_map_user_iov(struct requ
  		return -EINVAL;
  
  	bio = blk_rq_map_bio_alloc(rq, nr_vecs, gfp_mask);
 -	if (bio == NULL)
 +	if (!bio)
  		return -ENOMEM;
++<<<<<<< HEAD
 +	/*
 +	 * No alignment requirements on our part to support arbitrary
 +	 * passthrough commands.
 +	 */
 +	ret = bio_iov_iter_get_pages(bio, iter, 0);
 +	if (ret)
 +		goto out_put;
++=======
+ 
+ 	if (blk_queue_pci_p2pdma(rq->q))
+ 		extraction_flags |= ITER_ALLOW_P2PDMA;
+ 	if (iov_iter_extract_will_pin(iter))
+ 		bio_set_flag(bio, BIO_PAGE_PINNED);
+ 
+ 	while (iov_iter_count(iter)) {
+ 		struct page *stack_pages[UIO_FASTIOV];
+ 		struct page **pages = stack_pages;
+ 		ssize_t bytes;
+ 		size_t offs;
+ 		int npages;
+ 
+ 		if (nr_vecs > ARRAY_SIZE(stack_pages))
+ 			pages = NULL;
+ 
+ 		bytes = iov_iter_extract_pages(iter, &pages, LONG_MAX,
+ 					       nr_vecs, extraction_flags, &offs);
+ 		if (unlikely(bytes <= 0)) {
+ 			ret = bytes ? bytes : -EFAULT;
+ 			if (pages != stack_pages)
+ 				kvfree(pages);
+ 			goto out_unmap;
+ 		}
+ 
+ 		npages = DIV_ROUND_UP(offs + bytes, PAGE_SIZE);
+ 
+ 		if (unlikely(offs & queue_dma_alignment(rq->q)))
+ 			j = 0;
+ 		else {
+ 			for (j = 0; j < npages; j++) {
+ 				struct page *page = pages[j];
+ 				unsigned int n = PAGE_SIZE - offs;
+ 				bool same_page = false;
+ 
+ 				if (n > bytes)
+ 					n = bytes;
+ 
+ 				if (!bio_add_hw_page(rq->q, bio, page, n, offs,
+ 						     max_sectors, &same_page))
+ 					break;
+ 
+ 				if (same_page)
+ 					bio_release_page(bio, page);
+ 				bytes -= n;
+ 				offs = 0;
+ 			}
+ 		}
+ 		/*
+ 		 * release the pages we didn't map into the bio, if any
+ 		 */
+ 		while (j < npages)
+ 			bio_release_page(bio, pages[j++]);
+ 		if (pages != stack_pages)
+ 			kvfree(pages);
+ 		/* couldn't stuff something into bio? */
+ 		if (bytes) {
+ 			iov_iter_revert(iter, bytes);
+ 			break;
+ 		}
+ 	}
+ 
++>>>>>>> block: fix memory leak in in bio_map_user_iov()
  	ret = blk_rq_append_bio(rq, bio);
  	if (ret)
 -		goto out_unmap;
 +		goto out_release;
  	return 0;
  
 - out_unmap:
 +out_release:
  	bio_release_pages(bio, false);
 +out_put:
  	blk_mq_map_bio_put(bio);
  	return ret;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants