linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Konstantin Meskhidze (A)" <konstantin.meskhidze@huawei.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: <willemdebruijn.kernel@gmail.com>, <gnoack3000@gmail.com>,
	<linux-security-module@vger.kernel.org>, <netdev@vger.kernel.org>,
	<netfilter-devel@vger.kernel.org>, <yusongping@huawei.com>,
	<artem.kuzin@huawei.com>
Subject: Re: [PATCH v13 07/12] landlock: Refactor landlock_add_rule() syscall
Date: Thu, 19 Oct 2023 14:57:20 +0300	[thread overview]
Message-ID: <d2ac366a-c929-0d2f-8855-0d7cf5e1704f@huawei.com> (raw)
In-Reply-To: <20231018.quie0uuphieB@digikod.net>



10/18/2023 7:34 PM, Mickaël Salaün пишет:
> On Mon, Oct 16, 2023 at 09:50:25AM +0800, Konstantin Meskhidze wrote:
>> Change the landlock_add_rule() syscall to support new rule types
>> in future Landlock versions. Add the add_rule_path_beneath() helper
>> to support current filesystem rules.
>> 
>> Signed-off-by: Konstantin Meskhidze <konstantin.meskhidze@huawei.com>
>> Link: https://lore.kernel.org/r/20230920092641.832134-8-konstantin.meskhidze@huawei.com
>> Signed-off-by: Mickaël Salaün <mic@digikod.net>
>> ---
>> 
>> Changes since v12:
>> * None.
>> 
>> Changes since v11:
>> * None.
>> 
>> Changes since v10:
>> * None.
>> 
>> Changes since v9:
>> * Minor fixes:
>> 	- deletes unnecessary curly braces.
>> 	- deletes unnecessary empty line.
>> 
>> Changes since v8:
>> * Refactors commit message.
>> * Minor fixes.
>> 
>> Changes since v7:
>> * None
>> 
>> Changes since v6:
>> * None
>> 
>> Changes since v5:
>> * Refactors syscall landlock_add_rule() and add_rule_path_beneath() helper
>> to make argument check ordering consistent and get rid of partial revertings
>> in following patches.
>> * Rolls back refactoring base_test.c seltest.
>> * Formats code with clang-format-14.
>> 
>> Changes since v4:
>> * Refactors add_rule_path_beneath() and landlock_add_rule() functions
>> to optimize code usage.
>> * Refactors base_test.c seltest: adds LANDLOCK_RULE_PATH_BENEATH
>> rule type in landlock_add_rule() call.
>> 
>> Changes since v3:
>> * Split commit.
>> * Refactors landlock_add_rule syscall.
>> 
>> ---
>>  security/landlock/syscalls.c | 92 +++++++++++++++++++-----------------
>>  1 file changed, 48 insertions(+), 44 deletions(-)
>> 
>> diff --git a/security/landlock/syscalls.c b/security/landlock/syscalls.c
>> index d35cd5d304db..8a54e87dbb17 100644
>> --- a/security/landlock/syscalls.c
>> +++ b/security/landlock/syscalls.c
>> @@ -274,6 +274,47 @@ static int get_path_from_fd(const s32 fd, struct path *const path)
>>  	return err;
>>  }
>> 
>> +static int add_rule_path_beneath(struct landlock_ruleset *const ruleset,
>> +				 const void __user *const rule_attr)
>> +{
>> +	struct landlock_path_beneath_attr path_beneath_attr;
>> +	struct path path;
>> +	int res, err;
>> +	access_mask_t mask;
>> +
>> +	/* Copies raw user space buffer, only one type for now. */
>> +	res = copy_from_user(&path_beneath_attr, rule_attr,
>> +			     sizeof(path_beneath_attr));
>> +	if (res)
>> +		return -EFAULT;
>> +
>> +	/*
>> +	 * Informs about useless rule: empty allowed_access (i.e. deny rules)
>> +	 * are ignored in path walks.
>> +	 */
>> +	if (!path_beneath_attr.allowed_access)
>> +		return -ENOMSG;
>> +
>> +	/*
>> +	 * Checks that allowed_access matches the @ruleset constraints
>> +	 * (ruleset->access_masks[0] is automatically upgraded to 64-bits).
>> +	 */
> 
> You now can replace this comment block with that:
> +	/* Checks that allowed_access matches the @ruleset constraints. */

   Done.
> 
>> +	mask = landlock_get_raw_fs_access_mask(ruleset, 0);
>> +	if ((path_beneath_attr.allowed_access | mask) != mask)
>> +		return -EINVAL;
>> +
>> +	/* Gets and checks the new rule. */
>> +	err = get_path_from_fd(path_beneath_attr.parent_fd, &path);
>> +	if (err)
>> +		return err;
>> +
>> +	/* Imports the new rule. */
>> +	err = landlock_append_fs_rule(ruleset, &path,
>> +				      path_beneath_attr.allowed_access);
>> +	path_put(&path);
>> +	return err;
>> +}
> .

  reply	other threads:[~2023-10-19 11:57 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16  1:50 [PATCH v13 00/12] Network support for Landlock Konstantin Meskhidze
2023-10-16  1:50 ` [PATCH v13 01/12] landlock: Make ruleset's access masks more generic Konstantin Meskhidze
2023-10-18 12:28   ` Mickaël Salaün
2023-10-19  1:45     ` Konstantin Meskhidze (A)
2023-10-16  1:50 ` [PATCH v13 02/12] landlock: Allow FS topology changes for domains without such rule type Konstantin Meskhidze
2023-10-16  1:50 ` [PATCH v13 03/12] landlock: Refactor landlock_find_rule/insert_rule Konstantin Meskhidze
2023-10-16  1:50 ` [PATCH v13 04/12] landlock: Refactor merge/inherit_ruleset functions Konstantin Meskhidze
2023-10-16  1:50 ` [PATCH v13 05/12] landlock: Move and rename layer helpers Konstantin Meskhidze
2023-10-16  1:50 ` [PATCH v13 06/12] landlock: Refactor " Konstantin Meskhidze
2023-10-16  1:50 ` [PATCH v13 07/12] landlock: Refactor landlock_add_rule() syscall Konstantin Meskhidze
2023-10-18 12:28   ` Mickaël Salaün
2023-10-19 11:59     ` Konstantin Meskhidze (A)
2023-10-18 16:34   ` Mickaël Salaün
2023-10-19 11:57     ` Konstantin Meskhidze (A) [this message]
2023-10-16  1:50 ` [PATCH v13 08/12] landlock: Add network rules and TCP hooks support Konstantin Meskhidze
2023-10-18 12:29   ` Mickaël Salaün
2023-10-20  4:08     ` Konstantin Meskhidze (A)
2023-10-20  9:49       ` Mickaël Salaün
2023-10-20 11:58         ` Konstantin Meskhidze (A)
2023-10-20 15:41           ` Mickaël Salaün
2023-10-23  7:23             ` Konstantin Meskhidze (A)
2023-10-23  8:30               ` Mickaël Salaün
2023-10-23  8:56                 ` Konstantin Meskhidze (A)
2023-10-24  2:51         ` Konstantin Meskhidze (A)
2023-10-24  3:18         ` Konstantin Meskhidze (A)
2023-10-24  9:03           ` Mickaël Salaün
2023-10-24  9:12             ` Konstantin Meskhidze (A)
2023-10-25 11:29               ` Mickaël Salaün
2023-10-26  2:02                 ` Konstantin Meskhidze (A)
2023-10-18 16:34   ` Mickaël Salaün
2023-10-20  9:40     ` Konstantin Meskhidze (A)
2023-10-16  1:50 ` [PATCH v13 09/12] selftests/landlock: Share enforce_ruleset() Konstantin Meskhidze
2023-10-16  1:50 ` [PATCH v13 10/12] selftests/landlock: Add 7 new test variants dedicated to network Konstantin Meskhidze
2023-10-18 12:32   ` Mickaël Salaün
2023-10-20 11:41     ` Konstantin Meskhidze (A)
2023-10-20 15:40       ` Mickaël Salaün
2023-10-23  7:09         ` Konstantin Meskhidze (A)
2023-10-23  8:44           ` Mickaël Salaün
2023-10-23  9:15             ` Konstantin Meskhidze (A)
2023-10-16  1:50 ` [PATCH v13 11/12] samples/landlock: Add network demo Konstantin Meskhidze
2023-10-18 12:33   ` Mickaël Salaün
2023-10-20 11:59     ` Konstantin Meskhidze (A)
2023-10-16  1:50 ` [PATCH v13 12/12] landlock: Document Landlock's network support Konstantin Meskhidze
2023-10-18 12:34   ` Mickaël Salaün
2023-10-20 12:17     ` Konstantin Meskhidze (A)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d2ac366a-c929-0d2f-8855-0d7cf5e1704f@huawei.com \
    --to=konstantin.meskhidze@huawei.com \
    --cc=artem.kuzin@huawei.com \
    --cc=gnoack3000@gmail.com \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=yusongping@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).