libselinux: Ignore files removed during relabeling
PATCH 1/1 libselinux: Ignore files removed during relabeling
In case ignore_noent is specified, ignore files removed during relabeling (race condition between folder read, file read and label set).
--- libselinux/src/selinux_restorecon.c | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
libselinux/src/selinux_restorecon.c +25 -5
@@ -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 ;
Signature · 1 line
2.51.0
Quoted 14 lines · Vit Mojzis
In case
ignore_noentis specified, ignore files removed during relabeling (race condition between folder read, file read and label set).Signed-off-by Vit Mojzis <[email protected]>--- libselinux/src/selinux_restorecon.c | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)libselinux/src/selinux_restorecon.c +0
-0
libselinux/src/selinux_restorecon.c static int restorecon_sb(const char *pathname, const struct stat *sb, · line 730
Quoted 5 lines
libselinux/src/selinux_restorecon.c +2
-0@@ -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.
Quoted 10 lines
libselinux/src/selinux_restorecon.c +6
-0+if (flags->verbose) +selinux_log (SELINUX_INFO , +"%s removed during relabeling\n" , + pathname); + goto out; + }if (errno !=ENODATA ) goto err;
libselinux/src/selinux_restorecon.c static int restorecon_sb(const char *pathname, const struct stat *sb, · line 776
Quoted 6 lines
libselinux/src/selinux_restorecon.c +1
-2@@ -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.
libselinux/src/selinux_restorecon.c static int restorecon_sb(const char *pathname, const struct stat *sb, · line 778
Quoted 2 lines
libselinux/src/selinux_restorecon.c +2
-0+/* Ignore files removed during relabeling if ignore_noent is set */ +if (flags->ignore_noent && errno ==ENOENT ){
And here too.
Quoted 27 lines
libselinux/src/selinux_restorecon.c +14
-3+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 ;
Stephen Smalley
maintainerQuoted 15 lines · Vit Mojzis
In case
ignore_noentis specified, ignore files removed during relabeling (race condition between folder read, file read and label set).Signed-off-by Vit Mojzis <[email protected]>--- libselinux/src/selinux_restorecon.c | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)libselinux/src/selinux_restorecon.c +0
-0
libselinux/src/selinux_restorecon.c static int restorecon_sb(const char *pathname, const struct stat *sb, · line 734
Quoted 9 lines
libselinux/src/selinux_restorecon.c +6
-0@@ -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);
I wouldn't bother with these log messages.
Quoted 8 lines
libselinux/src/selinux_restorecon.c +2
-0+ goto out; + }if (errno !=ENODATA ) goto err;@@ -765,8 +773,19 @@ static int restorecon_sb(const char *pathname, const struct stat *sb, }
libselinux/src/selinux_restorecon.c static int restorecon_sb(const char *pathname, const struct stat *sb, · line 782
Quoted 10 lines
libselinux/src/selinux_restorecon.c +7
-2if (!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);
Ditto.
Quoted 27 lines
libselinux/src/selinux_restorecon.c +10
-4+ 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
PATCH v2 1/1 libselinux: Ignore files removed during relabeling
In case ignore_noent is specified, ignore files removed during relabeling (race condition between folder read, file read and label set).
--- libselinux/src/selinux_restorecon.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
libselinux/src/selinux_restorecon.c +15 -5
@@ -726,6 +726,9 @@ 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 ) + goto out;if (errno !=ENODATA ) goto err;
@@ -765,8 +768,14 @@ 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 ) + goto out; +else + goto err; + } + updated = true; }
@@ -932,9 +941,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 ;
Signature · 1 line
2.51.0
Quoted 6 lines · Vit Mojzis
In case
ignore_noentis specified, ignore files removed during relabeling (race condition between folder read, file read and label set).Signed-off-by Vit Mojzis <[email protected]>
Quoted 53 lines
--- libselinux/src/selinux_restorecon.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)libselinux/src/selinux_restorecon.c +15
-6@@ -726,6 +726,9 @@ 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 ) + goto out;if (errno !=ENODATA ) goto err;@@ -765,8 +768,14 @@ 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 ) + goto out; +else + goto err; + } + updated = true; }@@ -932,9 +941,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
Stephen Smalley
maintainerQuoted 10 lines · Stephen Smalley
Quoted 6 lines · Vit Mojzis
In case
ignore_noentis specified, ignore files removed during relabeling (race condition between folder read, file read and label set).Signed-off-by Vit Mojzis <[email protected]>Acked-by Stephen Smalley <[email protected]>
Thanks, merged.