Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1506826ybh; Thu, 16 Jul 2020 14:16:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFcUufoFacnIyZuIVop+XtzJQHIvLluy9BzU9dbex13SEO4S7lXGdgkeoXnH6bOpMKvUZ+ X-Received: by 2002:a17:906:e294:: with SMTP id gg20mr5384488ejb.521.1594934203317; Thu, 16 Jul 2020 14:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594934203; cv=none; d=google.com; s=arc-20160816; b=OFJc3nXa1o9d5BsfI7ez/weUJtwNHVAfOPEqahdve+pE06iuwaVixAAxJZH2QSPHQl n6p5uFiaS7Ybg9obCJ8C+YQFQoMowCSEVxp6RO5gGKucVJMdFzam9I6vKPdy1PWzaQ7y rldQM4eOY3CFZ2NjmpfgqOPm5k7bH/93AFg3H9tlzR7yNeraId3KmNAvC+5wMBbh9Bdf 15kILUfKNXkGZXUKCS8Az57bA8hr6HvqBzK61zpdGAHYF26e0F2QXNzZPQstG0O6uHK9 O8Gy7PRwY2bPsDYEZJ8GZj9sQjJowphSI2zEk1duWBIyQqBLd/Q8XpH+Ic4P55iCGmsx o9mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lmZBQbjqMeBLnSI9FVD3UqngzNA1tgpRunHRVfsAN4E=; b=fM0nd6aU701pffAPgRyx97/psepFieYKEdwGBaBJAwIoT+5PG1x/5eiKEExaJu3TmG soxQCyQaiP2bVG23qrBjhIKKdJEDigZzBkzDRggiivNKcKEHITRu/fbnkPlrYkgn0KGS fvyAKtEYJB8H+dZefMrD+SnXd43uYLedRx16ZeG08u+BaZIBor0H0EjJQGjRZ9LxW8Xh 7BTCQyt252rrHKx/MGIPXbncwdM7X+AdZxWSgvGfBVuVs2X+AZcU+LT0d0Qv/J1OQvfw 2edFhbfy9tuuoM9LcrF73QJlG9lFb6XVg314C0myBSBO0hhh2IKdZ9JEoTNKDJn5ijV0 IAvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jrlSSu3d; 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 i16si3876189eds.541.2020.07.16.14.16.19; Thu, 16 Jul 2020 14:16:43 -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=jrlSSu3d; 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 S1726846AbgGPVQN (ORCPT + 99 others); Thu, 16 Jul 2020 17:16:13 -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-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