Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2548195rdb; Sun, 3 Dec 2023 23:54:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNh2fVcA/x6nuRekRhB8ByetXY069c8p2ZWJAoeuqYEjEvb/ClaYsZn1zGHPBs6s10Uxau X-Received: by 2002:a05:6a00:3310:b0:6ce:38a2:c5d9 with SMTP id cq16-20020a056a00331000b006ce38a2c5d9mr3493423pfb.26.1701676449329; Sun, 03 Dec 2023 23:54:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701676449; cv=none; d=google.com; s=arc-20160816; b=heBpM2TcLFs8y7h4FsA3gPoIxhDdJ6ZokTlwYpDfoMopG5TWQzlTKIml5ySMybq5yU q+nwHiIBo8SUneo7l+2jvSTiMyLS3XK2NlKL+Lak/ZQa9u/dpCRKilM2exQZg7PwLSoC dwlMo75Vvif5U/jdh+g3cYVLei7/wmGrqa+zJgkDkvk6IW4kJxQPzcbcMP46EzV+eKn9 6uhFOkwiYYeWIZTITfn293X+HDkBVsj7m8EFKcVQEFKJHTih32SX2L9S1wpepnQoVlvw 6D53ZkFViouCKHIBYrKlSSX+FjSBovigAbFY63Q7NTLmNJHI/AwW2O1Er+V2m/CHdmlV CG3g== 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=qSYPL9SSYIEL+UjOst0lDq7nFAgBqlkYnLNNO6AAkNU=; fh=1v5zqbO9sIGUc9bsdyhYE0zxdK1knZz2xnJYWUWMFKo=; b=Oggn8sQtjrSUJRQpUx5A7AI5T+TiZNx5PDoXd1oOHJa/Pc+9Jc7HcbnSi+CLgHrVVX KzncyFKoruTSvCK/7lgFlDQ52pG7JGk9/6KaXMsu3WHTY7LXyZXITfyDu3ud4D03dG47 cgWe7lkA+mz5h4pyyj0ViGTfZvbuHRYONXT7skpVZ9DtF6AG6YyVwpCU155mKIVnCZst M93GX9QCGkma5gpYU+42qD7KzYKVYTdE8+Bv4XccH9cSVLnKGZPGvZa5ngoNWWdErGou 8ynL9ebjXVjyWjmlVCWDcRH+a1u6nmMxCqMySwcfQN2V3xYcT16KtL25xWXOFTrpQ2Xm E7pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=hfVmBXDq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id bv63-20020a632e42000000b005c67196cbf1si2501909pgb.408.2023.12.03.23.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 23:54:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=hfVmBXDq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id A74BA808EEC4; Sun, 3 Dec 2023 23:53:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343692AbjLDHxT (ORCPT + 99 others); Mon, 4 Dec 2023 02:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234773AbjLDHwr (ORCPT ); Mon, 4 Dec 2023 02:52:47 -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 B27771B1; Sun, 3 Dec 2023 23:52:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1701676352; bh=qsEBHDax+s7znxB3EesnA+Cx/J6JWc+CwYaqV7C/mz4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hfVmBXDqoE2YJJldVofqpz/WfcE44RA5hrjOLjKrsSgg8+Vqz84+o+k8l9htgRRuh GNgCzJ2F8uqa8XxJuyz10kUjmac79RpTKqgK2TP3AAPjAx7N0rDGu3MpOebqHilblI e96AYqMrxRiH3i0WeQj0kc2hdK4B6hopDMqYiW6c= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 04 Dec 2023 08:52:26 +0100 Subject: [PATCH v2 13/18] sysctl: move sysctl type to ctl_table_header MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231204-const-sysctl-v2-13-7a5060b11447@weissschuh.net> References: <20231204-const-sysctl-v2-0-7a5060b11447@weissschuh.net> In-Reply-To: <20231204-const-sysctl-v2-0-7a5060b11447@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=1701676350; l=3565; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=qsEBHDax+s7znxB3EesnA+Cx/J6JWc+CwYaqV7C/mz4=; b=tMIii9ffAADr2UzePskIfAqvkha4rSZzcbOgaBFMjvqiqSSnOcNxY/LJgEC+njVgyCMiCAdq9 SW3QXP7NxdDA0aQiXdPhxD49iCJoOupbeLO1zlHRwAauVfNse8Y++Ct 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 fry.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 (fry.vger.email [0.0.0.0]); Sun, 03 Dec 2023 23:53:58 -0800 (PST) In a future commit the sysctl core will only use "const struct ctl_table". As a preparation for that move this mutable field from "struct ctl_table" to "struct ctl_table_header". This is also more correct in general as this is in fact a property of the header and not the table itself. Signed-off-by: Thomas Weißschuh --- fs/proc/proc_sysctl.c | 11 ++++++----- include/linux/sysctl.h | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 689a30196d0c..a398cc77637f 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -31,7 +31,7 @@ static const struct inode_operations proc_sys_dir_operations; /* Support for permanently empty directories */ static struct ctl_table sysctl_mount_point[] = { - {.type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY } + { } }; /** @@ -49,11 +49,11 @@ struct ctl_table_header *register_sysctl_mount_point(const char *path) EXPORT_SYMBOL(register_sysctl_mount_point); #define sysctl_is_perm_empty_ctl_header(hptr) \ - (hptr->ctl_table[0].type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY) + (hptr->type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY) #define sysctl_set_perm_empty_ctl_header(hptr) \ - (hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY) + (hptr->type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY) #define sysctl_clear_perm_empty_ctl_header(hptr) \ - (hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_DEFAULT) + (hptr->type = SYSCTL_TABLE_TYPE_DEFAULT) void proc_sys_poll_notify(struct ctl_table_poll *poll) { @@ -231,7 +231,8 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header) return -EROFS; /* Am I creating a permanently empty directory? */ - if (sysctl_is_perm_empty_ctl_header(header)) { + if (header->ctl_table == sysctl_mount_point || + sysctl_is_perm_empty_ctl_header(header)) { if (!RB_EMPTY_ROOT(&dir->root)) return -EINVAL; sysctl_set_perm_empty_ctl_header(dir_h); diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index ada36ef8cecb..061ea65104be 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -137,17 +137,6 @@ struct ctl_table { void *data; int maxlen; umode_t mode; - /** - * enum type - Enumeration to differentiate between ctl target types - * @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations - * @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently - * empty directory target to serve - * as mount point. - */ - enum { - SYSCTL_TABLE_TYPE_DEFAULT, - SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY - } type; proc_handler *proc_handler; /* Callback for text formatting */ struct ctl_table_poll *poll; void *extra1; @@ -188,6 +177,17 @@ struct ctl_table_header { struct ctl_dir *parent; struct ctl_node *node; struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */ + /** + * enum type - Enumeration to differentiate between ctl target types + * @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations + * @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently + * empty directory target to serve + * as mount point. + */ + enum { + SYSCTL_TABLE_TYPE_DEFAULT, + SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY + } type; }; struct ctl_dir { -- 2.43.0