Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp13336rdg; Wed, 11 Oct 2023 18:47:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFve4AGD9cEQ1oID9OXSiZb1qRb0xsJJGNRkrOMcc29YSBFdTKNRpCcMATiCD4jcoKPsprK X-Received: by 2002:a92:c56b:0:b0:34f:f5a4:3e68 with SMTP id b11-20020a92c56b000000b0034ff5a43e68mr30548937ilj.30.1697075277215; Wed, 11 Oct 2023 18:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697075277; cv=none; d=google.com; s=arc-20160816; b=Z8666LGplq2z1BTGAheeaLR3SAvbf6y5rohyDykJN97u866AvZPpDyuBfynoBC8pjX OQiDtLCIwjt3NX3y7LVWZibeLcBHbGnVPflu/2o6RL8gMYbTOe9QmawVknyp0QUj2NTT fqTSiW/mwywizYbF1+qY7/CdR+89l69Bzi2hlnGANfNsqmUTJE2M8aJNIm1u792Zdef+ A7qoSL3eUNQ1aOcUmYOnaqFys1xBkodBoQgpxSOpPt1SnxzG09GpkHrWsEFSUE1zwbhA +BRwlLxurwAyWG2eZ4QcCo5yzOsAGbd72G7878s2uilf/VyOdwIzLs48wW5U4OWdcFdz cI7A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=niFFbP3jkBocCEpB48HyTZeog/L/1NdzvkHsVOEBE3Q=; fh=5YBmAF6SiFPK19yasnrFcO3VT5KcPKYZINskqAtrAh0=; b=AWFF7Bu/vE73sUlrx0ITggxApjLSCDCqgan16528X2EHrFZn6dD1efOsBMSNgl3Qmq AcUxP+DBdyR7MeYs6BdEJciavGliEE0kALPF6gPTVM58fgSE/JvGZ9t94c2+dQIxx28j mP0mrECuhiYK6qXyc16CLitV97gP8KrN1wpE3y7NIzk6Z2hG/OKYwc+SxtakKIpoQ9eI XAL/gS6khfOoeLVfb+zhUQEcUnU1hL/Mbm/ENe0H8JulPJit4UcqOqneEaK7rI1qmtSo SA6s0XO2u1b+zcoS5+BX7hjmq5eiPGDwUb8PcLiE1IDDQdkrLZCuJ49Q6qaLfcEtHuYF otZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="njh/SVwT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id 126-20020a630084000000b00578c4d1f530si1068826pga.728.2023.10.11.18.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 18:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="njh/SVwT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id CB9A580BC556; Wed, 11 Oct 2023 18:47:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235264AbjJLBrm (ORCPT + 99 others); Wed, 11 Oct 2023 21:47:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235260AbjJLBrl (ORCPT ); Wed, 11 Oct 2023 21:47:41 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BCE1C9; Wed, 11 Oct 2023 18:47:39 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39C1UARb013082; Thu, 12 Oct 2023 01:47:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=niFFbP3jkBocCEpB48HyTZeog/L/1NdzvkHsVOEBE3Q=; b=njh/SVwTdcEebmjBpo/HXTTpzYsuW3PCXq7Y9xpWKcFVWlmYXBiJf+tLmSK15ZRGpYPR nw7+JXGka6pwtoB+/3wspejQaMp0osBHE1y31FcFabNwEpDSpUAdWYp2NenXd6s5O2Fg rToSXuh9oM/oRTLe3UI3CeycTmo0FBZoFeFPNe9LXuUHHj21K1OoezF9QxeehKza3HBZ PKfuJa0xrnqMqAoCBtawKB+JytU7kTVrNl78y4aDOanVRXGJRxwVfyemuqqVL466F9CW 8W9KNb04vo7rzZCjS3NA0kbd+HO+rFkOrGy+c60dGBbZgL462KbLeSenZuorAE0WwGSh Zw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnmdsaqqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 01:47:34 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39C1lXoU006865 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 01:47:33 GMT Received: from hu-jiangenj-sha.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 11 Oct 2023 18:47:32 -0700 From: Joey Jiao To: CC: , Luis Chamberlain , Subject: [PATCH v4] module: Add CONFIG_MODULE_DISABLE_INIT_FREE option Date: Thu, 12 Oct 2023 07:17:19 +0530 Message-ID: <20231012014720.19748-1-quic_jiangenj@quicinc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: EjLvWMSfftV7a94CGc-vf1e4evPCmbtd X-Proofpoint-GUID: EjLvWMSfftV7a94CGc-vf1e4evPCmbtd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_02,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 clxscore=1015 spamscore=0 phishscore=0 impostorscore=0 mlxlogscore=951 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120013 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 11 Oct 2023 18:47:52 -0700 (PDT) X-Spam-Level: ** To facilitate syzkaller test, it's essential for the module to retain the same address across reboots. In userspace, the execution of modprobe commands must occur sequentially. In the kernel, selecting the CONFIG_MODULE_DISABLE_INIT_FREE option disables the asynchronous freeing of init sections. Signed-off-by: Joey Jiao --- kernel/module/Kconfig | 12 ++++++++++++ kernel/module/main.c | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index 33a2e991f608..88206bc4c7d4 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -389,4 +389,16 @@ config MODULES_TREE_LOOKUP def_bool y depends on PERF_EVENTS || TRACING || CFI_CLANG +config MODULE_DISABLE_INIT_FREE + bool "Disable freeing of init sections" + default n + help + By default, kernel will free init sections after module being fully + loaded. + + MODULE_DISABLE_INIT_FREE allows users to prevent the freeing of init + sections. This option is particularly helpful for syzkaller fuzzing, + ensuring that the module consistently loads into the same address + across reboots. + endif # MODULES diff --git a/kernel/module/main.c b/kernel/module/main.c index 98fedfdb8db5..0f242b7b29fe 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2593,7 +2593,8 @@ static noinline int do_init_module(struct module *mod) * be cleaned up needs to sync with the queued work - ie * rcu_barrier() */ - if (llist_add(&freeinit->node, &init_free_list)) + if (llist_add(&freeinit->node, &init_free_list) && + !IS_ENABLED(CONFIG_MODULE_DISABLE_INIT_FREE)) schedule_work(&init_free_wq); mutex_unlock(&module_mutex); -- 2.42.0