From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sahitya Tummala <stummala@codeaurora.org>,
Christoph Hellwig <hch@lst.de>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.4 08/13] configfs: Fix use-after-free when accessing sd->s_dentry
Date: Sat, 8 Jun 2019 07:48:40 -0400 [thread overview]
Message-ID: <20190608114847.9973-8-sashal@kernel.org> (raw)
In-Reply-To: <20190608114847.9973-1-sashal@kernel.org>
From: Sahitya Tummala <stummala@codeaurora.org>
[ Upstream commit f6122ed2a4f9c9c1c073ddf6308d1b2ac10e0781 ]
In the vfs_statx() context, during path lookup, the dentry gets
added to sd->s_dentry via configfs_attach_attr(). In the end,
vfs_statx() kills the dentry by calling path_put(), which invokes
configfs_d_iput(). Ideally, this dentry must be removed from
sd->s_dentry but it doesn't if the sd->s_count >= 3. As a result,
sd->s_dentry is holding reference to a stale dentry pointer whose
memory is already freed up. This results in use-after-free issue,
when this stale sd->s_dentry is accessed later in
configfs_readdir() path.
This issue can be easily reproduced, by running the LTP test case -
sh fs_racer_file_list.sh /config
(https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/fs/racer/fs_racer_file_list.sh)
Fixes: 76ae281f6307 ('configfs: fix race between dentry put and lookup')
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/configfs/dir.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index a7a1b218f308..8e709b641b55 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -58,15 +58,13 @@ static void configfs_d_iput(struct dentry * dentry,
if (sd) {
/* Coordinate with configfs_readdir */
spin_lock(&configfs_dirent_lock);
- /* Coordinate with configfs_attach_attr where will increase
- * sd->s_count and update sd->s_dentry to new allocated one.
- * Only set sd->dentry to null when this dentry is the only
- * sd owner.
- * If not do so, configfs_d_iput may run just after
- * configfs_attach_attr and set sd->s_dentry to null
- * even it's still in use.
+ /*
+ * Set sd->s_dentry to null only when this dentry is the one
+ * that is going to be killed. Otherwise configfs_d_iput may
+ * run just after configfs_attach_attr and set sd->s_dentry to
+ * NULL even it's still in use.
*/
- if (atomic_read(&sd->s_count) <= 2)
+ if (sd->s_dentry == dentry)
sd->s_dentry = NULL;
spin_unlock(&configfs_dirent_lock);
--
2.20.1
next prev parent reply other threads:[~2019-06-08 11:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-08 11:48 [PATCH AUTOSEL 4.4 01/13] mISDN: make sure device name is NUL terminated Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 02/13] x86/CPU/AMD: Don't force the CPB cap when running under a hypervisor Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 03/13] perf/ring_buffer: Fix exposing a temporarily decreased data_head Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 04/13] perf/ring_buffer: Add ordering to rb->nest increment Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 05/13] gpio: fix gpio-adp5588 build errors Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 06/13] net: tulip: de4x5: Drop redundant MODULE_DEVICE_TABLE() Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 07/13] i2c: dev: fix potential memory leak in i2cdev_ioctl_rdwr Sasha Levin
2019-06-08 11:48 ` Sasha Levin [this message]
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 09/13] ia64: fix build errors by exporting paddr_to_nid() Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 10/13] KVM: PPC: Book3S: Use new mutex to synchronize access to rtas token list Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 11/13] net: sh_eth: fix mdio access in sh_eth_close() for R-Car Gen2 and RZ/A1 SoCs Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 12/13] scsi: libcxgbi: add a check for NULL pointer in cxgbi_check_route() Sasha Levin
2019-06-08 11:48 ` [PATCH AUTOSEL 4.4 13/13] scsi: libsas: delete sas port if expander discover failed Sasha Levin
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=20190608114847.9973-8-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stummala@codeaurora.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
Powered by JetHome