* [U-Boot] [PATCH] fs: ext4: Prevent infinite loop in ext4fs_iterate_dir
@ 2015-11-18 17:42 Thomas Fitzsimmons
2015-11-23 7:06 ` Stefan Roese
2015-11-23 22:44 ` [U-Boot] " Tom Rini
0 siblings, 2 replies; 3+ messages in thread
From: Thomas Fitzsimmons @ 2015-11-18 17:42 UTC (permalink / raw)
To: u-boot
If the ext3 journal gets out of sync with what is written on disk, for
example because of an unexpected power cut, ext4fs_read_file can
return an all-zero directory entry. In that case, ext4fs_iterate_dir
would infinite loop.
This patch detects when a directory entry's direntlen member is 0 and
returns a failure status, which breaks out of the infinite loop. As a
result, U-Boot will not find files that may subsequently be recovered
when the journal is replayed.
This is better behaviour than hanging in an infinite loop, but as a
further improvement maybe U-Boot could interpret the ext3 journal and
actually find the unsynced entries.
Signed-off-by: Thomas Fitzsimmons <fitzsim@cisco.com>
---
fs/ext4/ext4_common.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 727a2f7..e73223a 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -1920,6 +1920,11 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
if (status < 0)
return 0;
+ if (dirent.direntlen == 0) {
+ printf("Failed to iterate over directory %s\n", name);
+ return 0;
+ }
+
if (dirent.namelen != 0) {
char filename[dirent.namelen + 1];
struct ext2fs_node *fdiro;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] fs: ext4: Prevent infinite loop in ext4fs_iterate_dir
2015-11-18 17:42 [U-Boot] [PATCH] fs: ext4: Prevent infinite loop in ext4fs_iterate_dir Thomas Fitzsimmons
@ 2015-11-23 7:06 ` Stefan Roese
2015-11-23 22:44 ` [U-Boot] " Tom Rini
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2015-11-23 7:06 UTC (permalink / raw)
To: u-boot
Hi Thomas,
On 18.11.2015 18:42, Thomas Fitzsimmons wrote:
> If the ext3 journal gets out of sync with what is written on disk, for
> example because of an unexpected power cut, ext4fs_read_file can
> return an all-zero directory entry. In that case, ext4fs_iterate_dir
> would infinite loop.
>
> This patch detects when a directory entry's direntlen member is 0 and
> returns a failure status, which breaks out of the infinite loop. As a
> result, U-Boot will not find files that may subsequently be recovered
> when the journal is replayed.
>
> This is better behaviour than hanging in an infinite loop, but as a
> further improvement maybe U-Boot could interpret the ext3 journal and
> actually find the unsynced entries.
>
> Signed-off-by: Thomas Fitzsimmons <fitzsim@cisco.com>
> ---
> fs/ext4/ext4_common.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
> index 727a2f7..e73223a 100644
> --- a/fs/ext4/ext4_common.c
> +++ b/fs/ext4/ext4_common.c
> @@ -1920,6 +1920,11 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
> if (status < 0)
> return 0;
>
> + if (dirent.direntlen == 0) {
> + printf("Failed to iterate over directory %s\n", name);
> + return 0;
> + }
> +
> if (dirent.namelen != 0) {
> char filename[dirent.namelen + 1];
> struct ext2fs_node *fdiro;
>
Reviewed-by: Stefan Roese <sr@denx.de>
Thanks,
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] fs: ext4: Prevent infinite loop in ext4fs_iterate_dir
2015-11-18 17:42 [U-Boot] [PATCH] fs: ext4: Prevent infinite loop in ext4fs_iterate_dir Thomas Fitzsimmons
2015-11-23 7:06 ` Stefan Roese
@ 2015-11-23 22:44 ` Tom Rini
1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2015-11-23 22:44 UTC (permalink / raw)
To: u-boot
On Wed, Nov 18, 2015 at 12:42:53PM -0500, Thomas Fitzsimmons wrote:
> If the ext3 journal gets out of sync with what is written on disk, for
> example because of an unexpected power cut, ext4fs_read_file can
> return an all-zero directory entry. In that case, ext4fs_iterate_dir
> would infinite loop.
>
> This patch detects when a directory entry's direntlen member is 0 and
> returns a failure status, which breaks out of the infinite loop. As a
> result, U-Boot will not find files that may subsequently be recovered
> when the journal is replayed.
>
> This is better behaviour than hanging in an infinite loop, but as a
> further improvement maybe U-Boot could interpret the ext3 journal and
> actually find the unsynced entries.
>
> Signed-off-by: Thomas Fitzsimmons <fitzsim@cisco.com>
> Reviewed-by: Stefan Roese <sr@denx.de>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151123/396abff4/attachment.sig>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-11-23 22:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-18 17:42 [U-Boot] [PATCH] fs: ext4: Prevent infinite loop in ext4fs_iterate_dir Thomas Fitzsimmons
2015-11-23 7:06 ` Stefan Roese
2015-11-23 22:44 ` [U-Boot] " Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.