Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp801059ybv; Wed, 5 Feb 2020 14:59:28 -0800 (PST) X-Google-Smtp-Source: APXvYqwNYDarYpEsKSOInc/gNGXQkibf0jaW0y7gjqvzIhwCudra/V6db+NDifSVlLUhSIJGpVym X-Received: by 2002:aca:f242:: with SMTP id q63mr4894470oih.72.1580943568326; Wed, 05 Feb 2020 14:59:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580943568; cv=none; d=google.com; s=arc-20160816; b=s6DHXds2lMJiG+tKbqsawppcKzkl7MWuAdl4jKM0h5Wie358K73q77BvXUw6562OO8 jAzfkwIJFy1LVFqsvGMRx9yREYtRuhu6x3u1FCROrMFEdFNVXH1IC8dIncausQ38Rr77 uf2NwYwq/GCQ3w1psnoDHSXCov9lYiYwluKlcyG7flpNhyqBlpNwzbtKBhxTBynm26eA WHgd7Zva02yVrdLvJ3Dplq89GfMh9V3t8D8ETNVGvsyRPLRc1d53r52bSbDHmzcFF3dD HoiRV9a5n0s2ubDAcWLKbjwMrLYHg83Tcx1Vpru3vOoNJ+qUn1nQBu4BATW16MDChVwl oXsw== 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=Amzhmy9xv9aiOonSPr+eThtNwsfLtl5zGLSppwlbgNs=; b=Sz4vQ9vauOosSm8UBBbmZW4iKy8r/1ySrQxvYOsgwQVVistHSmGxuNMb/aEkKccaaC /qg6fDyWqLymiQ8xaG6/594+KFFjVhRpbb7LgSw2pn2zw48sdi4xpfSpbkD3KGq9cnst EDpNvZ9oRiExF7HdeZYajlmR3/eal0lBlC3thsnr2EoSbAbw36LYc+w8VMbtRDojb4OO oDLqkTlFS3Wp1BoFUxXGND9gVJ9JqfNiOkLBEpTz2btknVICAawhnNhvbjU2TtY91hnb 9WVYc6KFt12HkQCN+ryKuDuKhJ9e24t2xzexwVv4q1UPG7ZcrdKBzIdKJ4nF3M+agA+/ bUJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=Rr3Zuwxj; 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 8si1065846oix.109.2020.02.05.14.59.16; Wed, 05 Feb 2020 14:59:28 -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=Rr3Zuwxj; 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 S1727815AbgBEW5D (ORCPT + 99 others); Wed, 5 Feb 2020 17:57:03 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:37913 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727798AbgBEW5C (ORCPT ); Wed, 5 Feb 2020 17:57:02 -0500 Received: by mail-ed1-f66.google.com with SMTP id p23so3870764edr.5 for ; Wed, 05 Feb 2020 14:56:59 -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=Amzhmy9xv9aiOonSPr+eThtNwsfLtl5zGLSppwlbgNs=; b=Rr3ZuwxjBG88ry1cXtNHdnsHK7RNLh2i2hW7ZcjXrXXVz1dH4kyMtKdSaBC1CgHQur rCvuy3O+y+wkmSkopUyOF1OMDhD5Hx2sYMQ0meeghuuW5a+Zn08zQjCRISQh9rPkNdLI 59Z8ME76zI91V5UP7hugC1xMeu73AOuDGvfa7wKGNTbTsSdGgEMMiHozgfut4YcVzURe G2c9J84y+lzCAe08WlYOCgBuodxP7gxMj+eT09LfB5r+cyv9tJ1KYWxRm+MN59LjZBco Q6x5NKczijf5H13m8eUXysrheth2N8SEecoHY/HTzEDU+eOsPj0dHABPnKvVDueKZ0ND s2Eg== 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=Amzhmy9xv9aiOonSPr+eThtNwsfLtl5zGLSppwlbgNs=; b=BDEi8bI76MgH7DoX6DEHAgOU+9NqcXm659x4s2epLMtC04v4uGujJDuvZq6dN7a87B LkYxMKGfLo88gVNmq1FryeLjohMxDugRXSwlqdmt1RjnM87odjnLlCPjYUvy7plBsn+h A/6+v68KeZCm3qXR8AzHRAhE/O5sbDkUBBQSp5kH7g/xHvjAm5HvUpCTxOqb5AxQYMq7 kWXLwuvTEfD+XYTaR9imHSrgnY7/zdUdfC/MtLxBLTCNvQbF2Vn60Unw8u1A+G1tCx/j pwsPBTiW/2CwWoQXi0qhgkQla4Lc6dzYQy6pGn0yXEesTtgGHPirOaX6KujbMkz46yuH Er8w== X-Gm-Message-State: APjAAAW2Aj62/5Y9jaJXzlF93c9ycSgJgQApmZxPnJ37fKdAXABz0AwV z3RbQt4ejuxMSC0ZE0dVaoz8HUvEPwS/wWHRc8/R X-Received: by 2002:a17:906:19d0:: with SMTP id h16mr350075ejd.70.1580943419104; Wed, 05 Feb 2020 14:56:59 -0800 (PST) MIME-Version: 1.0 References: <5941671b6b6b5de28ab2cc80e72f288cf83291d5.1577736799.git.rgb@redhat.com> <20200205003930.2efpm4tvrisgmj4t@madcap2.tricolour.ca> In-Reply-To: <20200205003930.2efpm4tvrisgmj4t@madcap2.tricolour.ca> From: Paul Moore Date: Wed, 5 Feb 2020 17:56:48 -0500 Message-ID: Subject: Re: [PATCH ghak90 V8 16/16] audit: add capcontid to set contid outside init_user_ns 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, Feb 4, 2020 at 7:39 PM Richard Guy Briggs wrote: > On 2020-01-22 16:29, Paul Moore wrote: > > On Tue, Dec 31, 2019 at 2:51 PM Richard Guy Briggs wrote: > > > > > > Provide a mechanism similar to CAP_AUDIT_CONTROL to explicitly give a > > > process in a non-init user namespace the capability to set audit > > > container identifiers. > > > > > > Provide /proc/$PID/audit_capcontid interface to capcontid. > > > Valid values are: 1==enabled, 0==disabled > > > > It would be good to be more explicit about "enabled" and "disabled" in > > the commit description. For example, which setting allows the target > > task to set audit container IDs of it's children processes? > > Ok... > > > > Report this action in message type AUDIT_SET_CAPCONTID 1022 with fields > > > opid= capcontid= old-capcontid= > > > > > > Signed-off-by: Richard Guy Briggs > > > --- > > > fs/proc/base.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ > > > include/linux/audit.h | 14 ++++++++++++ > > > include/uapi/linux/audit.h | 1 + > > > kernel/audit.c | 35 +++++++++++++++++++++++++++++ > > > 4 files changed, 105 insertions(+) ... > > > diff --git a/kernel/audit.c b/kernel/audit.c > > > index 1287f0b63757..1c22dd084ae8 100644 > > > --- a/kernel/audit.c > > > +++ b/kernel/audit.c > > > @@ -2698,6 +2698,41 @@ static bool audit_contid_isowner(struct task_struct *tsk) > > > return false; > > > } > > > > > > +int audit_set_capcontid(struct task_struct *task, u32 enable) > > > +{ > > > + u32 oldcapcontid; > > > + int rc = 0; > > > + struct audit_buffer *ab; > > > + > > > + if (!task->audit) > > > + return -ENOPROTOOPT; > > > + oldcapcontid = audit_get_capcontid(task); > > > + /* if task is not descendant, block */ > > > + if (task == current) > > > + rc = -EBADSLT; > > > + else if (!task_is_descendant(current, task)) > > > + rc = -EXDEV; > > > > See my previous comments about error code sanity. > > I'll go with EXDEV. > > > > + else if (current_user_ns() == &init_user_ns) { > > > + if (!capable(CAP_AUDIT_CONTROL) && !audit_get_capcontid(current)) > > > + rc = -EPERM; > > > > I think we just want to use ns_capable() in the context of the current > > userns to check CAP_AUDIT_CONTROL, yes? Something like this ... > > I thought we had firmly established in previous discussion that > CAP_AUDIT_CONTROL in anything other than init_user_ns was completely irrelevant > and untrustable. In the case of a container with multiple users, and multiple applications, one being a nested orchestrator, it seems relevant to allow that container to control which of it's processes are able to exercise CAP_AUDIT_CONTROL. Granted, we still want to control it within the overall host, e.g. the container in question must be allowed to run a nested orchestrator, but allowing the container itself to provide it's own granularity seems like the right thing to do. > > if (current_user_ns() != &init_user_ns) { > > if (!ns_capable(CAP_AUDIT_CONTROL) || !audit_get_capcontid()) > > rc = -EPERM; > > } else if (!capable(CAP_AUDIT_CONTROL)) > > rc = -EPERM; > > -- paul moore www.paul-moore.com