Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp30750imm; Tue, 31 Jul 2018 13:13:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdGTkqwZHfbOS3QXkAAMAnUq4BkcOO8EghHB3ftVVhW8TK88GcrcG60Z241tqmCN9ZIcfwI X-Received: by 2002:a62:ea05:: with SMTP id t5-v6mr23509429pfh.228.1533068017395; Tue, 31 Jul 2018 13:13:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533068017; cv=none; d=google.com; s=arc-20160816; b=dqhIk+Azhssxovb7ToHJgOP8cpvT3xpvgkwtZXrEnxKFPW2SEaOUrP8NBEx4lJxizz knhbX0uTrbHFDMIN+qpcc+W7y1QiWN21gs5wiWZYGDvHGjtVB8ZLhcUrRGG8quYSmnTS dE5Qv6kB4z5J9z7FJoKiYuIbTAym6UgBBsJcNTcqthQtD6VqOyKIBbxLW3U+0H14NVko PHXCUJl+pB8GEEVl9L8sVzBbdH2KDn2iCOfzY7/SsSUr2NMu15UOz3R9xyWC26ODVJGC HBHXpiCMC6evJ81KronSMfEWsRz/+hWFTW8f3+ZG9wj2o9HHpWbU3L5JbHHKm7u+P4vL xHXw== 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=MLaE3OQ7HcvRvlll0DpgfuZyqyj+nwi/DFdPdqDXxhY=; b=PhhcEzOZlwipcwQ58GipZARKSnXfLHIaQleTxepKGQyoo5XUbUO78b/qlN7KGCX/lP DBLnbWM1cLK2ASAaenDsM/Xd9n+yCy1GPAxQPWIA/QqURtrChQO6y5RX4Xd4HZG8kEFl +cuosBRGXn3CgUGf23LevBA36Kqzpfa9NZfPmsgGwMMJzTO8QXIqhtwyPC5yuT28ry66 tuoPRwXuXfPMJitfKF3Q9QuSH7fRhIHx20rLgiGWWdT6TKQWcGxu+u6q46ye8k58jagM RV4AwTLtUeUmP342GvygnBeHX2FZyj3p1FTpEReWwVYCXOWQl03AAAQGg7IYsmgC6tpC GR1A== 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 n1-v6si14052924pge.57.2018.07.31.13.13.18; Tue, 31 Jul 2018 13:13:37 -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 S1732768AbeGaVxt (ORCPT + 99 others); Tue, 31 Jul 2018 17:53:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33438 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732659AbeGaVxs (ORCPT ); Tue, 31 Jul 2018 17:53:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B8887DAC2; Tue, 31 Jul 2018 20:11:49 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-17.rdu2.redhat.com [10.10.112.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 795AC2026D7E; Tue, 31 Jul 2018 20:11:46 +0000 (UTC) From: Richard Guy Briggs To: containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org Cc: luto@kernel.org, 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: [PATCH ghak90 (was ghak32) V4 09/10] audit: NETFILTER_PKT: record each container ID associated with a netNS Date: Tue, 31 Jul 2018 16:07:44 -0400 Message-Id: <3f5edfb0d530d7f0061fe11b817b315b350b9d86.1533065887.git.rgb@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 31 Jul 2018 20:11:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 31 Jul 2018 20:11:49 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 Add audit container identifier auxiliary record(s) to NETFILTER_PKT event standalone records. Iterate through all potential audit container identifiers associated with a network namespace. Signed-off-by: Richard Guy Briggs --- include/linux/audit.h | 5 +++++ kernel/audit.c | 26 ++++++++++++++++++++++++++ net/netfilter/xt_AUDIT.c | 12 ++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/linux/audit.h b/include/linux/audit.h index 9a02095..8755f4d 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -169,6 +169,8 @@ extern int audit_log_contid(struct audit_context *context, extern void audit_netns_contid_add(struct net *net, u64 contid); extern void audit_netns_contid_del(struct net *net, u64 contid); extern void audit_switch_task_namespaces(struct nsproxy *ns, struct task_struct *p); +extern void audit_log_netns_contid_list(struct net *net, + struct audit_context *context); extern int audit_update_lsm_rules(void); @@ -228,6 +230,9 @@ static inline void audit_netns_contid_del(struct net *net, u64 contid) { } static inline void audit_switch_task_namespaces(struct nsproxy *ns, struct task_struct *p) { } +static inline void audit_log_netns_contid_list(struct net *net, + struct audit_context *context) +{ } #define audit_enabled AUDIT_OFF #endif /* CONFIG_AUDIT */ diff --git a/kernel/audit.c b/kernel/audit.c index c5fed3b..b23711c 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -392,6 +392,32 @@ void audit_switch_task_namespaces(struct nsproxy *ns, struct task_struct *p) audit_netns_contid_add(new->net_ns, contid); } +void audit_log_netns_contid_list(struct net *net, struct audit_context *context) +{ + spinlock_t *lock = audit_get_netns_contid_list_lock(net); + struct audit_buffer *ab; + struct audit_contid *cont; + bool first = true; + + /* Generate AUDIT_CONTAINER record with container ID CSV list */ + ab = audit_log_start(context, GFP_ATOMIC, AUDIT_CONTAINER); + if (!ab) { + audit_log_lost("out of memory in audit_log_netns_contid_list"); + return; + } + audit_log_format(ab, "contid="); + spin_lock(lock); + list_for_each_entry(cont, audit_get_netns_contid_list(net), list) { + if (!first) + audit_log_format(ab, ","); + audit_log_format(ab, "%llu", cont->id); + first = false; + } + spin_unlock(lock); + audit_log_end(ab); +} +EXPORT_SYMBOL(audit_log_netns_contid_list); + void audit_panic(const char *message) { switch (audit_failure) { diff --git a/net/netfilter/xt_AUDIT.c b/net/netfilter/xt_AUDIT.c index af883f1..44fac3f 100644 --- a/net/netfilter/xt_AUDIT.c +++ b/net/netfilter/xt_AUDIT.c @@ -71,10 +71,13 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) { struct audit_buffer *ab; int fam = -1; + struct audit_context *context; + struct net *net; if (audit_enabled == AUDIT_OFF) - goto errout; - ab = audit_log_start(NULL, GFP_ATOMIC, AUDIT_NETFILTER_PKT); + goto out; + context = audit_alloc_local(GFP_ATOMIC); + ab = audit_log_start(context, GFP_ATOMIC, AUDIT_NETFILTER_PKT); if (ab == NULL) goto errout; @@ -104,7 +107,12 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) audit_log_end(ab); + net = xt_net(par); + audit_log_netns_contid_list(net, context); + errout: + audit_free_context(context); +out: return XT_CONTINUE; } -- 1.8.3.1