aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--security/keys/trusted.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index bd85315cbfeb..98aa89ff7bfd 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -1147,20 +1147,21 @@ static long trusted_read(const struct key *key, char __user *buffer,
1147 p = dereference_key_locked(key); 1147 p = dereference_key_locked(key);
1148 if (!p) 1148 if (!p)
1149 return -EINVAL; 1149 return -EINVAL;
1150 if (!buffer || buflen <= 0)
1151 return 2 * p->blob_len;
1152 ascii_buf = kmalloc(2 * p->blob_len, GFP_KERNEL);
1153 if (!ascii_buf)
1154 return -ENOMEM;
1155 1150
1156 bufp = ascii_buf; 1151 if (buffer && buflen >= 2 * p->blob_len) {
1157 for (i = 0; i < p->blob_len; i++) 1152 ascii_buf = kmalloc(2 * p->blob_len, GFP_KERNEL);
1158 bufp = hex_byte_pack(bufp, p->blob[i]); 1153 if (!ascii_buf)
1159 if ((copy_to_user(buffer, ascii_buf, 2 * p->blob_len)) != 0) { 1154 return -ENOMEM;
1155
1156 bufp = ascii_buf;
1157 for (i = 0; i < p->blob_len; i++)
1158 bufp = hex_byte_pack(bufp, p->blob[i]);
1159 if (copy_to_user(buffer, ascii_buf, 2 * p->blob_len) != 0) {
1160 kzfree(ascii_buf);
1161 return -EFAULT;
1162 }
1160 kzfree(ascii_buf); 1163 kzfree(ascii_buf);
1161 return -EFAULT;
1162 } 1164 }
1163 kzfree(ascii_buf);
1164 return 2 * p->blob_len; 1165 return 2 * p->blob_len;
1165} 1166}
1166 1167