Bug 279939 - sysutils/pefs-kmod: causes panic when module is loaded
Summary: sysutils/pefs-kmod: causes panic when module is loaded
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-24 01:21 UTC by Bill Blake
Modified: 2024-06-26 11:38 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (darius)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Blake 2024-06-24 01:21:23 UTC
I just did a fresh install of 14.1 and attempted to kldload the pefs module.  I got the following panic:

Fatal trap 18: integer divide fault while in kernel mode
cpuid = 2; apic id = 02
instruction pointer   = 0x20:0xffffffff8080b7a4
stack pointer         = 0x28:0xfffffe00848337c0
frame pointer         = 0x28:0xfffffe0084833860
code segment          = base rx0, limit 0xfffff, type 0x1b
                      = DPL 0, pres 1, long 1, def32 0, gran 1
processor eflags      = interrupt enabled, resume, IOPL = 0
current process               = 27 (kldload)
rdi: 0000000000000000 rsi: 0000000000000000 rdx: 0000000000000000
rcx: 0000000000000000  r8: 0000000000200000  r9: 0000000000000000
rax: 00000000fffffbe0 rbx: 0000000000000000 rbp: fffffe0084833860
r10: 0000000000000000 r11: 3ffffffffffffff8 r12: 00000000fffffc00
r13: 0000000000000000 r14: 0000000000000000 r15: 1ffffffffffffff8
trap number           = 18
panic: integer divide fault
cpuid = 2
time = 1719189798

The last pefs statement executed was in sys/fs/pefs/pefs_crypto.c:pefs_crypto_init().  The first statement of that function is:

pefs_ctx_zone = uma_zcreate("pefs_ctx", sizeof(struct pefs_ctx), NULL, pefs_zone_dtor_bzero, NULL, NULL, UMA_ALIGN_CACHE, 0);

I put prints before and after that statement; the before printed, the after did not.

The pefs source apparently did not change between 14.0 and 14.1, and this panic did not happen on 14.0.
Comment 1 Daniel O'Connor 2024-06-24 01:28:49 UTC
Hi Bill,
How did you build the PEFS module?
Can you try rebuilding it from source? (ie cd /usr/ports/sysutils/pefs-kmod ; make ; sudo make install)
Comment 2 Bill Blake 2024-06-24 01:38:46 UTC
I grabbed a copy of the distribution, unpacked it into a random directory, and ran "PEFS_DEBUG=1 make".  The panic occurred with the package and with my compiled version.
Comment 3 Bill Blake 2024-06-24 02:02:51 UTC
I realized that there was one thing I hadn't done: try it with the GENERIC kernel.  So I did and still got the panic.  But I also got a stack trace:

#0 0xffffffff80b7fbfd at kdb_backtrace+0x5d
#1 0xffffffff80b32961 at vpanic+0x131
#2 0xffffffff80b32823 at panic+0x43
#3 0xffffffff80fff91b at trap_fatal+0x40b
#4 0xffffffff80fd6a48 at calltrap+0x8
#5 0xffffffff80e9d351 at zone_alloc_item+0x191
#6 0xffffffff80e9c904 at zone_ctor+0x5a4
#7 0xffffffff80e9d351 at zone_alloc_item+0x191
#8 0xffffffff80e9cfdd at uma_zcreate+0x8d
#9 0xffffffff83000788 at pefs_crypto_init+0x28
#10 0xffffffff82ff90ef at pefs_init+0xef
#11 0xffffffff80c06bb6 at vfs_modevent+0x3f6
#12 0xffffffff80b0dc35 at module_register_init+0x85
#13 0xffffffff80afe8c1 at linker_load_module+0xb81
#14 0xffffffff80b003f4 at kern_kldload+0x164
#15 0xffffffff80b0050c at sys_kldload+0x5c
#16 0xffffffff810001c0 at amd64_syscall+0x100
#17 0xffffffff80fd735b at fast_syscall_common+0xf8
Comment 4 Fernando Apesteguía freebsd_committer freebsd_triage 2024-06-24 08:27:49 UTC
(In reply to Bill Blake from comment #2)
What do you mean by grabbing a copy of the distribution? The distribution set that comes in the DVD?
Comment 5 Daniel O'Connor 2024-06-24 08:34:01 UTC
mm, annoyingly I cannot reproduce this.

I updated my old 14-current VM to 14.1-RELEASE-p1 FreeBSD 14.1-RELEASE-p1 releng/14.1-0892dff10 and built pefs from source (head of the repo - 350fed3) and the KLD loads and some quick tests show it operates properly.

Do your installed headers match your kernel?
Comment 6 Bill Blake 2024-06-24 12:01:16 UTC
Reading the last comment, I realized that I had in fact compiled pefs-kmod on 14.0 and then ran it on 14.1 when I got the panic.  But I also got the panic when I used the pefs-kmod package straight out of the box.  So, even though the version compiled on 14.1 does work, there is still the problem of the stock pefs-kmod panic.

I had the thought that I had somehow downloaded the 14.0 package into the 14.1 system.  Sure enough, I had...so I thought.  So then I booted into the 14.1 system, did a pkg fetch and...it was still the 14.0 package, byte for byte.  I have not, AFAIK, made any changes in the 14.1 system that should affect package fetching. (I have not modified /etc/pkg/FreeBSD.conf; the url contains "quarterly", as it always has.)

So either I'm not getting 14.1 packages when I do a pkg fetch when running a 14.1 system or the 14.1 pefs-kmod package wasn't recompiled for the release.
Comment 7 Daniel O'Connor 2024-06-24 12:39:38 UTC
I think kernel module packages are in a bit of an unfortunate position. The kernel ABI is not regulated very well so there are incidental breakages all the time.

I usually rebuild ports which install KLDs to avoid the issue - you can do `make install FORCE_PKG_REGISTER=1` and it will overwrite the package with the port built one without disturbing dependencies.

I am a bit surprised that it panics rather than just complaining about a version mismatch, however as I said earlier there are often accidental breakages.
Comment 8 Bill Blake 2024-06-24 12:59:26 UTC
Kinda the point of the package system is that one shouldn't have to do things like that.

Be that as it may, it's up to the people who deal with package distribution to address the problem; I'll just hack around it for now.
Comment 9 Fernando Apesteguía freebsd_committer freebsd_triage 2024-06-24 13:55:05 UTC
(In reply to Bill Blake from comment #8)
Packages in the repository are built for the lowest release available for that branch. So packages used by 14.x are built on 14.0 until 14.0 reaches EoL.

In an ideal world we would have latest and quarterly branches for every supported release at any point in time, but we are not there yet.

There is even a patch in freebsd-update(8), that didn't make it into 14.1, that scans the system for modules installed from ports and advises the user to rebuild them after upgrading to a new release: https://reviews.freebsd.org/rGbc0c6c9cf3a9f9a54dbdd92dd8f1f65ff8092d17

Other modules like virtualbox-kmod-ose will just refuse to load in a 14.1 system if the module was built on a 14.0 system.
Comment 10 Bill Blake 2024-06-24 22:24:49 UTC
(In reply to Fernando Apesteguía from comment #9)

In other words, so long as I'm on 14.x, x > 0, I'm not going to be able to use the package system for pefs-kmod (and maybe other kernel modules). I build my systems "manually" (it's actually a script I tweak a little for each new version that does a full install onto some spare partitions), so it's no biggie to make it grab the pefs-kmod distribution and compile it, but still.....

Anyway, someone ought to at least patch pefs-kmod to make it fail nicely on 14.x.
Comment 11 Daniel O'Connor 2024-06-24 23:34:05 UTC
You don't need to build everything with ports, just the -kmod packages.

I agree it is not ideal but that is the way it is (for now).
Comment 12 Fernando Apesteguía freebsd_committer freebsd_triage 2024-06-25 16:29:26 UTC
(In reply to Daniel O'Connor from comment #11)
Daniel, can you take care of that?
It might be even done as in the virtualbox-ose-kmod.
Comment 13 Bill Blake 2024-06-26 00:23:46 UTC
Just an FYI.  I did a "make package" on pefs-kmod using a 14.1 file system (chrooted, the underlying system was 14.0), and installed the compiled package (in the 14.1 file system). I then booted into the 14.1 system and all is well; I have had no other issues with the upgrade.
Comment 14 Daniel O'Connor 2024-06-26 01:36:23 UTC
(In reply to Fernando Apesteguía from comment #12)
What do you mean exactly?
Comment 15 Fernando Apesteguía freebsd_committer freebsd_triage 2024-06-26 11:38:55 UTC
(In reply to Daniel O'Connor from comment #14)
A pkg-message.in in which we advertise what FreeBSD version the kmod was built on and that rebuilding is recommended.