Commit a4014d8f authored by David Howells's avatar David Howells Committed by Linus Torvalds

[PATCH] Keys: Base keyring size on key pointer not key struct

The attached patch makes the keyring functions calculate the new size of a
keyring's payload based on the size of pointer to the key struct, not the size
of the key struct itself.
Signed-Off-By: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 682d4fc9
...@@ -129,7 +129,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source) ...@@ -129,7 +129,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source)
int loop, ret; int loop, ret;
const unsigned limit = const unsigned limit =
(PAGE_SIZE - sizeof(*klist)) / sizeof(struct key); (PAGE_SIZE - sizeof(*klist)) / sizeof(struct key *);
ret = 0; ret = 0;
...@@ -150,7 +150,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source) ...@@ -150,7 +150,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source)
max = limit; max = limit;
ret = -ENOMEM; ret = -ENOMEM;
size = sizeof(*klist) + sizeof(struct key) * max; size = sizeof(*klist) + sizeof(struct key *) * max;
klist = kmalloc(size, GFP_KERNEL); klist = kmalloc(size, GFP_KERNEL);
if (!klist) if (!klist)
goto error; goto error;
...@@ -163,7 +163,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source) ...@@ -163,7 +163,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source)
klist->nkeys = sklist->nkeys; klist->nkeys = sklist->nkeys;
memcpy(klist->keys, memcpy(klist->keys,
sklist->keys, sklist->keys,
sklist->nkeys * sizeof(struct key)); sklist->nkeys * sizeof(struct key *));
for (loop = klist->nkeys - 1; loop >= 0; loop--) for (loop = klist->nkeys - 1; loop >= 0; loop--)
atomic_inc(&klist->keys[loop]->usage); atomic_inc(&klist->keys[loop]->usage);
...@@ -783,7 +783,7 @@ int __key_link(struct key *keyring, struct key *key) ...@@ -783,7 +783,7 @@ int __key_link(struct key *keyring, struct key *key)
ret = -ENFILE; ret = -ENFILE;
if (max > 65535) if (max > 65535)
goto error3; goto error3;
size = sizeof(*klist) + sizeof(*key) * max; size = sizeof(*klist) + sizeof(struct key *) * max;
if (size > PAGE_SIZE) if (size > PAGE_SIZE)
goto error3; goto error3;
...@@ -895,7 +895,8 @@ int key_unlink(struct key *keyring, struct key *key) ...@@ -895,7 +895,8 @@ int key_unlink(struct key *keyring, struct key *key)
key_is_present: key_is_present:
/* we need to copy the key list for RCU purposes */ /* we need to copy the key list for RCU purposes */
nklist = kmalloc(sizeof(*klist) + sizeof(*key) * klist->maxkeys, nklist = kmalloc(sizeof(*klist) +
sizeof(struct key *) * klist->maxkeys,
GFP_KERNEL); GFP_KERNEL);
if (!nklist) if (!nklist)
goto nomem; goto nomem;
...@@ -905,12 +906,12 @@ int key_unlink(struct key *keyring, struct key *key) ...@@ -905,12 +906,12 @@ int key_unlink(struct key *keyring, struct key *key)
if (loop > 0) if (loop > 0)
memcpy(&nklist->keys[0], memcpy(&nklist->keys[0],
&klist->keys[0], &klist->keys[0],
loop * sizeof(klist->keys[0])); loop * sizeof(struct key *));
if (loop < nklist->nkeys) if (loop < nklist->nkeys)
memcpy(&nklist->keys[loop], memcpy(&nklist->keys[loop],
&klist->keys[loop + 1], &klist->keys[loop + 1],
(nklist->nkeys - loop) * sizeof(klist->keys[0])); (nklist->nkeys - loop) * sizeof(struct key *));
/* adjust the user's quota */ /* adjust the user's quota */
key_payload_reserve(keyring, key_payload_reserve(keyring,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment