From patchwork Mon Dec 23 09:37:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Pavlu X-Patchwork-Id: 13918645 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF4A91922DD for ; Mon, 23 Dec 2024 09:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734946750; cv=none; b=K0oCdKFCzNHuMCx2B9R7JSGP8NdVBVpj2Xl5YuF42sKZYSy2YUsJm/YKdhlkNTcVjeU1QmqKSNKGEujmMEaF3PSsbRt/8gvqQeP6EHgj6nifPkKlzsqQqyVH1Jqs/GsrTEVT20RJtF2Q7B7fkqfZGbzi2T4hoSuTLuf7hxGMrfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734946750; c=relaxed/simple; bh=ETP1ymbYo1qfIFjSyhEeHy3LDAuXB162qdikBGe/IQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b+NhJ/3XfA6TDZNVMPmjjqQDtoN1QfUES04QxkbNII6cHbFfcM75jtt9CxJsYgCFIQg55025V7NE4OQOsVN5eFsD+eApvD2YAhC5kKdGCi5b13nyyRVTUH7pICmdVqUc1PKmx0sL0+o0zvhTLClHoVb3EJ45d9vRRStmZQxW5zQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=S/uPR2kL; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="S/uPR2kL" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-435f8f29f8aso28851215e9.2 for ; Mon, 23 Dec 2024 01:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1734946747; x=1735551547; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2WQPaGV5b+bcwoSffAZhjDIDuT9+0kfuESUg3le7qes=; b=S/uPR2kLF86smPRNNp62sdxWFylsWDsHWYWqW+3KQ5uPAboMJ7IYggifp3LBWvxwH/ 9yh4OYk5oEwIq6sU3pvxfEV+PkbM3vfVYLWf4HpXoDecL7OESzxwTCdt4Y0ucl+QG9UU GwGvlFVNNbKzMCGNhWQFqxml6Q+2r2J9cBQ8pN2IixylqGrCikViYn90FQqz1RnBwbKZ x1nayG1QWsT3DysiLneGOFsVN04Rs74+0IC9RnPz12dAfpDTN+MAahWTq25MDL5XEcVz DEBJsgK8euDi14hX6w5h6cC6gXoICRAdQJ+GJIPzRCUUsWfbwWdq5G5lBgAgGH5mO7lr 2Upw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734946747; x=1735551547; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2WQPaGV5b+bcwoSffAZhjDIDuT9+0kfuESUg3le7qes=; b=i1Kz95TjHP00CsOBzo7I+Ty9PjCJp6lUv2d6GhcuBFt2h7Z0CBEHBAKprt0T8YKBra iSjl+V9j9RXCxbBmiCW7ptI+Sm9vhIhqWV0qkY8d6dxGFaw/hwkPLLMWzOfoqoW+JBc0 rvUG3VTcZffgRkFOcQBqAnJN17toHxTK7eN+2LtsJqWbwOeLH1uRbg8DiOGlWrYQ+/1U ut7S22v5fXqF54W0RIkmJEsbRdTTIBdYmge/lkjLZ0hPsPgeNaG+xuxOyThoGXXpDfxa IyFC4XCwYXNnxxy7OppEToI7HP/H7gFFvFDAPhDxgFTRg7pgt0uoAC1q9NhffwoyQFq1 Suwg== X-Gm-Message-State: AOJu0Yzj55hcHBRRjIf5OMvpk/efMg8G88RXlVoUx5E3TMr/bSl1uyG9 4OD9/qi/njfXvLtFurhD4SBsGLCivZHKjYIoO58U5tURv6ByBDgDQoe0Hs7GIm8= X-Gm-Gg: ASbGncse+0IDGfN40ISjHtLL1IrrnRGGFCrKYwclDz+iZj1gTw7Pg+rc49jZa3kUagX rVU0Fvk4VXH9tLj8sak6IGCKwnRLCdVRYWtcGDjWRmwqItuNeOClmPHwDom+dM9ZMLZT5Na104W JLgzQ7Fgedgp56UWowrESuVKkC/+vQUTYiWxOKcpcb+Pwz3vptjMXyc2tgDJpn9SC4sqjitTYKX Y0WUsKgBG0MzU9M/Y5CSpmDYfDmzkSVPDIJPVLQbgG+0KkO7cDTmgAFIllw X-Google-Smtp-Source: AGHT+IFm5r7Cf+dDlJFPMsarFoOSiqqlJkGJ9HXC2Cwjx2DL/obpCNE4LF9QIF4f2V7W2lIYeSDR9w== X-Received: by 2002:a05:600c:470a:b0:434:f767:68ea with SMTP id 5b1f17b1804b1-43668548337mr99288815e9.5.1734946747191; Mon, 23 Dec 2024 01:39:07 -0800 (PST) Received: from dhcp161.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c829235sm10773868f8f.15.2024.12.23.01.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 01:39:06 -0800 (PST) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Ard Biesheuvel Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] module: Constify parameters of module_enforce_rwx_sections() Date: Mon, 23 Dec 2024 10:37:47 +0100 Message-ID: <20241223093840.29417-2-petr.pavlu@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241223093840.29417-1-petr.pavlu@suse.com> References: <20241223093840.29417-1-petr.pavlu@suse.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Minor cleanup, this is a non-functional change. Signed-off-by: Petr Pavlu --- kernel/module/internal.h | 5 +++-- kernel/module/strict_rwx.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/module/internal.h b/kernel/module/internal.h index daef2be83902..7e78f6a8e85e 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -330,8 +330,9 @@ static inline struct module *mod_find(unsigned long addr, struct mod_tree_root * int module_enable_rodata_ro(const struct module *mod, bool after_init); int module_enable_data_nx(const struct module *mod); int module_enable_text_rox(const struct module *mod); -int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, - char *secstrings, struct module *mod); +int module_enforce_rwx_sections(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, + const char *secstrings, + const struct module *mod); #ifdef CONFIG_MODULE_SIG int module_sig_check(struct load_info *info, int flags); diff --git a/kernel/module/strict_rwx.c b/kernel/module/strict_rwx.c index 239e5013359d..d1c43309bb25 100644 --- a/kernel/module/strict_rwx.c +++ b/kernel/module/strict_rwx.c @@ -81,8 +81,9 @@ int module_enable_data_nx(const struct module *mod) return 0; } -int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, - char *secstrings, struct module *mod) +int module_enforce_rwx_sections(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, + const char *secstrings, + const struct module *mod) { const unsigned long shf_wx = SHF_WRITE | SHF_EXECINSTR; int i; From patchwork Mon Dec 23 09:37:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Pavlu X-Patchwork-Id: 13918648 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 761DA192589 for ; Mon, 23 Dec 2024 09:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734946752; cv=none; b=EIihs9hlw3z6nqGblVWGU35LDHeWBv+L3kJieYzPd11ldFzxAP8aoI+U0UiMujvKvL8vUi+fZFmXIXuuTDFNJT/k1o/CfC7pnwSwrDVmAm7IDMh3JZJ1v3uozJE+ve4mF6YRjNGEWLKw10fXHWDjBjt+bviFP51QgoYfmc6NuPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734946752; c=relaxed/simple; bh=6tdjyAZQ6cbVp+w0GpB3/BWnpCb4MftVCuh43tzcHRA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sAUTjM2J6UF72zluvdopuvt/CdaXN+2xi/Gkz21ro2xFOFqNk/cxGbeeJNOrZxDCYi5jHEaFdC5VDuCkTTOPbldO1nsiwMyvThdgvjIpFrQs1fURETPCexl1rBqhujHUtfp9Dg9nYTr+1BB4JuDpTxdS3iZwmQUA70L7cPmqM5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=P+2WMAfr; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="P+2WMAfr" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4361815b96cso26194185e9.1 for ; Mon, 23 Dec 2024 01:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1734946748; x=1735551548; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NexceldLvPH8eTfckj5Ngxuw5KfU1fsgYnDIWr0Vew8=; b=P+2WMAfr+RPh6VW3zUhMMiEmXd7Lj/nhNSOjLuacpvBuRoRnvGlaut/NLpEm/9ITio D0cX6b6z2p+LLqA9hq2aYp69aVxeRJODVRS5luOdjbOg5eykvVSo3bQtj+m0CIhGFpuB z4Rt23WmBoDOuYn6dPOQJEm0RnpWxxMm5IEYpbNqx675VbVhUkdlmAg1zL7kPGQGOTi7 YrynVzfythnzmi0un2HD52RdYC7oi+34EHM4jL4nDAHvfMN0tL+O9ZhzASn/luMf0/8K Sx6J67tB3DIwY0tZcaoivVpQTh0F0kql5/kKOaoQOXS5+BBy4cABfd3PbHfeA8gGJ9x1 1GVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734946748; x=1735551548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NexceldLvPH8eTfckj5Ngxuw5KfU1fsgYnDIWr0Vew8=; b=KTsCwzw9f34BmAYjCEgbvk05ldFvhE2up1fwc07vXjpXIvQskhxt+gNBlmulC2vWqw 4bkeHxrZHsTKc33jJdRptFtX1kEkzoQZLEOElX3hYQhsvAQvFwvJpMg65EyotI6DzFQO B4yvQNXnfzLj8WAbnDgERiddbMFGltPai2eakVmJZH3EGfxQRmg5/4bEBnXINEFOTVJ5 LDE19i4pjz6o+CHlDgt/uVIH14LB2Qt3shkll/5gw6CxB2sriZXqFfdsbBdjHEWzjr4W ghgh6kBLGYXJLA/znAXQUMig5Gs3o7r+5eKCg0jFVKbEpIlUSzofa47YLhZ+kfkUZuDJ lfGA== X-Gm-Message-State: AOJu0Ywf7UrnaFtuycLIyPc2HWUqCyr56CcOOVxXvAfdjM3TOClhXBlT LSmxLmsVWpQjWrf/VJ/UHNOox228WUMJgJzDzNXtB1OU9CtWD7PZXVnwY3HmRKI= X-Gm-Gg: ASbGncsklmnzq5p2nnnXSmYL/VFoKPywy9hky/pUIj2rLrSqTTvGc+XO3/9ySNeJRY3 +0Po3kDkblqG788NKip+McNScgR7q10ZFYLY2W9v9ze6ACCymhMY0ZFQpFHcJuir/u4utjpJYDC +gsxeyTheUCj9zM0MYEQ9YJqFj4BD7yYPr3kH255s6eZtQD2aQ/KMLJsTeDhKbY9LuiZO6vmIff J6RA5+s8gpc6azk56kCBLLP4oQtUh2v3RVP95+Y1SASwBk5kYLcz235j6tu X-Google-Smtp-Source: AGHT+IEeEsudDKP/+A7DnHtNti9OLkLotRBCvT8iEm73qgWuk5HeUCkRxJarZJy9KksulKFauzJM0A== X-Received: by 2002:a05:600c:4748:b0:434:a7e7:a1ca with SMTP id 5b1f17b1804b1-43668b5f5b7mr89549795e9.20.1734946747810; Mon, 23 Dec 2024 01:39:07 -0800 (PST) Received: from dhcp161.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c829235sm10773868f8f.15.2024.12.23.01.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 01:39:07 -0800 (PST) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Ard Biesheuvel Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] module: Add a separate function to mark sections as read-only after init Date: Mon, 23 Dec 2024 10:37:48 +0100 Message-ID: <20241223093840.29417-3-petr.pavlu@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241223093840.29417-1-petr.pavlu@suse.com> References: <20241223093840.29417-1-petr.pavlu@suse.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the logic to mark special sections as read-only after module initialization into a separate function, along other related code in strict_rwx.c. Use a table with names of such sections to make it easier to add more. Signed-off-by: Petr Pavlu --- kernel/module/internal.h | 2 ++ kernel/module/main.c | 18 +++--------------- kernel/module/strict_rwx.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/kernel/module/internal.h b/kernel/module/internal.h index 7e78f6a8e85e..c4c918d9b65e 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -333,6 +333,8 @@ int module_enable_text_rox(const struct module *mod); int module_enforce_rwx_sections(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, const char *secstrings, const struct module *mod); +void module_mark_ro_after_init(const Elf_Ehdr *hdr, Elf_Shdr *sechdrs, + const char *secstrings); #ifdef CONFIG_MODULE_SIG int module_sig_check(struct load_info *info, int flags); diff --git a/kernel/module/main.c b/kernel/module/main.c index 5399c182b3cb..12ca6c6d7efd 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2710,7 +2710,6 @@ core_param(module_blacklist, module_blacklist, charp, 0400); static struct module *layout_and_allocate(struct load_info *info, int flags) { struct module *mod; - unsigned int ndx; int err; /* Allow arches to frob section contents and sizes. */ @@ -2728,22 +2727,11 @@ static struct module *layout_and_allocate(struct load_info *info, int flags) info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC; /* - * Mark ro_after_init section with SHF_RO_AFTER_INIT so that - * layout_sections() can put it in the right place. + * Mark relevant sections as SHF_RO_AFTER_INIT so layout_sections() can + * put them in the right place. * Note: ro_after_init sections also have SHF_{WRITE,ALLOC} set. */ - ndx = find_sec(info, ".data..ro_after_init"); - if (ndx) - info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT; - /* - * Mark the __jump_table section as ro_after_init as well: these data - * structures are never modified, with the exception of entries that - * refer to code in the __init section, which are annotated as such - * at module load time. - */ - ndx = find_sec(info, "__jump_table"); - if (ndx) - info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT; + module_mark_ro_after_init(info->hdr, info->sechdrs, info->secstrings); /* * Determine total sizes, and put offsets in sh_entsize. For now diff --git a/kernel/module/strict_rwx.c b/kernel/module/strict_rwx.c index d1c43309bb25..598f89195336 100644 --- a/kernel/module/strict_rwx.c +++ b/kernel/module/strict_rwx.c @@ -101,3 +101,36 @@ int module_enforce_rwx_sections(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, return 0; } + +static const char *const ro_after_init[] = { + /* + * Section .data..ro_after_init holds data explicitly annotated by + * __ro_after_init. + */ + ".data..ro_after_init", + + /* + * Section __jump_table holds data structures that are never modified, + * with the exception of entries that refer to code in the __init + * section, which are marked as such at module load time. + */ + "__jump_table", +}; + +void module_mark_ro_after_init(const Elf_Ehdr *hdr, Elf_Shdr *sechdrs, + const char *secstrings) +{ + int i, j; + + for (i = 1; i < hdr->e_shnum; i++) { + Elf_Shdr *shdr = &sechdrs[i]; + + for (j = 0; j < ARRAY_SIZE(ro_after_init); j++) { + if (strcmp(secstrings + shdr->sh_name, + ro_after_init[j]) == 0) { + shdr->sh_flags |= SHF_RO_AFTER_INIT; + break; + } + } + } +} From patchwork Mon Dec 23 09:37:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Pavlu X-Patchwork-Id: 13918647 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39DD1192B73 for ; Mon, 23 Dec 2024 09:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734946752; cv=none; b=MbY2vdn0dVKuCnEh3UxzIXydLx4WVGtuKsh/G39NQsQn9GiyLI9bIkxrYrLwsU0JVDRqT3S036n0XKMXJl7f+vz5lDhVuctgs/YcsZ6s7s7ZiaaoKzbLX95QVi74AXDmig+8S5t3qgD63pYP9d0+xmJ5uP5K3Bl6COxuDuqajF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734946752; c=relaxed/simple; bh=UH4xbEe0zmFXOwPUKrl24/lhmUI7cbLTQl/c73IEBaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GhXIvictY7lXLAIKgDBX1R6tFDiU4QQNynM3PAgJ4SOuQxsgFfQ6zdR6n6U8XH+KVM/BQ7NPX/1BWyDDY09fJrdgEeOFPCiJjrxpyvmaTFJ5madHMXMISQC/ZpNpQJLPbj52/PGSXigzumzHILsJqAyjh6Zla1JCvyu4V6TjSHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=fxR+k1WO; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="fxR+k1WO" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-385e27c75f4so2912452f8f.2 for ; Mon, 23 Dec 2024 01:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1734946748; x=1735551548; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HLu09/IZb76vH1AepGLoCNTFGrmu/5Ir8RKortKBDcM=; b=fxR+k1WOP+yrLzNAlMDe3uKprLZKgG/wgPAJpEQFWc4omwMB4MGvtsscFZBbKd4K6Z FGpqC8dSg1Q1uzWEbcNxnx46ameWzFpk2lLG9I9S943XqtOdl3wxBVDqlva9Ilecx0hK m84uPkygCY3v+85a3XFdPy0Kg/UYj5Qe43Z1gHB+myP8tby2XR2dlcx2XbOm/XLtI6Cc qbzMGBKLHMi+WQN0Lu4BZ/I/8wo013G1mG9njLAbf2rfdSfYVbTo7XIAMXLE3RaW43Gh ivMYeu01k9kYROg2TQ3YJByYotYao0ISMkRrEJTeDe29dAmfe1yVmVyBoaouy11QFhjp gAiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734946748; x=1735551548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HLu09/IZb76vH1AepGLoCNTFGrmu/5Ir8RKortKBDcM=; b=dPT2fmtyKOKrkJExyMJY71nT5QAnBiIl+5fuL+tJeXZ6gUEdEj/lrFRjsQrOxloATw Sxdq6G4F0ebzfOsPxy3C8uDDcmqgzqtFRLFzAwGbSC1zpkfi7GH+hoEthDc6KJTJ2nxp KQAz/wf9yT/QxTCA6Gyb7zUqf3J9A3iYwS5N/ZgejMF7Ilp5S64DNuN/MDNYApvMMANP TG3coKpTdsMWkvwjhyNvUdMpOQVA00iDwXiES67iu3UTqSD7VszEJ4PlqNdiI+XO9dcC VOpQxK3A7Z4K94tB3qLiVeq3+hCmB7kAmRHoyaaZQqYUCknz7aIJ5Z0b4AR7Xeqa0aCE Sddw== X-Gm-Message-State: AOJu0YxI1kEYNeL000C004CTFkVejDPysuJE10CaitaYu6QXnp7tHmuR gu0KK4QG70iT+6l4e+sn5I07yjtNbDJd34N0kiaAkMjtEoj/HUpkySY29TgbrY6TM31uiJNHos2 2 X-Gm-Gg: ASbGncsJzJRjpXw8zaDN7lsUW1jUYWfBH3u1DDRoFNuqKFXUHEEiQl7MzF2HqYXnRFQ bT6qxEFLEU55ZoZfAg9+Fbmj/o6NsH3NG0305+6g3Y6fyUPxDS5UU5XaCAcpbfWMQeorprcJVbA gb+N29Zb+ndM2m2LImm+u7kqTQypWqxU+Oxb2ZekR0Z0e8MhKibA5O/Zaz8jKxTtJaw4XHRlyqZ qtthCVIpMp5jSvAsIULsMNauUIbAnUf4ihbkKR5DItbl8D/1G5p42gPJx6z X-Google-Smtp-Source: AGHT+IH/O/K2z2kiA821Hde63hWbwa0B+QD6rT/zP3IoMk1MAKsl29HlJV0aQSy+OLPVN88I+iGbAg== X-Received: by 2002:a5d:5f48:0:b0:385:faaa:9d1d with SMTP id ffacd0b85a97d-38a221fae50mr11914975f8f.35.1734946748435; Mon, 23 Dec 2024 01:39:08 -0800 (PST) Received: from dhcp161.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c829235sm10773868f8f.15.2024.12.23.01.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 01:39:08 -0800 (PST) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Ard Biesheuvel Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] module: Make .static_call_sites read-only after init Date: Mon, 23 Dec 2024 10:37:49 +0100 Message-ID: <20241223093840.29417-4-petr.pavlu@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241223093840.29417-1-petr.pavlu@suse.com> References: <20241223093840.29417-1-petr.pavlu@suse.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Section .static_call_sites holds data structures that need to be sorted and processed only at module load time. This initial processing happens in static_call_add_module(), which is invoked as a callback to the MODULE_STATE_COMING notification from prepare_coming_module(). The section is never modified afterwards. Make it therefore read-only after module initialization to avoid any (non-)accidental modifications. Signed-off-by: Petr Pavlu --- kernel/module/strict_rwx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/module/strict_rwx.c b/kernel/module/strict_rwx.c index 598f89195336..4ae5facab569 100644 --- a/kernel/module/strict_rwx.c +++ b/kernel/module/strict_rwx.c @@ -115,6 +115,15 @@ static const char *const ro_after_init[] = { * section, which are marked as such at module load time. */ "__jump_table", + +#ifdef CONFIG_HAVE_STATIC_CALL_INLINE + /* + * Section .static_call_sites holds data structures that need to be + * sorted and processed at module load time but are never modified + * afterwards. + */ + ".static_call_sites", +#endif }; void module_mark_ro_after_init(const Elf_Ehdr *hdr, Elf_Shdr *sechdrs,