From: Alexey Dobriyan <adobriyan@gmail.com>
To: "Mateusz Stępień" <mateusz.stepien@netrounds.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: PROBLEM: Old content of /proc/net after switching network namespace
Date: Fri, 4 Jan 2019 14:09:33 +0300 [thread overview]
Message-ID: <20190104110933.GA2682@avx2> (raw)
In-Reply-To: <4749d3bd-eac9-2a3e-aa93-d76d2e015945@netrounds.com>
On Fri, Jan 04, 2019 at 09:21:23AM +0100, Mateusz Stępień wrote:
> After changing network namespace using setns, the content of /proc/net
> still represents the original namespace.
> It looks like procfs dentries are not invalidated in dcache properly
> after the namespace switch.
> It happens only, when you read content of /proc/net before changing
> namespace
> The problem is reproducible in 4.19.13 but not in 4.14.X.
> Bisecting the stable kernel tree shows that the commit
> https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=1da4d377f943fe4194ffb9fb9c26cc58fad4dd24
> introduced the problem.
> Reverting mentioned commit resolves it.
>
> MCVE (slightly modified example from [man 2 setns]):
open /proc/net/dev
read
close
setns
open /proc/net/dev
read
close
This bug was discussed recently and Al even posted how to fix it
properly.
Try this horror patch meanwhile:
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -219,19 +219,30 @@ void proc_free_inum(unsigned int inum)
ida_simple_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST);
}
+static bool net_root(const struct proc_dir_entry *pde)
+{
+ return pde->parent == &proc_root && pde->mode == 0;
+}
+
static int proc_misc_d_revalidate(struct dentry *dentry, unsigned int flags)
{
+ const struct proc_dir_entry *pde;
+
if (flags & LOOKUP_RCU)
return -ECHILD;
- if (atomic_read(&PDE(d_inode(dentry))->in_use) < 0)
+ pde = PDE(d_inode(dentry));
+
+ if (atomic_read(&pde->in_use) < 0 || net_root(pde))
return 0; /* revalidate */
return 1;
}
static int proc_misc_d_delete(const struct dentry *dentry)
{
- return atomic_read(&PDE(d_inode(dentry))->in_use) < 0;
+ const struct proc_dir_entry *pde = PDE(d_inode(dentry));
+
+ return atomic_read(&pde->in_use) < 0 || net_root(pde);
}
static const struct dentry_operations proc_misc_dentry_ops = {
next prev parent reply other threads:[~2019-01-04 11:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-04 8:21 PROBLEM: Old content of /proc/net after switching network namespace Mateusz Stępień
2019-01-04 11:09 ` Alexey Dobriyan [this message]
2019-01-07 8:54 ` Mateusz Stępień
2019-01-07 12:39 ` Alexey Dobriyan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190104110933.GA2682@avx2 \
--to=adobriyan@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mateusz.stepien@netrounds.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.