diff options
author | Ivan Delalande <colona@arista.com> | 2018-12-13 18:20:52 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-12-13 20:59:44 -0500 |
commit | ea5751ccd665a2fd1b24f9af81f6167f0718c5f6 (patch) | |
tree | 1cc50a3dbdf449f104a3cb4295ed84193607180c | |
parent | 0afa99648350dbd6d08ee3efd2376db240a6c458 (diff) |
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: ace0c791e6c3 ("proc/sysctl: Don't grab i_lock under sysctl_lock.")
Cc: stable@vger.kernel.org
Signed-off-by: Ivan Delalande <colona@arista.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/proc/proc_sysctl.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 89921a0d2ebb..4d598a399bbf 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c | |||
@@ -464,7 +464,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, | |||
464 | 464 | ||
465 | inode = new_inode(sb); | 465 | inode = new_inode(sb); |
466 | if (!inode) | 466 | if (!inode) |
467 | goto out; | 467 | return ERR_PTR(-ENOMEM); |
468 | 468 | ||
469 | inode->i_ino = get_next_ino(); | 469 | inode->i_ino = get_next_ino(); |
470 | 470 | ||
@@ -474,8 +474,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, | |||
474 | if (unlikely(head->unregistering)) { | 474 | if (unlikely(head->unregistering)) { |
475 | spin_unlock(&sysctl_lock); | 475 | spin_unlock(&sysctl_lock); |
476 | iput(inode); | 476 | iput(inode); |
477 | inode = NULL; | 477 | return ERR_PTR(-ENOENT); |
478 | goto out; | ||
479 | } | 478 | } |
480 | ei->sysctl = head; | 479 | ei->sysctl = head; |
481 | ei->sysctl_entry = table; | 480 | ei->sysctl_entry = table; |
@@ -500,7 +499,6 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, | |||
500 | if (root->set_ownership) | 499 | if (root->set_ownership) |
501 | root->set_ownership(head, table, &inode->i_uid, &inode->i_gid); | 500 | root->set_ownership(head, table, &inode->i_uid, &inode->i_gid); |
502 | 501 | ||
503 | out: | ||
504 | return inode; | 502 | return inode; |
505 | } | 503 | } |
506 | 504 | ||
@@ -549,10 +547,11 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, | |||
549 | goto out; | 547 | goto out; |
550 | } | 548 | } |
551 | 549 | ||
552 | err = ERR_PTR(-ENOMEM); | ||
553 | inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); | 550 | 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); | ||
555 | goto out; | 553 | goto out; |
554 | } | ||
556 | 555 | ||
557 | d_set_d_op(dentry, &proc_sys_dentry_operations); | 556 | d_set_d_op(dentry, &proc_sys_dentry_operations); |
558 | err = d_splice_alias(inode, dentry); | 557 | err = d_splice_alias(inode, dentry); |
@@ -685,7 +684,7 @@ static bool proc_sys_fill_cache(struct file *file, | |||
685 | if (d_in_lookup(child)) { | 684 | if (d_in_lookup(child)) { |
686 | struct dentry *res; | 685 | struct dentry *res; |
687 | inode = proc_sys_make_inode(dir->d_sb, head, table); | 686 | inode = proc_sys_make_inode(dir->d_sb, head, table); |
688 | if (!inode) { | 687 | if (IS_ERR(inode)) { |
689 | d_lookup_done(child); | 688 | d_lookup_done(child); |
690 | dput(child); | 689 | dput(child); |
691 | return false; | 690 | return false; |