selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ondrej Mosnacek <omosnace@redhat.com>
To: selinux@vger.kernel.org, Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>,
	Ondrej Mosnacek <omosnace@redhat.com>
Subject: [RFC PATCH v3 6/9] [fixup] fix handling of invalid context in convert_context
Date: Thu, 29 Nov 2018 13:53:59 +0100	[thread overview]
Message-ID: <20181129125402.5900-7-omosnace@redhat.com> (raw)
In-Reply-To: <20181129125402.5900-1-omosnace@redhat.com>

We can reuse the temporary string 's' and save one kstrdup() call.
---
 security/selinux/ss/services.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 3c5887838e12..e70c7c5d7f26 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1934,15 +1934,19 @@ static int convert_context(struct context *oldc, struct context *newc, void *p)
 
 		rc = string_to_context_struct(args->newp, NULL, s,
 					      newc, SECSID_NULL);
+		if (rc == -EINVAL) {
+			/* Retain string representation for later mapping. */
+			context_init(newc);
+			newc->str = s;
+			newc->len = oldc->len;
+			rc = 0;
+			goto out;
+		}
 		kfree(s);
 		if (!rc) {
 			pr_info("SELinux:  Context %s became valid (mapped).\n",
 				oldc->str);
 			goto out;
-		} else if (rc == -EINVAL) {
-			/* Retain string representation for later mapping. */
-			rc = 0;
-			goto out;
 		} else {
 			/* Other error condition, e.g. ENOMEM. */
 			pr_err("SELinux:   Unable to map context %s, rc = %d.\n",
-- 
2.19.2


  parent reply	other threads:[~2018-11-29 12:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 12:53 [RFC PATCH v3 0/9] Fix ENOMEM errors during policy reload Ondrej Mosnacek
2018-11-29 12:53 ` [RFC PATCH v3 1/9] selinux: use separate table for initial SID lookup Ondrej Mosnacek
2018-11-29 12:53 ` [RFC PATCH v3 2/9] [squash] do not store entry for SECSID_NULL Ondrej Mosnacek
2018-11-29 12:53 ` [RFC PATCH v3 3/9] [fixup] fix handling of SECSID_NULL Ondrej Mosnacek
2018-11-29 22:14   ` Paul Moore
2018-11-30 15:13     ` Ondrej Mosnacek
2018-11-29 12:53 ` [RFC PATCH v3 4/9] [fixup] cosmetic tweak for sidtab_search_core() Ondrej Mosnacek
2018-11-29 12:53 ` [RFC PATCH v3 5/9] selinux: overhaul sidtab to fix bug and improve performance Ondrej Mosnacek
2018-11-29 12:53 ` Ondrej Mosnacek [this message]
2018-11-29 12:54 ` [RFC PATCH v3 7/9] [fixup] remove the now unneeded 'out' label Ondrej Mosnacek
2018-11-29 12:54 ` [RFC PATCH v3 8/9] [fixup] fix SIDTAB_LEAF_ENTRIES to use the correct size macro Ondrej Mosnacek
2018-11-29 12:54 ` [RFC PATCH v3 9/9] [squash] add back reverse lookup cache to sidtab Ondrej Mosnacek

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=20181129125402.5900-7-omosnace@redhat.com \
    --to=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --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).