All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dominick Grift <dominick.grift@defensec.nl>
To: Petr Lautrbach <lautrbach@redhat.com>
Cc: "Christian Göttsche" <cgoettsche@seltendoof.de>,
	selinux@vger.kernel.org,
	"Christian Göttsche" <cgzones@googlemail.com>
Subject: Re: [PATCH v2 2/2] libselinux: retain LIFO order for path substitutions
Date: Tue, 10 Jun 2025 13:28:15 +0200	[thread overview]
Message-ID: <871prrlttc.fsf@defensec.nl> (raw)
In-Reply-To: <87plfbetzh.fsf@redhat.com> (Petr Lautrbach's message of "Tue, 10 Jun 2025 13:06:26 +0200")

Petr Lautrbach <lautrbach@redhat.com> writes:

> Christian Göttsche <cgoettsche@seltendoof.de> writes:
>
>> From: Christian Göttsche <cgzones@googlemail.com>
>>
>> Store the path substitutions in LIFO order as in previous versions.
>>
>> Fixes: 4d436e4b ("libselinux: use vector instead of linked list for substitutions")
>> Reported-by: Dominick Grift <dominick.grift@defensec.nl>
>> Link: https://lore.kernel.org/selinux/87ldqftsxd.fsf@defensec.nl/
>> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>> ---
>> v2: add patch
>> ---
>>  libselinux/src/label_file.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
>> index 61a9ddb6..b785eab6 100644
>> --- a/libselinux/src/label_file.c
>> +++ b/libselinux/src/label_file.c
>> @@ -1350,6 +1350,15 @@ static int selabel_subs_init(const char *path, struct selabel_digest *digest,
>>  	if (digest_add_specfile(digest, cfg, NULL, sb.st_size, path) < 0)
>>  		goto err;
>>  
>> +	/* LIFO order for backward compatibility */
>> +	for (uint32_t i = 0; i < tmp_num/2; i++) {
>> +		struct selabel_sub swap;
>> +
>> +		swap = tmp[i];
>> +		tmp[i] = tmp[tmp_num - i - 1];
>> +		tmp[tmp_num - i - 1] = swap;
>> +	}
>> +
>>  	*out_subs = tmp;
>>  	*out_num = tmp_num;
>>  	*out_alloc = tmp_alloc;
>> -- 
>> 2.49.0
>
> It fixes the original reproducer:
>
> root@fedora:/# cat /etc/selinux/fedora-selinux/contexts/files/file_contexts.subs
> /new_root /
> /new_root/foo /usr/bin
> root@fedora:/# matchpathcon /new_root /new_root/foo
> /new_root       system_u:object_r:root_t:s0
> /new_root/foo   system_u:object_r:bin_t:s0
>
> but it's important to say it depends on the order of entries in .subst:
>
> root@fedora:/# cat /etc/selinux/fedora-selinux/contexts/files/file_contexts.subs
> /new_root/foo /usr/bin
> /new_root /
> root@fedora:/# matchpathcon /new_root /new_root/foo
> /new_root       system_u:object_r:root_t:s0
> /new_root/foo   system_u:object_r:etc_runtime_t:s0
>
>
> it looks like it was like that even before with 3.8:
>
> [root@fedora-41 /]# cat /etc/selinux/targeted/contexts/files/file_contexts.subs
> /new_root /
> /new_root/foo /usr/bin
> [root@fedora-41 /]# matchpathcon /new_root /new_root/foo
> /new_root       system_u:object_r:root_t:s0
> /new_root/foo   system_u:object_r:bin_t:s0
>
> [root@fedora-41 /]# cat /etc/selinux/targeted/contexts/files/file_contexts.subs
> /new_root/foo /usr/bin
> /new_root /
> [root@fedora-41 /]# matchpathcon /new_root /new_root/foo
> /new_root       system_u:object_r:root_t:s0
> /new_root/foo   system_u:object_r:etc_runtime_t:s0
>
> It would be great to have this behavior documented, but it's a different
> issue.
>
> If there's no other objection I'll merge tomorrow before 3.9-rc1.
>
> Acked-by: Petr Lautrbach <lautrbach@redhat.com>
>

I applied this patch and it addresses my issue (restores compatiblity).
I can also confirm that ordering the specs indeed also addresses the
issue at least in a simple test I did.

I do prefer that ordering shouldnt matter.

Thanks!

-- 
gpg --locate-keys dominick.grift@defensec.nl (wkd)
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
Dominick Grift
Mastodon: @kcinimod@defensec.nl

  reply	other threads:[~2025-06-10 11:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 12:30 [PATCH v2 1/2] libselinux: prioritize local literal fcontext definitions Christian Göttsche
2025-05-30 12:30 ` [PATCH v2 2/2] libselinux: retain LIFO order for path substitutions Christian Göttsche
2025-06-10 11:06   ` Petr Lautrbach
2025-06-10 11:28     ` Dominick Grift [this message]
2025-06-10 18:09       ` James Carter
2025-06-10  9:52 ` [PATCH v2 1/2] libselinux: prioritize local literal fcontext definitions Petr Lautrbach

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=871prrlttc.fsf@defensec.nl \
    --to=dominick.grift@defensec.nl \
    --cc=cgoettsche@seltendoof.de \
    --cc=cgzones@googlemail.com \
    --cc=lautrbach@redhat.com \
    --cc=selinux@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.