From patchwork Tue Jan 4 15:50:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= X-Patchwork-Id: 12703603 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40D16C433F5 for ; Tue, 4 Jan 2022 15:45:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235016AbiADPpU (ORCPT ); Tue, 4 Jan 2022 10:45:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235057AbiADPpR (ORCPT ); Tue, 4 Jan 2022 10:45:17 -0500 Received: from smtp-42a8.mail.infomaniak.ch (smtp-42a8.mail.infomaniak.ch [IPv6:2001:1600:4:17::42a8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B29C061761 for ; Tue, 4 Jan 2022 07:45:15 -0800 (PST) Received: from smtp-2-0001.mail.infomaniak.ch (unknown [10.5.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4JSxlF1GWrzN3f1x; Tue, 4 Jan 2022 16:45:13 +0100 (CET) Received: from localhost (unknown [23.97.221.149]) by smtp-2-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4JSxlD5cMHzljsW5; Tue, 4 Jan 2022 16:45:12 +0100 (CET) From: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= To: Al Viro , Andrew Morton Cc: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , Alejandro Colomar , Aleksa Sarai , Andy Lutomirski , Arnd Bergmann , Casey Schaufler , Christian Brauner , Christian Heimes , Deven Bowers , Dmitry Vyukov , Eric Biggers , Eric Chiang , Florian Weimer , Geert Uytterhoeven , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Kees Cook , Lakshmi Ramasubramanian , Luis Chamberlain , "Madhavan T . Venkataraman" , Matthew Garrett , Matthew Wilcox , Miklos Szeredi , Mimi Zohar , Paul Moore , =?utf-8?q?Philippe_Tr=C3=A9buchet?= , Scott Shell , Shuah Khan , Stephen Rothwell , Steve Dower , Steve Grubb , Thibaut Sautereau , Vincent Strubel , Xiaoming Ni , Yin Fengwei , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= Subject: [PATCH v18 1/4] printk: Move back proc_dointvec_minmax_sysadmin() to sysctl.c Date: Tue, 4 Jan 2022 16:50:21 +0100 Message-Id: <20220104155024.48023-2-mic@digikod.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104155024.48023-1-mic@digikod.net> References: <20220104155024.48023-1-mic@digikod.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Mickaël Salaün The proc_dointvec_minmax_sysadmin() helper is useful for the fs.trusted_for_policy sysctl brought by the next commit. This partially revert commit 642fd23fb826 ("printk: move printk sysctl to printk/sysctl.c") from Luis Chamberlain's 20211129-sysctl-cleanups branch [1], to share the proc_dointvec_minmax_sysadmin() helper. FYI, this previous commit also got the buffer pointer an __user attribute. Also remove the forgotten ten_thousand static variable (moved to kernel/printk/sysctl.c). Link: https://lkml.kernel.org/r/20211124231435.1445213-6-mcgrof@kernel.org [1] Cc: Al Viro Cc: Andrew Morton Cc: Luis Chamberlain Cc: Xiaoming Ni Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20220104155024.48023-2-mic@digikod.net --- include/linux/sysctl.h | 2 ++ kernel/printk/sysctl.c | 9 --------- kernel/sysctl.c | 9 +++++++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 180adf7da785..cf1ba98aab50 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -69,6 +69,8 @@ int proc_dobool(struct ctl_table *table, int write, void *buffer, int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *); int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *); int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *); +int proc_dointvec_minmax_sysadmin(struct ctl_table *, int, void *, size_t *, + loff_t *); int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos); int proc_dou8vec_minmax(struct ctl_table *table, int write, void *buffer, diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c index 653ae04aab7f..c7129428ee9b 100644 --- a/kernel/printk/sysctl.c +++ b/kernel/printk/sysctl.c @@ -11,15 +11,6 @@ static const int ten_thousand = 10000; -static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos) -{ - if (write && !capable(CAP_SYS_ADMIN)) - return -EPERM; - - return proc_dointvec_minmax(table, write, buffer, lenp, ppos); -} - static struct ctl_table printk_sysctls[] = { { .procname = "printk", diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 5ae443b2882e..2e2027e323fd 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -888,6 +888,15 @@ static int proc_taint(struct ctl_table *table, int write, return err; } +int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos) +{ + if (write && !capable(CAP_SYS_ADMIN)) + return -EPERM; + + return proc_dointvec_minmax(table, write, buffer, lenp, ppos); +} + /** * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure * @min: pointer to minimum allowable value