Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1077229imm; Wed, 6 Jun 2018 10:04:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIKWgIp5jFvwbnettEJVrB12CbLyot7evRBKtHs2K0yqD2GR6F7QEIa7FYxrnKgsl8gR7Qk X-Received: by 2002:a17:902:7898:: with SMTP id q24-v6mr4132529pll.254.1528304679964; Wed, 06 Jun 2018 10:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528304679; cv=none; d=google.com; s=arc-20160816; b=kxJMPyfwd3OtOC5fSUetilvNLK3UFxSioFhHUN3vmVFUsxiIYIIk1+hwI5q+XdEZPy f1f722weJyEgEyvFrJUqKCfVcWMFSqusY2TNHo1lWBC6sxWhmsSLY/YiDtnEX5Pr6g+s cvlX5Cd2b8VGTLi9dgNVEyWqAaGnU4E5FYJ/qdRH+NWN+AXBeGRJGbEBhp+sNZBwFjOK XfaD45QWfRkt6cql68mBhDvT16mXCcWYxSCfijEw1FUNwJ+oPq2oFlRvViG4UntHjJzF Uv7+iLpXnrqJeUjSpkalmJcA7iPkE9r0Y09atN6IdzwVf+DMWybIpG9qHkIZrnzYKr6J 2PHA== 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=832jLlJTq5vvA3b8+pngtXJC2rSTtlYbBFvIJJEmyTc=; b=xI36ABeg/jWcVNnHID43G0fDotvdQ9+B5rMwY9xFByUtoAlePrlfhFp+GG9tk1eOyv dgnRRGv9uPI9n84ZtrqkmEp8+fCZld+nQfY/kpwuZgzAsfdhPFzBjUpvGtVa69p1UYfA AADgRNlVnPMkSSHg8Cov6hX4zIgIYZhQpqeUoHKF4GAcxEXlKXzxB9TVfBG8TrEHLNVr 5ICZ0Cki3coVFWZfeOQUI8MV+on0FpKYt6YAXU8udpDFERy83Ckboz1tewKZjf8cXAlx EupHfCgRr193IHZAC8+wrBMgQTWgHeBDkWHl5EJtoGQBEklnhCltZvm74+e1L57mcejX XyyQ== 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 z7-v6si27756642pfn.247.2018.06.06.10.04.24; Wed, 06 Jun 2018 10:04:39 -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 S933721AbeFFRBt (ORCPT + 99 others); Wed, 6 Jun 2018 13:01:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35498 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933699AbeFFRBp (ORCPT ); Wed, 6 Jun 2018 13:01:45 -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 67FA5A28EC; Wed, 6 Jun 2018 17:01:44 +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 BD14C6B401; Wed, 6 Jun 2018 17:01:30 +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 08/10] audit: NETFILTER_PKT: record each container ID associated with a netNS Date: Wed, 6 Jun 2018 12:58:35 -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.2]); Wed, 06 Jun 2018 17:01:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 06 Jun 2018 17:01:44 +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 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 | 20 +++++++++++++++++++- kernel/auditsc.c | 2 ++ net/netfilter/xt_AUDIT.c | 12 ++++++++++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/linux/audit.h b/include/linux/audit.h index 7e2e51c..4560a4e 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -167,6 +167,8 @@ extern int audit_log_contid(struct audit_context *context, extern void audit_contid_add(struct net *net, u64 contid); extern void audit_contid_del(struct net *net, u64 contid); extern void audit_switch_task_namespaces(struct nsproxy *ns, struct task_struct *p); +extern void audit_log_contid_list(struct net *net, + struct audit_context *context); extern int audit_update_lsm_rules(void); @@ -231,6 +233,9 @@ static inline void audit_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_contid_list(struct net *net, + struct audit_context *context) +{ } #define audit_enabled 0 #endif /* CONFIG_AUDIT */ diff --git a/kernel/audit.c b/kernel/audit.c index ecd2de4..8cca41a 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -382,6 +382,20 @@ void audit_switch_task_namespaces(struct nsproxy *ns, struct task_struct *p) audit_contid_add(new->net_ns, contid); } +void audit_log_contid_list(struct net *net, struct audit_context *context) +{ + struct audit_contid *cont; + int i = 0; + + list_for_each_entry(cont, audit_get_contid_list(net), list) { + char buf[14]; + + sprintf(buf, "net%u", i++); + audit_log_contid(context, buf, cont->id); + } +} +EXPORT_SYMBOL(audit_log_contid_list); + void audit_panic(const char *message) { switch (audit_failure) { @@ -2132,17 +2146,21 @@ int audit_log_contid(struct audit_context *context, char *op, u64 contid) { struct audit_buffer *ab; + gfp_t gfpflags; if (!cid_valid(contid)) return 0; + /* We can be called in atomic context via audit_tg() */ + gfpflags = (in_atomic() || irqs_disabled()) ? GFP_ATOMIC : GFP_KERNEL; /* Generate AUDIT_CONTAINER record with container ID */ - ab = audit_log_start(context, GFP_KERNEL, AUDIT_CONTAINER); + ab = audit_log_start(context, gfpflags, AUDIT_CONTAINER); if (!ab) return -ENOMEM; audit_log_format(ab, "op=%s contid=%llu", op, contid); audit_log_end(ab); return 0; } +EXPORT_SYMBOL(audit_log_contid); void audit_log_key(struct audit_buffer *ab, char *key) { diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 6ab5e5e..e2a16d2 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -1015,6 +1015,7 @@ struct audit_context *audit_alloc_local(void) context->in_syscall = 1; return context; } +EXPORT_SYMBOL(audit_alloc_local); void audit_free_context(struct audit_context *context) { @@ -1029,6 +1030,7 @@ void audit_free_context(struct audit_context *context) audit_proctitle_free(context); kfree(context); } +EXPORT_SYMBOL(audit_free_context); static int audit_log_pid_context(struct audit_context *context, pid_t pid, kuid_t auid, kuid_t uid, unsigned int sessionid, diff --git a/net/netfilter/xt_AUDIT.c b/net/netfilter/xt_AUDIT.c index f368ee6..10d2707 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 == 0) - goto errout; - ab = audit_log_start(NULL, GFP_ATOMIC, AUDIT_NETFILTER_PKT); + goto out; + context = audit_alloc_local(); + 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_contid_list(net, context); + errout: + audit_free_context(context); +out: return XT_CONTINUE; } -- 1.8.3.1