From nobody@FreeBSD.org  Sun Mar 16 15:16:09 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 9ACC41065670
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 16 Mar 2008 15:16:09 +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 A64908FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 16 Mar 2008 15:16:09 +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 m2GFCiMR051458
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 16 Mar 2008 15:12:44 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m2GFCiP1051457;
	Sun, 16 Mar 2008 15:12:44 GMT
	(envelope-from nobody)
Message-Id: <200803161512.m2GFCiP1051457@www.freebsd.org>
Date: Sun, 16 Mar 2008 15:12:44 GMT
From: Richard Arends <richard@unixguru.nl>
To: freebsd-gnats-submit@FreeBSD.org
Subject: TinyBSD remove_workdir function needs some extra checking for existing mounts
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         121763
>Category:       misc
>Synopsis:       TinyBSD remove_workdir function needs some extra checking for existing mounts
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 16 15:20:03 UTC 2008
>Closed-Date:    Mon Mar 24 10:39:53 UTC 2008
>Last-Modified:  Mon Mar 24 10:40:02 UTC 2008
>Originator:     Richard Arends
>Release:        7.0-RELEASE
>Organization:
unixguru.nl
>Environment:
FreeBSD tinybsd.unixguru.nl 7.0-STABLE FreeBSD 7.0-STABLE #1: Sun Mar 16 11:17:33 CET 2008     root@tinybsd.unixguru.nl:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
If a tinybsd build is interrupted and later started again, there's a possibility that directory's are still mounted with mount_nullfs.

Running the remove_workdir function can than do severe damage to the build host, because it wil remove anything below $WORKDIR, thus also the mounted directory's like /lib. ..oops..
>How-To-Repeat:
Interupt a tinybsd build at the time it is building the (optional) ports. Then start it again and the remove_workdir function will delete everything under $WORKDIR, 
>Fix:
Apply the patch

Patch attached with submission follows:

--- tinybsd	2008-03-16 09:28:42.000000000 +0100
+++ tinybsd.new	2008-03-16 15:44:33.000000000 +0100
@@ -248,12 +248,21 @@
 }
 
 remove_workdir() {
-	chflags -R noschg ${WORKDIR}
-	echo "${TS} Removing "${WORKDIR}
-	rm -rf ${WORKDIR}
-	echo "${TS} Removing Build Kernel Directory"
-	rm -rf /usr/obj/usr/src/sys/${KERNCONF}
-	echo "${TS}  done."
+	# Before removing check if there is not a mount under $WORKDIR anymore
+	MOUNT_CHECK=`mount|egrep "on ${WORKDIR}"`
+
+	if [ ! -z "${MOUNT_CHECK}" ]; then
+		echo "There are mounts under the workdir (${WORKDIR}). Please umount them before running this script"
+		exit 1
+	else
+		exit 11
+		chflags -R noschg ${WORKDIR}
+		echo "${TS} Removing "${WORKDIR}
+		rm -rf ${WORKDIR}
+		echo "${TS} Removing Build Kernel Directory"
+		rm -rf /usr/obj/usr/src/sys/${KERNCONF}
+		echo "${TS}  done."
+	fi
 }
 
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Sun Mar 16 16:13:59 UTC 2008 
Responsible-Changed-Why:  
I'll take it. 

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

From: Richard Arends <richard@unixguru.nl>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/121763: TinyBSD remove_workdir function needs some extra checking for existing mounts
Date: Sun, 16 Mar 2008 16:48:16 +0100

 --qMm9M+Fa2AknHoGS
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Hello,
 
 In the patch is an extra 'exit 11' that should not be there. Sorry for
 the inconvenience, the attached patch is the right one.
  
 -- 
 Regards,
 
 Richard.
 
 /* Homo Sapiens non urinat in ventum */
 
 --qMm9M+Fa2AknHoGS
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="patch.txt"
 
 --- tinybsd.org	2008-03-16 15:54:10.000000000 +0100
 +++ tinybsd	2008-03-16 15:50:49.000000000 +0100
 @@ -248,12 +248,20 @@
  }
  
  remove_workdir() {
 -	chflags -R noschg ${WORKDIR}
 -	echo "${TS} Removing "${WORKDIR}
 -	rm -rf ${WORKDIR}
 -	echo "${TS} Removing Build Kernel Directory"
 -	rm -rf /usr/obj/usr/src/sys/${KERNCONF}
 -	echo "${TS}  done."
 +	# Before removing check if there is not a mount under $WORKDIR anymore
 +	MOUNT_CHECK=`mount|egrep "on ${WORKDIR}"`
 +
 +	if [ ! -z "${MOUNT_CHECK}" ]; then
 +		echo "There are mounts under the workdir (${WORKDIR}). Please umount them before running this script"
 +		exit 1
 +	else
 +		chflags -R noschg ${WORKDIR}
 +		echo "${TS} Removing "${WORKDIR}
 +		rm -rf ${WORKDIR}
 +		echo "${TS} Removing Build Kernel Directory"
 +		rm -rf /usr/obj/usr/src/sys/${KERNCONF}
 +		echo "${TS}  done."
 +	fi
  }
  
  
 
 --qMm9M+Fa2AknHoGS--
State-Changed-From-To: open->patched 
State-Changed-By: remko 
State-Changed-When: Thu Mar 20 12:57:00 UTC 2008 
State-Changed-Why:  
Patched in current will MFC in a few days 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/121763: commit references a PR
Date: Thu, 20 Mar 2008 12:57:00 +0000 (UTC)

 remko       2008-03-20 12:56:49 UTC
 
   FreeBSD src repository
 
   Modified files:
     tools/tools/tinybsd  tinybsd 
   Log:
   Alert properly when we have stale mounts left after interupting
   a tinybsd build.  If we do not do this, we can accidentally remove
   critical files from directories like /lib (if mounted).
   
   PR:             misc/121763
   Submitted by:   Richard Arends < richard at unixguru dot nl >
   MFC after:      3 days
   
   Revision  Changes    Path
   1.9       +14 -6     src/tools/tools/tinybsd/tinybsd
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: remko 
State-Changed-When: Mon Mar 24 10:39:52 UTC 2008 
State-Changed-Why:  
MFC'ed to releng7, thanks for the submission richard! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/121763: commit references a PR
Date: Mon, 24 Mar 2008 10:39:40 +0000 (UTC)

 remko       2008-03-24 10:39:34 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     tools/tools/tinybsd  tinybsd 
   Log:
   MFC rev 1.9 tinybsd
   
     Alert properly when we have stale mounts left after interupting
     a tinybsd build.  If we do not do this, we can accidentally remove
     critical files from directories like /lib (if mounted).
   
     PR:             misc/121763
     Submitted by:   Richard Arends < richard at unixguru dot nl >
     MFC after:      3 days
   
   Approved by:    imp (mentor, implicit)
   
   Revision  Changes    Path
   1.7.2.2   +14 -6     src/tools/tools/tinybsd/tinybsd
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
