{
char *payload;
+ /*
+ * If the payload is less than or equal to the size of a pointer, then
+ * an allocation here is wasteful. Just copy the data directly to the
+ * payload.value union member instead.
+ *
+ * With this however, you must check the datalen before trying to
+ * dereference payload.data!
+ */
+ if (prep->datalen <= sizeof(void *)) {
+ key->payload.value = 0;
+ memcpy(&key->payload.value, prep->data, prep->datalen);
+ key->datalen = prep->datalen;
+ return 0;
+ }
payload = kmalloc(prep->datalen, GFP_KERNEL);
if (!payload)
return -ENOMEM;
static inline void
cifs_idmap_key_destroy(struct key *key)
{
- kfree(key->payload.data);
+ if (key->datalen > sizeof(void *))
+ kfree(key->payload.data);
}
static struct key_type cifs_idmap_key_type = {
* probably a safe assumption but might be better to check based on
* sidtype.
*/
- if (sidkey->datalen < sizeof(uid_t)) {
+ if (sidkey->datalen != sizeof(uid_t)) {
rc = -EIO;
cFYI(1, "%s: Downcall contained malformed key "
"(datalen=%hu)", __func__, sidkey->datalen);
}
if (sidtype == SIDOWNER)
- fuid = *(uid_t *)sidkey->payload.value;
+ fuid = (uid_t)sidkey->payload.value;
else
- fgid = *(gid_t *)sidkey->payload.value;
+ fgid = (gid_t)sidkey->payload.value;
out_key_put:
key_put(sidkey);