Bug 292127 - 32-bit libgeom does not work on a 64-bit kernel
Summary: 32-bit libgeom does not work on a 64-bit kernel
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 16.0-CURRENT
Hardware: i386 Any
: --- Affects Some People
Assignee: Dag-Erling Smørgrav
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-02 09:45 UTC by Dag-Erling Smørgrav
Modified: 2026-01-12 17:22 UTC (History)
1 user (show)

See Also:
des: mfc-stable15+
des: mfc-stable14+
des: mfc-stable13+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-01-02 09:45:05 UTC
The following trivial libgeom program segfaults on 32-bit systems:

$ cat g.c                               
#include <libgeom.h>

int main(void)
{
	struct gmesh mesh;

	if (geom_gettree(&mesh) != 0)
		return (1);
	geom_deletetree(&mesh);
	return (0);
}
$ cc -Wall -Wextra -ggdb -o g g.c -lgeom
$ gdb -quiet g
Reading symbols from g...
(gdb) r
Starting program: /tmp/g 
warning: Could not load shared library symbols for [vdso].
Do you need "set solib-search-path" or "set sysroot"?

Program received signal SIGSEGV, Segmentation fault.
Address not mapped to object.
0x20447231 in delete_config (gp=0x206ee5d4)
    at /usr/src/lib/libgeom/geom_xml2tree.c:502
502			LIST_REMOVE(cf, lg_config);
(gdb) bt
#0  0x20447231 in delete_config (gp=0x206ee5d4)
    at /usr/src/lib/libgeom/geom_xml2tree.c:502
#1  geom_deletetree (gmp=0xffffdb98)
    at /usr/src/lib/libgeom/geom_xml2tree.c:524
#2  0x00401541 in main () at g.c:9
Comment 1 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-01-02 12:26:39 UTC
https://reviews.freebsd.org/D54452
Comment 2 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-01-02 12:27:07 UTC
https://reviews.freebsd.org/D54452
Comment 3 commit-hook freebsd_committer freebsd_triage 2026-01-03 09:11:11 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=27894e20f140ee2729c14b589035870c8185b87d

commit 27894e20f140ee2729c14b589035870c8185b87d
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-01-03 09:09:51 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-01-03 09:10:23 +0000

    libgeom: Fix segfault in 32-on-64 case

    We were using strtoul() to parse object identifiers, which are kernel
    pointers.  This works fine as long as the kernel and userland match,
    but in a 32-bit libgeom on a 64-bit kernel this will return ULONG_MAX
    for all objects, resulting in memory corruption when we later pick the
    wrong object while resolving consumer-producer references.

    MFC after:      1 week
    PR:             292127
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D54452

 lib/libgeom/geom_xml2tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 4 Mark Millard 2026-01-03 23:42:10 UTC
(In reply to commit-hook from comment #3)

The quick test on the Windows Dev Kit 2023
after the pkgbase update has the gpart show
output looking good in the armv7 chroot:

# uname -apKU
FreeBSD aarch64-main-pbase 16.0-CURRENT FreeBSD 16.0-CURRENT main-n282840-4b0d5d1d6a7c GENERIC-NODEBUG arm armv7 1600007 1600007

# gpart show
=>        34  1000215149  nda0  GPT  (477G)
          34        2014        - free -  (1007K)
        2048      532480     1  efi  (260M)
      534528       32768     2  ms-reserved  (16M)
      567296   997287936     3  ms-basic-data  (476G)
   997855232     2359296     4  ms-recovery  (1G)
  1000214528         655        - free -  (328K)

=>        34  2930277101  da0  GPT  (1T)
          34       32734       - free -  (16M)
       32768      501760    1  efi  (245M)
      534528    20971520    2  freebsd-swap  (10G)
    21506048    29360128    3  freebsd-swap  (14G)
    50866176    33554432    4  freebsd-swap  (16G)
    84420608    67108864    5  freebsd-swap  (32G)
   151529472    96468992    6  freebsd-swap  (46G)
   247998464   268435456    7  freebsd-swap  (128G)
   516433920     7340032    8  freebsd-swap  (4G)
   523773952    13096960       - free -  (6G)
   536870912  2357198848    9  freebsd-ufs  (1T)
  2894069760    36207375       - free -  (17G)


(I've no clue how to do even basic testing of
devstat: so that has no explicit testing here.)


Thanks for getting that working.
Comment 5 Mark Millard 2026-01-04 00:26:59 UTC
(In reply to Mark Millard from comment #4)

Turns out that devstat is apparently used in
iostat and that in an armv7 chroot on aarch64:

# iostat
iostat: devstat_getdevs: error getting device stats
devstat_getdevs: Cannot allocate memory

vmstat gets the same:

# vmstat
vmstat: devstat_getdevs: error getting device stats
devstat_getdevs: Cannot allocate memory

gstat looks to just find no devices.

Native aarch64 looks more normal but I've no clue
show to validate the details such commands report
in general.
Comment 6 commit-hook freebsd_committer freebsd_triage 2026-01-12 17:18:58 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=08e7bdaf18b9d452501772cf7914a252363cba61

commit 08e7bdaf18b9d452501772cf7914a252363cba61
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-01-03 09:09:51 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-01-12 17:18:22 +0000

    libgeom: Fix segfault in 32-on-64 case

    We were using strtoul() to parse object identifiers, which are kernel
    pointers.  This works fine as long as the kernel and userland match,
    but in a 32-bit libgeom on a 64-bit kernel this will return ULONG_MAX
    for all objects, resulting in memory corruption when we later pick the
    wrong object while resolving consumer-producer references.

    MFC after:      1 week
    PR:             292127
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D54452

    (cherry picked from commit 27894e20f140ee2729c14b589035870c8185b87d)

 lib/libgeom/geom_xml2tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2026-01-12 17:19:59 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=92f299dc666d82925abbe33e826eb52fb1ffb013

commit 92f299dc666d82925abbe33e826eb52fb1ffb013
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-01-03 09:09:51 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-01-11 02:30:31 +0000

    libgeom: Fix segfault in 32-on-64 case

    We were using strtoul() to parse object identifiers, which are kernel
    pointers.  This works fine as long as the kernel and userland match,
    but in a 32-bit libgeom on a 64-bit kernel this will return ULONG_MAX
    for all objects, resulting in memory corruption when we later pick the
    wrong object while resolving consumer-producer references.

    MFC after:      1 week
    PR:             292127
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D54452

    (cherry picked from commit 27894e20f140ee2729c14b589035870c8185b87d)

 lib/libgeom/geom_xml2tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2026-01-12 17:20:00 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0ba11021c46a84855af445e6b0420dd9b8b36023

commit 0ba11021c46a84855af445e6b0420dd9b8b36023
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-01-03 09:09:51 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-01-11 02:30:46 +0000

    libgeom: Fix segfault in 32-on-64 case

    We were using strtoul() to parse object identifiers, which are kernel
    pointers.  This works fine as long as the kernel and userland match,
    but in a 32-bit libgeom on a 64-bit kernel this will return ULONG_MAX
    for all objects, resulting in memory corruption when we later pick the
    wrong object while resolving consumer-producer references.

    MFC after:      1 week
    PR:             292127
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D54452

    (cherry picked from commit 27894e20f140ee2729c14b589035870c8185b87d)

 lib/libgeom/geom_xml2tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)