net: tcp2: fix unaligned access in the TCP2 stack

The TCP2 stack does operations directly on the packet data which may
or may not be aligned.  The unaligned access causes a fault on the
Cortex-M0+ so use the UNALIGNED_* macros instead.

Signed-off-by: Michael Hope <mlhx@google.com>
This commit is contained in:
Michael Hope 2020-06-23 19:44:49 +02:00 committed by Jukka Rissanen
commit b046ca5409
2 changed files with 7 additions and 5 deletions

View file

@ -508,7 +508,8 @@ static bool tcp_options_check(struct tcp_options *recv_options,
goto end;
}
recv_options->mss = ntohs(*((uint16_t *)(options + 2)));
recv_options->mss =
ntohs(UNALIGNED_GET((uint16_t *)(options + 2)));
recv_options->mss_found = true;
NET_DBG("MSS=%hu", recv_options->mss);
break;

View file

@ -12,8 +12,8 @@
#define MIN3(_a, _b, _c) MIN((_a), MIN((_b), (_c)))
#endif
#define th_seq(_x) ntohl((_x)->th_seq)
#define th_ack(_x) ntohl((_x)->th_ack)
#define th_seq(_x) ntohl(UNALIGNED_GET(&(_x)->th_seq))
#define th_ack(_x) ntohl(UNALIGNED_GET(&(_x)->th_ack))
#define tcp_slist(_slist, _op, _type, _link) \
({ \
@ -211,8 +211,9 @@ struct tcp { /* TCP connection */
({ \
bool result = false; \
\
if (*(_fl) && (_cond) && (*(_fl) _op (_mask))) { \
*(_fl) &= ~(_mask); \
if (UNALIGNED_GET(_fl) && (_cond) && \
(UNALIGNED_GET(_fl) _op(_mask))) { \
UNALIGNED_PUT(UNALIGNED_GET(_fl) & ~(_mask), _fl); \
result = true; \
} \
\