aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2005-07-07 20:57:03 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-07 21:23:46 -0400
commita4014d8f61a6a136d22422cf8aa978e6495dbad9 (patch)
treebb5d995c2511b99e131ca92020ffc10cafee4447
parent682d4fc93105ebf0bdfbb04a4b85047999b17844 (diff)
[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: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--security/keys/keyring.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index 90a551e4da66..a1f6bac647a1 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -129,7 +129,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source)
129 int loop, ret; 129 int loop, ret;
130 130
131 const unsigned limit = 131 const unsigned limit =
132 (PAGE_SIZE - sizeof(*klist)) / sizeof(struct key); 132 (PAGE_SIZE - sizeof(*klist)) / sizeof(struct key *);
133 133
134 ret = 0; 134 ret = 0;
135 135
@@ -150,7 +150,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source)
150 max = limit; 150 max = limit;
151 151
152 ret = -ENOMEM; 152 ret = -ENOMEM;
153 size = sizeof(*klist) + sizeof(struct key) * max; 153 size = sizeof(*klist) + sizeof(struct key *) * max;
154 klist = kmalloc(size, GFP_KERNEL); 154 klist = kmalloc(size, GFP_KERNEL);
155 if (!klist) 155 if (!klist)
156 goto error; 156 goto error;
@@ -163,7 +163,7 @@ static int keyring_duplicate(struct key *keyring, const struct key *source)
163 klist->nkeys = sklist->nkeys; 163 klist->nkeys = sklist->nkeys;
164 memcpy(klist->keys, 164 memcpy(klist->keys,
165 sklist->keys, 165 sklist->keys,
166 sklist->nkeys * sizeof(struct key)); 166 sklist->nkeys * sizeof(struct key *));
167 167
168 for (loop = klist->nkeys - 1; loop >= 0; loop--) 168 for (loop = klist->nkeys - 1; loop >= 0; loop--)
169 atomic_inc(&klist->keys[loop]->usage); 169 atomic_inc(&klist->keys[loop]->usage);
@@ -783,7 +783,7 @@ int __key_link(struct key *keyring, struct key *key)
783 ret = -ENFILE; 783 ret = -ENFILE;
784 if (max > 65535) 784 if (max > 65535)
785 goto error3; 785 goto error3;
786 size = sizeof(*klist) + sizeof(*key) * max; 786 size = sizeof(*klist) + sizeof(struct key *) * max;
787 if (size > PAGE_SIZE) 787 if (size > PAGE_SIZE)
788 goto error3; 788 goto error3;
789 789
@@ -895,7 +895,8 @@ int key_unlink(struct key *keyring, struct key *key)
895 895
896key_is_present: 896key_is_present:
897 /* we need to copy the key list for RCU purposes */ 897 /* we need to copy the key list for RCU purposes */
898 nklist = kmalloc(sizeof(*klist) + sizeof(*key) * klist->maxkeys, 898 nklist = kmalloc(sizeof(*klist) +
899 sizeof(struct key *) * klist->maxkeys,
899 GFP_KERNEL); 900 GFP_KERNEL);
900 if (!nklist) 901 if (!nklist)
901 goto nomem; 902 goto nomem;
@@ -905,12 +906,12 @@ key_is_present:
905 if (loop > 0) 906 if (loop > 0)
906 memcpy(&nklist->keys[0], 907 memcpy(&nklist->keys[0],
907 &klist->keys[0], 908 &klist->keys[0],
908 loop * sizeof(klist->keys[0])); 909 loop * sizeof(struct key *));
909 910
910 if (loop < nklist->nkeys) 911 if (loop < nklist->nkeys)
911 memcpy(&nklist->keys[loop], 912 memcpy(&nklist->keys[loop],
912 &klist->keys[loop + 1], 913 &klist->keys[loop + 1],
913 (nklist->nkeys - loop) * sizeof(klist->keys[0])); 914 (nklist->nkeys - loop) * sizeof(struct key *));
914 915
915 /* adjust the user's quota */ 916 /* adjust the user's quota */
916 key_payload_reserve(keyring, 917 key_payload_reserve(keyring,