Hello,

the patch works. Can you apply the patch to the regular netbsd-10 sources?


Best Regards
Uwe


On Tue, 17 Jun 2025, Michael van Elst wrote:

6b...@6bone.informatik.uni-leipzig.de writes:

newfs -m 1 -O 2 -o space -q user -q group /dev/dk1
/dev/rdk1: 267036672.0MB (546891104184 sectors) block size 32768, fragment
size 4096
        using 303430 cylinder groups of 880.06MB, 28162 blks, 7168 inodes.
super-block backups (for fsck_ffs -b #) at:
192, 1802560, 3604928, 5407296, 7209664, 9012032, 10814400, 12616768, 14419136,
..............................................................................

fsck -f /dev/dk1
** /dev/rdk1
** File system is already clean
fsck: /dev/rdk1: Segmentation fault

(A core file is created. However, there is no error message. Dmesg also
provides no information.)


The segfault can be reproduced:

(gdb) where
#0  0x00007c0fe318268c in memset () from /lib/libc.so.12
#1  0x00000000e581131b in __memset_ichk (len=8545173504, src=0,
   dst=<optimized out>)
   at /home/netbsd10/destdir.amd64/usr/include/ssp/string.h:84
#2  setup (dev=dev@entry=0x7c0fe3d5d000 "./testimage",
   origdev=origdev@entry=0x7c0fe3d5d000 "./testimage")
   at /home/netbsd10/src/sbin/fsck_ffs/setup.c:504
#3  0x00000000e580815e in checkfilesys (
   filesys=filesys@entry=0x7c0fe3d5d000 "./testimage",
   origfs=origfs@entry=0x7c0fe3d5d000 "./testimage", child=0)
   at /home/netbsd10/src/sbin/fsck_ffs/main.c:397
#4  0x00000000e5818500 in main (argc=<optimized out>, argv=0x7f7fffe8a6a0)
   at /home/netbsd10/src/sbin/fsck_ffs/main.c:336

       /*
        * allocate and initialize the necessary maps
        */
       bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));
       blockmap = aligned_alloc(DEV_BSIZE, (unsigned)bmapsize);
       if (blockmap == NULL) {
               pwarn("cannot alloc %u bytes for blockmap\n",
                   (unsigned)bmapsize);
               goto badsblabel;
       }
       memset(blockmap, 0, bmapsize);

with:

(gdb) print bmapsize
$1 = 8545173504

but:

(gdb) print (unsigned)bmapsize
$3 = 4250206208



This helps:

Index: sbin/fsck_ffs/setup.c
===================================================================
RCS file: /cvsroot/src/sbin/fsck_ffs/setup.c,v
retrieving revision 1.104.2.2
diff -p -u -r1.104.2.2 setup.c
--- sbin/fsck_ffs/setup.c       13 May 2023 11:54:17 -0000      1.104.2.2
+++ sbin/fsck_ffs/setup.c       17 Jun 2025 05:37:30 -0000
@@ -87,7 +87,7 @@ setup(const char *dev, const char *origd
{
       uint32_t cg;
       long size, asked, i, j;
-       long bmapsize;
+       size_t bmapsize;
       struct disk_geom geo;
       struct dkwedge_info dkw;
       off_t sizepb;
@@ -495,10 +495,10 @@ setup(const char *dev, const char *origd
        * allocate and initialize the necessary maps
        */
       bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));
-       blockmap = aligned_alloc(DEV_BSIZE, (unsigned)bmapsize);
+       blockmap = aligned_alloc(DEV_BSIZE, bmapsize);
       if (blockmap == NULL) {
-               pwarn("cannot alloc %u bytes for blockmap\n",
-                   (unsigned)bmapsize);
+               pwarn("cannot alloc %zu bytes for blockmap\n",
+                   bmapsize);
               goto badsblabel;
       }
       memset(blockmap, 0, bmapsize);


N.B. fsck takes about 9GB RAM for the empty filesystem of that size.


Greetings,

Reply via email to