Re: [PATCH ghak59 V2 3/6] audit: exclude user records from syscall context

From: Paul Moore
Date: Mon Nov 19 2018 - 13:06:03 EST


On Fri, Jul 27, 2018 at 3:51 PM Richard Guy Briggs <rgb@xxxxxxxxxx> wrote:
> Since the function audit_log_common_recv_msg() is shared by a number of
> AUDIT_CONFIG_CHANGE and the entire range of AUDIT_USER_* record types,
> and since the AUDIT_CONFIG_CHANGE message type has been converted to a
> syscall accompanied record type, special-case the AUDIT_USER_* range of
> messages so they remain standalone records.
>
> See: https://github.com/linux-audit/audit-kernel/issues/59
> Signed-off-by: Richard Guy Briggs <rgb@xxxxxxxxxx>
> ---
> kernel/audit.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)

While I'm a big fan of associating records into a single event when
they are related, in the case of these user messages the syscall
information isn't related to the logged user event, it is related with
the process' *logging* of the user event. I agree with the idea
behind this patch, but I have some comments about the patch itself:

* I understand you separated this out because you weren't sure if it
was desirable, but now that you know it is desirable it really should
be squashed into patch 2/6 so that it is a single change.
* I'm not a fan of creating __audit_log_common_recv_msg() in this
case; let's just create a audit_log_user_recv_msg() (or similar)
instead and leave audit_log_common_recv_msg() as it is after patch
2/6.

> diff --git a/kernel/audit.c b/kernel/audit.c
> index 6cfe3c9..62ada1b 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -1054,7 +1054,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
> return err;
> }
>
> -static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)
> +static void __audit_log_common_recv_msg(struct audit_context *context,
> + struct audit_buffer **ab, u16 msg_type)
> {
> uid_t uid = from_kuid(&init_user_ns, current_uid());
> pid_t pid = task_tgid_nr(current);
> @@ -1064,7 +1065,7 @@ static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)
> return;
> }
>
> - *ab = audit_log_start(audit_context(), GFP_KERNEL, msg_type);
> + *ab = audit_log_start(context, GFP_KERNEL, msg_type);
> if (unlikely(!*ab))
> return;
> audit_log_format(*ab, "pid=%d uid=%u", pid, uid);
> @@ -1072,6 +1073,11 @@ static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)
> audit_log_task_context(*ab);
> }
>
> +static inline void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)
> +{
> + __audit_log_common_recv_msg(audit_context(), ab, msg_type);
> +}
> +
> int is_audit_feature_set(int i)
> {
> return af.features & AUDIT_FEATURE_TO_MASK(i);
> @@ -1338,7 +1344,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
> if (err)
> break;
> }
> - audit_log_common_recv_msg(&ab, msg_type);
> + __audit_log_common_recv_msg(NULL, &ab, msg_type);
> if (msg_type != AUDIT_USER_TTY)
> audit_log_format(ab, " msg='%.*s'",
> AUDIT_MESSAGE_TEXT_MAX,
> --
> 1.8.3.1
>


--
paul moore
www.paul-moore.com