selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ondrej Mosnacek <omosnace@redhat.com>
To: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: SElinux list <selinux@vger.kernel.org>,
	James Carter <jwcart2@gmail.com>,
	Chris PeBenito <pebenito@ieee.org>,
	Petr Lautrbach <plautrba@redhat.com>
Subject: Re: [PATCH v5 1/2] libsepol,checkpolicy: optimize storage of filename transitions
Date: Thu, 23 Jul 2020 00:15:14 +0200	[thread overview]
Message-ID: <CAFqZXNs43nOnPJBsi+qp0fsu_ykdmrJwuKbQhMF3wEZGK0KftA@mail.gmail.com> (raw)
In-Reply-To: <CAEjxPJ6jiWr5ZHWLqirAmu+9R=_qECyTrXPqtKSqwMeEdHZFQg@mail.gmail.com>

On Tue, Jul 21, 2020 at 8:23 PM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
> On Sun, Jul 19, 2020 at 6:35 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> >
> > In preparation to support a new policy format with a more optimal
> > representation of filename transition rules, this patch applies an
> > equivalent change from kernel commit c3a276111ea2 ("selinux: optimize
> > storage of filename transitions").
> >
> > See the kernel commit's description [1] for the rationale behind this
> > representation. This change doesn't bring any measurable difference of
> > policy build performance (semodule -B) on Fedora.
> >
> > [1] https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/commit/?id=c3a276111ea2572399281988b3129683e2a6b60b
> >
> > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > ---
>
> > diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
> > index c6733fa4..01a90438 100644
> > --- a/checkpolicy/policy_define.c
> > +++ b/checkpolicy/policy_define.c
> > @@ -3388,40 +3387,21 @@ int define_filename_trans(void)
> <snip>
> > +                               dup_name = NULL;
> > +                               rc = policydb_filetrans_insert(
> > +                                       policydbp, s+1, t+1, c+1, name,
> > +                                       &dup_name, otype, NULL
> > +                               );
> > +                               free(dup_name);
>
> The dup_name / name_alloc handling seems rather odd.  In every caller
> except one you follow the pattern above, where we set it to NULL, call
> policydb_filetrans_insert, and then free it immediately.  I'm not sure
> why you are doing it this way.

The original intent was to allow a choice between putting the already
allocated string into the key (when the caller function owns it) vs.
allocating a new string (when the caller gets just a read-only
reference to it), while also leaving the string allocated in case such
key already exists (so that the caller can use it in an error message,
as filename_trans_read_one_compat() used to do). However, after
rebasing on top of d27aa22dbeec ("libsepol: drop broken warning on
duplicate filename transitions") such function interface seems to be
no longer optimal... I'll see if I can simplify it.

Thanks for pointing it out.

-- 
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel
Red Hat, Inc.


  reply	other threads:[~2020-07-22 22:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-19 10:35 [PATCH v5 0/2] userspace: Implement new format of filename trans rules Ondrej Mosnacek
2020-07-19 10:35 ` [PATCH v5 1/2] libsepol,checkpolicy: optimize storage of filename transitions Ondrej Mosnacek
2020-07-21 18:22   ` Stephen Smalley
2020-07-22 22:15     ` Ondrej Mosnacek [this message]
2020-07-19 10:35 ` [PATCH v5 2/2] libsepol: implement POLICYDB_VERSION_COMP_FTRANS Ondrej Mosnacek
2020-07-19 11:31 ` [PATCH v5 0/2] userspace: Implement new format of filename trans rules 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=CAFqZXNs43nOnPJBsi+qp0fsu_ykdmrJwuKbQhMF3wEZGK0KftA@mail.gmail.com \
    --to=omosnace@redhat.com \
    --cc=jwcart2@gmail.com \
    --cc=pebenito@ieee.org \
    --cc=plautrba@redhat.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    /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).