Skip to contentSkip to conversation

KEYS: fix KEYCTL_INSTANTIATE_IOV error case memory leak

PATCH New Tommi Rantala 1 participant 1 message Nov 2, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KEYS: fix KEYCTL_INSTANTIATE_IOV error case memory leak

Avoid leaking memory in the keyctl() KEYCTL_INSTANTIATE_IOV operation, by also checking in the error case if rw_copy_check_uvector() kmalloc'd memory for us.

Discovered with Trinity.

---
 security/keys/keyctl.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/keys/keyctl.c +2 -1
index 5d34b4e..a2c32a2 100644
@@ -1132,12 +1132,13 @@ long keyctl_instantiate_key_iov(key_serial_t id,
 	ret = rw_copy_check_uvector(WRITE, _payload_iov, ioc,
 				    ARRAY_SIZE(iovstack), iovstack, &iov);
 	if (ret < 0)
-		return ret;
+		goto out;
 	if (ret == 0)
 		goto no_payload_free;
 
 	ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
 
+out:
 	if (iov != iovstack)
 		kfree(iov);
 	return ret;
Signature · 1 line
1.7.9.5