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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 8F499C4363A for ; Thu, 29 Oct 2020 01:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2501020725 for ; Thu, 29 Oct 2020 01:08:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BDrxX4f+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732084AbgJ2BHj (ORCPT ); Wed, 28 Oct 2020 21:07:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732285AbgJ2BGR (ORCPT ); Wed, 28 Oct 2020 21:06:17 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81242C0613CF for ; Wed, 28 Oct 2020 18:06:16 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id a7so1164572lfk.9 for ; Wed, 28 Oct 2020 18:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=bUbdsznkyssxZQUaGiYFef8NyYzvzo9ihU0AaJ53g/g=; b=BDrxX4f+Wgvz7T2nQLENN+0irWwn/eNDmAKCTDCqH7wbKE23tfFJlUZmPAsdIVT6av 1Or1eDLwD4Ua1/VtLB9aLqgums1ThYkU6EoVz66waVy839CCdRQ4/jA5GhhAy7zJx4fP lIOBOse97g1uBe2mm7vsNQdWsRKzB5bSgNBV7JJSa9s1KuspQmNoz02kO+9neBnMrIfH 9p9f4n15YsHkpW5CrApshNR4MlYwwrAZ2bcyzIfJFWhzAWKQIqVwpqwuGuD0xVKFI8YG 73ZcamzLaX7g3KVQHvBjBMxnmz2K2Y3WZoOLFQ4cjIZQPuTwsIYEU7TMMrzclXdPmFDT MJYA== 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:content-transfer-encoding; bh=bUbdsznkyssxZQUaGiYFef8NyYzvzo9ihU0AaJ53g/g=; b=fgPVyWIJG4z3Vzde8OFPqh3GS7Aj8H7jngdvSgbQnhAN+wVDgU7zwphEqm9Zop7IrL 2TbThQ4yXVfAge8nwUUx7HQietvzjSx5FwkBhoTXypLyiV7HPCsQaZ7pU46rJJ/BJcJu vCUJwyUVEIG1lppW3fZElAiKqfAwQjag1bSegWYga23hhL4nJsTrog9nLtbV8ZSrq5+B Jn4YjxY2QebV4jHf/rxmwHusrZVqk251ewyyZltSGvW1EhT01mQLjSiLNRwo3dCLJzRK FTTlSNIKVs0cx5mHuVJJslOX98JxdMy6pfUmimnEPKj6T2D4cG9m7U652nFSafKm87Ek anqA== X-Gm-Message-State: AOAM530p+zDCFKzNr01B2FmmDbPq1QCUbDWu6RXTQZJVwTFTMgGUfrdl NoMErLu3uI8NDTcF/krJ62q8ho5mUZNcfsdQbWcNQQ== X-Google-Smtp-Source: ABdhPJzcgEeCZDlwnUhahSeOHzAbFOzhL6qDHJsbmuNSbxi7XgpEx/FS/YazDdtI2Qw49nUhEoyWwL1tVaMHgN9tVZA= X-Received: by 2002:a05:6512:1054:: with SMTP id c20mr662361lfb.576.1603933574802; Wed, 28 Oct 2020 18:06:14 -0700 (PDT) MIME-Version: 1.0 References: <20201027200358.557003-1-mic@digikod.net> <20201027200358.557003-2-mic@digikod.net> In-Reply-To: <20201027200358.557003-2-mic@digikod.net> From: Jann Horn Date: Thu, 29 Oct 2020 02:05:47 +0100 Message-ID: Subject: Re: [PATCH v22 01/12] landlock: Add object management To: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Cc: James Morris , "Serge E . Hallyn" , Al Viro , Andy Lutomirski , Anton Ivanov , Arnd Bergmann , Casey Schaufler , Jeff Dike , Jonathan Corbet , Kees Cook , Michael Kerrisk , Richard Weinberger , Shuah Khan , Vincent Dagonneau , Kernel Hardening , Linux API , linux-arch , "open list:DOCUMENTATION" , linux-fsdevel , kernel list , "open list:KERNEL SELFTEST FRAMEWORK" , linux-security-module , "the arch/x86 maintainers" , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Tue, Oct 27, 2020 at 9:04 PM Micka=C3=ABl Sala=C3=BCn = wrote: > A Landlock object enables to identify a kernel object (e.g. an inode). > A Landlock rule is a set of access rights allowed on an object. Rules > are grouped in rulesets that may be tied to a set of processes (i.e. > subjects) to enforce a scoped access-control (i.e. a domain). > > Because Landlock's goal is to empower any process (especially > unprivileged ones) to sandbox themselves, we cannot rely on a > system-wide object identification such as file extended attributes. > Indeed, we need innocuous, composable and modular access-controls. > > The main challenge with these constraints is to identify kernel objects > while this identification is useful (i.e. when a security policy makes > use of this object). But this identification data should be freed once > no policy is using it. This ephemeral tagging should not and may not be > written in the filesystem. We then need to manage the lifetime of a > rule according to the lifetime of its objects. To avoid a global lock, > this implementation make use of RCU and counters to safely reference > objects. > > A following commit uses this generic object management for inodes. > > Cc: James Morris > Cc: Jann Horn > Cc: Kees Cook > Cc: Serge E. Hallyn > Signed-off-by: Micka=C3=ABl Sala=C3=BCn Reviewed-by: Jann Horn except for some minor nits: [...] > diff --git a/security/landlock/object.c b/security/landlock/object.c [...] > +void landlock_put_object(struct landlock_object *const object) > +{ > + /* > + * The call to @object->underops->release(object) might sleep e.g= ., s/ e.g.,/, e.g./ > + * because of iput(). > + */ > + might_sleep(); > + if (!object) > + return; [...] > +} > diff --git a/security/landlock/object.h b/security/landlock/object.h [...] > +struct landlock_object { > + /** > + * @usage: This counter is used to tie an object to the rules mat= ching > + * it or to keep it alive while adding a new rule. If this count= er > + * reaches zero, this struct must not be modified, but this count= er can > + * still be read from within an RCU read-side critical section. = When > + * adding a new rule to an object with a usage counter of zero, w= e must > + * wait until the pointer to this object is set to NULL (or recyc= led). > + */ > + refcount_t usage; > + /** > + * @lock: Guards against concurrent modifications. This lock mus= t be s/must be/must be held/ ? > + * from the time @usage drops to zero until any weak references f= rom > + * @underobj to this object have been cleaned up. > + * > + * Lock ordering: inode->i_lock nests inside this. > + */ > + spinlock_t lock; [...] > +}; > + > +struct landlock_object *landlock_create_object( > + const struct landlock_object_underops *const underops, > + void *const underojb); nit: "underobj"