Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1073766imm; Wed, 6 Jun 2018 10:02:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLRQYRHBb9IfAoGV+CwElL67+t/qwFvpO6UdeuXpCWKxMvyIuixujd3iYENLvc6ZjyohTvK X-Received: by 2002:a65:4a04:: with SMTP id s4-v6mr3184542pgq.376.1528304538645; Wed, 06 Jun 2018 10:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528304538; cv=none; d=google.com; s=arc-20160816; b=K1OFvubDXk8i2Dt5YwRddlesaUh07PF2NT6aEv9dNTbZcFvfaXlMkusGpS1moiFmuF BXhU5Z/fXFBLzdUZp2brx1W94t3qTjP0iXv0s3w6+ErBQtSAFrQWytAUPzUs6Jxdj8UE L/hRVWRZE6jGeX4YHLjbtsGcr3niZZvbi5QWRDOzvvd37YwgAr1DDfasiMeQUnEF2KFy Xf0ufhNs0iWDq3RD4Eg6BNSJ/4hquFsIBP7X0Q6D6WEJ5powJFWSc2O/4llK35j8+d1A 1UPmDSxM9IUfMncdx0dpmTdV/BKOndHlL7SdIovy50ed9mq31xLeGH9Nps3VLvTQoWOq TzVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=WpOsmoImor/ukyM214FWr/Hy1IeRWpHSjYQPLSXIeDk=; b=L7xaTpwkkhuLD+mmf8343oFQRWdndiReWF6eF+P/QbS2Y6WjMbqtm9R7MhcDhVhpat x9gfDHRm3JKKz1HtsG4I79esYMwHe3jpOiVXOyVwxljZbiwCplfxYZJLqhTS35o4uK8k seGVRdrzaDKA2lVmz6gYFcnWAiHSy/dsiEiPl7pqag6w+nCtzJwFG9JslBrFbXDk5l2O rq0YWiQ6gMYkImI2ZeAGNEDswXXmnUougO1mhawGHkyfUIJrkzuLcNQdSWJ0i9xBSk8T 1dYSFaJEkmn+Ge9aEY/k9EoEQjXRQjXrIi927isxv9nYT8d30W5cuoyXlVV8rQmt88yl oLHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e39-v6si52795976plg.168.2018.06.06.10.02.03; Wed, 06 Jun 2018 10:02:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933623AbeFFRBN (ORCPT + 99 others); Wed, 6 Jun 2018 13:01:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53214 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752390AbeFFRBJ (ORCPT ); Wed, 6 Jun 2018 13:01:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F3284078340; Wed, 6 Jun 2018 17:01:08 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-57.rdu2.redhat.com [10.10.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F2C96468B; Wed, 6 Jun 2018 17:01:02 +0000 (UTC) From: Richard Guy Briggs To: cgroups@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org Cc: luto@kernel.org, jlayton@redhat.com, carlos@redhat.com, viro@zeniv.linux.org.uk, dhowells@redhat.com, simo@redhat.com, eparis@parisplace.org, serge@hallyn.com, ebiederm@xmission.com, Richard Guy Briggs Subject: [RFC PATCH ghak90 (was ghak32) V3 04/10] audit: add support for non-syscall auxiliary records Date: Wed, 6 Jun 2018 12:58:31 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 06 Jun 2018 17:01:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 06 Jun 2018 17:01:08 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rgb@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Standalone audit records have the timestamp and serial number generated on the fly and as such are unique, making them standalone. This new function audit_alloc_local() generates a local audit context that will be used only for a standalone record and its auxiliary record(s). The context is discarded immediately after the local associated records are produced. Signed-off-by: Richard Guy Briggs --- include/linux/audit.h | 8 ++++++++ kernel/auditsc.c | 25 +++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/linux/audit.h b/include/linux/audit.h index ab50985..f549121 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -232,7 +232,9 @@ struct audit_task_info { extern struct audit_task_info init_struct_audit; extern void __init audit_task_init(void); extern int audit_alloc(struct task_struct *task); +extern struct audit_context *audit_alloc_local(void); extern void audit_free(struct task_struct *task); +extern void audit_free_context(struct audit_context *context); extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3); extern void __audit_syscall_exit(int ret_success, long ret_value); @@ -493,6 +495,12 @@ static inline int audit_alloc(struct task_struct *task) { return 0; } +static inline struct audit_context *audit_alloc_local(void) +{ + return NULL; +} +static inline void audit_free_context(struct audit_context *context) +{ } static inline void audit_free(struct task_struct *task) { } static inline void audit_syscall_entry(int major, unsigned long a0, diff --git a/kernel/auditsc.c b/kernel/auditsc.c index cface9d..81c9765 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -916,8 +916,11 @@ static inline void audit_free_aux(struct audit_context *context) static inline struct audit_context *audit_alloc_context(enum audit_state state) { struct audit_context *context; + gfp_t gfpflags; - context = kzalloc(sizeof(*context), GFP_KERNEL); + /* We can be called in atomic context via audit_tg() */ + gfpflags = (in_atomic() || irqs_disabled()) ? GFP_ATOMIC : GFP_KERNEL; + context = kzalloc(sizeof(*context), gfpflags); if (!context) return NULL; context->state = state; @@ -993,8 +996,26 @@ struct audit_task_info init_struct_audit = { .ctx = NULL, }; -static inline void audit_free_context(struct audit_context *context) +struct audit_context *audit_alloc_local(void) { + struct audit_context *context; + + if (!audit_ever_enabled) + return NULL; /* Return if not auditing. */ + + context = audit_alloc_context(AUDIT_RECORD_CONTEXT); + if (!context) + return NULL; + context->serial = audit_serial(); + context->ctime = current_kernel_time64(); + context->in_syscall = 1; + return context; +} + +void audit_free_context(struct audit_context *context) +{ + if (!context) + return; audit_free_names(context); unroll_tree_refs(context, NULL, 0); free_tree_refs(context); -- 1.8.3.1