Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp348499pxu; Thu, 7 Jan 2021 06:39:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGDc3aSTFZ+tBUxC4jcWFJSZAFIU5Eb0BR7h1EGViPMgsEZjv9rPfM7GbLPRTkQ5RBQTb7 X-Received: by 2002:a17:907:206a:: with SMTP id qp10mr6714031ejb.432.1610030397896; Thu, 07 Jan 2021 06:39:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610030397; cv=none; d=google.com; s=arc-20160816; b=Im5kOU3xZyrp5sNohpL92pMnRYus3N4S/JPhRTSBgsdcoqG2wCbn9oHcHRVa8C9vIF Ep0eTCOdKS7tXIPvw3NujQBRXN/znranT7x15j2gAygNcpkMnrfPboSpMMC+z0OpDLad gSxDiDGNd2ypKOU4JfJ4XWPy2y0jXSb+1Ob2KL1ELGQye3nHgJqxDfI+QM9ryPQDCil8 P2okZIEAJkETS8BMeRYlUpJEmE2QkNiALQQYh0QUmpWWWEXsGgQjVczbiHZeqIaCJ0In /WW5LXkCOXdEbhDF55ZPdm2EOtADghlByuwr8S9g0kILTDYyZNSI07hLe7JWPTLRTHrA 2yqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+WkCEmdvOggL1hjhFRS3xTARcK2A3HwoTO/uVgRnU/Q=; b=dU2YkQJaUJHXvDIvqBIOFUy6h/xbJQTsgUZFHryTSkMdQBfiimUtIYlUXU2NoK2vU3 0ECxtIxWbvV1hPWn5Fzc4hFPuZgcOmRwF7PkCpkMhHAe9qMDdMYTsE3zPhu0mV4AF8Ag +0eeFrmAX04BtsiwUJLX2NX+Er1X1N6oHdNNc/MouYjQc33w9qu5ZFHQRF8pG7SDTMP6 G920OXHrmHe3JPNfFJsdfIm7202gEkm2ZIu0YNJcbZaCAEChbdwFKv+umyYSy46mjGzt u2Y75ytj26nIaZdv/PbzuXnwGZlWixPg/e2KkIW6FToWOTy2M/uqSq7NKQ3uUNj+XEob Qc0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C49yDeNn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id no7si2148596ejb.586.2021.01.07.06.39.34; Thu, 07 Jan 2021 06:39:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C49yDeNn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729309AbhAGOhr (ORCPT + 99 others); Thu, 7 Jan 2021 09:37:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:46235 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729149AbhAGOcE (ORCPT ); Thu, 7 Jan 2021 09:32:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C11D42339F; Thu, 7 Jan 2021 14:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610029865; bh=4x0SBRPSAB8n2LXqFve1WbygbDfp1EtedWhGfC9a91I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C49yDeNnpD46aNY3yNdQ7Ao1hXpCsXhbAj/D9LW+zZEEgXXcuuDUj/Qq78l7xSxWf Sg852NECS0VSVTBQeTCf0XScOOl3+rD9SgpG7hkaWl25cVyyBe3jG6CtAYKvsQnLLd YDwMG/QCC5XqsCn7PtarF0oqndnSN9QSLlMUG58I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Morey-Chaisemartin , Jessica Yu , Sasha Levin Subject: [PATCH 4.14 23/29] module: delay kobject uevent until after module init call Date: Thu, 7 Jan 2021 15:31:38 +0100 Message-Id: <20210107143056.245832583@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210107143052.973437064@linuxfoundation.org> References: <20210107143052.973437064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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. 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 c4f0a8fe144e1..0b2654592d3a7 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1789,7 +1789,6 @@ static int mod_sysfs_init(struct module *mod) if (err) mod_kobject_put(mod); - /* delay uevent until full sysfs population */ out: return err; } @@ -1826,7 +1825,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: @@ -3481,6 +3479,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