Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1006281ybv; Thu, 13 Feb 2020 13:52:16 -0800 (PST) X-Google-Smtp-Source: APXvYqyrYTBvloSH96yaltDBt9GtTBd6YVDZd6o8aopo9e3vBKFm+czGzq7baUtMGQROyq6jxQ9X X-Received: by 2002:a05:6830:1050:: with SMTP id b16mr15200331otp.140.1581630736670; Thu, 13 Feb 2020 13:52:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581630736; cv=none; d=google.com; s=arc-20160816; b=vh7pdmyzjD62WxMXJ6D9tD5GAYBZiL5B5RcGTUQu4g86fqYZH+wrNsNz9NSPH3Xcqp E6YSGykfubHawPdrcSdLwxsMS4SlkQUxNLCk7Zk9HSl9GgGMtu6PhuvKlg42EG6YnaTE o7e349/VjJyHTbpj2skDYEkKHX7nyYbAWXfELq6blsf9SC1Jrs20tmC8T9LHqZBr2jly 2UDLyaVFzrF4P0Zsr7KippzcsLTd3n7Pl3ptTBL+dRJjubArRRpcdfkNi7DxFmwTem1N 5hpmvKBQ5la4h8V+GYCAXVYacG+bFg7ZzDTyb+ypeddMVqkDESJWnJVCvwp5/phmKleP xYXQ== 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=CIr8PnObM5ymwiwL1EiMYkctE0asXfoeHqvExzLeSc4=; b=WM3J6d++4zMFcDhrrm9ku1E7zD4QfwOZVZs1MBDU2/bsq3KCinkhhfIQiVPhRzOCi5 dWatrI1Ix/7l6BHi+rQiN+Bap/zLZvzXSfH6zf2zPoXXIIQGTaBhXvVTTgaPDAQG6wj5 3+2saN2b9G6yeotRnOyBu4C3lGjZdV7XjNVkcCTRftxwZ3oo6TkZXvwp2IWBi0rjW/e5 qNmsbD54xY+BuL+OCHq4BrhoEywDNhvm8zRMEzZtW3Bd1S4eK3dBC9aSi3KIxusOZSLs WjLEsD2AMUIkX+rU7NYIXDSN2h1Exlaf5ZxoZJTkM0Y5f1nWtaZ5xHHsuctMC9RTktPi XU1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=FqFjEPBA; 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 10si1668908ois.76.2020.02.13.13.52.04; Thu, 13 Feb 2020 13:52:16 -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=FqFjEPBA; 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 S1728650AbgBMVtv (ORCPT + 99 others); Thu, 13 Feb 2020 16:49:51 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:38544 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbgBMVtv (ORCPT ); Thu, 13 Feb 2020 16:49:51 -0500 Received: by mail-ed1-f68.google.com with SMTP id p23so8694989edr.5 for ; Thu, 13 Feb 2020 13:49:50 -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=CIr8PnObM5ymwiwL1EiMYkctE0asXfoeHqvExzLeSc4=; b=FqFjEPBAWPA+rQxGxDZQVc/+KDC775ecwL3/+FaBoa2038OKUe3oN6g8shGj/YRVtO kRm/wFg1uwYyzuvE14fQXQ/6hccJfwRgO3aVKboiJnszaYINoRpEp4EArtkScaku61pv QZ6TB6Ttwea8tpsUi/cKCopeKQgLK3GqQTdzhfnRTdTRXeGrihMjkHplbG+dbDWPPg8u EotRIFc6D/ah43gjEO73ItC+Y45grJMPIZ36X9aHuxaoapr80EM/gJKOUsD9kMnu1vJr YN+eSSyvvyTL2Fyf5YZg/7zFE2QFdGsBJ87am0k5EsyuLu8LGmzWJZqAFQG8z9n1hf0k nCnw== 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=CIr8PnObM5ymwiwL1EiMYkctE0asXfoeHqvExzLeSc4=; b=X8mtwc5g/qiJ7175KrMDo4vrGGQJH0lL4oWP6WQXEIV/kxS2alwYGGmWFv672bsAE4 YZfYnjcvIWJ24c6d7LN1zxq9c77lD20kqwajxLif1od68x8x8+dKuitBhcCCLH6thmf1 hgkgxMZ1dSvut6cNnfOiD5hYpbNSuYr7Ai8+3T3kp4BG6f4dKO9JhhlyNMtdPJc9pYb8 yNJ86/2xsxcA7byecCmoAyTR5rwXZYyHNpX5Ch57DfqKWmfbAsfojtNCXXL0kEohQEUd PmEFkG2zYJkM2w8FaB563H428fN3rG3NTnkKVDDkpTwumbgkRZRH+tZvqu4AqlhMbL6k Mwlg== X-Gm-Message-State: APjAAAVhrvsZn+G8Mw8veFp83yxemEPlF1i9vUW9XP+iDdkV1Ilgsvam Vgun/+xddfjcjW/cpDNt+/M2IG+HJ9XFvioKSx+w X-Received: by 2002:a17:906:9352:: with SMTP id p18mr17616846ejw.95.1581630589598; Thu, 13 Feb 2020 13:49:49 -0800 (PST) MIME-Version: 1.0 References: <6452955c1e038227a5cd169f689f3fd3db27513f.1577736799.git.rgb@redhat.com> <20200130192753.n7jjrshbhrczjzoe@madcap2.tricolour.ca> <20200205235056.e5365xtgz7rbese2@madcap2.tricolour.ca> In-Reply-To: <20200205235056.e5365xtgz7rbese2@madcap2.tricolour.ca> From: Paul Moore Date: Thu, 13 Feb 2020 16:49:38 -0500 Message-ID: Subject: Re: [PATCH ghak90 V8 13/16] audit: track container nesting To: Richard Guy Briggs Cc: nhorman@tuxdriver.com, linux-api@vger.kernel.org, containers@lists.linux-foundation.org, LKML , dhowells@redhat.com, Linux-Audit Mailing List , netfilter-devel@vger.kernel.org, ebiederm@xmission.com, simo@redhat.com, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, Eric Paris , mpatel@redhat.com, Serge Hallyn 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, Feb 5, 2020 at 6:51 PM Richard Guy Briggs wrote: > On 2020-02-05 18:05, Paul Moore wrote: > > On Thu, Jan 30, 2020 at 2:28 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: > > > > > > > > > > Track the parent container of a container to be able to filter and > > > > > report nesting. > > > > > > > > > > Now that we have a way to track and check the parent container of a > > > > > container, modify the contid field format to be able to report that > > > > > nesting using a carrat ("^") separator to indicate nesting. The > > > > > original field format was "contid=" for task-associated records > > > > > and "contid=[,[...]]" for network-namespace-associated > > > > > records. The new field format is > > > > > "contid=[^[...]][,[...]]". > > > > > > > > Let's make sure we always use a comma as a separator, even when > > > > recording the parent information, for example: > > > > "contid=[,^[...]][,[...]]" > > > > > > The intent here is to clearly indicate and separate nesting from > > > parallel use of several containers by one netns. If we do away with > > > that distinction, then we lose that inheritance accountability and > > > should really run the list through a "uniq" function to remove the > > > produced redundancies. This clear inheritance is something Steve was > > > looking for since tracking down individual events/records to show that > > > inheritance was not aways feasible due to rolled logs or search effort. > > > > Perhaps my example wasn't clear. I'm not opposed to the little > > carat/hat character indicating a container's parent, I just think it > > would be good to also include a comma *in*addition* to the carat/hat. > > Ah, ok. Well, I'd offer that it would be slightly shorter, slightly > less cluttered and having already written the parser in userspace, I > think the parser would be slightly simpler. > > I must admit, I was a bit puzzled by your snippet of code that was used > as a prefix to the next item rather than as a postfix to the given item. > > Can you say why you prefer the comma in addition? Generally speaking, I believe that a single delimiter is both easier for the eyes to parse, and easier/safer for machines to parse as well. In this particular case I think of the comma as a delimiter and the carat as a modifier, reusing the carat as a delimiter seems like a bad idea to me. > > > > > diff --git a/kernel/audit.c b/kernel/audit.c > > > > > index ef8e07524c46..68be59d1a89b 100644 > > > > > --- a/kernel/audit.c > > > > > +++ b/kernel/audit.c > > > > > > > > > @@ -492,6 +493,7 @@ void audit_switch_task_namespaces(struct nsproxy *ns, struct task_struct *p) > > > > > audit_netns_contid_add(new->net_ns, contid); > > > > > } > > > > > > > > > > +void audit_log_contid(struct audit_buffer *ab, u64 contid); > > > > > > > > If we need a forward declaration, might as well just move it up near > > > > the top of the file with the rest of the declarations. > > > > > > Ok. > > > > > > > > +void audit_log_contid(struct audit_buffer *ab, u64 contid) > > > > > +{ > > > > > + struct audit_contobj *cont = NULL, *prcont = NULL; > > > > > + int h; > > > > > > > > It seems safer to pass the audit container ID object and not the u64. > > > > > > It would also be faster, but in some places it isn't available such as > > > for ptrace and signal targets. This also links back to the drop record > > > refcounts to hold onto the contobj until process exit, or signal > > > delivery. > > > > > > What we could do is to supply two potential parameters, a contobj and/or > > > a contid, and have it use the contobj if it is valid, otherwise, use the > > > contid, as is done for names and paths supplied to audit_log_name(). > > > > Let's not do multiple parameters, that begs for misuse, let's take the > > wrapper function route: > > > > func a(int id) { > > // important stuff > > } > > > > func ao(struct obj) { > > a(obj.id); > > } > > > > ... and we can add a comment that you *really* should be using the > > variant that passes an object. > > I was already doing that where it available, and dereferencing the id > for the call. But I see an advantage to having both parameters supplied > to the function, since it saves us the trouble of dereferencing it, > searching for the id in the hash list and re-locating the object if the > object is already available. I strongly prefer we not do multiple parameters for the same "thing"; I would much rather do the wrapper approach as described above. I would also like to see us use the audit container ID object as much as possible, using a bare integer should be a last resort. -- paul moore www.paul-moore.com