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

gh-121996: Introduce --disable-safety and --enable-slower-safety options #122054

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ jobs:
with:
save: false
- name: Configure CPython
run: ./configure --config-cache --with-pydebug --with-openssl=$OPENSSL_DIR
run: ./configure --config-cache --enable-slower-safety --with-pydebug --with-openssl=$OPENSSL_DIR
- name: Build CPython
run: make -j4
- name: Display build info
Expand Down Expand Up @@ -380,6 +380,7 @@ jobs:
../cpython-ro-srcdir/configure \
--config-cache \
--with-pydebug \
--enable-slower-safety \
--with-openssl=$OPENSSL_DIR
- name: Build CPython out-of-tree
working-directory: ${{ env.CPYTHON_BUILDDIR }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
./configure \
--config-cache \
--with-pydebug \
--enable-slower-safety \
${{ inputs.free-threading && '--disable-gil' || '' }} \
--prefix=/opt/python-dev \
--with-openssl="$(brew --prefix openssl@3.0)"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
../cpython-ro-srcdir/configure
--config-cache
--with-pydebug
--enable-slower-safety
--with-openssl=$OPENSSL_DIR
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
- name: Build CPython out-of-tree
Expand Down
19 changes: 19 additions & 0 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,25 @@ Security Options
The settings ``python`` and *STRING* also set TLS 1.2 as minimum
protocol version.

.. option:: --disable-safety

Disable compiler options that are recommended by `OpenSSF`_ for security reasons with no performance overhead.
If this option is not enabled, CPython will be built based on safety compiler options with no slow down.

.. _OpenSSF: https://openssf.org/

.. versionadded:: 3.14

.. option:: --enable-slower-safety

Enable compiler options that are recommended by `OpenSSF`_ for security reasons which require overhead.
If this option is not enabled, CPython will not be built based on safety compiler options which performance impact.

.. _OpenSSF: https://openssf.org/

.. versionadded:: 3.14


macOS Options
-------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Introduce ./configure --disable-safety and --enable-slower-safety options.
Patch by Donghee Na.
49 changes: 46 additions & 3 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2499,9 +2499,28 @@ AS_VAR_IF([with_strict_overflow], [yes],

# Enable flags that warn and protect for potential security vulnerabilities.
# These flags should be enabled by default for all builds.
AX_CHECK_COMPILE_FLAG([-fstack-protector-strong], [BASECFLAGS="$BASECFLAGS -fstack-protector-strong"], [AC_MSG_WARN([-fstack-protector-strong not supported])], [-Werror])
AX_CHECK_COMPILE_FLAG([-Wtrampolines], [BASECFLAGS="$BASECFLAGS -Wtrampolines"], [AC_MSG_WARN([-Wtrampolines not supported])], [-Werror])
AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=3], [BASECFLAGS="$BASECFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"], [AC_MSG_WARN([-D_FORTIFY_SOURCE=3 not supported])])

AC_MSG_CHECKING([for --disable-safety])
AC_ARG_ENABLE([safety],
[AS_HELP_STRING([--disable-safety], [disable usage of the security compiler options with no performance overhead])],
[AS_VAR_IF([enable_safety], [yes], [disable_safety=no], [disable_saftey=yes])], [disable_saftey=no])
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: disable_saftey should be disable_safety

AC_MSG_RESULT([$disable_safety])

if test "$disable_safety" = "no"
then
AX_CHECK_COMPILE_FLAG([-fstack-protector-strong], [BASECFLAGS="$BASECFLAGS -fstack-protector-strong"], [AC_MSG_WARN([-fstack-protector-strong not supported])], [-Werror])
AX_CHECK_COMPILE_FLAG([-Wtrampolines], [BASECFLAGS="$BASECFLAGS -Wtrampolines"], [AC_MSG_WARN([-Wtrampolines not supported])], [-Werror])
Copy link
Contributor

Choose a reason for hiding this comment

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

The mixing of warning options with an actual codegen option (SSP) doesn't feel ideal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, tbh, pretty much every Linux distro builds with SSP and _F_S=2 at least..

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's handle it as the seperate PR cc @nohlson

fi

AC_MSG_CHECKING([for --enable-slower-safety])
AC_ARG_ENABLE([slower-safety],
[AS_HELP_STRING([--enable-slower-safety], [enable usage of the security compiler options with performance overhead])],[])
AC_MSG_RESULT([$enable_slower_safety])

if test "$enable_slower_safety" = "yes"
then
AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=3], [BASECFLAGS="$BASECFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"], [AC_MSG_WARN([-D_FORTIFY_SOURCE=3 not supported])])
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use AX_ADD_FORTIFY_SOURCE.

Copy link
Member Author

@corona10 corona10 Jul 22, 2024

Choose a reason for hiding this comment

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

#122054 (comment) ditto,
This PR is not about compiler options but more about how we can enable them and disable them without interuptting @nohlson 's experimentation.

fi

case $GCC in
yes)
Expand Down
Loading