From 8a9ff49d785dfa0d133f66af715b210bca964cdb Mon Sep 17 00:00:00 2001 From: kettenis Date: Fri, 20 Oct 2023 18:53:12 +0000 Subject: [PATCH] Avoid forcible mounting a dirty filessystem. Mount such filesystems read-only instead. This means that writing to the filesystem will fail. As a consequence chmod'ing of files in the bootloader will fail, but that will fix itself on the next clean boot. Same change as I committed to powerpc64 a few days ago. ok kn@, deraadt@ --- sys/arch/octeon/stand/rdboot/disk.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sys/arch/octeon/stand/rdboot/disk.c b/sys/arch/octeon/stand/rdboot/disk.c index eda089bc34f..847b84551c4 100644 --- a/sys/arch/octeon/stand/rdboot/disk.c +++ b/sys/arch/octeon/stand/rdboot/disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.c,v 1.2 2020/05/26 13:30:47 visa Exp $ */ +/* $OpenBSD: disk.c,v 1.3 2023/10/20 18:53:12 kettenis Exp $ */ /* * Copyright (c) 2019 Visa Hankala @@ -180,11 +180,13 @@ disk_open(const char *path) memset(&ffs_args, 0, sizeof(ffs_args)); ffs_args.fspec = devpath; - if (mount(MOUNT_FFS, "/mnt", MNT_FORCE | MNT_NOATIME, - &ffs_args) == -1) { - fprintf(stderr, "failed to mount %s: %s\n", devpath, - strerror(errno)); - return NULL; + if (mount(MOUNT_FFS, "/mnt", MNT_NOATIME, &ffs_args) == -1) { + if (mount(MOUNT_FFS, "/mnt", MNT_RDONLY, &ffs_args) == -1) { + fprintf(stderr, "failed to mount %s: %s\n", devpath, + strerror(errno)); + return NULL; + } + fprintf(stderr, "%s: mounted read-only\n", devpath); } if (chroot("/mnt") == -1) { fprintf(stderr, "failed to chroot: %s\n", strerror(errno)); -- 2.20.1