All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: Richard Guy Briggs <rgb@redhat.com>
Cc: Eric Paris <eparis@parisplace.org>,
	Linux-Audit Mailing List <linux-audit@redhat.com>
Subject: Re: [RFC PATCH v1] audit: log AUDIT_TIME_* records only from rules
Date: Thu, 20 Jan 2022 18:07:58 -0500	[thread overview]
Message-ID: <CAHC9VhSC2N+LB=neJC=3-L4_rP8gfO5HBFjGWXMKjxOBr2Ymcg@mail.gmail.com> (raw)
In-Reply-To: <20220112210622.GC1550715@madcap2.tricolour.ca>

On Wed, Jan 12, 2022 at 4:06 PM Richard Guy Briggs <rgb@redhat.com> wrote:
> On 2021-12-29 17:51, Paul Moore wrote:
> > On Thu, Nov 4, 2021 at 5:00 PM Richard Guy Briggs <rgb@redhat.com> wrote:
> > > AUDIT_TIME_* events are generated when there are syscall rules present that are
> > > not related to time keeping.  This will produce noisy log entries that could
> > > flood the logs and hide events we really care about.
> > >
> > > Rather than immediately produce the AUDIT_TIME_* records, store the data and
> > > log it at syscall exit time respecting the filter rules.
> > >
> > > Please see https://bugzilla.redhat.com/show_bug.cgi?id=1991919
> > >
> > > Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
> > > ---
> > > Note: This is a quick and dirty proof-of-concept.  If this approach of
> > > storing the values in the audit_context for later filtering is
> > > acceptable I'll clean up the patch (re-name functions) and re-submit.
> > >
> > >  kernel/audit.h   |  6 ++++++
> > >  kernel/auditsc.c | 29 +++++++++++++++++++++++++----
> > >  2 files changed, 31 insertions(+), 4 deletions(-)
> >
> > Reviewing this now with a more critical eye since it is longer just a
> > quick-n-dirty proof of concept ...
> >
> > > diff --git a/kernel/audit.h b/kernel/audit.h
> > > index 3b64a97f6091..25d63731b0e0 100644
> > > --- a/kernel/audit.h
> > > +++ b/kernel/audit.h
> > > @@ -196,6 +196,12 @@ struct audit_context {
> > >                 struct {
> > >                         char                    *name;
> > >                 } module;
> > > +               struct {
> > > +                       struct audit_ntp_data   data;
> > > +               } ntp;
> > > +               struct {
> > > +                       struct timespec64       injoffset;
> > > +               } tk;
> >
> > With the ntp and tk structs being separate parts of a union, are we
> > going to have a problem when ADJ_SETOFFSET is set in a call to
> > do_adjtimex()?
>
> Yes, so since both record types can exist in one event, either both
> pieces of data will need to be in one struct within the union, or
> one piece of data will need to go outside of the union (preferably the
> smaller one to avoid bloating struct audit_context more than necessary).
> The tk data is smaller and is easier to check if it is set, so that
> might be better to store outside the union.
>
> Since show_special is keyed off record type, it makes more sense to
> store one of those datum outside the union and process it outside
> show_special to avoid record type tricks in show_special.

It seems so much easier just to put both "data" and "injoffset" inside
a single struct within the union, and considering the size of
mq_getsetattr in that same union I doubt the size will increase
significantly (or at all, if my quick estimation stands up).

I believe our best approach is to stay consistent with how we handle
other things similar to this, I don't currently see any reason why the
NTP adjustments would require special handling.

As an aside, how did you test this and not run into this issue?

> > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> > > index 6efb0bb909d0..8983790ad86a 100644
> > > --- a/kernel/auditsc.c
> > > +++ b/kernel/auditsc.c
> > > @@ -1210,11 +1210,18 @@ static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name)
> > >                          from_kuid(&init_user_ns, name->fcap.rootid));
> > >  }
> > >
> > > +void __audit_ntp_log_(const struct audit_ntp_data *ad);
> > > +
> > >  static void show_special(struct audit_context *context, int *call_panic)
> > >  {
> > >         struct audit_buffer *ab;
> > >         int i;
> > >
> > > +       if (context->type == AUDIT_TIME_ADJNTPVAL) {
> > > +               __audit_ntp_log_(&context->ntp.data);
> > > +               return;
> > > +       }
> >
> > Can we find a way to move this down into the main switch statement in
> > show_special() like you did with AUDIT_TIME_INJOFFSET?  This looks
> > *really* hacky to me.  Why should AUDIT_TIME_ADJNTPVAL be different
> > from the other "special" bits?
>
> Agreed, it *looked* hacky to me too.  As previously noted, this was the
> most expedient way to do this due to the unknown number of records being
> generated, minimum of zero (max 6).  show_special allocates an
> audit_buffer before processing the specific record type, assuming it
> exists.  In the case of audit_ntp_data, it may all be equal and not need
> to be logged.
>
> Ideally, the old vs new data should be compared at the time of the call
> from do_adjtimex() to find out if we even need to store that data
> when all old and new values are equal.
>
> So, a bit more pre-processing during the call to avoid storing the
> information if it isn't needed will avoid it at syscall exit.  Are you
> ok with that?

The currently proposed approach is ugly enough that I think it is
worth looking at alternatives, let's see what you can come up with in
the next version and make a decision then.

> > > @@ -2588,7 +2609,7 @@ static void audit_log_ntp_val(const struct audit_ntp_data *ad,
> > >                   "op=%s old=%lli new=%lli", op, val->oldval, val->newval);
> > >  }
> > >
> > > -void __audit_ntp_log(const struct audit_ntp_data *ad)
> > > +void __audit_ntp_log_(const struct audit_ntp_data *ad)
> > >  {
> > >         audit_log_ntp_val(ad, "offset", AUDIT_NTP_OFFSET);
> > >         audit_log_ntp_val(ad, "freq",   AUDIT_NTP_FREQ);
> >
> > Ooof, *please* don't end a function, or any symbol for that matter,
> > with an underscore.
>
> Ok, renamed to be consistent with others called from show_special().

Thanks.

-- 
paul moore
paul-moore.com

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit


      parent reply	other threads:[~2022-01-20 23:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 20:59 [RFC PATCH v1] audit: log AUDIT_TIME_* records only from rules Richard Guy Briggs
2021-11-04 21:29 ` Paul Moore
2021-11-04 21:53   ` Richard Guy Briggs
2021-11-19 16:15     ` Paul Moore
2021-11-19 18:01       ` Richard Guy Briggs
2021-11-24 15:44         ` Paul Moore
2021-12-21 20:50           ` Richard Guy Briggs
2021-12-23 17:38             ` Paul Moore
2021-12-24 14:21               ` Richard Guy Briggs
2021-12-27 15:07                 ` Paul Moore
2021-12-29 22:51 ` Paul Moore
2022-01-12 21:06   ` Richard Guy Briggs
2022-01-12 21:46     ` Casey Schaufler
2022-01-20 23:07     ` Paul Moore [this message]

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='CAHC9VhSC2N+LB=neJC=3-L4_rP8gfO5HBFjGWXMKjxOBr2Ymcg@mail.gmail.com' \
    --to=paul@paul-moore.com \
    --cc=eparis@parisplace.org \
    --cc=linux-audit@redhat.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.