-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Unset D_FORTIFY_SOURCE and remove unneeded copied functions #8556
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
Conversation
Commit 4e2ab71 reverts micropython/micropython@5cf71b5 which solved micropython#6046, which I'm seeing again on my gentoo system with D_FORTIFY_HARDENED enabled by default. Unfortunately we can't just revert the revertion because circuitpython enforces prototypes for defined functions, which is why 4e2ab71 was implemented initially. Micropython doesn't suffer from this issue. The implemented fix is to just circumvent D_FORTIFY_SOURCE, a nice side-effect is we can remove the re-implemented functions that were added on the initial `string.h` removal.
|
Could you give more background on this? Which toolchain are you compiling with? We don't see this issue ourselves. Is it specific on gentoo? Is it is just when you compile |
I'm using gentoo's crossdev
This can be reproduced by defining the
It happens on any toolchain built with source hardening.
I think this file is the only one affected.
No, although if you follow the linked commits & issues you'll see that a function in this file was created to support source hardening and then was undone in 4e2ab71 so the defined function isn't necessary anymore. ensuring that source hardening is turned off circumvents this issue & workarounds (that don't work anymore) See micropython#6046
$ make BOARD=adafruit_feather_rp2040 V=4 |
|
The reason I'm asking is that in the past few merges from MicroPython sources, we've trying to reduce the differences between the files we share with MicroPython. So this change is an increase in skew. Could you fix this in both MicroPython and CircuitPython by guarding the definition of We are also labeling differences from upstream with |
Okay, that makes a lot of sense. Would a better approach then be to provide a |
|
For your particular case, can you leave our prototype declaration in and conditionalize the
I am little confused by this, because it don't see 4e2ab71 as a full revert, but just adding the declaration and changing the include. But I may be misunderstanding something. In other words, can you keep the upstream declaration, and add/conditionalize whatever is necessary to make both our regular builds and your builds work? |
Sorry for the confusion, thanks for bearing with me. The issue I'm seeing was introduced with the
I can re-add the I'll say again though, if your goal is to maintain parity than the ideal way forward would probably be removing the |
|
another possible alternative (only compile-tested, for adafruit feather rp2040, with -D_FORTIFY_SOURCE=1 manually added to CFLAGS) commit 1650ce6d42e3106e2e60d0e2984dfcd0829d8162
Author: Jeff Epler <jepler@gmail.com>
Date: Sat Nov 4 21:07:21 2023 +0100
string0: Undo any definition of these to macros
.. which can occur in <string.h>, particularly when -D_FORTIFY_SOURCE,
which we otherwise rely on to provide a prototype.
diff --git a/shared/libc/string0.c b/shared/libc/string0.c
index b0a2620300..9e97002c29 100644
--- a/shared/libc/string0.c
+++ b/shared/libc/string0.c
@@ -28,6 +28,14 @@
#include <stddef.h>
#include <string.h>
+#undef memcpy
+#undef memmove
+#undef memset
+#undef stpcpy
+#undef strcpy
+#undef strcat
+#undef strncpy
+
#include "py/mpconfig.h"
#ifndef likely |
|
yet another possibilty diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index 5f0af02a6e..701156cd1a 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -52,7 +52,8 @@ BASE_CFLAGS = \
-DCIRCUITPY_CANARY_WORD=0xADAF00 \
-DCIRCUITPY_SAFE_RESTART_WORD=0xDEADBEEF \
-DCIRCUITPY_BOARD_ID="\"$(BOARD)\"" \
- --param max-inline-insns-single=500
+ --param max-inline-insns-single=500 \
+ -U_FORTIFY_SOURCE
# Use these flags to debug build times and header includes.
# -ftime-reportto disable _FORTIFY_SOURCE everywhere; this might get rid of the need to have the "chk" version of memcpy, too. |
|
Yeah @jepler, disabling that flag everywhere might be preferred even if the issue has only exposed itself to me for this file (there could definitely be others, though) both those solutions seem to work for me, thanks for acknowledging the intention behind the |
|
I'm closing this since we took one of the alternative solutions in #8663 -- please feel free to continue the conversation if this is still not resolved for you. |
Commit 4e2ab71 reverts micropython/micropython@5cf71b5 which solved micropython#6046, which I'm seeing again on my gentoo system with D_FORTIFY_HARDENED enabled by default.
Unfortunately we can't just revert the revertion because circuitpython enforces prototypes for defined functions, which is why 4e2ab71 was implemented initially. Micropython doesn't suffer from this issue.
The implemented fix is to just circumvent D_FORTIFY_SOURCE, a nice side-effect is we can remove the re-implemented functions that were added on the initial
string.hremoval.