Blame SOURCES/0021-fs-ntfs3-add-checks-for-allocation-failure.patch

Kmods SIG 8b815c
From a1b04d380ab64790a7b4a8eb52e14679e47065ab Mon Sep 17 00:00:00 2001
Kmods SIG 8b815c
From: Dan Carpenter <dan.carpenter@oracle.com>
Kmods SIG 8b815c
Date: Tue, 24 Aug 2021 14:52:36 +0300
Kmods SIG 8b815c
Subject: [Backport a1b04d380ab6] src: add checks for allocation failure
Kmods SIG 8b815c
Kmods SIG 8b815c
Add a check for when the kzalloc() in init_rsttbl() fails.  Some of
Kmods SIG 8b815c
the callers checked for NULL and some did not.  I went down the call
Kmods SIG 8b815c
tree and added NULL checks where ever they were missing.
Kmods SIG 8b815c
Kmods SIG 8b815c
Fixes: b46acd6a6a62 ("src: Add NTFS journal")
Kmods SIG 8b815c
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Kmods SIG 8b815c
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Kmods SIG 8b815c
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Kmods SIG 8b815c
---
Kmods SIG 8b815c
 src/fslog.c | 18 ++++++++++++++++--
Kmods SIG 8b815c
 1 file changed, 16 insertions(+), 2 deletions(-)
Kmods SIG 8b815c
Kmods SIG 8b815c
diff --git a/src/fslog.c b/src/fslog.c
Kmods SIG 8b815c
index 2c213b55979ed06c03f4e74998fd03f9a9a8827b..7144ea8a9ab898e35c75e06192f20f9d93504bb8 100644
Kmods SIG 8b815c
--- a/src/fslog.c
Kmods SIG 8b815c
+++ b/src/fslog.c
Kmods SIG 8b815c
@@ -809,6 +809,9 @@ static inline struct RESTART_TABLE *init_rsttbl(u16 esize, u16 used)
Kmods SIG 8b815c
 	u32 lf = sizeof(struct RESTART_TABLE) + (used - 1) * esize;
Kmods SIG 8b815c
 	struct RESTART_TABLE *t = kzalloc(bytes, GFP_NOFS);
Kmods SIG 8b815c
 
Kmods SIG 8b815c
+	if (!t)
Kmods SIG 8b815c
+		return NULL;
Kmods SIG 8b815c
+
Kmods SIG 8b815c
 	t->size = cpu_to_le16(esize);
Kmods SIG 8b815c
 	t->used = cpu_to_le16(used);
Kmods SIG 8b815c
 	t->free_goal = cpu_to_le32(~0u);
Kmods SIG 8b815c
@@ -831,7 +834,11 @@ static inline struct RESTART_TABLE *extend_rsttbl(struct RESTART_TABLE *tbl,
Kmods SIG 8b815c
 	u16 esize = le16_to_cpu(tbl->size);
Kmods SIG 8b815c
 	__le32 osize = cpu_to_le32(bytes_per_rt(tbl));
Kmods SIG 8b815c
 	u32 used = le16_to_cpu(tbl->used);
Kmods SIG 8b815c
-	struct RESTART_TABLE *rt = init_rsttbl(esize, used + add);
Kmods SIG 8b815c
+	struct RESTART_TABLE *rt;
Kmods SIG 8b815c
+
Kmods SIG 8b815c
+	rt = init_rsttbl(esize, used + add);
Kmods SIG 8b815c
+	if (!rt)
Kmods SIG 8b815c
+		return NULL;
Kmods SIG 8b815c
 
Kmods SIG 8b815c
 	memcpy(rt + 1, tbl + 1, esize * used);
Kmods SIG 8b815c
 
Kmods SIG 8b815c
@@ -864,8 +871,11 @@ static inline void *alloc_rsttbl_idx(struct RESTART_TABLE **tbl)
Kmods SIG 8b815c
 	__le32 *e;
Kmods SIG 8b815c
 	struct RESTART_TABLE *t = *tbl;
Kmods SIG 8b815c
 
Kmods SIG 8b815c
-	if (!t->first_free)
Kmods SIG 8b815c
+	if (!t->first_free) {
Kmods SIG 8b815c
 		*tbl = t = extend_rsttbl(t, 16, ~0u);
Kmods SIG 8b815c
+		if (!t)
Kmods SIG 8b815c
+			return NULL;
Kmods SIG 8b815c
+	}
Kmods SIG 8b815c
 
Kmods SIG 8b815c
 	off = le32_to_cpu(t->first_free);
Kmods SIG 8b815c
 
Kmods SIG 8b815c
@@ -4482,6 +4492,10 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
Kmods SIG 8b815c
 		}
Kmods SIG 8b815c
 
Kmods SIG 8b815c
 		dp = alloc_rsttbl_idx(&dptbl);
Kmods SIG 8b815c
+		if (!dp) {
Kmods SIG 8b815c
+			err = -ENOMEM;
Kmods SIG 8b815c
+			goto out;
Kmods SIG 8b815c
+		}
Kmods SIG 8b815c
 		dp->target_attr = cpu_to_le32(t16);
Kmods SIG 8b815c
 		dp->transfer_len = cpu_to_le32(t32 << sbi->cluster_bits);
Kmods SIG 8b815c
 		dp->lcns_follow = cpu_to_le32(t32);
Kmods SIG 8b815c
-- 
Kmods SIG 8b815c
2.31.1
Kmods SIG 8b815c