From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Dmitry Safonov <dima@arista.com>,
Amir Goldstein <amir73il@gmail.com>,
Christian Brauner <brauner@kernel.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6 67/72] ovl: support encoding fid from inode with no alias
Date: Tue, 21 Jan 2025 18:52:33 +0100 [thread overview]
Message-ID: <20250121174526.015766656@linuxfoundation.org> (raw)
In-Reply-To: <20250121174523.429119852@linuxfoundation.org>
6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <amir73il@gmail.com>
commit c45beebfde34aa71afbc48b2c54cdda623515037 upstream.
Dmitry Safonov reported that a WARN_ON() assertion can be trigered by
userspace when calling inotify_show_fdinfo() for an overlayfs watched
inode, whose dentry aliases were discarded with drop_caches.
The WARN_ON() assertion in inotify_show_fdinfo() was removed, because
it is possible for encoding file handle to fail for other reason, but
the impact of failing to encode an overlayfs file handle goes beyond
this assertion.
As shown in the LTP test case mentioned in the link below, failure to
encode an overlayfs file handle from a non-aliased inode also leads to
failure to report an fid with FAN_DELETE_SELF fanotify events.
As Dmitry notes in his analyzis of the problem, ovl_encode_fh() fails
if it cannot find an alias for the inode, but this failure can be fixed.
ovl_encode_fh() seldom uses the alias and in the case of non-decodable
file handles, as is often the case with fanotify fid info,
ovl_encode_fh() never needs to use the alias to encode a file handle.
Defer finding an alias until it is actually needed so ovl_encode_fh()
will not fail in the common case of FAN_DELETE_SELF fanotify events.
Fixes: 16aac5ad1fa9 ("ovl: support encoding non-decodable file handles")
Reported-by: Dmitry Safonov <dima@arista.com>
Closes: https://lore.kernel.org/linux-fsdevel/CAOQ4uxiie81voLZZi2zXS1BziXZCM24nXqPAxbu8kxXCUWdwOg@mail.gmail.com/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/r/20250105162404.357058-3-amir73il@gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/overlayfs/export.c | 46 +++++++++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 21 deletions(-)
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -181,35 +181,37 @@ static int ovl_connect_layer(struct dent
*
* Return 0 for upper file handle, > 0 for lower file handle or < 0 on error.
*/
-static int ovl_check_encode_origin(struct dentry *dentry)
+static int ovl_check_encode_origin(struct inode *inode)
{
- struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
+ struct ovl_fs *ofs = OVL_FS(inode->i_sb);
bool decodable = ofs->config.nfs_export;
+ struct dentry *dentry;
+ int err;
/* No upper layer? */
if (!ovl_upper_mnt(ofs))
return 1;
/* Lower file handle for non-upper non-decodable */
- if (!ovl_dentry_upper(dentry) && !decodable)
+ if (!ovl_inode_upper(inode) && !decodable)
return 1;
/* Upper file handle for pure upper */
- if (!ovl_dentry_lower(dentry))
+ if (!ovl_inode_lower(inode))
return 0;
/*
* Root is never indexed, so if there's an upper layer, encode upper for
* root.
*/
- if (dentry == dentry->d_sb->s_root)
+ if (inode == d_inode(inode->i_sb->s_root))
return 0;
/*
* Upper decodable file handle for non-indexed upper.
*/
- if (ovl_dentry_upper(dentry) && decodable &&
- !ovl_test_flag(OVL_INDEX, d_inode(dentry)))
+ if (ovl_inode_upper(inode) && decodable &&
+ !ovl_test_flag(OVL_INDEX, inode))
return 0;
/*
@@ -218,17 +220,25 @@ static int ovl_check_encode_origin(struc
* ovl_connect_layer() will try to make origin's layer "connected" by
* copying up a "connectable" ancestor.
*/
- if (d_is_dir(dentry) && decodable)
- return ovl_connect_layer(dentry);
+ if (!decodable || !S_ISDIR(inode->i_mode))
+ return 1;
+
+ dentry = d_find_any_alias(inode);
+ if (!dentry)
+ return -ENOENT;
+
+ err = ovl_connect_layer(dentry);
+ dput(dentry);
+ if (err < 0)
+ return err;
/* Lower file handle for indexed and non-upper dir/non-dir */
return 1;
}
-static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct dentry *dentry,
+static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct inode *inode,
u32 *fid, int buflen)
{
- struct inode *inode = d_inode(dentry);
struct ovl_fh *fh = NULL;
int err, enc_lower;
int len;
@@ -237,7 +247,7 @@ static int ovl_dentry_to_fid(struct ovl_
* Check if we should encode a lower or upper file handle and maybe
* copy up an ancestor to make lower file handle connectable.
*/
- err = enc_lower = ovl_check_encode_origin(dentry);
+ err = enc_lower = ovl_check_encode_origin(inode);
if (enc_lower < 0)
goto fail;
@@ -257,8 +267,8 @@ out:
return err;
fail:
- pr_warn_ratelimited("failed to encode file handle (%pd2, err=%i)\n",
- dentry, err);
+ pr_warn_ratelimited("failed to encode file handle (ino=%lu, err=%i)\n",
+ inode->i_ino, err);
goto out;
}
@@ -266,19 +276,13 @@ static int ovl_encode_fh(struct inode *i
struct inode *parent)
{
struct ovl_fs *ofs = OVL_FS(inode->i_sb);
- struct dentry *dentry;
int bytes, buflen = *max_len << 2;
/* TODO: encode connectable file handles */
if (parent)
return FILEID_INVALID;
- dentry = d_find_any_alias(inode);
- if (!dentry)
- return FILEID_INVALID;
-
- bytes = ovl_dentry_to_fid(ofs, dentry, fid, buflen);
- dput(dentry);
+ bytes = ovl_dentry_to_fid(ofs, inode, fid, buflen);
if (bytes <= 0)
return FILEID_INVALID;
next prev parent reply other threads:[~2025-01-21 17:56 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 17:51 [PATCH 6.6 00/72] 6.6.74-rc1 review Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 01/72] net: ethernet: ti: cpsw_ale: Fix cpsw_ale_get_field() Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 02/72] bpf: Fix bpf_sk_select_reuseport() memory leak Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 03/72] openvswitch: fix lockup on tx to unregistering netdev with carrier Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 04/72] pktgen: Avoid out-of-bounds access in get_imix_entries Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 05/72] net: add exit_batch_rtnl() method Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 06/72] gtp: use " Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 07/72] gtp: Use for_each_netdev_rcu() in gtp_genl_dump_pdp() Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 08/72] gtp: Destroy device along with udp sockets netns dismantle Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 09/72] nfp: bpf: prevent integer overflow in nfp_bpf_event_output() Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 10/72] net: xilinx: axienet: Fix IRQ coalescing packet count overflow Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 11/72] net: fec: handle page_pool_dev_alloc_pages error Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 12/72] net/mlx5: Fix RDMA TX steering prio Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 13/72] net/mlx5: Clear port select structure when fail to create Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 14/72] net/mlx5e: Fix inversion dependency warning while enabling IPsec tunnel Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 15/72] net/mlx5e: Rely on reqid in IPsec tunnel mode Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 16/72] net/mlx5e: Always start IPsec sequence number from 1 Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 17/72] drm/vmwgfx: Add new keep_resv BO param Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 18/72] drm/v3d: Ensure job pointer is set to NULL after job completion Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 19/72] soc: ti: pruss: Fix pruss APIs Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 20/72] hwmon: (tmp513) Fix division of negative numbers Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 21/72] Revert "mtd: spi-nor: core: replace dummy buswidth from addr to data" Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 22/72] i2c: mux: demux-pinctrl: check initial mux selection, too Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 23/72] i2c: rcar: fix NACK handling when being a target Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 24/72] smb: client: fix double free of TCP_Server_Info::hostname Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 25/72] mac802154: check local interfaces before deleting sdata list Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 26/72] hfs: Sanity check the root record Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 27/72] fs: fix missing declaration of init_files Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 28/72] kheaders: Ignore silly-rename files Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 29/72] cachefiles: Parse the "secctx" immediately Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 30/72] scsi: ufs: core: Honor runtime/system PM levels if set by host controller drivers Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 31/72] selftests: tc-testing: reduce rshift value Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 32/72] ACPI: resource: acpi_dev_irq_override(): Check DMI match last Greg Kroah-Hartman
2025-01-21 17:51 ` [PATCH 6.6 33/72] iomap: avoid avoid truncating 64-bit offset to 32 bits Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 34/72] poll_wait: add mb() to fix theoretical race between waitqueue_active() and .poll() Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 35/72] RDMA/bnxt_re: Fix to export port num to ib_query_qp Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 36/72] nvmet: propagate npwg topology Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 37/72] x86/asm: Make serialize() always_inline Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 38/72] ALSA: hda/realtek: Add support for Ayaneo System using CS35L41 HDA Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 39/72] zram: fix potential UAF of zram table Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 40/72] i2c: atr: Fix client detach Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 41/72] mptcp: be sure to send ack when mptcp-level window re-opens Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 42/72] mptcp: fix spurious wake-up on under memory pressure Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 43/72] selftests: mptcp: avoid spurious errors on disconnect Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 44/72] net: ethernet: xgbe: re-add aneg to supported features in PHY quirks Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 45/72] vsock/bpf: return early if transport is not assigned Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 46/72] vsock/virtio: discard packets if the transport changes Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 47/72] vsock/virtio: cancel close work in the destructor Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 48/72] vsock: reset socket state when de-assigning the transport Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 49/72] vsock: prevent null-ptr-deref in vsock_*[has_data|has_space] Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 50/72] nouveau/fence: handle cross device fences properly Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 51/72] filemap: avoid truncating 64-bit offset to 32 bits Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 52/72] fs/proc: fix softlockup in __read_vmcore (part 2) Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 53/72] gpio: xilinx: Convert gpio_lock to raw spinlock Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 54/72] pmdomain: imx8mp-blk-ctrl: add missing loop break condition Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 55/72] irqchip: Plug a OF node reference leak in platform_irqchip_probe() Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 56/72] irqchip/gic-v3: Handle CPU_PM_ENTER_FAILED correctly Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 57/72] irqchip/gic-v3-its: Dont enable interrupts in its_irq_set_vcpu_affinity() Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 58/72] hrtimers: Handle CPU state correctly on hotplug Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 59/72] drm/i915/fb: Relax clear color alignment to 64 bytes Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 60/72] drm/amdgpu: always sync the GFX pipe on ctx switch Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 61/72] Revert "PCI: Use preserve_config in place of pci_flags" Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 62/72] iio: imu: inv_icm42600: fix spi burst write not supported Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 63/72] drm/amd/display: Fix out-of-bounds access in dcn21_link_encoder_create Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 64/72] block: fix uaf for flush rq while iterating tags Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 65/72] ocfs2: fix deadlock in ocfs2_get_system_file_inode Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 66/72] ovl: pass realinode to ovl_encode_real_fh() instead of realdentry Greg Kroah-Hartman
2025-01-21 17:52 ` Greg Kroah-Hartman [this message]
2025-01-21 17:52 ` [PATCH 6.6 68/72] fs: relax assertions on failure to encode file handles Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 69/72] Revert "drm/amdgpu: rework resume handling for display (v2)" Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 70/72] nfsd: add list_head nf_gc to struct nfsd_file Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 71/72] x86/xen: fix SLS mitigation in xen_hypercall_iret() Greg Kroah-Hartman
2025-01-21 17:52 ` [PATCH 6.6 72/72] net: fix data-races around sk->sk_forward_alloc Greg Kroah-Hartman
2025-01-21 18:57 ` [PATCH 6.6 00/72] 6.6.74-rc1 review Florian Fainelli
2025-01-21 20:41 ` Peter Schneider
2025-01-21 23:35 ` Shuah Khan
2025-01-21 23:47 ` SeongJae Park
2025-01-22 9:25 ` Ron Economos
2025-01-22 12:06 ` Naresh Kamboju
2025-01-22 13:23 ` Jon Hunter
2025-01-22 14:41 ` Muhammad Usama Anjum
2025-01-22 17:04 ` Mark Brown
2025-01-22 20:18 ` [PATCH 6.6] " Hardik Garg
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=20250121174526.015766656@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=dima@arista.com \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/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).