[05/16] libelf: Fix elf_end deadlock

Message ID 20231010134300.53830-5-mark@klomp.org
State Committed
Headers
Series [01/16] lib: Add new once_define and once macros to eu-config.h |

Commit Message

Mark Wielaard Oct. 10, 2023, 1:42 p.m. UTC
  From: Heather McIntyre <hsm2@rice.edu>

	* libelf/elf_end.c (elf_end): Add rwlock_unlock before
	early return.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libelf/elf_end.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Mark Wielaard Oct. 10, 2023, 3:28 p.m. UTC | #1
Hi Heather,

On Tue, 2023-10-10 at 15:42 +0200, Mark Wielaard wrote:
> From: Heather McIntyre <hsm2@rice.edu>
> 
> 	* libelf/elf_end.c (elf_end): Add rwlock_unlock before
> 	early return.
> 
> Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
> Signed-off-by: Mark Wielaard <mark@klomp.org>
> ---
>  libelf/elf_end.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libelf/elf_end.c b/libelf/elf_end.c
> index 89727cb3..80f4d13f 100644
> --- a/libelf/elf_end.c
> +++ b/libelf/elf_end.c
> @@ -82,7 +82,10 @@ elf_end (Elf *elf)
>        elf->state.ar.ar_sym = NULL;
>  
>        if (elf->state.ar.children != NULL)
> -	return 0;
> +	{
> +	  rwlock_unlock(elf->lock);
> +	  return 0;
> +	}
>      }
>  
>    /* Remove this structure from the children list.  */

This looks obviously correct. All other early returns also release the
lock.

Thanks,

Mark
  

Patch

diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 89727cb3..80f4d13f 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -82,7 +82,10 @@  elf_end (Elf *elf)
       elf->state.ar.ar_sym = NULL;
 
       if (elf->state.ar.children != NULL)
-	return 0;
+	{
+	  rwlock_unlock(elf->lock);
+	  return 0;
+	}
     }
 
   /* Remove this structure from the children list.  */