@@ -1152,8 +1152,13 @@ access the data:
wrap the RCU calls to this element:
rcu_assign_keypointer(struct key *key, void *data);
+
+ /* access payload with semaphore held */
void *rcu_dereference_key(struct key *key);
+ /* access payload in RCU read-side section*/
+ void *rcu_read_dereference_key(struct key *key);
+
===================
DEFINING A KEY TYPE
@@ -53,6 +53,11 @@ static inline const struct user_key_payload *user_key_payload(const struct key *
return (struct user_key_payload *)rcu_dereference_key(key);
}
+static inline const struct user_key_payload *user_key_payload_rcu(const struct key *key)
+{
+ return (struct user_key_payload *)rcu_read_dereference_key(key);
+}
+
#endif /* CONFIG_KEYS */
#endif /* _KEYS_USER_TYPE_H */
@@ -358,6 +358,9 @@ static inline bool key_is_instantiated(const struct key *key)
(rcu_dereference_protected((KEY)->payload.rcu_data0, \
rwsem_is_locked(&((struct key *)(KEY))->sem)))
+#define rcu_read_dereference_key(KEY) \
+ (rcu_dereference((KEY)->payload.rcu_data0))
+
#define rcu_assign_keypointer(KEY, PAYLOAD) \
do { \
rcu_assign_pointer((KEY)->payload.rcu_data0, (PAYLOAD)); \
user_key_payload() is wrapper for rcu_dereference_protected(), and can't be used with just rcu_read_lock() held. This patch adds user_key_payload_rcu() for accessing key payload in RCU read-side section, without the need to hold key semaphore. Signed-off-by: Jan Stancek <jstancek@redhat.com> --- Documentation/security/keys.txt | 5 +++++ include/keys/user-type.h | 5 +++++ include/linux/key.h | 3 +++ 3 files changed, 13 insertions(+)