Skip to content

Fix segfault when interrupting fapolicyd startup#391

Merged
stevegrubb merged 1 commit intolinux-application-whitelisting:mainfrom
rmetrich:early_segfaults
Jan 23, 2026
Merged

Fix segfault when interrupting fapolicyd startup#391
stevegrubb merged 1 commit intolinux-application-whitelisting:mainfrom
rmetrich:early_segfaults

Conversation

@rmetrich
Copy link
Contributor

In non-daemon mode, hitting Ctrl-C while fapolicyd initializes leads to getting 2 segfaults:
- first one in term_handler() because q is not initialized yet
- then one in coredump_handler() because m is not initialized yet

Reproducer:

# fapolicyd --debug
[...]
01/22/26 10:48:37 [ INFO ]: Loading rpmdb backend
^CSegmentation fault (core dumped)

GDB shows:

   (gdb) bt
    #0  mlist_first (m=m@entry=0x0) at daemon/mounts.c:86  <<<<< SECOND SEGFAULT
    #1  0x00005627e02de9ec in unmark_fanotify (m=0x0) at daemon/notify.c:258
    #2  0x00005627e02dda13 in coredump_handler (sig=11) at daemon/fapolicyd.c:336
    #3  coredump_handler (sig=11) at daemon/fapolicyd.c:333
    #4  <signal handler called>
    #5  __new_sem_post (sem=0x20) at sem_post.c:36         <<<<< FIRST SEGFAULT
    #6  <signal handler called>
    #7  __recvmsg_syscall (flags=0, msg=0x7ffe93e00350, fd=6) at ../sysdeps/unix/sysv/linux/recvmsg.c:27
    #8  __libc_recvmsg (fd=6, msg=msg@entry=0x7ffe93e00350, flags=flags@entry=0)
        at ../sysdeps/unix/sysv/linux/recvmsg.c:41
    #9  0x00005627e02eef82 in rpm_load_list (conf=<optimized out>) at library/rpm-backend.c:260
    #10 0x00005627e02ecc02 in backend_load (conf=conf@entry=0x5627e02fa0e0 <config>) at library/backend-manager.c:152
    #11 0x00005627e02e21c0 in init_database (config=config@entry=0x5627e02fa0e0 <config>) at library/database.c:1440
    #12 0x00005627e02db599 in main (argc=<optimized out>, argv=<optimized out>) at daemon/fapolicyd.c:1053
   ~~~

@stevegrubb
Copy link
Member

This looks like it contains another patch already merged.

In general, I would fix this in the function that crashes and not the call of the function. Typically at the beginning of a function you would test for NULL and return.

@rmetrich
Copy link
Contributor Author

This looks like it contains another patch already merged.

In general, I would fix this in the function that crashes and not the call of the function. Typically at the beginning of a function you would test for NULL and return.

Yes we could but since it's a rare condition I think it's better to not check constantly q or m in the functions using it. It's better for performances of fapolicyd.

@stevegrubb
Copy link
Member

Neither of these are on the hot path. Just check the value on entry and we're good to go.

In non-daemon mode, hitting Ctrl-C while fapolicyd initializes leads to
getting 2 segfaults:
- first one in term_handler() because 'q' is not initialized yet
- then one in coredump_handler() because 'm' is not initialized yet

Reproducer:
~~~
 # fapolicyd --debug
 [...]
 01/22/26 10:48:37 [ INFO ]: Loading rpmdb backend
 ^CSegmentation fault (core dumped)
~~~

GDB shows:
~~~
(gdb) bt
 #0  mlist_first (m=m@entry=0x0) at daemon/mounts.c:86  <<<<< SECOND SEGFAULT
 linux-application-whitelisting#1  0x00005627e02de9ec in unmark_fanotify (m=0x0) at daemon/notify.c:258
 linux-application-whitelisting#2  0x00005627e02dda13 in coredump_handler (sig=11) at daemon/fapolicyd.c:336
 linux-application-whitelisting#3  coredump_handler (sig=11) at daemon/fapolicyd.c:333
 linux-application-whitelisting#4  <signal handler called>
 linux-application-whitelisting#5  __new_sem_post (sem=0x20) at sem_post.c:36         <<<<< FIRST SEGFAULT
 linux-application-whitelisting#6  <signal handler called>
 linux-application-whitelisting#7  __recvmsg_syscall (flags=0, msg=0x7ffe93e00350, fd=6) at ../sysdeps/unix/sysv/linux/recvmsg.c:27
 linux-application-whitelisting#8  __libc_recvmsg (fd=6, msg=msg@entry=0x7ffe93e00350, flags=flags@entry=0)
     at ../sysdeps/unix/sysv/linux/recvmsg.c:41
 linux-application-whitelisting#9  0x00005627e02eef82 in rpm_load_list (conf=<optimized out>) at library/rpm-backend.c:260
 linux-application-whitelisting#10 0x00005627e02ecc02 in backend_load (conf=conf@entry=0x5627e02fa0e0 <config>) at library/backend-manager.c:152
 linux-application-whitelisting#11 0x00005627e02e21c0 in init_database (config=config@entry=0x5627e02fa0e0 <config>) at library/database.c:1440
 linux-application-whitelisting#12 0x00005627e02db599 in main (argc=<optimized out>, argv=<optimized out>) at daemon/fapolicyd.c:1053
~~~
@rmetrich
Copy link
Contributor Author

Neither of these are on the hot path. Just check the value on entry and we're good to go.

OK, done.

@stevegrubb
Copy link
Member

Thanks!

@stevegrubb stevegrubb merged commit 6762080 into linux-application-whitelisting:main Jan 23, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants