From patchwork Thu Mar 2 20:28:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157825 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 240FFC6FA8E for ; Thu, 2 Mar 2023 20:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbjCBU3X (ORCPT ); Thu, 2 Mar 2023 15:29:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbjCBU3P (ORCPT ); Thu, 2 Mar 2023 15:29:15 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66E161A96D; Thu, 2 Mar 2023 12:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=xBLSlmQtAyz0qvRsNFvWuwWpKiVVHBEV1aJjBlE0tQE=; b=4T8dlcCaoBdPNTMUrPR4ZbnWKQ U/IiQYDF39ySJMrN6t8k85pINxzuzMBynHpatoaVq6IXt382QmOz4MCgHXk4gQyssT+L2V6r2Xgp0 mHMRuBldnqbFgWlOBCQJ3Wr1Se7TbGQGcfyx4FUCT8tHP9Yz7384pJlViVAMhMm1yVlDrykvbhx8A oDhxb2B5OrxGxRGCsnlNBqirlR8fG48v1/jZurECPr7nqG8Ax/uhyLvYwpFRcqf/eGQvfIOCYuLVY kjnFShUFiauUdPpIKvVPSmPerkyLZy0SUhMx1g5sR934vN3pnwjtbVdx3dtsOvNTV+bIB+yvThhWJ e44/VfRA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXR-003Fx9-Rz; Thu, 02 Mar 2023 20:28:29 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 01/11] proc_sysctl: update docs for __register_sysctl_table() Date: Thu, 2 Mar 2023 12:28:16 -0800 Message-Id: <20230302202826.776286-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Update the docs for __register_sysctl_table() to make it clear no child entries can be passed. When the child is true these are non-leaf entries on the ctl table and sysctl treats these as directories. The point to __register_sysctl_table() is to deal only with directories not part of the ctl table where thay may riside, to be simple and avoid recursion. While at it, hint towards using long on extra1 and extra2 later. Signed-off-by: Luis Chamberlain --- fs/proc/proc_sysctl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 5851eb5bc726..1df0beb50dbe 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1287,7 +1287,7 @@ static int insert_links(struct ctl_table_header *head) * __register_sysctl_table - register a leaf sysctl table * @set: Sysctl tree to register on * @path: The path to the directory the sysctl table is in. - * @table: the top-level table structure + * @table: the top-level table structure without any child * * Register a sysctl table hierarchy. @table should be a filled in ctl_table * array. A completely 0 filled entry terminates the table. @@ -1308,9 +1308,12 @@ static int insert_links(struct ctl_table_header *head) * proc_handler - the text handler routine (described below) * * extra1, extra2 - extra pointers usable by the proc handler routines + * XXX: we should eventually modify these to use long min / max [0] + * [0] https://lkml.kernel.org/87zgpte9o4.fsf@email.froward.int.ebiederm.org * * Leaf nodes in the sysctl tree will be represented by a single file - * under /proc; non-leaf nodes will be represented by directories. + * under /proc; non-leaf nodes (where child is not NULL) are not allowed, + * sysctl_check_table() verifies this. * * There must be a proc_handler routine for any terminal nodes. * Several default handlers are available to cover common cases - @@ -1352,7 +1355,7 @@ struct ctl_table_header *__register_sysctl_table( spin_lock(&sysctl_lock); dir = &set->dir; - /* Reference moved down the diretory tree get_subdir */ + /* Reference moved down the directory tree get_subdir */ dir->header.nreg++; spin_unlock(&sysctl_lock); @@ -1369,6 +1372,11 @@ struct ctl_table_header *__register_sysctl_table( if (namelen == 0) continue; + /* + * namelen ensures if name is "foo/bar/yay" only foo is + * registered first. We traverse as if using mkdir -p and + * return a ctl_dir for the last directory entry. + */ dir = get_subdir(dir, name, namelen); if (IS_ERR(dir)) goto fail; From patchwork Thu Mar 2 20:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157819 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 C9BD2C6FA8E for ; Thu, 2 Mar 2023 20:29:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbjCBU3N (ORCPT ); Thu, 2 Mar 2023 15:29:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbjCBU3M (ORCPT ); Thu, 2 Mar 2023 15:29:12 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5162A1A96D; Thu, 2 Mar 2023 12:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=/B53CtexeyD9Bd10s0zaJAUsHZrSjOaoezyvPxx8LTk=; b=kRovkSM5K1GhgJjJe0utOQ9MZY hpy6mdK+hdW7jylca3OqRuGOqomE9o3CJgh4EGuz6lp4VM+DigRs+oMJLZbx1vPfYAJGYvE/AZwdR zZMqIaZw9YNZrnir2UYXxGBYxi/AOSq6sF5ZDXLpiyr8lp6UjqhN/VKoOTg8OCGk9qa6qaxPQ/cFv /zAiY16rKO6TLzH1g2wL004PtEqFK9PR7b5zQiS749hfGIwUIGGJkzbEseFVd7V08//at3INtBAsB ehall8mmM0GZyxzilQRwnIGiLlRqdOFLBF5J1OIcHnXiivobw3jlcxCB7V9Z2lFMd/l7y5EuA2dCg f+aooOFA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXR-003FxB-Uq; Thu, 02 Mar 2023 20:28:29 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 02/11] proc_sysctl: move helper which creates required subdirectories Date: Thu, 2 Mar 2023 12:28:17 -0800 Message-Id: <20230302202826.776286-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Move the code which creates the subdirectories for a ctl table into a helper routine so to make it easier to review. Document the goal. This creates no functional changes. Signed-off-by: Luis Chamberlain Reviewed-by: John Johansen --- fs/proc/proc_sysctl.c | 56 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 1df0beb50dbe..6b9b2694d430 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1283,6 +1283,35 @@ static int insert_links(struct ctl_table_header *head) return err; } +/* Find the directory for the ctl_table. If one is not found create it. */ +static struct ctl_dir *sysctl_mkdir_p(struct ctl_dir *dir, const char *path) +{ + const char *name, *nextname; + + for (name = path; name; name = nextname) { + int namelen; + nextname = strchr(name, '/'); + if (nextname) { + namelen = nextname - name; + nextname++; + } else { + namelen = strlen(name); + } + if (namelen == 0) + continue; + + /* + * namelen ensures if name is "foo/bar/yay" only foo is + * registered first. We traverse as if using mkdir -p and + * return a ctl_dir for the last directory entry. + */ + dir = get_subdir(dir, name, namelen); + if (IS_ERR(dir)) + break; + } + return dir; +} + /** * __register_sysctl_table - register a leaf sysctl table * @set: Sysctl tree to register on @@ -1334,7 +1363,6 @@ struct ctl_table_header *__register_sysctl_table( { struct ctl_table_root *root = set->dir.header.root; struct ctl_table_header *header; - const char *name, *nextname; struct ctl_dir *dir; struct ctl_table *entry; struct ctl_node *node; @@ -1359,29 +1387,9 @@ struct ctl_table_header *__register_sysctl_table( dir->header.nreg++; spin_unlock(&sysctl_lock); - /* Find the directory for the ctl_table */ - for (name = path; name; name = nextname) { - int namelen; - nextname = strchr(name, '/'); - if (nextname) { - namelen = nextname - name; - nextname++; - } else { - namelen = strlen(name); - } - if (namelen == 0) - continue; - - /* - * namelen ensures if name is "foo/bar/yay" only foo is - * registered first. We traverse as if using mkdir -p and - * return a ctl_dir for the last directory entry. - */ - dir = get_subdir(dir, name, namelen); - if (IS_ERR(dir)) - goto fail; - } - + dir = sysctl_mkdir_p(dir, path); + if (IS_ERR(dir)) + goto fail; spin_lock(&sysctl_lock); if (insert_header(dir, header)) goto fail_put_dir_locked; From patchwork Thu Mar 2 20:28:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157828 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 6407FC7EE43 for ; Thu, 2 Mar 2023 20:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbjCBU3s (ORCPT ); Thu, 2 Mar 2023 15:29:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230076AbjCBU30 (ORCPT ); Thu, 2 Mar 2023 15:29:26 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B25C81E5D1; Thu, 2 Mar 2023 12:29:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Twn8MQ1Gcyzszq3QMuH8qlsxJH8SeLsz2Z/0dFs1T4k=; b=OcKK2q+bPChjV8lLm8hD8AxY/r 0ZovvoOZyeZWiN66xALTlkMSscbzMU03wN2Numi+F46tX1ap0g9sJmBv8Vf2/tFtlHSaGnf8vY1Iq OWJZu6BWsKEm0gwUWsNQtpbPMSinmD3Sd4Wf+VCgJqs72vkHGe5kr0edfkTfwCjcFQxx4yTjYSN5L 4T2Zq+MUsJ1tcSPlT3LJEBjnctee8Tn0g+giVPsQH2/KO3gYJSaf12NznKHR3fgF0pJh4TNcCwyts 0ggEuqJC5rprNeKbjssHjNnzh4wdI8cykjd8bxvzx6Yx+oxPQ/yvC+38szw8Mk7St5joqEuNvKKXI 3NnI8Vdw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxD-1R; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 03/11] sysctl: clarify register_sysctl_init() base directory order Date: Thu, 2 Mar 2023 12:28:18 -0800 Message-Id: <20230302202826.776286-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Relatively new docs which I added which hinted the base directories needed to be created before is wrong, remove that incorrect comment. This has been hinted before by Eric twice already [0] [1], I had just not verified that until now. Now that I've verified that updates the docs to relax the context described. [0] https://lkml.kernel.org/r/875ys0azt8.fsf@email.froward.int.ebiederm.org [1] https://lkml.kernel.org/r/87ftbiud6s.fsf@x220.int.ebiederm.org Suggested-by: Eric W. Biederman Signed-off-by: Luis Chamberlain --- fs/proc/proc_sysctl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 6b9b2694d430..15d5e02f1ec0 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1440,10 +1440,7 @@ EXPORT_SYMBOL(register_sysctl); * register_sysctl() failing on init are extremely low, and so for both reasons * this function does not return any error as it is used by initialization code. * - * Context: Can only be called after your respective sysctl base path has been - * registered. So for instance, most base directories are registered early on - * init before init levels are processed through proc_sys_init() and - * sysctl_init_bases(). + * Context: if your base directory does not exist it will be created for you. */ void __init __register_sysctl_init(const char *path, struct ctl_table *table, const char *table_name) From patchwork Thu Mar 2 20:28:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157824 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 F249CC678D4 for ; Thu, 2 Mar 2023 20:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbjCBU3W (ORCPT ); Thu, 2 Mar 2023 15:29:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbjCBU3P (ORCPT ); Thu, 2 Mar 2023 15:29:15 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 535CE1A969; Thu, 2 Mar 2023 12:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=aQxjJTI+/dgkfmOIkPQGBpoNeT0L25JfaRzqJBNjzfI=; b=M9Ls3cLPjLxNw64e3/lgGKMi96 8TAGSLVibINE1yswDzR8JzobcbigsqbuREDkc+CYrF+RiHQSMgAmf6yrV1lO4kjZ2FzXnswl3+03A fcXNLxcyw8wBceOCZgds3wn3ORO7gc72kXSfmwu1mIvI/VrkdFToLXMUmTN/4AFfj8FMxmgxKCTlW a2hz5P4cP+sg7uV9qEpfkZGPF+NtATW9+gSwUB4XXxjdkzh/W3WwvSlZt9iJNRHdedq1LxFqmXf7F v2p6ZK6mtaRZOj4/WdAkAizmAIpcCkvVRU8DvSY2i5CXtjK6tQvdpqTDANTTSQUtTD/eXXdsfuX5j +pvTdI2g==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxF-4H; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 04/11] apparmor: simplify sysctls with register_sysctl_init() Date: Thu, 2 Mar 2023 12:28:19 -0800 Message-Id: <20230302202826.776286-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Using register_sysctl_paths() is really only needed if you have subdirectories with entries. We can use the simple register_sysctl() instead. Signed-off-by: Luis Chamberlain Reviewed-by: Georgia Garcia Acked-by: John Johansen --- security/apparmor/lsm.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index d6cc4812ca53..47c7ec7e5a80 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1764,11 +1764,6 @@ static int apparmor_dointvec(struct ctl_table *table, int write, return proc_dointvec(table, write, buffer, lenp, ppos); } -static struct ctl_path apparmor_sysctl_path[] = { - { .procname = "kernel", }, - { } -}; - static struct ctl_table apparmor_sysctl_table[] = { { .procname = "unprivileged_userns_apparmor_policy", @@ -1790,8 +1785,7 @@ static struct ctl_table apparmor_sysctl_table[] = { static int __init apparmor_init_sysctl(void) { - return register_sysctl_paths(apparmor_sysctl_path, - apparmor_sysctl_table) ? 0 : -ENOMEM; + return register_sysctl("kernel", apparmor_sysctl_table) ? 0 : -ENOMEM; } #else static inline int apparmor_init_sysctl(void) From patchwork Thu Mar 2 20:28:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157829 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 294E5C7EE33 for ; Thu, 2 Mar 2023 20:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbjCBU3t (ORCPT ); Thu, 2 Mar 2023 15:29:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbjCBU3R (ORCPT ); Thu, 2 Mar 2023 15:29:17 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F22062DE64; Thu, 2 Mar 2023 12:29:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=WXKrajJbqkbUb299wVP+wMZwzux4ve5i7i48jqTzVOM=; b=3AqsqJI8lCaM8wKT1MeU5adKVx yZUVeEU7kgWNaQDeh/xzFucDN4Eo2WI0oQhEQtYjLrZzlxLm/K6EgYpusTJvObavKIQq5OQ7/aGV6 P2qhNLsnCTtYcoT2Gq6mV8hgc9pqnjQJyJPPBTxPS6+CxINAW06uYQhM/r+B2a+rTf1gZC3ORUVpl SFWiS9VweZ2Oedn5boZUmx5k9N3jEUYi+qIyoewiOXydRoabiTbtzYKZ6ihTguLW4MLFxkxmc2Cnx 42fqvnsTQpDvHVmGcTxt7SbWhhrBrKOXofmIibo3iaW6acX0VORs7MqgDieHMi6lTGwAMqQNMKExv jE531YOQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxH-71; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 05/11] loadpin: simplify sysctls use with register_sysctl() Date: Thu, 2 Mar 2023 12:28:20 -0800 Message-Id: <20230302202826.776286-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org register_sysctl_paths() is not required, we can just use register_sysctl() with the required path specified. Signed-off-by: Luis Chamberlain Acked-by: Kees Cook Reviewed-by: John Johansen --- security/loadpin/loadpin.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c index d73a281adf86..c971464b4ad5 100644 --- a/security/loadpin/loadpin.c +++ b/security/loadpin/loadpin.c @@ -52,12 +52,6 @@ static bool deny_reading_verity_digests; #endif #ifdef CONFIG_SYSCTL -static struct ctl_path loadpin_sysctl_path[] = { - { .procname = "kernel", }, - { .procname = "loadpin", }, - { } -}; - static struct ctl_table loadpin_sysctl_table[] = { { .procname = "enforce", @@ -262,7 +256,7 @@ static int __init loadpin_init(void) enforce ? "" : "not "); parse_exclude(); #ifdef CONFIG_SYSCTL - if (!register_sysctl_paths(loadpin_sysctl_path, loadpin_sysctl_table)) + if (!register_sysctl("kernel/loadpin", loadpin_sysctl_table)) pr_notice("sysctl registration failed!\n"); #endif security_add_hooks(loadpin_hooks, ARRAY_SIZE(loadpin_hooks), "loadpin"); From patchwork Thu Mar 2 20:28:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157823 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 EFA52C7EE39 for ; Thu, 2 Mar 2023 20:29:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbjCBU3U (ORCPT ); Thu, 2 Mar 2023 15:29:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjCBU3Q (ORCPT ); Thu, 2 Mar 2023 15:29:16 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68D821ABDC; Thu, 2 Mar 2023 12:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=H2cUIW21WZq17g9O2oNgRsa778WFbjBOimotIrmyA/E=; b=nNmP8ACa3bYQFO+va5O1HA9FsY 7uEoxbwqkYk/qt113tW2SYA9YMG3a2AHu8L7Iv3iQ0EMlgc7BBKKyksmjuEvEnZO0sSPh+srw21Ed 92vGNiItW9t2AeJ5aH7Je//Kla0sYsQd6yw57DZXv4g5YLEqNM5fx8BqApdQ2WOzt1ETsFacehG28 1v5ozP5b85IjoFEOhl2RVeEKNDt9QH7O2q/lI+HC3DfepUovBBCkaCjB4ahImpZOYcj2qeiGF+SSR bKm0l0YVBiFRo1VjmJYCVnVBvM6yvLikEV5zJHWv1DMHYb3GMsppkfKWHIApcwT0D+DZwuAqLb0xi hYGi9dkg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxJ-9n; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 06/11] yama: simplfy sysctls with register_sysctl() Date: Thu, 2 Mar 2023 12:28:21 -0800 Message-Id: <20230302202826.776286-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org register_sysctl_paths() is only need if you have directories with entries, simplify this by using register_sysctl(). Signed-off-by: Luis Chamberlain Acked-by: Kees Cook --- security/yama/yama_lsm.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index 06e226166aab..90dd012b0db5 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c @@ -447,12 +447,6 @@ static int yama_dointvec_minmax(struct ctl_table *table, int write, static int max_scope = YAMA_SCOPE_NO_ATTACH; -static struct ctl_path yama_sysctl_path[] = { - { .procname = "kernel", }, - { .procname = "yama", }, - { } -}; - static struct ctl_table yama_sysctl_table[] = { { .procname = "ptrace_scope", @@ -467,7 +461,7 @@ static struct ctl_table yama_sysctl_table[] = { }; static void __init yama_init_sysctl(void) { - if (!register_sysctl_paths(yama_sysctl_path, yama_sysctl_table)) + if (!register_sysctl("kernel/yama", yama_sysctl_table)) panic("Yama: sysctl registration failed.\n"); } #else From patchwork Thu Mar 2 20:28:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157826 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 E14D1C678D4 for ; Thu, 2 Mar 2023 20:29:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjCBU3a (ORCPT ); Thu, 2 Mar 2023 15:29:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229970AbjCBU3Q (ORCPT ); Thu, 2 Mar 2023 15:29:16 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4A4C2202D; Thu, 2 Mar 2023 12:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=+Hoy53VeqZDOL/t9ch2P6jt/ahEQQ6UBHYjZPmP5kVI=; b=Pc795+UC8GmLBrVgybdkFp55Y8 315+vdPN8i3iM63aUS7f+Bs9nYk0siO1Smy4WXyTKX4WnXYTW317Ls+MdoHwjPtaJBBNrmkKmrRIZ KHYF0wDjJ9lM0uHA+Yoa5IWrsNzTN0F5G24GFM0fnpK94APmt7QI6hLGYvl6S5RM9LQx7qtZzAJ1a wo+xnJLrUNLJLtoY4EOjzj1p9mOCpV+GCulivVw8EcDbsAKVp7urur1hSh0wTy0UyyHkfajf7F0Yc u6Y+2ntmlAtdyf/PeyB09Rnt5PWHWHN3RIoFE1e6NjYSeBtRijn7YFOFzIRKFO2ougvtK7txbQ6y2 piHryISw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxL-Ca; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 07/11] seccomp: simplify sysctls with register_sysctl_init() Date: Thu, 2 Mar 2023 12:28:22 -0800 Message-Id: <20230302202826.776286-8-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org register_sysctl_paths() is only needed if you have childs (directories) with entries. Just use register_sysctl_init() as it also does the kmemleak check for you. Signed-off-by: Luis Chamberlain Acked-by: Kees Cook --- kernel/seccomp.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index cebf26445f9e..d3e584065c7f 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -2368,12 +2368,6 @@ static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write, return ret; } -static struct ctl_path seccomp_sysctl_path[] = { - { .procname = "kernel", }, - { .procname = "seccomp", }, - { } -}; - static struct ctl_table seccomp_sysctl_table[] = { { .procname = "actions_avail", @@ -2392,14 +2386,7 @@ static struct ctl_table seccomp_sysctl_table[] = { static int __init seccomp_sysctl_init(void) { - struct ctl_table_header *hdr; - - hdr = register_sysctl_paths(seccomp_sysctl_path, seccomp_sysctl_table); - if (!hdr) - pr_warn("sysctl registration failed\n"); - else - kmemleak_not_leak(hdr); - + register_sysctl_init("kernel/seccomp", seccomp_sysctl_table); return 0; } From patchwork Thu Mar 2 20:28:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157827 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 94322C7EE37 for ; Thu, 2 Mar 2023 20:29:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbjCBU3n (ORCPT ); Thu, 2 Mar 2023 15:29:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbjCBU3S (ORCPT ); Thu, 2 Mar 2023 15:29:18 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A1032ED54; Thu, 2 Mar 2023 12:29:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Bays9fkBFms7vhPJoOG9l9IJ7nM/VsUcupIDAJVjf80=; b=Bz1QvwzCl7hRI0wtSOphGbHAjd moIi7Iqb1DdJU55W/01ooclWjla3NRkjZN8KVAJTjDnBHx56pp6jV+k/vQDQHDlEEGrYiKd97L8hf ciLumPQjTGpY60IvmgF2Vhq4jHu1hyB1Sd5I5mYi26CzS2nijc5XMgeu7qQ/aDRk8PAiyFPygV9uX 6zDAhjyOF+7Gd7zpEiaaYWe+ZssvpcYMJmYAdwPvLSFQdFZ7I+qjgHnnpJ25RXsLmk0te+Fc+WTrC nB/zhVB0QfdOUAmrW8bGzZmKaXOthdUTNfbaGIEJS/3ZbCBqtLS1H2j1MJd2kdm1R54lAjRnPe8YS fmBJaTKA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxN-Eb; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 08/11] kernel: pid_namespace: simplify sysctls with register_sysctl() Date: Thu, 2 Mar 2023 12:28:23 -0800 Message-Id: <20230302202826.776286-9-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org register_sysctl_paths() is only required if your child (directories) have entries and pid_namespace does not. So use register_sysctl_init() instead where we don't care about the return value and use register_sysctl() where we do. Signed-off-by: Luis Chamberlain Acked-by: Jeff Xu --- kernel/pid_namespace.c | 3 +-- kernel/pid_sysctl.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 46e0d5a3f91f..b43eee07b00c 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -314,7 +314,6 @@ static struct ctl_table pid_ns_ctl_table[] = { }, { } }; -static struct ctl_path kern_path[] = { { .procname = "kernel", }, { } }; #endif /* CONFIG_CHECKPOINT_RESTORE */ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) @@ -473,7 +472,7 @@ static __init int pid_namespaces_init(void) pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC | SLAB_ACCOUNT); #ifdef CONFIG_CHECKPOINT_RESTORE - register_sysctl_paths(kern_path, pid_ns_ctl_table); + register_sysctl_init("kernel", pid_ns_ctl_table); #endif register_pid_ns_sysctl_table_vm(); diff --git a/kernel/pid_sysctl.h b/kernel/pid_sysctl.h index e22d072e1e24..d67a4d45bb42 100644 --- a/kernel/pid_sysctl.h +++ b/kernel/pid_sysctl.h @@ -46,10 +46,9 @@ static struct ctl_table pid_ns_ctl_table_vm[] = { }, { } }; -static struct ctl_path vm_path[] = { { .procname = "vm", }, { } }; static inline void register_pid_ns_sysctl_table_vm(void) { - register_sysctl_paths(vm_path, pid_ns_ctl_table_vm); + register_sysctl("vm", pid_ns_ctl_table_vm); } #else static inline void initialize_memfd_noexec_scope(struct pid_namespace *ns) {} From patchwork Thu Mar 2 20:28:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157820 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 78352C678D4 for ; Thu, 2 Mar 2023 20:29:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbjCBU3P (ORCPT ); Thu, 2 Mar 2023 15:29:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbjCBU3N (ORCPT ); Thu, 2 Mar 2023 15:29:13 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0456A19683; Thu, 2 Mar 2023 12:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=G2dvxuEO3y0hAzFqFB/q2zGbeQi/W5a2UeiLF5jk9G8=; b=dz5ZgYi0lmfMYDtwxeNMmARonM bGKbYQrkx2v9+PjH3cal0POP2lH7QGVLsumOWP5m4oUHoTA4tIZoVq7nwf0xv3F6KIvgMiPJMu7+X 0o4Ko9mOYbBvD5AZjAIbXFyfIT0A4CrDKfVULMACnA2mIezbuYKLOyERcRHU1l583qQiZKfSePJCa 2LZXJSBJ64TQkJvCq0UqFAQE0p8uE6dgsv9fOAtyT8N4BZwVtUmdFZ6E1TuDrwoCDowsHQs5L35h7 hXz+2zE/s6nLemRtxxIDFJFMoyFobXifCqs8HoANisI/dBldTE+xmMW0dpM22OOEdTizcKnhRDGdg 8G5txOUA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxP-Gb; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 09/11] fs-verity: simplify sysctls with register_sysctl() Date: Thu, 2 Mar 2023 12:28:24 -0800 Message-Id: <20230302202826.776286-10-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org register_sysctl_paths() is only needed if your child (directories) have entries but this does not so just use register_sysctl() so to do away with the path specification. Signed-off-by: Luis Chamberlain --- fs/verity/signature.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/fs/verity/signature.c b/fs/verity/signature.c index e7d3ca919a1e..b8c51ad40d3a 100644 --- a/fs/verity/signature.c +++ b/fs/verity/signature.c @@ -88,12 +88,6 @@ int fsverity_verify_signature(const struct fsverity_info *vi, #ifdef CONFIG_SYSCTL static struct ctl_table_header *fsverity_sysctl_header; -static const struct ctl_path fsverity_sysctl_path[] = { - { .procname = "fs", }, - { .procname = "verity", }, - { } -}; - static struct ctl_table fsverity_sysctl_table[] = { { .procname = "require_signatures", @@ -109,8 +103,7 @@ static struct ctl_table fsverity_sysctl_table[] = { static int __init fsverity_sysctl_init(void) { - fsverity_sysctl_header = register_sysctl_paths(fsverity_sysctl_path, - fsverity_sysctl_table); + fsverity_sysctl_header = register_sysctl("fs/verity", fsverity_sysctl_table); if (!fsverity_sysctl_header) { pr_err("sysctl registration failed!\n"); return -ENOMEM; From patchwork Thu Mar 2 20:28:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157822 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 12509C7EE45 for ; Thu, 2 Mar 2023 20:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjCBU3T (ORCPT ); Thu, 2 Mar 2023 15:29:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbjCBU3Q (ORCPT ); Thu, 2 Mar 2023 15:29:16 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5830A19F35; Thu, 2 Mar 2023 12:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=HudEwxK4LxjEbcX61XhJokDY+tUfMk0/fd7PxDNcDCE=; b=P8dofZ6rdK4Re2PjCV19YaCRW9 Dtf2EhtYU92txmayFoU3Ntggo+CVRTt7tPZP04nR23G2ZKUznaTDWlmNm+N41EYbpYsreJ6QWU0dd H7Q3JpaAzLWd2+gc9QduwlwxocaYhfEDjw/KmpIBV81LTBRG2HAVG1/44e3rJA2jJ672uR8Zh/XEF YOZH7e0ncbWHwEpumBjLvR5QW75JM9mdyfXylHusHgm4l+vc+I92tDx0ZElDm0lnK4iTBUUqafdwC EMPEhMOEe7SnM5PHQ0jzTvOvbzt7nG9/3wWlWfupXUvp4CrqR7zPfYC6VoRJBhADapyST8phjyXMD yOozgATg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxR-Ia; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 10/11] csky: simplify alignment sysctl registration Date: Thu, 2 Mar 2023 12:28:25 -0800 Message-Id: <20230302202826.776286-11-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Using register_sysctl_paths() is only required if we are using leafs with entries but all we are doing is creates leafs with just one leaf and then entries and register_sysctl_init() works well with that already. The 555 permission is already retained by the new_dir() proc sysctl directory creator. Signed-off-by: Luis Chamberlain --- arch/csky/abiv1/alignment.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/arch/csky/abiv1/alignment.c b/arch/csky/abiv1/alignment.c index 2df115d0e210..b60259daed1b 100644 --- a/arch/csky/abiv1/alignment.c +++ b/arch/csky/abiv1/alignment.c @@ -332,22 +332,9 @@ static struct ctl_table alignment_tbl[5] = { {} }; -static struct ctl_table sysctl_table[2] = { - { - .procname = "csky_alignment", - .mode = 0555, - .child = alignment_tbl}, - {} -}; - -static struct ctl_path sysctl_path[2] = { - {.procname = "csky"}, - {} -}; - static int __init csky_alignment_init(void) { - register_sysctl_paths(sysctl_path, sysctl_table); + register_sysctl_init("csky/csky_alignment", alignment_tbl); return 0; } From patchwork Thu Mar 2 20:28:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13157821 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 14F68C6FA8E for ; Thu, 2 Mar 2023 20:29:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjCBU3R (ORCPT ); Thu, 2 Mar 2023 15:29:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjCBU3O (ORCPT ); Thu, 2 Mar 2023 15:29:14 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A7F199FC; Thu, 2 Mar 2023 12:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=wgFqT2w/eK3dzdLgYbGtjhgywFNrzKWQTAiGgoTWdic=; b=zuz/8Msfgxa1qz/+0bvXQ8D3Dp E3r+AMFHIPNG69xjYkIr9FvCfgMSUDnVjlJT4SOx0FFzkxlUeu+75oiSFUOzzw/QtZi8iGr0sllE4 /BdnnxIPUFFxPl9MpfNst/iqR18werqw5FZ2dDHaUZ1Ooj9cCZLhyJPoVn+xk8AunsF3x7UMGgb9G XPHI5mus6/eMOr8SqayIwWTq5KMJ3EynxiojmBY+kt8Q5rXJ3xVd54ebBq7uFJgZgjWXUwxJpzKdy 1P4naZHSWeF6x1Q9wk9JuoR8linxmXFjFNARUmAUNpYdIIdUlr3gyM+cQT1mytSJEYpjCSRuJQWJs x/LSF5Pw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXpXS-003FxT-Kb; Thu, 02 Mar 2023 20:28:30 +0000 From: Luis Chamberlain To: ebiederm@xmission.com, keescook@chromium.org, yzaikin@google.com, john.johansen@canonical.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, luto@amacapital.net, wad@chromium.org, dverkamp@chromium.org, paulmck@kernel.org, baihaowen@meizu.com, frederic@kernel.org, jeffxu@google.com, ebiggers@kernel.org, tytso@mit.edu, guoren@kernel.org Cc: j.granados@samsung.com, zhangpeng362@huawei.com, tangmeng@uniontech.com, willy@infradead.org, nixiaoming@huawei.com, sujiaxun@uniontech.com, patches@lists.linux.dev, linux-fsdevel@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 11/11] proc_sysctl: deprecate register_sysctl_paths() Date: Thu, 2 Mar 2023 12:28:26 -0800 Message-Id: <20230302202826.776286-12-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302202826.776286-1-mcgrof@kernel.org> References: <20230302202826.776286-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Now that all users are removed, drop the export for register_sysctl_paths() Signed-off-by: Luis Chamberlain --- fs/proc/proc_sysctl.c | 30 +++++++++--------------------- include/linux/sysctl.h | 11 ----------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 15d5e02f1ec0..ff06434f7be1 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1486,6 +1486,7 @@ static int count_subheaders(struct ctl_table *table) return nr_subheaders + has_files; } +/* Note: this can recurse and call itself when dealing with subdirectories */ static int register_leaf_sysctl_tables(const char *path, char *pos, struct ctl_table_header ***subheader, struct ctl_table_set *set, struct ctl_table *table) @@ -1571,9 +1572,10 @@ static int register_leaf_sysctl_tables(const char *path, char *pos, * Register a sysctl table hierarchy. @table should be a filled in ctl_table * array. A completely 0 filled entry terminates the table. * - * See __register_sysctl_table for more details. + * See __register_sysctl_table for more details. This routine can + * recurse by having register_leaf_sysctl_tables() call itself. */ -struct ctl_table_header *__register_sysctl_paths( +static struct ctl_table_header *__register_sysctl_paths( struct ctl_table_set *set, const struct ctl_path *path, struct ctl_table *table) { @@ -1613,6 +1615,7 @@ struct ctl_table_header *__register_sysctl_paths( subheader = subheaders; header->ctl_table_arg = ctl_table_arg; + /* this can recurse */ if (register_leaf_sysctl_tables(new_path, pos, &subheader, set, table)) goto err_register_leaves; @@ -1635,37 +1638,22 @@ struct ctl_table_header *__register_sysctl_paths( } /** - * register_sysctl_paths - register a sysctl table hierarchy - * @path: The path to the directory the sysctl table is in. + * register_sysctl_table - register a sysctl table hierarchy * @table: the top-level table structure * * Register a sysctl table hierarchy. @table should be a filled in ctl_table * array. A completely 0 filled entry terminates the table. * * See __register_sysctl_paths for more details. - */ -struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, - struct ctl_table *table) -{ - return __register_sysctl_paths(&sysctl_table_root.default_set, - path, table); -} -EXPORT_SYMBOL(register_sysctl_paths); - -/** - * register_sysctl_table - register a sysctl table hierarchy - * @table: the top-level table structure - * - * Register a sysctl table hierarchy. @table should be a filled in ctl_table - * array. A completely 0 filled entry terminates the table. * - * See register_sysctl_paths for more details. + * This is a deprecated compatibility wrapper. You should avoid adding new + * users of this into the kernel. */ struct ctl_table_header *register_sysctl_table(struct ctl_table *table) { static const struct ctl_path null_path[] = { {} }; - return register_sysctl_paths(null_path, table); + return __register_sysctl_paths(&sysctl_table_root.default_set, null_path, table); } EXPORT_SYMBOL(register_sysctl_table); diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 780690dc08cd..e8459fc56b50 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -221,13 +221,8 @@ extern void retire_sysctl_set(struct ctl_table_set *set); struct ctl_table_header *__register_sysctl_table( struct ctl_table_set *set, const char *path, struct ctl_table *table); -struct ctl_table_header *__register_sysctl_paths( - struct ctl_table_set *set, - const struct ctl_path *path, struct ctl_table *table); struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table); struct ctl_table_header *register_sysctl_table(struct ctl_table * table); -struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, - struct ctl_table *table); void unregister_sysctl_table(struct ctl_table_header * table); @@ -277,12 +272,6 @@ static inline struct ctl_table_header *register_sysctl_mount_point(const char *p return NULL; } -static inline struct ctl_table_header *register_sysctl_paths( - const struct ctl_path *path, struct ctl_table *table) -{ - return NULL; -} - static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table) { return NULL;