selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rahul Sandhu" <nvraxn@gmail.com>
To: "Vit Mojzis" <vmojzis@redhat.com>, <selinux@vger.kernel.org>
Subject: Re: [PATCH] libselinux: Ignore files removed during relabeling
Date: Thu, 16 Oct 2025 19:24:57 +0100	[thread overview]
Message-ID: <DDJYGZAJRMC4.O9KO64SAAPFJ@gmail.com> (raw)
In-Reply-To: <20251016180929.452863-1-vmojzis@redhat.com>

On Thu Oct 16, 2025 at 7:08 PM BST, Vit Mojzis wrote:
> In case ignore_noent is specified, ignore files removed during
> relabeling (race condition between folder read, file read and label
> set).
>
> Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
> ---
>  libselinux/src/selinux_restorecon.c | 30 ++++++++++++++++++++++++-----
>  1 file changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> index 39eabeb9..7cad4c8d 100644
> --- a/libselinux/src/selinux_restorecon.c
> +++ b/libselinux/src/selinux_restorecon.c
> @@ -726,6 +726,14 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
>  			    pathname, newcon);
>  
>  	if (lgetfilecon_raw(pathname, &curcon) < 0) {
> +		/* Ignore files removed during relabeling if ignore_noent is set */
> +		if (flags->ignore_noent && errno == ENOENT){

Nit: there should be a space after the `(` and before the `{`, inline with the rest of the code style.

> +			if (flags->verbose)
> +				selinux_log(SELINUX_INFO,
> +					    "%s removed during relabeling\n",
> +					    pathname);
> +			goto out;
> +		}
>  		if (errno != ENODATA)
>  			goto err;
>  
> @@ -765,8 +773,19 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
>  		}
>  
>  		if (!flags->nochange) {
> -			if (lsetfilecon(pathname, newcon) < 0)
> -				goto err;
> +			if (lsetfilecon(pathname, newcon) < 0){

Same as above.

> +				/* Ignore files removed during relabeling if ignore_noent is set */
> +				if (flags->ignore_noent && errno == ENOENT){

And here too.

> +					if (flags->verbose)
> +						selinux_log(SELINUX_INFO,
> +							    "%s removed during relabeling\n",
> +							    pathname);
> +					goto out;
> +				}
> +				else
> +					goto err;
> +			}
> +
>  			updated = true;
>  		}
>  
> @@ -932,9 +951,10 @@ loop_body:
>  		case FTS_NS:
>  			error = errno;
>  			errno = ftsent->fts_errno;
> -			selinux_log(SELINUX_ERROR,
> -				    "Could not stat %s: %m.\n",
> -				    ftsent->fts_path);
> +			if (!state->flags.ignore_noent || errno != ENOENT)
> +				selinux_log(SELINUX_ERROR,
> +					    "Could not stat %s: %m.\n",
> +					    ftsent->fts_path);
>  			errno = error;
>  			fts_set(fts, ftsent, FTS_SKIP);
>  			continue;


  reply	other threads:[~2025-10-16 18:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 18:08 [PATCH] libselinux: Ignore files removed during relabeling Vit Mojzis
2025-10-16 18:24 ` Rahul Sandhu [this message]
2025-10-16 19:38 ` Stephen Smalley
2025-10-17 15:08   ` [PATCH v2] " Vit Mojzis
2025-10-20 12:46     ` Stephen Smalley
2025-10-21 13:46       ` Stephen Smalley

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=DDJYGZAJRMC4.O9KO64SAAPFJ@gmail.com \
    --to=nvraxn@gmail.com \
    --cc=selinux@vger.kernel.org \
    --cc=vmojzis@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).