Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5264749ybl; Wed, 22 Jan 2020 13:30:32 -0800 (PST) X-Google-Smtp-Source: APXvYqyxGSJRsbkzoN4PRoiHOsXrCTfF+FGDJifqXiLw7KADAP2tilfD01XfT6M4U13JZk6F43G3 X-Received: by 2002:a9d:73ca:: with SMTP id m10mr9176761otk.312.1579728632645; Wed, 22 Jan 2020 13:30:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579728632; cv=none; d=google.com; s=arc-20160816; b=Osh/bvjeN7dN3AwU0CbRFrY7cWLsgspAu1cax4FhLz/DfKTZSij0iqlSbTGsw1sMIU TL06BISbnR0XY5o75C1iB4m9FATQK181RwTy6C/wAI1QdvE/5TAqyFWkpw90LhLLE6KW Nj+IDjVqRLMNE79drzeEMWojT8b+yTHVJV1oeBSX6IJbGxB+1WB7K3V4SrGwyRHht3VD flIiT/hpgoqail7f9X2WsxW9AajUDK1rjNWiXlYOYkJIgNuOXwSJu66qGvU/ny70mMsI EkKPEQVr4848nFTRaKFSIIqOv1hKqvz6rYwPa8hSjdqjaVOgCooQBQw5b2WUWy7xq8Fa EOYg== 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=UlbIRxeN9Q76SjfgK7QR1Vwr+MWjG4ms1YscK+m3ZzA=; b=q2nYTdGHtqs2z2Grv18bQ6XP5l2XyrOfaHktYZqMk8qYlPOH3NNkZmhQMzwztBKhSB FinbqiktGb8lY2Vus2TKW/kobxmlm2fHGKUU6+RmgScF3I0Fyiiu3fgOTFuEN3haDIeN CAEimQV0i6xZR2Pp1spDG84R0l/5M3mkPFQSEcJ03t6Xr4uixx6rqmjcRYExqjik15/S fleurgsxEejyJpFO7tTWrEGQaBBaXP93rNIh8SToMF29xhk3BWbp79rI0YtwLTYcVHeR 5sQK6/by+fqxs5Ml49DMmH3GpcTgTUMBIjZHhUHS1nf8JVoAQ9gzZEgbz2CVuYvhQotj 1hMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=sjR3Kohy; 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 s1si22592777oic.234.2020.01.22.13.30.20; Wed, 22 Jan 2020 13:30:32 -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=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=sjR3Kohy; 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 S1728205AbgAVV2Q (ORCPT + 99 others); Wed, 22 Jan 2020 16:28:16 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40141 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbgAVV2Q (ORCPT ); Wed, 22 Jan 2020 16:28:16 -0500 Received: by mail-lf1-f68.google.com with SMTP id i23so713989lfo.7 for ; Wed, 22 Jan 2020 13:28:14 -0800 (PST) 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=UlbIRxeN9Q76SjfgK7QR1Vwr+MWjG4ms1YscK+m3ZzA=; b=sjR3KohyzTMBY/tFrzlS/cG22yQtz+Kj0wlR28uWlOMMS98+mdyhDRY4wdLlRbRBWQ 4VlXyQi9Pw2NSmQ8fvwn9NxitppXBQTEWwjARvDbpiJhj/K0Y2i1EITeGLzwZ9AH5V63 j8XDebSAcj8dY4OSKlnr8BS/HvXVTvkfh1v1rMq9jtjpDyFdJqJ5TCN1NW8CiCsvMp5t Xhb80Ol0PeyJlSg/G7BNimSobNlNwIOJ510Xic8jSS7FVl0FfJkgEVDeG1eadjiSlAeb Czd8yw50v5cUx1XPONGfCW8/GGWBMBpXhutQp8L57JTt9oNAhGO4n84vU5u8OGXSD6G4 ZanA== 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=UlbIRxeN9Q76SjfgK7QR1Vwr+MWjG4ms1YscK+m3ZzA=; b=q9USg/2NfxoYWSCGSy6S+sZ2T+owQgcpm4jPkqh6k8JdxrNDOJqh3bvziVCLnsQqa7 YYTDGPDWbO+QDI3B2ak/UKggpyYztjslh5YRuyGgTpoOmU6EsGyNWF9+vNc16qQh3M43 AOGepbTnCaY7BVSgIQTAVIOjkJSq/mjGrrHtuBbCa/uzo5xF7ekIdkYkdoPnAAaN3xuN DIyGdk7CrbLRw/lbh+IBBRJGfW9qZxjvD1NNvVBRiwtfOqZIqG+yiI0me50aHZYLED1d UHPo7LmccyvNB5wiaZQczGmXa0bZ1Uqz8uUJRH4gvHs0GNSa4b7zK0WRT5kxos+xF9RY 4Yrg== X-Gm-Message-State: APjAAAWYHF/0ZmcEc8RU5rrQEzW7qURX+HvQt+OLUwv0AzEUzBifheMl 4wBs52mT9aJIH+qNsSgaKn3fBtIOps1gdDqaAia5 X-Received: by 2002:a19:dc1e:: with SMTP id t30mr2878129lfg.34.1579728493389; Wed, 22 Jan 2020 13:28:13 -0800 (PST) MIME-Version: 1.0 References: <70ad50e69185c50843d5e14462f1c4f03655d503.1577736799.git.rgb@redhat.com> In-Reply-To: <70ad50e69185c50843d5e14462f1c4f03655d503.1577736799.git.rgb@redhat.com> From: Paul Moore Date: Wed, 22 Jan 2020 16:28:02 -0500 Message-ID: Subject: Re: [PATCH ghak90 V8 02/16] audit: add container id 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 Tue, Dec 31, 2019 at 2:49 PM Richard Guy Briggs wrote: > > Implement the proc fs write to set the audit container identifier of a > process, emitting an AUDIT_CONTAINER_OP record to document the event. > > This is a write from the container orchestrator task to a proc entry of > the form /proc/PID/audit_containerid where PID is the process ID of the > newly created task that is to become the first task in a container, or > an additional task added to a container. > > The write expects up to a u64 value (unset: 18446744073709551615). > > The writer must have capability CAP_AUDIT_CONTROL. > > This will produce a record such as this: > type=CONTAINER_OP msg=audit(2018-06-06 12:39:29.636:26949) : op=set opid=2209 contid=123456 old-contid=18446744073709551615 > > The "op" field indicates an initial set. The "opid" field is the > object's PID, the process being "contained". New and old audit > container identifier values are given in the "contid" fields. > > It is not permitted to unset the audit container identifier. > A child inherits its parent's audit container identifier. > > Please see the github audit kernel issue for the main feature: > https://github.com/linux-audit/audit-kernel/issues/90 > Please see the github audit userspace issue for supporting additions: > https://github.com/linux-audit/audit-userspace/issues/51 > 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: Serge Hallyn > Acked-by: Steve Grubb > Acked-by: Neil Horman > Reviewed-by: Ondrej Mosnacek > Signed-off-by: Richard Guy Briggs > --- > fs/proc/base.c | 36 ++++++++++++++++++++++++++++ > include/linux/audit.h | 25 ++++++++++++++++++++ > include/uapi/linux/audit.h | 2 ++ > kernel/audit.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ > kernel/audit.h | 1 + > kernel/auditsc.c | 4 ++++ > 6 files changed, 126 insertions(+) ... > diff --git a/kernel/audit.c b/kernel/audit.c > index 397f8fb4836a..2d7707426b7d 100644 > --- a/kernel/audit.c > +++ b/kernel/audit.c > @@ -2356,6 +2358,62 @@ int audit_signal_info(int sig, struct task_struct *t) > return audit_signal_info_syscall(t); > } > > +/* > + * audit_set_contid - set current task's audit contid > + * @task: target task > + * @contid: contid value > + * > + * Returns 0 on success, -EPERM on permission failure. > + * > + * Called (set) from fs/proc/base.c::proc_contid_write(). > + */ > +int audit_set_contid(struct task_struct *task, u64 contid) > +{ > + u64 oldcontid; > + int rc = 0; > + struct audit_buffer *ab; > + > + task_lock(task); > + /* Can't set if audit disabled */ > + if (!task->audit) { > + task_unlock(task); > + return -ENOPROTOOPT; > + } > + oldcontid = audit_get_contid(task); > + read_lock(&tasklist_lock); > + /* Don't allow the audit containerid to be unset */ > + if (!audit_contid_valid(contid)) > + rc = -EINVAL; > + /* if we don't have caps, reject */ > + else if (!capable(CAP_AUDIT_CONTROL)) > + rc = -EPERM; > + /* if task has children or is not single-threaded, deny */ > + else if (!list_empty(&task->children)) > + rc = -EBUSY; > + else if (!(thread_group_leader(task) && thread_group_empty(task))) > + rc = -EALREADY; [NOTE: there is a bigger issue below which I think is going to require a respin/fixup of this patch so I'm going to take the opportunity to do a bit more bikeshedding ;)] It seems like we could combine both the thread/children checks under a single -EBUSY return value. In both cases the caller should be able to determine if the target process is multi-threaded for has spawned children, yes? FWIW, my motivation for this question is that -EALREADY seems like a poor choice here. > + /* if contid is already set, deny */ > + else if (audit_contid_set(task)) > + rc = -ECHILD; Does -EEXIST make more sense here? > + read_unlock(&tasklist_lock); > + if (!rc) > + task->audit->contid = contid; > + task_unlock(task); > + > + if (!audit_enabled) > + return rc; > + > + ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_CONTAINER_OP); > + if (!ab) > + return rc; > + > + audit_log_format(ab, > + "op=set opid=%d contid=%llu old-contid=%llu", > + task_tgid_nr(task), contid, oldcontid); > + audit_log_end(ab); Assuming audit is enabled we always emit the record above, even if we were not actually able to set the Audit Container ID (ACID); this seems wrong to me. I think the proper behavior would be to either add a "res=" field to indicate success/failure or only emit the record when we actually change a task's ACID. Considering the impact that the ACID value will potentially have on the audit stream, it seems like always logging the record and including a "res=" field may be the safer choice. > + return rc; > +} > + > /** > * audit_log_end - end one audit record > * @ab: the audit_buffer -- paul moore www.paul-moore.com