From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>,
Theodore Ts'o <tytso@mit.edu>, Sasha Levin <sashal@kernel.org>,
adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 07/26] ext4: ext4_search_dir should return a proper error
Date: Fri, 4 Oct 2024 14:29:33 -0400 [thread overview]
Message-ID: <20241004183005.3675332-7-sashal@kernel.org> (raw)
In-Reply-To: <20241004183005.3675332-1-sashal@kernel.org>
From: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
[ Upstream commit cd69f8f9de280e331c9e6ff689ced0a688a9ce8f ]
ext4_search_dir currently returns -1 in case of a failure, while it returns
0 when the name is not found. In such failure cases, it should return an
error code instead.
This becomes even more important when ext4_find_inline_entry returns an
error code as well in the next commit.
-EFSCORRUPTED seems appropriate as such error code as these failures would
be caused by unexpected record lengths and is in line with other instances
of ext4_check_dir_entry failures.
In the case of ext4_dx_find_entry, the current use of ERR_BAD_DX_DIR was
left as is to reduce the risk of regressions.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Link: https://patch.msgid.link/20240821152324.3621860-2-cascardo@igalia.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ext4/namei.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index bf312f94c3bf7..39630c8cb8d38 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1427,7 +1427,7 @@ static inline bool ext4_match(const struct inode *parent,
}
/*
- * Returns 0 if not found, -1 on failure, and 1 on success
+ * Returns 0 if not found, -EFSCORRUPTED on failure, and 1 on success
*/
int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size,
struct inode *dir, struct ext4_filename *fname,
@@ -1448,7 +1448,7 @@ int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size,
* a full check */
if (ext4_check_dir_entry(dir, NULL, de, bh, search_buf,
buf_size, offset))
- return -1;
+ return -EFSCORRUPTED;
*res_dir = de;
return 1;
}
@@ -1456,7 +1456,7 @@ int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size,
de_len = ext4_rec_len_from_disk(de->rec_len,
dir->i_sb->s_blocksize);
if (de_len <= 0)
- return -1;
+ return -EFSCORRUPTED;
offset += de_len;
de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
}
@@ -1608,8 +1608,10 @@ static struct buffer_head *__ext4_find_entry(struct inode *dir,
goto cleanup_and_exit;
} else {
brelse(bh);
- if (i < 0)
+ if (i < 0) {
+ ret = ERR_PTR(i);
goto cleanup_and_exit;
+ }
}
next:
if (++block >= nblocks)
@@ -1703,7 +1705,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
if (retval == 1)
goto success;
brelse(bh);
- if (retval == -1) {
+ if (retval < 0) {
bh = ERR_PTR(ERR_BAD_DX_DIR);
goto errout;
}
--
2.43.0
next prev parent reply other threads:[~2024-10-04 18:30 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-04 18:29 [PATCH AUTOSEL 5.10 01/26] bpf: Check percpu map value size first Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 02/26] s390/boot: Compile all files with the same march flag Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 03/26] s390/facility: Disable compile time optimization for decompressor code Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 04/26] s390/mm: Add cond_resched() to cmm_alloc/free_pages() Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 05/26] ext4: fix i_data_sem unlock order in ext4_ind_migrate() Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 06/26] ext4: avoid use-after-free in ext4_ext_show_leaf() Sasha Levin
2024-10-04 18:29 ` Sasha Levin [this message]
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 08/26] ext4: nested locking for xattr inode Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 09/26] s390/cpum_sf: Remove WARN_ON_ONCE statements Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 10/26] ktest.pl: Avoid false positives with grub2 skip regex Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 11/26] RDMA/mad: Improve handling of timed out WRs of mad agent Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 12/26] PCI: Add function 0 DMA alias quirk for Glenfly Arise chip Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 13/26] clk: bcm: bcm53573: fix OF node leak in init Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 14/26] PCI: Add ACS quirk for Qualcomm SA8775P Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 15/26] i2c: i801: Use a different adapter-name for IDF adapters Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 16/26] PCI: Mark Creative Labs EMU20k2 INTx masking as broken Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 17/26] ntb: ntb_hw_switchtec: Fix use after free vulnerability in switchtec_ntb_remove due to race condition Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 18/26] media: videobuf2-core: clear memory related fields in __vb2_plane_dmabuf_put() Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 19/26] clk: imx: Remove CLK_SET_PARENT_GATE for DRAM mux for i.MX7D Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 20/26] usb: chipidea: udc: enable suspend interrupt after usb reset Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 21/26] usb: dwc2: Adjust the timing of USB Driver Interrupt Registration in the Crashkernel Scenario Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 22/26] virtio_pmem: Check device status before requesting flush Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 23/26] tools/iio: Add memory allocation failure check for trigger_name Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 24/26] driver core: bus: Return -EIO instead of 0 when show/store invalid bus attribute Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 25/26] drm/amd/display: Check null pointer before dereferencing se Sasha Levin
2024-10-04 18:29 ` [PATCH AUTOSEL 5.10 26/26] fbdev: sisfb: Fix strbuf array overflow Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241004183005.3675332-7-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=cascardo@igalia.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox