Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1377337

[PATCH 4.2.y-ckt 07/70] fs: add file_dentry()

From Kamal Mostafa <kamal@canonical.com>
Newsgroups linux.kernel
Subject [PATCH 4.2.y-ckt 07/70] fs: add file_dentry()
Date 2016-04-12 23:40 +0200
Message-ID <rnect-5Ws-71@gated-at.bofh.it> (permalink)
References <rndzH-5be-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

---8<------------------------------------------------------------

From: Miklos Szeredi <miklos@szeredi.hu>

commit d101a125954eae1d397adda94ca6319485a50493 upstream.

This series fixes bugs in nfs and ext4 due to 4bacc9c9234c ("overlayfs:
Make f_path always point to the overlay and f_inode to the underlay").

Regular files opened on overlayfs will result in the file being opened on
the underlying filesystem, while f_path points to the overlayfs
mount/dentry.

This confuses filesystems which get the dentry from struct file and assume
it's theirs.

Add a new helper, file_dentry() [*], to get the filesystem's own dentry
from the file.  This checks file->f_path.dentry->d_flags against
DCACHE_OP_REAL, and returns file->f_path.dentry if DCACHE_OP_REAL is not
set (this is the common, non-overlayfs case).

In the uncommon case it will call into overlayfs's ->d_real() to get the
underlying dentry, matching file_inode(file).

The reason we need to check against the inode is that if the file is copied
up while being open, d_real() would return the upper dentry, while the open
file comes from the lower dentry.

[*] If possible, it's better simply to use file_inode() instead.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Trond Myklebust <trond.myklebust@primarydata.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Daniel Axtens <dja@axtens.net>
[ kamal: backport to 4.2-stable: context ]
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 fs/dcache.c            |  5 ++++-
 fs/overlayfs/super.c   | 33 +++++++++++++++++++++++++++++++++
 include/linux/dcache.h | 11 +++++++++++
 include/linux/fs.h     | 10 ++++++++++
 4 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 403d24d..4f3d081 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1666,7 +1666,8 @@ void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
 				DCACHE_OP_REVALIDATE	|
 				DCACHE_OP_WEAK_REVALIDATE	|
 				DCACHE_OP_DELETE	|
-				DCACHE_OP_SELECT_INODE));
+				DCACHE_OP_SELECT_INODE	|
+				DCACHE_OP_REAL));
 	dentry->d_op = op;
 	if (!op)
 		return;
@@ -1684,6 +1685,8 @@ void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
 		dentry->d_flags |= DCACHE_OP_PRUNE;
 	if (op->d_select_inode)
 		dentry->d_flags |= DCACHE_OP_SELECT_INODE;
+	if (op->d_real)
+		dentry->d_flags |= DCACHE_OP_REAL;
 
 }
 EXPORT_SYMBOL(d_set_d_op);
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 000b2ed..a1acc60 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -276,6 +276,37 @@ static void ovl_dentry_release(struct dentry *dentry)
 	}
 }
 
+static struct dentry *ovl_d_real(struct dentry *dentry, struct inode *inode)
+{
+	struct dentry *real;
+
+	if (d_is_dir(dentry)) {
+		if (!inode || inode == d_inode(dentry))
+			return dentry;
+		goto bug;
+	}
+
+	real = ovl_dentry_upper(dentry);
+	if (real && (!inode || inode == d_inode(real)))
+		return real;
+
+	real = ovl_dentry_lower(dentry);
+	if (!real)
+		goto bug;
+
+	if (!inode || inode == d_inode(real))
+		return real;
+
+	/* Handle recursion */
+	if (real->d_flags & DCACHE_OP_REAL)
+		return real->d_op->d_real(real, inode);
+
+bug:
+	WARN(1, "ovl_d_real(%pd4, %s:%lu\n): real dentry not found\n", dentry,
+	     inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0);
+	return dentry;
+}
+
 static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
 {
 	struct ovl_entry *oe = dentry->d_fsdata;
@@ -320,11 +351,13 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
 static const struct dentry_operations ovl_dentry_operations = {
 	.d_release = ovl_dentry_release,
 	.d_select_inode = ovl_d_select_inode,
+	.d_real = ovl_d_real,
 };
 
 static const struct dentry_operations ovl_reval_dentry_operations = {
 	.d_release = ovl_dentry_release,
 	.d_select_inode = ovl_d_select_inode,
+	.d_real = ovl_d_real,
 	.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 8a2e009..9c6a4fd 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_real)(struct dentry *, struct inode *);
 } ____cacheline_aligned;
 
 /*
@@ -228,6 +229,8 @@ struct dentry_operations {
 #define DCACHE_FALLTHRU			0x01000000 /* Fall through to lower layer */
 #define DCACHE_OP_SELECT_INODE		0x02000000 /* Unioned entry: dcache op selects inode */
 
+#define DCACHE_OP_REAL			0x08000000
+
 extern seqlock_t rename_lock;
 
 /*
@@ -582,4 +585,12 @@ static inline struct dentry *d_backing_dentry(struct dentry *upper)
 	return upper;
 }
 
+static inline struct dentry *d_real(struct dentry *dentry)
+{
+	if (unlikely(dentry->d_flags & DCACHE_OP_REAL))
+		return dentry->d_op->d_real(dentry, NULL);
+	else
+		return dentry;
+}
+
 #endif	/* __LINUX_DCACHE_H */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 5f59f86..b675ea0 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1209,6 +1209,16 @@ static inline struct inode *file_inode(const struct file *f)
 	return f->f_inode;
 }
 
+static inline struct dentry *file_dentry(const struct file *file)
+{
+	struct dentry *dentry = file->f_path.dentry;
+
+	if (unlikely(dentry->d_flags & DCACHE_OP_REAL))
+		return dentry->d_op->d_real(dentry, file_inode(file));
+	else
+		return dentry;
+}
+
 static inline int posix_lock_file_wait(struct file *filp, struct file_lock *fl)
 {
 	return posix_lock_inode_wait(file_inode(filp), fl);
-- 
2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[4.2.y-ckt stable] Linux 4.2.8-ckt8 stable review Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 69/70] mwifiex: fix corner case association failure Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 35/70] ext4: ignore quota mount options if the quota feature is enabled Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 64/70] lib/ucs2_string: Correct ucs2 -> utf8 conversion Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 63/70] efi: Add pstore variables to the deletion whitelist Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 65/70] ipr: Fix out-of-bounds null overwrite Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 22/70] USB: cypress_m8: add endpoint sanity check Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 62/70] efi: Make efivarfs entries immutable by default Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 61/70] efi: Make our variable validation list include the guid Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 09/70] hwmon: (max1111) Return -ENODEV from max1111_read_channel if not instantiated Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 70/70] net: phy: at803x: Request 'reset' GPIO only for AT8030 PHY Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:00 +0200
  [PATCH 4.2.y-ckt 42/70] USB: serial: ftdi_sio: Add support for ICP DAS I-756xU devices Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 49/70] parisc: Fix kernel crash with reversed copy_from_user() Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 55/70] pinctrl: nomadik: fix pull debug print inversion Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 38/70] mac80211: properly deal with station hashtable insert errors Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 39/70] compiler-gcc: disable -ftracer for __noclone functions Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 47/70] gpio: pca953x: Use correct u16 value for register word write Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 36/70] xen/events: Mask a moving irq Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 43/70] USB: serial: cp210x: Adding GE Healthcare Device ID Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 41/70] Btrfs: fix file/data loss caused by fsync after rename and new inode Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 33/70] mm: fix invalid node in alloc_migrate_target() Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 57/70] KVM: x86: move steal time initialization to vcpu entry time Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 37/70] usb: renesas_usbhs: fix to avoid using a disabled ep in usbhsg_queue_done() Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 40/70] rbd: use GFP_NOIO consistently for request allocations Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 50/70] parisc: Unbreak handling exceptions from kernel modules Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 52/70] net: bcmgenet: fix dev->stats.tx_bytes accounting Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 31/70] KVM: x86: Inject pending interrupt even if pending nmi exist Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 34/70] iio: st_magn: always define ST_MAGN_TRIGGER_SET_STATE Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 48/70] parisc: Avoid function pointers for kernel exception routines Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 56/70] ip6_tunnel: set rtnl_link_ops before calling register_netdevice Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 45/70] virtio: virtio 1.0 cs04 spec compliance for reset Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 54/70] ipv6: udp: fix UDP_MIB_IGNOREDMULTI updates Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 44/70] USB: option: add "D-Link DWM-221 B1" device id Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:30 +0200
  [PATCH 4.2.y-ckt 30/70] ALSA: hda - fix front mic problem for a HP desktop Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 27/70] drm/dp: move hw_mutex up the call stack Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 08/70] nfs: use file_dentry() Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 24/70] [media] au0828: fix au0828_v4l2_close() dev_state race condition Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 02/70] PKCS#7: pkcs7_validate_trust(): initialize the _trusted output argument Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 16/70] usb: renesas_usbhs: avoid NULL pointer derefernce in usbhsf_pkt_handler() Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 10/70] drm/radeon: add another R7 370 quirk Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 20/70] ALSA: usb-audio: Fix double-free in error paths after snd_usb_add_audio_stream() call Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 05/70] ALSA: hda - Apply fix for white noise on Asus N550JV, too Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 26/70] sd: Fix excessive capacity printing on devices with blocks bigger than 512 bytes Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 23/70] USB: digi_acceleport: do sanity checking for the number of ports Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 32/70] ALSA: timer: Use mod_timer() for rearming the system timer Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 14/70] pinctrl: pistachio: fix mfio84-89 function description and pinmux. Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 15/70] pinctrl: sunxi: Fix A33 external interrupts not working Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 28/70] drm/udl: Use unlocked gem unreferencing Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 03/70] ALSA: hda - Asus N750JV external subwoofer fixup Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 12/70] powerpc/mm: Fixup preempt underflow with huge pages Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 04/70] ALSA: hda - Fix white noise on Asus N750JV headphone Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 18/70] btrfs: fix crash/invalid memory access on fsync when using overlayfs Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 29/70] ext4: add lockdep annotations for i_data_sem Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 11/70] drm/radeon: add a dpm quirk for all R7 370 parts Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 13/70] pinctrl: sh-pfc: only use dummy states for non-DT platforms Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 17/70] usb: renesas_usbhs: disable TX IRQ before starting TX DMAC transfer Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 21/70] USB: mct_u232: add sanity checking in probe Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 25/70] [media] au0828: Fix dev_state handling Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200
  [PATCH 4.2.y-ckt 07/70] fs: add file_dentry() Kamal Mostafa <kamal@canonical.com> - 2016-04-12 23:40 +0200

csiph-web