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,USER_AGENT_SANE_1 autolearn=ham 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 8A192C5ACD6 for ; Wed, 18 Mar 2020 16:03:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D69420770 for ; Wed, 18 Mar 2020 16:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584547404; bh=8+bhNeSa7Nigx9lS/u8FMlPTHye2zcWuNkajfPvjVP0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=Kl6XAlEpf1ugpEzQVxLBhiJE+fGR3R8nVd9xWFsrbLsOxitjAb3+H5odtq/gntckq qu5bVn0ODYqDYxdrdOC99kqB4Tflk6tR0RPliT6czgbCXBFjO4a75DxO2RDqDZzfj9 Fzr6AQWuKx8HOsUEMy74LoNfI1mzZDWB6qib+PFI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727154AbgCRQDX (ORCPT ); Wed, 18 Mar 2020 12:03:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:57966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbgCRQDW (ORCPT ); Wed, 18 Mar 2020 12:03:22 -0400 Received: from linux-8ccs (p5B2812F9.dip0.t-ipconnect.de [91.40.18.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 383192076C; Wed, 18 Mar 2020 16:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584547401; bh=8+bhNeSa7Nigx9lS/u8FMlPTHye2zcWuNkajfPvjVP0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Izl6b0ua1+tYjXnLnem1GifC/wnoWuzCPXbuSvOV+fm4FovYEdx2fZwZeuoazXHf4 KKqkDz2I/toW12IdmVG+tsC/k++kMxwuB22RWbqkIb8l6JogE9XAeBR84cnYgojkIz NXSxU3AXxtELDbwGdexG+SICwJ2InYehXnsNies4= Date: Wed, 18 Mar 2020 17:03:16 +0100 From: Jessica Yu To: Eric Biggers Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexei Starovoitov , Andrew Morton , Greg Kroah-Hartman , Jeff Vander Stoep , Kees Cook , Luis Chamberlain , NeilBrown , stable@vger.kernel.org Subject: Re: [PATCH v3 1/5] kmod: make request_module() return an error when autoloading is disabled Message-ID: <20200318160316.GC4144@linux-8ccs> References: <20200314213426.134866-1-ebiggers@kernel.org> <20200314213426.134866-2-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200314213426.134866-2-ebiggers@kernel.org> X-OS: Linux linux-8ccs 4.12.14-lp150.12.61-default x86_64 User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Eric Biggers [14/03/20 14:34 -0700]: >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. > >Acked-by: Luis Chamberlain >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: NeilBrown >Signed-off-by: Eric Biggers Reviewed-by: Jessica Yu