* [PATCH AUTOSEL 6.1 02/28] fs/ntfs3: Improve ntfs_dir_count
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 03/28] fs/ntfs3: Correct hard links updating when dealing with DOS names Sasha Levin
` (9 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit 6a799c928b78b14999b7705c4cca0f88e297fe96 ]
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/dir.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index c2fb76bb28f4..72cdfa8727d3 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -515,11 +515,9 @@ static int ntfs_dir_count(struct inode *dir, bool *is_empty, size_t *dirs,
struct INDEX_HDR *hdr;
const struct ATTR_FILE_NAME *fname;
u32 e_size, off, end;
- u64 vbo = 0;
size_t drs = 0, fles = 0, bit = 0;
- loff_t i_size = ni->vfs_inode.i_size;
struct indx_node *node = NULL;
- u8 index_bits = ni->dir.index_bits;
+ size_t max_indx = ni->vfs_inode.i_size >> ni->dir.index_bits;
if (is_empty)
*is_empty = true;
@@ -563,7 +561,7 @@ static int ntfs_dir_count(struct inode *dir, bool *is_empty, size_t *dirs,
fles += 1;
}
- if (vbo >= i_size)
+ if (bit >= max_indx)
goto out;
err = indx_used_bit(&ni->dir, ni, &bit);
@@ -573,8 +571,7 @@ static int ntfs_dir_count(struct inode *dir, bool *is_empty, size_t *dirs,
if (bit == MINUS_ONE_T)
goto out;
- vbo = (u64)bit << index_bits;
- if (vbo >= i_size)
+ if (bit >= max_indx)
goto out;
err = indx_read(&ni->dir, ni, bit << ni->dir.idx2vbn_bits,
@@ -584,7 +581,6 @@ static int ntfs_dir_count(struct inode *dir, bool *is_empty, size_t *dirs,
hdr = &node->index->ihdr;
bit += 1;
- vbo = (u64)bit << ni->dir.idx2vbn_bits;
}
out:
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 03/28] fs/ntfs3: Correct hard links updating when dealing with DOS names
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 02/28] fs/ntfs3: Improve ntfs_dir_count Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 04/28] fs/ntfs3: Print warning while fixing hard links count Sasha Levin
` (8 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit 1918c10e137eae266b8eb0ab1cc14421dcb0e3e2 ]
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/record.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index ba336c7280b8..ab03c373cec6 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -491,8 +491,20 @@ bool mi_remove_attr(struct ntfs_inode *ni, struct mft_inode *mi,
return false;
if (ni && is_attr_indexed(attr)) {
- le16_add_cpu(&ni->mi.mrec->hard_links, -1);
- ni->mi.dirty = true;
+ u16 links = le16_to_cpu(ni->mi.mrec->hard_links);
+ struct ATTR_FILE_NAME *fname =
+ attr->type != ATTR_NAME ?
+ NULL :
+ resident_data_ex(attr,
+ SIZEOF_ATTRIBUTE_FILENAME);
+ if (fname && fname->type == FILE_NAME_DOS) {
+ /* Do not decrease links count deleting DOS name. */
+ } else if (!links) {
+ /* minor error. Not critical. */
+ } else {
+ ni->mi.mrec->hard_links = cpu_to_le16(links - 1);
+ ni->mi.dirty = true;
+ }
}
used -= asize;
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 04/28] fs/ntfs3: Print warning while fixing hard links count
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 02/28] fs/ntfs3: Improve ntfs_dir_count Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 03/28] fs/ntfs3: Correct hard links updating when dealing with DOS names Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 05/28] fs/ntfs3: Fix detected field-spanning write (size 8) of single field "le->name" Sasha Levin
` (7 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit 85ba2a75faee759809a7e43b4c103ac59bac1026 ]
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index dc937089a464..42dd9fdaf415 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -402,7 +402,6 @@ static struct inode *ntfs_read_mft(struct inode *inode,
goto out;
if (!is_match && name) {
- /* Reuse rec as buffer for ascii name. */
err = -ENOENT;
goto out;
}
@@ -417,6 +416,7 @@ static struct inode *ntfs_read_mft(struct inode *inode,
if (names != le16_to_cpu(rec->hard_links)) {
/* Correct minor error on the fly. Do not mark inode as dirty. */
+ ntfs_inode_warn(inode, "Correct links count -> %u.", names);
rec->hard_links = cpu_to_le16(names);
ni->mi.dirty = true;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 05/28] fs/ntfs3: Fix detected field-spanning write (size 8) of single field "le->name"
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (2 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 04/28] fs/ntfs3: Print warning while fixing hard links count Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 06/28] fs/ntfs3: Add NULL ptr dereference checking at the end of attr_allocate_frame() Sasha Levin
` (6 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit d155617006ebc172a80d3eb013c4b867f9a8ada4 ]
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/ntfs.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h
index 0f38d558169a..8b580515b1d6 100644
--- a/fs/ntfs3/ntfs.h
+++ b/fs/ntfs3/ntfs.h
@@ -517,7 +517,7 @@ struct ATTR_LIST_ENTRY {
__le64 vcn; // 0x08: Starting VCN of this attribute.
struct MFT_REF ref; // 0x10: MFT record number with attribute.
__le16 id; // 0x18: struct ATTRIB ID.
- __le16 name[3]; // 0x1A: Just to align. To get real name can use bNameOffset.
+ __le16 name[]; // 0x1A: Just to align. To get real name can use name_off.
}; // sizeof(0x20)
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 06/28] fs/ntfs3: Add NULL ptr dereference checking at the end of attr_allocate_frame()
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (3 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 05/28] fs/ntfs3: Fix detected field-spanning write (size 8) of single field "le->name" Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 07/28] fs/ntfs3: Disable ATTR_LIST_ENTRY size check Sasha Levin
` (5 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit aaab47f204aaf47838241d57bf8662c8840de60a ]
It is preferable to exit through the out: label because
internal debugging functions are located there.
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/attrib.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index 2215179c925b..2618bf5a3789 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -1658,8 +1658,10 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
le_b = NULL;
attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL,
0, NULL, &mi_b);
- if (!attr_b)
- return -ENOENT;
+ if (!attr_b) {
+ err = -ENOENT;
+ goto out;
+ }
attr = attr_b;
le = le_b;
@@ -1740,13 +1742,15 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
ok:
run_truncate_around(run, vcn);
out:
- if (new_valid > data_size)
- new_valid = data_size;
+ if (attr_b) {
+ if (new_valid > data_size)
+ new_valid = data_size;
- valid_size = le64_to_cpu(attr_b->nres.valid_size);
- if (new_valid != valid_size) {
- attr_b->nres.valid_size = cpu_to_le64(valid_size);
- mi_b->dirty = true;
+ valid_size = le64_to_cpu(attr_b->nres.valid_size);
+ if (new_valid != valid_size) {
+ attr_b->nres.valid_size = cpu_to_le64(valid_size);
+ mi_b->dirty = true;
+ }
}
return err;
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 07/28] fs/ntfs3: Disable ATTR_LIST_ENTRY size check
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (4 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 06/28] fs/ntfs3: Add NULL ptr dereference checking at the end of attr_allocate_frame() Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 08/28] fs/ntfs3: use non-movable memory for ntfs3 MFT buffer cache Sasha Levin
` (4 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Konstantin Komarov, kernel test robot, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit 4cdfb6e7bc9c80142d33bf1d4653a73fa678ba56 ]
The use of sizeof(struct ATTR_LIST_ENTRY) has been replaced with le_size(0)
due to alignment peculiarities on different platforms.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312071005.g6YrbaIe-lkp@intel.com/
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/attrlist.c | 8 ++++----
fs/ntfs3/ntfs.h | 2 --
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/fs/ntfs3/attrlist.c b/fs/ntfs3/attrlist.c
index 0c6a68e71e7d..723e49ec83ce 100644
--- a/fs/ntfs3/attrlist.c
+++ b/fs/ntfs3/attrlist.c
@@ -127,12 +127,13 @@ struct ATTR_LIST_ENTRY *al_enumerate(struct ntfs_inode *ni,
{
size_t off;
u16 sz;
+ const unsigned le_min_size = le_size(0);
if (!le) {
le = ni->attr_list.le;
} else {
sz = le16_to_cpu(le->size);
- if (sz < sizeof(struct ATTR_LIST_ENTRY)) {
+ if (sz < le_min_size) {
/* Impossible 'cause we should not return such le. */
return NULL;
}
@@ -141,7 +142,7 @@ struct ATTR_LIST_ENTRY *al_enumerate(struct ntfs_inode *ni,
/* Check boundary. */
off = PtrOffset(ni->attr_list.le, le);
- if (off + sizeof(struct ATTR_LIST_ENTRY) > ni->attr_list.size) {
+ if (off + le_min_size > ni->attr_list.size) {
/* The regular end of list. */
return NULL;
}
@@ -149,8 +150,7 @@ struct ATTR_LIST_ENTRY *al_enumerate(struct ntfs_inode *ni,
sz = le16_to_cpu(le->size);
/* Check le for errors. */
- if (sz < sizeof(struct ATTR_LIST_ENTRY) ||
- off + sz > ni->attr_list.size ||
+ if (sz < le_min_size || off + sz > ni->attr_list.size ||
sz < le->name_off + le->name_len * sizeof(short)) {
return NULL;
}
diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h
index 8b580515b1d6..ba26a465b309 100644
--- a/fs/ntfs3/ntfs.h
+++ b/fs/ntfs3/ntfs.h
@@ -521,8 +521,6 @@ struct ATTR_LIST_ENTRY {
}; // sizeof(0x20)
-static_assert(sizeof(struct ATTR_LIST_ENTRY) == 0x20);
-
static inline u32 le_size(u8 name_len)
{
return ALIGN(offsetof(struct ATTR_LIST_ENTRY, name) +
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 08/28] fs/ntfs3: use non-movable memory for ntfs3 MFT buffer cache
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (5 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 07/28] fs/ntfs3: Disable ATTR_LIST_ENTRY size check Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 09/28] fs/ntfs3: Prevent generic message "attempt to access beyond end of device" Sasha Levin
` (3 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Ism Hong, Konstantin Komarov, Sasha Levin, ntfs3
From: Ism Hong <ism.hong@gmail.com>
[ Upstream commit d6d33f03baa43d763fe094ca926eeae7d3421d07 ]
Since the buffer cache for ntfs3 metadata is not released until the file
system is unmounted, allocating from the movable zone may result in cma
allocation failures. This is due to the page still being used by ntfs3,
leading to migration failures.
To address this, this commit use sb_bread_umovable() instead of
sb_bread(). This change prevents allocation from the movable zone,
ensuring compatibility with scenarios where the buffer head is not
released until unmount. This patch is inspired by commit
a8ac900b8163("ext4: use non-movable memory for the ext4 superblock").
The issue is found when playing video files stored in NTFS on the
Android TV platform. During this process, the media parser reads the
video file, causing ntfs3 to allocate buffer cache from the CMA area.
Subsequently, the hardware decoder attempts to allocate memory from the
same CMA area. However, the page is still in use by ntfs3, resulting in
a migrate failure in alloc_contig_range().
The pinned page and allocating stacktrace reported by page owner shows
below:
page:ffffffff00b68880 refcount:3 mapcount:0 mapping:ffffff80046aa828
index:0xc0040 pfn:0x20fa4
aops:def_blk_aops ino:0
flags: 0x2020(active|private)
page dumped because: migration failure
page last allocated via order 0, migratetype Movable,
gfp_mask 0x108c48
(GFP_NOFS|__GFP_NOFAIL|__GFP_HARDWALL|__GFP_MOVABLE),
page_owner tracks the page as allocated
prep_new_page
get_page_from_freelist
__alloc_pages_nodemask
pagecache_get_page
__getblk_gfp
__bread_gfp
ntfs_read_run_nb
ntfs_read_bh
mi_read
ntfs_iget5
dir_search_u
ntfs_lookup
__lookup_slow
lookup_slow
walk_component
path_lookupat
Signed-off-by: Ism Hong <ism.hong@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.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 8c9abaf139e6..977e1422f904 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -1015,7 +1015,7 @@ static inline u64 bytes_to_block(const struct super_block *sb, u64 size)
static inline struct buffer_head *ntfs_bread(struct super_block *sb,
sector_t block)
{
- struct buffer_head *bh = sb_bread(sb, block);
+ struct buffer_head *bh = sb_bread_unmovable(sb, block);
if (bh)
return bh;
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 09/28] fs/ntfs3: Prevent generic message "attempt to access beyond end of device"
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (6 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 08/28] fs/ntfs3: use non-movable memory for ntfs3 MFT buffer cache Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-18 18:00 ` Pavel Machek
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 10/28] fs/ntfs3: Correct function is_rst_area_valid Sasha Levin
` (2 subsequent siblings)
10 siblings, 1 reply; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit 5ca87d01eba7bdfe9536a157ca33c1455bb8d16c ]
It used in test environment.
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/fsntfs.c | 24 ++++++++++++++++++++++++
fs/ntfs3/ntfs_fs.h | 14 +-------------
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c
index 873b1434a998..34813429e2ab 100644
--- a/fs/ntfs3/fsntfs.c
+++ b/fs/ntfs3/fsntfs.c
@@ -976,6 +976,30 @@ static inline __le32 security_hash(const void *sd, size_t bytes)
return cpu_to_le32(hash);
}
+/*
+ * simple wrapper for sb_bread_unmovable.
+ */
+struct buffer_head *ntfs_bread(struct super_block *sb, sector_t block)
+{
+ struct ntfs_sb_info *sbi = sb->s_fs_info;
+ struct buffer_head *bh;
+
+ if (unlikely(block >= sbi->volume.blocks)) {
+ /* prevent generic message "attempt to access beyond end of device" */
+ ntfs_err(sb, "try to read out of volume at offset 0x%llx",
+ (u64)block << sb->s_blocksize_bits);
+ return NULL;
+ }
+
+ bh = sb_bread_unmovable(sb, block);
+ if (bh)
+ return bh;
+
+ ntfs_err(sb, "failed to read volume at offset 0x%llx",
+ (u64)block << sb->s_blocksize_bits);
+ return NULL;
+}
+
int ntfs_sb_read(struct super_block *sb, u64 lbo, size_t bytes, void *buffer)
{
struct block_device *bdev = sb->s_bdev;
diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index 977e1422f904..cbeda94d7161 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -580,6 +580,7 @@ bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes);
int log_replay(struct ntfs_inode *ni, bool *initialized);
/* Globals from fsntfs.c */
+struct buffer_head *ntfs_bread(struct super_block *sb, sector_t block);
bool ntfs_fix_pre_write(struct NTFS_RECORD_HEADER *rhdr, size_t bytes);
int ntfs_fix_post_read(struct NTFS_RECORD_HEADER *rhdr, size_t bytes,
bool simple);
@@ -1012,19 +1013,6 @@ static inline u64 bytes_to_block(const struct super_block *sb, u64 size)
return (size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
}
-static inline struct buffer_head *ntfs_bread(struct super_block *sb,
- sector_t block)
-{
- struct buffer_head *bh = sb_bread_unmovable(sb, block);
-
- if (bh)
- return bh;
-
- ntfs_err(sb, "failed to read volume at offset 0x%llx",
- (u64)block << sb->s_blocksize_bits);
- return NULL;
-}
-
static inline struct ntfs_inode *ntfs_i(struct inode *inode)
{
return container_of(inode, struct ntfs_inode, vfs_inode);
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH AUTOSEL 6.1 09/28] fs/ntfs3: Prevent generic message "attempt to access beyond end of device"
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 09/28] fs/ntfs3: Prevent generic message "attempt to access beyond end of device" Sasha Levin
@ 2024-02-18 18:00 ` Pavel Machek
2024-02-18 18:06 ` Greg KH
0 siblings, 1 reply; 14+ messages in thread
From: Pavel Machek @ 2024-02-18 18:00 UTC (permalink / raw)
To: Sasha Levin; +Cc: linux-kernel, stable, Konstantin Komarov, ntfs3
[-- Attachment #1: Type: text/plain, Size: 2743 bytes --]
Hi!
> From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
>
> [ Upstream commit 5ca87d01eba7bdfe9536a157ca33c1455bb8d16c ]
>
> It used in test environment.
This seems to just replace one printk with another; not sure we want
it in stable.
Best regards,
Pavel
> diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c
> index 873b1434a998..34813429e2ab 100644
> --- a/fs/ntfs3/fsntfs.c
> +++ b/fs/ntfs3/fsntfs.c
> @@ -976,6 +976,30 @@ static inline __le32 security_hash(const void *sd, size_t bytes)
> return cpu_to_le32(hash);
> }
>
> +/*
> + * simple wrapper for sb_bread_unmovable.
> + */
> +struct buffer_head *ntfs_bread(struct super_block *sb, sector_t block)
> +{
> + struct ntfs_sb_info *sbi = sb->s_fs_info;
> + struct buffer_head *bh;
> +
> + if (unlikely(block >= sbi->volume.blocks)) {
> + /* prevent generic message "attempt to access beyond end of device" */
> + ntfs_err(sb, "try to read out of volume at offset 0x%llx",
> + (u64)block << sb->s_blocksize_bits);
> + return NULL;
> + }
> +
> + bh = sb_bread_unmovable(sb, block);
> + if (bh)
> + return bh;
> +
> + ntfs_err(sb, "failed to read volume at offset 0x%llx",
> + (u64)block << sb->s_blocksize_bits);
> + return NULL;
> +}
> +
> int ntfs_sb_read(struct super_block *sb, u64 lbo, size_t bytes, void *buffer)
> {
> struct block_device *bdev = sb->s_bdev;
> diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
> index 977e1422f904..cbeda94d7161 100644
> --- a/fs/ntfs3/ntfs_fs.h
> +++ b/fs/ntfs3/ntfs_fs.h
> @@ -580,6 +580,7 @@ bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes);
> int log_replay(struct ntfs_inode *ni, bool *initialized);
>
> /* Globals from fsntfs.c */
> +struct buffer_head *ntfs_bread(struct super_block *sb, sector_t block);
> bool ntfs_fix_pre_write(struct NTFS_RECORD_HEADER *rhdr, size_t bytes);
> int ntfs_fix_post_read(struct NTFS_RECORD_HEADER *rhdr, size_t bytes,
> bool simple);
> @@ -1012,19 +1013,6 @@ static inline u64 bytes_to_block(const struct super_block *sb, u64 size)
> return (size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
> }
>
> -static inline struct buffer_head *ntfs_bread(struct super_block *sb,
> - sector_t block)
> -{
> - struct buffer_head *bh = sb_bread_unmovable(sb, block);
> -
> - if (bh)
> - return bh;
> -
> - ntfs_err(sb, "failed to read volume at offset 0x%llx",
> - (u64)block << sb->s_blocksize_bits);
> - return NULL;
> -}
> -
> static inline struct ntfs_inode *ntfs_i(struct inode *inode)
> {
> return container_of(inode, struct ntfs_inode, vfs_inode);
--
People of Russia, stop Putin before his war on Ukraine escalates.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH AUTOSEL 6.1 09/28] fs/ntfs3: Prevent generic message "attempt to access beyond end of device"
2024-02-18 18:00 ` Pavel Machek
@ 2024-02-18 18:06 ` Greg KH
0 siblings, 0 replies; 14+ messages in thread
From: Greg KH @ 2024-02-18 18:06 UTC (permalink / raw)
To: Pavel Machek; +Cc: Sasha Levin, linux-kernel, stable, Konstantin Komarov, ntfs3
On Sun, Feb 18, 2024 at 07:00:10PM +0100, Pavel Machek wrote:
> Hi!
>
> > From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
> >
> > [ Upstream commit 5ca87d01eba7bdfe9536a157ca33c1455bb8d16c ]
> >
> > It used in test environment.
>
> This seems to just replace one printk with another; not sure we want
> it in stable.
It provides a better clue as to what the error is, I think it is a valid
change.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH AUTOSEL 6.1 10/28] fs/ntfs3: Correct function is_rst_area_valid
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (7 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 09/28] fs/ntfs3: Prevent generic message "attempt to access beyond end of device" Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 11/28] fs/ntfs3: Update inode->i_size after success write into compressed file Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 12/28] fs/ntfs3: Fix oob in ntfs_listxattr Sasha Levin
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Konstantin Komarov, Robert Morris, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit 1b7dd28e14c4728ae1a815605ca33ffb4ce1b309 ]
Reported-by: Robert Morris <rtm@csail.mit.edu>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/fslog.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index 710cb5aa5a65..d53ef128fa73 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -465,7 +465,7 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr)
{
const struct RESTART_AREA *ra;
u16 cl, fl, ul;
- u32 off, l_size, file_dat_bits, file_size_round;
+ u32 off, l_size, seq_bits;
u16 ro = le16_to_cpu(rhdr->ra_off);
u32 sys_page = le32_to_cpu(rhdr->sys_page_size);
@@ -511,13 +511,15 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr)
/* Make sure the sequence number bits match the log file size. */
l_size = le64_to_cpu(ra->l_size);
- file_dat_bits = sizeof(u64) * 8 - le32_to_cpu(ra->seq_num_bits);
- file_size_round = 1u << (file_dat_bits + 3);
- if (file_size_round != l_size &&
- (file_size_round < l_size || (file_size_round / 2) > l_size)) {
- return false;
+ seq_bits = sizeof(u64) * 8 + 3;
+ while (l_size) {
+ l_size >>= 1;
+ seq_bits -= 1;
}
+ if (seq_bits != ra->seq_num_bits)
+ return false;
+
/* The log page data offset and record header length must be quad-aligned. */
if (!IS_ALIGNED(le16_to_cpu(ra->data_off), 8) ||
!IS_ALIGNED(le16_to_cpu(ra->rec_hdr_len), 8))
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 11/28] fs/ntfs3: Update inode->i_size after success write into compressed file
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (8 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 10/28] fs/ntfs3: Correct function is_rst_area_valid Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 12/28] fs/ntfs3: Fix oob in ntfs_listxattr Sasha Levin
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Konstantin Komarov, Giovanni Santini, Sasha Levin, ntfs3
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
[ Upstream commit d68968440b1a75dee05cfac7f368f1aa139e1911 ]
Reported-by: Giovanni Santini <giovannisantini93@yahoo.it>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/file.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index f31c0389a2e7..14efe46df91e 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -1110,6 +1110,8 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
iocb->ki_pos += written;
if (iocb->ki_pos > ni->i_valid)
ni->i_valid = iocb->ki_pos;
+ if (iocb->ki_pos > i_size)
+ i_size_write(inode, iocb->ki_pos);
return written;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH AUTOSEL 6.1 12/28] fs/ntfs3: Fix oob in ntfs_listxattr
2024-02-13 0:21 [PATCH AUTOSEL 6.1 01/28] fs/ntfs3: Modified fix directory element type detection Sasha Levin
` (9 preceding siblings ...)
2024-02-13 0:22 ` [PATCH AUTOSEL 6.1 11/28] fs/ntfs3: Update inode->i_size after success write into compressed file Sasha Levin
@ 2024-02-13 0:22 ` Sasha Levin
10 siblings, 0 replies; 14+ messages in thread
From: Sasha Levin @ 2024-02-13 0:22 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Edward Adam Davis, syzbot+65e940cfb8f99a97aca7,
Konstantin Komarov, Sasha Levin, ntfs3
From: Edward Adam Davis <eadavis@qq.com>
[ Upstream commit 731ab1f9828800df871c5a7ab9ffe965317d3f15 ]
The length of name cannot exceed the space occupied by ea.
Reported-and-tested-by: syzbot+65e940cfb8f99a97aca7@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ntfs3/xattr.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c
index df15e00c2a3a..d98cf7b382bc 100644
--- a/fs/ntfs3/xattr.c
+++ b/fs/ntfs3/xattr.c
@@ -217,6 +217,9 @@ static ssize_t ntfs_list_ea(struct ntfs_inode *ni, char *buffer,
if (!ea->name_len)
break;
+ if (ea->name_len > ea_size)
+ break;
+
if (buffer) {
/* Check if we can use field ea->name */
if (off + ea_size > size)
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread