Skip to contentSkip to conversation

checkpolicy: Check the right bits of an ibpkeycon rule subnet prefix

PATCH Applied James Carter 2 participants 4 messages Jul 8, 2024 – Jul 29, 2024 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpolicy: Check the right bits of an ibpkeycon rule subnet prefix

The lower 64 bits of the subnet prefix for an ibpkeycon rule should all be 0's. Unfortunately the check uses the s6_addr macro which refers to the 16 entry array of 8-bit values in the union and does not refer to the correct bits.

Use the s6_addr32 macro instead which refers to the 4 entry array of 32-bit values in the union and refers to the lower 64 bits.

---
 checkpolicy/policy_define.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
checkpolicy/policy_define.c +1 -1
index 4931f23d..bfeda86b 100644
@@ -5036,7 +5036,7 @@ int define_ibpkey_context(unsigned int low, unsigned int high)
 		goto out;
 	}
 
-	if (subnet_prefix.s6_addr[2] || subnet_prefix.s6_addr[3]) {
+	if (subnet_prefix.s6_addr32[2] || subnet_prefix.s6_addr32[3]) {
 		yyerror("subnet prefix should be 0's in the low order 64 bits.");
 		rc = -1;
 		goto out;
Signature · 1 line
2.45.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · James Carter

The lower 64 bits of the subnet prefix for an ibpkeycon rule should all be 0's. Unfortunately the check uses the s6_addr macro which refers to the 16 entry array of 8-bit values in the union and does not refer to the correct bits.

Use the s6_addr32 macro instead which refers to the 4 entry array of 32-bit values in the union and refers to the lower 64 bits.

Quoted 21 lines
---
 checkpolicy/policy_define.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
checkpolicy/policy_define.c +1 -2
index 4931f23d..bfeda86b 100644
@@ -5036,7 +5036,7 @@ int define_ibpkey_context(unsigned int low, unsigned int high)
                goto out;
        }
 
-       if (subnet_prefix.s6_addr[2] || subnet_prefix.s6_addr[3]) {
+       if (subnet_prefix.s6_addr32[2] || subnet_prefix.s6_addr32[3]) {
                yyerror("subnet prefix should be 0's in the low order 64 bits.");
                rc = -1;
                goto out;
--

2.45.2

maintainer
#2 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · James Carter

The lower 64 bits of the subnet prefix for an ibpkeycon rule should all be 0's. Unfortunately the check uses the s6_addr macro which refers to the 16 entry array of 8-bit values in the union and does not refer to the correct bits.

Quoted 6 lines
Quoted 4 lines

Use the s6_addr32 macro instead which refers to the 4 entry array of 32-bit values in the union and refers to the lower 64 bits.

One caveat here is that I believe this breaks building checkpolicy on macOS because s6_addr32 is non-portable.
But it looks like a previous commit re-introduced the usage of s6_addr32 (we had gotten rid of them earlier to avoid needing ifdefs for macOS).

Quoted 22 lines
Quoted 22 lines
---
 checkpolicy/policy_define.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
checkpolicy/policy_define.c +1 -2
index 4931f23d..bfeda86b 100644
@@ -5036,7 +5036,7 @@ int define_ibpkey_context(unsigned int low, unsigned int high)
                goto out;
        }
 
-       if (subnet_prefix.s6_addr[2] || subnet_prefix.s6_addr[3]) {
+       if (subnet_prefix.s6_addr32[2] || subnet_prefix.s6_addr32[3]) {
                yyerror("subnet prefix should be 0's in the low order 64 bits.");
                rc = -1;
                goto out;
--

2.45.2

maintainer Applied
#3 lore raw
Quoted 16 lines · Stephen Smalley
Quoted 13 lines · Stephen Smalley
Quoted 10 lines · James Carter

The lower 64 bits of the subnet prefix for an ibpkeycon rule should all be 0's. Unfortunately the check uses the s6_addr macro which refers to the 16 entry array of 8-bit values in the union and does not refer to the correct bits.

Use the s6_addr32 macro instead which refers to the 4 entry array of 32-bit values in the union and refers to the lower 64 bits.

Quoted 7 lines
Quoted 1 line

One caveat here is that I believe this breaks building checkpolicy on macOS because s6_addr32 is non-portable.
But it looks like a previous commit re-introduced the usage of s6_addr32 (we had gotten rid of them earlier to avoid needing ifdefs for macOS).

Applied. We may need to revisit though at some point for macOS.