Subject: bin/3612: mount_union doesn't expand directories to full paths
To: None <gnats-bugs@gnats.netbsd.org>
From: None <nimenees@par0163.urh.uiuc.edu>
List: netbsd-bugs
Date: 05/12/1997 20:36:13
>Number:         3612
>Category:       bin
>Synopsis:       mount_union fails to expand paths causing future unmounts to fail
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 12 18:50:02 1997
>Last-Modified:
>Originator:     Eric Haszlakiewicz
>Organization:
>Release:        1.2E
>Environment:
	Pentium, Current kernel as of 5/12/97.
System: NetBSD par0163.urh.uiuc.edu 1.2E NetBSD 1.2E (REALMS) #59: Thu May 8 13:39:27 CDT 1997 root@par0163.urh.uiuc.edu:/usr/src/sys/arch/i386/compile/REALMS i386


>Description:
	mount_union takes whatever mount point you give it and doesn't
expand it to a full path name.  This causes problems when trying to unmount
it since umount does expand the path name.
	
>How-To-Repeat:
par0163# mkdir abc bbb
par0163# mount_union abc bbb
par0163# mount
/dev/wd0a on / type ffs (local)
/dev/wd0e on /usr type ffs (local)
/dev/wd0f on /dos type msdos (local)
/dev/wd1a on /emul/freebsd type ffs (local)
/dev/wd1e on /emul/freebsd/usr type ffs (local)
<above>:/u/abc on bbb type union (local)
par0163# umount bbb
umount: /u/bbb: not currently mounted
par0163# 

>Fix:
	This seems to solve the problem.

*** mount_union.c.old   Mon May 12 17:26:24 1997
--- mount_union.c       Mon May 12 17:33:56 1997
*************** main(argc, argv)
*** 79,84 ****
--- 79,85 ----
        struct union_args args;
        int ch, mntflags;
        char target[MAXPATHLEN];
+       char mntpath[MAXPATHLEN];
  
        mntflags = 0;
        args.mntflags = UNMNT_ABOVE;
*************** main(argc, argv)
*** 109,121 ****
        if (realpath(argv[0], target) == 0)
                err(1, "%s", target);
  
!       if (subdir(target, argv[1]) || subdir(argv[1], target))
!               errx(1, "%s (%s) and %s are not distinct paths",
!                   argv[0], target, argv[1]);
  
        args.target = target;
  
!       if (mount(MOUNT_UNION, argv[1], mntflags, &args))
                err(1, NULL);
        exit(0);
  }
--- 110,125 ----
        if (realpath(argv[0], target) == 0)
                err(1, "%s", target);
  
!       if (realpath(argv[1], mntpath) == 0)
!               err(1, "realpath %s", argv[1]);
! 
!       if (subdir(target, mntpath) || subdir(mntpath, target))
!               errx(1, "%s (%s) and %s (%s) are not distinct paths",
!                   argv[0], target, argv[1], mntpath);
  
        args.target = target;
  
!       if (mount(MOUNT_UNION, mntpath, mntflags, &args))
                err(1, NULL);
        exit(0);
  }

>Audit-Trail:
>Unformatted: