mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: linux-fsdevel@vger.kernel.org
Cc: hch@infradead.org, viro@ZenIV.linux.org.uk,
	linux-kernel@vger.kernel.org, John Johansen <jjohansen@suse.de>
Subject: [patch 2/8] vfs: fix sys_getcwd for detached mounts
Date: Thu, 29 May 2008 13:32:47 +0200	[thread overview]
Message-ID: <20080529113309.365088543@szeredi.hu> (raw)
In-Reply-To: <20080529113245.450308367@szeredi.hu>

[-- Attachment #1: d_path_fix_detached_path.patch --]
[-- Type: text/plain, Size: 1483 bytes --]

From: Miklos Szeredi <mszeredi@suse.cz>

Currently getcwd(2) on a detached mount will give a garbled result:

   > mkdir /mnt/foo
   > mount --bind /etc /mnt/foo
   > cd /mnt/foo/skel
   > /bin/pwd
   /mnt/foo/skel
   > umount -l /mnt/foo
   > /bin/pwd
   etcskel

After the patch it will give a much saner "/skel" result.

Thanks to John Johansen for pointing out this bug.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
CC: John Johansen <jjohansen@suse.de>
---
 fs/dcache.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Index: linux-2.6/fs/dcache.c
===================================================================
--- linux-2.6.orig/fs/dcache.c	2008-05-29 12:46:22.000000000 +0200
+++ linux-2.6/fs/dcache.c	2008-05-29 12:46:22.000000000 +0200
@@ -1825,10 +1825,20 @@ char *__d_path(const struct path *path, 
 	return retval;
 
 global_root:
-	retval += 1;	/* hit the slash */
-	name = &dentry->d_name;
-	if (prepend(&retval, &buflen, name->name, name->len) != 0)
-		goto Elong;
+	/*
+	 * If this is a root dentry, then overwrite the slash.  This
+	 * will also DTRT with pseudo filesystems which have root
+	 * dentries named "foo:".
+	 *
+	 * Otherwise this is the root of a detached mount, so don't do
+	 * anything.
+	 */
+	if (IS_ROOT(dentry)) {
+		retval += 1;
+		name = &dentry->d_name;
+		if (prepend(&retval, &buflen, name->name, name->len) != 0)
+			goto Elong;
+	}
 	root->mnt = vfsmnt;
 	root->dentry = dentry;
 	return retval;

--

  parent reply	other threads:[~2008-05-29 11:34 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-29 11:32 [patch 0/8] vfs: more cleanups and fixes Miklos Szeredi
2008-05-29 11:32 ` [patch 1/8] vfs: dcache cleanups Miklos Szeredi
2008-05-29 12:23   ` Matthew Wilcox
2008-05-31  8:18   ` Christoph Hellwig
2008-05-29 11:32 ` Miklos Szeredi [this message]
2008-05-31  8:20   ` [patch 2/8] vfs: fix sys_getcwd for detached mounts Christoph Hellwig
2008-05-29 11:32 ` [patch 3/8] Make d_path() consistent across mount operations Miklos Szeredi
2008-05-31  8:22   ` Christoph Hellwig
2008-06-01 20:38     ` Miklos Szeredi
2008-06-02  5:55       ` Christoph Hellwig
2008-05-29 11:32 ` [patch 4/8] nfsd: rename MAY_ flags Miklos Szeredi
2008-05-29 12:47   ` Christoph Hellwig
2008-05-29 14:02     ` Miklos Szeredi
2008-05-29 20:40       ` J. Bruce Fields
2008-05-30  7:36         ` Christoph Hellwig
2008-05-30  9:07           ` Miklos Szeredi
2008-05-30  9:53             ` Miklos Szeredi
2008-05-30 20:12             ` J. Bruce Fields
2008-05-29 11:32 ` [patch 5/8] vfs: annotate permission operations Miklos Szeredi
2008-05-31  8:23   ` Christoph Hellwig
2008-05-29 11:32 ` [patch 6/8] Factor out sysctl pathname code Miklos Szeredi
2008-05-31  8:27   ` Christoph Hellwig
2008-06-03 13:34     ` Stephen Smalley
2008-05-29 11:32 ` [patch 7/8] vfs: clean up getattr API Miklos Szeredi
2008-05-29 11:32 ` [patch 8/8] vfs: create file_remove_suid() helper Miklos Szeredi
2008-05-31  8:29   ` Christoph Hellwig
2008-06-01 20:45     ` Miklos Szeredi
2008-06-02  6:05       ` Christoph Hellwig
2008-06-02  7:06         ` Miklos Szeredi

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=20080529113309.365088543@szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=hch@infradead.org \
    --cc=jjohansen@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.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

all inboxes | Powered by JetHome®