Skip to content

fix: add hardening compiler flags in debian/rules#434

Merged
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:sec
Jul 3, 2025
Merged

fix: add hardening compiler flags in debian/rules#434
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:sec

Conversation

@mhduiy

@mhduiy mhduiy commented Jul 2, 2025

Copy link
Copy Markdown
Contributor
  1. Added DEB_CFLAGS_MAINT_APPEND with -Wall for C compiler warnings
  2. Added DEB_CXXFLAGS_MAINT_APPEND with -Wall for C++ compiler warnings
  3. Added DEB_LDFLAGS_MAINT_APPEND with multiple security hardening flags:
    • --as-needed for linker optimization
    • -z relro for RELRO protection
    • -z now for immediate binding
    • -z noexecstack for non-executable stacks
    • -E for exporting symbols
  4. These changes improve security and code quality by enabling additional warnings and linker protections

fix: 在 debian/rules 中添加编译器加固标志

  1. 为 C 编译器添加 DEB_CFLAGS_MAINT_APPEND 并启用 -Wall 警告
  2. 为 C++ 编译器添加 DEB_CXXFLAGS_MAINT_APPEND 并启用 -Wall 警告
  3. 为链接器添加 DEB_LDFLAGS_MAINT_APPEND 包含多个安全加固标志:
    • --as-needed 用于链接器优化
    • -z relro 用于 RELRO 保护
    • -z now 用于立即绑定
    • -z noexecstack 用于非可执行栈
    • -E 用于导出符号
  4. 这些更改通过启用额外的警告和链接器保护来提高安全性和代码质量

Summary by Sourcery

Enable additional compiler warnings and linker hardening flags in debian packaging to improve security and code quality

Build:

  • Append '-Wall' to DEB_CFLAGS_MAINT_APPEND for C compiler warnings
  • Append '-Wall' to DEB_CXXFLAGS_MAINT_APPEND for C++ compiler warnings
  • Append security hardening flags (--as-needed, -z relro, -z now, -z noexecstack, -E) to DEB_LDFLAGS_MAINT_APPEND

1. Added DEB_CFLAGS_MAINT_APPEND with -Wall for C compiler warnings
2. Added DEB_CXXFLAGS_MAINT_APPEND with -Wall for C++ compiler warnings
3. Added DEB_LDFLAGS_MAINT_APPEND with multiple security hardening
flags:
   - --as-needed for linker optimization
   - -z relro for RELRO protection
   - -z now for immediate binding
   - -z noexecstack for non-executable stacks
   - -E for exporting symbols
4. These changes improve security and code quality by enabling
additional warnings and linker protections

fix: 在 debian/rules 中添加编译器加固标志

1. 为 C 编译器添加 DEB_CFLAGS_MAINT_APPEND 并启用 -Wall 警告
2. 为 C++ 编译器添加 DEB_CXXFLAGS_MAINT_APPEND 并启用 -Wall 警告
3. 为链接器添加 DEB_LDFLAGS_MAINT_APPEND 包含多个安全加固标志:
   - --as-needed 用于链接器优化
   - -z relro 用于 RELRO 保护
   - -z now 用于立即绑定
   - -z noexecstack 用于非可执行栈
   - -E 用于导出符号
4. 这些更改通过启用额外的警告和链接器保护来提高安全性和代码质量
@sourcery-ai

sourcery-ai Bot commented Jul 2, 2025

Copy link
Copy Markdown

Reviewer's Guide

Extended debian/rules to append -Wall to C/C++ warnings and apply linker hardening flags (--as-needed, -z relro, -z now, -z noexecstack, -E) for improved security and code quality.

File-Level Changes

Change Details Files
Enabled strict warning flags for C and C++ compilers
  • Added DEB_CFLAGS_MAINT_APPEND with -Wall
  • Added DEB_CXXFLAGS_MAINT_APPEND with -Wall
debian/rules
Configured linker with security hardening options
  • Appended --as-needed
  • Appended -z relro
  • Appended -z now
  • Appended -z noexecstack
  • Appended -E
debian/rules

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @mhduiy - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

在提供的 debian/rules 文件更改中,添加了一些新的环境变量来增强构建过程中的编译和链接选项。以下是对这些更改的审查:

代码质量

  • 环境变量设置:新增的环境变量 DEB_CFLAGS_MAINT_APPENDDEB_CXXFLAGS_MAINT_APPENDDEB_LDFLAGS_MAINT_APPEND 用于追加编译器和链接器的标志。这些标志有助于提高代码质量,例如启用所有警告 (-Wall),以及优化链接过程 (-Wl,--as-needed, -Wl,-z,relro, -Wl,-z,now, -Wl,-z,noexecstack, -Wl,-E)。

代码性能

  • 链接优化:添加的链接器标志 -Wl,--as-needed-Wl,-z,relro-Wl,-z,now-Wl,-z,noexecstack-Wl,-E 旨在优化二进制文件的性能和安全性。例如,-Wl,--as-needed 会移除未使用的库,-Wl,-z,relro-Wl,-z,now 用于减少内存泄漏,-Wl,-z,noexecstack 防止栈溢出攻击,-Wl,-E 确保所有符号都可见。

代码安全性

  • 编译器警告:通过 -Wall 标志启用所有编译器警告,有助于发现潜在的错误和问题,从而提高代码的安全性。
  • 链接器安全选项-Wl,-z,relro-Wl,-z,now 选项有助于提高二进制文件的安全性,通过减少内存泄漏和延迟绑定。

代码维护

  • 环境变量命名:使用 DEB_ 前缀来命名环境变量,符合 Debian 包维护的最佳实践,确保这些设置在构建过程中被正确应用。

建议

  • 文档说明:建议在 debian/rules 文件中添加注释,说明为什么选择这些特定的编译和链接标志,以及它们对项目的影响。这有助于其他维护者理解这些更改的目的和重要性。

总体来说,这些更改有助于提高代码的质量、性能和安全性,是一个积极的改进。

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mhduiy mhduiy merged commit 451d32f into linuxdeepin:master Jul 3, 2025
13 of 15 checks 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.

3 participants