Bug 278936 - mqueuefs: Crashes when removing queue as user
Summary: mqueuefs: Crashes when removing queue as user
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
: 278937 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-05-12 16:43 UTC by Ricardo Branco
Modified: 2024-05-22 22:19 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ricardo Branco 2024-05-12 16:43:43 UTC
A mounted mqueuefs crashes when removing queue as user.

To reproduce:
$ sudo mount -t mqueuefs none /mnt
$ sudo touch /mnt/queue1
$ sudo rm -f /mnt/queue1

This only seems to crash on -CURRENT as I couldn't reproduce on -RELEASE or -STABLE.

You can use the QEMU VM at 
https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/amd64/Latest/FreeBSD-15.0-CURRENT-amd64-ufs.qcow2.xz

dmesg log:

Fatal trap 9: general protection fault while in kernel mode
cpuid = 1; apic id = 01
instruction pointer	= 0x20:0xffffffff80ba8aae
stack pointer	        = 0x28:0xfffffe0068c12e50
frame pointer	        = 0x28:0xfffffe0068c12ec0
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		= 0 (thread taskq)
rdi: deadc0dedeadc0de rsi: 000000000000c0de rdx: 0000000000000000
rcx: 0000000000000001  r8: 0000000000000001  r9: 0000000000000000
rax: 0000000000000001 rbx: fffff800034f6400 rbp: fffffe0068c12ec0
r10: 0000000000010000 r11: 0000000000000001 r12: 0000000000000001
r13: 000000000000c0de r14: fffff800034f6458 r15: fffff80104001020
trap number		= 9
panic: general protection fault
cpuid = 1
time = 1715530856
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0068c12b90
vpanic() at vpanic+0x13f/frame 0xfffffe0068c12cc0
panic() at panic+0x43/frame 0xfffffe0068c12d20
trap_fatal() at trap_fatal+0x40b/frame 0xfffffe0068c12d80
calltrap() at calltrap+0x8/frame 0xfffffe0068c12d80
--- trap 0x9, rip = 0xffffffff80ba8aae, rsp = 0xfffffe0068c12e50, rbp = 0xfffffe0068c12ec0 ---
taskqueue_run_locked() at taskqueue_run_locked+0x1be/frame 0xfffffe0068c12ec0
taskqueue_thread_loop() at taskqueue_thread_loop+0xd3/frame 0xfffffe0068c12ef0
fork_exit() at fork_exit+0x82/frame 0xfffffe0068c12f30
fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe0068c12f30
--- trap 0, rip = 0, rsp = 0, rbp = 0 ---
KDB: enter: panic
Comment 1 Ricardo Branco 2024-05-12 16:46:53 UTC
*** Bug 278937 has been marked as a duplicate of this bug. ***
Comment 2 Ricardo Branco 2024-05-20 12:29:39 UTC
The crash doesn't happen when I include "std.nodebug" in my kernel config.

But I also tried by removing taskqueue_enqueue call, not seen in synthetic filesystems, and it works.  PR at https://github.com/freebsd/freebsd-src/pull/1249
Comment 3 Ricardo Branco 2024-05-20 13:29:41 UTC
I managed to crash -STABLE (didn't try -RELEASE) like this:

$ sudo mount -t mqueuefs none /mnt

$ touch /mnt/{1..101}  # Needs Bash I think
touch: /mnt/101: Resource temporarily unavailable

$ sysctl kern.mqueue
kern.mqueue.curmq: 100
kern.mqueue.maxmq: 100
kern.mqueue.maxmsgsize: 16384
kern.mqueue.maxmsg: 100

$ rm -f /mnt/*

$ sysctl kern.mqueue
kern.mqueue.curmq: 0
kern.mqueue.maxmq: 100
kern.mqueue.maxmsgsize: 16384
kern.mqueue.maxmsg: 100

$ for i in {1..101} ; do posixmqcontrol create -d /$i -s 1 -d 1; done
posixmqcontrol: mq_open(create): Too many open files in system

$ rm -f /mnt/*



POSIX message queues seem broken on FreeBSD. There's no limit per-user. I tried this on Linux and it only allowed me to create only 10 messages queues as user, without limiting root.
Comment 4 Ricardo Branco 2024-05-20 13:33:04 UTC
The command for creating mq's above:

$ for i in {1..101} ; do posixmqcontrol create -q /$i -s 1 -d 1; done
Comment 5 Konstantin Belousov freebsd_committer freebsd_triage 2024-05-22 22:19:50 UTC
https://reviews.freebsd.org/D45305