Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1833330rdh; Sat, 25 Nov 2023 04:54:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4e+uNRq5aOW2HdEybON5nOKUau5dpVEppbhfL/5kBsTLjX3S9fNhAr/3LC6cTwLXWGenT X-Received: by 2002:a17:90b:1bc5:b0:285:8628:47b9 with SMTP id oa5-20020a17090b1bc500b00285862847b9mr6557381pjb.47.1700916849317; Sat, 25 Nov 2023 04:54:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700916849; cv=none; d=google.com; s=arc-20160816; b=Jnk0Nbpm6E/136dodDH0qfrQ8ZqgOH8b5zbrNkle+yiusKgLeUaLOTj5OOOQj+S4ys 7ZWjuYCBGrQpCKA4/MSkWg7d3vDpBFLF2dFfmZX/9XXZqPRs4+JACE2HMVvArbtwilQo D3IN5/pgbvAv3ATuTCx1pfJ3FBYmcVCA6ZpckfV7KpFbDysMNEgrdQqTQuzM2YU4YccS M3wjQzEugCXjR7AMNohGVE2/p/wyMwdvcrW1lN/9I+qtiPPd9sUbTUQmw2PbTLXW+D25 KxA1XNpIrEafSa9dVEWhQzexuDLFwETDaRUjQ5YQ3b+qACGxmA5ECHiq7PMCw9lTJkMI nxLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=mdk+hVe/UEv0WpIi6WQxX5/1YUCPyC4wYUFiOvXW2KI=; fh=1v5zqbO9sIGUc9bsdyhYE0zxdK1knZz2xnJYWUWMFKo=; b=HtioyMrQFYksHGmxlELqByE0DBApiVeUExXeqBVq9AhxZo9WY2KJ2WobDmfWN5x74x W+4d0sxxL5ixNUTF1OFH0MqcfgpBatyDcFADzkiVGhzBeBu9smn60Qn9TZHP+/n/h3cK BZdXlMi3vKMXL3BgNBlCm/MCs6Sr9UWVx100chKKpwn+a9QW7Z0+HVNvHYk7aIjPfIEC iwEUXKBuG/l39tySmsq9uyV33agpkwTyqz1bsQgf+4POK3h0uH9ds7MOOtcWlETdJn8n GoETWgYqjezNPkW0I4LH2OniXxIAMbV6xHCRaYvO0s+FmxSKqD+Rq86+mqNlVkHbZwSz jOcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=ruCv9eFB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id nh19-20020a17090b365300b002841a9ca614si5569107pjb.187.2023.11.25.04.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 04:54:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=ruCv9eFB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 9CAC8804EE5F; Sat, 25 Nov 2023 04:54:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232220AbjKYMxK (ORCPT + 99 others); Sat, 25 Nov 2023 07:53:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232063AbjKYMwz (ORCPT ); Sat, 25 Nov 2023 07:52:55 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3C34EA; Sat, 25 Nov 2023 04:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1700916777; bh=eBhOR2st0kYur9zVJzF7EyOPAu0FRzljdghuY8XBOWo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ruCv9eFB2WE77RMf3vbBpk3bVkniSFw8IzlWE7Fz17sBjZveEjpMX/8aQzd/joQC4 GZXSqv+GOalkDZJhIn4RnxKmGIpU6yxvpQLSJ/+T1d7/sNmHooD6FNhIAtqRE6DJin cl4L4Ub8SOMaXprr1Hvc8BN9KOB6cNfx/dSGUBMM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 25 Nov 2023 13:52:55 +0100 Subject: [PATCH RFC 6/7] treewide: sysctl: migrate proc_dobool to proc_handler_new MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231125-const-sysctl-v1-6-5e881b0e0290@weissschuh.net> References: <20231125-const-sysctl-v1-0-5e881b0e0290@weissschuh.net> In-Reply-To: <20231125-const-sysctl-v1-0-5e881b0e0290@weissschuh.net> To: Kees Cook , "Gustavo A. R. Silva" , Luis Chamberlain , Iurii Zaikin , Greg Kroah-Hartman , Joel Granados Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700916776; l=4649; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=eBhOR2st0kYur9zVJzF7EyOPAu0FRzljdghuY8XBOWo=; b=TFErwepsPpof08h6PaKYFgDvwr7V8L6MNxWawrT6FywU47nmnGgngRZWo7O9VIC6e33pJRYvE Sbzhxjkb1MYBkiG8Yh7Iyu7dSbhzCyWNshcdo390tV38npbE01v1uDT X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Sat, 25 Nov 2023 04:54:06 -0800 (PST) proc_handler_new() prevents the handler function from modifying the ctl_table which then can be put into .rodata. Signed-off-by: Thomas Weißschuh --- arch/riscv/kernel/vector.c | 2 +- drivers/tty/tty_io.c | 2 +- fs/lockd/svc.c | 2 +- fs/proc/proc_sysctl.c | 4 ++-- include/linux/sysctl.h | 2 +- kernel/sysctl.c | 4 ++-- mm/hugetlb_vmemmap.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index 578b6292487e..d2a37fe88174 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -253,7 +253,7 @@ static struct ctl_table riscv_v_default_vstate_table[] = { .data = &riscv_v_implicit_uacc, .maxlen = sizeof(riscv_v_implicit_uacc), .mode = 0644, - .proc_handler = proc_dobool, + .proc_handler_new = proc_dobool, }, }; diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 06414e43e0b5..a7bcc22fdae9 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3601,7 +3601,7 @@ static struct ctl_table tty_table[] = { .data = &tty_legacy_tiocsti, .maxlen = sizeof(tty_legacy_tiocsti), .mode = 0644, - .proc_handler = proc_dobool, + .proc_handler_new = proc_dobool, }, { .procname = "ldisc_autoload", diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c index 81be07c1d3d1..90ea8cd382d3 100644 --- a/fs/lockd/svc.c +++ b/fs/lockd/svc.c @@ -466,7 +466,7 @@ static struct ctl_table nlm_sysctls[] = { .data = &nsm_use_hostnames, .maxlen = sizeof(bool), .mode = 0644, - .proc_handler = proc_dobool, + .proc_handler_new = proc_dobool, }, { .procname = "nsm_local_state", diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 0817d315fa36..742a99540f2b 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1119,7 +1119,7 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table) err |= sysctl_err(path, table, "array not allowed"); } - if (table->proc_handler == proc_dobool) { + if (table->proc_handler_new == proc_dobool) { if (table->maxlen != sizeof(bool)) err |= sysctl_err(path, table, "array not allowed"); } @@ -1133,7 +1133,7 @@ static int sysctl_check_table(const char *path, struct ctl_table_header *header) int err = 0; list_for_each_table_entry(entry, header) { if ((entry->proc_handler_new == proc_dostring) || - (entry->proc_handler == proc_dobool) || + (entry->proc_handler_new == proc_dobool) || (entry->proc_handler == proc_dointvec) || (entry->proc_handler == proc_douintvec) || (entry->proc_handler == proc_douintvec_minmax) || diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 2699605c5da5..2dfaf718a21b 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -67,7 +67,7 @@ typedef int proc_handler_new(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos); int proc_dostring(const struct ctl_table *, int, void *, size_t *, loff_t *); -int proc_dobool(struct ctl_table *table, int write, void *buffer, +int proc_dobool(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos); int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *); int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 7acd1cde0a5c..c76668f47bcc 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -702,7 +702,7 @@ int do_proc_douintvec(struct ctl_table *table, int write, * * Returns 0 on success. */ -int proc_dobool(struct ctl_table *table, int write, void *buffer, +int proc_dobool(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { struct ctl_table tmp; @@ -1504,7 +1504,7 @@ int proc_dostring(const struct ctl_table *table, int write, return -ENOSYS; } -int proc_dobool(struct ctl_table *table, int write, +int proc_dobool(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { return -ENOSYS; diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 87818ee7f01d..e61e9fbfd639 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -779,7 +779,7 @@ static struct ctl_table hugetlb_vmemmap_sysctls[] = { .data = &vmemmap_optimize_enabled, .maxlen = sizeof(vmemmap_optimize_enabled), .mode = 0644, - .proc_handler = proc_dobool, + .proc_handler_new = proc_dobool, }, { } }; -- 2.43.0