From nobody@FreeBSD.org  Thu Aug  7 02:30:41 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 406E6106567C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  7 Aug 2008 02:30:41 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 2E8FF8FC27
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  7 Aug 2008 02:30:41 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m772UfmF065404
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 7 Aug 2008 02:30:41 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m772UeIX065403;
	Thu, 7 Aug 2008 02:30:40 GMT
	(envelope-from nobody)
Message-Id: <200808070230.m772UeIX065403@www.freebsd.org>
Date: Thu, 7 Aug 2008 02:30:40 GMT
From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch]  rc.d/tmp: Prevent mounting /tmp in second time
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         126324
>Category:       bin
>Synopsis:       [patch]  rc.d/tmp: Prevent mounting /tmp in second time
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-rc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 07 02:40:01 UTC 2008
>Closed-Date:    Wed Oct 31 09:48:24 UTC 2012
>Last-Modified:  Wed Oct 31 09:48:24 UTC 2012
>Originator:     Alex Kozlov
>Release:        FreeBSD 6.3
>Organization:
private
>Environment:
>Description:
Prevent mounting /tmp in second time after switching to singleuser and back.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: src/etc/rc.d/tmp
@@ -43,6 +43,7 @@
 #
 case "${tmpmfs}" in
 [Yy][Ee][Ss])
+	/sbin/umount /tmp 2>/dev/null && echo /tmp was already mounted!
 	mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 	chmod 01777 /tmp
 	;;
@@ -57,6 +58,7 @@
 			echo "dropping into shell, ^D to continue anyway."
 			/bin/sh
 		else
+			/sbin/umount /tmp 2>/dev/null && echo /tmp was already mounted!
 			mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 			chmod 01777 /tmp
 		fi


>Release-Note:
>Audit-Trail:

From: Kris Kennaway <kris@FreeBSD.org>
To: Alex Kozlov <spam@rm-rf.kiev.ua>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/126324: [patch] rc.d/tmp: Prevent mounting /tmp in second
 time
Date: Thu, 07 Aug 2008 12:34:41 +0200

 Alex Kozlov wrote:
 
 > Index: src/etc/rc.d/tmp
 > @@ -43,6 +43,7 @@
 >  #
 >  case "${tmpmfs}" in
 >  [Yy][Ee][Ss])
 > +	/sbin/umount /tmp 2>/dev/null && echo /tmp was already mounted!
 >  	mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 >  	chmod 01777 /tmp
 >  	;;
 > @@ -57,6 +58,7 @@
 >  			echo "dropping into shell, ^D to continue anyway."
 >  			/bin/sh
 >  		else
 > +			/sbin/umount /tmp 2>/dev/null && echo /tmp was already mounted!
 >  			mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 >  			chmod 01777 /tmp
 >  		fi
 
 This will destroy any files the admin may have deliberately created on 
 /tmp after dropping to single user mode.
 
 Kris

From: Kris Kennaway <kris@FreeBSD.org>
To: Kris Kennaway <kris@FreeBSD.org>
Cc: Alex Kozlov <spam@rm-rf.kiev.ua>, freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/126324: [patch] rc.d/tmp: Prevent mounting /tmp in second
 time
Date: Thu, 07 Aug 2008 12:35:43 +0200

 Kris Kennaway wrote:
 > Alex Kozlov wrote:
 > 
 >> Index: src/etc/rc.d/tmp
 >> @@ -43,6 +43,7 @@
 >>  #
 >>  case "${tmpmfs}" in
 >>  [Yy][Ee][Ss])
 >> +    /sbin/umount /tmp 2>/dev/null && echo /tmp was already mounted!
 >>      mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 >>      chmod 01777 /tmp
 >>      ;;
 >> @@ -57,6 +58,7 @@
 >>              echo "dropping into shell, ^D to continue anyway."
 >>              /bin/sh
 >>          else
 >> +            /sbin/umount /tmp 2>/dev/null && echo /tmp was already 
 >> mounted!
 >>              mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 >>              chmod 01777 /tmp
 >>          fi
 > 
 > This will destroy any files the admin may have deliberately created on 
 > /tmp after dropping to single user mode.
 
 Er, coffee hadn't kicked in.  That will only happen with tmpfs which 
 isn't used yet.  Still, a better solution might keep that in mind to 
 avoid introducing a bug later.
 
 Kris

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: Kris Kennaway <kris@FreeBSD.org>, bug-followup@freebsd.org,
	spam@rm-rf.kiev.ua
Cc:  
Subject: Re: bin/126324: [patch] rc.d/tmp: Prevent mounting /tmp in second
	time
Date: Thu, 7 Aug 2008 19:57:53 +0300

 On Thu, Aug 07, 2008 at 12:35:43PM +0200, Kris Kennaway wrote:
 > Kris Kennaway wrote:
 > > Alex Kozlov wrote:
 > > 
 > >> Index: src/etc/rc.d/tmp
 > >> @@ -43,6 +43,7 @@
 > >>  #
 > >>  case "${tmpmfs}" in
 > >>  [Yy][Ee][Ss])
 > >> +    /sbin/umount /tmp 2>/dev/null && echo /tmp was already mounted!
 > >>      mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 > >>      chmod 01777 /tmp
 > >>      ;;
 > >> @@ -57,6 +58,7 @@
 > >>              echo "dropping into shell, ^D to continue anyway."
 > >>              /bin/sh
 > >>          else
 > >> +            /sbin/umount /tmp 2>/dev/null && echo /tmp was already 
 > >> mounted!
 > >>              mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 > >>              chmod 01777 /tmp
 > >>          fi
 > > 
 > > This will destroy any files the admin may have deliberately created on 
 > > /tmp after dropping to single user mode.
 > 
 > Er, coffee hadn't kicked in.  That will only happen with tmpfs which 
 > isn't used yet.  Still, a better solution might keep that in mind to 
 > avoid introducing a bug later.
 Well, as alternative We can just don't touch /tmp if it already mounted.
 This also prevent md device leak at least until bin/114468 will be
 resolved.
 
 
 --
 Adios

From: Kris Kennaway <kris@FreeBSD.org>
To: Alex Kozlov <spam@rm-rf.kiev.ua>
Cc: bug-followup@freebsd.org
Subject: Re: bin/126324: [patch] rc.d/tmp: Prevent mounting /tmp in second
 time
Date: Thu, 07 Aug 2008 19:25:49 +0200

 Alex Kozlov wrote:
 
 > Well, as alternative We can just don't touch /tmp if it already mounted.
 
 This is much better on general grounds.
 
 > This also prevent md device leak at least until bin/114468 will be
 > resolved.
 
 I don't like that PR since it introduces a layering violation, and 
 doesn't come with a justification of why it is necessary.
 
 Utilities that operate on filesystems shouldn't have knowledge about a 
 particular kind of backing store.
 
 Kris

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: Kris Kennaway <kris@FreeBSD.org>, bug-followup@freebsd.org,
	spam@rm-rf.kiev.ua
Cc:  
Subject: Re: bin/126324: [patch] rc.d/tmp: Prevent mounting /tmp in second
	time
Date: Thu, 7 Aug 2008 21:49:03 +0300

 On Thu, Aug 07, 2008 at 07:25:49PM +0200, Kris Kennaway wrote:
 > Alex Kozlov wrote:
 > 
 > > Well, as alternative We can just don't touch /tmp if it already mounted.
 > This is much better on general grounds.
 I post patch for review soon.
 
 > > This also prevent md device leak at least until bin/114468 will be
 > > resolved.
 > 
 > I don't like that PR since it introduces a layering violation, and 
 > doesn't come with a justification of why it is necessary.
 > 
 > Utilities that operate on filesystems shouldn't have knowledge about a 
 > particular kind of backing store.
 I agree that this solution is a little ugly but also true that We need
 a simple way to garbage collect md devices.
 
 Current way is even more ugly:
 md=$(mount |grep ${mp}|cut -f1 -d' '); umount ${mp}; mdconfig -d -u ${md}
 
 
 --
 Adios
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Thu Aug 7 19:36:37 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer(s).  Deliberately don't reclassify as conf for 
now as discussions are currently ongoing. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=126324 

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: Kris Kennaway <kris@FreeBSD.org>, bug-followup@freebsd.org,
	spam@rm-rf.kiev.ua
Cc:  
Subject: Re: bin/126324: [patch] rc.d/tmp: Prevent mounting /tmp in second
	time
Date: Fri, 8 Aug 2008 03:25:19 +0300

 On Thu, Aug 07, 2008 at 06:50:06PM +0000, Alex Kozlov wrote:
 > The following reply was made to PR bin/126324; it has been noted by GNATS.
 > 
 > From: Alex Kozlov <spam@rm-rf.kiev.ua>
 > To: Kris Kennaway <kris@FreeBSD.org>, bug-followup@freebsd.org,
 >   spam@rm-rf.kiev.ua
 > Cc:  
 > Subject: Re: bin/126324: [patch] rc.d/tmp: Prevent mounting /tmp in second
 >   time
 > Date: Thu, 7 Aug 2008 21:49:03 +0300
 > 
 >  On Thu, Aug 07, 2008 at 07:25:49PM +0200, Kris Kennaway wrote:
 >  > Alex Kozlov wrote:
 >  > 
 >  > > Well, as alternative We can just don't touch /tmp if it already mounted.
 >  > This is much better on general grounds.
 >  I post patch for review soon.
 
 Index: src/etc/rc.d/tmp
 @@ -37,13 +37,20 @@
 
  load_rc_config $name
 
 +is_mounted ()
 +{
 +   /sbin/mount | /usr/bin/grep -ql $1 && return 0
 +   return 1
 +}
 +
  # If we do not have a writable /tmp, create a memory
  # filesystem for /tmp.  If /tmp is a symlink (e.g. to /var/tmp,
 -# then it should already be writable).
 +# then it should already be writable). If we already have /tmp
 +# mounted somewhere, doing nothing.
  #
  case "${tmpmfs}" in
  [Yy][Ee][Ss])
 -   mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 +   is_mounted /tmp || mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
     chmod 01777 /tmp
     ;;
  [Nn][Oo])
 @@ -57,7 +64,7 @@
             echo "dropping into shell, ^D to continue anyway."
             /bin/sh
         else
 -           mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
 +           is_mounted /tmp || mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
             chmod 01777 /tmp
         fi
     fi

From: Alex Kozlov <spam@rm-rf.kiev.ua>
To: bug-followup@freebsd.org, spam@rm-rf.kiev.ua
Cc:  
Subject: Re: bin/126324: [patch]  rc.d/tmp: Prevent mounting /tmp in second
 time
Date: Mon, 18 Jan 2010 05:52:18 +0200

 Hi
 
 Similiar patch was applied in r192246, so this pr can be closed.
 
 
 --
 Adios
State-Changed-From-To: open->patched 
State-Changed-By: jh 
State-Changed-When: Fri Mar 5 06:06:26 UTC 2010 
State-Changed-Why:  
Fixed in r192246. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=126324 
State-Changed-From-To: patched->closed 
State-Changed-By: crees 
State-Changed-When: Wed Oct 31 09:48:23 UTC 2012 
State-Changed-Why:  
192246 was 8-CURRENT, and merged to stable/7 in r221224 

http://www.freebsd.org/cgi/query-pr.cgi?pr=126324 
>Unformatted:
