Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp785151ybh; Wed, 18 Mar 2020 09:05:06 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvhbVSX4Pbn2e0pnynquf0VNdLD3gZSorYoZQhZeh8i0TZSI4gu1ZiI5pgWKe1eh24pTbo2 X-Received: by 2002:a9d:6c88:: with SMTP id c8mr4661324otr.338.1584547506521; Wed, 18 Mar 2020 09:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584547506; cv=none; d=google.com; s=arc-20160816; b=T7d+juY/lOsTloPfrkNHi/Aac7AYLlOU6aJc01q5OZLYyxb+Pbfv16XfXK30yhL4Vf rKzA8BCy3tk+KQQ3GFn/lcHMWaH6EY2RMnukJIULyTbC6WdxMVAQvLKt0DNr9C+NDY1k 6+H9V4bG0ClWeuH/Zzgps8/IrL5A15a5wrlHQTbJR4nouOKHjgIq2xmUBDXoTArOJyxd O2OG2uV4uaV4v7nIAEt6ay32D0jysUcYbIsClCNKHAvN6FcyH9Kgx9+vpiaPdGr2i4Fn 5Yc1/9ocY/ggpMK9Vb29mXHdN1SjN0fTRK1IJjAMEzZaxntlrQkZU/tsvt8SQWwMu4T0 +BWQ== 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:dkim-signature; bh=z3+0t4tjJtCpVmSi+szPtSvW/StFpIxsny0ln5ZnB1Q=; b=Oxvcc7rauz+dNvjQ1zzE5sUQSUvuzzQrdEeb59ZTb0hvZqwwt469KohvUkP9hLIHn0 9GNX4UgL+K5MKQ/My/gEsnFstS1oGA+OUIBXUhxqOOrKrh8yKInDcbgMxu6Cp2Obf6nj zHushZR0c0y/DFFYwPaNAr8G+/SkpqLdUP5E7P4VwBL2nv0IxXqqdiZioo6EYyDlj2ec ymbLK/c5aWVTLsnUv1x75Q5TOPikPBCpQvhmQsO32L4lpygDD5dle1GcG0wP8GncZ1Zf 8hPhKCdVYKoNXX7t9q9ni6X1+rZZet6QtE8sDNdEBu3DGjvj/mlUmZZnq9gaJrdms48t 804w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Izl6b0ua; 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=pass (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 q6si3729725otc.265.2020.03.18.09.04.47; Wed, 18 Mar 2020 09:05:06 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Izl6b0ua; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727133AbgCRQDX (ORCPT + 99 others); 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