[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <VI1P193MB0752429AFF2B87041B0D9E2799C4A@VI1P193MB0752.EURP193.PROD.OUTLOOK.COM>
Date: Tue, 3 Oct 2023 17:18:52 +0800
From: Juntong Deng <juntong.deng@...look.com>
To: akpm@...ux-foundation.org, willy@...radead.org, vbabka@...e.cz,
lstoakes@...il.com
Cc: linux-kernel@...r.kernel.org,
linux-kernel-mentees@...ts.linuxfoundation.org,
syzbot+e295147e14b474e4ad70@...kaller.appspotmail.com
Subject: [PATCH] pagevec: Add remaining space check before adding folio to batch.
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@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e295147e14b474e4ad70
Signed-off-by: Juntong Deng <juntong.deng@...look.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
Powered by blists - more mailing lists