All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ondrej Mosnacek <omosnace@redhat.com>
To: Paul Moore <paul@paul-moore.com>
Cc: Richard Guy Briggs <rgb@redhat.com>,
	Linux-Audit Mailing List <linux-audit@redhat.com>
Subject: Re: [PATCH ghak95] audit: Do not log full CWD path on empty relative paths
Date: Thu, 13 Sep 2018 15:57:54 +0200	[thread overview]
Message-ID: <CAFqZXNsVomgWXsGa2EWqJmQpmjFKcZvz4nEd8zSfraMoYOv9Zg@mail.gmail.com> (raw)
In-Reply-To: <CAFqZXNsn-qgU93CHbrZ+Uk6HpcwnopEQHG+Amk=U=WCapZ5bCw@mail.gmail.com>

On Mon, Aug 27, 2018 at 3:00 PM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> On Fri, Aug 24, 2018 at 4:09 PM Paul Moore <paul@paul-moore.com> wrote:
> >
> > On Fri, Aug 3, 2018 at 3:08 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> > > On Fri, Aug 3, 2018 at 12:24 AM Paul Moore <paul@paul-moore.com> wrote:
> > > > On Thu, Aug 2, 2018 at 7:45 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> > > > >
> > > > > When a relative path has just a single component and we want to emit a
> > > > > nametype=PARENT record, the current implementation just reports the full
> > > > > CWD path (which is alrady available in the audit context).
> > > > >
> > > > > This is wrong for three reasons:
> > > > > 1. Wasting log space for redundant data (CWD path is already in the CWD
> > > > >    record).
> > > > > 2. Inconsistency with other PATH records (if a relative PARENT directory
> > > > >    path contains at least one component, only the verbatim relative path
> > > > >    is logged).
> > > > > 3. In some syscalls (e.g. openat(2)) the relative path may not even be
> > > > >    relative to the CWD, but to another directory specified as a file
> > > > >    descriptor. In that case the logged path is simply plain wrong.
> > > > >
> > > > > This patch modifies this behavior to simply report "." in the
> > > > > aforementioned case, which is equivalent to an "empty" directory path
> > > > > and can be concatenated with the actual base directory path (CWD or
> > > > > dirfd from openat(2)-like syscall) once support for its logging is added
> > > > > later. In the meantime, defaulting to CWD as base directory on relative
> > > > > paths (as already done by the userspace tools) will be enough to achieve
> > > > > results equivalent to the current behavior.
> > > > >
> > > > > See: https://github.com/linux-audit/audit-kernel/issues/95
> > > > >
> > > > > Fixes: 9c937dcc7102 ("[PATCH] log more info for directory entry change events")
> > > > > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > > > > ---
> > > > >  kernel/audit.c | 9 ++++-----
> > > > >  1 file changed, 4 insertions(+), 5 deletions(-)
> > > > >
> > > > > diff --git a/kernel/audit.c b/kernel/audit.c
> > > > > index 2a8058764aa6..4f18bd48eb4b 100644
> > > > > --- a/kernel/audit.c
> > > > > +++ b/kernel/audit.c
> > > > > @@ -2127,28 +2127,27 @@ void audit_log_name(struct audit_context *context, struct audit_names *n,
> > > > >
> > > > >         audit_log_format(ab, "item=%d", record_num);
> > > > >
> > > > > +       audit_log_format(ab, " name=");
> > > > >         if (path)
> > > > > -               audit_log_d_path(ab, " name=", path);
> > > > > +               audit_log_d_path(ab, NULL, path);
> > > > >         else if (n->name) {
> > > > >                 switch (n->name_len) {
> > > > >                 case AUDIT_NAME_FULL:
> > > > >                         /* log the full path */
> > > > > -                       audit_log_format(ab, " name=");
> > > > >                         audit_log_untrustedstring(ab, n->name->name);
> > > > >                         break;
> > > > >                 case 0:
> > > > >                         /* name was specified as a relative path and the
> > > > >                          * directory component is the cwd */
> > > > > -                       audit_log_d_path(ab, " name=", &context->pwd);
> > > > > +                       audit_log_untrustedstring(ab, ".");
> > > >
> > > > This isn't a comprehensive review, I only gave this a quick look, but
> > > > considering you are only logging "." above we can safely use
> > > > audit_log_string() and safe a few cycles.
> > >
> > > I used audit_log_untrustedstring() to maintain the current norm that
> > > the name= field would always contain a quoted string (either in
> > > double-quotes or hex-escaped). I don't know if such consistency is
> > > important for parsing in userspace (it should probably be robust
> > > enough to handle any format), but I wanted to be on the safe side.
> >
> > In this particular case there should be no visible difference in the
> > resulting record and audit_log_string() is going to have less overhead
> > in the kernel.
>
> OK, so should I just replace it with:
>
>     audit_log_string(ab, ".");
>
> or should I still escape the path manually:
>
>     audit_log_string(ab, "\".\"");
>
> ?

Paul, could you please answer this question so I can move forward? :)

>
> >
> > > > Honestly, looking at the rest of this function, why are we using
> > > > audit_log_format() in the case where we are simply writing a string
> > > > literal?  While I haven't tested it, simple code inspection would seem
> > > > to indicate that audit_log_string() should be much quicker than
> > > > audit_log_format()?  I realize this isn't strictly a problem from this
> > > > patch, but we probably shouldn't be propagating this mistake any
> > > > further.
> > >
> > > Good point. If I happen to be sending a v2 of the patch, I will switch
> > > to audit_log_string() where possible. Otherwise, I'll leave it to you
> > > to fix up when applying (it will probably clash with your patch
> > > anyway).
> >
> > Please fit it yourself and resubmit.
> >
> > As a general rule I shouldn't need to fix things like this when
> > merging.  While things like this sometimes happen, they are special
> > cases and are usually the result of short deadlines, missing devs,
> > etc.  In general I try to limit my modifications to merge fuzz and
> > minor code changes like whitespace fixes, silly checkpatch warnings,
> > etc.
>
> Understood, will do.
>
> --
> Ondrej Mosnacek <omosnace at redhat dot com>
> Associate Software Engineer, Security Technologies
> Red Hat, Inc.

Thanks,

--
Ondrej Mosnacek <omosnace at redhat dot com>
Associate Software Engineer, Security Technologies
Red Hat, Inc.

  reply	other threads:[~2018-09-13 13:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02 11:44 [PATCH ghak95] audit: Do not log full CWD path on empty relative paths Ondrej Mosnacek
2018-08-02 13:29 ` Richard Guy Briggs
2018-08-02 22:24 ` Paul Moore
2018-08-03  7:08   ` Ondrej Mosnacek
2018-08-24 14:09     ` Paul Moore
2018-08-27 13:00       ` Ondrej Mosnacek
2018-09-13 13:57         ` Ondrej Mosnacek [this message]
2018-09-13 14:13           ` Paul Moore
2018-09-19  1:35             ` Paul Moore
2018-09-19 11:01               ` Ondrej Mosnacek
2018-09-19 15:44                 ` Paul Moore
2018-10-31  8:54                   ` Ondrej Mosnacek
2018-11-05 23:30                     ` Paul Moore
2018-11-06  8:08                       ` Ondrej Mosnacek
2018-11-06 20:19                         ` Paul Moore
2018-11-13 15:25                           ` Ondrej Mosnacek
2018-11-13 16:30                             ` Paul Moore
2018-12-01 16:50                               ` Steve Grubb
2018-12-04  0:17                                 ` Paul Moore
2018-12-04  8:07                                 ` Ondrej Mosnacek
2018-12-04 22:19                                   ` Paul Moore
2018-08-03  0:03 ` Paul Moore
2018-08-24 15:00   ` Paul Moore
2018-08-24 15:14     ` Steve Grubb
2018-08-27 12:42       ` Ondrej Mosnacek
2018-08-24 12:59 ` Ondrej Mosnacek
2018-08-24 14:28   ` Steve Grubb

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=CAFqZXNsVomgWXsGa2EWqJmQpmjFKcZvz4nEd8zSfraMoYOv9Zg@mail.gmail.com \
    --to=omosnace@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=rgb@redhat.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 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.