aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/key-ui.h41
-rw-r--r--include/linux/key.h9
-rw-r--r--include/linux/keyctl.h11
-rw-r--r--include/linux/sched.h8
4 files changed, 59 insertions, 10 deletions
diff --git a/include/linux/key-ui.h b/include/linux/key-ui.h
index 159ca8d54e9a..cc326174a808 100644
--- a/include/linux/key-ui.h
+++ b/include/linux/key-ui.h
@@ -1,4 +1,4 @@
1/* key-ui.h: key userspace interface stuff for use by keyfs 1/* key-ui.h: key userspace interface stuff
2 * 2 *
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. 3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com) 4 * Written by David Howells (dhowells@redhat.com)
@@ -84,8 +84,45 @@ static inline int key_any_permission(const struct key *key, key_perm_t perm)
84 return kperm != 0; 84 return kperm != 0;
85} 85}
86 86
87static inline int key_task_groups_search(struct task_struct *tsk, gid_t gid)
88{
89 int ret;
90
91 task_lock(tsk);
92 ret = groups_search(tsk->group_info, gid);
93 task_unlock(tsk);
94 return ret;
95}
96
97static inline int key_task_permission(const struct key *key,
98 struct task_struct *context,
99 key_perm_t perm)
100{
101 key_perm_t kperm;
102
103 if (key->uid == context->fsuid) {
104 kperm = key->perm >> 16;
105 }
106 else if (key->gid != -1 &&
107 key->perm & KEY_GRP_ALL && (
108 key->gid == context->fsgid ||
109 key_task_groups_search(context, key->gid)
110 )
111 ) {
112 kperm = key->perm >> 8;
113 }
114 else {
115 kperm = key->perm;
116 }
117
118 kperm = kperm & perm & KEY_ALL;
119
120 return kperm == perm;
121
122}
87 123
88extern struct key *lookup_user_key(key_serial_t id, int create, int part, 124extern struct key *lookup_user_key(struct task_struct *context,
125 key_serial_t id, int create, int partial,
89 key_perm_t perm); 126 key_perm_t perm);
90 127
91extern long join_session_keyring(const char *name); 128extern long join_session_keyring(const char *name);
diff --git a/include/linux/key.h b/include/linux/key.h
index 2bfbf88d2740..970bbd916cf4 100644
--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -199,10 +199,12 @@ extern int key_payload_reserve(struct key *key, size_t datalen);
199extern int key_instantiate_and_link(struct key *key, 199extern int key_instantiate_and_link(struct key *key,
200 const void *data, 200 const void *data,
201 size_t datalen, 201 size_t datalen,
202 struct key *keyring); 202 struct key *keyring,
203 struct key *instkey);
203extern int key_negate_and_link(struct key *key, 204extern int key_negate_and_link(struct key *key,
204 unsigned timeout, 205 unsigned timeout,
205 struct key *keyring); 206 struct key *keyring,
207 struct key *instkey);
206extern void key_revoke(struct key *key); 208extern void key_revoke(struct key *key);
207extern void key_put(struct key *key); 209extern void key_put(struct key *key);
208 210
@@ -245,9 +247,6 @@ extern struct key *keyring_search(struct key *keyring,
245 struct key_type *type, 247 struct key_type *type,
246 const char *description); 248 const char *description);
247 249
248extern struct key *search_process_keyrings(struct key_type *type,
249 const char *description);
250
251extern int keyring_add_key(struct key *keyring, 250extern int keyring_add_key(struct key *keyring,
252 struct key *key); 251 struct key *key);
253 252
diff --git a/include/linux/keyctl.h b/include/linux/keyctl.h
index 381dedc370a3..8d7c59a29e09 100644
--- a/include/linux/keyctl.h
+++ b/include/linux/keyctl.h
@@ -20,6 +20,16 @@
20#define KEY_SPEC_USER_SESSION_KEYRING -5 /* - key ID for UID-session keyring */ 20#define KEY_SPEC_USER_SESSION_KEYRING -5 /* - key ID for UID-session keyring */
21#define KEY_SPEC_GROUP_KEYRING -6 /* - key ID for GID-specific keyring */ 21#define KEY_SPEC_GROUP_KEYRING -6 /* - key ID for GID-specific keyring */
22 22
23/* request-key default keyrings */
24#define KEY_REQKEY_DEFL_NO_CHANGE -1
25#define KEY_REQKEY_DEFL_DEFAULT 0
26#define KEY_REQKEY_DEFL_THREAD_KEYRING 1
27#define KEY_REQKEY_DEFL_PROCESS_KEYRING 2
28#define KEY_REQKEY_DEFL_SESSION_KEYRING 3
29#define KEY_REQKEY_DEFL_USER_KEYRING 4
30#define KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5
31#define KEY_REQKEY_DEFL_GROUP_KEYRING 6
32
23/* keyctl commands */ 33/* keyctl commands */
24#define KEYCTL_GET_KEYRING_ID 0 /* ask for a keyring's ID */ 34#define KEYCTL_GET_KEYRING_ID 0 /* ask for a keyring's ID */
25#define KEYCTL_JOIN_SESSION_KEYRING 1 /* join or start named session keyring */ 35#define KEYCTL_JOIN_SESSION_KEYRING 1 /* join or start named session keyring */
@@ -35,5 +45,6 @@
35#define KEYCTL_READ 11 /* read a key or keyring's contents */ 45#define KEYCTL_READ 11 /* read a key or keyring's contents */
36#define KEYCTL_INSTANTIATE 12 /* instantiate a partially constructed key */ 46#define KEYCTL_INSTANTIATE 12 /* instantiate a partially constructed key */
37#define KEYCTL_NEGATE 13 /* negate a partially constructed key */ 47#define KEYCTL_NEGATE 13 /* negate a partially constructed key */
48#define KEYCTL_SET_REQKEY_KEYRING 14 /* set default request-key keyring */
38 49
39#endif /* _LINUX_KEYCTL_H */ 50#endif /* _LINUX_KEYCTL_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 901742f92389..2c69682b0444 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -561,9 +561,10 @@ struct group_info {
561 groups_free(group_info); \ 561 groups_free(group_info); \
562} while (0) 562} while (0)
563 563
564struct group_info *groups_alloc(int gidsetsize); 564extern struct group_info *groups_alloc(int gidsetsize);
565void groups_free(struct group_info *group_info); 565extern void groups_free(struct group_info *group_info);
566int set_current_groups(struct group_info *group_info); 566extern int set_current_groups(struct group_info *group_info);
567extern int groups_search(struct group_info *group_info, gid_t grp);
567/* access the groups "array" with this macro */ 568/* access the groups "array" with this macro */
568#define GROUP_AT(gi, i) \ 569#define GROUP_AT(gi, i) \
569 ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK]) 570 ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK])
@@ -660,6 +661,7 @@ struct task_struct {
660 struct user_struct *user; 661 struct user_struct *user;
661#ifdef CONFIG_KEYS 662#ifdef CONFIG_KEYS
662 struct key *thread_keyring; /* keyring private to this thread */ 663 struct key *thread_keyring; /* keyring private to this thread */
664 unsigned char jit_keyring; /* default keyring to attach requested keys to */
663#endif 665#endif
664 int oomkilladj; /* OOM kill score adjustment (bit shift). */ 666 int oomkilladj; /* OOM kill score adjustment (bit shift). */
665 char comm[TASK_COMM_LEN]; /* executable name excluding path 667 char comm[TASK_COMM_LEN]; /* executable name excluding path