Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[patch 2/8] vfs: fix sys_getcwd for detached mounts

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


miklos at szeredi

May 29, 2008, 4:32 AM

Post #1 of 2 (469 views)
Permalink
[patch 2/8] vfs: fix sys_getcwd for detached mounts

From: Miklos Szeredi <mszeredi [at] suse>

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 [at] suse>
CC: John Johansen <jjohansen [at] suse>
---
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;

--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


hch at infradead

May 31, 2008, 1:20 AM

Post #2 of 2 (405 views)
Permalink
Re: [patch 2/8] vfs: fix sys_getcwd for detached mounts [In reply to]

On Thu, May 29, 2008 at 01:32:47PM +0200, Miklos Szeredi wrote:
> From: Miklos Szeredi <mszeredi [at] suse>
>
> 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.

I'm not sure just cuttinig of the prefix is perfect, but the previous
behvaiour is obviously completely wrong, and the change is simple
enough. So okay from me.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.