ntfs3.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH (repost)] fs/ntfs3: Use __GFP_NOWARN allocation at ntfs_load_attr_list()
@ 2023-03-28 11:05 Tetsuo Handa
  2023-04-19 11:19 ` [PATCH v2] fs/ntfs3: validate data_size " Tetsuo Handa
  0 siblings, 1 reply; 2+ messages in thread
From: Tetsuo Handa @ 2023-03-28 11:05 UTC (permalink / raw)
  To: Konstantin Komarov; +Cc: ntfs3

syzbot is reporting too large allocation at ntfs_load_attr_list(), for
a crafted filesystem can have huge data_size.

Reported-by: syzbot <syzbot+89dbb3a789a5b9711793@syzkaller.appspotmail.com>
Link: https://syzkaller.appspot.com/bug?extid=89dbb3a789a5b9711793
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
Michal Hocko does not like blind __GFP_NOWARN usage. But since it seems that
nobody can answer the max size to accept, reposting as-is.
https://lkml.kernel.org/r/518d5b42-be63-28ad-f28e-0f1d5d992230@I-love.SAKURA.ne.jp

 fs/ntfs3/attrlist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs3/attrlist.c b/fs/ntfs3/attrlist.c
index c0c6bcbc8c05..81c22df27c72 100644
--- a/fs/ntfs3/attrlist.c
+++ b/fs/ntfs3/attrlist.c
@@ -52,7 +52,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
 
 	if (!attr->non_res) {
 		lsize = le32_to_cpu(attr->res.data_size);
-		le = kmalloc(al_aligned(lsize), GFP_NOFS);
+		le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
 		if (!le) {
 			err = -ENOMEM;
 			goto out;
@@ -80,7 +80,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
 		if (err < 0)
 			goto out;
 
-		le = kmalloc(al_aligned(lsize), GFP_NOFS);
+		le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
 		if (!le) {
 			err = -ENOMEM;
 			goto out;
-- 
2.18.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2] fs/ntfs3: validate data_size at ntfs_load_attr_list()
  2023-03-28 11:05 [PATCH (repost)] fs/ntfs3: Use __GFP_NOWARN allocation at ntfs_load_attr_list() Tetsuo Handa
@ 2023-04-19 11:19 ` Tetsuo Handa
  0 siblings, 0 replies; 2+ messages in thread
From: Tetsuo Handa @ 2023-04-19 11:19 UTC (permalink / raw)
  To: Konstantin Komarov; +Cc: ntfs3

syzbot is reporting too large allocation at ntfs_load_attr_list(), for
a crafted filesystem can have huge data_size.

If -1023 <= (ssize_t) lsize <= 0 range, kmalloc(al_aligned(lsize)) allows
writing lsize bytes at ZERO_SIZE_PTR. But since nobody knows the valid
range, let's try limiting to 0 < lsize <= 1048576 range (and also add
__GFP_NOWARN in case costly memory allocation failed).

Reported-by: syzbot <syzbot+89dbb3a789a5b9711793@syzkaller.appspotmail.com>
Link: https://syzkaller.appspot.com/bug?extid=89dbb3a789a5b9711793
Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 fs/ntfs3/attrlist.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs3/attrlist.c b/fs/ntfs3/attrlist.c
index c0c6bcbc8c05..46d52f66aca4 100644
--- a/fs/ntfs3/attrlist.c
+++ b/fs/ntfs3/attrlist.c
@@ -52,7 +52,12 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
 
 	if (!attr->non_res) {
 		lsize = le32_to_cpu(attr->res.data_size);
-		le = kmalloc(al_aligned(lsize), GFP_NOFS);
+		/* Arbitrary limit for avoid accessing ZERO_SIZE_PTR. */
+		if (!lsize || lsize > 1048576) {
+			err = -ENOMEM;
+			goto out;
+		}
+		le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
 		if (!le) {
 			err = -ENOMEM;
 			goto out;
@@ -80,7 +85,12 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
 		if (err < 0)
 			goto out;
 
-		le = kmalloc(al_aligned(lsize), GFP_NOFS);
+		/* Arbitrary limit for avoid accessing ZERO_SIZE_PTR. */
+		if (!lsize || lsize > 1048576) {
+			err = -ENOMEM;
+			goto out;
+		}
+		le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
 		if (!le) {
 			err = -ENOMEM;
 			goto out;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-19 11:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28 11:05 [PATCH (repost)] fs/ntfs3: Use __GFP_NOWARN allocation at ntfs_load_attr_list() Tetsuo Handa
2023-04-19 11:19 ` [PATCH v2] fs/ntfs3: validate data_size " Tetsuo Handa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).