Skip to content

Commit ea5751c

Browse files
colonaAl Viro
authored andcommitted
proc/sysctl: don't return ENOMEM on lookup when a table is unregistering
proc_sys_lookup can fail with ENOMEM instead of ENOENT when the corresponding sysctl table is being unregistered. In our case we see this upon opening /proc/sys/net/*/conf files while network interfaces are being deleted, which confuses our configuration daemon. The problem was successfully reproduced and this fix tested on v4.9.122 and v4.20-rc6. v2: return ERR_PTRs in all cases when proc_sys_make_inode fails instead of mixing them with NULL. Thanks Al Viro for the feedback. Fixes: ace0c79 ("proc/sysctl: Don't grab i_lock under sysctl_lock.") Cc: [email protected] Signed-off-by: Ivan Delalande <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 0afa996 commit ea5751c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

fs/proc/proc_sysctl.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
464464

465465
inode = new_inode(sb);
466466
if (!inode)
467-
goto out;
467+
return ERR_PTR(-ENOMEM);
468468

469469
inode->i_ino = get_next_ino();
470470

@@ -474,8 +474,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
474474
if (unlikely(head->unregistering)) {
475475
spin_unlock(&sysctl_lock);
476476
iput(inode);
477-
inode = NULL;
478-
goto out;
477+
return ERR_PTR(-ENOENT);
479478
}
480479
ei->sysctl = head;
481480
ei->sysctl_entry = table;
@@ -500,7 +499,6 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
500499
if (root->set_ownership)
501500
root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
502501

503-
out:
504502
return inode;
505503
}
506504

@@ -549,10 +547,11 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
549547
goto out;
550548
}
551549

552-
err = ERR_PTR(-ENOMEM);
553550
inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
554-
if (!inode)
551+
if (IS_ERR(inode)) {
552+
err = ERR_CAST(inode);
555553
goto out;
554+
}
556555

557556
d_set_d_op(dentry, &proc_sys_dentry_operations);
558557
err = d_splice_alias(inode, dentry);
@@ -685,7 +684,7 @@ static bool proc_sys_fill_cache(struct file *file,
685684
if (d_in_lookup(child)) {
686685
struct dentry *res;
687686
inode = proc_sys_make_inode(dir->d_sb, head, table);
688-
if (!inode) {
687+
if (IS_ERR(inode)) {
689688
d_lookup_done(child);
690689
dput(child);
691690
return false;

0 commit comments

Comments
 (0)