Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 2 participants 4 messages Sep 25, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
 security/ipe/policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/policy.c +1 -1
index bf5aa97911e1..3a0069c6d5af 100644
@@ -107,7 +107,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 v2 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.

---
v2: also update documentation

 Documentation/admin-guide/LSM/ipe.rst | 2 +-
 security/ipe/policy.c                 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/admin-guide/LSM/ipe.rst +1 -1
index 47323494d119..7cd04d3261ad 100644
@@ -269,7 +269,7 @@ in the kernel. This file is write-only and accepts a PKCS#7 signed
 policy. Two checks will always be performed on this policy: First, the
 ``policy_names`` must match with the updated version and the existing
 version. Second the updated policy must have a policy version greater than
-or equal to the currently-running version. This is to prevent rollback attacks.
+to the currently-running version. This is to prevent rollback attacks.
 
 The ``delete`` file is used to remove a policy that is no longer needed.
 This file is write-only and accepts a value of ``1`` to delete the policy.
security/ipe/policy.c +1 -1
index 3a0069c6d5af..45f7d6a0ed23 100644
@@ -106,7 +106,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
#2 lore raw

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

Quoted 24 lines · On 9/25/2024 1:42 PM, [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.

---
v2: also update documentation

  Documentation/admin-guide/LSM/ipe.rst | 2 +-
  security/ipe/policy.c                 | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/admin-guide/LSM/ipe.rst +0 -0
index 47323494d119..7cd04d3261ad 100644

Documentation/admin-guide/LSM/ipe.rst in the kernel. This file is write-only and accepts a PKCS#7 signed · line 272

Quoted 5 lines
Documentation/admin-guide/LSM/ipe.rst +1 -1
@@ -269,7 +269,7 @@ in the kernel. This file is write-only and accepts a PKCS#7 signed
  policy. Two checks will always be performed on this policy: First, the
  ``policy_names`` must match with the updated version and the existing
  version. Second the updated policy must have a policy version greater than
-or equal to the currently-running version. This is to prevent rollback attacks.
+to the currently-running version. This is to prevent rollback attacks.

The "to" here should also be removed.

-Fan

Quoted 16 lines
Documentation/admin-guide/LSM/ipe.rst +0 -0
  The ``delete`` file is used to remove a policy that is no longer needed.
  This file is write-only and accepts a value of ``1`` to delete the policy.
security/ipe/policy.c +1 -1
index 3a0069c6d5af..45f7d6a0ed23 100644
@@ -106,7 +106,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;
  	}
Acked-by on v2 1/2
#3 lore raw
In reply to [email protected]
Quoted 18 lines · On 9/25/2024 1:42 PM, [email protected] wrote:

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.

---
  security/ipe/policy.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/policy.c +0 -0
index bf5aa97911e1..3a0069c6d5af 100644

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

Quoted 8 lines
security/ipe/policy.c +1 -1
@@ -107,7 +107,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;
  	}
 

I'm still in the process of applying kernel.org account, once I get everything setup I will include this in my tree.

If that process take too long time I may ask Paul to merge this from the lsm tree in next merge window.

-Fan