public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 6.1 01/10] fs/ntfs3: Check if more than chunk-size bytes are written
@ 2024-10-14  3:58 Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 02/10] fs/ntfs3: Fix warning possible deadlock in ntfs_set_state Sasha Levin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sasha Levin @ 2024-10-14  3:58 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Andrew Ballance, Konstantin Komarov, Sasha Levin, ntfs3

From: Andrew Ballance <andrewjballance@gmail.com>

[ Upstream commit 9931122d04c6d431b2c11b5bb7b10f28584067f0 ]

A incorrectly formatted chunk may decompress into
more than LZNT_CHUNK_SIZE bytes and a index out of bounds
will occur in s_max_off.

Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ntfs3/lznt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/ntfs3/lznt.c b/fs/ntfs3/lznt.c
index 28f654561f279..09db01c1098cd 100644
--- a/fs/ntfs3/lznt.c
+++ b/fs/ntfs3/lznt.c
@@ -236,6 +236,9 @@ static inline ssize_t decompress_chunk(u8 *unc, u8 *unc_end, const u8 *cmpr,
 
 	/* Do decompression until pointers are inside range. */
 	while (up < unc_end && cmpr < cmpr_end) {
+		// return err if more than LZNT_CHUNK_SIZE bytes are written
+		if (up - unc > LZNT_CHUNK_SIZE)
+			return -EINVAL;
 		/* Correct index */
 		while (unc + s_max_off[index] < up)
 			index += 1;
-- 
2.43.0


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

* [PATCH AUTOSEL 6.1 02/10] fs/ntfs3: Fix warning possible deadlock in ntfs_set_state
  2024-10-14  3:58 [PATCH AUTOSEL 6.1 01/10] fs/ntfs3: Check if more than chunk-size bytes are written Sasha Levin
@ 2024-10-14  3:58 ` Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 03/10] fs/ntfs3: Stale inode instead of bad Sasha Levin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2024-10-14  3:58 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Konstantin Komarov, syzbot+c2ada45c23d98d646118, Sasha Levin,
	ntfs3

From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

[ Upstream commit 5b2db723455a89dc96743d34d8bdaa23a402db2f ]

Use non-zero subkey to skip analyzer warnings.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Reported-by: syzbot+c2ada45c23d98d646118@syzkaller.appspotmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ntfs3/ntfs_fs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index a88f6879fcaaa..26dbe1b46fdd1 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -328,7 +328,7 @@ struct mft_inode {
 
 /* Nested class for ntfs_inode::ni_lock. */
 enum ntfs_inode_mutex_lock_class {
-	NTFS_INODE_MUTEX_DIRTY,
+	NTFS_INODE_MUTEX_DIRTY = 1,
 	NTFS_INODE_MUTEX_SECURITY,
 	NTFS_INODE_MUTEX_OBJID,
 	NTFS_INODE_MUTEX_REPARSE,
-- 
2.43.0


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

* [PATCH AUTOSEL 6.1 03/10] fs/ntfs3: Stale inode instead of bad
  2024-10-14  3:58 [PATCH AUTOSEL 6.1 01/10] fs/ntfs3: Check if more than chunk-size bytes are written Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 02/10] fs/ntfs3: Fix warning possible deadlock in ntfs_set_state Sasha Levin
@ 2024-10-14  3:58 ` Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 04/10] fs/ntfs3: Fix possible deadlock in mi_read Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 05/10] fs/ntfs3: Additional check in ni_clear() Sasha Levin
  3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2024-10-14  3:58 UTC (permalink / raw)
  To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3

From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

[ Upstream commit 1fd21919de6de245b63066b8ee3cfba92e36f0e9 ]

Fixed the logic of processing inode with wrong sequence number.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ntfs3/inode.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index 28cbae3954315..026ed43c06704 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -524,11 +524,15 @@ struct inode *ntfs_iget5(struct super_block *sb, const struct MFT_REF *ref,
 	if (inode->i_state & I_NEW)
 		inode = ntfs_read_mft(inode, name, ref);
 	else if (ref->seq != ntfs_i(inode)->mi.mrec->seq) {
-		/* Inode overlaps? */
-		_ntfs_bad_inode(inode);
+		/*
+		 * Sequence number is not expected.
+		 * Looks like inode was reused but caller uses the old reference
+		 */
+		iput(inode);
+		inode = ERR_PTR(-ESTALE);
 	}
 
-	if (IS_ERR(inode) && name)
+	if (IS_ERR(inode))
 		ntfs_set_state(sb->s_fs_info, NTFS_DIRTY_ERROR);
 
 	return inode;
-- 
2.43.0


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

* [PATCH AUTOSEL 6.1 04/10] fs/ntfs3: Fix possible deadlock in mi_read
  2024-10-14  3:58 [PATCH AUTOSEL 6.1 01/10] fs/ntfs3: Check if more than chunk-size bytes are written Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 02/10] fs/ntfs3: Fix warning possible deadlock in ntfs_set_state Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 03/10] fs/ntfs3: Stale inode instead of bad Sasha Levin
@ 2024-10-14  3:58 ` Sasha Levin
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 05/10] fs/ntfs3: Additional check in ni_clear() Sasha Levin
  3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2024-10-14  3:58 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Konstantin Komarov, syzbot+bc7ca0ae4591cb2550f9, Sasha Levin,
	ntfs3

From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

[ Upstream commit 03b097099eef255fbf85ea6a786ae3c91b11f041 ]

Mutex lock with another subclass used in ni_lock_dir().

Reported-by: syzbot+bc7ca0ae4591cb2550f9@syzkaller.appspotmail.com
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ntfs3/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index a9549e73081fb..7cad1bc2b314f 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -79,7 +79,7 @@ static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry,
 		if (err < 0)
 			inode = ERR_PTR(err);
 		else {
-			ni_lock(ni);
+			ni_lock_dir(ni);
 			inode = dir_search_u(dir, uni, NULL);
 			ni_unlock(ni);
 		}
-- 
2.43.0


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

* [PATCH AUTOSEL 6.1 05/10] fs/ntfs3: Additional check in ni_clear()
  2024-10-14  3:58 [PATCH AUTOSEL 6.1 01/10] fs/ntfs3: Check if more than chunk-size bytes are written Sasha Levin
                   ` (2 preceding siblings ...)
  2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 04/10] fs/ntfs3: Fix possible deadlock in mi_read Sasha Levin
@ 2024-10-14  3:58 ` Sasha Levin
  3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2024-10-14  3:58 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Konstantin Komarov, syzbot+3bfd2cc059ab93efcdb4, Sasha Levin,
	ntfs3

From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

[ Upstream commit d178944db36b3369b78a08ba520de109b89bf2a9 ]

Checking of NTFS_FLAGS_LOG_REPLAYING added to prevent access to
uninitialized bitmap during replay process.

Reported-by: syzbot+3bfd2cc059ab93efcdb4@syzkaller.appspotmail.com
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ntfs3/frecord.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index b3299cda59622..44bcc9c7591d9 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -102,7 +102,9 @@ void ni_clear(struct ntfs_inode *ni)
 {
 	struct rb_node *node;
 
-	if (!ni->vfs_inode.i_nlink && ni->mi.mrec && is_rec_inuse(ni->mi.mrec))
+	if (!ni->vfs_inode.i_nlink && ni->mi.mrec &&
+	    is_rec_inuse(ni->mi.mrec) &&
+	    !(ni->mi.sbi->flags & NTFS_FLAGS_LOG_REPLAYING))
 		ni_delete_all(ni);
 
 	al_destroy(ni);
-- 
2.43.0


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

end of thread, other threads:[~2024-10-14  3:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14  3:58 [PATCH AUTOSEL 6.1 01/10] fs/ntfs3: Check if more than chunk-size bytes are written Sasha Levin
2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 02/10] fs/ntfs3: Fix warning possible deadlock in ntfs_set_state Sasha Levin
2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 03/10] fs/ntfs3: Stale inode instead of bad Sasha Levin
2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 04/10] fs/ntfs3: Fix possible deadlock in mi_read Sasha Levin
2024-10-14  3:58 ` [PATCH AUTOSEL 6.1 05/10] fs/ntfs3: Additional check in ni_clear() Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox