Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp495443pxa; Fri, 21 Aug 2020 12:38:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5O9RSAzU3S+E8rEHTO0jHIxJ5vlqgpCSuB9tbBBOm/kflV4Tvjz6MteuJvRfRBAb/Hpl0 X-Received: by 2002:a17:906:454f:: with SMTP id s15mr4227856ejq.130.1598038696599; Fri, 21 Aug 2020 12:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598038696; cv=none; d=google.com; s=arc-20160816; b=nA2olSsl9LLcTaK+ly7raFMB9jiVC4qigfl1dnJVDRX8/bLRm6TNwOE9BVjDU1raxk qcvXSG19oI4aR9kTKHN2IJ3v4alXpes6gU1sOuklXzZESmcso4Gy9qZWEw80coA3BjHa m9j3JxXsI8XDMSwck9tkVCXaNerU1U1s72FGOx1OfAjqxPJCdxnxdaaxFNi7Mncw4RoD UKF4i/XGn/PSOuLnr3Twk8syHoLnm3G6Ftyji3XF24mQLS5DJeGfx7FiXwluMG62M4JC vdvqXOqnzC8uytVYihg8fli6WUfWXGvPf5Vsly9hNqBVh08GlWmNWDHhsm3awpsKknTO sJNg== 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=jQURKxDjRWMiMTxRUVV2iQZ2ZeobDW7AH50DwoJj7f8=; b=WfgjKu9XkS0i08u1dfKDFROsWLda2n2TU83xd7pthG0wEbQktQH3JmVjFlvRzaxCKw 4+BRIXH1wF5A5kUPdUy44D9LI0jbJQIZqO48BKZeq0oNeTEgrZmBA2BgA8BqdE9iNqzT 7C30tOBxzM7MyWaUCBVVEFnrlWUczN6JRrCi4sGW0VOT5J40vJo8niXUzFQzvmXvqdYw G8ypG6jooWiiD1Y1vquYKyp22Ufayzk6jVAaxqDdP5MbOFzbPjEH6qaBQxo5ZyVx8WF2 geXiK0kLHzmige9QvBrgSn2COS/PTUnDEIMQUNATfwNJXdu9rNdh3E40CJZ/CAndGDc7 67DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=sD6uHtx5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si1801724edq.44.2020.08.21.12.37.52; Fri, 21 Aug 2020 12:38:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=sD6uHtx5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbgHUThH (ORCPT + 99 others); Fri, 21 Aug 2020 15:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726431AbgHUThE (ORCPT ); Fri, 21 Aug 2020 15:37:04 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2958DC061755 for ; Fri, 21 Aug 2020 12:37:04 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id qc22so3689210ejb.4 for ; Fri, 21 Aug 2020 12:37:03 -0700 (PDT) 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=jQURKxDjRWMiMTxRUVV2iQZ2ZeobDW7AH50DwoJj7f8=; b=sD6uHtx5WmZbLrlelrAxJJlU8yrwBa7XdhUItXD/MUiuplcXnFHNbs0uCDwUQgzFtN jurCNLEA/E4vr3a4yeIje3FqyDQI8sRF2c9YCo0QgyXFJuEqVPmkW2lS0/NsyrCgrxja tHGI+6w07Ab8+AjC5II2mNiy2hdZ+3qmZyA6KHRLmlNmhG0wcFb6d/3S35p6poEvsoRd vlwL/zS/4H3Jx2D9+lvUJjrS4TpaS1QO3eL2d4amih7Ujdzt9QbFU97rAayMqUXL50px JXF3OtgHHiAAnV5emKHZq4o9IjgjW6eSdpoPKf4Z/6Md2pN6nt5uPCWgvaPZOR/vzBsW mzSw== 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=jQURKxDjRWMiMTxRUVV2iQZ2ZeobDW7AH50DwoJj7f8=; b=McjT6N5kVUtvA4qqGtU7M/zb3BUN6xdQQfYzhIdKM8pEGNsD+xdXG0wVMaEWcuuJc3 OGj33BZbXK10DgoYRGhx4dBvrfNtLVsaU09jmbA1VeBZP6SgjQhkHR6w64s/VXmPpvzW vW90EFRTD71KwouPpiu7gzYRMHLseisC7eqC2z0vysDB5EwQlnlwKY+zQmLopuzNYr+n JjVJnk4xAIwtiEDx01mnLYHKAwn6Fhi9Lr213wyoaaY+45XVJKZZwv74U98FZuJm9Bx1 UJHupFeORL7i5cXP3N8zQwlUrxm2WxWsJ+LYWVYrpLesO1eBKsuV3A1kbh1HQX+kSCcV iiow== X-Gm-Message-State: AOAM5328cvUP01agvfhuQiXVUErb2g8cYx2qrpI+ZKcVNkwHoh613aQr wKPoI2cVGACqk1f2If6ruuTo4Bf8F36FxrGEK61d X-Received: by 2002:a17:906:43c9:: with SMTP id j9mr4383574ejn.542.1598038620869; Fri, 21 Aug 2020 12:37:00 -0700 (PDT) MIME-Version: 1.0 References: <20200729200545.5apwc7fashwsnglj@madcap2.tricolour.ca> In-Reply-To: <20200729200545.5apwc7fashwsnglj@madcap2.tricolour.ca> From: Paul Moore Date: Fri, 21 Aug 2020 15:36:49 -0400 Message-ID: Subject: Re: [PATCH ghak90 V9 02/13] 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, Ondrej Mosnacek , 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 Wed, Jul 29, 2020 at 4:06 PM Richard Guy Briggs wrote: > On 2020-07-05 11:09, Paul Moore wrote: > > On Sat, Jun 27, 2020 at 9:22 AM Richard Guy Briggs wrote: ... > > > @@ -212,6 +219,33 @@ void __init audit_task_init(void) > > > 0, SLAB_PANIC, NULL); > > > } > > > > > > +/* rcu_read_lock must be held by caller unless new */ > > > +static struct audit_contobj *_audit_contobj_hold(struct audit_contobj *cont) > > > +{ > > > + if (cont) > > > + refcount_inc(&cont->refcount); > > > + return cont; > > > +} > > > + > > > +static struct audit_contobj *_audit_contobj_get(struct task_struct *tsk) > > > +{ > > > + if (!tsk->audit) > > > + return NULL; > > > + return _audit_contobj_hold(tsk->audit->cont); > > > +} > > > + > > > +/* rcu_read_lock must be held by caller */ > > > +static void _audit_contobj_put(struct audit_contobj *cont) > > > +{ > > > + if (!cont) > > > + return; > > > + if (refcount_dec_and_test(&cont->refcount)) { > > > + put_task_struct(cont->owner); > > > + list_del_rcu(&cont->list); > > > > You should check your locking; I'm used to seeing exclusive locks > > (e.g. the spinlock) around list adds/removes, it just reads/traversals > > that can be done with just the RCU lock held. > > Ok, I've redone the locking yet again. I knew this on one level but > that didn't translate consistently to code... > > > > + kfree_rcu(cont, rcu); > > > + } > > > +} > > > > Another nitpick, but it might be nice to have similar arguments to the > > _get() and _put() functions, e.g. struct audit_contobj, but that is > > some serious bikeshedding (basically rename _hold() to _get() and > > rename _hold to audit_task_contid_hold() or similar). > > I have some idea what you are trying to say, but I think you misspoke. > Did you mean rename _hold to _get, rename _get to > audit_task_contobj_hold()? It reads okay to me, but I know what I'm intending here :) I agree it could be a bit confusing. Let me try to put my suggestion into some quick pseudo-code function prototypes to make things a bit more concrete. The _audit_contobj_hold() function would become: struct audit_contobj *_audit_contobj_hold(struct task_struct *tsk); The _audit_contobj_get() function would become: struct audit_contobj *_audit_contobj_get(struct audit_contobj *cont); The _audit_contobj_put() function would become: void _audit_contobj_put(struct audit_contobj *cont); Basically swap the _get() and _hold() function names so that the arguments are the same for both the _get() and _set() functions. Does this make more sense? > > > /** > > > * audit_alloc - allocate an audit info block for a task > > > * @tsk: task > > > @@ -232,6 +266,9 @@ int audit_alloc(struct task_struct *tsk) > > > } > > > info->loginuid = audit_get_loginuid(current); > > > info->sessionid = audit_get_sessionid(current); > > > + rcu_read_lock(); > > > + info->cont = _audit_contobj_get(current); > > > + rcu_read_unlock(); > > > > The RCU locks aren't strictly necessary here, are they? In fact I > > suppose we could probably just replace the _get() call with a > > refcount_set(1) just as we do in audit_set_contid(), yes? > > I don't understand what you are getting at here. It needs a *contobj, > along with bumping up the refcount of the existing contobj. Sorry, you can disregard. My mental definition for audit_alloc() is permanently messed up; I usually double check myself before commenting on related code, but I must have forgotten here. -- paul moore www.paul-moore.com