Skip to contentSkip to conversation

evm: fix writing <securityfs>/evm overflow

PATCH In review Mimi Zohar 2 participants 2 messages Apr 29, 2021

Subsystems (4)
lore
Share & tools
lore

Mimi Zohar

author maintainer
#0 lore raw

PATCH 1/1 evm: fix writing <securityfs>/evm overflow

EVM_SETUP_COMPLETE is defined as 0x80000000, which is larger than INT_MAX. The "-fno-strict-overflow" compiler option properly prevents signaling EVM that the EVM policy setup is complete. Define and read an unsigned int.

Fixes f00d79750712 ("EVM: Allow userspace to signal an RSA key has been

loaded")

---
 security/integrity/evm/evm_secfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/integrity/evm/evm_secfs.c +3 -2
index bbc85637e18b..0007d3362754 100644
@@ -66,12 +66,13 @@ static ssize_t evm_read_key(struct file *filp, char __user *buf,
 static ssize_t evm_write_key(struct file *file, const char __user *buf,
 			     size_t count, loff_t *ppos)
 {
-	int i, ret;
+	unsigned int i;
+	int ret;
 
 	if (!capable(CAP_SYS_ADMIN) || (evm_initialized & EVM_SETUP_COMPLETE))
 		return -EPERM;
 
-	ret = kstrtoint_from_user(buf, count, 0, &i);
+	ret = kstrtouint_from_user(buf, count, 0, &i);
 
 	if (ret)
 		return ret;
Signature · 1 line
2.27.0
Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Mimi Zohar

EVM_SETUP_COMPLETE is defined as 0x80000000, which is larger than INT_MAX. The "-fno-strict-overflow" compiler option properly prevents signaling EVM that the EVM policy setup is complete. Define and read an unsigned int.

Fixes f00d79750712 ("EVM: Allow userspace to signal an RSA key has been

loaded")

Quoted 24 lines
---
  security/integrity/evm/evm_secfs.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
security/integrity/evm/evm_secfs.c +3 -2
index bbc85637e18b..0007d3362754 100644
@@ -66,12 +66,13 @@ static ssize_t evm_read_key(struct file *filp, char __user *buf,
  static ssize_t evm_write_key(struct file *file, const char __user *buf,
  			     size_t count, loff_t *ppos)
  {
-	int i, ret;
+	unsigned int i;
+	int ret;
 
  	if (!capable(CAP_SYS_ADMIN) || (evm_initialized & EVM_SETUP_COMPLETE))
  		return -EPERM;
 
-	ret = kstrtoint_from_user(buf, count, 0, &i);
+	ret = kstrtouint_from_user(buf, count, 0, &i);
 
  	if (ret)
  		return ret;