From patchwork Sat Nov 25 12:52:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13468490 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="fztyoxz+" Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC742D3; Sat, 25 Nov 2023 04:52:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1700916776; bh=iUFGOwiGkTIEhre+odhGn4/1WdiJ+qVq49adTV3gQHM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fztyoxz+RxX7MwxRfaVFrpt8zAzdiGOJNQQaZ2liuOTEhZJSPtgzPDAwdy8d+nduu 6HIpQDcLALScEvSo3TB44K9Cg07c0e+d5EKM4CrbFZS+z4cX07Vb3ZYhQbCW8bF+IK CuVl6bAJigVYO1bVG73ZQ0PsCKDHyk2/sxUnLMcc= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 25 Nov 2023 13:52:50 +0100 Subject: [PATCH RFC 1/7] sysctl: add helper sysctl_run_handler Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231125-const-sysctl-v1-1-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=1484; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=iUFGOwiGkTIEhre+odhGn4/1WdiJ+qVq49adTV3gQHM=; b=Cv+9BCerGMTP/2lwcmiBVc/6/kwT01UgiJ38sgxdeBN+8Ofpm5XgsYBpLeAWweL5YsfOi/XO9 t1IRt8PjV7dBp1eb61hCnnM6/2qS3I9vKlVDUuz7KXnyXahSMJE7Xs2 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= A future patch will introduce a second handler function. To make the code future-proof add the sysctl_run_handler function that automatically can call the correct handler function. Signed-off-by: Thomas Weißschuh --- fs/proc/proc_sysctl.c | 2 +- include/linux/sysctl.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 8064ea76f80b..1bb0aa2ff501 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -597,7 +597,7 @@ static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter, goto out_free_buf; /* careful: calling conventions are nasty here */ - error = table->proc_handler(table, write, kbuf, &count, &iocb->ki_pos); + error = sysctl_run_handler(table, write, kbuf, &count, &iocb->ki_pos); if (error) goto out_free_buf; diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 61b40ea81f4d..604aaaa1fce2 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -298,4 +298,10 @@ static inline bool sysctl_is_alias(char *param) int sysctl_max_threads(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos); +static inline int sysctl_run_handler(struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + return ctl->proc_handler(ctl, write, buffer, lenp, ppos); +} + #endif /* _LINUX_SYSCTL_H */