* [PATCH] pagevec: Add remaining space check before adding folio to batch.
@ 2023-10-03 9:18 Juntong Deng
2023-10-03 11:40 ` Matthew Wilcox
0 siblings, 1 reply; 2+ messages in thread
From: Juntong Deng @ 2023-10-03 9:18 UTC (permalink / raw)
To: akpm, willy, vbabka, lstoakes
Cc: linux-kernel, linux-kernel-mentees, syzbot+e295147e14b474e4ad70
Currently there is no check for remaining space before adding folio to
batch, which means that folios can still be added via folio_batch_add()
when the batch is full and cause errors.
The following is related bug reported by Syzbot:
UBSAN: array-index-out-of-bounds in ./include/linux/pagevec.h:74:2
index 255 is out of range for type 'struct folio *[15]'
Checking the remaining space before adding folio to the batch can
solve this bug.
Reported-by: syzbot+e295147e14b474e4ad70@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e295147e14b474e4ad70
Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
---
include/linux/pagevec.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index 87cc678adc85..208f9a99889f 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -71,7 +71,9 @@ static inline unsigned int folio_batch_space(struct folio_batch *fbatch)
static inline unsigned folio_batch_add(struct folio_batch *fbatch,
struct folio *folio)
{
- fbatch->folios[fbatch->nr++] = folio;
+ if (folio_batch_space(fbatch))
+ fbatch->folios[fbatch->nr++] = folio;
+
return folio_batch_space(fbatch);
}
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] pagevec: Add remaining space check before adding folio to batch.
2023-10-03 9:18 [PATCH] pagevec: Add remaining space check before adding folio to batch Juntong Deng
@ 2023-10-03 11:40 ` Matthew Wilcox
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2023-10-03 11:40 UTC (permalink / raw)
To: Juntong Deng
Cc: akpm, vbabka, lstoakes, linux-kernel, linux-kernel-mentees,
syzbot+e295147e14b474e4ad70
On Tue, Oct 03, 2023 at 05:18:52PM +0800, Juntong Deng wrote:
> Currently there is no check for remaining space before adding folio to
> batch, which means that folios can still be added via folio_batch_add()
> when the batch is full and cause errors.
No. This is an ntfs3 error. It corrupted the stack. You can't fix
this in pagevec. Ignore all syzbot treports that involve ntfs3.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-03 11:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-03 9:18 [PATCH] pagevec: Add remaining space check before adding folio to batch Juntong Deng
2023-10-03 11:40 ` Matthew Wilcox
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®