\subsection{Root filesystem}

\begin{frame}[fragile]{The chosen solutions
  \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  To have a verified root filesystem, we have chosen the following solutions:
  \begin{itemize}
  \item Have an unalterable filesystem:
    \begin{itemize}
    \item read-only filesystem: impossible to modify it \\
      => \texttt{squashfs}: type for read-only filesystem
    \item Not part of the secure-boot process but it was important for us
    \end{itemize}
  \item Authenticate the rootfs
    \begin{itemize}
    \item \texttt{dm-verity}:
      \begin{itemize}
      \item infrastructure to check if the rootfs is the one we
        are expecting \\
        => authentication of the squashfs image
      \item needs userspace applications to authenticate the
        system. Need to have these tools available \\
        => use an initramfs builtin as a first filesystem
      \item the kernel is already in the chain of trust
      \end{itemize}
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{dm-verity
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{itemize}
  \item \texttt{Device-Mapper}: infrastructure in the Linux kernel to create
    virtual layers of block devices
  \item \texttt{Device-Mapper verity}: provides integrity checking
    of block devices using kernel crypto API
  \item could hash the whole block device and compare it with the
    expected hash
  \item instead, use a cryptographic hash tree (Merkle tree)
  \item blocks are hashed and hash verified with hash tree \textbf{only on access}
  \item except the leaf nodes that are data, each node is the hash of its
    children. Until only one last hash  => \textbf{root hash}
  \item needs userspace apps: \textbf{cryptsetup} provides different tools
    (\textit{veritysetup})
  \end{itemize}
  \begin{center}
    \includegraphics[width=0.4\textwidth]{images/dm-verity-hash-table.png}
  \end{center}
\end{frame}

\begin{frame}[fragile]{dm-verity in our case
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=1\textwidth]{drawings/05_dm-verity-overview1.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item boot the kernel with initramfs
    \item have an init-script that uses \texttt{veritysetup} on block device (ubiblk0)
    \item \texttt{veritysetup}: a userspace application to authenticate devices
      according to root\_hash
    \item if OK, verified squashfs available
    \item if NOK, fails to have squashfs => init stops here
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{dm-verity: create hash tree
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=1\textwidth]{drawings/05_dm-verity-cmd1-1.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item \texttt{veritysetup} creates the hash tree (hash.img) and prints
      the root hash
    \item by default, the hash image is contained on another device/image than
      the one we want to authenticate
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{dm-verity: create hash tree
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=1\textwidth]{drawings/05_dm-verity-cmd1-2.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item not our use-case: want only one device \\
      => concatenate the hash image at the end of our squashfs image
    \item \texttt{veritysetup} has an option \texttt{--hash-offset} to
      locate the hash area in the same device/image
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{dm-verity: authenticate device
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=1\textwidth]{drawings/05_dm-verity-cmd2.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item use \texttt{veritysetup} to authenticate the block device
    \item need the root hash and the offset (where to find the hash tree)
    \item if authentication is successful, can mount (or switch-root) the verified squashfs
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{dm-verity: authenticate device
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=1\textwidth]{drawings/05_dm-verity-cmd2-.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item use \texttt{veritysetup} to authenticate the block device
    \item need the root hash and the offset (where to find the hash tree)
    \item if authentication is successful, can mount (or switch-root) the verified squashfs
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{dm-verity: authenticate device
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=1\textwidth]{drawings/05_dm-verity-cmd3.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item use \texttt{veritysetup} to authenticate the block device
    \item need the root hash and the offset (where to find the hash tree)
    \item if authentication is successful, can mount (or switch-root) the verified squashfs
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{U-Boot: passing hash-offset
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \includegraphics[width=1\textwidth]{drawings/05_uboot-script.pdf}
    \column{0.4\textwidth}
    \begin{itemize}
    \item create a U-Boot environment script
    \item but the U-Boot environment script can be attacked
    \item add this script in the \texttt{FitImage} \\
      => has a signature of the hash of the binary
    \item Once sourced, set \texttt{bootargs} to have offset and root hash
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{The final mechanism
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=0.9\textwidth]{drawings/05_dm-verity-overview2.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item source U-Boot script to set \texttt{bootargs} with hash and offset
    \item bootargs read by Linux's init-script to retrieve hash/offset values
    \item used with \texttt{veritysetup} to authenticate the block device
    \item use \texttt{switch-root} tool to switch the rootfs from initramfs
      to squashfs
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{The final mechanism
    \hfill\includegraphics[width=.5\linewidth]{drawings/00_banner-rootfs.pdf}\hspace*{0.5em}}
  \begin{columns}
    \column{0.6\textwidth}
    \begin{center}
      \includegraphics[width=0.9\textwidth]{drawings/05_dm-verity-overview3.pdf}
    \end{center}
    \column{0.4\textwidth}
    \begin{itemize}
    \item source U-Boot script to set \texttt{bootargs} with hash and offset
    \item bootargs read by Linux's init-script to retrieve hash/offset values
    \item used with \texttt{veritysetup} to authenticate the block device
    \item use \texttt{switch-root} tool to switch the rootfs from initramfs
      to squashfs
    \end{itemize}
  \end{columns}
\end{frame}
