2016-03-11 00:45:01

by Daniel Axtens

[permalink] [raw]
Subject: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

Hi,

Trying to run a Docker container on a mainline kernel is failing
intermittently, in interesting and exciting ways, such as:

$ docker run -it --rm --env PACKAGE=sinatra npmtest
operation not permitted
docker: Error response from daemon: Cannot start container 4fc0120a6389f25241f84527a0d31854806f6fe4fd98d019f790cea0ae7e230b: [10] System error: operation not permitted.

$ docker run -it --rm --env PACKAGE=sinatra npmtest
Unable to find user tester
docker: Error response from daemon: Cannot start container a28d6256cfcde750e8e4ff60fc72217b19b58160df68f55d798ea2f3000c4564: [10] System error: Unable to find user tester.

$ docker run ...
...
Error: EPERM, operation not permitted '/usr/share/npm/node_modules/npmconf/node_modules/config-chain/index.js'

$ docker run ...
...
Error: EPERM, operation not permitted '/usr/lib/nodejs/form-data/form_data.js'

$ docker run ...
...
/bin/bash: /usr/bin/npm: Operation not permitted

Each of these failures is accompanied by lines in dmesg like these:

EXT4-fs warning (device sda2): ext4_file_open:402: Inconsistent encryption contexts: 27842/3691208

EXT4-fs warning (device sda2): ext4_file_open:402: Inconsistent encryption contexts: 41086/3128060

(With different context numbers each time)

Grepping for the error message took me to ff978b09f973:
"ext4 crypto: move context consistency check to ext4_file_open()"
which went in to mainline in rc5.

A build with the source rolled back to the commit immediately before
that doesn't exhibit the issue.

Docker is using Overlay filesystems backing onto an ext4 filesystem, so
some interaction between Overlay FS and ext4 may be the cause. I'm not
much of a file system developer so I don't really know where to go from
here, but I'm happy to help however I can.

The machine is a ppc64le VM running Ubuntu, docker 1.11.0-dev, build
dd32445. I've turned on most of the kernel debugging options I can think
of and nothing interesting is showing up. fsck reports the root ext4
filesystem is clean. If I've missed any helpful info please let me know.

Regards,
Daniel Axtens


2016-03-11 02:15:15

by Theodore Ts'o

[permalink] [raw]
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

On Fri, Mar 11, 2016 at 11:44:54AM +1100, Daniel Axtens wrote:
> Hi,
>
> Trying to run a Docker container on a mainline kernel is failing
> intermittently, in interesting and exciting ways, such as:
>
> $ docker run -it --rm --env PACKAGE=sinatra npmtest
> operation not permitted
> docker: Error response from daemon: Cannot start container 4fc0120a6389f25241f84527a0d31854806f6fe4fd98d019f790cea0ae7e230b: [10] System error: operation not permitted.
>
> EXT4-fs warning (device sda2): ext4_file_open:402: Inconsistent encryption contexts: 27842/3691208

This could only happen if the EXT4_ENCRYPT_FL flag is set. (I assume
you weren't actually trying to use ext4 encryption.) The flag can't
be set using the FS_IOC_SETFLAGS ioctl. It can only be set using
EXT4_IOC_SET_ENCRYPTION_POLICY.

The only thing I can think of is that overlayfs is somehow setting or
otherwise corrupting the i_flags.

So if you could try changing the relevant code in ext4_file_open() to
look like this:

if (ext4_encrypted_inode(dir) &&
!ext4_is_child_context_consistent_with_parent(dir, inode)) {
char tmpbuf[128];

ext4_warning(inode->i_sb,
"Inconsistent encryption contexts: %lu/%lu\n",
(unsigned long) dir->i_ino,
(unsigned long) inode->i_ino);
cp = d_path(&filp->f_path, tmpbuf, sizeof(tmpbuf));
if (!IS_ERR(cp))
pr_err("pathname: %s\n", cp);
pr_err("inode flags: %lu\n", EXT4_I(inode)->i_flags);
WARN_ON(1);
return -EPERM;
}

This should give you the stack trace as well as the pathname and inode
flag information. This will hopefully give us a bit more context
about how this is happening.

- Ted

2016-03-11 15:32:56

by Miklos Szeredi

[permalink] [raw]
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

On Thu, Mar 10, 2016 at 09:15:06PM -0500, Theodore Ts'o wrote:
> On Fri, Mar 11, 2016 at 11:44:54AM +1100, Daniel Axtens wrote:
> > Hi,
> >
> > Trying to run a Docker container on a mainline kernel is failing
> > intermittently, in interesting and exciting ways, such as:
> >
> > $ docker run -it --rm --env PACKAGE=sinatra npmtest
> > operation not permitted
> > docker: Error response from daemon: Cannot start container 4fc0120a6389f25241f84527a0d31854806f6fe4fd98d019f790cea0ae7e230b: [10] System error: operation not permitted.
> >
> > EXT4-fs warning (device sda2): ext4_file_open:402: Inconsistent encryption contexts: 27842/3691208
>
> This could only happen if the EXT4_ENCRYPT_FL flag is set. (I assume
> you weren't actually trying to use ext4 encryption.) The flag can't
> be set using the FS_IOC_SETFLAGS ioctl. It can only be set using
> EXT4_IOC_SET_ENCRYPTION_POLICY.
>
> The only thing I can think of is that overlayfs is somehow setting or
> otherwise corrupting the i_flags.

Could you please try the following patch?

It adds more sanity checks to unlink/rmdir/rename to prevent passing an
inappropriate dentry to the underlying filesystem, which could have caused the
corruption.

Thanks,
Miklos


---
fs/overlayfs/dir.c | 59 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 38 insertions(+), 21 deletions(-)

--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -596,21 +596,25 @@ static int ovl_remove_upper(struct dentr
{
struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent);
struct inode *dir = upperdir->d_inode;
- struct dentry *upper = ovl_dentry_upper(dentry);
+ struct dentry *upper;
int err;

inode_lock_nested(dir, I_MUTEX_PARENT);
+ upper = lookup_one_len(dentry->d_name.name, upperdir,
+ dentry->d_name.len);
+ err = PTR_ERR(upper);
+ if (IS_ERR(upper))
+ goto out_unlock;
+
err = -ESTALE;
- if (upper->d_parent == upperdir) {
- /* Don't let d_delete() think it can reset d_inode */
- dget(upper);
+ if (upper == ovl_dentry_upper(dentry)) {
if (is_dir)
err = vfs_rmdir(dir, upper);
else
err = vfs_unlink(dir, upper, NULL);
- dput(upper);
ovl_dentry_version_inc(dentry->d_parent);
}
+ dput(upper);

/*
* Keeping this dentry hashed would mean having to release
@@ -620,6 +624,7 @@ static int ovl_remove_upper(struct dentr
*/
if (!err)
d_drop(dentry);
+out_unlock:
inode_unlock(dir);

return err;
@@ -840,29 +845,39 @@ static int ovl_rename2(struct inode *old

trap = lock_rename(new_upperdir, old_upperdir);

- olddentry = ovl_dentry_upper(old);
- newdentry = ovl_dentry_upper(new);
- if (newdentry) {
+
+ olddentry = lookup_one_len(old->d_name.name, old_upperdir,
+ old->d_name.len);
+ err = PTR_ERR(olddentry);
+ if (IS_ERR(olddentry))
+ goto out_unlock;
+
+ err = -ESTALE;
+ if (olddentry != ovl_dentry_upper(old))
+ goto out_dput_old;
+
+ newdentry = lookup_one_len(new->d_name.name, new_upperdir,
+ new->d_name.len);
+ err = PTR_ERR(newdentry);
+ if (IS_ERR(newdentry))
+ goto out_dput_old;
+
+ err = -ESTALE;
+ if (ovl_dentry_upper(new)) {
if (opaquedir) {
- newdentry = opaquedir;
- opaquedir = NULL;
+ if (newdentry != opaquedir)
+ goto out_dput;
} else {
- dget(newdentry);
+ if (newdentry != ovl_dentry_upper(new))
+ goto out_dput;
}
} else {
+ if (!d_is_negative(newdentry) &&
+ (!new_opaque || !ovl_is_whiteout(newdentry)))
+ goto out_dput;
new_create = true;
- newdentry = lookup_one_len(new->d_name.name, new_upperdir,
- new->d_name.len);
- err = PTR_ERR(newdentry);
- if (IS_ERR(newdentry))
- goto out_unlock;
}

- err = -ESTALE;
- if (olddentry->d_parent != old_upperdir)
- goto out_dput;
- if (newdentry->d_parent != new_upperdir)
- goto out_dput;
if (olddentry == trap)
goto out_dput;
if (newdentry == trap)
@@ -925,6 +940,8 @@ static int ovl_rename2(struct inode *old

out_dput:
dput(newdentry);
+out_dput_old:
+ dput(olddentry);
out_unlock:
unlock_rename(new_upperdir, old_upperdir);
out_revert_creds:

2016-03-11 23:32:20

by Daniel Axtens

[permalink] [raw]
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

Hi Miklos,

> Could you please try the following patch?
>
> It adds more sanity checks to unlink/rmdir/rename to prevent passing an
> inappropriate dentry to the underlying filesystem, which could have caused the
> corruption.

I've tested with your patch.

I'm still seeing similar errors but anecdotally I seem to be seeing them
at a significantly reduced rate. (I can check properly if the rate
changes if that helps.)

Errors are still like this: (I applied Ted's debug info stuff on top of
your patch)

[ 246.364767] EXT4-fs warning (device sda2): ext4_file_open:388: Inconsistent encryption contexts: 49318/2952405
[ 246.364767]
[ 246.365000] pathname: /home/dja/kernel/overlay/linux/include/dt-bindings/dma/nbpfaxi.h
[ 246.365170] inode flags: 48000080000
[ 246.365255] ------------[ cut here ]------------
[ 246.365346] WARNING: at /scratch/dja/linux/fs/ext4/file.c:393
[ 246.365460] Modules linked in: ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 xt_addrtype iptable_filter ip_tables xt_conntrack x_tables nf_nat nf_conntrack br_netfilter bridge stp llc overlay
[ 246.366086] CPU: 4 PID: 2780 Comm: tar Tainted: G W 4.5.0-rc7-00219-gc253bd0 #10
[ 246.366252] task: c0000003e5fd5500 ti: c0000003ec0bc000 task.ti: c0000003ec0bc000
[ 246.366393] NIP: c0000000005f949c LR: c0000000005f9498 CTR: c0000000000d7410
[ 246.366535] REGS: c0000003ec0bf360 TRAP: 0700 Tainted: G W (4.5.0-rc7-00219-gc253bd0)
[ 246.366713] MSR: 8000000000029033 <SF,EE,ME,IR,DR,RI,LE> CR: 28888828 XER: 00000000
[ 246.367073] CFAR: c00000000116faac SOFTE: 1
GPR00: c0000000005f9498 c0000003ec0bf5e0 c000000002c06500 0000000000000018
GPR04: 0000000000000001 c0000000001f15a0 0000000000000000 0000000000000001
GPR08: 0000000000000007 0000000000000000 0000000000000001 646e69622d74642f
GPR12: 0000000000008800 c00000000fb82400 00000000000081a4 0000000088000000
GPR16: c00000029829e220 0000000000000000 0000000000000000 c0000003f311b810
GPR20: c0000003e5fd5500 0000000000000000 0000000000000000 c0000000025fce38
GPR24: 0000000000000001 c0000002982fb270 c0000003f8e0f000 c0000003e98ff420
GPR28: c0000003f8e0e000 c000000298300000 c0000003f311b800 c0000002982fb098
[ 246.368951] NIP [c0000000005f949c] ext4_file_open+0x34c/0x4a0
[ 246.369068] LR [c0000000005f9498] ext4_file_open+0x348/0x4a0
[ 246.369184] Call Trace:
[ 246.369238] [c0000003ec0bf5e0] [c0000000005f9498] ext4_file_open+0x348/0x4a0 (unreliable)
[ 246.369404] [c0000003ec0bfae0] [c0000000004c5c04] do_dentry_open+0x2e4/0x590
[ 246.369547] [c0000003ec0bfb50] [c0000000004ea0bc] path_openat+0x9ac/0x1f10
[ 246.369689] [c0000003ec0bfc80] [c0000000004ed9d8] do_filp_open+0xa8/0x1a0
[ 246.369836] [c0000003ec0bfdc0] [c0000000004c87e0] do_sys_open+0x1b0/0x340
[ 246.369982] [c0000003ec0bfe30] [c000000000009210] system_call+0x38/0xb4
[ 246.370123] Instruction dump:
[ 246.370195] 419d0014 3c62fe83 38630408 48b76575 60000000 2fbf01f0 41de0150 e89ffe60
[ 246.370445] 3c62fe83 38630418 48b76559 60000000 <0fe00000> 3860ffff 4bfffdd4 60000000
[ 246.370715] ---[ end trace befd0478e64e65a3 ]---


There doesn't seem to be any pattern to the broken directories - here's
a snippet of the tar output:
tar: linux/include/dt-bindings/dma/axi-dmac.h: Cannot open: Operation not permitted
tar: linux/include/dt-bindings/dma/sun4i-a10.h: Cannot open: Operation not permitted
tar: linux/include/dt-bindings/dma/at91.h: Cannot open: Operation not permitted
tar: linux/include/dt-bindings/dma/nbpfaxi.h: Cannot open: Operation not permitted
tar: linux/include/soc/at91/at91sam9_sdramc.h: Cannot open: Operation not permitted
tar: linux/include/soc/at91/at91sam9_ddrsdr.h: Cannot open: Operation not permitted
tar: linux/drivers/isdn/hysdn/hysdn_pof.h: Cannot open: Operation not permitted
tar: linux/drivers/isdn/hysdn/Makefile: Cannot open: Operation not permitted
tar: linux/drivers/isdn/hysdn/hysdn_net.c: Cannot open: Operation not permitted
tar: linux/drivers/isdn/hysdn/hysdn_defs.h: Cannot open: Operation not permitted
tar: linux/drivers/isdn/hysdn/boardergo.c: Cannot open: Operation not permitted
tar: linux/drivers/isdn/hysdn/hysdn_init.c: Cannot open: Operation not permitted

The set of broken directories seems to be somewhat consistent if I rerun
the command within the same overlay mount (especially the first couple
of directories), but if I unmount the overlay, clean the upper and work
directories, and remount it, the set of broken directories is different.

Regards,
Daniel

2016-03-14 06:47:31

by Daniel Axtens

[permalink] [raw]
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

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.

Regards,
Daniel

[ 118.453138] EXT4-fs warning (device dm-1): ext4_file_open:388: Inconsistent encryption contexts: 29256/13376200

[ 118.453143] pathname: /etc/passwd
[ 118.453146] inode flags: 40000080000
[ 118.453147] ------------[ cut here ]------------
[ 118.453153] WARNING: CPU: 3 PID: 2246 at /scratch/dja/linux/fs/ext4/file.c:393 ext4_file_open+0x18a/0x2d0()
[ 118.453155] Modules linked in: veth rfcomm xt_addrtype xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 iptable_filter ip_tables x_tables nf_nat nf_conntrack bridge stp llc overlay bnep nls_iso8859_1 uvcvideo snd_hda_codec_hdmi btusb btrtl videobuf2_vmalloc btbcm videobuf2_memops videobuf2_v4l2 btintel intel_powerclamp bluetooth snd_hda_codec_cirrus videobuf2_core snd_hda_codec_generic videodev joydev coretemp snd_hda_intel media kvm_intel snd_hda_codec bcm5974 input_leds snd_seq_midi snd_hda_core snd_hwdep snd_seq_midi_event snd_rawmidi kvm snd_seq applesmc input_polldev snd_seq_device snd_pcm snd_timer irqbypass acpi_als snd kfifo_buf shpchp soundcore industrialio intel_ips sbs apple_gmux sbshc lpc_ich apple_bl mac_hid parport_pc ppdev
[ 118.453197] lp parport autofs4 drbg ansi_cprng algif_skcipher af_alg dm_crypt uas usb_storage hid_generic hid_appleir hid_apple usbhid hid crct10dif_pclmul crc32_pclmul ghash_clmulni_intel aesni_intel nouveau i915 aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd mxm_wmi wmi ahci ttm firewire_ohci i2c_algo_bit libahci firewire_core drm_kms_helper crc_itu_t syscopyarea tg3 sysfillrect sysimgblt fb_sys_fops ptp drm pps_core video
[ 118.453224] CPU: 3 PID: 2246 Comm: docker Not tainted 4.5.0-rc7+ #1
[ 118.453226] Hardware name: Apple Inc. MacBookPro6,2/Mac-F22586C8, BIOS MBP61.88Z.0057.B0A.1005121001 05/12/10
[ 118.453228] 0000000000000286 00000000df47ba90 ffff880164ab77b8 ffffffff813dc903
[ 118.453230] 0000000000000000 ffffffff81cee120 ffff880164ab77f0 ffffffff810806b6
[ 118.453233] ffff8801642ca2a8 ffff880089d06c00 ffff88007978ec60 ffff880035418000
[ 118.453235] Call Trace:
[ 118.453243] [<ffffffff813dc903>] dump_stack+0x63/0x90
[ 118.453248] [<ffffffff810806b6>] warn_slowpath_common+0x86/0xc0
[ 118.453250] [<ffffffff810807fa>] warn_slowpath_null+0x1a/0x20
[ 118.453252] [<ffffffff81298fda>] ext4_file_open+0x18a/0x2d0
[ 118.453256] [<ffffffff81016743>] ? __switch_to+0x253/0x5a0
[ 118.453262] [<ffffffff81812ca1>] ? __schedule+0x391/0xa30
[ 118.453266] [<ffffffffc00d889e>] ? kcryptd_io_read+0x6e/0x80 [dm_crypt]
[ 118.453269] [<ffffffff81813c60>] ? bit_wait_timeout+0xa0/0xa0
[ 118.453271] [<ffffffff81813375>] ? schedule+0x35/0x80
[ 118.453274] [<ffffffff8181661f>] ? schedule_timeout+0x22f/0x2c0
[ 118.453279] [<ffffffff815a035f>] ? scsi_request_fn+0x3f/0x640
[ 118.453283] [<ffffffff810f4afc>] ? ktime_get+0x3c/0xb0
[ 118.453287] [<ffffffff8113c78d>] ? delayacct_end+0x5d/0x70
[ 118.453289] [<ffffffff8113c8d0>] ? __delayacct_blkio_end+0x60/0xa0
[ 118.453291] [<ffffffff818128cd>] ? io_schedule_timeout+0xfd/0x140
[ 118.453293] [<ffffffff81813746>] ? __wait_on_bit+0x76/0x90
[ 118.453296] [<ffffffff81813c60>] ? bit_wait_timeout+0xa0/0xa0
[ 118.453298] [<ffffffff818137e1>] ? out_of_line_wait_on_bit+0x81/0xb0
[ 118.453302] [<ffffffff810c33a0>] ? autoremove_wake_function+0x40/0x40
[ 118.453305] [<ffffffff812cb819>] ? __ext4_ext_check+0x119/0x390
[ 118.453308] [<ffffffff81249ec2>] ? __wait_on_buffer+0x32/0x40
[ 118.453310] [<ffffffff810c2fe5>] ? wake_up_bit+0x25/0x30
[ 118.453315] [<ffffffff8122e379>] ? unlock_new_inode+0x49/0x80
[ 118.453319] [<ffffffff812a2148>] ? ext4_iget+0xa18/0xbf0
[ 118.453321] [<ffffffff81229f57>] ? __d_instantiate+0x97/0xf0
[ 118.453323] [<ffffffff81229e3c>] ? d_rehash+0x4c/0x60
[ 118.453325] [<ffffffff8122c0c7>] ? d_splice_alias+0xa7/0x2b0
[ 118.453327] [<ffffffff8122accf>] ? dput+0x2f/0x220
[ 118.453332] [<ffffffffc0847c59>] ? ovl_permission+0xe9/0x240 [overlay]
[ 118.453337] [<ffffffff812101bf>] do_dentry_open+0x1cf/0x310
[ 118.453339] [<ffffffff81298e50>] ? ext4_check_all_de+0xb0/0xb0
[ 118.453341] [<ffffffff812116b8>] vfs_open+0x58/0x60
[ 118.453345] [<ffffffff81220c7a>] path_openat+0x1ea/0x1400
[ 118.453348] [<ffffffff81223a51>] do_filp_open+0x91/0x100
[ 118.453352] [<ffffffff810a1c76>] ? __put_cred+0x46/0x50
[ 118.453354] [<ffffffff812314c6>] ? __alloc_fd+0x46/0x180
[ 118.453356] [<ffffffff81211a25>] do_sys_open+0x125/0x210
[ 118.453359] [<ffffffff81211b44>] SyS_openat+0x14/0x20
[ 118.453362] [<ffffffff818174f6>] entry_SYSCALL_64_fastpath+0x16/0x75
[ 118.453364] ---[ end trace f6e9d91a0c7899ce ]---
[ 118.453390] EXT4-fs warning (device dm-1): ext4_file_open:388: Inconsistent encryption contexts: 29256/13376196

[ 118.453393] pathname: /etc/group
[ 118.453394] inode flags: 40000080000
[ 118.453395] ------------[ cut here ]------------
[ 118.453397] WARNING: CPU: 3 PID: 2246 at /scratch/dja/linux/fs/ext4/file.c:393 ext4_file_open+0x18a/0x2d0()
[ 118.453398] Modules linked in: veth rfcomm xt_addrtype xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 iptable_filter ip_tables x_tables nf_nat nf_conntrack bridge stp llc overlay bnep nls_iso8859_1 uvcvideo snd_hda_codec_hdmi btusb btrtl videobuf2_vmalloc btbcm videobuf2_memops videobuf2_v4l2 btintel intel_powerclamp bluetooth snd_hda_codec_cirrus videobuf2_core snd_hda_codec_generic videodev joydev coretemp snd_hda_intel media kvm_intel snd_hda_codec bcm5974 input_leds snd_seq_midi snd_hda_core snd_hwdep snd_seq_midi_event snd_rawmidi kvm snd_seq applesmc input_polldev snd_seq_device snd_pcm snd_timer irqbypass acpi_als snd kfifo_buf shpchp soundcore industrialio intel_ips sbs apple_gmux sbshc lpc_ich apple_bl mac_hid parport_pc ppdev
[ 118.453424] lp parport autofs4 drbg ansi_cprng algif_skcipher af_alg dm_crypt uas usb_storage hid_generic hid_appleir hid_apple usbhid hid crct10dif_pclmul crc32_pclmul ghash_clmulni_intel aesni_intel nouveau i915 aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd mxm_wmi wmi ahci ttm firewire_ohci i2c_algo_bit libahci firewire_core drm_kms_helper crc_itu_t syscopyarea tg3 sysfillrect sysimgblt fb_sys_fops ptp drm pps_core video
[ 118.453442] CPU: 3 PID: 2246 Comm: docker Tainted: G W 4.5.0-rc7+ #1
[ 118.453443] Hardware name: Apple Inc. MacBookPro6,2/Mac-F22586C8, BIOS MBP61.88Z.0057.B0A.1005121001 05/12/10
[ 118.453444] 0000000000000286 00000000df47ba90 ffff880164ab77b8 ffffffff813dc903
[ 118.453447] 0000000000000000 ffffffff81cee120 ffff880164ab77f0 ffffffff810806b6
[ 118.453449] ffff8801642c9e70 ffff880157256100 ffff88007978ec60 ffff880035418000
[ 118.453451] Call Trace:
[ 118.453454] [<ffffffff813dc903>] dump_stack+0x63/0x90
[ 118.453456] [<ffffffff810806b6>] warn_slowpath_common+0x86/0xc0
[ 118.453458] [<ffffffff810807fa>] warn_slowpath_null+0x1a/0x20
[ 118.453460] [<ffffffff81298fda>] ext4_file_open+0x18a/0x2d0
[ 118.453462] [<ffffffff81016743>] ? __switch_to+0x253/0x5a0
[ 118.453465] [<ffffffff81812ca1>] ? __schedule+0x391/0xa30
[ 118.453467] [<ffffffffc00d889e>] ? kcryptd_io_read+0x6e/0x80 [dm_crypt]
[ 118.453470] [<ffffffff81813c60>] ? bit_wait_timeout+0xa0/0xa0
[ 118.453472] [<ffffffff81813375>] ? schedule+0x35/0x80
[ 118.453474] [<ffffffff8181661f>] ? schedule_timeout+0x22f/0x2c0
[ 118.453477] [<ffffffff815a035f>] ? scsi_request_fn+0x3f/0x640
[ 118.453481] [<ffffffff813e24b2>] ? radix_tree_lookup_slot+0x22/0x50
[ 118.453482] [<ffffffff8124a19e>] ? bh_lru_install+0x17e/0x1c0
[ 118.453485] [<ffffffff813e24b2>] ? radix_tree_lookup_slot+0x22/0x50
[ 118.453486] [<ffffffff8124a19e>] ? bh_lru_install+0x17e/0x1c0
[ 118.453489] [<ffffffff8124a919>] ? __find_get_block+0x109/0x110
[ 118.453491] [<ffffffff812cb819>] ? __ext4_ext_check+0x119/0x390
[ 118.453493] [<ffffffff8124b0cb>] ? __getblk_gfp+0x2b/0x60
[ 118.453495] [<ffffffff810c2fe5>] ? wake_up_bit+0x25/0x30
[ 118.453498] [<ffffffff8122e379>] ? unlock_new_inode+0x49/0x80
[ 118.453500] [<ffffffff812a2148>] ? ext4_iget+0xa18/0xbf0
[ 118.453502] [<ffffffff81229f57>] ? __d_instantiate+0x97/0xf0
[ 118.453504] [<ffffffff81229e3c>] ? d_rehash+0x4c/0x60
[ 118.453506] [<ffffffff8122c0c7>] ? d_splice_alias+0xa7/0x2b0
[ 118.453508] [<ffffffff8122accf>] ? dput+0x2f/0x220
[ 118.453511] [<ffffffffc0847c59>] ? ovl_permission+0xe9/0x240 [overlay]
[ 118.453514] [<ffffffff812101bf>] do_dentry_open+0x1cf/0x310
[ 118.453516] [<ffffffff81298e50>] ? ext4_check_all_de+0xb0/0xb0
[ 118.453518] [<ffffffff812116b8>] vfs_open+0x58/0x60
[ 118.453521] [<ffffffff81220c7a>] path_openat+0x1ea/0x1400
[ 118.453523] [<ffffffff81223a51>] do_filp_open+0x91/0x100
[ 118.453526] [<ffffffff810a1c76>] ? __put_cred+0x46/0x50
[ 118.453528] [<ffffffff812314c6>] ? __alloc_fd+0x46/0x180
[ 118.453530] [<ffffffff81211a25>] do_sys_open+0x125/0x210
[ 118.453532] [<ffffffff81211b44>] SyS_openat+0x14/0x20
[ 118.453534] [<ffffffff818174f6>] entry_SYSCALL_64_fastpath+0x16/0x75
[ 118.453536] ---[ end trace f6e9d91a0c7899cf ]---
[ 118.582696] EXT4-fs warning (device dm-1): ext4_file_open:388: Inconsistent encryption contexts: 30168/12584552

[ 118.582704] pathname: /bin/bash
[ 118.582707] inode flags: 40000080000
[ 118.582709] ------------[ cut here ]------------
[ 118.582718] WARNING: CPU: 0 PID: 2246 at /scratch/dja/linux/fs/ext4/file.c:393 ext4_file_open+0x18a/0x2d0()
[ 118.582721] Modules linked in: veth rfcomm xt_addrtype xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 iptable_filter ip_tables x_tables nf_nat nf_conntrack bridge stp llc overlay bnep nls_iso8859_1 uvcvideo snd_hda_codec_hdmi btusb btrtl videobuf2_vmalloc btbcm videobuf2_memops videobuf2_v4l2 btintel intel_powerclamp bluetooth snd_hda_codec_cirrus videobuf2_core snd_hda_codec_generic videodev joydev coretemp snd_hda_intel media kvm_intel snd_hda_codec bcm5974 input_leds snd_seq_midi snd_hda_core snd_hwdep snd_seq_midi_event snd_rawmidi kvm snd_seq applesmc input_polldev snd_seq_device snd_pcm snd_timer irqbypass acpi_als snd kfifo_buf shpchp soundcore industrialio intel_ips sbs apple_gmux sbshc lpc_ich apple_bl mac_hid parport_pc ppdev
[ 118.582792] lp parport autofs4 drbg ansi_cprng algif_skcipher af_alg dm_crypt uas usb_storage hid_generic hid_appleir hid_apple usbhid hid crct10dif_pclmul crc32_pclmul ghash_clmulni_intel aesni_intel nouveau i915 aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd mxm_wmi wmi ahci ttm firewire_ohci i2c_algo_bit libahci firewire_core drm_kms_helper crc_itu_t syscopyarea tg3 sysfillrect sysimgblt fb_sys_fops ptp drm pps_core video
[ 118.582836] CPU: 0 PID: 2246 Comm: docker Tainted: G W 4.5.0-rc7+ #1
[ 118.582841] Hardware name: Apple Inc. MacBookPro6,2/Mac-F22586C8, BIOS MBP61.88Z.0057.B0A.1005121001 05/12/10
[ 118.582846] 0000000000000286 00000000df47ba90 ffff880164ab7738 ffffffff813dc903
[ 118.582851] 0000000000000000 ffffffff81cee120 ffff880164ab7770 ffffffff810806b6
[ 118.582854] ffff8801642eb7c0 ffff880071624400 ffff8800797b6a28 ffff880035418000
[ 118.582858] Call Trace:
[ 118.582869] [<ffffffff813dc903>] dump_stack+0x63/0x90
[ 118.582876] [<ffffffff810806b6>] warn_slowpath_common+0x86/0xc0
[ 118.582880] [<ffffffff810807fa>] warn_slowpath_null+0x1a/0x20
[ 118.582883] [<ffffffff81298fda>] ext4_file_open+0x18a/0x2d0
[ 118.582891] [<ffffffff81812ca1>] ? __schedule+0x391/0xa30
[ 118.582896] [<ffffffff81813c60>] ? bit_wait_timeout+0xa0/0xa0
[ 118.582899] [<ffffffff81813375>] ? schedule+0x35/0x80
[ 118.582904] [<ffffffff8181661f>] ? schedule_timeout+0x22f/0x2c0
[ 118.582911] [<ffffffff810f4afc>] ? ktime_get+0x3c/0xb0
[ 118.582919] [<ffffffff8113c78d>] ? delayacct_end+0x5d/0x70
[ 118.582925] [<ffffffff8113c8d0>] ? __delayacct_blkio_end+0x60/0xa0
[ 118.582931] [<ffffffff818128cd>] ? io_schedule_timeout+0xfd/0x140
[ 118.582937] [<ffffffff813e24b2>] ? radix_tree_lookup_slot+0x22/0x50
[ 118.582941] [<ffffffff8124a19e>] ? bh_lru_install+0x17e/0x1c0
[ 118.582945] [<ffffffff8124a919>] ? __find_get_block+0x109/0x110
[ 118.582950] [<ffffffff812cb819>] ? __ext4_ext_check+0x119/0x390
[ 118.582953] [<ffffffff8124b0cb>] ? __getblk_gfp+0x2b/0x60
[ 118.582959] [<ffffffff810c2fe5>] ? wake_up_bit+0x25/0x30
[ 118.582965] [<ffffffff8122e379>] ? unlock_new_inode+0x49/0x80
[ 118.582970] [<ffffffff812a2148>] ? ext4_iget+0xa18/0xbf0
[ 118.582974] [<ffffffff81229f57>] ? __d_instantiate+0x97/0xf0
[ 118.582978] [<ffffffff8122accf>] ? dput+0x2f/0x220
[ 118.582987] [<ffffffffc0847c59>] ? ovl_permission+0xe9/0x240 [overlay]
[ 118.582995] [<ffffffff812101bf>] do_dentry_open+0x1cf/0x310
[ 118.583001] [<ffffffff81298e50>] ? ext4_check_all_de+0xb0/0xb0
[ 118.583008] [<ffffffff812116b8>] vfs_open+0x58/0x60
[ 118.583015] [<ffffffff81220c7a>] path_openat+0x1ea/0x1400
[ 118.583020] [<ffffffff810aaa39>] ? ttwu_do_wakeup+0x19/0xe0
[ 118.583026] [<ffffffff81223a51>] do_filp_open+0x91/0x100
[ 118.583033] [<ffffffff81385f8f>] ? apparmor_cred_prepare+0x2f/0x50
[ 118.583038] [<ffffffff81219546>] do_open_execat+0x76/0x180
[ 118.583042] [<ffffffff8121a96d>] do_execveat_common.isra.34+0x1cd/0x750
[ 118.583046] [<ffffffff81222a42>] ? getname_flags+0x72/0x1f0
[ 118.583050] [<ffffffff8121b21a>] SyS_execve+0x3a/0x50
[ 118.583054] [<ffffffff81817795>] stub_execve+0x5/0x5
[ 118.583058] [<ffffffff818174f6>] ? entry_SYSCALL_64_fastpath+0x16/0x75
[ 118.583061] ---[ end trace f6e9d91a0c7899d0 ]---
[ 118.583358] EXT4-fs warning (device dm-1): ext4_file_open:388: Inconsistent encryption contexts: 29256/12584870

[ 118.583362] pathname: /etc/localtime
[ 118.583365] inode flags: 40000080000
[ 118.583367] ------------[ cut here ]------------
[ 118.583372] WARNING: CPU: 0 PID: 2246 at /scratch/dja/linux/fs/ext4/file.c:393 ext4_file_open+0x18a/0x2d0()
[ 118.583374] Modules linked in: veth rfcomm xt_addrtype xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 iptable_filter ip_tables x_tables nf_nat nf_conntrack bridge stp llc overlay bnep nls_iso8859_1 uvcvideo snd_hda_codec_hdmi btusb btrtl videobuf2_vmalloc btbcm videobuf2_memops videobuf2_v4l2 btintel intel_powerclamp bluetooth snd_hda_codec_cirrus videobuf2_core snd_hda_codec_generic videodev joydev coretemp snd_hda_intel media kvm_intel snd_hda_codec bcm5974 input_leds snd_seq_midi snd_hda_core snd_hwdep snd_seq_midi_event snd_rawmidi kvm snd_seq applesmc input_polldev snd_seq_device snd_pcm snd_timer irqbypass acpi_als snd kfifo_buf shpchp soundcore industrialio intel_ips sbs apple_gmux sbshc lpc_ich apple_bl mac_hid parport_pc ppdev
[ 118.583428] lp parport autofs4 drbg ansi_cprng algif_skcipher af_alg dm_crypt uas usb_storage hid_generic hid_appleir hid_apple usbhid hid crct10dif_pclmul crc32_pclmul ghash_clmulni_intel aesni_intel nouveau i915 aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd mxm_wmi wmi ahci ttm firewire_ohci i2c_algo_bit libahci firewire_core drm_kms_helper crc_itu_t syscopyarea tg3 sysfillrect sysimgblt fb_sys_fops ptp drm pps_core video
[ 118.583465] CPU: 0 PID: 2246 Comm: docker Tainted: G W 4.5.0-rc7+ #1
[ 118.583468] Hardware name: Apple Inc. MacBookPro6,2/Mac-F22586C8, BIOS MBP61.88Z.0057.B0A.1005121001 05/12/10
[ 118.583470] 0000000000000286 00000000df47ba90 ffff880164ab77b8 ffffffff813dc903
[ 118.583474] 0000000000000000 ffffffff81cee120 ffff880164ab77f0 ffffffff810806b6
[ 118.583478] ffff8801642ebbf8 ffff880071624c00 ffff88007978ec60 ffff880035418000
[ 118.583482] Call Trace:
[ 118.583488] [<ffffffff813dc903>] dump_stack+0x63/0x90
[ 118.583492] [<ffffffff810806b6>] warn_slowpath_common+0x86/0xc0
[ 118.583496] [<ffffffff810807fa>] warn_slowpath_null+0x1a/0x20
[ 118.583500] [<ffffffff81298fda>] ext4_file_open+0x18a/0x2d0
[ 118.583505] [<ffffffff81813c60>] ? bit_wait_timeout+0xa0/0xa0
[ 118.583511] [<ffffffff81813375>] ? schedule+0x35/0x80
[ 118.583518] [<ffffffff8181661f>] ? schedule_timeout+0x22f/0x2c0
[ 118.583525] [<ffffffff810f4afc>] ? ktime_get+0x3c/0xb0
[ 118.583530] [<ffffffff8113c78d>] ? delayacct_end+0x5d/0x70
[ 118.583534] [<ffffffff8113c8d0>] ? __delayacct_blkio_end+0x60/0xa0
[ 118.583537] [<ffffffff818128cd>] ? io_schedule_timeout+0xfd/0x140
[ 118.583541] [<ffffffff813e24b2>] ? radix_tree_lookup_slot+0x22/0x50
[ 118.583545] [<ffffffff8124a19e>] ? bh_lru_install+0x17e/0x1c0
[ 118.583548] [<ffffffff813e24b2>] ? radix_tree_lookup_slot+0x22/0x50
[ 118.583552] [<ffffffff8124a19e>] ? bh_lru_install+0x17e/0x1c0
[ 118.583555] [<ffffffff813e24b2>] ? radix_tree_lookup_slot+0x22/0x50
[ 118.583559] [<ffffffff8124a19e>] ? bh_lru_install+0x17e/0x1c0
[ 118.583563] [<ffffffff8124a919>] ? __find_get_block+0x109/0x110
[ 118.583566] [<ffffffff812cb819>] ? __ext4_ext_check+0x119/0x390
[ 118.583570] [<ffffffff8124b0cb>] ? __getblk_gfp+0x2b/0x60
[ 118.583574] [<ffffffff810c2fe5>] ? wake_up_bit+0x25/0x30
[ 118.583578] [<ffffffff8122e379>] ? unlock_new_inode+0x49/0x80
[ 118.583582] [<ffffffff812a2148>] ? ext4_iget+0xa18/0xbf0
[ 118.583586] [<ffffffff8122accf>] ? dput+0x2f/0x220
[ 118.583589] [<ffffffff81229f57>] ? __d_instantiate+0x97/0xf0
[ 118.583592] [<ffffffff81229e3c>] ? d_rehash+0x4c/0x60
[ 118.583596] [<ffffffff8122c0c7>] ? d_splice_alias+0xa7/0x2b0
[ 118.583600] [<ffffffff8122accf>] ? dput+0x2f/0x220
[ 118.583606] [<ffffffffc0847c59>] ? ovl_permission+0xe9/0x240 [overlay]
[ 118.583611] [<ffffffff812101bf>] do_dentry_open+0x1cf/0x310
[ 118.583614] [<ffffffff81298e50>] ? ext4_check_all_de+0xb0/0xb0
[ 118.583618] [<ffffffff812116b8>] vfs_open+0x58/0x60
[ 118.583623] [<ffffffff81220c7a>] path_openat+0x1ea/0x1400
[ 118.583628] [<ffffffff81223a51>] do_filp_open+0x91/0x100
[ 118.583632] [<ffffffff812314c6>] ? __alloc_fd+0x46/0x180
[ 118.583636] [<ffffffff81211a25>] do_sys_open+0x125/0x210
[ 118.583640] [<ffffffff81211b44>] SyS_openat+0x14/0x20
[ 118.583644] [<ffffffff818174f6>] entry_SYSCALL_64_fastpath+0x16/0x75
[ 118.583647] ---[ end trace f6e9d91a0c7899d1 ]---

2016-03-14 10:26:27

by Miklos Szeredi

[permalink] [raw]
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

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);

2016-03-14 22:49:42

by Daniel Axtens

[permalink] [raw]
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

Hi Miklos,

> 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)/

That works! Many thanks to you and Ted.

Feel free to let me know if you'd like my Tested-by on any of these patches.

Regards,
Daniel

>
> 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);

2016-03-31 20:39:55

by Marc Haber

[permalink] [raw]
Subject: Re: ext4_file_open: Inconsistent encryption contexts (commit ff978b09f973) breaking Docker

On Mon, Mar 14, 2016 at 11:27:35AM +0100, Miklos Szeredi wrote:
> Could you please try the below patch?

I can confirm that I have the issue on kernel 4.5 with Debian's
schroot using overlayfs, and that this patch fixes it.

It should be in 4.5.1.

Greetings
Marc

--
-----------------------------------------------------------------------------
Marc Haber | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421