aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge E. Hallyn <serue@us.ibm.com>2009-09-16 17:27:41 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-10-09 16:47:24 -0400
commita8ba8bffbe1f3f8b3450d294b9e68d299b158209 (patch)
tree39d0dda740dd5dd97fece54db16600bffc60bb6f
parent3d14b518481eb1fa10c6f6ef9efd5f4cc0f84b28 (diff)
Staging: p9auth: a few fixes
1. The memory into which we copy 'u1@u2' needs space for u1, @, u2, and a final \0 which strcat copies in. 2. Strsep changes the value of its first argument. So use a temporary variable to pass to it, so we pass the original value to kfree! 3. Allocate an extra char to user_buf, because we need a trailing \0 since we later kstrdup it. I am about to send out an LTP testcase for this driver, but in addition the correctness of the hashing can be verified as follows: #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char *argv[]) { char in[41], out[20]; unsigned int v; int i, ret; ret = read(STDIN_FILENO, in, 40); if (ret != 40) exit(1); in[40] = '\0'; for (i = 0; i < 20; i++) { sscanf(&in[2*i], "%02x", &v); out[i] = v; } write(STDOUT_FILENO, out, 20); } as root, to test userid 501 switching to uid 0, choosing 'random' string 'ab': echo -n "501@0" > plain openssl sha1 -hmac 'ab' plain |awk '{ print $2 '} > dgst ./unhex < dgst > dgst.u mknod /dev/caphash 504 0 mknod /dev/capuse 504 1 chmod ugo+w /dev/capuse cat dgst.u > /dev/caphash as uid 501, echo "501@0@ab" > /dev/capuse id -u # should now show 0. Signed-off-by: Serge E. Hallyn <serue@us.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/p9auth/p9auth.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/staging/p9auth/p9auth.c b/drivers/staging/p9auth/p9auth.c
index 9111dcba37a1..8ccfff723eec 100644
--- a/drivers/staging/p9auth/p9auth.c
+++ b/drivers/staging/p9auth/p9auth.c
@@ -183,7 +183,7 @@ static ssize_t cap_write(struct file *filp, const char __user *buf,
183 user_buf_running = NULL; 183 user_buf_running = NULL;
184 hash_str = NULL; 184 hash_str = NULL;
185 node_ptr = kmalloc(sizeof(struct cap_node), GFP_KERNEL); 185 node_ptr = kmalloc(sizeof(struct cap_node), GFP_KERNEL);
186 user_buf = kzalloc(count, GFP_KERNEL); 186 user_buf = kzalloc(count+1, GFP_KERNEL);
187 if (!node_ptr || !user_buf) 187 if (!node_ptr || !user_buf)
188 goto out; 188 goto out;
189 189
@@ -207,6 +207,7 @@ static ssize_t cap_write(struct file *filp, const char __user *buf,
207 list_add(&(node_ptr->list), &(dev->head->list)); 207 list_add(&(node_ptr->list), &(dev->head->list));
208 node_ptr = NULL; 208 node_ptr = NULL;
209 } else { 209 } else {
210 char *tmpu;
210 if (!cap_devices[0].head || 211 if (!cap_devices[0].head ||
211 list_empty(&(cap_devices[0].head->list))) { 212 list_empty(&(cap_devices[0].head->list))) {
212 retval = -EINVAL; 213 retval = -EINVAL;
@@ -218,10 +219,10 @@ static ssize_t cap_write(struct file *filp, const char __user *buf,
218 * need to split it and hash 'user1@user2' using 'randomstring' 219 * need to split it and hash 'user1@user2' using 'randomstring'
219 * as the key. 220 * as the key.
220 */ 221 */
221 user_buf_running = kstrdup(user_buf, GFP_KERNEL); 222 tmpu = user_buf_running = kstrdup(user_buf, GFP_KERNEL);
222 source_user = strsep(&user_buf_running, "@"); 223 source_user = strsep(&tmpu, "@");
223 target_user = strsep(&user_buf_running, "@"); 224 target_user = strsep(&tmpu, "@");
224 rand_str = strsep(&user_buf_running, "@"); 225 rand_str = tmpu;
225 if (!source_user || !target_user || !rand_str) { 226 if (!source_user || !target_user || !rand_str) {
226 retval = -EINVAL; 227 retval = -EINVAL;
227 goto out; 228 goto out;
@@ -229,7 +230,8 @@ static ssize_t cap_write(struct file *filp, const char __user *buf,
229 230
230 /* hash the string user1@user2 with rand_str as the key */ 231 /* hash the string user1@user2 with rand_str as the key */
231 len = strlen(source_user) + strlen(target_user) + 1; 232 len = strlen(source_user) + strlen(target_user) + 1;
232 hash_str = kzalloc(len, GFP_KERNEL); 233 /* src, @, len, \0 */
234 hash_str = kzalloc(len+1, GFP_KERNEL);
233 strcat(hash_str, source_user); 235 strcat(hash_str, source_user);
234 strcat(hash_str, "@"); 236 strcat(hash_str, "@");
235 strcat(hash_str, target_user); 237 strcat(hash_str, target_user);