intel / ledmon

Enclosure LED Utilities
GNU General Public License v2.0
72 stars 44 forks source link

Add compiler defenses flags #145

Closed pawpiatko closed 10 months ago

pawpiatko commented 11 months ago

It is essential to avoid buffer overflows and similar bugs as much as possible.

Add AX_CHECK_LINK_FLAG macro usage witch requires autoconf-archive package to be installed.

Add compiler flags: -D_FORTIFY_SOURCE - Compile-time protection against static sized buffer overflows, -fstack-protector-strong - Adds stack canaries to functions as safety checks against stack overwrites, -fPIE - Enables an ELF binary executable to be position independent, -fPIC - Ensures that shared object code that is built into shared libraries should be position independent code,.

Add linker flags: -pie - works together with gcc flag fPIE- please see its description, -z,relro - A security measure which makes some binary sections read-only, -z,now - Immediate Binding (Bindnow), -z,noexecstack - Prevents stack from being executable.

Add 'autoconf-archive' package dependency to github workflows. This package is requied by githab actions.

Fix compilation warnings.

ktanska commented 11 months ago

Verified

mtkaczyk commented 10 months ago

@tasleson It seems that we introduced an issue in Makefiles by overwriting AM_CFLAGS. We determined that the flags are lost. Here original code:

AM_CFLAGS = -I$(top_srcdir)/src/lib/include -I$(top_srcdir)/src -I$(top_srcdir)/config -I$(top_srcdir)/src/lib
{...}
ledmon_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS)

Could you please take a look and see if the changes have sense?

tasleson commented 10 months ago

@tasleson It seems that we introduced an issue in Makefiles by overwriting AM_CFLAGS. We determined that the flags are lost. Here original code:

AM_CFLAGS = -I$(top_srcdir)/src/lib/include -I$(top_srcdir)/src -I$(top_srcdir)/config -I$(top_srcdir)/src/lib
{...}
ledmon_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS)

Some observations on this

mtkaczyk commented 10 months ago

Some observations on this

  • Distributions will have their own preferred set of compiler/linker flags that are used during packaging which will override what the project is specifying
  • We have some additional compiler warnings

We are obligated to follow Intel rules and those flags are required . Adding them here is the simplest solution but I agree that it is aggressive. Another option is to make a test compilation with more "controversial" flags and "-Werror" to break on any warning. I think that fits better because we can just ignore failing test until we get the warning resolved.

This PR doesn't compile for me. The CI checks are not running configure and enabling the library and the building of the unit tests.

Thanks, I think it is it something we should improve. Feel free to open the issue.

@pawpiatko please take a look.

tasleson commented 10 months ago

Thanks, I think it is it something we should improve. Feel free to open the issue.

Opened PR: https://github.com/intel/ledmon/pull/157

pawpiatko commented 10 months ago

tasleson could you please verify this change on your side? How can I reproduce warnings from utils files? Our compilation tests on GH actions are not catching them.

tasleson commented 10 months ago

tasleson could you please verify this change on your side? How can I reproduce warnings from utils files? Our compilation tests on GH actions are not catching them.

I'm using gcc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1). I think the compilers used for CI are older. Please see: https://github.com/intel/ledmon/pull/162

ktanska commented 10 months ago

@pawpiatko you can add gcc 13 to file https://github.com/intel/ledmon/blob/master/.github/workflows/review.yml and check the results then.

pawpiatko commented 10 months ago

@tasleson I'm still unable to reproduce it after adding gcc 13 to our CI. Could you please fix them out your side after submitting this change?

tasleson commented 10 months ago

@tasleson I'm still unable to reproduce it after adding gcc 13 to our CI. Could you please fix them out your side after submitting this change?

That is interesting. As I've mentioned a couple of times, I have PR up that includes this PR before the gcc-13 addition which also includes a fix for the utils warnings ref. 43915fc2c16b90db8a8ad1e88b4b8de441b77432

When this PR gets merged, I can fix up my PR for the other things I found and resubmit it.