Page MenuHomeFreeBSD

Prepare the system for _FORTIFY_SOURCE
AcceptedPublic

Authored by kevans on Oct 5 2021, 3:48 AM.
Tags
None
Referenced Files
F81987461: D32307.diff
Wed, Apr 24, 4:46 AM
Unknown Object (File)
Sun, Apr 21, 9:56 PM
Unknown Object (File)
Tue, Apr 16, 5:30 AM
Unknown Object (File)
Fri, Apr 12, 6:54 AM
Unknown Object (File)
Sat, Mar 30, 5:00 PM
Unknown Object (File)
Feb 17 2024, 8:45 PM
Unknown Object (File)
Feb 6 2024, 9:42 PM
Unknown Object (File)
Jan 3 2024, 4:27 PM

Details

Reviewers
ngie
imp
Group Reviewers
Klara
Summary

Notably:

  • libc needs to #undef some of the macros from ssp/* for underlying implementations
  • ssp/* wants a __RENAME() macro (snatched more or less from NetBSD)

There's some extra hinkiness included for read(), since libc spells it
as "_read" while the rest of the world spells it "read."

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 41956
Build 38844: arc lint + arc unit

Event Timeline

kevans requested review of this revision.Oct 5 2021, 3:48 AM

Re _read, I thought all system calls had three functions foo, _foo and sys_foo depending on which layer of indirection you were trying to bypass... I know that's why libc uses things like _read and _write.

In D32307#729071, @imp wrote:

Re _read, I thought all system calls had three functions foo, _foo and sys_foo depending on which layer of indirection you were trying to bypass... I know that's why libc uses things like _read and _write.

Right, sorry, I need to update that comment.

In D32307#729071, @imp wrote:

Re _read, I thought all system calls had three functions foo, _foo and sys_foo depending on which layer of indirection you were trying to bypass... I know that's why libc uses things like _read and _write.

Right, sorry, I need to update that comment.

You've likely already thought of this, but if not... do we need to _FORTIFY_SOURCE system calls that FreeBSD has that are 'read like' that aren't in NetBSD?

arichardson added inline comments.
lib/libc/amd64/string/bcopy.c
14

(bcopy) will prevent function macro expansion, no need for #undef. Same for the other files.

kib added inline comments.
lib/libc/Makefile
24

I am not sure about all current and future uses of this define, but I dislike it being taken from the user namespace.

Usually we use something like _IN_LIBC

lib/libc/Makefile
24

It also wouldn't be used much, but I wonder if it'd be better to just -D_FORTIFY_SOURCE_read=_read and default _FORTIFY_SOURCE_read to read in the header.

Just prevent macro expansion, and use -D_FORTIFY_SOURCE_read instead of defining
some indicator for "in libc" to be misused later.

imp requested changes to this revision.Sep 25 2022, 4:57 AM
imp added inline comments.
lib/libc/sys/read.c
39

you only changed an include...
and nothing else...
So what does this accomplish?

sys/sys/cdefs.h
637–638

I'm torn on this #else...
It means that no compilers that don't define PCC nor GNUC will be an automatic error
EVEN IF THEY DONT USE __RENAME()

So that's bad, right? I'd be tempted to either leave it undefined or # it like you do for kernel standalone....

This revision now requires changes to proceed.Sep 25 2022, 4:57 AM
kevans marked an inline comment as done.
  • Remove include that was shadily added that doesn't seem to be needed now
  • Don't break with __RENAME() use unless it's used

The latter means these compilers can still build against our headers as long as
they don't enable _FORTIFY_SOURCE.

des added inline comments.
contrib/netbsd-tests/lib/libc/ssp/h_gets.c
37

What if it's defined to 0?

contrib/netbsd-tests/lib/libc/ssp/h_gets.c
37

Meh, why not just #undef it unconditionally? We're not bringing gets() back, and if we do as a macro then it's still going to blow up the below __sym_compat

Just undefine gets unconditionally, note with a comment why

Remove bogus header that crept in

I think a rebase is in order... this diff is picking up a lot of "noise" that have nothing to do with fortify....

lib/libc/Makefile
70–71

seems like this could be its own thing, no?

73

Here (and elsewhere) this change could be its own commit.

113–118

This is a good change, but could be separate. It's not related to foritfy.

133–136

nice cleanup, also independent of fortify.

lib/libc/amd64/string/bzero.c
5

is this really still around. Yikes!

lib/libc/stdio/sprintf.c
44

This stuff is long gone... rebase needed?

In D32307#1023676, @imp wrote:

I think a rebase is in order... this diff is picking up a lot of "noise" that have nothing to do with fortify....

This set of comments doesn't seem to make much sense when viewed on the current version of the review... I suspect it might have produced on the diff of old/new that brought it forward 3 years?

this looks good to me now (forget about my other comments... I clicked some something weird maybe?)

lib/libc/Makefile
70–71

nevermind.. Don't know what I clicked on, but there were lots of noise like this...

This revision is now accepted and ready to land.Mon, Apr 22, 7:25 PM