pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-uecups/+/40787?usp=email )
Change subject: tun_device: Make sure struct iphdr access is 4-byte aligned
......................................................................
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(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-uecups refs/changes/87/40787/1
diff --git a/daemon/tun_device.c b/daemon/tun_device.c
index 6a0d8b6..5d71147 100644
--- a/daemon/tun_device.c
+++ b/daemon/tun_device.c
@@ -200,7 +200,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);
@@ -213,7 +215,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
https://gerrit.osmocom.org/c/osmo-uecups/+/40787?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-uecups
Gerrit-Branch: master
Gerrit-Change-Id: I610c8e9b150c234b7d4997e0b1c4d4a9ce4de9ec
Gerrit-Change-Number: 40787
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>