From: Dennis Lam <dennis.lamerice@gmail.com>
To: iro@zeniv.linux.org.uk, viro@zeniv.linux.org.uk
Cc: Dennis Lam <dennis.lamerice@gmail.com>,
linux-kernel@vger.kernel.org,
syzbot+f2a9c06bfaa027217ebb@syzkaller.appspotmail.com
Subject: [PATCH] btrfs: Change iov_iter_alignment_iovec to check iovec count before accesses an iovec
Date: Sun, 21 Jul 2024 16:19:18 -0400 [thread overview]
Message-ID: <20240721201924.48781-2-dennis.lamerice@gmail.com> (raw)
In-Reply-To: <dennis.lamerice@gmail.com>
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
next reply other threads:[~2024-07-21 20:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-21 20:19 Dennis Lam [this message]
2024-07-21 20:52 ` [PATCH RESEND] " Dennis Lam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240721201924.48781-2-dennis.lamerice@gmail.com \
--to=dennis.lamerice@gmail.com \
--cc=iro@zeniv.linux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+f2a9c06bfaa027217ebb@syzkaller.appspotmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®