From: Kees Cook <keescook@chromium.org>
To: Paul Moore <paul@paul-moore.com>
Cc: linux-kernel@vger.kernel.org,
"Jérémie Galarneau" <jeremie.galarneau@efficios.com>,
s.mesoraca16@gmail.com, viro@zeniv.linux.org.uk,
dan.carpenter@oracle.com, akpm@linux-foundation.org,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
kernel-hardening@lists.openwall.com, linux-audit@redhat.com,
torvalds@linux-foundation.org
Subject: Re: [PATCH] audit: Report suspicious O_CREAT usage
Date: Wed, 25 Sep 2019 16:14:48 -0700 [thread overview]
Message-ID: <201909251614.5FDA48B1@keescook> (raw)
In-Reply-To: <201909251348.A1542A52@keescook>
On Wed, Sep 25, 2019 at 02:02:33PM -0700, Kees Cook wrote:
> This renames the very specific audit_log_link_denied() to
> audit_log_path_denied() and adds the AUDIT_* type as an argument. This
> allows for the creation of the new AUDIT_ANOM_CREAT that can be used to
> report the fifo/regular file creation restrictions that were introduced
> in commit 30aba6656f61 ("namei: allow restricted O_CREAT of FIFOs and
> regular files"). Without this change, discovering that the restriction
> is enabled can be very challenging:
> https://lore.kernel.org/lkml/CA+jJMxvkqjXHy3DnV5MVhFTL2RUhg0WQ-XVFW3ngDQOdkFq0PA@mail.gmail.com
>
> Reported-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This is not a complete fix because reporting was broken in commit
> 15564ff0a16e ("audit: make ANOM_LINK obey audit_enabled and
> audit_dummy_context")
> which specifically goes against the intention of these records: they
> should _always_ be reported. If auditing isn't enabled, they should be
> ratelimited.
>
> Instead of using audit, should this just go back to using
> pr_ratelimited()?
> ---
> fs/namei.c | 7 +++++--
> include/linux/audit.h | 5 +++--
> include/uapi/linux/audit.h | 1 +
> kernel/audit.c | 11 ++++++-----
> 4 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index 671c3c1a3425..0e60f81e1d5a 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -925,7 +925,7 @@ static inline int may_follow_link(struct nameidata *nd)
> return -ECHILD;
>
> audit_inode(nd->name, nd->stack[0].link.dentry, 0);
> - audit_log_link_denied("follow_link");
> + audit_log_path_denied(AUDIT_ANOM_LINK, "follow_link");
> return -EACCES;
> }
>
> @@ -993,7 +993,7 @@ static int may_linkat(struct path *link)
> if (safe_hardlink_source(inode) || inode_owner_or_capable(inode))
> return 0;
>
> - audit_log_link_denied("linkat");
> + audit_log_path_denied(AUDIT_ANOM_LINK, "linkat");
> return -EPERM;
> }
>
> @@ -1031,6 +1031,9 @@ static int may_create_in_sticky(struct dentry * const dir,
> (dir->d_inode->i_mode & 0020 &&
> ((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) ||
> (sysctl_protected_regular >= 2 && S_ISREG(inode->i_mode))))) {
> + audit_log_path_denied(AUDIT_ANOM_CREAT,
> + S_ISFIFO(inode->i_mode) ? "fifo"
> + : "regular");
> return -EACCES;
> }
> return 0;
> diff --git a/include/linux/audit.h b/include/linux/audit.h
> index aee3dc9eb378..b3715e2ee1c5 100644
> --- a/include/linux/audit.h
> +++ b/include/linux/audit.h
> @@ -156,7 +156,8 @@ extern void audit_log_d_path(struct audit_buffer *ab,
> const struct path *path);
> extern void audit_log_key(struct audit_buffer *ab,
> char *key);
> -extern void audit_log_link_denied(const char *operation);
> +extern void audit_log_path_denied(int type,
> + const char *operation);
> extern void audit_log_lost(const char *message);
>
> extern int audit_log_task_context(struct audit_buffer *ab);
> @@ -217,7 +218,7 @@ static inline void audit_log_d_path(struct audit_buffer *ab,
> { }
> static inline void audit_log_key(struct audit_buffer *ab, char *key)
> { }
> -static inline void audit_log_link_denied(const char *string)
> +static inline void audit_log_path_denied(int type, const char *string);
Oops, typo above (should be no trailing ";"). Thanks 0day-bot! I didn't
build without CONFIG_AUDIT. :)
-Kees
> { }
> static inline int audit_log_task_context(struct audit_buffer *ab)
> {
> diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
> index c89c6495983d..3ad935527177 100644
> --- a/include/uapi/linux/audit.h
> +++ b/include/uapi/linux/audit.h
> @@ -143,6 +143,7 @@
> #define AUDIT_ANOM_PROMISCUOUS 1700 /* Device changed promiscuous mode */
> #define AUDIT_ANOM_ABEND 1701 /* Process ended abnormally */
> #define AUDIT_ANOM_LINK 1702 /* Suspicious use of file links */
> +#define AUDIT_ANOM_CREAT 1703 /* Suspicious file creation */
> #define AUDIT_INTEGRITY_DATA 1800 /* Data integrity verification */
> #define AUDIT_INTEGRITY_METADATA 1801 /* Metadata integrity verification */
> #define AUDIT_INTEGRITY_STATUS 1802 /* Integrity enable status */
> diff --git a/kernel/audit.c b/kernel/audit.c
> index da8dc0db5bd3..ed7402ac81b6 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -2155,18 +2155,19 @@ void audit_log_task_info(struct audit_buffer *ab)
> EXPORT_SYMBOL(audit_log_task_info);
>
> /**
> - * audit_log_link_denied - report a link restriction denial
> - * @operation: specific link operation
> + * audit_log_path_denied - report a path restriction denial
> + * @type: audit message type (AUDIT_ANOM_LINK, AUDIT_ANOM_CREAT, etc)
> + * @operation: specific operation name
> */
> -void audit_log_link_denied(const char *operation)
> +void audit_log_path_denied(int type, const char *operation)
> {
> struct audit_buffer *ab;
>
> if (!audit_enabled || audit_dummy_context())
> return;
>
> - /* Generate AUDIT_ANOM_LINK with subject, operation, outcome. */
> - ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_ANOM_LINK);
> + /* Generate log with subject, operation, outcome. */
> + ab = audit_log_start(audit_context(), GFP_KERNEL, type);
> if (!ab)
> return;
> audit_log_format(ab, "op=%s", operation);
> --
> 2.17.1
>
>
> --
> Kees Cook
--
Kees Cook
next prev parent reply other threads:[~2019-09-25 23:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-25 21:02 [PATCH] audit: Report suspicious O_CREAT usage Kees Cook
2019-09-25 21:40 ` kbuild test robot
2019-09-25 22:02 ` kbuild test robot
2019-09-25 23:14 ` Kees Cook [this message]
2019-09-26 15:31 ` Paul Moore
2019-09-30 13:50 ` Steve Grubb
2019-09-30 18:29 ` Kees Cook
2019-10-01 5:31 ` Paul Moore
2019-10-01 5:37 ` Paul Moore
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=201909251614.5FDA48B1@keescook \
--to=keescook@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=jeremie.galarneau@efficios.com \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-audit@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=paul@paul-moore.com \
--cc=s.mesoraca16@gmail.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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