Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable hardening options in the build #3445

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

pmatilai
Copy link
Member

Commit 6e19c16 broke the build under Fedora default compiler flags due to missing mode argument to open(). Fix that and couple of not-handled return code cases, and make the build default to -fhardened to avoid this happening again.

The mode argument to open() is not optional when O_CREAT is used.
The compiler doesn't check for it by default but it breaks the build
under _FORTIFY_SOURCE

Fixes build regression on default Fedora flags introduced in commit
6e19c16
fchmodat() on glibc has warn_unused_result attribute and so this
emits a compiler warning with -fhardened, and that in turn breaks
the build with -Werror.

Using += is enough to trick the compiler to think we actually used
the value for something. We SHOULD handle failure here somehow
intelligently (eg differentiate between ENOENT and possible other
harmless errors etc) but can't dive to that just now.
@pmatilai pmatilai requested a review from a team as a code owner November 14, 2024 09:10
@pmatilai pmatilai requested review from ffesti and dmnks and removed request for a team November 14, 2024 09:10
@@ -82,8 +84,13 @@ static rpmRC audit_tsm_post(rpmPlugin plugin, rpmts ts, int res)
rasprintf(&eventTxt,
"op=%s %s sw_type=rpm key_enforce=%u gpg_res=%u %s",
op, nevra, enforce, verified, dir);
audit_log_user_comm_message(auditFd, AUDIT_SOFTWARE_UPDATE,
eventTxt, NULL, NULL, NULL, NULL, result);
if (audit_log_user_comm_message(auditFd, AUDIT_SOFTWARE_UPDATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this deserves a TODO comment, like the one in removeSBITS(), just so we can grep for these (in theory) in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it's actually just as easy to do the right thing and make it a warning, just filter out the message you get when auditd isn't running, similarly to what we do in systemd_inhibit and dbus_announce.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat, seems like the innocent nitpick turned into something more useful 😄

Copy link
Member Author

@pmatilai pmatilai Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. This is the kind of stuff that happens when you just want something quickly out of the way and instead of stopping to think for a second (because this is not the thing you're interested just now) you think to work around it somehow. And then later realize doing the right thing would've been at least as simple 🤦 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, having someone else stop you in the tracks, if just for a second, unlocks your hidden potential sometimes 😄

@pmatilai pmatilai force-pushed the hardened-pr branch 2 times, most recently from e4b2c63 to 154ece0 Compare November 14, 2024 12:42
audit_log_user_comm_message has warn_unused_result attribute and so this
emits a compiler warning with -fhardened, and that in turn breaks
the build with -Werror.

Emit a warning if audit log message fails, but suppress ECONNREFUSED to
silence spurious warnings in environments where audit daemon isn't
available, such as containers (like our test-suite) or rescue images.
This isn't entirely ideal but is consistent with what we do in similar
cases in eg systemd_inhibit (708e613)
and dbus_announce (071be75) plugins.

For extra entertainment, something in the GH CI environment causes
runroot_user tests to fail with EPERM, whereas no such errors occur
locally. Filter it out too.
This probably explains some of the oddities and seemingly missing
warnings we've been seeing...
This enables all manner of highly useful safety checks that we generally
want enabled.
@dmnks
Copy link
Contributor

dmnks commented Nov 14, 2024

Yay, all green now. Looks good now, thanks!

@dmnks dmnks merged commit 7713b8f into rpm-software-management:master Nov 14, 2024
1 check 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