Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5483123ybl; Tue, 4 Feb 2020 15:04:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxWqPqwT5LmvOAsTpNDuylA+pjzEB5VSCF6GW8QGJtrovWbHqQUeqY+p+oXUgSavktAeOLi X-Received: by 2002:aca:4c11:: with SMTP id z17mr913830oia.104.1580857447291; Tue, 04 Feb 2020 15:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580857447; cv=none; d=google.com; s=arc-20160816; b=KlTaN70lnuaVh+mfh6oLh713U8mdrGPxlaMFPwhH8H/jEA2nMO0RmEqLCa/4Tr14bO 1JghThJQAmIkjnfuueDqhkS5CeD3BxLisjvWA1a7zLuKTfnRPf/8Vz8aCE6GFkifPQGF AEWr0DiSxY95x/b3OaTZJ7PNicrp+cigun+GzOUwcO+eLmF0E114SeHGH8bWexYEMR84 Hq8S40HFTmnVSUTKHNngjdqpdWAD/ahW6G/66ADrEyCRCM8rJ1p0PPLbkLb8tTwPR2YN lDgZ8r8bg+Mhet3L4TQiPXX/2njXEC+b2qBUhRn9ATabMg4CQMu4xNYZBd4t3wsa94if OO6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NKr69gnaNBcjsWSr0bho3ksQ06JauqQQ0HsRD8GC1SM=; b=AH4oRCYu6wtGGAxA8UpYGp+wL9JhgGPCOy5LVU1AC/y3oLaaBpvsmdR6tROsr4mI1Y M8iKdaKvEqlM0BRyziZuAsK4NFH1PBz1gJdxuBLMYfqWBzr+6h+ephV5eOtapj1TVPzx QDAEB+bnm0s2DzoW5ca7WS4oW2CEU5ZAbsjfh4j5lM0xPVUmQlsHpmdkhR0yBwDtO6bk nziwaodyWYsp6qHajjQ47loOHuvAXGikaF8ypc5qpz7nlMRr6CKZ3phXlShWF2evPL1j B4MYGHSAis3gfrLts3SxffeAU5ixa2dwmHzY5fqbWTsfb7fP6RNMCJirUC2xJGPDVI4o OBCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WR7NDBJT; 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 r82si10795820oie.116.2020.02.04.15.03.55; Tue, 04 Feb 2020 15:04:07 -0800 (PST) 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=WR7NDBJT; 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 S1727690AbgBDXC5 (ORCPT + 99 others); Tue, 4 Feb 2020 18:02:57 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:40743 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727412AbgBDXC4 (ORCPT ); Tue, 4 Feb 2020 18:02:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580857375; 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: in-reply-to:in-reply-to:references:references; bh=NKr69gnaNBcjsWSr0bho3ksQ06JauqQQ0HsRD8GC1SM=; b=WR7NDBJTcIJlQtvVsUkAYJI4bZUoP9SV8ujxf3RFiicJTBPwNw5tX8ODyYf5Oa3xjXeuAK 30gWx/idw2srPJY0Z9TwH4CluK6acKFvQxBuLtTy7CU91SsmGMviZh421scr4WCjl/iKP5 FE/iIg2EsySMZs0lO5pks8km4T2yYx4= 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-78-MhIqW77NP0-JlIJr67CfLA-1; Tue, 04 Feb 2020 18:02:53 -0500 X-MC-Unique: MhIqW77NP0-JlIJr67CfLA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C227A18AB2C0; Tue, 4 Feb 2020 23:02:51 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-16.rdu2.redhat.com [10.10.112.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6D4877927; Tue, 4 Feb 2020 23:02:37 +0000 (UTC) Date: Tue, 4 Feb 2020 18:02:35 -0500 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 V8 05/16] audit: log drop of contid on exit of last task Message-ID: <20200204230235.dwunh76dum4kkssp@madcap2.tricolour.ca> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-01-22 16:28, Paul Moore wrote: > On Tue, Dec 31, 2019 at 2:50 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 | 17 +++++++++++++++++ > > kernel/audit.h | 2 ++ > > kernel/auditsc.c | 2 ++ > > 3 files changed, 21 insertions(+) > > > > diff --git a/kernel/audit.c b/kernel/audit.c > > index 4bab20f5f781..fa8f1aa3a605 100644 > > --- a/kernel/audit.c > > +++ b/kernel/audit.c > > @@ -2502,6 +2502,23 @@ int audit_set_contid(struct task_struct *task, u64 contid) > > return rc; > > } > > > > +void audit_log_container_drop(void) > > +{ > > + struct audit_buffer *ab; > > + > > + if (!current->audit || !current->audit->cont || > > + refcount_read(¤t->audit->cont->refcount) > 1) > > + return; > > + ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_CONTAINER_OP); > > + if (!ab) > > + return; > > + > > + audit_log_format(ab, "op=drop opid=%d contid=%llu old-contid=%llu", > > + task_tgid_nr(current), audit_get_contid(current), > > + audit_get_contid(current)); > > + audit_log_end(ab); > > +} > > Assumine we are careful about where we call it in audit_free(...), you > are confident we can't do this as part of _audit_contobj_put(...), > yes? We need audit_log_container_drop in audit_free_syscall() due to needing context, which gets freed in audit_free_syscall() called from audit_free(). We need audit_log_container_drop in audit_log_exit() due to having that record included before the EOE record at the end of audit_log_exit(). We could put in _contobj_put() if we drop context and any attempt to connect it with a syscall record, which I strongly discourage. The syscall record contains info about subject, container_id record only contains info about container object other than subj pid. > > /** > > * audit_log_end - end one audit record > > * @ab: the audit_buffer > > diff --git a/kernel/audit.h b/kernel/audit.h > > index e4a31aa92dfe..162de8366b32 100644 > > --- a/kernel/audit.h > > +++ b/kernel/audit.h > > @@ -255,6 +255,8 @@ extern void audit_log_d_path_exe(struct audit_buffer *ab, > > extern struct tty_struct *audit_get_tty(void); > > extern void audit_put_tty(struct tty_struct *tty); > > > > +extern void audit_log_container_drop(void); > > + > > /* audit watch/mark/tree functions */ > > #ifdef CONFIG_AUDITSYSCALL > > extern unsigned int audit_serial(void); > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index 0e2d50533959..bd855794ad26 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -1568,6 +1568,8 @@ static void audit_log_exit(void) > > > > audit_log_proctitle(); > > > > + audit_log_container_drop(); > > + > > /* Send end of event record to help user space know we are finished */ > > ab = audit_log_start(context, GFP_KERNEL, AUDIT_EOE); > > if (ab) > > -- > > 1.8.3.1 > > > > -- > paul moore > www.paul-moore.com > - 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