Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d720024e authored by Michael LeMay's avatar Michael LeMay Committed by Linus Torvalds
Browse files

[PATCH] selinux: add hooks for key subsystem



Introduce SELinux hooks to support the access key retention subsystem
within the kernel.  Incorporate new flask headers from a modified version
of the SELinux reference policy, with support for the new security class
representing retained keys.  Extend the "key_alloc" security hook with a
task parameter representing the intended ownership context for the key
being allocated.  Attach security information to root's default keyrings
within the SELinux initialization routine.

Has passed David's testsuite.

Signed-off-by: default avatarMichael LeMay <mdlemay@epoch.ncsc.mil>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
Acked-by: default avatarChris Wright <chrisw@sous-sol.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f893afbe
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ This document has the following sections:
	- Key overview
	- Key service overview
	- Key access permissions
	- SELinux support
	- New procfs files
	- Userspace system call interface
	- Kernel services
@@ -232,6 +233,34 @@ For changing the ownership, group ID or permissions mask, being the owner of
the key or having the sysadmin capability is sufficient.


===============
SELINUX SUPPORT
===============

The security class "key" has been added to SELinux so that mandatory access
controls can be applied to keys created within various contexts.  This support
is preliminary, and is likely to change quite significantly in the near future.
Currently, all of the basic permissions explained above are provided in SELinux
as well; SE Linux is simply invoked after all basic permission checks have been
performed.

Each key is labeled with the same context as the task to which it belongs.
Typically, this is the same task that was running when the key was created.
The default keyrings are handled differently, but in a way that is very
intuitive:

 (*) The user and user session keyrings that are created when the user logs in
     are currently labeled with the context of the login manager.

 (*) The keyrings associated with new threads are each labeled with the context
     of their associated thread, and both session and process keyrings are
     handled similarly.

Note, however, that the default keyrings associated with the root user are
labeled with the default kernel context, since they are created early in the
boot process, before root has a chance to log in.


================
NEW PROCFS FILES
================
+13 −5
Original line number Diff line number Diff line
@@ -241,8 +241,9 @@ extern void unregister_key_type(struct key_type *ktype);

extern struct key *key_alloc(struct key_type *type,
			     const char *desc,
			     uid_t uid, gid_t gid, key_perm_t perm,
			     int not_in_quota);
			     uid_t uid, gid_t gid,
			     struct task_struct *ctx,
			     key_perm_t perm, int not_in_quota);
extern int key_payload_reserve(struct key *key, size_t datalen);
extern int key_instantiate_and_link(struct key *key,
				    const void *data,
@@ -292,7 +293,9 @@ extern int key_unlink(struct key *keyring,
		      struct key *key);

extern struct key *keyring_alloc(const char *description, uid_t uid, gid_t gid,
				 int not_in_quota, struct key *dest);
				 struct task_struct *ctx,
				 int not_in_quota,
				 struct key *dest);

extern int keyring_clear(struct key *keyring);

@@ -313,7 +316,8 @@ extern void keyring_replace_payload(struct key *key, void *replacement);
 * the userspace interface
 */
extern struct key root_user_keyring, root_session_keyring;
extern int alloc_uid_keyring(struct user_struct *user);
extern int alloc_uid_keyring(struct user_struct *user,
			     struct task_struct *ctx);
extern void switch_uid_keyring(struct user_struct *new_user);
extern int copy_keys(unsigned long clone_flags, struct task_struct *tsk);
extern int copy_thread_group_keys(struct task_struct *tsk);
@@ -342,7 +346,7 @@ extern void key_init(void);
#define make_key_ref(k)			({ NULL; })
#define key_ref_to_ptr(k)		({ NULL; })
#define is_key_possessed(k)		0
#define alloc_uid_keyring(u)		0
#define alloc_uid_keyring(u,c)		0
#define switch_uid_keyring(u)		do { } while(0)
#define __install_session_keyring(t, k)	({ NULL; })
#define copy_keys(f,t)			0
@@ -355,6 +359,10 @@ extern void key_init(void);
#define key_fsgid_changed(t)		do { } while(0)
#define key_init()			do { } while(0)

/* Initial keyrings */
extern struct key root_user_keyring;
extern struct key root_session_keyring;

#endif /* CONFIG_KEYS */
#endif /* __KERNEL__ */
#endif /* _LINUX_KEY_H */
+6 −4
Original line number Diff line number Diff line
@@ -1313,7 +1313,7 @@ struct security_operations {

	/* key management security hooks */
#ifdef CONFIG_KEYS
	int (*key_alloc)(struct key *key);
	int (*key_alloc)(struct key *key, struct task_struct *tsk);
	void (*key_free)(struct key *key);
	int (*key_permission)(key_ref_t key_ref,
			      struct task_struct *context,
@@ -3008,9 +3008,10 @@ static inline int security_xfrm_policy_lookup(struct xfrm_policy *xp, u32 sk_sid

#ifdef CONFIG_KEYS
#ifdef CONFIG_SECURITY
static inline int security_key_alloc(struct key *key)
static inline int security_key_alloc(struct key *key,
				     struct task_struct *tsk)
{
	return security_ops->key_alloc(key);
	return security_ops->key_alloc(key, tsk);
}

static inline void security_key_free(struct key *key)
@@ -3027,7 +3028,8 @@ static inline int security_key_permission(key_ref_t key_ref,

#else

static inline int security_key_alloc(struct key *key)
static inline int security_key_alloc(struct key *key,
				     struct task_struct *tsk)
{
	return 0;
}
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ struct user_struct * alloc_uid(uid_t uid)
		new->mq_bytes = 0;
		new->locked_shm = 0;

		if (alloc_uid_keyring(new) < 0) {
		if (alloc_uid_keyring(new, current) < 0) {
			kmem_cache_free(uid_cachep, new);
			return NULL;
		}
+1 −1
Original line number Diff line number Diff line
@@ -860,7 +860,7 @@ static int dummy_setprocattr(struct task_struct *p, char *name, void *value, siz
}

#ifdef CONFIG_KEYS
static inline int dummy_key_alloc(struct key *key)
static inline int dummy_key_alloc(struct key *key, struct task_struct *ctx)
{
	return 0;
}
Loading