falcosecurity / libs

libsinsp, libscap, the kernel module driver, and the eBPF driver sources
https://falcosecurity.github.io/libs/
Apache License 2.0
222 stars 161 forks source link

Potential problems with strict-aliasing violations (libsinsp/fdinfo.cpp) #1964

Open hhoffstaette opened 1 month ago

hhoffstaette commented 1 month ago

Describe the bug

Gentoo QA complains about the following potential problems with strict-aliasing violations when doing naughty pointer things:

/tmp/portage/dev-debug/sysdig-0.38.1/work/libs-0.17.2/userspace/libsinsp/fdinfo.cpp: In member function 'virtual libsinsp::state::static_struct::field_infos sinsp_fdinfo::static_fields() const':
/tmp/portage/dev-debug/sysdig-0.38.1/work/libs-0.17.2/userspace/libsinsp/fdinfo.cpp:149:41: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  149 |         define_static_field(ret, this, ((uint64_t*) &m_sockinfo.m_ipv6info.m_fields.m_sip)[0], "socket_ipv6_src_ip_low");
      |                                        ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/portage/dev-debug/sysdig-0.38.1/work/libs-0.17.2/userspace/libsinsp/fdinfo.cpp:151:41: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  151 |         define_static_field(ret, this, ((uint64_t*) &m_sockinfo.m_ipv6info.m_fields.m_dip)[0], "socket_ipv6_dest_ip_low");
      |                                        ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/portage/dev-debug/sysdig-0.38.1/work/libs-0.17.2/userspace/libsinsp/fdinfo.cpp:159:41: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  159 |         define_static_field(ret, this, ((uint64_t*) &m_sockinfo.m_ipv6serverinfo.m_ip)[0], "socket_ipv6_server_ip_low");
      |                                        ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

How to reproduce it

Building sysdig-0.38.x+libs-0.17.2 with gcc-13.3 and -Werror=strict-aliasing should show this.

Expected behaviour

No QA violations (if possible)

Environment

Gentoo Linux, ~amd64 (testing)

6.10.0 :)

From source - I am the package maintainer

Additional context

I understand that accessing the union needs to accommodate the IPv6 address and have no immediate solution either. Sorry :disappointed:

FedeDP commented 1 month ago

/cc @LucaGuerra our pointer hero!