Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp294641rdf; Tue, 21 Nov 2023 03:03:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAfuas35/0XLGnyzQyGR7JeLyH8a3YIquy4j1i5GuAFTfRsT2WCF34l2C5/6bzHA/AC1I4 X-Received: by 2002:a05:6830:44a4:b0:6d6:4f51:1e3e with SMTP id r36-20020a05683044a400b006d64f511e3emr12968843otv.25.1700564633162; Tue, 21 Nov 2023 03:03:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700564633; cv=none; d=google.com; s=arc-20160816; b=H5uye3RFAxcOtcsvOWI8DM8TOqMzXEufPpfBwpxjUAPmOnEzft39AmwVUMuWKfOpLe d9PXofLW96Q//illufYitTygliixh3YyDNfEP63GEoMCUF/AEYZV9QaSpZklp25vDh5+ NB9NxSoWu1SPrp4hgUJQaOyJHKb2okiDGGvpfo44ukov/VDHycT4EkcTv3glPRN3R5iW 2bowN8wO4ROSC2IQtjYiB4p4OWX49Mb0i9ADt4Q/1EOP0zZpJhFzSZESVHX/jz7tE7Gd K2Bjul4ejEae/8bkJaQffbZq7BxonnC35ZKt/Ssz8dqqMg4ftgym/nLuh+INmG7AlAFc Z5hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ACt/yowjzNp1LE+eC8d+qSzMfjW2BNeElD/+w56z18s=; fh=sEA+bv7n9ZOjBdt28PN1MBz/mg4eJOi/hLAXW9x9iqI=; b=Q3gsa0jcygm5UFwajKDGG8Lka3aQ+fBgqsaqJ+PGfrATDRP9GAT/XQefCYiIMCHUO4 8FRJWDCvQL+tmMkCjK9hCjJwZqG8uRk5Udm+j3RbngX9gN5D8lAN++bfxAKOdQno5bqA TcUzQwjrV9xPYIAMAC1gxXDNts8it+BHEFr442PRKMY7yscXJi+ips4rhSUkQs5KmKzt Ddm/RffHkYi0mfDLqgbBVrQMUWui7uUC6tfmj+3A04CrFY+MUPlovxuGGtYut2bjoNrI AJ3YLWu6AZ7ov2weaAH5cuX2+cONEmVk7MzaqvTeiWmheCQXCpve3bZ8b5MIrFwEIgPJ CWqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CBA5qgIA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id y19-20020a63ce13000000b005b8f0ff9b35si10566358pgf.406.2023.11.21.03.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 03:03:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CBA5qgIA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1B19B802957E; Tue, 21 Nov 2023 03:03:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234111AbjKULC7 (ORCPT + 99 others); Tue, 21 Nov 2023 06:02:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231439AbjKULCe (ORCPT ); Tue, 21 Nov 2023 06:02:34 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 263DC132 for ; Tue, 21 Nov 2023 03:02:30 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id B96FEC433C8; Tue, 21 Nov 2023 11:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700564549; bh=52JkpIJppkZJcZh8UX3QIgjrV5B2xTu1H4YPWo7oRts=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=CBA5qgIAHx1kluHI3pFbL4dQQXqnEBUT52wmFB62ag5SYxGvQuO2RBsqgUDO5pHqb 0I0cbqA2FcAFbObvMcKiuB6fJzC5Ih6n6cNboPkOWwy2ogpouNxp9/iDeQcUtiHDUN npipMLojSH/NR0EY6vCD413lAmnwmRe11Qwk4cuolKp9JMz3/dszMuutFNyChZarRr eVe3/WSBC3oiEtKjTo10hkOFRcjgU89nWxo5+85bWEYQd0lQwGTSVIGTz0t499U4Z7 AsWpmyRCW+OxOLMD6xkgDTOQQtM4oF9LxpVv8kxy+mq1ULGoNm+QN/Svb+8lDIFz+p wBCpq3nM8/ZYA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FE80C61D94; Tue, 21 Nov 2023 11:02:29 +0000 (UTC) From: Joel Granados via B4 Relay Date: Tue, 21 Nov 2023 12:02:19 +0100 Subject: [PATCH 2/3] sysctl: Add a selftest for handling empty dirs MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231121-jag-fix_out_of_bounds_insert-v1-2-571e76d51316@samsung.com> References: <20231121-jag-fix_out_of_bounds_insert-v1-0-571e76d51316@samsung.com> In-Reply-To: <20231121-jag-fix_out_of_bounds_insert-v1-0-571e76d51316@samsung.com> To: Luis Chamberlain , Kees Cook , Iurii Zaikin , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, Joel Granados X-Mailer: b4 0.13-dev-86aa5 X-Developer-Signature: v=1; a=openpgp-sha256; l=3897; i=j.granados@samsung.com; h=from:subject:message-id; bh=bKjIXr0H+JsfSfz8xoXCVF/jy2aS3I1Y63fFXt/C07E=; b=owEB7QES/pANAwAKAbqXzVK3lkFPAcsmYgBlXI5D0LZq/oFYRZ4WUYe0Wlyd9gXjLPnh7W7YW qMrp4gEAWuJAbMEAAEKAB0WIQSuRwlXJeYxJc7LJ5C6l81St5ZBTwUCZVyOQwAKCRC6l81St5ZB T4fYC/wJkklJdFj9BvtYlU849BuM7cf7Qh5+ZjpAmMELnTk6sRAvSlANrBRLxx8hBkD+jlfkOr2 I+sFj78+0dfjdDBlcuKxNgEYp7U2cYRdy4e5OZ7rupNaO4aVF726D0pcA4ayG41RpJF0MX/m2Wk I8QqJzwgdLy0HF5JMT8gve19MS57N+KJ364mnaHpNjczMMejIgW+3P+Nm31RFvvPkVv4Z7rG22G IDySN/8AOVXH/EOIEx5UAB2MLEGLt4DYpy3JNWJlAfPc1Gd4WcqxAaSsMNoo2IluWUzh3QhHwCF wWT2iT1j8m7QNdKd6WuaLsxKN7ULhMuSfcDRJxI8Ml3BQgcZ0AHfQjR5263qAHbKMrNaZoPHaRN 5W3PC3aHH3eyuPWOlPA1wk+ZQjS7UhuSvK6jH6MaCSi96ch32L0RVrg18zUCWEj+E/nbiFDDIoT 7YNN3sm5PXfVwyElGz7HPWuwzli4yjK8iiyUD7YROTX5u1wiWPE5cWQdqnsTqgj2atYss= X-Developer-Key: i=j.granados@samsung.com; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for j.granados@samsung.com/default with auth_id=70 X-Original-From: Joel Granados Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 03:03:50 -0800 (PST) From: Joel Granados Basic test to ensure that empty directories can be registered and that they in turn can serve as a base dir for other registrations. Add one test to the sysctl selftest module. It first registers an empty directory under "empty_add" and then uses that as a base to register another empty dir. The sysctl bash script then checks that "empty_add" is present and that there an empty directory within it. Signed-off-by: Joel Granados --- lib/test_sysctl.c | 29 +++++++++++++++++++++++++++++ tools/testing/selftests/sysctl/sysctl.sh | 23 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index 8036aa91a1cb..730908bc1c2b 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c @@ -35,6 +35,8 @@ static struct { struct ctl_table_header *test_h_setup_node; struct ctl_table_header *test_h_mnt; struct ctl_table_header *test_h_mnterror; + struct ctl_table_header *empty_add; + struct ctl_table_header *empty; } sysctl_test_headers; struct test_sysctl_data { @@ -220,6 +222,25 @@ static int test_sysctl_run_register_mount_point(void) return 0; } +static struct ctl_table test_table_empty[] = { }; + +static int test_sysctl_run_register_empty(void) +{ + /* Tets that an empty dir can be created */ + sysctl_test_headers.empty_add + = register_sysctl("debug/test_sysctl/empty_add", test_table_empty); + if (!sysctl_test_headers.empty_add) + return -ENOMEM; + + /* Test that register on top of an empty dir works */ + sysctl_test_headers.empty + = register_sysctl("debug/test_sysctl/empty_add/empty", test_table_empty); + if (!sysctl_test_headers.empty) + return -ENOMEM; + + return 0; +} + static int __init test_sysctl_init(void) { int err; @@ -233,6 +254,10 @@ static int __init test_sysctl_init(void) goto out; err = test_sysctl_run_register_mount_point(); + if (err) + goto out; + + err = test_sysctl_run_register_empty(); out: return err; @@ -248,6 +273,10 @@ static void __exit test_sysctl_exit(void) unregister_sysctl_table(sysctl_test_headers.test_h_mnt); if (sysctl_test_headers.test_h_mnterror) unregister_sysctl_table(sysctl_test_headers.test_h_mnterror); + if (sysctl_test_headers.empty) + unregister_sysctl_table(sysctl_test_headers.empty); + if (sysctl_test_headers.empty_add) + unregister_sysctl_table(sysctl_test_headers.empty_add); } module_exit(test_sysctl_exit); diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index 444b2befda82..e956d2c3b7e9 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -35,6 +35,7 @@ ALL_TESTS="$ALL_TESTS 0007:1:1:boot_int:1" ALL_TESTS="$ALL_TESTS 0008:1:1:match_int:1" ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0" ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0" +ALL_TESTS="$ALL_TESTS 0011:1:1:empty_add:0" function allow_user_defaults() { @@ -828,6 +829,27 @@ sysctl_test_0010() return 0 } +sysctl_test_0011() +{ + TARGET="${SYSCTL}/$(get_test_target 0011)" + echo -n "Testing empty dir handling in ${TARGET} ... " + if [ ! -d ${TARGET} ]; then + echo -e "FAIL\nCould not create ${TARGET}" >&2 + rc=1 + test_rc + fi + + TARGET2="${TARGET}/empty" + if [ ! -d ${TARGET2} ]; then + echo -e "FAIL\nCould not create ${TARGET2}" >&2 + rc=1 + test_rc + fi + + echo "OK" + return 0 +} + list_tests() { echo "Test ID list:" @@ -846,6 +868,7 @@ list_tests() echo "0008 x $(get_test_count 0008) - tests sysctl macro values match" echo "0009 x $(get_test_count 0009) - tests sysct unregister" echo "0010 x $(get_test_count 0010) - tests sysct mount point" + echo "0011 x $(get_test_count 0011) - tests empty directories" } usage() -- 2.30.2