All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Edwards <gedwards@ddn.com>
To: Paul Moore <paul@paul-moore.com>
Cc: Richard Guy Briggs <rgb@redhat.com>, linux-audit@redhat.com
Subject: Re: [PATCH 1/2] audit: move processing of "audit" boot param to audit_init()
Date: Tue, 27 Feb 2018 08:59:21 -0700	[thread overview]
Message-ID: <20180227155920.GA13528@psuche> (raw)
In-Reply-To: <CAHC9VhRpbXbr3SJ6gafjxhoWePHJkJdDV_3SrZLYvz6a-DK70Q@mail.gmail.com>

On Mon, Feb 26, 2018 at 07:00:51PM -0500, Paul Moore wrote:
>
> In the process of trying to explain things a bit further (see the
> discussion thread in 0/2), I realized that some example code might
> speak better than I could.  Below is what I was thinking for a fix; I
> haven't tested it, so it may blow up badly, but hopefully it makes
> things a bit more clear.
>
> One thing of note, I did away with the kstrtol() altogether, when we
> are only looking for zero and one it seems easier to just compare the
> strings.
>
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 1a3e75d9a66c..5dd63f60ef90 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -61,6 +61,7 @@
> #include <linux/gfp.h>
> #include <linux/pid.h>
> #include <linux/slab.h>
> +#include <linux/string.h>
>
> #include <linux/audit.h>
>
> @@ -86,6 +87,7 @@ static int    audit_initialized;
> #define AUDIT_OFF      0
> #define AUDIT_ON       1
> #define AUDIT_LOCKED   2
> +#define AUDIT_ARGERR   3       /* indicate a "audit=X" syntax error at boot */
> u32            audit_enabled = AUDIT_OFF;
> bool           audit_ever_enabled = !!AUDIT_OFF;
>
> @@ -1581,6 +1583,12 @@ static int __init audit_init(void)
>        if (audit_initialized == AUDIT_DISABLED)
>                return 0;
>
> +       /* handle any delayed error reporting from audit_enable() */
> +       if (audit_default == AUDIT_ARGERR) {
> +               pr_err("invalid 'audit' parameter value, use 0 or 1\n");
> +               audit_default = AUDIT_ON;
> +       }
> +

If you are just going to pr_err() on invalid audit parameter instead of
panic, you don't need AUDIT_ARGERR at all or the delayed error reporting
of it here.  You can just use pr_err() in audit_enable() directly.

>        audit_buffer_cache = kmem_cache_create("audit_buffer",
>                                               sizeof(struct audit_buffer),
>                                               0, SLAB_PANIC, NULL);
> @@ -1618,19 +1626,23 @@ postcore_initcall(audit_init);
> /* Process kernel command-line parameter at boot time.  audit=0 or audit=1. */
> static int __init audit_enable(char *str)
> {
> -       long val;
> +       /* NOTE: we can't reliably send any messages to the console here */
>
> -       if (kstrtol(str, 0, &val))
> -               panic("audit: invalid 'audit' parameter value (%s)\n", str);
> -       audit_default = (val ? AUDIT_ON : AUDIT_OFF);
> +       if (!strcasecmp(str, "off") || !strcmp(str, "0"))
> +               audit_default = AUDIT_OFF;
> +       else if (!strcasecmp(str, "on") || !strcmp(str, "1"))
> +               audit_default = AUDIT_ON;
> +       else
> +               audit_default = AUDIT_ARGERR;

Just pr_err() here and set audit_default = AUDIT_ON for the error case.

>
> -       if (audit_default == AUDIT_OFF)
> +       if (audit_default) {
> +               audit_enabled = AUDIT_ON;
> +               audit_ever_enabled = AUDIT_ON;
> +       } else {
> +               audit_enabled = AUDIT_OFF;
> +               audit_ever_enabled = AUDIT_OFF;
>                audit_initialized = AUDIT_DISABLED;
> -       if (audit_set_enabled(audit_default))
> -               panic("audit: error setting audit state (%d)\n", audit_default);

You could leave this here if you did error
reporting/audit_default=AUDIT_ON in audit_enable() directly.

> -
> -       pr_info("%s\n", audit_default ?
> -               "enabled (after initialization)" : "disabled (until reboot)");
> +       }
>
>        return 1;
> }

Another idea I had was switching those original panic() calls to
audit_panic(), and then making audit_failure another __setup option,
i.e. audit_failure={silent,printk,panic} corresponding to
AUDIT_FAIL_{SILENT,PRINTK,PANIC}.  You could default it to
AUDIT_FAIL_PRINTK as it is today.  Users that really cared could boot
with audit_failure=panic.  I don't know if that would be overloading
audit_panic() outside of its intended purpose, though.

Greg

  parent reply	other threads:[~2018-02-27 15:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-23  0:22 [PATCH 0/2] audit boot parameter cleanups Greg Edwards
2018-02-23  0:22 ` [PATCH 1/2] audit: move processing of "audit" boot param to audit_init() Greg Edwards
2018-02-27  0:00   ` Paul Moore
2018-02-27  5:53     ` Richard Guy Briggs
2018-02-27 12:43       ` Paul Moore
2018-02-27 19:01         ` Richard Guy Briggs
2018-02-27 15:59     ` Greg Edwards [this message]
2018-02-27 22:28       ` Paul Moore
2018-02-27 22:52         ` Greg Edwards
2018-03-02 20:33           ` Paul Moore
2018-03-02 21:46             ` Greg Edwards
2018-03-02 22:30               ` Paul Moore
2018-02-23  0:22 ` [PATCH 2/2] audit: add "on"/"off" as valid boot parameter values Greg Edwards
2018-02-23 16:07 ` [PATCH 0/2] audit boot parameter cleanups Richard Guy Briggs
2018-02-23 23:58   ` Paul Moore
2018-02-26  4:58     ` Richard Guy Briggs

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=20180227155920.GA13528@psuche \
    --to=gedwards@ddn.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.