From patchwork Mon Dec 25 06:15:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 183128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp253085dyb; Sun, 24 Dec 2023 22:15:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7LNGZwcHhY87kmN7D1clGhAoGqgDm3TyvXltDfNQauAWDS1et3TMw51oOcu+ISn6SFfC5 X-Received: by 2002:a05:6214:1c8a:b0:67f:b97:f092 with SMTP id ib10-20020a0562141c8a00b0067f0b97f092mr6727780qvb.87.1703484952719; Sun, 24 Dec 2023 22:15:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703484952; cv=none; d=google.com; s=arc-20160816; b=ZgFj5bGoTAH8ak7RSNURiK4+ki4OMjbNtsppqA9CPAltYwNVyPy4ro7iFOsl1aOL8I pFRZFreU+EiUGiCJQDtohrOYfAKerBlOQRtI95COhqbTp8qAnps2f4KvpDVvXydVN/fm rNObXDlShVBcXHRkAvEnF++CxpZpgmrnQKclAnC4gY/qahWC3wiHZ5S9lILfbv17G4Le liai4uRBYiCVAzpVqoSV32pFQFsBL6ZHvduoxSEAGRvrmy9UCYwo/DyGgmwl3gCcAy1E 9HHxvPoxkbOMjjMgnJjCeFEz5mUGkAkrCM0Th9oeTxD2uyUflPK5WvGyHKDYV8ePxyI1 bL2Q== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10901-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n6-20020a0c8c06000000b0067f9d77f4bdsi5941276qvb.289.2023.12.24.22.15.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 22:15:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10901-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10901-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10901-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 81AA21C20B4C for ; Mon, 25 Dec 2023 06:15:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55F701C14; Mon, 25 Dec 2023 06:15:39 +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 X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd100002.china.huawei.com (7.221.188.184) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785720028085232209 X-GMAIL-MSGID: 1786233438072958076 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 */