From: Vit Mojzis <vmojzis@redhat.com>
To: selinux@vger.kernel.org
Subject: [PATCH] libselinux: Ignore files removed during relabeling
Date: Thu, 16 Oct 2025 20:08:37 +0200 [thread overview]
Message-ID: <20251016180929.452863-1-vmojzis@redhat.com> (raw)
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){
+ 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){
+ /* Ignore files removed during relabeling if ignore_noent is set */
+ if (flags->ignore_noent && errno == ENOENT){
+ 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;
--
2.51.0
next reply other threads:[~2025-10-16 18:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 18:08 Vit Mojzis [this message]
2025-10-16 18:24 ` [PATCH] libselinux: Ignore files removed during relabeling Rahul Sandhu
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=20251016180929.452863-1-vmojzis@redhat.com \
--to=vmojzis@redhat.com \
--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;
as well as URLs for NNTP newsgroup(s).