Skip to contentSkip to conversation

lib/iov_iter.c: initialize bi.bi_idx before iterating over bvec

PATCH In review Ming Lei 3 participants 3 messages Oct 31, 2024

Subsystems (3)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 lib/iov_iter.c: initialize bi.bi_idx before iterating over bvec

Initialize bi.bi_idx as 0 before iterating over bvec, otherwise garbage data can be used as ->bi_idx.

Cc Christoph Hellwig <[email protected]>
Reported-and-tested-by Klara Modin <[email protected]>
Fixes e4e535bff2bc ("iov_iter: don't require contiguous pages in iov_iter_extract_bvec_pages")
---
 lib/iov_iter.c | 1 +
 1 file changed, 1 insertion(+)
lib/iov_iter.c +1 -0
index 9fc06f5fb748..c761f6db3cb4 100644
@@ -1699,6 +1699,7 @@ static ssize_t iov_iter_extract_bvec_pages(struct iov_iter *i,
 		i->bvec++;
 		skip = 0;
 	}
+	bi.bi_idx = 0;
 	bi.bi_size = maxsize + skip;
 	bi.bi_bvec_done = skip;
 
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Ming Lei

Initialize bi.bi_idx as 0 before iterating over bvec, otherwise garbage data can be used as ->bi_idx.

Cc Christoph Hellwig <[email protected]>
Reported-and-tested-by Klara Modin <[email protected]>
Fixes e4e535bff2bc ("iov_iter: don't require contiguous pages in iov_iter_extract_bvec_pages")
---
 lib/iov_iter.c | 1 +
 1 file changed, 1 insertion(+)
lib/iov_iter.c +0 -0
index 9fc06f5fb748..c761f6db3cb4 100644

lib/iov_iter.c static ssize_t iov_iter_extract_bvec_pages(struct iov_iter *i, · line 1702

Quoted 4 lines
lib/iov_iter.c +1 -0
@@ -1699,6 +1699,7 @@ static ssize_t iov_iter_extract_bvec_pages(struct iov_iter *i,
 		i->bvec++;
 		skip = 0;
 	}
+	bi.bi_idx = 0;

Looks good, but the more future proof variant would be to initialize bi to zero at declaration time:

	struct bvec_iter bi = { };

Either way:

maintainer
#2 lore raw
In reply to Ming Lei
Quoted 2 lines · Ming Lei

Initialize bi.bi_idx as 0 before iterating over bvec, otherwise garbage data can be used as ->bi_idx.

For some reason this wasn't on lore, so manual reply to say that I applied it.

Signature · 1 line
Jens Axboe