From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04670C3F68F for ; Thu, 13 Feb 2020 21:49:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1A37217BA for ; Thu, 13 Feb 2020 21:49:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore-com.20150623.gappssmtp.com header.i=@paul-moore-com.20150623.gappssmtp.com header.b="FqFjEPBA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbgBMVtv (ORCPT ); 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-Google-Smtp-Source: APXvYqzSQm4JJnSM2NwbsgUln1Ol3jVku13aQhiI2KX5XKlMiqINrDBjs9ZRBvvzwBRwGvS0GSsKMYn/KfzBkhIn7o0= 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