From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18540C25B74 for ; Sat, 18 May 2024 14:00:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B3A16B0082; Sat, 18 May 2024 10:00:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33CDF6B0083; Sat, 18 May 2024 10:00:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 205986B0085; Sat, 18 May 2024 10:00:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 006D16B0082 for ; Sat, 18 May 2024 10:00:24 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 657491406E6 for ; Sat, 18 May 2024 14:00:24 +0000 (UTC) X-FDA: 82131676368.02.97B0DB8 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by imf15.hostedemail.com (Postfix) with ESMTP id 8511BA0002 for ; Sat, 18 May 2024 14:00:21 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=weissschuh.net header.s=mail header.b=d3oHzbDP; spf=pass (imf15.hostedemail.com: domain of linux@weissschuh.net designates 159.69.126.157 as permitted sender) smtp.mailfrom=linux@weissschuh.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716040822; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Ck8i313tK34lXumPeju0WTNecJTXkbfBfguwnaUhVDI=; b=uZerBv1n5JUAHbc8I/jHbx8VIn4yG0hu3w7FdmWDtb1qVaa2P9U5ApfRXcChkdcRTlsZqq WV2Y/YUGnLorX8wXYZthNq25TqjcAxGVvTicSQctFuE5rdPfn4s7JgCxG2O3ESMVP1uQ8C L2Jx7jaKkapjxb2bzYhNb9MMnJqcxTI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716040822; a=rsa-sha256; cv=none; b=8CGtOlnA2dZEL1bEBogxijyzc7x024C0t15+9uWWn8pCwNobyoP4Dp3zoQybk/FcKFJa/q Iii4NiCdn3adAzJm9Ab2lm25AaDBQ6W1hxAd2PgxYp1/MwHIitzyOVSUBZWSlyM0WD7VXw 7PBA8Q4koiICW8QwEJ1EjFz1K+nnIKE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=weissschuh.net header.s=mail header.b=d3oHzbDP; spf=pass (imf15.hostedemail.com: domain of linux@weissschuh.net designates 159.69.126.157 as permitted sender) smtp.mailfrom=linux@weissschuh.net; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1716040819; bh=61bJ2tqEF4n1McZZ9lfES2X9u82Av68XY/fmxSjnnHw=; h=From:Date:Subject:To:Cc:From; b=d3oHzbDPuXyiPxXwyIkD0wYo5dxCSIOt4VaXpOLQBbeu0YVDPPfV2QrxFjtWWBiIJ ec05tUXLqqjUR2UPES7usKst15os9tFW/AhGkgGACXd+5eFNcvUYNtpxPsu+vIkOD3 /B+9gQkHOFKMuUcJ0yfY+voDm+TfF+Z3h6xdlbH4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 18 May 2024 16:00:04 +0200 Subject: [PATCH] mm/hugetlb: constify ctl_table arguments of utility functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240518-sysctl-const-handler-hugetlb-v1-1-47e34e2871b2@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAGO0SGYC/x3MQQqEMAxA0atI1gY0jlS8yuBijFEDpQ5NlRHx7 pZZPvj8C0yiikFfXBDlUNMtZNRlAbx+wiKoUzZQRa+qrTu00zh55C1YwlxMXiKu+yLJj8jUucY xkWsZ8uIbZdbff/8e7vsB9MrC1W4AAAA= To: Muchun Song , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Joel Granados , Luis Chamberlain X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716040818; l=3639; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=61bJ2tqEF4n1McZZ9lfES2X9u82Av68XY/fmxSjnnHw=; b=rR1MGhjRwrmAdI7KVzpkJ8wR2BDA/vbFj3Q+VN3FPM4Np3zANg44QwQMhTDWrDwThcSH4hjRo VCZKmbxyQyGCjExmpL9w5YLFn2Gguund5Y0dOqk6cWyeZcNsBs3tr7e X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8511BA0002 X-Rspam-User: X-Stat-Signature: 9qyamxokzx41c885sweo9wbanc1kuex7 X-HE-Tag: 1716040821-701935 X-HE-Meta: U2FsdGVkX19Tww6UyCmr9y8QlXCmZ11tMSHl2cU4WwggFophDVRqq9bhEZNYUhUyUdDH/u8ZYMCJE/Uw+Vgv/uLQrBVpgpLTXDMdBUHw21qh5sVKDztba2lyuoFIvv9FM83x14Pnwk88/aWJqRKxMFzBXurBMMwy1wFNxgve0GkvpZTP4rkekS1KrcWMIWUux3vWB6TejMDRHZUph+sJRsWaGxNw1EfaW68/Hp3Ty597e30OewDDfB281R8vOE3XmMbXPzAUECn0UTjB1P7XYCwhRMAdsLCgHaEnES7deCA0tJXsXgeTFqEQ0bsc5/RbvwPHH+jTBFMrRJAxnA2uwN04IetSfV2are0EDgOfMJWfp4zCeXq8VjCYbAH81V5FJAxZee4rUWsF5aYdYhnzt++9m5F2Lo4tmDlBZkzJAroBlGtwK5MCVYXT3IKXqc5PQ9v6Cv/FZerYUK3YmRUjNBPEs17SBa24Pa528AAsN6w8Onm5uTRG9qedTEgYhKhaHk4UTSGcY2SYFKKkNS4SLWls6Mh/oHdxApJMKBzlgBuPUY0tbdaw2fTsMlcy3FchCs+OFlQ0I11XShE2LU2xjyydMCJYG1bAc6yn7xURkevSZ79T2bAaJULjHYgeJh2xX5fCxPhBHs7x+h/3zzOt04F9uh//c1+cJWpNbeNSvT3WWuKZv5gl3jSzRQrIkIhaeLQ/y5UnoqqKOq+LaExEQ5skkqjQr8eCQybu/gQ0UscpuKK32aSw/60s/fPHRGB4t5Ge6ZGPXZN2ffd8waJIjLvStyN8VwGVv/hL/fpYeQhx96MfnXwEBD0lnTXj87Zv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The sysctl core is preparing to only expose instances of struct ctl_table as "const". This will also affect the ctl_table argument of sysctl handlers. As the function prototype of all sysctl handlers throughout the tree needs to stay consistent that change will be done in one commit. To reduce the size of that final commit, switch utility functions which are not bound by "typedef proc_handler" to "const struct ctl_table". No functional change. Signed-off-by: Thomas Weißschuh --- This patch(set) is meant to be applied through your subsystem tree. Or at your preference through the sysctl tree. Motivation ========== Moving structures containing function pointers into unmodifiable .rodata prevents attackers or bugs from corrupting and diverting those pointers. Also the "struct ctl_table" exposed by the sysctl core were never meant to be mutated by users. For this goal changes to both the sysctl core and "const" qualifiers for various sysctl APIs are necessary. Full Process ============ * Drop ctl_table modifications from the sysctl core ([0], in mainline) * Constify arguments to ctl_table_root::{set_ownership,permissions} ([1], in mainline) * Migrate users of "ctl_table_header::ctl_table_arg" to "const". (in mainline) * Afterwards convert "ctl_table_header::ctl_table_arg" itself to const. (in mainline) * Prepare helpers used to implement proc_handlers throughout the tree to use "const struct ctl_table *". ([2], in progress, this patch) * Afterwards switch over all proc_handlers callbacks to use "const struct ctl_table *" in one commit. ([2], in progress) Only custom handlers will be affected, the big commit avoids a disruptive and messy transition phase. * Switch over the internals of the sysctl core to "const struct ctl_table *" (to be done) * Switch include/linux/sysctl.h to "const struct ctl_table *" (to be done) * Transition instances of "struct ctl_table" through the tree to const (to be done) A work-in-progress view containing all the outlined changes can be found at https://git.sr.ht/~t-8ch/linux sysctl-constfy [0] https://lore.kernel.org/lkml/20240322-sysctl-empty-dir-v2-0-e559cf8ec7c0@weissschuh.net/ [1] https://lore.kernel.org/lkml/20240315-sysctl-const-ownership-v3-0-b86680eae02e@weissschuh.net/ [2] https://lore.kernel.org/lkml/20240423-sysctl-const-handler-v3-0-e0beccb836e2@weissschuh.net/ Cc: Joel Granados Cc: Luis Chamberlain --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ce7be5c24442..53bb1bb86efa 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4916,7 +4916,7 @@ static unsigned int allowed_mems_nr(struct hstate *h) } #ifdef CONFIG_SYSCTL -static int proc_hugetlb_doulongvec_minmax(struct ctl_table *table, int write, +static int proc_hugetlb_doulongvec_minmax(const struct ctl_table *table, int write, void *buffer, size_t *length, loff_t *ppos, unsigned long *out) { @@ -4933,7 +4933,7 @@ static int proc_hugetlb_doulongvec_minmax(struct ctl_table *table, int write, } static int hugetlb_sysctl_handler_common(bool obey_mempolicy, - struct ctl_table *table, int write, + const struct ctl_table *table, int write, void *buffer, size_t *length, loff_t *ppos) { struct hstate *h = &default_hstate; --- base-commit: 4b377b4868ef17b040065bd468668c707d2477a5 change-id: 20240518-sysctl-const-handler-hugetlb-c28737c2275c Best regards, -- Thomas Weißschuh