From: Miklos Szeredi <miklos@szeredi.hu>
To: Daniel Axtens <dja@axtens.net>
Cc: Theodore Ts'o <tytso@mit.edu>,
linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org,
viro@zeniv.linux.org.uk, linux-unionfs@vger.kernel.org
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker
Date: Mon, 14 Mar 2016 11:27:35 +0100 [thread overview]
Message-ID: <20160314102735.GM8655@tucsk> (raw)
In-Reply-To: <87ziu1eetp.fsf@gamma.ozlabs.ibm.com>
On Mon, Mar 14, 2016 at 05:47:14PM +1100, Daniel Axtens wrote:
> Hi all,
>
> To make sure I wasn't crazy, I installed a mainline kernel on my x86 laptop.
>
> It also doesn't work there, but I do get a far more detailed set of
> backtraces, which I've added below. It also means it's not powerpc
> specific, which should help in debugging it.
Hi Daniel,
Could you please try the below patch?
It's actually three patches rolled into one:
1) ext4: use dget_parent() in ext4_file_open()
Even with dget_parent() we don't hold i_mutex on directory and so the file
could be moved in the mean time. Not sure if it's a problem. Ted?
2) vfs: add file_dentry()
Posted here:
http://marc.info/?l=linux-fsdevel&m=145745197615687&w=2
3) ext4: use file_dentry()
s/\([a-z_]*\)->f_path\.dentry/file_dentry(\1)/
Thanks,
Miklos
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 4cd318f31cbe..38847f38b34a 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -335,7 +335,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
struct super_block *sb = inode->i_sb;
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
struct vfsmount *mnt = filp->f_path.mnt;
- struct inode *dir = filp->f_path.dentry->d_parent->d_inode;
+ struct dentry *dir;
struct path path;
char buf[64], *cp;
int ret;
@@ -379,14 +379,18 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
if (ext4_encryption_info(inode) == NULL)
return -ENOKEY;
}
- if (ext4_encrypted_inode(dir) &&
- !ext4_is_child_context_consistent_with_parent(dir, inode)) {
+
+ dir = dget_parent(file_dentry(filp));
+ if (ext4_encrypted_inode(d_inode(dir)) &&
+ !ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) {
ext4_warning(inode->i_sb,
"Inconsistent encryption contexts: %lu/%lu\n",
- (unsigned long) dir->i_ino,
+ (unsigned long) d_inode(dir)->i_ino,
(unsigned long) inode->i_ino);
+ dput(dir);
return -EPERM;
}
+ dput(dir);
/*
* Set up the jbd2_inode if we are opening the inode for
* writing and the journal is present
diff --git a/fs/open.c b/fs/open.c
index 55bdc75e2172..6326c11eda78 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -831,6 +831,17 @@ char *file_path(struct file *filp, char *buf, int buflen)
}
EXPORT_SYMBOL(file_path);
+struct dentry *file_dentry(const struct file *file)
+{
+ struct dentry *dentry = file->f_path.dentry;
+
+ if (likely(d_inode(dentry) == file_inode(file)))
+ return dentry;
+ else
+ return dentry->d_op->d_native_dentry(dentry, file_inode(file));
+}
+EXPORT_SYMBOL(file_dentry);
+
/**
* vfs_open - open the file at the given path
* @path: path to open
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 619ad4b016d2..5142aa2034c4 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -336,14 +336,30 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
return ret;
}
+static struct dentry *ovl_d_native_dentry(struct dentry *dentry,
+ struct inode *inode)
+{
+ struct ovl_entry *oe = dentry->d_fsdata;
+ struct dentry *realentry = ovl_upperdentry_dereference(oe);
+
+ if (realentry && inode == d_inode(realentry))
+ return realentry;
+ realentry = __ovl_dentry_lower(oe);
+ if (realentry && inode == d_inode(realentry))
+ return realentry;
+ BUG();
+}
+
static const struct dentry_operations ovl_dentry_operations = {
.d_release = ovl_dentry_release,
.d_select_inode = ovl_d_select_inode,
+ .d_native_dentry = ovl_d_native_dentry,
};
static const struct dentry_operations ovl_reval_dentry_operations = {
.d_release = ovl_dentry_release,
.d_select_inode = ovl_d_select_inode,
+ .d_native_dentry = ovl_d_native_dentry,
.d_revalidate = ovl_dentry_revalidate,
.d_weak_revalidate = ovl_dentry_weak_revalidate,
};
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index c4b5f4b3f8f8..99ecb6de636c 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -161,6 +161,7 @@ struct dentry_operations {
struct vfsmount *(*d_automount)(struct path *);
int (*d_manage)(struct dentry *, bool);
struct inode *(*d_select_inode)(struct dentry *, unsigned);
+ struct dentry *(*d_native_dentry)(struct dentry *, struct inode *);
} ____cacheline_aligned;
/*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ae681002100a..1091d9f43271 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1234,6 +1234,8 @@ static inline struct inode *file_inode(const struct file *f)
return f->f_inode;
}
+extern struct dentry *file_dentry(const struct file *file);
+
static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
{
return locks_lock_inode_wait(file_inode(filp), fl);
next prev parent reply other threads:[~2016-03-14 10:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-11 0:44 ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker Daniel Axtens
2016-03-11 2:15 ` Theodore Ts'o
2016-03-11 15:34 ` Miklos Szeredi
2016-03-11 23:32 ` Daniel Axtens
2016-03-14 6:47 ` Daniel Axtens
2016-03-14 10:27 ` Miklos Szeredi [this message]
2016-03-14 22:49 ` Daniel Axtens
2016-03-31 20:39 ` Marc Haber
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=20160314102735.GM8655@tucsk \
--to=miklos@szeredi.hu \
--cc=dja@axtens.net \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).