All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] restorecond: invalidate local_lock_fd properly when closing it
@ 2021-02-28  8:48 Nicolas Iooss
  2021-03-03 15:08 ` Petr Lautrbach
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Iooss @ 2021-02-28  8:48 UTC (permalink / raw)
  To: selinux

If flock(local_lock_fd,...) fails, in function local_server(), the file
descriptor to the lock file is closed but local_lock_fd is not reset to
-1. This leads to server() calling end_local_server(), which closes the
file descriptor again.

Fix this double-close issue by setting local_lock_fd to -1 after closing
it.

This issue was found by using Facebook's Infer static analyzer.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 restorecond/user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/restorecond/user.c b/restorecond/user.c
index a24b8407b048..47b86823ff79 100644
--- a/restorecond/user.c
+++ b/restorecond/user.c
@@ -230,9 +230,10 @@ static int local_server(void) {
 		return -1;
 	}
 	if (flock(local_lock_fd, LOCK_EX | LOCK_NB) < 0) {
-		close(local_lock_fd);
 		if (debug_mode)
 			perror("flock");
+		close(local_lock_fd);
+		local_lock_fd = -1;
 		return -1;
 	}
 	/* watch for stdin/terminal going away */
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] restorecond: invalidate local_lock_fd properly when closing it
  2021-02-28  8:48 [PATCH 1/1] restorecond: invalidate local_lock_fd properly when closing it Nicolas Iooss
@ 2021-03-03 15:08 ` Petr Lautrbach
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Lautrbach @ 2021-03-03 15:08 UTC (permalink / raw)
  To: Nicolas Iooss, selinux

Nicolas Iooss <nicolas.iooss@m4x.org> writes:

> If flock(local_lock_fd,...) fails, in function local_server(), the file
> descriptor to the lock file is closed but local_lock_fd is not reset to
> -1. This leads to server() calling end_local_server(), which closes the
> file descriptor again.
>
> Fix this double-close issue by setting local_lock_fd to -1 after closing
> it.
>
> This issue was found by using Facebook's Infer static analyzer.
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
>

Acked-by: Petr Lautrbach <plautrba@redhat.com>

and merged. Thanks!

> ---
>  restorecond/user.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/restorecond/user.c b/restorecond/user.c
> index a24b8407b048..47b86823ff79 100644
> --- a/restorecond/user.c
> +++ b/restorecond/user.c
> @@ -230,9 +230,10 @@ static int local_server(void) {
>  		return -1;
>  	}
>  	if (flock(local_lock_fd, LOCK_EX | LOCK_NB) < 0) {
> -		close(local_lock_fd);
>  		if (debug_mode)
>  			perror("flock");
> +		close(local_lock_fd);
> +		local_lock_fd = -1;
>  		return -1;
>  	}
>  	/* watch for stdin/terminal going away */
> -- 
> 2.30.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-04  0:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-28  8:48 [PATCH 1/1] restorecond: invalidate local_lock_fd properly when closing it Nicolas Iooss
2021-03-03 15:08 ` Petr Lautrbach

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.