Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1586537
| From | Jan Stancek <jstancek@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/2] KEYS: add user_key_payload_rcu() |
| Date | 2017-02-23 00:00 +0100 |
| Message-ID | <tdO37-jP-5@gated-at.bofh.it> (permalink) |
| References | <tdO37-jP-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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(+)
diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt
index 3849814bfe6d..da89a854edd2 100644
--- a/Documentation/security/keys.txt
+++ b/Documentation/security/keys.txt
@@ -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
diff --git a/include/keys/user-type.h b/include/keys/user-type.h
index c56fef40f53e..521bf3369904 100644
--- a/include/keys/user-type.h
+++ b/include/keys/user-type.h
@@ -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 */
diff --git a/include/linux/key.h b/include/linux/key.h
index 722914798f37..b6a8c5896761 100644
--- a/include/linux/key.h
+++ b/include/linux/key.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)); \
--
1.8.3.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/2] key payload access with just rcu_read_lock() Jan Stancek <jstancek@redhat.com> - 2017-02-23 00:00 +0100
[PATCH 2/2] NFS: use user_key_payload_rcu() in RCU read-side section Jan Stancek <jstancek@redhat.com> - 2017-02-23 00:00 +0100
[PATCH 1/2] KEYS: add user_key_payload_rcu() Jan Stancek <jstancek@redhat.com> - 2017-02-23 00:00 +0100
Re: [PATCH 0/2] key payload access with just rcu_read_lock() David Howells <dhowells@redhat.com> - 2017-02-27 23:10 +0100
Re: [PATCH 0/2] key payload access with just rcu_read_lock() David Howells <dhowells@redhat.com> - 2017-02-28 02:20 +0100
Re: [PATCH 0/2] key payload access with just rcu_read_lock() Jan Stancek <jstancek@redhat.com> - 2017-02-28 10:20 +0100
Re: [PATCH 0/2] key payload access with just rcu_read_lock() David Howells <dhowells@redhat.com> - 2017-02-28 11:30 +0100
Re: [PATCH 0/2] key payload access with just rcu_read_lock() Jan Stancek <jstancek@redhat.com> - 2017-02-28 15:30 +0100
Re: [PATCH 0/2] key payload access with just rcu_read_lock() Jan Stancek <jstancek@redhat.com> - 2017-02-28 03:40 +0100
csiph-web