Skip to content

net_if: misaligned access #88665

@ghost

Description

Describe the bug
UB sanitizers finds misaligned reads/writes of struct in_addr when running in native_sim.

To Reproduce

  1. Build for native_sim with UB-sanitizer enabled
  2. Run the sim
  3. Network Ping
  4. ->UB sanitizer finds misaligned accesses

Expected behavior
UB sanitizer should not find misaligned access under those circumstances.

Impact

  • Either those are a real problem
  • Or they are false positives, and the UB sanitizer can not be used to test an application in above circumstances to find actual problems

Logs and console output
Snippes tripping UBsan:

/**
 * @brief Check if the IPv4 address is a loopback address (127.0.0.0/8).
 *
 * @param addr IPv4 address
 *
 * @return True if address is a loopback address, False otherwise.
 */
static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
{
	return addr->s4_addr[0] == 127U;
}
/**
 *  @brief Compare two IPv4 addresses
 *
 *  @param addr1 Pointer to IPv4 address.
 *  @param addr2 Pointer to IPv4 address.
 *
 *  @return True if the addresses are the same, false otherwise.
 */
static inline bool net_ipv4_addr_cmp(const struct in_addr *addr1,
				     const struct in_addr *addr2)
{
	return UNALIGNED_GET(&addr1->s_addr) == UNALIGNED_GET(&addr2->s_addr);
}
/**
 * @brief Check if the IPv4 address is a multicast address.
 *
 * @param addr IPv4 address
 *
 * @return True if address is multicast address, False otherwise.
 */
static inline bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
{
	return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xF0000000) == 0xE0000000;
}

Environment (please complete the following information):
TBD

Additional context
TBD

Metadata

Metadata

Assignees

Labels

area: NetworkingbugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions