From: Maneesh Soni <maneesh@in.ibm.com>
To: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>
Cc: LKML <linux-kernel@vger.kernel.org>,
Dipankar Sarma <dipankar@in.ibm.com>,
Andrew Morton <akpm@osdl.org>
Subject: [PATCH 2.6] is_subdir-fix
Date: Wed, 28 Jan 2004 10:50:29 +0530 [thread overview]
Message-ID: <20040128052029.GA1285@in.ibm.com> (raw)
o The following patch fixes is_subdir() races with d_move. Due to concurrent
d_move, in is_subdir() we can end up accessing freed d_parent pointer in
case of pre-emptible kernel. To avoid this we can use rcu_read_lock() and
rcu_read_unlock().
o This also fixes the seqlock uses in is_subdir() as we need to restart the
the inner loop with the origianl new_dentry passed to the routine in case
of any rename occured while we are traversing d_parent links.
fs/dcache.c | 9 +++++++++
1 files changed, 9 insertions(+)
diff -puN fs/dcache.c~is_subdir-fix fs/dcache.c
--- linux-2.6.2-rc2/fs/dcache.c~is_subdir-fix 2004-01-27 22:38:17.000000000 +0530
+++ linux-2.6.2-rc2-maneesh/fs/dcache.c 2004-01-27 23:43:17.000000000 +0530
@@ -1429,15 +1429,23 @@ out:
*
* Returns 1 if new_dentry is a subdirectory of the parent (at any depth).
* Returns 0 otherwise.
+ * Caller must ensure that "new_dentry" is pinned before calling is_subdir()
*/
int is_subdir(struct dentry * new_dentry, struct dentry * old_dentry)
{
int result;
+ struct dentry * saved = new_dentry;
unsigned long seq;
result = 0;
+ /* need rcu_readlock to protect against the d_parent trashing due to
+ * d_move
+ */
+ rcu_read_lock();
do {
+ /* for restarting inner loop in case of seq retry */
+ new_dentry = saved;
seq = read_seqbegin(&rename_lock);
for (;;) {
if (new_dentry != old_dentry) {
@@ -1451,6 +1459,7 @@ int is_subdir(struct dentry * new_dentry
break;
}
} while (read_seqretry(&rename_lock, seq));
+ rcu_read_unlock();
return result;
}
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-5044999 Fax: 91-80-5268553
T/L : 9243696
reply other threads:[~2004-01-28 5:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20040128052029.GA1285@in.ibm.com \
--to=maneesh@in.ibm.com \
--cc=akpm@osdl.org \
--cc=dipankar@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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