Revert "libselinux: verify file_contexts when using restorecon"
PATCH 1/1 Revert "libselinux: verify file_contexts when using restorecon"
This reverts commit 814631d3aebaa041073a42c677c1ed62ce7830d5. As reported by Petr Lautrbach, this commit changed the behavior of selabel_open() when SELABEL_OPT_VALIDATE is 0, and this would be an API change.
--- libselinux/src/label.c | 7 ++++--- libselinux/src/label_backends_android.c | 2 +- libselinux/src/label_file.c | 2 +- libselinux/src/label_file.h | 2 +- libselinux/src/label_internal.h | 6 ++++-- libselinux/src/matchpathcon.c | 5 +++-- 6 files changed, 14 insertions(+), 10 deletions(-)
libselinux/src/label.c +4 -3
@@ -121,11 +121,12 @@ static inline int selabel_is_validate_set(const struct selinux_opt *opts,return 0 ; } -int selabel_validate (struct selabel_lookup_rec *contexts) +int selabel_validate (struct selabel_handle *rec, +struct selabel_lookup_rec *contexts) {int rc =0 ; -if (contexts->validated) +if (!rec->validating || contexts->validated) goto out; rc =selinux_validate (&contexts->ctx_raw);
@@ -142,7 +143,7 @@ static int selabel_fini(struct selabel_handle *rec, struct selabel_lookup_rec *lr, int translating) { - if (compat_validate(lr, rec->spec_file, lr->lineno)) + if (compat_validate(rec, lr, rec->spec_file, lr->lineno)) return -1; if (translating && !lr->ctx_trans &&
libselinux/src/label_backends_android.c +1 -1
@@ -122,7 +122,7 @@ static int process_line(struct selabel_handle *rec, spec_arr[nspec].lr.ctx_raw = context;if (rec->validating) { -if (selabel_validate (&spec_arr[nspec].lr) <0 ) { +if (selabel_validate (rec, &spec_arr[nspec].lr) <0 ) {selinux_log (SELINUX_ERROR ,"%s: line %u has invalid context %s\n" , path, lineno, spec_arr[nspec].lr.ctx_raw);
libselinux/src/label_file.c +1 -1
@@ -328,7 +328,7 @@ end_arch_check: spec->lr.ctx_raw = str_buf;if (strcmp (spec->lr.ctx_raw,"<<none>>" ) && rec->validating) { -if (selabel_validate (&spec->lr) <0 ) { +if (selabel_validate (rec, &spec->lr) <0 ) {selinux_log (SELINUX_ERROR ,"%s: context %s is invalid\n" , path, spec->lr.ctx_raw);
libselinux/src/label_file.h +1 -1
@@ -509,7 +509,7 @@ static inline int process_line(struct selabel_handle *rec,spec_hasMetaChars (&spec_arr[nspec]);if (strcmp (context,"<<none>>" ) && rec->validating) -return compat_validate (&spec_arr[nspec].lr, path, lineno); +return compat_validate (rec, &spec_arr[nspec].lr, path, lineno);return 0 ; }
libselinux/src/label_internal.h +4 -2
@@ -112,7 +112,8 @@ struct selabel_handle {* Validation function */ extern int -selabel_validate(struct selabel_lookup_rec *contexts) hidden; +selabel_validate(struct selabel_handle *rec, + struct selabel_lookup_rec *contexts) hidden;/* * Compatibility support
@@ -127,7 +128,8 @@ extern void __attribute__ ((format(printf, 1, 2)))selinux_log (type, fmt); extern int -compat_validate(struct selabel_lookup_rec *contexts, +compat_validate(struct selabel_handle *rec, + struct selabel_lookup_rec *contexts, const char *path, unsigned lineno) hidden;/*
libselinux/src/matchpathcon.c +3 -2
@@ -35,7 +35,8 @@ void set_matchpathcon_printf(void (*f) (const char *fmt, ...)) myprintf_compat =1 ; } -int compat_validate (struct selabel_lookup_rec *contexts, +int compat_validate (struct selabel_handle *rec, +struct selabel_lookup_rec *contexts,const char *path,unsigned lineno) {int rc;
@@ -46,7 +47,7 @@ int compat_validate(struct selabel_lookup_rec *contexts,else if (mycanoncon) rc =mycanoncon (path, lineno, ctx);else { - rc =selabel_validate (contexts); + rc =selabel_validate (rec, contexts);if (rc <0 ) {if (lineno) { COMPAT_LOG(SELINUX_WARNING,
Signature · 1 line
2.14.3
Quoted 131 lines · Stephen Smalley
This reverts commit
814631d3aebaa041073a42c677c1ed62ce7830d5. As reported by Petr Lautrbach, this commit changed the behavior ofselabel_open()whenSELABEL_OPT_VALIDATEis 0, and this would be an API change.Reported-by Petr Lautrbach <[email protected]>Signed-off-by Stephen Smalley <[email protected]>--- libselinux/src/label.c | 7 ++++--- libselinux/src/label_backends_android.c | 2 +- libselinux/src/label_file.c | 2 +- libselinux/src/label_file.h | 2 +- libselinux/src/label_internal.h | 6 ++++-- libselinux/src/matchpathcon.c | 5 +++-- 6 files changed, 14 insertions(+), 10 deletions(-)libselinux/src/label.c +4
-3@@ -121,11 +121,12 @@ static inline int selabel_is_validate_set(const struct selinux_opt *opts,return 0 ; } -int selabel_validate (struct selabel_lookup_rec *contexts) +int selabel_validate (struct selabel_handle *rec, +struct selabel_lookup_rec *contexts) {int rc =0 ; -if (contexts->validated) +if (!rec->validating || contexts->validated) goto out; rc =selinux_validate (&contexts->ctx_raw);@@ -142,7 +143,7 @@ static int selabel_fini(struct selabel_handle *rec, struct selabel_lookup_rec *lr, int translating) { - if (compat_validate(lr, rec->spec_file, lr->lineno)) + if (compat_validate(rec, lr, rec->spec_file, lr->lineno)) return -1; if (translating && !lr->ctx_trans &&libselinux/src/label_backends_android.c +1
-1@@ -122,7 +122,7 @@ static int process_line(struct selabel_handle *rec, spec_arr[nspec].lr.ctx_raw = context;if (rec->validating) { -if (selabel_validate (&spec_arr[nspec].lr) <0 ) { +if (selabel_validate (rec, &spec_arr[nspec].lr) <0 ) {selinux_log (SELINUX_ERROR ,"%s: line %u has invalid context %s\n" , path, lineno, spec_arr[nspec].lr.ctx_raw);libselinux/src/label_file.c +1
-1@@ -328,7 +328,7 @@ end_arch_check: spec->lr.ctx_raw = str_buf;if (strcmp (spec->lr.ctx_raw,"<<none>>" ) && rec->validating) { -if (selabel_validate (&spec->lr) <0 ) { +if (selabel_validate (rec, &spec->lr) <0 ) {selinux_log (SELINUX_ERROR ,"%s: context %s is invalid\n" , path, spec->lr.ctx_raw);libselinux/src/label_file.h +1
-1@@ -509,7 +509,7 @@ static inline int process_line(struct selabel_handle *rec,spec_hasMetaChars (&spec_arr[nspec]);if (strcmp (context,"<<none>>" ) && rec->validating) -return compat_validate (&spec_arr[nspec].lr, path, lineno); +return compat_validate (rec, &spec_arr[nspec].lr, path, lineno);return 0 ; }libselinux/src/label_internal.h +4
-2@@ -112,7 +112,8 @@ struct selabel_handle {* Validation function */ extern int -selabel_validate(struct selabel_lookup_rec *contexts) hidden; +selabel_validate(struct selabel_handle *rec, + struct selabel_lookup_rec *contexts) hidden;/* * Compatibility support @@ -127,7 +128,8 @@ extern void __attribute__ ((format(printf, 1, 2)))selinux_log (type, fmt); extern int -compat_validate(struct selabel_lookup_rec *contexts, +compat_validate(struct selabel_handle *rec, + struct selabel_lookup_rec *contexts, const char *path, unsigned lineno) hidden;/* libselinux/src/matchpathcon.c +3
-3@@ -35,7 +35,8 @@ void set_matchpathcon_printf(void (*f) (const char *fmt, ...)) myprintf_compat =1 ; } -int compat_validate (struct selabel_lookup_rec *contexts, +int compat_validate (struct selabel_handle *rec, +struct selabel_lookup_rec *contexts,const char *path,unsigned lineno) {int rc;@@ -46,7 +47,7 @@ int compat_validate(struct selabel_lookup_rec *contexts,else if (mycanoncon) rc =mycanoncon (path, lineno, ctx);else { - rc =selabel_validate (contexts); + rc =selabel_validate (rec, contexts);if (rc <0 ) {if (lineno) { COMPAT_LOG(SELINUX_WARNING, --
Quoted 2 lines
2.14.3
Sorry for the delay, yes this does indeed break the behavior of the open flags and needs to be reverted.
Quoted 129 lines · William Roberts
Quoted 128 lines · Stephen Smalley
This reverts commit
814631d3aebaa041073a42c677c1ed62ce7830d5. As reported by Petr Lautrbach, this commit changed the behavior ofselabel_open()whenSELABEL_OPT_VALIDATEis 0, and this would be an API change.Reported-by Petr Lautrbach <[email protected]>Signed-off-by Stephen Smalley <[email protected]>--- libselinux/src/label.c | 7 ++++--- libselinux/src/label_backends_android.c | 2 +- libselinux/src/label_file.c | 2 +- libselinux/src/label_file.h | 2 +- libselinux/src/label_internal.h | 6 ++++-- libselinux/src/matchpathcon.c | 5 +++-- 6 files changed, 14 insertions(+), 10 deletions(-)libselinux/src/label.c +4
-3@@ -121,11 +121,12 @@ static inline int selabel_is_validate_set(const struct selinux_opt *opts,return 0 ; } -int selabel_validate (struct selabel_lookup_rec *contexts) +int selabel_validate (struct selabel_handle *rec, +struct selabel_lookup_rec *contexts) {int rc =0 ; -if (contexts->validated) +if (!rec->validating || contexts->validated) goto out; rc =selinux_validate (&contexts->ctx_raw);@@ -142,7 +143,7 @@ static int selabel_fini(struct selabel_handle *rec, struct selabel_lookup_rec *lr, int translating) { - if (compat_validate(lr, rec->spec_file, lr->lineno)) + if (compat_validate(rec, lr, rec->spec_file, lr->lineno)) return -1; if (translating && !lr->ctx_trans &&libselinux/src/label_backends_android.c +1
-1@@ -122,7 +122,7 @@ static int process_line(struct selabel_handle *rec, spec_arr[nspec].lr.ctx_raw = context;if (rec->validating) { -if (selabel_validate (&spec_arr[nspec].lr) <0 ) { +if (selabel_validate (rec, &spec_arr[nspec].lr) <0 ) {selinux_log (SELINUX_ERROR ,"%s: line %u has invalid context %s\n" , path, lineno, spec_arr[nspec].lr.ctx_raw);libselinux/src/label_file.c +1
-1@@ -328,7 +328,7 @@ end_arch_check: spec->lr.ctx_raw = str_buf;if (strcmp (spec->lr.ctx_raw,"<<none>>" ) && rec->validating) { -if (selabel_validate (&spec->lr) <0 ) { +if (selabel_validate (rec, &spec->lr) <0 ) {selinux_log (SELINUX_ERROR ,"%s: context %s is invalid\n" , path, spec->lr.ctx_raw);libselinux/src/label_file.h +1
-1@@ -509,7 +509,7 @@ static inline int process_line(struct selabel_handle *rec,spec_hasMetaChars (&spec_arr[nspec]);if (strcmp (context,"<<none>>" ) && rec->validating) -return compat_validate (&spec_arr[nspec].lr, path, lineno); +return compat_validate (rec, &spec_arr[nspec].lr, path, lineno);return 0 ; }libselinux/src/label_internal.h +4
-2@@ -112,7 +112,8 @@ struct selabel_handle {* Validation function */ extern int -selabel_validate(struct selabel_lookup_rec *contexts) hidden; +selabel_validate(struct selabel_handle *rec, + struct selabel_lookup_rec *contexts) hidden;/* * Compatibility support @@ -127,7 +128,8 @@ extern void __attribute__ ((format(printf, 1, 2)))selinux_log (type, fmt); extern int -compat_validate(struct selabel_lookup_rec *contexts, +compat_validate(struct selabel_handle *rec, + struct selabel_lookup_rec *contexts, const char *path, unsigned lineno) hidden;/* libselinux/src/matchpathcon.c +3
-2@@ -35,7 +35,8 @@ void set_matchpathcon_printf(void (*f) (const char *fmt, ...)) myprintf_compat =1 ; } -int compat_validate (struct selabel_lookup_rec *contexts, +int compat_validate (struct selabel_handle *rec, +struct selabel_lookup_rec *contexts,const char *path,unsigned lineno) {int rc;@@ -46,7 +47,7 @@ int compat_validate(struct selabel_lookup_rec *contexts,else if (mycanoncon) rc =mycanoncon (path, lineno, ctx);else { - rc =selabel_validate (contexts); + rc =selabel_validate (rec, contexts);if (rc <0 ) {
Quoted 8 lines
Quoted 5 lines
libselinux/src/matchpathcon.c +0
-1if (lineno) { COMPAT_LOG(SELINUX_WARNING, --2.14.3
Sorry for the delay, yes this does indeed break the behavior of the open flags and needs to be reverted.
FYI: this was merged:
https://github.com/SELinuxProject/selinux/commit/87a58b6b4ebf88da78bf1386c36d8d982ca41525