pespin submitted this change.
tun_device: Make sure struct iphdr access is 4-byte aligned
"struct iphdr" from netinet/ip.h used in parse_pkt() is not "packed",
hence compiler expects to find the struct pointer aligned to 4-bytes.
Re-arrange the stack buffer to make sure iphdr ends up being stored
aligned.
This was caught by running osmo-uecups with --enable-sanitize in TTCN3
testsuite ttcn3-5gc-test.
Change-Id: I610c8e9b150c234b7d4997e0b1c4d4a9ce4de9ec
---
M daemon/tun_device.c
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/daemon/tun_device.c b/daemon/tun_device.c
index 350e322..2c67d5c 100644
--- a/daemon/tun_device.c
+++ b/daemon/tun_device.c
@@ -203,7 +203,9 @@
{
struct tun_device *tun = (struct tun_device *)arg;
struct gtp_daemon *d = tun->d;
- uint8_t base_buffer[sizeof(struct gtp1_header) + sizeof(struct gtp1_exthdr) + MAX_UDP_PACKET];
+ /* Make sure "buffer" below ends up aligned to 4byte so that it can access struct iphdr in a 4-byte aligned way. */
+ const size_t payload_off_4byte_aligned = ((sizeof(struct gtp1_header) + sizeof(struct gtp1_exthdr)) + 3) & (~0x3);
+ uint8_t base_buffer[payload_off_4byte_aligned + MAX_UDP_PACKET];
int old_cancelst_unused;
pthread_cleanup_push(tun_device_pthread_cleanup_routine, tun);
@@ -216,7 +218,7 @@
struct gtp_tunnel *t;
struct pkt_info pinfo;
int rc, nread;
- uint8_t *buffer = base_buffer + sizeof(base_buffer) - MAX_UDP_PACKET;
+ uint8_t *buffer = base_buffer + payload_off_4byte_aligned;
/* 1) read from tun */
rc = read(tun->fd, buffer, MAX_UDP_PACKET);
To view, visit change 40787. To unsubscribe, or for help writing mail filters, visit settings.