Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2189017iof; Tue, 7 Jun 2022 22:37:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygT50CmQ7/TZPBEx32rPhuLJpKT2crFihWEli9rlJ4vHyh5/TRA8AjP/jzeKnWz1udnpzp X-Received: by 2002:a05:6a00:cd2:b0:51c:28b5:1573 with SMTP id b18-20020a056a000cd200b0051c28b51573mr11382575pfv.59.1654666671752; Tue, 07 Jun 2022 22:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666671; cv=none; d=google.com; s=arc-20160816; b=ToJNChdYhIatEygljCUB+AO0CsARg7yMRfpmKq47zXbufT/mBpN2BMt4cgMm4mywda cG7Z4jzTnhqtvUpY+lqIrfHCWkHpD+5IYe87E15FUctcVgf52ExHuxxGvnQXSFGS1/2O 5pIkQJogtM2wuNma6dekEjgrWQUkMloilcSkOhoQearUB14vPDo6FsWDNHhpVfdL35hi xAscNQ2N+myzieCYAB+HIEhMPhMMCdXvuIP92/aOC/zPAXdBRrP6RJM+tnVig75LlxT+ bBN0/VeDRWKvDIaRwoe5v0hGeEkWTGSJP3nNTB3U0Jc7bzIiAVgtA9AawmosWK9v7x8f umPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9r4JCil87KoDhkkoy0n2Kb44t3JuVOC8lGDjeKa+wEg=; b=s4ERlYjgQ8Drca60/bp17acct+4wvb+qwtY0j9eb+FHAOBF4BDv2FmZPSAjDc3ZLxk cu9D2Gr+D8Vwci+fwMRRVzUASYHsMI8RafVwx8HVMp3OPPrN9/Kp91p7RDGh6TPowjKn 2jG06TZ+T+J4FsUNsVW0F6RoIDifDgZ85dGk5QtMTzF+/W5jLVyvz85xtl8RymdtjnAN 9+O+uRW4tpgpQ0neARLi/xT5qhWnBnGGAWoAqWLkeTY/qSLnhoVFCKVpxQCI4OBnJwhG Hbhgflu7pqmeben1UOJWRoVUFWv8NxKRf/egHs4WtXHOQI4YVq6bzODTSxUVq4ciCeSQ Nz5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UpoZWbTI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l3-20020a17090270c300b0016362d70cf1si24733907plt.50.2022.06.07.22.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:37:51 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UpoZWbTI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 464C449EC79; Tue, 7 Jun 2022 22:13:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386257AbiFHA3w (ORCPT + 99 others); Tue, 7 Jun 2022 20:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385312AbiFGWVa (ORCPT ); Tue, 7 Jun 2022 18:21:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A458C19A726; Tue, 7 Jun 2022 12:21:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5A01F60A1D; Tue, 7 Jun 2022 19:21:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F7C3C385A5; Tue, 7 Jun 2022 19:21:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629688; bh=5or48Sd0+2qQPDKl+woFHQA/id1AA8D8c0YmSyWFprU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UpoZWbTIvLuWoxcMu2sLHJp4ZbqnWhOYe30uiveNxPPf67VgDvj3KpJnpvn07yQmw jZ0Dy3h1xciyIajAFAp1JM1TEpfpmIuLRHgDGntbcx7OXybwSIRpKUI7qgBF490G0R 6sbdQL4yla24hv8MS6zBK5RlYW15ddhNkWB2qvzs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= Subject: [PATCH 5.18 781/879] selftests/landlock: Extend access right tests to directories Date: Tue, 7 Jun 2022 19:04:59 +0200 Message-Id: <20220607165025.541305893@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mickaël Salaün commit d18955d094d09a220cf8f533f5e896a2fe31575a upstream. Make sure that all filesystem access rights can be tied to directories. Rename layout1.file_access_rights to layout1.file_and_dir_access_rights to reflect this change. Cc: Shuah Khan Link: https://lore.kernel.org/r/20220506160820.524344-6-mic@digikod.net Cc: stable@vger.kernel.org Signed-off-by: Mickaël Salaün Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/landlock/fs_test.c | 30 +++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) --- a/tools/testing/selftests/landlock/fs_test.c +++ b/tools/testing/selftests/landlock/fs_test.c @@ -418,11 +418,12 @@ TEST_F_FORK(layout1, inval) /* clang-format on */ -TEST_F_FORK(layout1, file_access_rights) +TEST_F_FORK(layout1, file_and_dir_access_rights) { __u64 access; int err; - struct landlock_path_beneath_attr path_beneath = {}; + struct landlock_path_beneath_attr path_beneath_file = {}, + path_beneath_dir = {}; struct landlock_ruleset_attr ruleset_attr = { .handled_access_fs = ACCESS_ALL, }; @@ -432,20 +433,33 @@ TEST_F_FORK(layout1, file_access_rights) ASSERT_LE(0, ruleset_fd); /* Tests access rights for files. */ - path_beneath.parent_fd = open(file1_s1d2, O_PATH | O_CLOEXEC); - ASSERT_LE(0, path_beneath.parent_fd); + path_beneath_file.parent_fd = open(file1_s1d2, O_PATH | O_CLOEXEC); + ASSERT_LE(0, path_beneath_file.parent_fd); + + /* Tests access rights for directories. */ + path_beneath_dir.parent_fd = + open(dir_s1d2, O_PATH | O_DIRECTORY | O_CLOEXEC); + ASSERT_LE(0, path_beneath_dir.parent_fd); + for (access = 1; access <= ACCESS_LAST; access <<= 1) { - path_beneath.allowed_access = access; + path_beneath_dir.allowed_access = access; + ASSERT_EQ(0, landlock_add_rule(ruleset_fd, + LANDLOCK_RULE_PATH_BENEATH, + &path_beneath_dir, 0)); + + path_beneath_file.allowed_access = access; err = landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH, - &path_beneath, 0); - if ((access | ACCESS_FILE) == ACCESS_FILE) { + &path_beneath_file, 0); + if (access & ACCESS_FILE) { ASSERT_EQ(0, err); } else { ASSERT_EQ(-1, err); ASSERT_EQ(EINVAL, errno); } } - ASSERT_EQ(0, close(path_beneath.parent_fd)); + ASSERT_EQ(0, close(path_beneath_file.parent_fd)); + ASSERT_EQ(0, close(path_beneath_dir.parent_fd)); + ASSERT_EQ(0, close(ruleset_fd)); } TEST_F_FORK(layout1, unknown_access_rights)