Cleanup: Re-organise source dir Re-organise the sources, add a top level "src" and "include" dir and move relevant files. Disable autotools automated includes and define them manually. This fixes problems with collision of header names with system headers. Include the autoconf config.h in the default includes and remove it where it's explicitely included. Remove _GNU_SOURCE defines since it's detected at configure for platforms that requires it and added to the config.h. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu_ref_get_safe: introduce new API Add a urcu_ref_get_safe API, which returns a boolean. It takes the value "false" if a LONG_MAX overflow would occur (get is not performed in this case), or true otherwise. It warns the user (at compile-time) if the return value is unchecked. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fix: handle reference count overflow The urcu refcounting API features a look and feel similar to the Linux kernel reference counting API, which has been the subject of CVE-2016-0728 (use-after-free). Therefore, improve the urcu refcounting API by dealing with reference counting overflow. For urcu_ref_get(), handle this by comparing the prior value with LONG_MAX before updating it with a cmpxchg. When an overflow would occur, trigger a abort() rather than allowing the overflow (which is a use-after-free security concern). For urcu_ref_get_unless_zero(), in addition to compare the prior value to 0, also compare it to LONG_MAX, and return failure (false) in both cases. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu/ref.h: implement urcu_ref_get_unless_zero() Allows getting a reference atomically if the reference count is not zero. Returns true if the reference is taken, false otherwise. This needs to be used in conjunction with another synchronization technique (e.g. RCU or mutex) to ensure existence of the reference count. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>