Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1821764pxa; Thu, 6 Aug 2020 17:23:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxZFtRBLqn55MuFIvOBy4GD4AcNedoorH335tcc1zy6jI6WIDec3NqqaZFSuVKfYoPHk2Y X-Received: by 2002:a17:906:9618:: with SMTP id s24mr6885622ejx.53.1596759786318; Thu, 06 Aug 2020 17:23:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596759786; cv=none; d=google.com; s=arc-20160816; b=kOjao4qStl5loe5JBpD7l0IJArp4viyBMYjAIve+hG69SM/J2UiPnhDb2Sy819E7ED N+/CsHXh4Cwb4Effv6B26da24f5yzXy9Xyu+xLctxxNdt/13iwgVAHUeKNXESJvPiemw sUiA+2T60XukfzLQygOhhuMHZ6peBB9sj6NWxP2RJ7p9ybnOLrCgIZTVVlLpYij684P5 GSOudNAgyiC4gCszzAxXaqQtKHxCAnXsREAzmXXe8lPLzu6nP2tiMGP6nExjZLUaIKUI T886Q+k6Y7hIw4iqGhAuSYlYn1q1PwYH0Twj1dXykpi9MeBScfOKE7GgLnKufr/v+Q+p +5fg== 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=vwItUOgNx85u5QZIQ4VOjuZBdBEzAvdaCSETt8ahY3s=; b=RilIZZiOHNfk3IgPoMU7U7isLi/sY8ieboWNYjoH6s2nxsTxruy9wTWW3QBb7QNZ+a dN7bbUspccs424WdNyYyGZ0l2ZdRvCEzKC9BirOZTGEcJS2iw9TXQuPgYgZQd4PRI56S rNdIuGhwcLqPHe08KLhNKK59HKhO3sZjOEFlymRsr/43f7glmleu6LPuPfNBOnE622En g0WVx0LqHhaccIghCdmfl9zNAHYEQYvdpZTRSaJVwBKq0P3zejPLBkBQmSnCUFS8kFoW oWe8t891PZu1qOkxBXlTwOpXFvAYawRASoCDNR1a84rTP6b7nrZcyQDGHNu5bLpfFy/8 A6uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HUOOHTOj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm22si5198243ejc.191.2020.08.06.17.22.43; Thu, 06 Aug 2020 17:23:06 -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=@chromium.org header.s=google header.b=HUOOHTOj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726038AbgHGAV5 (ORCPT + 99 others); Thu, 6 Aug 2020 20:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726013AbgHGAVz (ORCPT ); Thu, 6 Aug 2020 20:21:55 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47957C06179E for ; Thu, 6 Aug 2020 17:21:55 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id f12so58360wru.13 for ; Thu, 06 Aug 2020 17:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vwItUOgNx85u5QZIQ4VOjuZBdBEzAvdaCSETt8ahY3s=; b=HUOOHTOjhFobum7n1FxSPal+6xOFjFHJ4KdS0H7W+nYIGtMNvuG6RtAWDbvRfRi0ON r3p8PkAPyykbju/M9pM+mqVPbykuZJ+c7T/2w1wt9VITrSqfM2RqDOqn7cXXRLbp3kK/ xaxlqE39pxK4B109IawxwyTE8wJHK7VJ9zpH4= 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=vwItUOgNx85u5QZIQ4VOjuZBdBEzAvdaCSETt8ahY3s=; b=PQdw8GwN2i5RwKUiGIAFxQHa+DTNJJq83GAJ2XTS1I7wcWBNfty2r/zPPJi8SeCU6v L0uNAG0o58HWMVyzlFZbLRaLSWVOrlXlvVurlv5P3y1fkZIfFXqh3FdAZIffBjI51OvP JhxPV0tzHJOkDtxwCe6pxIiVcA4n91aejCyF78XK4MBGpO5ICPFBLsNM7JEBSfX3KLSi h5SDTFQN/KizSKO2eWNRACBth5UXJyZDsEmCK2Mfmdf/6D2ulc43ZlG4lx3/EGFyOl0f H6ZSvz6p2C7xN16mH+4S6+V+jFeJ8tMxARB8rcRXVCKwqL5PWp3rtv4818CLOOfLjwHN M94Q== X-Gm-Message-State: AOAM533I5vWDHFLJMOCHwpTwaf0j0yOZRtNtBvf6PhBaLgFP2L5OlRX5 K8W1AffNW8WVmnxrZ39leb5IVgYC7c9oyWjHey//Tw== X-Received: by 2002:adf:efce:: with SMTP id i14mr9666726wrp.359.1596759713673; Thu, 06 Aug 2020 17:21:53 -0700 (PDT) MIME-Version: 1.0 References: <20200729175845.1745471-1-keescook@chromium.org> <20200729175845.1745471-10-keescook@chromium.org> In-Reply-To: <20200729175845.1745471-10-keescook@chromium.org> From: KP Singh Date: Fri, 7 Aug 2020 02:21:42 +0200 Message-ID: Subject: Re: [PATCH v4 09/17] LSM: Introduce kernel_post_load_data() hook To: Kees Cook Cc: Greg Kroah-Hartman , Scott Branden , Mimi Zohar , Luis Chamberlain , Takashi Iwai , Jessica Yu , SeongJae Park , linux-efi@vger.kernel.org, Linux Security Module list , linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, open list 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 7:59 PM Kees Cook wrote: > > There are a few places in the kernel where LSMs would like to have > visibility into the contents of a kernel buffer that has been loaded or > read. While security_kernel_post_read_file() (which includes the > buffer) exists as a pairing for security_kernel_read_file(), no such > hook exists to pair with security_kernel_load_data(). > > Earlier proposals for just using security_kernel_post_read_file() with a > NULL file argument were rejected (i.e. "file" should always be valid for > the security_..._file hooks, but it appears at least one case was > left in the kernel during earlier refactoring. (This will be fixed in > a subsequent patch.) > > Since not all cases of security_kernel_load_data() can have a single > contiguous buffer made available to the LSM hook (e.g. kexec image > segments are separately loaded), there needs to be a way for the LSM to > reason about its expectations of the hook coverage. In order to handle > this, add a "contents" argument to the "kernel_load_data" hook that > indicates if the newly added "kernel_post_load_data" hook will be called > with the full contents once loaded. That way, LSMs requiring full contents > can choose to unilaterally reject "kernel_load_data" with contents=false > (which is effectively the existing hook coverage), but when contents=true > they can allow it and later evaluate the "kernel_post_load_data" hook > once the buffer is loaded. > > With this change, LSMs can gain coverage over non-file-backed data loads > (e.g. init_module(2) and firmware userspace helper), which will happen > in subsequent patches. > > Additionally prepare IMA to start processing these cases. > > Signed-off-by: Kees Cook Thanks for adding this! Would be really useful for us. Reviewed-by: KP Singh > --- > drivers/base/firmware_loader/fallback.c | 2 +- [...] > index 5de45010fb1a..1a5c68196faf 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -4019,7 +4019,7 @@ static int selinux_kernel_read_file(struct file *file, > return rc; > } > > -static int selinux_kernel_load_data(enum kernel_load_data_id id) > +static int selinux_kernel_load_data(enum kernel_load_data_id id, bool contents) > { > int rc = 0; > > -- > 2.25.1 >