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=-9.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS 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 9F212C433E5 for ; Thu, 16 Jul 2020 21:16:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 787C3207DD for ; Thu, 16 Jul 2020 21:16:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jrlSSu3d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726905AbgGPVQO (ORCPT ); Thu, 16 Jul 2020 17:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbgGPVQM (ORCPT ); Thu, 16 Jul 2020 17:16:12 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9BFFC08C5CE for ; Thu, 16 Jul 2020 14:16:11 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id p3so5502194pgh.3 for ; Thu, 16 Jul 2020 14:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=lmZBQbjqMeBLnSI9FVD3UqngzNA1tgpRunHRVfsAN4E=; b=jrlSSu3doUVtC/cF6fPEixkmZ7d3kTAXWl4iNsSM4I6YoEFL+12kpcB6R9QQdqWsrL tXF4IFkuk15RdtqH+h3KXuu4gjR6RZUWVUL2RXcBy7kHTyR41Iagp8SO/Nhhy6hRv9LC SJF0MSnv27iK1CLHjM8qOEZHVhyaIK8raTTYM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=lmZBQbjqMeBLnSI9FVD3UqngzNA1tgpRunHRVfsAN4E=; b=giULsej1ZGTdYzrPK1TKo7GZ+qwCVYj4ai9s2eRDDq71iM7KZ0yRk2N9mHfT+sf+vc 1CaK43R83QXw3e8RUkKSO9FKcddDBREGRUSg+H50S8m6NPgohq9m5c9rO3oj7gBifF/e 26pjZWZ1C9eLZvepWFxl//QpK5HS/r09DlZw0wNvZg2kgit5rytIhM8Jk3KqCMyAIKdF 5Z2k4miyaPzgmygcskmEI6MQOosDl/nQQPun3HZ7bUEu1RXX5/clcWdbVClStOm47OlW dTiKq4jG8hBEEgu0DZnTMbwmPBDAKKky5252dljM9s4FqHmdtpDdDBcX74BFG6GNy+cw wbxw== X-Gm-Message-State: AOAM533EYCBC13CmzXtjZsan9Ukm2W6yB3asAG4PNZBosaUNHqsFQmHa nHQyq85s7snO8+CETl5NjaQAzQ== X-Google-Smtp-Source: ABdhPJxx6Jf69e3T4HfcHOftkZ9Viu9RPr7fEyeFqrBzPYqKcb2Yk/GKdggH4BwCHYsK3kDOz6WVQw== X-Received: by 2002:a63:c947:: with SMTP id y7mr5734755pgg.357.1594934171026; Thu, 16 Jul 2020 14:16:11 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a30sm5752036pfr.87.2020.07.16.14.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 14:16:09 -0700 (PDT) Date: Thu, 16 Jul 2020 14:16:09 -0700 From: Kees Cook To: Scott Branden Cc: Matthew Wilcox , James Morris , Luis Chamberlain , Mimi Zohar , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro , Jessica Yu , Dmitry Kasatkin , "Serge E. Hallyn" , Casey Schaufler , "Eric W. Biederman" , Peter Zijlstra , Matthew Garrett , David Howells , Mauro Carvalho Chehab , Randy Dunlap , "Joel Fernandes (Google)" , KP Singh , Dave Olsthoorn , Hans de Goede , Peter Jones , Andrew Morton , Stephen Boyd , Paul Moore , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH 2/4] fs: Remove FIRMWARE_PREALLOC_BUFFER from kernel_read_file() enums Message-ID: <202007161415.10D015477@keescook> References: <20200707081926.3688096-1-keescook@chromium.org> <20200707081926.3688096-3-keescook@chromium.org> <3fdb3c53-7471-14d8-ce6a-251d8b660b8a@broadcom.com> <20200710220411.GR12769@casper.infradead.org> <128120ca-7465-e041-7481-4c5d53f639dd@broadcom.com> <202007101543.912633AA73@keescook> <9ba08503-e515-6761-63de-a3b611720b1b@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9ba08503-e515-6761-63de-a3b611720b1b@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 16, 2020 at 01:35:17PM -0700, Scott Branden wrote: > On 2020-07-10 3:44 p.m., Kees Cook wrote: > > On Fri, Jul 10, 2020 at 03:10:25PM -0700, Scott Branden wrote: > > > > > > On 2020-07-10 3:04 p.m., Matthew Wilcox wrote: > > > > On Fri, Jul 10, 2020 at 02:00:32PM -0700, Scott Branden wrote: > > > > > > @@ -950,8 +951,8 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size, > > > > > > goto out; > > > > > > } > > > > > > - if (id != READING_FIRMWARE_PREALLOC_BUFFER) > > > > > > - *buf = vmalloc(i_size); > > > > > > + if (!*buf) > > > > > The assumption that *buf is always NULL when id != > > > > > READING_FIRMWARE_PREALLOC_BUFFER doesn't appear to be correct. > > > > > I get unhandled page faults due to this change on boot. > > > > Did it give you a stack backtrace? > > > Yes, but there's no requirement that *buf need to be NULL when calling this > > > function. > > > To fix my particular crash I added the following locally: > > > > > > --- a/kernel/module.c > > > +++ b/kernel/module.c > > > @@ -3989,7 +3989,7 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char > > > __user *, uargs, int, flags) > > >  { > > >      struct load_info info = { }; > > >      loff_t size; > > > -    void *hdr; > > > +    void *hdr = NULL; > > >      int err; > > > > > >      err = may_init_module(); > > Thanks for the diagnosis and fix! I haven't had time to cycle back > > around to this series yet. Hopefully soon. :) > > > In order to assist in your patchset I have combined it with my patch series > here: > https://github.com/sbranden/linux/tree/kernel_read_file_for_kees > > Please let me know if this matches your expectations for my patches or if > there is something else I need to change. Thanks! I was working on the next revision of this last night, and I'm trying to get through today's email to finish it. I'll take a look! -- Kees Cook