\begin{exe} {Security and Mount Options}

   We are going to mount a partition or loop device with
   the \verb?noexec? option to prevent execution of
   programs that reside on the filesystem therein.  You can
   certainly do this with a pre-existing and mounted
   partition, but you may not be able to easily change the
   behavior while the partition is mounted.  Therefore, to
   demonstrate we'll use a loop device, which is a harmless
   procedure.

   \begin{enumerate}
      \item
      Set up an empty file, put a filesystem on it and mount
      it.
      \item
      Copy an executable file to it from somewhere else on
      your system and test that it works in the new
      location.
      \item
      Unmount it and remount with the \verb?noexec? option.
      \item
      Test if the executable still works.  It should give
      you an error because of the \texttt{noexec} mount
      option.
      \item
      Clean up.
   \end{enumerate}

   \begin{sol}

      \begin{enumerate}
         \item
         \begin{cmd}
$ dd if=/dev/zero of=image bs=1M count=100
$ sudo mkfs.ext3 image
$ mkdir mountpoint
$ sudo mount -o loop image mountpoint
         \end{cmd}
         \item
         \begin{cmd}
$ sudo cp /bin/ls mountpoint
$ mountpoint/ls
         \end{cmd}
         \item
         \begin{cmd}
$ sudo umount mountpoint
$ sudo mount -o noexec,loop image mountpoint
         \end{cmd}
         or
         \begin{cmd}
$ sudo mount -o noexec,remount image mountpoint
         \end{cmd}
         \item
         \begin{cmd}
$ mountpoint/ls
         \end{cmd}
         \item
         \begin{cmd}
$ sudo umount mountpoint
$ rm image
$ rmdir mountpoint
         \end{cmd}
      \end{enumerate}

      Note that this is not persistent. To make it
      persistent you would need to add the option to
      \filelink{/etc/fstab} with a line like:
      \begin{configlst}[in \texttt{/etc/fstab}]
/home/student/image  /home/student/mountpoint    ext3    loop,rw,noexec 0 0
      \end{configlst}
   \end{sol}
\end{exe}

