* [PATCH] btrfs: Change iov_iter_alignment_iovec to check iovec count before accesses an iovec
@ 2024-07-21 20:19 Dennis Lam
2024-07-21 20:52 ` [PATCH RESEND] " Dennis Lam
0 siblings, 1 reply; 2+ messages in thread
From: Dennis Lam @ 2024-07-21 20:19 UTC (permalink / raw)
To: iro, viro; +Cc: Dennis Lam, linux-kernel, syzbot+f2a9c06bfaa027217ebb
When checking iov_iter_alignment_iovec for valid read and the iovec is empty,
the function still tries to iterate non-existant values. In this case, the iov
variable is empty and attempting to use iov->iov_len causes a kernel crash.
This patch fixes this by checking the size of the iovec before iterating.
Signed-off-by: Dennis Lam <dennis.lamerice@gmail.com>
---
lib/iov_iter.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 4a6a9f419bd7..2d82ecf1b622 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -783,7 +783,7 @@ static unsigned long iov_iter_alignment_iovec(const struct iov_iter *i)
size_t size = i->count;
size_t skip = i->iov_offset;
- do {
+ while(size) {
size_t len = iov->iov_len - skip;
if (len) {
res |= (unsigned long)iov->iov_base + skip;
@@ -794,7 +794,7 @@ static unsigned long iov_iter_alignment_iovec(const struct iov_iter *i)
}
iov++;
skip = 0;
- } while (size);
+ }
return res;
}
--
2.45.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH RESEND] btrfs: Change iov_iter_alignment_iovec to check iovec count before accesses an iovec
2024-07-21 20:19 [PATCH] btrfs: Change iov_iter_alignment_iovec to check iovec count before accesses an iovec Dennis Lam
@ 2024-07-21 20:52 ` Dennis Lam
0 siblings, 0 replies; 2+ messages in thread
From: Dennis Lam @ 2024-07-21 20:52 UTC (permalink / raw)
To: dennis.lamerice, akpm, viro; +Cc: linux-kernel, syzbot+f2a9c06bfaa027217ebb
When checking iov_iter_alignment_iovec for valid read and the iovec is empty,
the function still tries to iterate non-existant values. In this case, the iov
variable is empty and attempting to use iov->iov_len causes a kernel crash.
This patch fixes this by checking the size of the iovec before iterating.
Resent this patch in thread because one of the emails I pasted was wrong.
Signed-off-by: Dennis Lam <dennis.lamerice@gmail.com>
---
lib/iov_iter.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 4a6a9f419bd7..2d82ecf1b622 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -783,7 +783,7 @@ static unsigned long iov_iter_alignment_iovec(const struct iov_iter *i)
size_t size = i->count;
size_t skip = i->iov_offset;
- do {
+ while(size) {
size_t len = iov->iov_len - skip;
if (len) {
res |= (unsigned long)iov->iov_base + skip;
@@ -794,7 +794,7 @@ static unsigned long iov_iter_alignment_iovec(const struct iov_iter *i)
}
iov++;
skip = 0;
- } while (size);
+ }
return res;
}
--
2.45.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-21 20:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-21 20:19 [PATCH] btrfs: Change iov_iter_alignment_iovec to check iovec count before accesses an iovec Dennis Lam
2024-07-21 20:52 ` [PATCH RESEND] " Dennis Lam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®