Skip to contentSkip to conversation

ipe: return -ESTALE instead of -EINVAL on update when new policy has a lower version

PATCH Superseded [email protected] 3 participants 7 messages Sep 22, 2024 – Sep 25, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ipe: return -ESTALE instead of -EINVAL on update when new policy has a lower version

From: Luca Boccassi <[email protected]>

When loading policies in userspace we want a recognizable error when an update attempts to use an old policy, as that is an error that needs to be treated differently from an invalid policy. Use -ESTALE as it is clear enough for an update mechanism.

---
Found while adding policy loading to systemd, like we do for IMA/SELinux
https://github.com/systemd/systemd/pull/34418

 security/ipe/policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/policy.c +1 -1
index 67a051620889..5de64441dfe7 100644
@@ -116,7 +116,7 @@ int ipe_update_policy(struct inode *root, const char *text, size_t textlen,
 	}
 
 	if (ver_to_u64(old) > ver_to_u64(new)) {
-		rc = -EINVAL;
+		rc = -ESTALE;
 		goto err;
 	}
 
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/2 ipe: also reject policy updates with the same version

From: Luca Boccassi <[email protected]>

Currently IPE accepts an update that has the same version as the policy being updated, but it doesn't make it a no-op nor it checks that the old and new policyes are the same. So it is possible to change the content of a policy, without changing its version. This is very confusing from userspace when managing policies.
Instead change the update logic to reject updates that have the same version with ESTALE, as that is much clearer and intuitive behaviour.

---
 security/ipe/policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/policy.c +1 -1
index 5de64441dfe7..01da3a377e7f 100644
@@ -115,7 +115,7 @@ int ipe_update_policy(struct inode *root, const char *text, size_t textlen,
 		goto err;
 	}
 
-	if (ver_to_u64(old) > ver_to_u64(new)) {
+	if (ver_to_u64(old) >= ver_to_u64(new)) {
 		rc = -ESTALE;
 		goto err;
 	}
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] ipe: also reject policy updates with the same version

Quoted 11 lines · On Sun, Sep 22, 2024 at 03:56:14PM +0200, [email protected] wrote:

From: Luca Boccassi <[email protected]>

Currently IPE accepts an update that has the same version as the policy being updated, but it doesn't make it a no-op nor it checks that the old and new policyes are the same. So it is possible to change the content of a policy, without changing its version. This is very confusing from userspace when managing policies.
Instead change the update logic to reject updates that have the same version with ESTALE, as that is much clearer and intuitive behaviour.

Makes sense.

for both, thanks.

-serge

Quoted 20 lines
---
 security/ipe/policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/policy.c +1 -1
index 5de64441dfe7..01da3a377e7f 100644
@@ -115,7 +115,7 @@ int ipe_update_policy(struct inode *root, const char *text, size_t textlen,
 		goto err;
 	}
 
-	if (ver_to_u64(old) > ver_to_u64(new)) {
+	if (ver_to_u64(old) >= ver_to_u64(new)) {
 		rc = -ESTALE;
 		goto err;
 	}
Signature · 1 line
2.39.5
#3 lore raw

Re: [PATCH 2/2] ipe: also reject policy updates with the same version

In reply to [email protected]
Quoted 20 lines · On 9/22/2024 6:56 AM, [email protected] wrote:

From: Luca Boccassi <[email protected]>

Currently IPE accepts an update that has the same version as the policy being updated, but it doesn't make it a no-op nor it checks that the old and new policyes are the same. So it is possible to change the content of a policy, without changing its version. This is very confusing from userspace when managing policies.
Instead change the update logic to reject updates that have the same version with ESTALE, as that is much clearer and intuitive behaviour.

---
  security/ipe/policy.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/policy.c +0 -0
index 5de64441dfe7..01da3a377e7f 100644

security/ipe/policy.c int ipe_update_policy(struct inode *root, const char *text, size_t textlen, · line 121

Quoted 8 lines
security/ipe/policy.c +1 -1
@@ -115,7 +115,7 @@ int ipe_update_policy(struct inode *root, const char *text, size_t textlen,
  		goto err;
  	}
 
-	if (ver_to_u64(old) > ver_to_u64(new)) {
+	if (ver_to_u64(old) >= ver_to_u64(new)) {
  		rc = -ESTALE;
  		goto err;
  	}

Hi Luca,

Can you elaborate more about the potential confusion for the userspace users?

The policy version is currently used to prevent the activation of outdated or vulnerable policies (e.g., to avoid activating a policy trusting a compromised device). The version is not incremented unless a vulnerability is identified. Essentially, version comparison acts as a minimum threshold, ensuring only policies that meet or exceed this version can be activated.

Additionally, the version check is performed in ipe_set_active_pol(), so it will need to be updated accordingly. The documentation should also be refreshed to reflect these changes and ensure consistency with the new version handling process.

-Fan

#4 lore raw

Re: [PATCH 2/2] ipe: also reject policy updates with the same version

Quoted 37 lines · Fan Wu
Quoted 20 lines · On 9/22/2024 6:56 AM, [email protected] wrote:

From: Luca Boccassi <[email protected]>

Currently IPE accepts an update that has the same version as the policy being updated, but it doesn't make it a no-op nor it checks that the old and new policyes are the same. So it is possible to change the content of a policy, without changing its version. This is very confusing from userspace when managing policies.
Instead change the update logic to reject updates that have the same version with ESTALE, as that is much clearer and intuitive behaviour.

---
  security/ipe/policy.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/policy.c +0 -0
index 5de64441dfe7..01da3a377e7f 100644

security/ipe/policy.c int ipe_update_policy(struct inode *root, const char *text, size_t textlen, · line 121

Quoted 8 lines
security/ipe/policy.c +1 -1
@@ -115,7 +115,7 @@ int ipe_update_policy(struct inode *root, const char *text, size_t textlen,
              goto err;
      }
 
-     if (ver_to_u64(old) > ver_to_u64(new)) {
+     if (ver_to_u64(old) >= ver_to_u64(new)) {
              rc = -ESTALE;
              goto err;
      }

Hi Luca,

Can you elaborate more about the potential confusion for the userspace users?

Quoted 6 lines

The policy version is currently used to prevent the activation of outdated or vulnerable policies (e.g., to avoid activating a policy trusting a compromised device). The version is not incremented unless a vulnerability is identified. Essentially, version comparison acts as a minimum threshold, ensuring only policies that meet or exceed this version can be activated.

"Version" suggests something that is bumped every time there is a change, that's usually what the term is used for. The fact that one can change the policy without changing the version confused me a lot. Perhaps it should be renamed to "generation" or so, to make it more clear that it is not intended to be changed every time, but just to signal the start of a new generation to avoid downgrade attacks?

Quoted 6 lines

Additionally, the version check is performed in ipe_set_active_pol(), so it will need to be updated accordingly. The documentation should also be refreshed to reflect these changes and ensure consistency with the new version handling process.

-Fan

#5 lore raw

Re: [PATCH 2/2] ipe: also reject policy updates with the same version

Quoted 4 lines · Luca Boccassi
Quoted 3 lines · Fan Wu

...

Quoted 12 lines
Quoted 11 lines

Hi Luca,

Can you elaborate more about the potential confusion for the userspace users?

The policy version is currently used to prevent the activation of outdated or vulnerable policies (e.g., to avoid activating a policy trusting a compromised device). The version is not incremented unless a vulnerability is identified. Essentially, version comparison acts as a minimum threshold, ensuring only policies that meet or exceed this version can be activated.

Quoted 7 lines

"Version" suggests something that is bumped every time there is a change, that's usually what the term is used for. The fact that one can change the policy without changing the version confused me a lot. Perhaps it should be renamed to "generation" or so, to make it more clear that it is not intended to be changed every time, but just to signal the start of a new generation to avoid downgrade attacks?

I’m inclined to keep the 'version' name, but I agree with your point. Requiring a newer version for policy updates makes sense to me. As for the version check in ipe_set_active_pol(), we can maintain the current behavior, allowing the version to continue serving as a minimum threshold for activating a policy. In this case, I think the only change needed for this patch is to update the documentation for the update operation.

-Fan

#6 lore raw

Re: [PATCH 2/2] ipe: also reject policy updates with the same version

Quoted 37 lines · Fan Wu
Quoted 4 lines · Luca Boccassi
Quoted 3 lines · Fan Wu

...

Quoted 12 lines
Quoted 11 lines

Hi Luca,

Can you elaborate more about the potential confusion for the userspace users?

The policy version is currently used to prevent the activation of outdated or vulnerable policies (e.g., to avoid activating a policy trusting a compromised device). The version is not incremented unless a vulnerability is identified. Essentially, version comparison acts as a minimum threshold, ensuring only policies that meet or exceed this version can be activated.

Quoted 7 lines

"Version" suggests something that is bumped every time there is a change, that's usually what the term is used for. The fact that one can change the policy without changing the version confused me a lot. Perhaps it should be renamed to "generation" or so, to make it more clear that it is not intended to be changed every time, but just to signal the start of a new generation to avoid downgrade attacks?

I’m inclined to keep the 'version' name, but I agree with your point. Requiring a newer version for policy updates makes sense to me. As for the version check in ipe_set_active_pol(), we can maintain the current behavior, allowing the version to continue serving as a minimum threshold for activating a policy. In this case, I think the only change needed for this patch is to update the documentation for the update operation.

Quoted 1 line

-Fan

Sure, just sent v2 with the doc update, thanks.