Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp147424ybh; Tue, 10 Mar 2020 21:34:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt/DLZ1C66QVKZ99GTJ1AozUzTeFQhOoA9YjFE9kJgMJk+ja6pVg0/dfMnSq3LvFa0dQkaD X-Received: by 2002:a9d:19c8:: with SMTP id k66mr833482otk.43.1583901265173; Tue, 10 Mar 2020 21:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583901265; cv=none; d=google.com; s=arc-20160816; b=yXgMB5GaNc24YGZHQ5gbHNs2VEGLnKtlU8zVtYbjKso8rPpK0LpLX2ShZgVuhiotGi 2B5hgCANj2H42RLwf3luiq+N6Mme8l6OJ6+V6lNlkiyNkINi8mudX3+veTSROypVXA82 7fGrehjf7bRVoCzpdFPtGxvF3zOnjZ8NSdM3UWvQIOcMqUnjz3YcmQhGFFptK3qeocp4 lH9eKY4Ma1rikhNNDrpsrGlbaw9uSi4Z6Mc+2QbBEITDmORV4vrto6dEy64tzPCTLGB5 jfz4a7qztoEGZJyIpJOIHQorGWLU98g3WqeQrMtWf3XDCzSiorhA8wJCIQ07/81gKnrz xn0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=y9CqbWhfL4v92L67bT4ytPNxC+GiQd5penxrum1IdpY=; b=TWhp1iwwsolIwXUnRmo4/EXp89bM6+YfGyaFTg+8JoojF3mqDMFEQr0BQ16uV0lZ0F PCTRSWvQr8VEAR5249JANHT0rWShez7XNaenEmj40pkKzsAAwqcYkxduB/8nkzsZBwnN HfdW+gKVO8LTXpQBzU1TdqMbE299r61ZP7I2be66/PrrRfNvp1dVt2A3n1Jhu8kVGNwT O8+taUgmKGjcVzN8rNCq3WasiMGy46FuVuyaei03zxgSsu5RAF+bRPeyNEhgcqE57lZH MuWQc8PXKQD2AZjDCcXfW/pxXwdmnzHoK8KsIpS5nVF165F6l3IA8ag4Av47w6czGTXG jt0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si497231otj.170.2020.03.10.21.34.11; Tue, 10 Mar 2020 21:34:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726393AbgCKEcZ (ORCPT + 99 others); Wed, 11 Mar 2020 00:32:25 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:53581 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725958AbgCKEcZ (ORCPT ); Wed, 11 Mar 2020 00:32:25 -0400 Received: by mail-pj1-f68.google.com with SMTP id l36so306775pjb.3; Tue, 10 Mar 2020 21:32:24 -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=y9CqbWhfL4v92L67bT4ytPNxC+GiQd5penxrum1IdpY=; b=N1Fy5y+D5FEggQp2glrbO3Rvu3KhR+BVyRTZAH+CKis/923M0wvRcDrHY47rzK567e GImXA0l0SSKPZCYuiwrjl3EHb+W2EwkBO7YUIPRI/wEqGhBVxgrZKvPGvTXWABTRuXYr af30ap3ZY8lYbU8AG6FAMpIbcBj4+KasRFh8B3wnV/FZD440ODdGPmPQHEYvQ1+SfAsJ DsLZYzVgXQDfWsWIkcVkDeeUtf81NedOLO8hm0hYy4eUZbiOgJQ59Cw3F120fwiZpMcO m9oq4BZau66fGcWBjIE2En/EfFRuv7paKzMKByQS2um2sH/d884WkJfUR0jRQuxbvB/X Y49w== X-Gm-Message-State: ANhLgQ0Kt//oPP34Vj4sfqJ+h+o+yokhszqTH9fQmBKpCTQwBXl1fBfS 3PrL+g7b8PjwWtxgHEEBmsc= X-Received: by 2002:a17:90a:da01:: with SMTP id e1mr1489918pjv.100.1583901143645; Tue, 10 Mar 2020 21:32:23 -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 b10sm3845793pjo.32.2020.03.10.21.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2020 21:32:22 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id C909C4028E; Wed, 11 Mar 2020 04:32:21 +0000 (UTC) Date: Wed, 11 Mar 2020 04:32:21 +0000 From: Luis Chamberlain To: Eric Biggers , NeilBrown , Josh Triplett Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Alexei Starovoitov , Andrew Morton , Greg Kroah-Hartman , Jeff Vander Stoep , Jessica Yu , Kees Cook Subject: Re: [PATCH] kmod: make request_module() return an error when autoloading is disabled Message-ID: <20200311043221.GK11244@42.do-not-panic.com> References: <20200310223731.126894-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200310223731.126894-1-ebiggers@kernel.org> 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 On Tue, Mar 10, 2020 at 03:37:31PM -0700, Eric Biggers wrote: > From: Eric Biggers > > It's long been possible to disable kernel module autoloading completely > by setting /proc/sys/kernel/modprobe to the empty string. This can be > preferable preferable but ... not documented. Or was this documented or recommended somewhere? > 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. However this is implicitly not true. For instance, as Neil recently chased down -- blacklisting a module today returns 0 as well, and so this corner case is implicitly set to return 0. > 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. Right, the de-facto practice of verification of a module to be loaded is for each caller to ensure with whatever heuristic it needs to ensure the module is loaded. > 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 > [...] Thanks for reporting this. > Arguably this warning is broken and should be removed, since the module > could have been unloaded already. No, the warning is present *because* debuggins issues for when the module which did not load is a rootfs is *really* hard to debug. Then, if the culprit of the issue is a userspace modprobe bug (it happens) this makes debugging *very* difficult as you won't know what failed at all, you just get a silent failed boot. > However, request_module() should also > 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. This is a user experience change though, and I wouldn't have on my radar who would use this, and expects the old behaviour. Josh, would you by chance? I'd like this to be more an RFC first so we get vetted parties to review. I take it this and Neil's case are cases we should revisit now, properly document as we didn't before, ensure we don't break anything, and also extend the respective kmod selftests to ensure we don't break these corner cases in the future. > 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 > Signed-off-by: Eric Biggers > --- > kernel/kmod.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/kmod.c b/kernel/kmod.c > index bc6addd9152b..a2de58de6ab6 100644 > --- a/kernel/kmod.c > +++ b/kernel/kmod.c > @@ -120,7 +120,7 @@ static int call_modprobe(char *module_name, int wait) > * invoke it. > * > * If module auto-loading support is disabled then this function > - * becomes a no-operation. > + * simply returns -ENOENT. > */ > int __request_module(bool wait, const char *fmt, ...) > { > @@ -137,7 +137,7 @@ int __request_module(bool wait, const char *fmt, ...) > WARN_ON_ONCE(wait && current_is_async()); > > if (!modprobe_path[0]) > - return 0; > + return -ENOENT; > > va_start(args, fmt); > ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args); > -- > 2.25.1.481.gfbce0eb801-goog >