Page MenuHomeFreeBSD

kernel: Enable -fstack-protector-strong
ClosedPublic

Authored by markj on May 7 2026, 4:32 PM.
Tags
None
Referenced Files
F163375068: D56870.diff
Wed, Jul 22, 3:35 PM
F163354807: D56870.id177370.diff
Wed, Jul 22, 11:02 AM
Unknown Object (File)
Tue, Jul 21, 6:34 PM
Unknown Object (File)
Wed, Jul 15, 7:21 AM
Unknown Object (File)
Wed, Jul 15, 7:21 AM
Unknown Object (File)
Jun 20 2026, 3:53 PM
Unknown Object (File)
Jun 16 2026, 9:13 PM
Unknown Object (File)
Jun 16 2026, 11:29 AM

Details

Summary

This extends stack canary use to all functions which perform operations
on arrays, not just those which operate on byte buffers.

Test Plan

I ran will-it-scale on a 16-core ryzen 7950X3D (hyperthreading enabled, will disable it if I do another run): https://people.freebsd.org/~markj/stack-protector-strong/will-it-scale2.html

The results aren't very conclusive. (will-it-scale also isn't a great test for this, but it's convenient and I have some scripts for it.) The stack-protector option changes the kernel's .text layout and I suspect that the small differences observed in the benchmark are a result of that rather than direct overhead of the option itself. In particular:

   text    data     bss     dec     hex filename
21042932        1756749 8728192 31527873        1e113c1 /boot/kernel.no-stack-protector/kernel
21142484        1756749 8728192 31627425        1e298a1 /boot/kernel.stack-protector/kernel
21485116        1756749 8728192 31970057        1e7d309 /boot/kernel.stack-protector-strong/kernel

and across the benchmarks there's no consistent "winner". I wouldn't expect the kernel to matter at all for the malloc 1KB benchmarks for instance, as there are no system calls happening.

With -fstack-protector-strong something like ~9000 functions in the kernel are covered, versus ~1500 by default. (This isn't counting kernel modules.)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 72878
Build 69761: arc lint + arc unit

Event Timeline

markj requested review of this revision.May 7 2026, 4:32 PM
olivier added a subscriber: olivier.

No performance impact (CPU usage increase) for our use case

This revision is now accepted and ready to land.May 12 2026, 9:02 PM
olce added a subscriber: olce.

Great!