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=-5.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 15B19C10DCE for ; Fri, 13 Mar 2020 00:57:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E215C206EB for ; Fri, 13 Mar 2020 00:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584061038; bh=lHsdMINLLczd7WRRMfdpTyi3bseSfwCftr2S7lte/oE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=Q9KzprI8F7yutKR/QVWq2T5WtxQpFUjE1H98HmKiNeYskPloQK+KjFXR+ARee8F8n vHIHZfKjdl/cxWU3CYAYUk8R5lutNPWNadnX2tlB3MKWg7bqlOIUePCSGEXJgqkAcT xx/o+hX22k+N7bqHfEkEm6j1F307ePKcCA+mQPoI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726877AbgCMA5O (ORCPT ); Thu, 12 Mar 2020 20:57:14 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:52482 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726620AbgCMA5N (ORCPT ); Thu, 12 Mar 2020 20:57:13 -0400 Received: by mail-pj1-f66.google.com with SMTP id f15so3273150pjq.2; Thu, 12 Mar 2020 17:57:13 -0700 (PDT) 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:in-reply-to:user-agent; bh=JYErxPxUaGUBplLH65PeMy/hBKN4L+ixr3Dg3MVBjtY=; b=qaHP9ogT8oLWmwccMZEGLlbI9D/F1DKloHtOY31zjA0L3EH1WcmXf9E1jpHkguu98U 8q05vMJC0B3v3dzdE+3ThU1qLnI2QdgeWldMTZgrfQdGO1J0LiPSR/ZrDEzKSNk3w45K 7MitT3y0tbKs11M6DlYJLs+Q8xsskBT09fXhErLJkRGv1EA4/pSkHU5AqOaXkoDQp4RY AkLYFeGIAkAO/jiapANF12OKc5sn3qXKBu067kVqjMcZ28rGEx0vCVyF7s2HCrO34E0K yZ4Q8KeqvN1ZcugDk8oxBgDiVhkZG83MOpBw80rKhGKUd4Gepo384WZApKuqEsYvfIQ9 CbqQ== X-Gm-Message-State: ANhLgQ33LKari1ageN6/hB2JrWuxXwTN7HweA/C13KvXFbe/TICfBfvz ZXG/conHTj8WDqNkg+ESWlc= X-Google-Smtp-Source: ADFU+vtVU3sloKfNJ/GHy6v7uSunVn8TinhhgU2e25piz35fqisnm35446HRFefBgI5y9Gx35kOMPg== X-Received: by 2002:a17:902:be08:: with SMTP id r8mr10871611pls.321.1584061032688; Thu, 12 Mar 2020 17:57:12 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id y7sm16017401pfq.159.2020.03.12.17.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 17:57:11 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id A6ED24028E; Fri, 13 Mar 2020 00:57:10 +0000 (UTC) Date: Fri, 13 Mar 2020 00:57:10 +0000 From: Luis Chamberlain To: Eric Biggers Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexei Starovoitov , Andrew Morton , Greg Kroah-Hartman , Jeff Vander Stoep , Jessica Yu , Kees Cook , NeilBrown , stable@vger.kernel.org Subject: Re: [PATCH v2 1/4] kmod: make request_module() return an error when autoloading is disabled Message-ID: <20200313005710.GQ11244@42.do-not-panic.com> References: <20200312202552.241885-1-ebiggers@kernel.org> <20200312202552.241885-2-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200312202552.241885-2-ebiggers@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu, Mar 12, 2020 at 01:25:49PM -0700, Eric Biggers wrote: > From: Eric Biggers > > It's long been possible to disable kernel module autoloading completely > (while still allowing manual module insertion) by setting > /proc/sys/kernel/modprobe to the empty string. This can be preferable > to setting it to a nonexistent file since it avoids the overhead of an > attempted execve(), avoids potential deadlocks, and avoids the call to > security_kernel_module_request() and thus on SELinux-based systems > eliminates the need to write SELinux rules to dontaudit module_request. > > However, when module autoloading is disabled in this way, > request_module() returns 0. This is broken because callers expect 0 to > mean that the module was successfully loaded. > > Apparently this was never noticed because this method of disabling > module autoloading isn't used much, and also most callers don't use the > return value of request_module() since it's always necessary to check > whether the module registered its functionality or not anyway. But > improperly returning 0 can indeed confuse a few callers, for example > get_fs_type() in fs/filesystems.c where it causes a WARNING to be hit: > > if (!fs && (request_module("fs-%.*s", len, name) == 0)) { > fs = __get_fs_type(name, len); > WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?\n", len, name); > } > > This is easily reproduced with: > > echo > /proc/sys/kernel/modprobe > mount -t NONEXISTENT none / > > It causes: > > request_module fs-NONEXISTENT succeeded, but still no fs? > WARNING: CPU: 1 PID: 1106 at fs/filesystems.c:275 get_fs_type+0xd6/0xf0 > [...] > > This should actually use pr_warn_once() rather than WARN_ONCE(), since > it's also user-reachable if userspace immediately unloads the module. > Regardless, request_module() should correctly return an error when it > fails. So let's make it return -ENOENT, which matches the error when > the modprobe binary doesn't exist. > > I've also sent patches to document and test this case. > > Cc: stable@vger.kernel.org > Cc: Alexei Starovoitov > Cc: Andrew Morton > Cc: Greg Kroah-Hartman > Cc: Jeff Vander Stoep > Cc: Jessica Yu > Cc: Kees Cook > Cc: Luis Chamberlain > Cc: NeilBrown > Signed-off-by: Eric Biggers Acked-by: Luis Chamberlain Luis