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=-24.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 1CD2DC433E6 for ; Wed, 30 Dec 2020 13:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCD7B2220B for ; Wed, 30 Dec 2020 13:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727863AbgL3NHR (ORCPT ); Wed, 30 Dec 2020 08:07:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:53388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727443AbgL3NF2 (ORCPT ); Wed, 30 Dec 2020 08:05:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A2D3D229C6; Wed, 30 Dec 2020 13:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609333473; bh=rfhFH6eg7o5FHaqFrhkBY1jIrNltm1Nk4Zj9m+m+6Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMvOxHCdU9uxrZNAgFe/MG+bH65nApiCDFtN9VTPujj8x5f/O57E4wI8Tp/KYv18X XZzqk9izjO0iOIXacBgUXQ6Z9XHZE0W1Q89M9+NtLH9147wxq+VcbKO4CMb4SaWW6H SkJsJCu5nxSqz9bz/PmgIhU8vlioyLa0BZKzxO3W+LEIUtLYxMADy8FDCGNbdVFC6Z nYEh0UsHUAvYX2mzQu2dUUBXK0BeN3bUk6LnVigETZYcxRko9+/Jj9y5yg/R5Xy7lp 9J5+YOgmKs6LsuOUXLZAks8vgB7TxbbwpH3ptQBICydIocnunV8lbmq/DFr2U25Cp1 feEEI3gGaBvaw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jessica Yu , Greg Kroah-Hartman , Nicolas Morey-Chaisemartin , Sasha Levin Subject: [PATCH AUTOSEL 4.19 08/10] module: delay kobject uevent until after module init call Date: Wed, 30 Dec 2020 08:04:20 -0500 Message-Id: <20201230130422.3637448-8-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201230130422.3637448-1-sashal@kernel.org> References: <20201230130422.3637448-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jessica Yu [ Upstream commit 38dc717e97153e46375ee21797aa54777e5498f3 ] Apparently there has been a longstanding race between udev/systemd and the module loader. Currently, the module loader sends a uevent right after sysfs initialization, but before the module calls its init function. However, some udev rules expect that the module has initialized already upon receiving the uevent. This race has been triggered recently (see link in references) in some systemd mount unit files. For instance, the configfs module creates the /sys/kernel/config mount point in its init function, however the module loader issues the uevent before this happens. sys-kernel-config.mount expects to be able to mount /sys/kernel/config upon receipt of the module loading uevent, but if the configfs module has not called its init function yet, then this directory will not exist and the mount unit fails. A similar situation exists for sys-fs-fuse-connections.mount, as the fuse sysfs mount point is created during the fuse module's init function. If udev is faster than module initialization then the mount unit would fail in a similar fashion. To fix this race, delay the module KOBJ_ADD uevent until after the module has finished calling its init routine. References: https://github.com/systemd/systemd/issues/17586 Reviewed-by: Greg Kroah-Hartman Tested-By: Nicolas Morey-Chaisemartin Signed-off-by: Jessica Yu Signed-off-by: Sasha Levin --- kernel/module.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 8dbe0ff22134e..429769605871d 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1806,7 +1806,6 @@ static int mod_sysfs_init(struct module *mod) if (err) mod_kobject_put(mod); - /* delay uevent until full sysfs population */ out: return err; } @@ -1843,7 +1842,6 @@ static int mod_sysfs_setup(struct module *mod, add_sect_attrs(mod, info); add_notes_attrs(mod, info); - kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); return 0; out_unreg_modinfo_attrs: @@ -3499,6 +3497,9 @@ static noinline int do_init_module(struct module *mod) blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_LIVE, mod); + /* Delay uevent until module has finished its init routine */ + kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); + /* * We need to finish all async code before the module init sequence * is done. This has potential to deadlock. For example, a newly -- 2.27.0