Bug 284270 - Add new features fortify, stack_autoinit and zeroregs
Summary: Add new features fortify, stack_autoinit and zeroregs
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Ports Framework (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Port Management Team
URL:
Keywords: feature
Depends on:
Blocks:
 
Reported: 2025-01-22 19:11 UTC by Alexander Leidinger
Modified: 2025-05-24 18:35 UTC (History)
2 users (show)

See Also:
netchild: maintainer-feedback? (portmgr)


Attachments
Add new Features "zeroreg" and "stack_autoinit". (640 bytes, patch)
2025-01-22 19:11 UTC, Alexander Leidinger
no flags Details | Diff
zeroreg feature (819 bytes, text/plain)
2025-01-22 19:12 UTC, Alexander Leidinger
no flags Details
stack_autoinit feature (587 bytes, text/plain)
2025-01-22 19:12 UTC, Alexander Leidinger
no flags Details
do not use zeroregs with python ports (412 bytes, patch)
2025-01-22 19:15 UTC, Alexander Leidinger
no flags Details | Diff
Add new Features "fortify", "stack_autoinit" and "zeroregs" (649 bytes, patch)
2025-03-21 19:25 UTC, Alexander Leidinger
no flags Details | Diff
fortify feature (304 bytes, patch)
2025-03-21 19:25 UTC, Alexander Leidinger
no flags Details | Diff
do not use zeroregs with python ports (413 bytes, patch)
2025-03-21 19:26 UTC, Alexander Leidinger
no flags Details | Diff
stack_autoinit feature (580 bytes, patch)
2025-03-21 19:27 UTC, Alexander Leidinger
no flags Details | Diff
zeroregs feature (981 bytes, patch)
2025-03-21 19:27 UTC, Alexander Leidinger
no flags Details | Diff
all in one patch - contains all of the other attachments (3.43 KB, patch)
2025-05-24 13:50 UTC, Alexander Leidinger
no flags Details | Diff
all in one patch (3.93 KB, patch)
2025-05-24 16:25 UTC, Alexander Leidinger
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Leidinger freebsd_committer freebsd_triage 2025-01-22 19:11:21 UTC
Created attachment 256911 [details]
Add new Features "zeroreg" and "stack_autoinit".

stack_autoinit is like OPT_INIT_ALL=zero for src.conf (zeros unitialized variables).
zeroreg is the same as https://cgit.freebsd.org/src/commit/?id=2a44cccd404d94c273c78e279df3fdc5531d25a2
Comment 1 Alexander Leidinger freebsd_committer freebsd_triage 2025-01-22 19:12:02 UTC
Created attachment 256912 [details]
zeroreg feature

add zeroreg file
Comment 2 Alexander Leidinger freebsd_committer freebsd_triage 2025-01-22 19:12:32 UTC
Created attachment 256913 [details]
stack_autoinit feature
Comment 3 Alexander Leidinger freebsd_committer freebsd_triage 2025-01-22 19:15:33 UTC
Created attachment 256914 [details]
do not use zeroregs with python ports
Comment 4 Alexander Leidinger freebsd_committer freebsd_triage 2025-01-22 19:17:08 UTC
I have both running on a jail host with postgresql/mysql/postfix/dovecot/bind/unbound/adguard/nginx/php/java/...
Comment 5 Alexander Leidinger freebsd_committer freebsd_triage 2025-01-25 17:39:24 UTC
I just noticed that for src I used ZEROREGS (committed) and for ports I used ZEROREG. For an approved commit I would use with S to be consistent with src.
Comment 6 Baptiste Daroussin freebsd_committer freebsd_triage 2025-03-21 14:18:40 UTC
Are you are you using "mailto:" ?

Other that this looks ok to me.
Comment 7 Alexander Leidinger freebsd_committer freebsd_triage 2025-03-21 19:25:18 UTC
Created attachment 258891 [details]
Add new Features "fortify", "stack_autoinit" and "zeroregs"
Comment 8 Alexander Leidinger freebsd_committer freebsd_triage 2025-03-21 19:25:46 UTC
Created attachment 258892 [details]
fortify feature
Comment 9 Alexander Leidinger freebsd_committer freebsd_triage 2025-03-21 19:26:26 UTC
Created attachment 258893 [details]
do not use zeroregs with python ports
Comment 10 Alexander Leidinger freebsd_committer freebsd_triage 2025-03-21 19:27:02 UTC
Created attachment 258894 [details]
stack_autoinit feature
Comment 11 Alexander Leidinger freebsd_committer freebsd_triage 2025-03-21 19:27:31 UTC
Created attachment 258895 [details]
zeroregs feature
Comment 12 Alexander Leidinger freebsd_committer freebsd_triage 2025-03-21 19:29:20 UTC
(In reply to Baptiste Daroussin from comment #6)
Removed the mailto, renamed from zerorg to zeroregs to match src as already commented, and added the fortify feature (also in use since a while in my local builds).

Good to commit?
Comment 13 Mathieu Arnold freebsd_committer freebsd_triage 2025-05-24 13:00:35 UTC
Is there a complete patch somewhere ?
Comment 14 Alexander Leidinger freebsd_committer freebsd_triage 2025-05-24 13:50:38 UTC
Created attachment 260685 [details]
all in one patch - contains all of the other attachments
Comment 15 Alexander Leidinger freebsd_committer freebsd_triage 2025-05-24 13:52:15 UTC
(In reply to Mathieu Arnold from comment #13)
Attachments 1+3 are small patches to add the features to the list and to mark the python ports zerorgs-unsafe. The other attachments are new files for the features directory.

I added the "all in one patch" which contains all of the other attachments.
Comment 16 Mathieu Arnold freebsd_committer freebsd_triage 2025-05-24 15:41:15 UTC
I have no idea what those three features do exactly. If possible, could you add a few lines of comment explaining what they are would be great.

By "what it does", I don't mean "add foo to CFLAGS" or "brush a thin coat of egg white on the crust" but more like "egg whites help the crust develop a deep gold colour"

I know some features don't explain anything, and I would consider it a bug :-)

Other than that, I trust bapt's judgement, looks ok to me too :-)
Comment 17 Alexander Leidinger freebsd_committer freebsd_triage 2025-05-24 16:25:04 UTC
Created attachment 260687 [details]
all in one patch

Add descriptions of what it does instead of relying on knowledge of the basesystem features.
Comment 18 Alexander Leidinger freebsd_committer freebsd_triage 2025-05-24 16:26:09 UTC
(In reply to Mathieu Arnold from comment #16)
Description added to the two features which didn't had them.
Comment 19 Mathieu Arnold freebsd_committer freebsd_triage 2025-05-24 17:42:20 UTC
Thank you, feel free to commit :-)
Comment 20 commit-hook freebsd_committer freebsd_triage 2025-05-24 18:21:57 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7a489e95c51f47f5e25a5613e375ec000618e52a

commit 7a489e95c51f47f5e25a5613e375ec000618e52a
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2025-05-24 18:17:24 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2025-05-24 18:21:13 +0000

    Mk/Features: Add features for fortify, zeroregs and stack autoinit.

    Those 3 features for ports go along with the cooresponding features from
    the basesystem (some only availabe in -current).

    The options you can put into make.conf for the ports collections are:

    WITH_FORTIFY=yes
        This enables mitigations of common memory safety issues, such as buffer
        overflows, by adding checks to functions like memcpy, strcpy, sprintf,
        and others when the compiler can determine the size of the destination
        buffer at compile time.

    WITH_STACK_AUTOINIT=yes
        This enables a compiler specific option to automatically initialize
        local (automatic) variables to prevent the use of uninitialized memory.

    WITH_ZEROREGS=yes
        Zero call-used registers at function return to increase program
        security by either mitigating Return-Oriented Programming (ROP)
        attacks or preventing information leakage through registers.
        This depends upon support from the compiler for a given architecture.
        This is disabled for python ports, currently there are issues.

    Approved by:    portmgr (mat)
    PR:             284270

 Mk/Features/fortify.mk (new)        | 18 ++++++++++++++++++
 Mk/Features/stack_autoinit.mk (new) | 23 +++++++++++++++++++++++
 Mk/Features/zeroregs.mk (new)       | 28 ++++++++++++++++++++++++++++
 Mk/Uses/python.mk                   |  2 ++
 Mk/bsd.port.mk                      |  3 ++-
 5 files changed, 73 insertions(+), 1 deletion(-)