Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2171253rdb; Sun, 24 Dec 2023 22:15:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3Cywc30bARfptr5qrtBoHhmYOTSTwFf9ce5CowHmKVOlNYFmRxmBptGf9LOPm9WfrLtJI X-Received: by 2002:a2e:2a02:0:b0:2cc:8017:c6e4 with SMTP id q2-20020a2e2a02000000b002cc8017c6e4mr2269571ljq.29.1703484946427; Sun, 24 Dec 2023 22:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703484946; cv=none; d=google.com; s=arc-20160816; b=qT6E4ZAZd6IXdFntqFHBGSIaa9ryQT436sXLHXyVYC7n6Lg277NxwzsDsw6aCwPKCr pRyw9SZvfO8QedTJDmvSmo0fjR8Lk3ZLvR9m9AySSi/jhgEjSRognfbWH3QbUoUaitDz I86HlTULjiVHLFowWZoX5z7j3VwubhCkCOwsAyAyBSJHKbmj27yo6UTKDsv4OuAqLE6V UwwY96CYZMtzyJrby5ivWnzb3hqtbDAgJSmvUIsn3fPH4qRBxYZ5in9CgaxY553V0gcy Ah+hFrnhkzKFcWmx7rvHuwzALLnKEa3VvWOO6P/20aTAVSpHydLED5vG36sq4c6QxwWD yJSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=qO4y4N6Ixk1GwwW6iVxLxyETp2+oMdraN4tiEI4oqkc=; fh=apHVRKwKsaXMTJEGzdPibXQvKV2XrvGFjIFMZPuzr5E=; b=A/frE3Y5chJJ5pL4j/ijOJUsRthm8s/iQMBgaf9nIK9VKEBz2zDUXjqKYN4a+g1BSo zHNM+V18vQXQ73wcbh9yLHyK6NKIX757B+fgy4oRWO3SPfKEBiDZ8hxtMpNORFaoQ8/e NlfXNAjaaY5fDn1EPyS+lOGISl46cLpqwsQcfZC3T4C9Eh/KF4QaH4yUx3Y26LMvMZ0W S4zC2vIYykxvkL8ylaFjrKfFVIl7ZJWK8BgEcMEvRDUqO5FyKUe5iFqitA8Zpy8QvJte eFTygMAewHvvEAxCSXnThCJjGu+TmPAFuL1wUjJ/CJq+lIzN2wh/hefjb4if0ANYwVCl SEQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10901-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10901-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 26-20020a50875a000000b0055411a2bb22si4097753edv.371.2023.12.24.22.15.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 22:15:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10901-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10901-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10901-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2F3AD1F212E0 for ; Mon, 25 Dec 2023 06:15:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5852B15A8; Mon, 25 Dec 2023 06:15:38 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32F5110FE; Mon, 25 Dec 2023 06:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Sz7121Fjtz1Q70R; Mon, 25 Dec 2023 14:15:02 +0800 (CST) Received: from kwepemd100002.china.huawei.com (unknown [7.221.188.184]) by mail.maildlp.com (Postfix) with ESMTPS id 4E62B1402E0; Mon, 25 Dec 2023 14:15:25 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100002.china.huawei.com (7.221.188.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Mon, 25 Dec 2023 14:15:24 +0800 From: Changbin Du To: Luis Chamberlain , Andrew Morton CC: , , Hui Wang , Stephen Rothwell , Changbin Du , Xiaoyi Su Subject: [PATCH v2] modules: wait do_free_init correctly Date: Mon, 25 Dec 2023 14:15:13 +0800 Message-ID: <20231225061513.2984575-1-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd100002.china.huawei.com (7.221.188.184) The commit 1a7b7d922081 ("modules: Use vmalloc special flag") moves do_free_init() into a global workqueue instead of call_rcu(). So now rcu_barrier() can not ensure that do_free_init has completed. We should wait it via flush_work(). Without this fix, we still could encounter false positive reports in W+X checking. Fixes: 1a7b7d922081 ("modules: Use vmalloc special flag") Signed-off-by: Changbin Du Cc: Xiaoyi Su --- v2: fix compilation issue for no CONFIG_MODULES found by 0-DAY. --- include/linux/moduleloader.h | 8 ++++++++ init/main.c | 5 +++-- kernel/module/main.c | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 001b2ce83832..89b1e0ed9811 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -115,6 +115,14 @@ int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *mod); +#ifdef CONFIG_MODULES +void flush_module_init_free_work(void); +#else +static inline void flush_module_init_free_work(void) +{ +} +#endif + /* Any cleanup needed when module leaves. */ void module_arch_cleanup(struct module *mod); diff --git a/init/main.c b/init/main.c index e24b0780fdff..f0b7e21ac67f 100644 --- a/init/main.c +++ b/init/main.c @@ -99,6 +99,7 @@ #include #include #include +#include #include #include @@ -1402,11 +1403,11 @@ static void mark_readonly(void) if (rodata_enabled) { /* * load_module() results in W+X mappings, which are cleaned - * up with call_rcu(). Let's make sure that queued work is + * up with init_free_wq. Let's make sure that queued work is * flushed so that we don't hit false positives looking for * insecure pages which are W+X. */ - rcu_barrier(); + flush_module_init_free_work(); mark_rodata_ro(); rodata_test(); } else diff --git a/kernel/module/main.c b/kernel/module/main.c index 98fedfdb8db5..1943ccb7414f 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2486,6 +2486,11 @@ static void do_free_init(struct work_struct *w) } } +void flush_module_init_free_work(void) +{ + flush_work(&init_free_wq); +} + #undef MODULE_PARAM_PREFIX #define MODULE_PARAM_PREFIX "module." /* Default value for module->async_probe_requested */ -- 2.25.1