SELinux Security Module development
 help / color / mirror / Atom feed
From: Petr Lautrbach <plautrba@redhat.com>
To: Nicolas Iooss <nicolas.iooss@m4x.org>, selinux@vger.kernel.org
Subject: Re: [PATCH 1/1] restorecond: invalidate local_lock_fd properly when closing it
Date: Wed, 03 Mar 2021 16:08:58 +0100	[thread overview]
Message-ID: <871rcwjmut.fsf@redhat.com> (raw)
In-Reply-To: <20210228084809.8387-1-nicolas.iooss@m4x.org>

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


      reply	other threads:[~2021-03-04  0:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871rcwjmut.fsf@redhat.com \
    --to=plautrba@redhat.com \
    --cc=nicolas.iooss@m4x.org \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox