Bug 293493 - in_pcb.h pulls in kernel headers when used in userspace
Summary: in_pcb.h pulls in kernel headers when used in userspace
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-02-27 17:47 UTC by Nick Reilly
Modified: 2026-03-24 20:11 UTC (History)
1 user (show)

See Also:


Attachments
Suggested patch (2.17 KB, patch)
2026-03-11 19:31 UTC, Nick Reilly
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Reilly 2026-02-27 17:47:27 UTC
in_pcb.h contains the definition of struct xinpcb for use by userspace applications. While it does have some sections of the file that are #ifdef _KERNEL, there are many other kernel parts that are not guarded, for example the first block of includes has kernel epoch and locking headers. My expectation is that these should not be pulled in when compiling user space code that uses the struct xinpcb.
Comment 1 Gleb Smirnoff freebsd_committer freebsd_triage 2026-02-28 02:52:39 UTC
Thanks Nick, that's a correct observation and needs to be improved. If you have a patch that is ready and tested (passes buildworld at least, but better pass tinderbox) I can push with your name as author.
Comment 2 Nick Reilly 2026-03-11 19:31:13 UTC
Created attachment 268732 [details]
Suggested patch

Sorry for the delay but here's a patch that works for me against main.

I don't have tinderbox setup, but it passes buildworld and buildkernel
Comment 3 Gleb Smirnoff freebsd_committer freebsd_triage 2026-03-11 19:40:38 UTC
Thanks a lot, Nick! I will probably also collapse all kernel related stuff into single piece and commit after some testing.
Comment 4 Gleb Smirnoff freebsd_committer freebsd_triage 2026-03-11 20:07:40 UTC
Ok, so appeared to be not so trivial, given presence of _WANT_INPCB. And I really want to do it right rather than quick fix.

Good news is that we have only once consumer of _WANT_INPCB left in the tree and I really want to remove it. I know there is also lsof outside of FreeBSD tree. But they will need to fix it themselves. We got all the APIs required to get data from kernel without going in there with dirty hands :)

I'll do that this month, as I'm already in the inpcb area right now.
Comment 5 Nick Reilly 2026-03-11 20:10:16 UTC
Sure, sounds good. Thanks!
Comment 6 commit-hook freebsd_committer freebsd_triage 2026-03-12 18:33:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=041e9eb1ae094a81e55fbcaba37eb2ac194658cc

commit 041e9eb1ae094a81e55fbcaba37eb2ac194658cc
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-03-12 18:02:27 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-03-12 18:32:30 +0000

    inpcb: overhaul in_pcb.h

    Pull up all user-visible stuff to the top of the file and isolate the
    rest under _KERNEL.  The user visible parts are:
    - struct in_conninfo
    - struct xinpcb
    - defines for inp_flags bits, that are shared between xinpcb and inpcb

    PR:     293493

 sys/netinet/in_pcb.h | 477 +++++++++++++++++++++++++--------------------------
 1 file changed, 231 insertions(+), 246 deletions(-)
Comment 7 Gleb Smirnoff freebsd_committer freebsd_triage 2026-03-24 20:11:13 UTC
Done properly in the main branch. The change won't be merged to stable branches.