Skip to content

Commit

Permalink
net: tcp2: fix unaligned access in the TCP2 stack
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nzmichaelh authored and jukkar committed Jul 22, 2020
1 parent 71e7cd3 commit b046ca5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion subsys/net/ip/tcp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions subsys/net/ip/tcp2_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
({ \
Expand Down Expand Up @@ -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; \
} \
\
Expand Down

0 comments on commit b046ca5

Please sign in to comment.