[hackers] [ubase] mount: don't call realpath on root target || Ioan-Adrian Ratiu

From: <git_AT_suckless.org>
Date: Sat, 30 Jun 2018 18:38:20 +0200 (CEST)

commit 4f5837147a14e0fb8ec1a2a46a9c4045bdb75696
Author: Ioan-Adrian Ratiu <adi_AT_adirat.com>
AuthorDate: Sat Apr 7 05:33:30 2018 +0300
Commit: sin <sin_AT_2f30.org>
CommitDate: Sat Jun 30 17:38:07 2018 +0100

    mount: don't call realpath on root target
    
    Musl libc realpath implementation calls readlink on a procfs
    path it computes via __procfdname (code at [1] & [2]).
    
    This is problematic if ubase mount is used in a PID 1 because procfs
    is not mounted and the kernel passes the rootfs mounted read-only, so
    the first step is to read-write remount the rootfs, which can't be
    done because procfs is not mounted. Thus we are in a dependency cycle:
    procfs can't be mounted because the root is read-only and so on.
    
    To break this cycle, don't call readlink on "/" (it doesn't really make
    sense anyway) so the rootfs can be remounted read-write, after which
    proc itself can be mounted and the rest of mount calls will succeed
    so systems running ubase + musl can succesfully boot into userspace.
    
    [1] https://git.musl-libc.org/cgit/musl/tree/src/misc/realpath.c?h=v1.1.19
    [2] https://git.musl-libc.org/cgit/musl/tree/src/internal/procfdname.c?h=v1.1.19
    
    Signed-off-by: Ioan-Adrian Ratiu <adi_AT_adirat.com>

diff --git a/mount.c b/mount.c
index 4ce6680..e3d00b8 100644
--- a/mount.c
+++ b/mount.c
_AT_@ -242,9 +242,11 @@ main(int argc, char *argv[])
         if (!target) {
                 target = argv[0];
                 source = NULL;
- if (!(resolvpath = realpath(target, NULL)))
- eprintf("realpath %s:", target);
- target = resolvpath;
+ if (strcmp(target, "/") != 0) {
+ if (!(resolvpath = realpath(target, NULL)))
+ eprintf("realpath %s:", target);
+ target = resolvpath;
+ }
         }
 
         for (i = 0; files[i]; i++) {
Received on Sat Jun 30 2018 - 18:38:20 CEST

This archive was generated by hypermail 2.3.0 : Sat Jun 30 2018 - 18:48:25 CEST