Bug 268922 - Mk/Uses/kmod.mk: not WITH_PIE safe
Summary: Mk/Uses/kmod.mk: not WITH_PIE safe
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Rene Ladan
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-13 08:23 UTC by Alexander Leidinger
Modified: 2023-01-21 14:46 UTC (History)
1 user (show)

See Also:
rene: maintainer-feedback+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Leidinger freebsd_committer freebsd_triage 2023-01-13 08:23:32 UTC
Hi,

building the port with WITH_PIE makes it fail (error message tells that ld can't relocate a specific symbol and that it should be recompiled wiht -fPIE). Until this is fixed, the port should get PIE_UNSAFE=yes in the Makefile (this fixes the build for me).

Bye,
Alexander.
Comment 1 John Baldwin freebsd_committer freebsd_triage 2023-01-19 23:00:47 UTC
Why are you building a kernel module with a userland-only build setting?  Kernel modules are not executables, so PIE doesn't make sense for any kernel module.  Maybe Mk/users/kmod.mk should be patched to set PIE_UNSAFE just as it currently sets SSP_UNSAFE?  That would avoid needing to patch all the various kmod ports.
Comment 2 Alexander Leidinger freebsd_committer freebsd_triage 2023-01-20 07:48:47 UTC
I'm not building it that way on purpose, the ports collection / poudriere is doing that automatically when the documented way of enabling WITH_PIE (and WITH_BIND_NOW and WITH_RELO) is used.

I didn't check how the port builds the kld and simply used the documented workaround for ports which fail. I agree that a more generic fix is favourable.
Comment 3 Rene Ladan freebsd_committer freebsd_triage 2023-01-20 12:22:19 UTC
I added a PIE_UNSAFE tag locally in kmod.mk. The only downside I see is that if a port installs both kernel modules and userland binaries that the userland binaries are also automatically tagged as PIE_UNSAFE.
Comment 4 commit-hook freebsd_committer freebsd_triage 2023-01-21 13:32:37 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1e765fa4cbf289770f6c1a55b4ec339c2fc44990

commit 1e765fa4cbf289770f6c1a55b4ec339c2fc44990
Author:     Rene Ladan <rene@FreeBSD.org>
AuthorDate: 2023-01-20 12:22:41 +0000
Commit:     Rene Ladan <rene@FreeBSD.org>
CommitDate: 2023-01-21 13:13:46 +0000

    Mk/Uses: tag kmod.mk as PIE_UNSAFE

    Kernel modules are not executables, so marking them safe for being a
    position-indepentent executable does not make sense.
    PR:             268922

 Mk/Uses/kmod.mk | 1 +
 1 file changed, 1 insertion(+)
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-01-21 13:35:38 UTC
A commit in branch 2023Q1 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=833eef7f4c845d48d28749a14e45d0eb4b960a74

commit 833eef7f4c845d48d28749a14e45d0eb4b960a74
Author:     Rene Ladan <rene@FreeBSD.org>
AuthorDate: 2023-01-20 12:22:41 +0000
Commit:     Rene Ladan <rene@FreeBSD.org>
CommitDate: 2023-01-21 13:35:27 +0000

    Mk/Uses: tag kmod.mk as PIE_UNSAFE

    Kernel modules are not executables, so marking them safe for being a
    position-indepentent executable does not make sense.
    PR:             268922

    (cherry picked from commit 1e765fa4cbf289770f6c1a55b4ec339c2fc44990)

 Mk/Uses/kmod.mk | 1 +
 1 file changed, 1 insertion(+)