Bug 114351 - subfs: created wrong mounts in special cases
Summary: subfs: created wrong mounts in special cases
Status: RESOLVED FIXED
Alias: None
Product: SUSE LINUX 10.0
Classification: openSUSE
Component: Basesystem (show other bugs)
Version: Beta 3
Hardware: Other All
: P5 - None : Blocker
Target Milestone: ---
Assignee: Jeff Mahoney
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-31 08:11 UTC by Danny Al-Gaaf
Modified: 2005-09-06 01:59 UTC (History)
3 users (show)

See Also:
Found By: Other
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
fix for subfs attempting to mount devices in detached namespaces (1.08 KB, patch)
2005-09-01 19:44 UTC, Jeff Mahoney
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Danny Al-Gaaf 2005-08-31 08:11:42 UTC
pasted in from mail discussion
----------
When you are in a invalid subfs mount directory (usb stick has been removed, 
plugged in again, but no "cd ." has been made yet) and you trigger the mount, it 
will result into mounting it on /. 

An easy way would be to check for argv[2]=/ in mount_real_fs() inside of the 
subfs module. Or there is there some better way of checking ? Would it be 
possible to avoid the needed "cd ." with some hack in the subfs module ?
----------
Comment 1 Chris L Mason 2005-09-01 01:18:26 UTC
Jeff, here's a subfs blocker for you. 
Comment 2 Jeff Mahoney 2005-09-01 15:54:47 UTC
Hrm. The steps to reproduce seem straightforward enough, but I can't seem to.

My usb stick is named "JEFFM-KEY."

I plug it in, and /media/JEFFM-KEY appears as it should.

I cd into a subdirectory of that, and ls. I wait a few moments, unplug the
stick, and try again. I get "No medium found" if I'm in the subfs root, or just
an empty listing if I'm in a subdirectory.

The mount point is removed. When I re-insert the stick, the mount point is
created again. Of course, since the directory went away, I'm not longer in
"that" directory, so the remount won't occur until I reassess the pathname.

I don't see anything about it getting mounted over /.

Is there something I'm missing in the reproduction?
Comment 3 Danny Al-Gaaf 2005-09-01 16:21:06 UTC
Try this:

- insert usbstick (wait for mount )
- cd /media/JEFFM-KEY
- remove usbstick
- reinsert usbstick
- ls (in /media/JEFFM-KEY)
- cat /proc/mounts (a mount to '/' for the usbstick )

If this not work, play around with ls befor remove stick or befor reinsert, but 
with the way about I can reproduce this here permanently.
Comment 4 Jeff Mahoney 2005-09-01 16:32:15 UTC
Ok, I can see it appearing in /proc/mounts, though it's not actually obscuring
the real / mount. Still, shouldn't be happening.
Comment 5 Danny Al-Gaaf 2005-09-01 16:33:46 UTC
note: in this case (mount to /) the submountd hangs up and try permanently to 
get '/' and access the harddisk every second. I maybe also take a look at 
submountd to prevent this, imo the real problem is the kernel modul which call 
the submountd.
Comment 6 Jeff Mahoney 2005-09-01 19:36:09 UTC
Ok, I understand what's happening here.

When the filesystem is umounted, and the process is chdir'd into the directory,
the tree is detached from the main filesystem hierarchy, creating an isolated
namespace. The path to the "old" mount point no longer exists, even if the
pathname in the filesystem itself does. This is similar to the following:

mkdir foo
cd foo
rmdir ../foo

I think a point of confusion is that bash's built-in 'pwd' command plays tricks
and remembers the pathname internally. That's why "cd ." works. Since the kernel
doesn't play such tricks, a chdir(2) call will not end up with the same results.

jeffm@speedracer:/media/JEFFM-KEY> /bin/pwd
/media/JEFFM-KEY
<remove stick>
jeffm@speedracer:/media/JEFFM-KEY> /bin/pwd
/

The second pwd shows that the process thinks it's in the root of an entirely
separate namespace. The processes "root" is actually still the root of the
"real" namespace. Unfortunately, there is no way to make the connection between
the two namespaces, since that link was severed when the namespace was detached.

I can detect this condition in the kernel, but since I can't re-establish the
pathname, there is no way of mounting the filesystem at the correct mount point.

I can cache it when there is a valid lookup -- but this violates one of the
tenets of Linux filesystem design: filesystem code shouldn't care where it's
mounted. I would very much not like to do this.

I think the correct answer is to detect the condition and fail the mount with
-ENOENT, the same as if a user tried creating a new object under the deleted
directory in the first example cited. The user can access the full pathname and
cause the mount to succeed.
Comment 7 Jeff Mahoney 2005-09-01 19:44:29 UTC
Created attachment 48528 [details]
fix for subfs attempting to mount devices in detached namespaces

This patch fixes subfs so that it doesn't attempt to mount filesystems in a
detached namespace.

It returns -ENOENT, similar to how the following condition would be handled:

speedracer:/mnt # mkdir foo
speedracer:/mnt # cd foo
speedracer:/mnt/foo # rmdir ../foo
speedracer:/mnt/foo # mount /dev/sdf1 .
mount: No such file or directory
speedracer:/mnt/foo #
Comment 8 Andreas Jaeger 2005-09-03 15:18:51 UTC
HAs this fix been committed to our kernel?  Can this bug get closed?
Comment 9 Jeff Mahoney 2005-09-06 01:59:10 UTC
Committed.