Skip to content

Commit 36de928

Browse files
committed
ext4: propagate errors up to ext4_find_entry()'s callers
If we run into some kind of error, such as ENOMEM, while calling ext4_getblk() or ext4_dx_find_entry(), we need to make sure this error gets propagated up to ext4_find_entry() and then to its callers. This way, transient errors such as ENOMEM can get propagated to the VFS. This is important so that the system calls return the appropriate error, and also so that in the case of ext4_lookup(), we return an error instead of a NULL inode, since that will result in a negative dentry cache entry that will stick around long past the OOM condition which caused a transient ENOMEM error. Google-Bug-Id: #17142205 Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent 7d1311b commit 36de928

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
18251825
/*
18261826
* Special error return code only used by dx_probe() and its callers.
18271827
*/
1828-
#define ERR_BAD_DX_DIR -75000
1828+
#define ERR_BAD_DX_DIR (-(MAX_ERRNO - 1))
18291829

18301830
/*
18311831
* Timeout and state flag for lazy initialization inode thread.

‎fs/ext4/namei.c‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
12271227
buffer */
12281228
int num = 0;
12291229
ext4_lblk_t nblocks;
1230-
int i, err;
1230+
int i, err = 0;
12311231
int namelen;
12321232

12331233
*res_dir = NULL;
@@ -1264,7 +1264,11 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
12641264
* return. Otherwise, fall back to doing a search the
12651265
* old fashioned way.
12661266
*/
1267-
if (bh || (err != ERR_BAD_DX_DIR))
1267+
if (err == -ENOENT)
1268+
return NULL;
1269+
if (err && err != ERR_BAD_DX_DIR)
1270+
return ERR_PTR(err);
1271+
if (bh)
12681272
return bh;
12691273
dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, "
12701274
"falling back\n"));
@@ -1295,6 +1299,11 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
12951299
}
12961300
num++;
12971301
bh = ext4_getblk(NULL, dir, b++, 0, &err);
1302+
if (unlikely(err)) {
1303+
if (ra_max == 0)
1304+
return ERR_PTR(err);
1305+
break;
1306+
}
12981307
bh_use[ra_max] = bh;
12991308
if (bh)
13001309
ll_rw_block(READ | REQ_META | REQ_PRIO,
@@ -1417,6 +1426,8 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
14171426
return ERR_PTR(-ENAMETOOLONG);
14181427

14191428
bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
1429+
if (IS_ERR(bh))
1430+
return (struct dentry *) bh;
14201431
inode = NULL;
14211432
if (bh) {
14221433
__u32 ino = le32_to_cpu(de->inode);
@@ -1450,6 +1461,8 @@ struct dentry *ext4_get_parent(struct dentry *child)
14501461
struct buffer_head *bh;
14511462

14521463
bh = ext4_find_entry(child->d_inode, &dotdot, &de, NULL);
1464+
if (IS_ERR(bh))
1465+
return (struct dentry *) bh;
14531466
if (!bh)
14541467
return ERR_PTR(-ENOENT);
14551468
ino = le32_to_cpu(de->inode);
@@ -2727,6 +2740,8 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
27272740

27282741
retval = -ENOENT;
27292742
bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
2743+
if (IS_ERR(bh))
2744+
return PTR_ERR(bh);
27302745
if (!bh)
27312746
goto end_rmdir;
27322747

@@ -2794,6 +2809,8 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
27942809

27952810
retval = -ENOENT;
27962811
bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
2812+
if (IS_ERR(bh))
2813+
return PTR_ERR(bh);
27972814
if (!bh)
27982815
goto end_unlink;
27992816

@@ -3121,6 +3138,8 @@ static int ext4_find_delete_entry(handle_t *handle, struct inode *dir,
31213138
struct ext4_dir_entry_2 *de;
31223139

31233140
bh = ext4_find_entry(dir, d_name, &de, NULL);
3141+
if (IS_ERR(bh))
3142+
return PTR_ERR(bh);
31243143
if (bh) {
31253144
retval = ext4_delete_entry(handle, dir, de, bh);
31263145
brelse(bh);
@@ -3202,6 +3221,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
32023221
dquot_initialize(new.inode);
32033222

32043223
old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, &old.de, NULL);
3224+
if (IS_ERR(old.bh))
3225+
return PTR_ERR(old.bh);
32053226
/*
32063227
* Check for inode number is _not_ due to possible IO errors.
32073228
* We might rmdir the source, keep it as pwd of some process
@@ -3214,6 +3235,10 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
32143235

32153236
new.bh = ext4_find_entry(new.dir, &new.dentry->d_name,
32163237
&new.de, &new.inlined);
3238+
if (IS_ERR(new.bh)) {
3239+
retval = PTR_ERR(new.bh);
3240+
goto end_rename;
3241+
}
32173242
if (new.bh) {
32183243
if (!new.inode) {
32193244
brelse(new.bh);
@@ -3330,6 +3355,8 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
33303355

33313356
old.bh = ext4_find_entry(old.dir, &old.dentry->d_name,
33323357
&old.de, &old.inlined);
3358+
if (IS_ERR(old.bh))
3359+
return PTR_ERR(old.bh);
33333360
/*
33343361
* Check for inode number is _not_ due to possible IO errors.
33353362
* We might rmdir the source, keep it as pwd of some process
@@ -3342,6 +3369,10 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
33423369

33433370
new.bh = ext4_find_entry(new.dir, &new.dentry->d_name,
33443371
&new.de, &new.inlined);
3372+
if (IS_ERR(new.bh)) {
3373+
retval = PTR_ERR(new.bh);
3374+
goto end_rename;
3375+
}
33453376

33463377
/* RENAME_EXCHANGE case: old *and* new must both exist */
33473378
if (!new.bh || le32_to_cpu(new.de->inode) != new.inode->i_ino)

0 commit comments

Comments
 (0)