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=-7.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 0B550C433E0 for ; Fri, 7 Aug 2020 00:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF76C20855 for ; Fri, 7 Aug 2020 00:21:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HUOOHTOj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726130AbgHGAV6 (ORCPT ); Thu, 6 Aug 2020 20:21:58 -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-Google-Smtp-Source: ABdhPJw7IlNrHiAatjwRzejW/qFOf8CuU+9oSt2zFkMHfDTIOYGDDIS1MZzK2AFyXhM1SERMQ4TPwB/50V0i6Q5JvOU= 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 >