All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Konstantin Khlebnikov <koct9i@gmail.com>,
	Viktor Stanchev <me@viktorstanchev.com>,
	Vivek Goyal <vgoyal@redhat.com>,
	Miklos Szeredi <miklos@szeredi.hu>
Subject: [PATCH 4.4 22/50] ovl: ignore lower entries when checking purity of non-directory entries
Date: Mon, 14 Mar 2016 10:50:40 -0700	[thread overview]
Message-ID: <20160314175016.600446639@linuxfoundation.org> (raw)
In-Reply-To: <20160314175013.403628835@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Konstantin Khlebnikov <koct9i@gmail.com>

commit 45d11738969633ec07ca35d75d486bf2d8918df6 upstream.

After rename file dentry still holds reference to lower dentry from
previous location. This doesn't matter for data access because data comes
from upper dentry. But this stale lower dentry taints dentry at new
location and turns it into non-pure upper. Such file leaves visible
whiteout entry after remove in directory which shouldn't have whiteouts at
all.

Overlayfs already tracks pureness of file location in oe->opaque.  This
patch just uses that for detecting actual path type.

Comment from Vivek Goyal's patch:

Here are the details of the problem. Do following.

$ mkdir upper lower work merged upper/dir/
$ touch lower/test
$ sudo mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=
work merged
$ mv merged/test merged/dir/
$ rm merged/dir/test
$ ls -l merged/dir/
/usr/bin/ls: cannot access merged/dir/test: No such file or directory
total 0
c????????? ? ? ? ?            ? test

Basic problem seems to be that once a file has been unlinked, a whiteout
has been left behind which was not needed and hence it becomes visible.

Whiteout is visible because parent dir is of not type MERGE, hence
od->is_real is set during ovl_dir_open(). And that means ovl_iterate()
passes on iterate handling directly to underlying fs. Underlying fs does
not know/filter whiteouts so it becomes visible to user.

Why did we leave a whiteout to begin with when we should not have.
ovl_do_remove() checks for OVL_TYPE_PURE_UPPER() and does not leave
whiteout if file is pure upper. In this case file is not found to be pure
upper hence whiteout is left.

So why file was not PURE_UPPER in this case? I think because dentry is
still carrying some leftover state which was valid before rename. For
example, od->numlower was set to 1 as it was a lower file. After rename,
this state is not valid anymore as there is no such file in lower.

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Reported-by: Viktor Stanchev <me@viktorstanchev.com>
Suggested-by: Vivek Goyal <vgoyal@redhat.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=109611
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/overlayfs/dir.c   |    7 +++++++
 fs/overlayfs/super.c |   12 +++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -903,6 +903,13 @@ static int ovl_rename2(struct inode *old
 	if (!overwrite && new_is_dir && !old_opaque && new_opaque)
 		ovl_remove_opaque(newdentry);
 
+	/*
+	 * Old dentry now lives in different location. Dentries in
+	 * lowerstack are stale. We cannot drop them here because
+	 * access to them is lockless. This could be only pure upper
+	 * or opaque directory - numlower is zero. Or upper non-dir
+	 * entry - its pureness is tracked by flag opaque.
+	 */
 	if (old_opaque != new_opaque) {
 		ovl_dentry_set_opaque(old, new_opaque);
 		if (!overwrite)
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -76,12 +76,14 @@ enum ovl_path_type ovl_path_type(struct
 	if (oe->__upperdentry) {
 		type = __OVL_PATH_UPPER;
 
-		if (oe->numlower) {
-			if (S_ISDIR(dentry->d_inode->i_mode))
-				type |= __OVL_PATH_MERGE;
-		} else if (!oe->opaque) {
+		/*
+		 * Non-dir dentry can hold lower dentry from previous
+		 * location. Its purity depends only on opaque flag.
+		 */
+		if (oe->numlower && S_ISDIR(dentry->d_inode->i_mode))
+			type |= __OVL_PATH_MERGE;
+		else if (!oe->opaque)
 			type |= __OVL_PATH_PURE;
-		}
 	} else {
 		if (oe->numlower > 1)
 			type |= __OVL_PATH_MERGE;

  parent reply	other threads:[~2016-03-14 18:18 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14 17:50 [PATCH 4.4 00/50] 4.4.6-stable review Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 01/50] arm64: account for sparsemem section alignment when choosing vmemmap offset Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 02/50] ARM: mvebu: fix overlap of Crypto SRAM with PCIe memory window Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 03/50] ARM: dts: dra7: do not gate cpsw clock due to errata i877 Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 04/50] ARM: OMAP2+: hwmod: Introduce ti,no-idle dt property Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 06/50] kvm: cap halt polling at exactly halt_poll_ns Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 08/50] KVM: s390: correct fprs on SIGP (STOP AND) STORE STATUS Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 09/50] KVM: PPC: Book3S HV: Sanitize special-purpose register values on guest exit Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 10/50] KVM: MMU: fix ept=0/pte.u=1/pte.w=0/CR0.WP=0/CR4.SMEP=1/EFER.NX=0 combo Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 11/50] KVM: MMU: fix reserved bit check for ept=0/CR0.WP=0/CR4.SMEP=1/EFER.NX=0 Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 13/50] s390/dasd: fix diag 0x250 inline assembly Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 14/50] tracing: Fix check for cpu online when event is disabled Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 15/50] dmaengine: at_xdmac: fix residue computation Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 16/50] jffs2: reduce the breakage on recovery from halfway failed rename() Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 17/50] ncpfs: fix a braino in OOM handling in ncp_fill_cache() Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 18/50] ASoC: dapm: Fix ctl value accesses in a wrong type Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 19/50] ASoC: samsung: Use IRQ safe spin lock calls Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 20/50] ASoC: wm8994: Fix enum ctl accesses in a wrong type Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 21/50] ASoC: wm8958: " Greg Kroah-Hartman
2016-03-14 17:50 ` Greg Kroah-Hartman [this message]
2016-03-14 17:50 ` [PATCH 4.4 23/50] ovl: fix working on distributed fs as lower layer Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 24/50] wext: fix message delay/ordering Greg Kroah-Hartman
2016-03-16 12:49   ` Ben Hutchings
2016-03-14 17:50 ` [PATCH 4.4 25/50] cfg80211/wext: fix message ordering Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 26/50] can: gs_usb: fixed disconnect bug by removing erroneous use of kfree() Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 27/50] iwlwifi: mvm: inc pending frames counter also when txing non-sta Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 28/50] mac80211: minstrel: Change expected throughput unit back to Kbps Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 29/50] mac80211: fix use of uninitialised values in RX aggregation Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 30/50] mac80211: minstrel_ht: set default tx aggregation timeout to 0 Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 32/50] mac80211: check PN correctly for GCMP-encrypted fragmented MPDUs Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 33/50] mac80211: Fix Public Action frame RX in AP mode Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 34/50] gpu: ipu-v3: Do not bail out on missing optional port nodes Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 35/50] x86/mm: Fix slow_virt_to_phys() for X86_PAE again Greg Kroah-Hartman
2016-03-14 17:50   ` Greg Kroah-Hartman
2016-03-14 17:50   ` Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 39/50] Revert "drm/radeon/pm: adjust display configuration after powerstate" Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 40/50] powerpc: Fix dedotify for binutils >= 2.26 Greg Kroah-Hartman
2016-03-14 17:50 ` [PATCH 4.4 41/50] powerpc/powernv: Add a kmsg_dumper that flushes console output on panic Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 42/50] powerpc/powernv: Fix OPAL_CONSOLE_FLUSH prototype and usages Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 43/50] userfaultfd: dont block on the last VM updates at exit time Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 44/50] ovl: copy new uid/gid into overlayfs runtime inode Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 45/50] ovl: fix getcwd() failure after unsuccessful rmdir Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 46/50] MIPS: Fix build error when SMP is used without GIC Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 47/50] MIPS: smp.c: Fix uninitialised temp_foreign_map Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 48/50] block: dont optimize for non-cloned bio in bio_get_last_bvec() Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 49/50] target: Drop incorrect ABORT_TASK put for completed commands Greg Kroah-Hartman
2016-03-14 17:51 ` [PATCH 4.4 50/50] ld-version: Fix awk regex compile failure Greg Kroah-Hartman
2016-03-14 23:12 ` [PATCH 4.4 00/50] 4.4.6-stable review Shuah Khan
2016-03-16 15:40   ` Greg Kroah-Hartman
2016-03-15  2:34 ` Guenter Roeck
2016-03-16 15:41   ` Greg Kroah-Hartman

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=20160314175016.600446639@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=koct9i@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@viktorstanchev.com \
    --cc=miklos@szeredi.hu \
    --cc=stable@vger.kernel.org \
    --cc=vgoyal@redhat.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.