Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4137055ybg; Fri, 25 Oct 2019 13:56:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKcZRnL2ccBiXeBFoDRZFq9AFsln+yye46oRwHKI/uNonYi2MZzhbUI4VSerGlRGs4S1cy X-Received: by 2002:a17:906:4488:: with SMTP id y8mr5347886ejo.322.1572036964289; Fri, 25 Oct 2019 13:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572036964; cv=none; d=google.com; s=arc-20160816; b=OQ53zn+Wfouxo7h6mevrdK3IGuMGmbui89bl2/rOKgJt2imfJKHrbxGVjGZa0z9yOr JhoCiHLxXmL2n90+IV4t1dDD2gfnjmg6TpELnFZ6Lt623NhZqFQNOSeu/b0aOLK/3oC5 AF16t6QhJNbhNA+BDD5KNe0KOlqLForNubacprm3/2W76KToMYCCwzFClV4/BuT8FtM9 kS+q3+am5hbFztHCuprf8OR4quqvwhBw3rrfytdqGppO9vS1vkUtg77XbsyVGWNbX2QZ CE0y6jNoqn4V9up85e2lKYraN1HPWUQnmA0hreRSm2/TBlfeLyOTYhQW2KFiSYvTY1ON YNoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gjP7lTTjpTfakTXfOsGFWUmjZaWNVRnXwyVyG8tVt5E=; b=pJ3ks81HgH22mA/Y8VQDy+MTlat89BaeXDMnXl6ByZPCMUBEAAgS1jqQTKoTFAsFpw f9i/m2fDE7jlnoRM+YaS4Pa+VIwpIr6Sgs/8VRPjr3AC8Z7BXj/AFKjKdcr9VNx+HMoM S4SCXTIMX+nq0JPgyhMaMql2pPvxlwi9cVgLmsp9RcybnkRMqrSsirqaIw+irMdlo/os JnyoHeo8BpwCVPNdEycpHFqZPIBRva2YnaBe3tdjc8ERBUgUXWj8zgYdm51xQQolevk8 w4vuIF1TP7ydRe+Lo054AijfsIM5ODO6M3XGkNUo/j761lLSKJu9XqK1woGd4B6xbW9h zizA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g1NSkzY+; 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=pass (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 z6si2048459edm.316.2019.10.25.13.55.39; Fri, 25 Oct 2019 13:56:04 -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=@redhat.com header.s=mimecast20190719 header.b=g1NSkzY+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727456AbfJYToV (ORCPT + 99 others); Fri, 25 Oct 2019 15:44:21 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:60035 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727457AbfJYToV (ORCPT ); Fri, 25 Oct 2019 15:44:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572032660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gjP7lTTjpTfakTXfOsGFWUmjZaWNVRnXwyVyG8tVt5E=; b=g1NSkzY+81DL8fIl6+i5hmRZJ03l6kAgyYmSOkhDMJ5NTOr+sW5mO2XtFKS7hUMChOXD/5 ILH5a1Q+0oBYNY0uhcBOwELx5idmPDH7vKVXUdAKBfRAzUMfgBjy33r1KsAIj+e2Mbrarw RWncQqX0CgYIYalqWr64qU6tHe7If7Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-2mG1hvoOMmKqLeTPX6Nl1w-1; Fri, 25 Oct 2019 15:44:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9EEE7801E66; Fri, 25 Oct 2019 19:44:13 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AED061001B23; Fri, 25 Oct 2019 19:43:59 +0000 (UTC) Date: Fri, 25 Oct 2019 15:43:56 -0400 From: Richard Guy Briggs To: Paul Moore 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 Subject: Re: [PATCH ghak90 V7 05/21] audit: log drop of contid on exit of last task Message-ID: <20191025194356.skqebldthpokwd2m@madcap2.tricolour.ca> References: <71b75f54342f32f176c2b6d94584f2a666964e68.1568834524.git.rgb@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 2mG1hvoOMmKqLeTPX6Nl1w-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-10-10 20:38, Paul Moore wrote: > On Wed, Sep 18, 2019 at 9:24 PM Richard Guy Briggs wrote= : > > Since we are tracking the life of each audit container indentifier, we > > can match the creation event with the destruction event. Log the > > destruction of the audit container identifier when the last process in > > that container exits. > > > > Signed-off-by: Richard Guy Briggs > > --- > > kernel/audit.c | 32 ++++++++++++++++++++++++++++++++ > > kernel/audit.h | 2 ++ > > kernel/auditsc.c | 2 ++ > > 3 files changed, 36 insertions(+) > > > > diff --git a/kernel/audit.c b/kernel/audit.c > > index ea0899130cc1..53d13d638c63 100644 > > --- a/kernel/audit.c > > +++ b/kernel/audit.c > > @@ -2503,6 +2503,38 @@ int audit_set_contid(struct task_struct *task, u= 64 contid) > > return rc; > > } > > > > +void audit_log_container_drop(void) > > +{ > > + struct audit_buffer *ab; > > + uid_t uid; > > + struct tty_struct *tty; > > + char comm[sizeof(current->comm)]; > > + > > + if (!current->audit || !current->audit->cont || > > + refcount_read(¤t->audit->cont->refcount) > 1) > > + return; > > + ab =3D audit_log_start(audit_context(), GFP_KERNEL, AUDIT_CONTA= INER_OP); > > + if (!ab) > > + return; > > + > > + uid =3D from_kuid(&init_user_ns, task_uid(current)); > > + tty =3D audit_get_tty(); > > + audit_log_format(ab, > > + "op=3Ddrop opid=3D%d contid=3D%llu old-contid= =3D%llu pid=3D%d uid=3D%u auid=3D%u tty=3D%s ses=3D%u", > > + task_tgid_nr(current), audit_get_contid(curren= t), > > + audit_get_contid(current), task_tgid_nr(curren= t), uid, > > + from_kuid(&init_user_ns, audit_get_loginuid(cu= rrent)), > > + tty ? tty_name(tty) : "(none)", > > + audit_get_sessionid(current)); > > + audit_put_tty(tty); > > + audit_log_task_context(ab); > > + audit_log_format(ab, " comm=3D"); > > + audit_log_untrustedstring(ab, get_task_comm(comm, current)); > > + audit_log_d_path_exe(ab, current->mm); > > + audit_log_format(ab, " res=3D1"); > > + audit_log_end(ab); > > +} >=20 > Why can't we just do this in audit_cont_put()? Is it because we call > audit_cont_put() in the new audit_free() function? What if we were to > do it in __audit_free()/audit_free_syscall()? The intent was to put this before the EOE record of a syscall so we could fill out all the fields similarly to op=3Dset, but this could stand alone dropping or nulling a bunch of fields. It would also never get printed if we left it before the EOE and had the audit signal info record keep a reference to it. Hmmm... > paul moore - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635