Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1093233rwb; Wed, 26 Jul 2023 07:30:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlGT17CYEFtM7jpxW3iv3Pr1OTJ99yn0cuk5SPP+L8xQSxlBEaHSU0C1JU1793aCG/4pK7c5 X-Received: by 2002:a05:6a00:1503:b0:64d:46b2:9a58 with SMTP id q3-20020a056a00150300b0064d46b29a58mr2981042pfu.26.1690381847166; Wed, 26 Jul 2023 07:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690381847; cv=none; d=google.com; s=arc-20160816; b=PTMprwl71h2nsUT/Zf351fMVNUAYaDNSXE7MVtt/RK5jNN83Ot+Ip23pPdjvJyZt6F 1bBKLFAHktgOsWqD+QDNTHYFK7l9y6gcdYHD89UYS0F7tGQ4qvCETCO4CDJcubhdKLOI UjzaQauXJzqUnrl8KKuo8/oqXV2uCeDln2r9W9L8kdlCFS7qTpYw5xsVMb7gxEKekw/T xrmfPWnt+E1AqoYM2kAT/IfyOVKl6oIKy/3YLoIjjkQw99o5bcxldzCkyyW4dLhrc/nU /KJ8o0wimfpnLgf79i1Awwl9a1fP/r/9AlQEfhHdyU0TVh+LnSV8hrOZe4EprnpdFmy+ +Jxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=A0yFUtcBmjlDc/JAvy8SEl8ns1g5aFjeEqkhCY5WXnw=; fh=jc9Oc4z2chBkB++ulkkGj5ASBtrAOk+67EQBS5BnDw0=; b=NuPLI0NDyCQM1dzJVZ39g0NlXIO7FVGcMOyEJZ3swt7kg7LmCDVzQe2+koTyVZwtBF n8wyhJT+silece/hAhmQ3JZVzUl3LCaSHPdekaUmI+pEwlieGVcMzcZ67lkgABfp2j3m Tz7Ivo1BJfRdrfRR1NZxDjzGi7wm3lKwEzRK8JjoSiA7CxFJPZOiQ3iEIrPq2maMWnPM TKkMYOjW949mKvJllOTGobtwHMbL+sM1bBm6xYXFrGFNebnsw1tCyebBnEkoh6aVKpAJ 3rqP0Ee0QStjik3qyOpBEGNHWE6hZk6vN/B9MfqXkyH7iLmvUlp3ICPGPJx98lLoI7bz xy4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="n8Cx/zpG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z15-20020a056a00240f00b00681fb4b7019si13178823pfh.220.2023.07.26.07.30.32; Wed, 26 Jul 2023 07:30:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="n8Cx/zpG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234323AbjGZOHF (ORCPT + 99 others); Wed, 26 Jul 2023 10:07:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234207AbjGZOHA (ORCPT ); Wed, 26 Jul 2023 10:07:00 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC8542706 for ; Wed, 26 Jul 2023 07:06:52 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140650euoutp01ebf66e7698818a70620e334f61ed597a~1cAcI4bGy2885428854euoutp01Z for ; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230726140650euoutp01ebf66e7698818a70620e334f61ed597a~1cAcI4bGy2885428854euoutp01Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380410; bh=A0yFUtcBmjlDc/JAvy8SEl8ns1g5aFjeEqkhCY5WXnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n8Cx/zpGERpqTQz+DVg8x5GyzY6Fc3IKT5Hb3hbJUgg7v4tIJlwrAZLfv7I3PLMz6 x+EX5jj/FNVmRuS+mWL6GeGYh8ZRXvQpJC9aPdhCQtjmhsxNz/jg/zaQnSyQHnRN/V oogrWrMt/08m1sQXWOfvf4KAncHKaBAGibg50ImM= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230726140650eucas1p1b2e6fc9826d0d0732b155ab6d48adfc8~1cAb_oX8t2257522575eucas1p1v; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 27.56.37758.A7821C46; Wed, 26 Jul 2023 15:06:50 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb~1cAbuJVld2261822618eucas1p1o; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230726140650eusmtrp1211dd44af609fa595ca6559c1464ada7~1cAbtgAVf2391823918eusmtrp1c; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) X-AuditID: cbfec7f5-815ff7000002937e-e3-64c1287a64e9 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A9.47.14344.A7821C46; Wed, 26 Jul 2023 15:06:50 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230726140649eusmtip2e2780fccf7021b940db173c2d91726aa~1cAbgzFjn3056730567eusmtip2X; Wed, 26 Jul 2023 14:06:49 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 01/14] sysctl: Prefer ctl_table_header in proc_sysctl Date: Wed, 26 Jul 2023 16:06:21 +0200 Message-Id: <20230726140635.2059334-2-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJKsWRmVeSWpSXmKPExsWy7djP87pVGgdTDLruS1ks3f+Q0eL/gnyL M925Fnv2nmSxuLxrDpvFjQlPGS1+/wCylu30c+DwmN1wkcVjwaZSj80rtDxuvbb12LSqk82j b8sqRo/Pm+QC2KO4bFJSczLLUov07RK4MtpOXmUuaFWraFjYxNLAuE6+i5GTQ0LARGJe+yzW LkYuDiGBFYwSnf1f2CGcL4wSizfuZYRwPjNK/Fv4gh2m5fT+HawgtpDAckaJu1PNIYpeMkrc +jyXESTBJqAjcf7NHeYuRg4OEYFYicVTUkDCzALTGSWWzJEBsYUFXCWWbNnIDGKzCKhKrO+5 yQ5SzitgK9G/2BpilbxE2/XpYBM5BewkVq79DraWV0BQ4u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bUWL1yUNg CWEBV4klWzaC2SwCqhLre26ygyzgFbCV6F9sDbFAXqLt+nRGEJtTwE5i5drvYPOFgEp6pj5l B7F5BQQlTs58wgJiMwPVN2+dzTyBUWAWktQsJKkFjEyrGEVSS4tz03OLjfSKE3OLS/PS9ZLz czcxAqNk27GfW3Ywrnz1Ue8QIxMH4yFGCQ5mJRFew5h9KUK8KYmVValF+fFFpTmpxYcYTYHO nsgsJZqcD4zTvJJ4QzMDU0MTM0sDU0szYyVxXs+CjkQhgfTEktTs1NSC1CKYPiYOTqkGpqjl OYvTlU5WSci8mTDZXli91GTpqgvnwu5vzOl7/THhjT6nG9cPV5NJHtLBk6Qnbrq8o/0+++zl Ww8qeG5JTCtf3Dpje+fJtNZLcms2LDN5XJEq0GCS5HTQf9eXZ/Z3s0uy61+t3Hp2q8FV5jm7 H9mpT6zJ8X4x+fpsyV2e53wXfJouFXrB9MgkVgUja+Hy6A+vt2sbuN9lFmkysr2eM7k+miu0 /kRAk907l7VzbrclhQYv/3nxS3eD8Z2XdtMSe91KNQ3upS+Zu3iZ7o5ngVmPT2zgPG/Tbpgk usT5yzZJp/diiS7Xtq76s1nbyk7Q97TU3reGHT3uWeo9fEc7dV9ZTNX4tzRiwcZTs62Y1iqx FGckGmoxFxUnAgCTiEtOGwMAAA== X-CMS-MailID: 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb References: <20230726140635.2059334-1-j.granados@samsung.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparation commit to use ctl_table_header instead of ctl_table as the element that is passed around in proc_sysctl.c. This will become necessary when the size can no longer be calculated by searching for an empty sentinel in the ctl_table array and will live in the ctl_table_header. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 5ea42653126e..94d71446da39 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1125,11 +1125,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table) return err; } -static int sysctl_check_table(const char *path, struct ctl_table *table) +static int sysctl_check_table(const char *path, struct ctl_table_header *header) { struct ctl_table *entry; int err = 0; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { if ((entry->proc_handler == proc_dostring) || (entry->proc_handler == proc_dobool) || (entry->proc_handler == proc_dointvec) || @@ -1159,8 +1159,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table) return err; } -static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table, - struct ctl_table_root *link_root) +static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_header *head) { struct ctl_table *link_table, *entry, *link; struct ctl_table_header *links; @@ -1170,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table name_bytes = 0; nr_entries = 0; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, head->ctl_table) { nr_entries++; name_bytes += strlen(entry->procname) + 1; } @@ -1189,12 +1188,12 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table link_name = (char *)&link_table[nr_entries + 1]; link = link_table; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, head->ctl_table) { int len = strlen(entry->procname) + 1; memcpy(link_name, entry->procname, len); link->procname = link_name; link->mode = S_IFLNK|S_IRWXUGO; - link->data = link_root; + link->data = head->root; link_name += len; link++; } @@ -1205,15 +1204,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table } static bool get_links(struct ctl_dir *dir, - struct ctl_table *table, struct ctl_table_root *link_root) + struct ctl_table_header *header, + struct ctl_table_root *link_root) { - struct ctl_table_header *head; + struct ctl_table_header *tmp_head; struct ctl_table *entry, *link; /* Are there links available for every entry in table? */ - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { const char *procname = entry->procname; - link = find_entry(&head, dir, procname, strlen(procname)); + link = find_entry(&tmp_head, dir, procname, strlen(procname)); if (!link) return false; if (S_ISDIR(link->mode) && S_ISDIR(entry->mode)) @@ -1224,10 +1224,10 @@ static bool get_links(struct ctl_dir *dir, } /* The checks passed. Increase the registration count on the links */ - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { const char *procname = entry->procname; - link = find_entry(&head, dir, procname, strlen(procname)); - head->nreg++; + link = find_entry(&tmp_head, dir, procname, strlen(procname)); + tmp_head->nreg++; } return true; } @@ -1246,13 +1246,13 @@ static int insert_links(struct ctl_table_header *head) if (IS_ERR(core_parent)) return 0; - if (get_links(core_parent, head->ctl_table, head->root)) + if (get_links(core_parent, head, head->root)) return 0; core_parent->header.nreg++; spin_unlock(&sysctl_lock); - links = new_links(core_parent, head->ctl_table, head->root); + links = new_links(core_parent, head); spin_lock(&sysctl_lock); err = -ENOMEM; @@ -1260,7 +1260,7 @@ static int insert_links(struct ctl_table_header *head) goto out; err = 0; - if (get_links(core_parent, head->ctl_table, head->root)) { + if (get_links(core_parent, head, head->root)) { kfree(links); goto out; } @@ -1371,7 +1371,7 @@ struct ctl_table_header *__register_sysctl_table( node = (struct ctl_node *)(header + 1); init_header(header, root, set, node, table); - if (sysctl_check_table(path, table)) + if (sysctl_check_table(path, header)) goto fail; spin_lock(&sysctl_lock); -- 2.30.2