2008-06-23 16:13:22

by Miklos Szeredi

[permalink] [raw]
Subject: [patch 3/3] vfs: fix sys_getcwd for detached mounts

From: Miklos Szeredi <[email protected]>

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 "detached:skel" as result.

Thanks to John Johansen for pointing out this bug.

Comment from Al Viro: use "detached:" prefix to differentiate it from
attached paths.

Reported-by: John Johansen <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
---
fs/dcache.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

Index: linux-2.6/fs/dcache.c
===================================================================
--- linux-2.6.orig/fs/dcache.c 2008-06-23 17:35:39.000000000 +0200
+++ linux-2.6/fs/dcache.c 2008-06-23 17:46:05.000000000 +0200
@@ -1828,8 +1828,16 @@ char *__d_path(const struct path *path,

global_root:
retval += 1; /* hit the slash */
- if (prepend_name(&retval, &buflen, &dentry->d_name) != 0)
- goto Elong;
+
+ if (IS_ROOT(dentry)) {
+ /* Attached, or pseudo filesystem with "foo:" prefix */
+ if (prepend_name(&retval, &buflen, &dentry->d_name) != 0)
+ goto Elong;
+ } else {
+ /* Detached */
+ if (prepend(&retval, &buflen, "detached:", 9) != 0)
+ goto Elong;
+ }
root->mnt = vfsmnt;
root->dentry = dentry;
return retval;

--


2008-06-23 16:53:21

by Miklos Szeredi

[permalink] [raw]
Subject: Re: [patch 3/3] vfs: fix sys_getcwd for detached mounts

> From: Miklos Szeredi <[email protected]>
>
> 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 "detached:skel" as result.
>
> Thanks to John Johansen for pointing out this bug.
>
> Comment from Al Viro: use "detached:" prefix to differentiate it from
> attached paths.
>
> Reported-by: John Johansen <[email protected]>
> Signed-off-by: Miklos Szeredi <[email protected]>
> ---
> fs/dcache.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> Index: linux-2.6/fs/dcache.c
> ===================================================================
> --- linux-2.6.orig/fs/dcache.c 2008-06-23 17:35:39.000000000 +0200
> +++ linux-2.6/fs/dcache.c 2008-06-23 17:46:05.000000000 +0200
> @@ -1828,8 +1828,16 @@ char *__d_path(const struct path *path,
>
> global_root:
> retval += 1; /* hit the slash */
> - if (prepend_name(&retval, &buflen, &dentry->d_name) != 0)
> - goto Elong;
> +
> + if (IS_ROOT(dentry)) {
> + /* Attached, or pseudo filesystem with "foo:" prefix */
> + if (prepend_name(&retval, &buflen, &dentry->d_name) != 0)
> + goto Elong;
> + } else {
> + /* Detached */
> + if (prepend(&retval, &buflen, "detached:", 9) != 0)
> + goto Elong;
> + }
> root->mnt = vfsmnt;
> root->dentry = dentry;
> return retval;
>
> --
>

Darn, this is wrong. It should be looking at vfsmnt->mnt_namespace ==
NULL.

Fixed patch coming up.

Miklos

2008-06-23 16:58:24

by Miklos Szeredi

[permalink] [raw]
Subject: Re: [patch 3/3] vfs: fix sys_getcwd for detached mounts

> Darn, this is wrong. It should be looking at vfsmnt->mnt_namespace ==
> NULL.
>
> Fixed patch coming up.

And the thing is: getcwd() did return garbage for detached mounts,
except if the mounted dentry was the root of the filesystem. Which
makes the "detached:..." change slightly prone to breaking something.
Still not very likely, but...

Miklos