Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 339482
b: refs/heads/master
c: 41a9f1f
h: refs/heads/master
v: v3
  • Loading branch information
Jeff Layton authored and Steve French committed Dec 9, 2012
1 parent 1a036b7 commit eb822a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: faa65f07d21e7d37190c91fdcf9f940d733ae3cc
refs/heads/master: 41a9f1f6b38664fc08431674d87871a57d763be1
23 changes: 19 additions & 4 deletions trunk/fs/cifs/cifsacl.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
{
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;
Expand All @@ -62,7 +76,8 @@ cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
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 = {
Expand Down Expand Up @@ -245,17 +260,17 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
* 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);
goto out_key_put;
}

if (sidtype == SIDOWNER)
fuid = *(uid_t *)sidkey->payload.value;
memcpy(&fuid, &sidkey->payload.value, sizeof(uid_t));
else
fgid = *(gid_t *)sidkey->payload.value;
memcpy(&fgid, &sidkey->payload.value, sizeof(gid_t));

out_key_put:
key_put(sidkey);
Expand Down

0 comments on commit eb822a4

Please sign in to comment.