All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libselinux:  Correctly handle an empty file_contexts file.
@ 2015-06-22 13:23 Stephen Smalley
  2015-06-22 19:40 ` Jeffrey Vander Stoep
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Smalley @ 2015-06-22 13:23 UTC (permalink / raw)
  To: selinux; +Cc: Stephen Smalley

If you add some local file contexts via semanage fcontext -a and
later delete them all via semanage fcontext -D, you get an empty
file_contexts.local file.  Then when you try to load it, getline()
returns 0 and we fall through to the out path without having set rc.
In label_file.c, rc will always be non-zero at this point because
we will have failed the load_mmap() call.  In sefcontext_compile,
rc may contain random garbage at this point.  Explicitly set rc
before the loop.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
---
 libselinux/src/label_file.c           | 3 ++-
 libselinux/utils/sefcontext_compile.c | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
index 1d6c36e..4faf808 100644
--- a/libselinux/src/label_file.c
+++ b/libselinux/src/label_file.c
@@ -425,9 +425,10 @@ static int process_file(const char *path, const char *suffix,
 		goto out;
 
 	/*
-	 * The do detailed validation of the input and fill the spec array
+	 * Then do detailed validation of the input and fill the spec array
 	 */
 	lineno = 0;
+	rc = 0;
 	while (getline(&line_buf, &line_len, fp) > 0) {
 		rc = process_line(rec, path, prefix, line_buf, ++lineno);
 		if (rc)
diff --git a/libselinux/utils/sefcontext_compile.c b/libselinux/utils/sefcontext_compile.c
index 1c46af8..a93105d 100644
--- a/libselinux/utils/sefcontext_compile.c
+++ b/libselinux/utils/sefcontext_compile.c
@@ -35,6 +35,7 @@ static int process_file(struct selabel_handle *rec, const char *filename)
 	}
 
 	line_num = 0;
+	rc = 0;
 	while (getline(&line_buf, &line_len, context_file) > 0) {
 		rc = process_line(rec, filename, prefix, line_buf, ++line_num);
 		if (rc)
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libselinux: Correctly handle an empty file_contexts file.
  2015-06-22 13:23 [PATCH] libselinux: Correctly handle an empty file_contexts file Stephen Smalley
@ 2015-06-22 19:40 ` Jeffrey Vander Stoep
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey Vander Stoep @ 2015-06-22 19:40 UTC (permalink / raw)
  To: Stephen Smalley; +Cc: SELinux

Acked-by:  Jeff Vander Stoep <jeffv@google.com>

On Mon, Jun 22, 2015 at 6:23 AM, Stephen Smalley <sds@tycho.nsa.gov> wrote:
> If you add some local file contexts via semanage fcontext -a and
> later delete them all via semanage fcontext -D, you get an empty
> file_contexts.local file.  Then when you try to load it, getline()
> returns 0 and we fall through to the out path without having set rc.
> In label_file.c, rc will always be non-zero at this point because
> we will have failed the load_mmap() call.  In sefcontext_compile,
> rc may contain random garbage at this point.  Explicitly set rc
> before the loop.
>
> Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
> ---
>  libselinux/src/label_file.c           | 3 ++-
>  libselinux/utils/sefcontext_compile.c | 1 +
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
> index 1d6c36e..4faf808 100644
> --- a/libselinux/src/label_file.c
> +++ b/libselinux/src/label_file.c
> @@ -425,9 +425,10 @@ static int process_file(const char *path, const char *suffix,
>                 goto out;
>
>         /*
> -        * The do detailed validation of the input and fill the spec array
> +        * Then do detailed validation of the input and fill the spec array
>          */
>         lineno = 0;
> +       rc = 0;
>         while (getline(&line_buf, &line_len, fp) > 0) {
>                 rc = process_line(rec, path, prefix, line_buf, ++lineno);
>                 if (rc)
> diff --git a/libselinux/utils/sefcontext_compile.c b/libselinux/utils/sefcontext_compile.c
> index 1c46af8..a93105d 100644
> --- a/libselinux/utils/sefcontext_compile.c
> +++ b/libselinux/utils/sefcontext_compile.c
> @@ -35,6 +35,7 @@ static int process_file(struct selabel_handle *rec, const char *filename)
>         }
>
>         line_num = 0;
> +       rc = 0;
>         while (getline(&line_buf, &line_len, context_file) > 0) {
>                 rc = process_line(rec, filename, prefix, line_buf, ++line_num);
>                 if (rc)
> --
> 2.1.0
>
> _______________________________________________
> Selinux mailing list
> Selinux@tycho.nsa.gov
> To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
> To get help, send an email containing "help" to Selinux-request@tycho.nsa.gov.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-22 19:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22 13:23 [PATCH] libselinux: Correctly handle an empty file_contexts file Stephen Smalley
2015-06-22 19:40 ` Jeffrey Vander Stoep

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.