Skip to content

Commit

Permalink
KEYS: Add an RCU payload dereference macro
Browse files Browse the repository at this point in the history
Add an RCU payload dereference macro as this seems to be a common piece of code
amongst key types that use RCU referenced payloads.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
  • Loading branch information
David Howells authored and James Morris committed Mar 8, 2011
1 parent 1cc26ba commit 633e804
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions include/linux/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ static inline key_serial_t key_serial(struct key *key)
return key ? key->serial : 0;
}

#define rcu_dereference_key(KEY) \
(rcu_dereference_protected((KEY)->payload.rcudata, \
rwsem_is_locked(&((struct key *)(KEY))->sem)))

#ifdef CONFIG_SYSCTL
extern ctl_table key_sysctls[];
#endif
Expand Down
3 changes: 1 addition & 2 deletions security/keys/encrypted.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,7 @@ static long encrypted_read(const struct key *key, char __user *buffer,
size_t asciiblob_len;
int ret;

epayload = rcu_dereference_protected(key->payload.data,
rwsem_is_locked(&((struct key *)key)->sem));
epayload = rcu_dereference_key(key);

/* returns the hex encoded iv, encrypted-data, and hmac as ascii */
asciiblob_len = epayload->datablob_len + ivsize + 1
Expand Down
3 changes: 1 addition & 2 deletions security/keys/trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,7 @@ static long trusted_read(const struct key *key, char __user *buffer,
char *bufp;
int i;

p = rcu_dereference_protected(key->payload.data,
rwsem_is_locked(&((struct key *)key)->sem));
p = rcu_dereference_key(key);
if (!p)
return -EINVAL;
if (!buffer || buflen <= 0)
Expand Down
3 changes: 1 addition & 2 deletions security/keys/user_defined.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ long user_read(const struct key *key, char __user *buffer, size_t buflen)
struct user_key_payload *upayload;
long ret;

upayload = rcu_dereference_protected(
key->payload.data, rwsem_is_locked(&((struct key *)key)->sem));
upayload = rcu_dereference_key(key);
ret = upayload->datalen;

/* we can return the data as is */
Expand Down

0 comments on commit 633e804

Please sign in to comment.