Fix use-after-free by tun thread after tun obj destroyed

The main thread calls pthread_cancel before freeing the tun object.
However, pthread_cancel doesn't kill the thread synchronously (man
pthread_cancel). Hence, the tun thread may still be running for a while
after the tun object is/has been(ing) freed.
Let's avoid this by making sure the thread is stopped before
freeing the object.
To accomplish it, we must wait for the thread to be cancelled. A cleanup
routie is added which will signal the "tun_released" message to the main
thread through an osmo_itq, which will then free the object (since
talloc context is managed by the main thread).

Related: SYS#5523
Change-Id: Idf005359afb41d3413b09281a9ff937d5eafcc7c
4 files changed
tree: 6dec07960b13297e171d77b755e45e42d45d4150
  1. contrib/
  2. daemon/
  3. debian/
  4. doc/
  5. ttcn3/
  6. .gitignore
  7. configure.ac
  8. git-version-gen
  9. Makefile.am
  10. README.md
README.md

osmo-uecups - Osmocom UE simulation control/user plane separation

This repository contains a C-language implementation of a simulator for the SGW/MME/UE side of GTP-U. It is part of the Osmocom Open Source Mobile Communications project.

This code is primarily intended to be used in testing of 2G/3G/4G GGSN and P-GW.

Every GTP tunnel (corresponding to a PDP context or EPC bearer) is terminated in a local 'tun' device, which in turn is put into its own network namespace.

This means you can simulate any number of users / sessions / bearers on a single machine without any routing nightmare.

The code only implements the user plane (GTP1U), and not the control plane like GTP1C or GTP2C. osmo-uecups-daemon exposes a JSON-over-SCTP protocol calleD UECUPS, which allows any external control plane instance to add/remove tunnels in the daemon

Homepage

The official homepage of the project is https://osmocom.org/projects/osmo-ggsn/wiki/osmo-uecups

GIT Repository

You can clone from the official osmo-bts.git repository using

git clone git://git.osmocom.org/osmo-uecups.git

There is a cgit interface at httsp://git.osmocom.org/osmo-uecups/

Documentation

FIXME

Mailing List

Discussions related to this software are happening on the osmocom-net-gprs@lists.osmocom.org mailing list, please see https://lists.osmocom.org/mailman/listinfo/osmocom-net-gprs for subscription options and the list archive.

Please observe the Osmocom Mailing List Rules when posting.

Contributing

Our coding standards are described at https://osmocom.org/projects/cellular-infrastructure/wiki/Coding_standards

We us a gerrit based patch submission/review process for managing contributions. Please see https://osmocom.org/projects/cellular-infrastructure/wiki/Gerrit for more details

The current patch queue for osmo-bts can be seen at https://gerrit.osmocom.org/#/q/project:osmo-uecups+status:open