Skip to contentSkip to conversation

Cil block inheritance

DISCUSSION Vit Mojzis 3 participants 7 messages Aug 26, 2021 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

Hi,
recent changes in block inheritance broke our use case where we use block inheritance for generating container policies (https://github.com/containers/udica/tree/main/udica/templates). Basically the policy is composed by inheriting selected "template" blocks, all of which inherit "container" block, so that they can use types defined there.

Reproducer:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

#semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1 Failed to copy block contents into blockinherit
Failed to resolve AST
semodule: Failed!

This used to work just fine.

The following workaround seems to be working as intended, but I'm not sure if it's the best approach. Types are only defined in template1 and the rest contains "optional" block, so that I can use types defined in template1).

(block template1 (type t))
(block template2
     (optional o
         (allow t t ( file ( read )))
     )
)
(block b (blockinherit template1) (blockinherit template2))

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file read;

Any pointers would be appreciated.

Thank you.

Vit

#1 lore raw
Quoted 8 lines · Vit Mojzis

Hi,
recent changes in block inheritance broke our use case where we use block inheritance for generating container policies
(https://github.com/containers/udica/tree/main/udica/templates). Basically the policy is composed by inheriting selected "template" blocks, all of which inherit "container" block, so that they can use types defined there.

Quoted 4 lines

Reproducer:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

In this example there is no point in inheriting template1, because template2 already inherits it.

(block template1

       (type t))
(block template2
       (blockinherit template1))
(block b (blockinherit template2)
       (allow t t (file (read))))

semodule -i test.cil
seinfo -t b.t

Quoted 16 lines

#semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1 Failed to copy block contents into blockinherit Failed to resolve AST
semodule: Failed!

This used to work just fine.

The following workaround seems to be working as intended, but I'm not sure if it's the best approach. Types are only defined in template1 and the rest contains "optional" block, so that I can use types defined in template1).

Quoted 7 lines

(block template1 (type t))
(block template2
     (optional o
         (allow t t ( file ( read )))
     )
)
(block b (blockinherit template1) (blockinherit template2))

You can just do something like this:

(block template1 (type t))
(block template2 (blockinherit template1) (optional o (allow t t (file (read))))
(block b (blockinherit template2))
semodule -i test.cil
sesearch -A -t b.t

Quoted 11 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file read;

Any pointers would be appreciated.

Thank you.

Vit

Signature · 4 lines
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift
author
#2 lore raw
Quoted 18 lines · Dominick Grift
Quoted 8 lines · Vit Mojzis

Hi,
recent changes in block inheritance broke our use case where we use block inheritance for generating container policies
(https://github.com/containers/udica/tree/main/udica/templates). Basically the policy is composed by inheriting selected "template" blocks, all of which inherit "container" block, so that they can use types defined there.

Quoted 4 lines

Reproducer:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

In this example there is no point in inheriting template1, because template2 already inherits it.

(block template1

Quoted 8 lines
        (type t))
(block template2
        (blockinherit template1))
(block b (blockinherit template2)
        (allow t t (file (read))))

semodule -i test.cil
seinfo -t b.t

Sure, but with more templates (as we have in udica) we get the same issue.

(block template1 (type t) )
(block template2 (blockinherit template1))
(block template3 (blockinherit template1))
(block b (blockinherit template2) (blockinherit template3))

# semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1
Failed to copy block contents into blockinherit
Failed to resolve AST
semodule:  Failed!

Template2 and template3 mostly inherit template1 for the type defined there (so that they can define rules containing the type).

Quoted 23 lines
Quoted 16 lines

#semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1 Failed to copy block contents into blockinherit Failed to resolve AST
semodule: Failed!

This used to work just fine.

The following workaround seems to be working as intended, but I'm not sure if it's the best approach. Types are only defined in template1 and the rest contains "optional" block, so that I can use types defined in template1).

Quoted 7 lines

(block template1 (type t))
(block template2
     (optional o
         (allow t t ( file ( read )))
     )
)
(block b (blockinherit template1) (blockinherit template2))

Quoted 8 lines

You can just do something like this:

(block template1 (type t))
(block template2 (blockinherit template1) (optional o (allow t t (file (read))))
(block b (blockinherit template2))
semodule -i test.cil
sesearch -A -t b.t

With more templates, this break as well.

But the following works:

(block template1 (type t))
(block template2 (optional o (allow t t (file (read)))))
(block template3 (optional o (allow t t (file (write)))))
(block b (blockinherit template1) (blockinherit template2) (blockinherit template3))

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file { read write };

Again, I'm not sure if this is the best solution, just the only one I managed to get working.

Vit

Quoted 10 lines
Quoted 10 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file read;

Any pointers would be appreciated.

Thank you.

Vit

#3 lore raw
Quoted 25 lines · Vit Mojzis
Quoted 24 lines · Dominick Grift
Quoted 8 lines · Vit Mojzis

Hi,
recent changes in block inheritance broke our use case where we use block inheritance for generating container policies
(https://github.com/containers/udica/tree/main/udica/templates). Basically the policy is composed by inheriting selected "template" blocks, all of which inherit "container" block, so that they can use types defined there.

Quoted 4 lines

Reproducer:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

In this example there is no point in inheriting template1, because template2 already inherits it.

(block template1

        (type t))
(block template2
        (blockinherit template1))
(block b (blockinherit template2)
        (allow t t (file (read))))
Quoted 8 lines
Quoted 2 lines

semodule -i test.cil
seinfo -t b.t

Sure, but with more templates (as we have in udica) we get the same issue.

(block template1 (type t) )
(block template2 (blockinherit template1))
(block template3 (blockinherit template1))
(block b (blockinherit template2) (blockinherit template3))

This boils down to the same as above, yes.

Quoted 52 lines
# semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1
Failed to copy block contents into blockinherit
Failed to resolve AST
semodule:  Failed!

Template2 and template3 mostly inherit template1 for the type defined there (so that they can define rules containing the type).

Quoted 23 lines
Quoted 16 lines

#semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1 Failed to copy block contents into blockinherit Failed to resolve AST
semodule: Failed!

This used to work just fine.

The following workaround seems to be working as intended, but I'm not sure if it's the best approach. Types are only defined in template1 and the rest contains "optional" block, so that I can use types defined in template1).

Quoted 7 lines

(block template1 (type t))
(block template2
     (optional o
         (allow t t ( file ( read )))
     )
)
(block b (blockinherit template1) (blockinherit template2))

Quoted 8 lines

You can just do something like this:

(block template1 (type t))
(block template2 (blockinherit template1) (optional o (allow t t (file (read))))
(block b (blockinherit template2))
semodule -i test.cil
sesearch -A -t b.t

With more templates, this break as well.

But the following works:

(block template1 (type t))
(block template2 (optional o (allow t t (file (read)))))
(block template3 (optional o (allow t t (file (write)))))
(block b (blockinherit template1) (blockinherit template2) (blockinherit template3))

Quoted 5 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file { read write };

Again, I'm not sure if this is the best solution, just the only one I managed to get working.

Looks good enough to me (if it works then it works). I am just surprised that the duplicate 'o' optional block is allowed.

Duplicate type declarations are no longer allowed as you noticed, but fortunately you do not need them.

Whether this eventually is the best solution probably depends on other aspects of the policy and on the requirements.

Quoted 14 lines

Vit

Quoted 10 lines
Quoted 10 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file read;

Any pointers would be appreciated.

Thank you.

Vit

Signature · 4 lines
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift
author
#4 lore raw
Quoted 87 lines · Dominick Grift
Quoted 25 lines · Vit Mojzis
Quoted 24 lines · Dominick Grift
Quoted 8 lines · Vit Mojzis

Hi,
recent changes in block inheritance broke our use case where we use block inheritance for generating container policies
(https://github.com/containers/udica/tree/main/udica/templates). Basically the policy is composed by inheriting selected "template" blocks, all of which inherit "container" block, so that they can use types defined there.

Quoted 4 lines

Reproducer:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

In this example there is no point in inheriting template1, because template2 already inherits it.

(block template1

         (type t))
(block template2
         (blockinherit template1))
(block b (blockinherit template2)
         (allow t t (file (read))))
Quoted 8 lines
Quoted 2 lines

semodule -i test.cil
seinfo -t b.t

Sure, but with more templates (as we have in udica) we get the same issue.

(block template1 (type t) )
(block template2 (blockinherit template1))
(block template3 (blockinherit template1))
(block b (blockinherit template2) (blockinherit template3))

This boils down to the same as above, yes.

Quoted 50 lines
# semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1
Failed to copy block contents into blockinherit
Failed to resolve AST
semodule:  Failed!

Template2 and template3 mostly inherit template1 for the type defined there (so that they can define rules containing the type).

Quoted 22 lines
Quoted 15 lines

#semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1 Failed to copy block contents into blockinherit Failed to resolve AST
semodule: Failed!

This used to work just fine.

The following workaround seems to be working as intended, but I'm not sure if it's the best approach. Types are only defined in template1 and the rest contains "optional" block, so that I can use types defined in template1).

Quoted 7 lines

(block template1 (type t))
(block template2
     (optional o
         (allow t t ( file ( read )))
     )
)
(block b (blockinherit template1) (blockinherit template2))

Quoted 8 lines

You can just do something like this:

(block template1 (type t))
(block template2 (blockinherit template1) (optional o (allow t t (file (read))))
(block b (blockinherit template2))
semodule -i test.cil
sesearch -A -t b.t

With more templates, this break as well.

But the following works:

(block template1 (type t))
(block template2 (optional o (allow t t (file (read)))))
(block template3 (optional o (allow t t (file (write)))))
(block b (blockinherit template1) (blockinherit template2) (blockinherit template3))

Quoted 7 lines
Quoted 5 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file { read write };

Again, I'm not sure if this is the best solution, just the only one I managed to get working.

Looks good enough to me (if it works then it works). I am just surprised that the duplicate 'o' optional block is allowed.

Thanks, I'll use different names for the optional blocks just to be sure.

Quoted 6 lines

Duplicate type declarations are no longer allowed as you noticed, but fortunately you do not need them.

Whether this eventually is the best solution probably depends on other aspects of the policy and on the requirements.

Sure, I guess I just needed to know that I'm not doing something wrong. Thank you.

Vit

Quoted 13 lines
Quoted 13 lines

Vit

Quoted 10 lines
Quoted 10 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file read;

Any pointers would be appreciated.

Thank you.

Vit

#5 lore raw
In reply to Dominick Grift
Quoted 91 lines · Dominick Grift
Quoted 25 lines · Vit Mojzis
Quoted 24 lines · Dominick Grift
Quoted 8 lines · Vit Mojzis

Hi,
recent changes in block inheritance broke our use case where we use block inheritance for generating container policies
(https://github.com/containers/udica/tree/main/udica/templates). Basically the policy is composed by inheriting selected "template" blocks, all of which inherit "container" block, so that they can use types defined there.

Quoted 4 lines

Reproducer:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

In this example there is no point in inheriting template1, because template2 already inherits it.

(block template1

        (type t))
(block template2
        (blockinherit template1))
(block b (blockinherit template2)
        (allow t t (file (read))))
Quoted 8 lines
Quoted 2 lines

semodule -i test.cil
seinfo -t b.t

Sure, but with more templates (as we have in udica) we get the same issue.

(block template1 (type t) )
(block template2 (blockinherit template1))
(block template3 (blockinherit template1))
(block b (blockinherit template2) (blockinherit template3))

This boils down to the same as above, yes.

Quoted 52 lines
# semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1
Failed to copy block contents into blockinherit
Failed to resolve AST
semodule:  Failed!

Template2 and template3 mostly inherit template1 for the type defined there (so that they can define rules containing the type).

Quoted 23 lines
Quoted 16 lines

#semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1 Failed to copy block contents into blockinherit Failed to resolve AST
semodule: Failed!

This used to work just fine.

The following workaround seems to be working as intended, but I'm not sure if it's the best approach. Types are only defined in template1 and the rest contains "optional" block, so that I can use types defined in template1).

Quoted 7 lines

(block template1 (type t))
(block template2
(optional o
(allow t t ( file ( read )))
)
)
(block b (blockinherit template1) (blockinherit template2))

Quoted 8 lines

You can just do something like this:

(block template1 (type t))
(block template2 (blockinherit template1) (optional o (allow t t (file (read))))
(block b (blockinherit template2))
semodule -i test.cil
sesearch -A -t b.t

With more templates, this break as well.

But the following works:

(block template1 (type t))
(block template2 (optional o (allow t t (file (read)))))
(block template3 (optional o (allow t t (file (write)))))
(block b (blockinherit template1) (blockinherit template2) (blockinherit template3))

Quoted 9 lines
Quoted 5 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file { read write };

Again, I'm not sure if this is the best solution, just the only one I managed to get working.

Looks good enough to me (if it works then it works). I am just surprised that the duplicate 'o' optional block is allowed.

Duplicate optional blocks are allowed unless an in-statement refers to one of them, because that is the only time the name matters.

Quoted 3 lines

Duplicate type declarations are no longer allowed as you noticed, but fortunately you do not need them.

Duplicate types are allowed when using secilc with the "-m" option. Unfortunately, that doesn't help when using semodule. It would probably be possible to add the option if necessary.

Jim

Quoted 23 lines

Whether this eventually is the best solution probably depends on other aspects of the policy and on the requirements.

Quoted 14 lines

Vit

Quoted 10 lines
Quoted 10 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file read;

Any pointers would be appreciated.

Thank you.

Vit

--
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6 E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift

#6 lore raw
In reply to Vit Mojzis
Quoted 85 lines · Vit Mojzis
Quoted 18 lines · Dominick Grift
Quoted 8 lines · Vit Mojzis

Hi,
recent changes in block inheritance broke our use case where we use block inheritance for generating container policies
(https://github.com/containers/udica/tree/main/udica/templates). Basically the policy is composed by inheriting selected "template" blocks, all of which inherit "container" block, so that they can use types defined there.

Quoted 4 lines

Reproducer:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

In this example there is no point in inheriting template1, because template2 already inherits it.

(block template1

Quoted 8 lines
        (type t))
(block template2
        (blockinherit template1))
(block b (blockinherit template2)
        (allow t t (file (read))))

semodule -i test.cil
seinfo -t b.t

Sure, but with more templates (as we have in udica) we get the same issue.

(block template1 (type t) )
(block template2 (blockinherit template1))
(block template3 (blockinherit template1))
(block b (blockinherit template2) (blockinherit template3))

# semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1
Failed to copy block contents into blockinherit
Failed to resolve AST
semodule:  Failed!

Template2 and template3 mostly inherit template1 for the type defined there (so that they can define rules containing the type).

Quoted 23 lines
Quoted 16 lines

#semodule -i test.cil
Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1 Failed to copy block contents into blockinherit Failed to resolve AST
semodule: Failed!

This used to work just fine.

The following workaround seems to be working as intended, but I'm not sure if it's the best approach. Types are only defined in template1 and the rest contains "optional" block, so that I can use types defined in template1).

Quoted 7 lines

(block template1 (type t))
(block template2
     (optional o
         (allow t t ( file ( read )))
     )
)
(block b (blockinherit template1) (blockinherit template2))

Quoted 8 lines

You can just do something like this:

(block template1 (type t))
(block template2 (blockinherit template1) (optional o (allow t t (file (read))))
(block b (blockinherit template2))
semodule -i test.cil
sesearch -A -t b.t

With more templates, this break as well.

But the following works:

(block template1 (type t))
(block template2 (optional o (allow t t (file (read)))))
(block template3 (optional o (allow t t (file (write)))))
(block b (blockinherit template1) (blockinherit template2) (blockinherit template3))

Quoted 5 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file { read write };

Again, I'm not sure if this is the best solution, just the only one I managed to get working.

Regardless, when push comes to shove compatiblity is probably just broken. People might have modules loaded that rely on this old behavior and upgrading SELinux user space could probably cause issues.

Quoted 14 lines

Vit

Quoted 10 lines
Quoted 10 lines

#semodule -i test.cil
#sesearch -A -s b.t
allow b.t b.t:file read;

Any pointers would be appreciated.

Thank you.

Vit

Signature · 4 lines
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift