* [PATCH 0/6] Syzbot bugfixes and refactoring
@ 2024-10-01 9:00 Konstantin Komarov
2024-10-01 9:00 ` [PATCH 1/6] fs/ntfs3: Fix possible deadlock in mi_read Konstantin Komarov
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Konstantin Komarov @ 2024-10-01 9:00 UTC (permalink / raw)
To: ntfs3; +Cc: linux-kernel, linux-fsdevel, Konstantin Komarov
Mostly fixes of problems that syzbot shows.
Konstantin Komarov (6):
fs/ntfs3: Fix possible deadlock in mi_read
fs/ntfs3: Additional check in ni_clear()
fs/ntfs3: Sequential field availability check in mi_enum_attr()
fs/ntfs3: Fix general protection fault in run_is_mapped_full
fs/ntfs3: Additional check in ntfs_file_release
fs/ntfs3: Format output messages like others fs in kernel
fs/ntfs3/file.c | 9 ++++++++-
fs/ntfs3/frecord.c | 4 +++-
fs/ntfs3/inode.c | 5 ++++-
fs/ntfs3/namei.c | 2 +-
fs/ntfs3/record.c | 15 +++++++--------
fs/ntfs3/super.c | 13 +++++++++----
6 files changed, 32 insertions(+), 16 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/6] fs/ntfs3: Fix possible deadlock in mi_read
2024-10-01 9:00 [PATCH 0/6] Syzbot bugfixes and refactoring Konstantin Komarov
@ 2024-10-01 9:00 ` Konstantin Komarov
2024-10-01 9:01 ` [PATCH 2/6] fs/ntfs3: Additional check in ni_clear() Konstantin Komarov
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Konstantin Komarov @ 2024-10-01 9:00 UTC (permalink / raw)
To: ntfs3
Cc: linux-kernel, linux-fsdevel, Konstantin Komarov,
syzbot+bc7ca0ae4591cb2550f9
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>
---
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 4c35262449d7..abf7e81584a9 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -81,7 +81,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.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] fs/ntfs3: Additional check in ni_clear()
2024-10-01 9:00 [PATCH 0/6] Syzbot bugfixes and refactoring Konstantin Komarov
2024-10-01 9:00 ` [PATCH 1/6] fs/ntfs3: Fix possible deadlock in mi_read Konstantin Komarov
@ 2024-10-01 9:01 ` Konstantin Komarov
2024-10-01 9:01 ` [PATCH 3/6] fs/ntfs3: Sequential field availability check in mi_enum_attr() Konstantin Komarov
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Konstantin Komarov @ 2024-10-01 9:01 UTC (permalink / raw)
To: ntfs3
Cc: linux-kernel, linux-fsdevel, Konstantin Komarov,
syzbot+3bfd2cc059ab93efcdb4
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>
---
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 7d4e54161291..41c7ffad2790 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.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] fs/ntfs3: Sequential field availability check in mi_enum_attr()
2024-10-01 9:00 [PATCH 0/6] Syzbot bugfixes and refactoring Konstantin Komarov
2024-10-01 9:00 ` [PATCH 1/6] fs/ntfs3: Fix possible deadlock in mi_read Konstantin Komarov
2024-10-01 9:01 ` [PATCH 2/6] fs/ntfs3: Additional check in ni_clear() Konstantin Komarov
@ 2024-10-01 9:01 ` Konstantin Komarov
2024-10-10 11:00 ` lei lu
2024-10-01 9:01 ` [PATCH 4/6] fs/ntfs3: Fix general protection fault in run_is_mapped_full Konstantin Komarov
` (2 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Konstantin Komarov @ 2024-10-01 9:01 UTC (permalink / raw)
To: ntfs3; +Cc: linux-kernel, linux-fsdevel, Konstantin Komarov
The code is slightly reformatted to consistently check field availability
without duplication.
Fixes: 556bdf27c2dd ("ntfs3: Add bounds checking to mi_enum_attr()")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
fs/ntfs3/record.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 427c71be0f08..f810f0419d25 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -237,6 +237,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
}
/* Can we use the first field (attr->type). */
+ /* NOTE: this code also checks attr->size availability. */
if (off + 8 > used) {
static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8);
return NULL;
@@ -257,10 +258,6 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
return NULL;
asize = le32_to_cpu(attr->size);
- if (asize < SIZEOF_RESIDENT) {
- /* Impossible 'cause we should not return such attribute. */
- return NULL;
- }
/* Check overflow and boundary. */
if (off + asize < off || off + asize > used)
@@ -290,6 +287,10 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
if (attr->non_res != 1)
return NULL;
+ /* Can we use memory including attr->nres.valid_size? */
+ if (asize < SIZEOF_NONRESIDENT)
+ return NULL;
+
t16 = le16_to_cpu(attr->nres.run_off);
if (t16 > asize)
return NULL;
@@ -316,7 +317,8 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
if (!attr->nres.svcn && is_attr_ext(attr)) {
/* First segment of sparse/compressed attribute */
- if (asize + 8 < SIZEOF_NONRESIDENT_EX)
+ /* Can we use memory including attr->nres.total_size? */
+ if (asize < SIZEOF_NONRESIDENT_EX)
return NULL;
tot_size = le64_to_cpu(attr->nres.total_size);
@@ -326,9 +328,6 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
if (tot_size > alloc_size)
return NULL;
} else {
- if (asize + 8 < SIZEOF_NONRESIDENT)
- return NULL;
-
if (attr->nres.c_unit)
return NULL;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] fs/ntfs3: Fix general protection fault in run_is_mapped_full
2024-10-01 9:00 [PATCH 0/6] Syzbot bugfixes and refactoring Konstantin Komarov
` (2 preceding siblings ...)
2024-10-01 9:01 ` [PATCH 3/6] fs/ntfs3: Sequential field availability check in mi_enum_attr() Konstantin Komarov
@ 2024-10-01 9:01 ` Konstantin Komarov
2024-10-01 9:01 ` [PATCH 5/6] fs/ntfs3: Additional check in ntfs_file_release Konstantin Komarov
2024-10-01 9:01 ` [PATCH 6/6] fs/ntfs3: Format output messages like others fs in kernel Konstantin Komarov
5 siblings, 0 replies; 8+ messages in thread
From: Konstantin Komarov @ 2024-10-01 9:01 UTC (permalink / raw)
To: ntfs3
Cc: linux-kernel, linux-fsdevel, Konstantin Komarov,
syzbot+9af29acd8f27fbce94bc
Fixed deleating of a non-resident attribute in ntfs_create_inode()
rollback.
Reported-by: syzbot+9af29acd8f27fbce94bc@syzkaller.appspotmail.com
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
fs/ntfs3/inode.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index 81746a959b47..5dc261404957 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -1718,7 +1718,10 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
attr = ni_find_attr(ni, NULL, NULL, ATTR_EA, NULL, 0, NULL, NULL);
if (attr && attr->non_res) {
/* Delete ATTR_EA, if non-resident. */
- attr_set_size(ni, ATTR_EA, NULL, 0, NULL, 0, NULL, false, NULL);
+ struct runs_tree run;
+ run_init(&run);
+ attr_set_size(ni, ATTR_EA, NULL, 0, &run, 0, NULL, false, NULL);
+ run_close(&run);
}
if (rp_inserted)
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] fs/ntfs3: Additional check in ntfs_file_release
2024-10-01 9:00 [PATCH 0/6] Syzbot bugfixes and refactoring Konstantin Komarov
` (3 preceding siblings ...)
2024-10-01 9:01 ` [PATCH 4/6] fs/ntfs3: Fix general protection fault in run_is_mapped_full Konstantin Komarov
@ 2024-10-01 9:01 ` Konstantin Komarov
2024-10-01 9:01 ` [PATCH 6/6] fs/ntfs3: Format output messages like others fs in kernel Konstantin Komarov
5 siblings, 0 replies; 8+ messages in thread
From: Konstantin Komarov @ 2024-10-01 9:01 UTC (permalink / raw)
To: ntfs3
Cc: linux-kernel, linux-fsdevel, Konstantin Komarov,
syzbot+8c652f14a0fde76ff11d
Reported-by: syzbot+8c652f14a0fde76ff11d@syzkaller.appspotmail.com
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
fs/ntfs3/file.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index 4fdcb5177ea1..eb935d4180c0 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -1314,7 +1314,14 @@ static int ntfs_file_release(struct inode *inode, struct file *file)
/* If we are last writer on the inode, drop the block reservation. */
if (sbi->options->prealloc &&
((file->f_mode & FMODE_WRITE) &&
- atomic_read(&inode->i_writecount) == 1)) {
+ atomic_read(&inode->i_writecount) == 1)
+ /*
+ * The only file when inode->i_fop = &ntfs_file_operations and
+ * init_rwsem(&ni->file.run_lock) is not called explicitly is MFT.
+ *
+ * Add additional check here.
+ */
+ && inode->i_ino != MFT_REC_MFT) {
ni_lock(ni);
down_write(&ni->file.run_lock);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] fs/ntfs3: Format output messages like others fs in kernel
2024-10-01 9:00 [PATCH 0/6] Syzbot bugfixes and refactoring Konstantin Komarov
` (4 preceding siblings ...)
2024-10-01 9:01 ` [PATCH 5/6] fs/ntfs3: Additional check in ntfs_file_release Konstantin Komarov
@ 2024-10-01 9:01 ` Konstantin Komarov
5 siblings, 0 replies; 8+ messages in thread
From: Konstantin Komarov @ 2024-10-01 9:01 UTC (permalink / raw)
To: ntfs3; +Cc: linux-kernel, linux-fsdevel, Konstantin Komarov
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
fs/ntfs3/super.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 128d49512f5d..6a0f6b0a3ab2 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -90,7 +90,7 @@ void ntfs_printk(const struct super_block *sb, const char *fmt, ...)
level = printk_get_level(fmt);
vaf.fmt = printk_skip_level(fmt);
vaf.va = &args;
- printk("%c%cntfs3: %s: %pV\n", KERN_SOH_ASCII, level, sb->s_id, &vaf);
+ printk("%c%cntfs3(%s): %pV\n", KERN_SOH_ASCII, level, sb->s_id, &vaf);
va_end(args);
}
@@ -124,10 +124,15 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)
struct dentry *de = d_find_alias(inode);
if (de) {
+ int len;
spin_lock(&de->d_lock);
- snprintf(name, sizeof(s_name_buf), " \"%s\"",
- de->d_name.name);
+ len = snprintf(name, sizeof(s_name_buf), " \"%s\"",
+ de->d_name.name);
spin_unlock(&de->d_lock);
+ if (len <= 0)
+ name[0] = 0;
+ else if (len >= sizeof(s_name_buf))
+ name[sizeof(s_name_buf) - 1] = 0;
} else {
name[0] = 0;
}
@@ -140,7 +145,7 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)
vaf.fmt = printk_skip_level(fmt);
vaf.va = &args;
- printk("%c%cntfs3: %s: ino=%lx,%s %pV\n", KERN_SOH_ASCII, level,
+ printk("%c%cntfs3(%s): ino=%lx,%s %pV\n", KERN_SOH_ASCII, level,
sb->s_id, inode->i_ino, name ? name : "", &vaf);
va_end(args);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/6] fs/ntfs3: Sequential field availability check in mi_enum_attr()
2024-10-01 9:01 ` [PATCH 3/6] fs/ntfs3: Sequential field availability check in mi_enum_attr() Konstantin Komarov
@ 2024-10-10 11:00 ` lei lu
0 siblings, 0 replies; 8+ messages in thread
From: lei lu @ 2024-10-10 11:00 UTC (permalink / raw)
To: almaz.alexandrovich; +Cc: linux-fsdevel, linux-kernel, ntfs3
Hi, Konstantin,
Refer to: https://lore.kernel.org/ntfs3/20240820105342.79788-1-llfamsec@gmail.com/T/#t.
In https://github.com/Paragon-Software-Group/linux-ntfs3/blob/master/fs/ntfs3/record.c#L267.
The code did not check the 'non_res' field. If asize is just 8 bytes, it still trigger OOB.
So I added "if (asize < SIZEOF_RESIDENT)" before accessing the 'non_res'. Because
SIZEOF_RESIDENT is smaller than SIZEOF_NONRESIDENT which seems to be the minimum size of
attr. Or maybe we can use "if (off + 9 > used)" directly.
Thanks,
LL
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-10-10 11:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-01 9:00 [PATCH 0/6] Syzbot bugfixes and refactoring Konstantin Komarov
2024-10-01 9:00 ` [PATCH 1/6] fs/ntfs3: Fix possible deadlock in mi_read Konstantin Komarov
2024-10-01 9:01 ` [PATCH 2/6] fs/ntfs3: Additional check in ni_clear() Konstantin Komarov
2024-10-01 9:01 ` [PATCH 3/6] fs/ntfs3: Sequential field availability check in mi_enum_attr() Konstantin Komarov
2024-10-10 11:00 ` lei lu
2024-10-01 9:01 ` [PATCH 4/6] fs/ntfs3: Fix general protection fault in run_is_mapped_full Konstantin Komarov
2024-10-01 9:01 ` [PATCH 5/6] fs/ntfs3: Additional check in ntfs_file_release Konstantin Komarov
2024-10-01 9:01 ` [PATCH 6/6] fs/ntfs3: Format output messages like others fs in kernel Konstantin Komarov
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).