From 83ee50f561a349906f463983653f94133bdbf833 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Wed, 19 May 2004 02:41:54 -0700 Subject: [PATCH] [PATCH] use-before-uninitialized value in ext3(2)_find_ goal From: Mingming Cao There is a uninitialized goal value being referenced in both ext3 and ext2 find goal block functions (ext3_find_goal() and ext2_find_goal()). In the non-sequential write case, these functions check the goal value(non zero) before calling ext3(2)_find_near() to find the goal block to allocate. Since the goal value is uninitialized(non zero), the ext3(2)_find_near() is never being called in the non-sequential write, thus ext3(2)_find_goal() failed to guide a goal block in the random write case. ext3(2)_new_block() takes the junk goal value and will turn it to goal 0 since it's normally beyond the filesystem block number limit. The fix is trivial. --- fs/ext2/inode.c | 1 + fs/ext3/inode.c | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index e7cc85d8bdb58..769c0b3af4473 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -584,6 +584,7 @@ out: if (err == -EAGAIN) goto changed; + goal = 0; if (ext2_find_goal(inode, iblock, chain, partial, &goal) < 0) goto changed; diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index b0456fd965bdf..7f62067496682 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c @@ -811,6 +811,7 @@ out: if (err == -EAGAIN) goto changed; + goal = 0; down(&ei->truncate_sem); if (ext3_find_goal(inode, iblock, chain, partial, &goal) < 0) { up(&ei->truncate_sem); -- 2.53.0