[PATCH v2 1/1] write_queue: Avoid possible use-after-free if fd is read-/writable

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Pablo Neira Ayuso pablo at gnumonks.org
Tue Jun 10 08:27:52 UTC 2014


On Tue, Jun 10, 2014 at 10:02:24AM +0200, Daniel Willmann wrote:
> From: Daniel Willmann <dwillmann at sysmocom.de>
> 
> If the FD is both readable and writable and the read callback closes the
> connection (and frees the surrounding structure) we shouldn't call the
> write callback (or check anything else in the read fd).
> 
> With this patch callback functions can return -EBADFD if they don't want
> the FD to be handled any more.
> ---
>  src/write_queue.c | 27 ++++++++++++++++++++++-----
>  1 file changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/src/write_queue.c b/src/write_queue.c
> index cef40f8..dcc0469 100644
> --- a/src/write_queue.c
> +++ b/src/write_queue.c
> @@ -21,8 +21,15 @@
>   *
>   */
>  
> +#include <errno.h>
>  #include <osmocom/core/write_queue.h>
>  
> +#define HANDLE_BAD_FD(rc, label) \
> +	do { \
> +		if (rc == -EBADFD) \
> +			goto label; \
> +	} while (0);

Do we really get anything good with this macro? This checking is only
required in three places in this patch.




More information about the OpenBSC mailing list