Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp261296ybp; Thu, 10 Oct 2019 17:43:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWCjTxOUXLr2f9QnRJUmaxk437PaQJOb44up1ukMVWF4A321p0XsQ3kKhGQ2iVKLCf3oBl X-Received: by 2002:aa7:df0b:: with SMTP id c11mr11034829edy.101.1570754583471; Thu, 10 Oct 2019 17:43:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570754583; cv=none; d=google.com; s=arc-20160816; b=XjE4PxIDejDvKw0PbxE/0b2qxetUEDl04rk2SEQ/0oivUoFgJxRHTPI4JUm85rY1Zj 6b5jAO75q3SeDSPCCAugab7grU7dvP7YXfgAU1RSYle3Ne/1ppX+uWpPf+Lr8y30t4QQ +LIo3HZzQnSi5INCHWUrvdOlrUcryo9jI5q82SThkLoJfFJTF/c2UmXcPFcPmZlIyx0N l6sbAnTXybI6hgAvJClPPJ+cFMEEO0RF0/SFIuwoKAOF4XDpelET0ECi4mzP+JPmIHZP dPf8y5qvVYVcqmTTPh9TWPBynJfu8+jVmDrC/QMkAHRwAKQ5I5rc9ncz5mRdo3o5uvT1 Ru1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=N487as+c+FNQH8UKaT6HaOwU2u0KpBH93Y19zrHfpEU=; b=Esis19+4+HJ4KiYluFf1L14KR3XQZEyc9JfmQ1Vg14gcAKBZTlM8KATUUDAwRBetwA 7AvDQ2eodYmy97a0X7DKIl7grXjCnlQNJ6muV/S0SCiQhMLqE1NzhsAK2ATZ6lth0jn4 +SG5+92gzxE38JXRaZuf7lqeK4zYDF3yTNy9/6/UMazndXPq+4tqOVeV6g6sZJsKwjg+ irLZ0SaWYvV/+UYeKExJjHtWa1p3Is3MCE4xevHVPb43EmGFJUM649fbHyFdIE9NniJU 4qjxI8WqaTll6FcX25ge6+22w++skBxedHD3AYB03hUh3zeYq5McijTIV0cZS4cO+tIe H71w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=ufwcAAv+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si4191281eja.377.2019.10.10.17.42.40; Thu, 10 Oct 2019 17:43:03 -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; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=ufwcAAv+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727895AbfJKAju (ORCPT + 99 others); Thu, 10 Oct 2019 20:39:50 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44696 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727917AbfJKAjt (ORCPT ); Thu, 10 Oct 2019 20:39:49 -0400 Received: by mail-lf1-f67.google.com with SMTP id q12so5720281lfc.11 for ; Thu, 10 Oct 2019 17:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=N487as+c+FNQH8UKaT6HaOwU2u0KpBH93Y19zrHfpEU=; b=ufwcAAv+UFt3XUw6Rd8NAzS51flGDXx3ywuA5XIH5+S2oFoO1Eaf6UmFdjOUMI6gka 6yCyta6ksoQrqSOl/4+hkHsG2c7boYbSkNyYM6xN8dBIPbyC96ggLQiwD1//Cssn99Rv 66i8F1CDFiyrlz+9H6hdBO4lrbiRgJ+nzfIONCUyXnWD2+c1GE1f7j8L2AMRZBEfy9g5 ZZYXTCvADd7l7/9pzVM3B1yUR1VRIxbYY8Yzx/B6+8NzIhME/H8YnuE2Mh06ykvkFBst ktCU1ig6EE3fVh6p9t8PnxmUOgUALw4WIVCUzgXCP7JYSSNw42EzsQ/ca4pdqBnSXpKU 7bVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=N487as+c+FNQH8UKaT6HaOwU2u0KpBH93Y19zrHfpEU=; b=CSuD327XnzHKdI8etWaFApfh5Q7FaFOm5bd7skFdOhgNdHeCB0j8Ge05rXKDxom25X MtOeb3kOLJ/udNYAtQDtm99M+U31OLQV63SRwpuJBFwqGg1rw5L77h78IGU24v1ZHh9b YAr27tnOAL4/JPn7ThePno9CPgu+2IQob86WTT1SS1cPBItH1a92F/G7z1tHv6THsHy8 PdXn3PW0XyV4tnjLbVuMOgZLFeEedk1Tyn0dChmfKak7tpb1CRUtbSbPZo5StUiv907L 9ufc2fq6t8UErAzXIr5fICaf31Po43VzQ+TehAuZ6K+HDjQyNEGQdKGvZMJ+7PjDSAAI opEw== X-Gm-Message-State: APjAAAWjw32g3kVsxY26734SSw1mep9dEZiwUZHEcOVRYRMJtK7JksNs KIqMo6AfUya1yEJYUGuAvDFejrMgSaHrqMJXjlZ2 X-Received: by 2002:a19:2394:: with SMTP id j142mr7362655lfj.13.1570754386530; Thu, 10 Oct 2019 17:39:46 -0700 (PDT) MIME-Version: 1.0 References: <91315ac64b44bcad9dfc623fa7fefe67d7d2561b.1568834524.git.rgb@redhat.com> In-Reply-To: <91315ac64b44bcad9dfc623fa7fefe67d7d2561b.1568834524.git.rgb@redhat.com> From: Paul Moore Date: Thu, 10 Oct 2019 20:39:35 -0400 Message-ID: Subject: Re: [PATCH ghak90 V7 12/21] audit: add support for containerid to network namespaces To: Richard Guy Briggs Cc: 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, sgrubb@redhat.com, omosnace@redhat.com, dhowells@redhat.com, simo@redhat.com, Eric Paris , Serge Hallyn , ebiederm@xmission.com, nhorman@tuxdriver.com, Dan Walsh , mpatel@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 18, 2019 at 9:26 PM Richard Guy Briggs wrote: > Audit events could happen in a network namespace outside of a task > context due to packets received from the net that trigger an auditing > rule prior to being associated with a running task. The network > namespace could be in use by multiple containers by association to the > tasks in that network namespace. We still want a way to attribute > these events to any potential containers. Keep a list per network > namespace to track these audit container identifiiers. > > Add/increment the audit container identifier on: > - initial setting of the audit container identifier via /proc > - clone/fork call that inherits an audit container identifier > - unshare call that inherits an audit container identifier > - setns call that inherits an audit container identifier > Delete/decrement the audit container identifier on: > - an inherited audit container identifier dropped when child set > - process exit > - unshare call that drops a net namespace > - setns call that drops a net namespace > > Please see the github audit kernel issue for contid net support: > https://github.com/linux-audit/audit-kernel/issues/92 > Please see the github audit testsuiite issue for the test case: > https://github.com/linux-audit/audit-testsuite/issues/64 > Please see the github audit wiki for the feature overview: > https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID > Signed-off-by: Richard Guy Briggs > Acked-by: Neil Horman > Reviewed-by: Ondrej Mosnacek > --- > include/linux/audit.h | 19 +++++++++++ > kernel/audit.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++-- > kernel/nsproxy.c | 4 +++ > 3 files changed, 108 insertions(+), 2 deletions(-) ... > diff --git a/kernel/audit.c b/kernel/audit.c > index 7cdb76b38966..e0c27bc39925 100644 > --- a/kernel/audit.c > +++ b/kernel/audit.c > @@ -373,6 +381,75 @@ static struct sock *audit_get_sk(const struct net *net) > return aunet->sk; > } > > +void audit_netns_contid_add(struct net *net, u64 contid) > +{ > + struct audit_net *aunet; > + struct list_head *contid_list; > + struct audit_contid *cont; > + > + if (!net) > + return; > + if (!audit_contid_valid(contid)) > + return; > + aunet = net_generic(net, audit_net_id); > + if (!aunet) > + return; > + contid_list = &aunet->contid_list; > + spin_lock(&aunet->contid_list_lock); > + list_for_each_entry_rcu(cont, contid_list, list) > + if (cont->id == contid) { > + refcount_inc(&cont->refcount); > + goto out; > + } > + cont = kmalloc(sizeof(struct audit_contid), GFP_ATOMIC); kmalloc(sizeof(*cont), GFP_ATOMIC) > + if (cont) { > + INIT_LIST_HEAD(&cont->list); > + cont->id = contid; > + refcount_set(&cont->refcount, 1); > + list_add_rcu(&cont->list, contid_list); > + } > +out: > + spin_unlock(&aunet->contid_list_lock); > +} -- paul moore www.paul-moore.com