NetBSD Problem Report #57010

From www@netbsd.org  Wed Sep 14 08:37:59 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 4CC691A923A
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 14 Sep 2022 08:37:59 +0000 (UTC)
Message-Id: <20220914083757.76AFF1A923D@mollari.NetBSD.org>
Date: Wed, 14 Sep 2022 08:37:57 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: ffs: mounting unclean non-root fs read-only causes spurious write to superblock
X-Send-Pr-Version: www-1.0

>Number:         57010
>Category:       kern
>Synopsis:       ffs: mounting unclean non-root fs read-only causes spurious write to superblock
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 14 08:40:00 +0000 2022
>Closed-Date:    Wed Mar 22 12:01:36 +0000 2023
>Last-Modified:  Wed Mar 22 12:01:36 +0000 2023
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
Ffe FfetBSD Ffoundation
>Environment:
NetBSD singbulli 9.99.99 NetBSD 9.99.99 (GENERIC) #174: Thu Sep  8 01:10:04 UTC 2022  root@singbulli:/home/riastradh/netbsd/current/obj.amd64/sys/arch/amd64/compile/GENERIC amd64
>Description:
The following logic in ffs_mount causes a write to the medium in ffs_cgupdate even if it is mounted read-only:

	if (fs->fs_fmod != 0) {	/* XXX */
		int err;

		fs->fs_fmod = 0;
		if (fs->fs_clean & FS_WASCLEAN)
			fs->fs_time = time_second;
		else {
			printf("%s: file system not clean (fs_clean=%#x); "
			    "please fsck(8)\n", mp->mnt_stat.f_mntfromname,
			    fs->fs_clean);
			printf("%s: lost blocks %" PRId64 " files %d\n",
			    mp->mnt_stat.f_mntfromname, fs->fs_pendingblocks,
			    fs->fs_pendinginodes);
		}
		err = UFS_WAPBL_BEGIN(mp);
		if (err == 0) {
			(void) ffs_cgupdate(ump, MNT_WAIT);
			UFS_WAPBL_END(mp);
		}
	}

This triggers the warning in the specfs spec_strategy function in spec_vnops.c (to which I added db_stacktrace, for attribution of blame):

[ 13476.731716] /altroot/altroot blk 5728 written while ro!
[ 13476.731716] VOP_STRATEGY() at netbsd:VOP_STRATEGY+0x3c
[ 13476.731716] bwrite() at netbsd:bwrite+0x158
[ 13476.731716] ffs_cgupdate() at netbsd:ffs_cgupdate+0x126
[ 13476.731716] ffs_mount() at netbsd:ffs_mount+0x281
[ 13476.741712] VFS_MOUNT() at netbsd:VFS_MOUNT+0x3c
[ 13476.741712] mount_domount() at netbsd:mount_domount+0xd0
[ 13476.741712] do_sys_mount() at netbsd:do_sys_mount+0x26a
[ 13476.741712] sys___mount50() at netbsd:sys___mount50+0x33
[ 13476.741712] syscall() at netbsd:syscall+0x196
[ 13476.741712] --- syscall (number 410) ---

>How-To-Repeat:
1. Interrupt use of a non-root file system during operation so fs->fs_fmod is set.
2. Mount the file system read-only.
>Fix:
Yes, please!

>Release-Note:

>Audit-Trail:
From: "Juergen Hannken-Illjes" <hannken@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57010 CVS commit: src/sys/ufs/ffs
Date: Thu, 10 Nov 2022 10:53:29 +0000

 Module Name:	src
 Committed By:	hannken
 Date:		Thu Nov 10 10:53:29 UTC 2022

 Modified Files:
 	src/sys/ufs/ffs: ffs_vfsops.c

 Log Message:
 Some changes to "fs->fs_fmod" and "fs->fs_clean":
 - clear "fs->fs_fmod" after reading the super block.
 - assert we don't write a super block when mounted read-only.
 - make sure "fs->fs_clean" is one of FS_ISCLEAN or FS_WASCLEAN.
 - print "file system not clean" on every mount.

 Should fix PR kern/57010: ffs: mounting unclean non-root fs read-only
 causes spurious write to superblock


 To generate a diff of this commit:
 cvs rdiff -u -r1.376 -r1.377 src/sys/ufs/ffs/ffs_vfsops.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: hannken@NetBSD.org
State-Changed-When: Wed, 22 Mar 2023 09:44:55 +0000
State-Changed-Why:
Committed a fix, ok to close?


State-Changed-From-To: feedback->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Wed, 22 Mar 2023 12:01:36 +0000
State-Changed-Why:
can't test right now, looks fixed, will reopen if it persists


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.