#include "afs/param.h"
#ifdef LINUX_KEYRING_SUPPORT
#include <linux/seq_file.h>
-#if KEY_TYPE_H_EXISTS
-#include <linux/key-type.h>
-#endif
#endif
RCSID
crset(*cr);
+#if defined(STRUCT_TASK_STRUCT_HAS_PARENT) && !defined(STRUCT_TASK_HAS_CRED)
if (change_parent) {
old_info = current->parent->group_info;
get_group_info(group_info);
current->parent->group_info = group_info;
put_group_info(old_info);
}
+#endif
return (0);
}
int change_parent)
{
struct group_info *group_info;
+#ifndef AFS_LINUX26_ONEGROUP_ENV
gid_t g0, g1;
+#endif
struct group_info *tmp;
int i;
#ifdef AFS_LINUX26_ONEGROUP_ENV
}
#ifdef LINUX_KEYRING_SUPPORT
-static struct key_type *__key_type_keyring;
+extern struct key_type key_type_keyring __attribute__((weak));
+static struct key_type *__key_type_keyring = &key_type_keyring;
static int
install_session_keyring(struct task_struct *task, struct key *keyring)
#ifdef KEY_ALLOC_NEEDS_STRUCT_TASK
keyring = key_alloc(__key_type_keyring, desc,
- task->uid, task->gid, task,
+ task_uid(task), task_gid(task), task,
(KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL,
not_in_quota);
#else
keyring = key_alloc(__key_type_keyring, desc,
- task->uid, task->gid,
+ task_uid(task), task_gid(task),
(KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL,
not_in_quota);
#endif
/* install the keyring */
spin_lock_irq(&task->sighand->siglock);
- old = task->signal->session_keyring;
+ old = task_session_keyring(task);
smp_wmb();
- task->signal->session_keyring = keyring;
+ task_session_keyring(task) = keyring;
spin_unlock_irq(&task->sighand->siglock);
if (old)
if (code == 0 && (*cr)->cr_rgid != NFSXLATOR_CRED) {
(void) install_session_keyring(current, NULL);
- if (current->signal->session_keyring) {
+ if (current_session_keyring()) {
struct key *key;
key_perm_t perm;
if (!IS_ERR(key)) {
key_instantiate_and_link(key, (void *) newpag, sizeof(afs_uint32),
- current->signal->session_keyring, NULL);
+ current_session_keyring(), NULL);
key_put(key);
}
}
{
int code;
afs_uint32 *userpag, pag = NOPAG;
+#ifndef AFS_LINUX26_ONEGROUP_ENV
int g0, g1;
+#endif
if (key->uid != 0 || key->gid != 0)
return -EPERM;
code = -EINVAL;
- get_group_info(current->group_info);
+ get_group_info(current_group_info());
if (datalen != sizeof(afs_uint32) || !data)
goto error;
- if (current->group_info->ngroups < NUMPAGGROUPS)
+ if (current_group_info()->ngroups < NUMPAGGROUPS)
goto error;
/* ensure key being set matches current pag */
#ifdef AFS_LINUX26_ONEGROUP_ENV
- pag = afs_get_pag_from_groups(current->group_info);
+ pag = afs_get_pag_from_groups(current_group_info());
#else
- g0 = GROUP_AT(current->group_info, 0);
- g1 = GROUP_AT(current->group_info, 1);
+ g0 = GROUP_AT(current_group_info(), 0);
+ g1 = GROUP_AT(current_group_info(), 1);
pag = afs_get_pag_from_groups(g0, g1);
#endif
code = 0;
error:
- put_group_info(current->group_info);
+ put_group_info(current_group_info());
return code;
}
void osi_keyring_init(void)
{
struct task_struct *p;
-#ifdef EXPORTED_TASKLIST_LOCK
- if (&tasklist_lock)
- read_lock(&tasklist_lock);
-#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-#ifdef EXPORTED_TASKLIST_LOCK
- else
-#endif
- rcu_read_lock();
-#endif
- p = find_task_by_pid(1);
- if (p && p->user->session_keyring)
- __key_type_keyring = p->user->session_keyring->type;
-#ifdef EXPORTED_TASKLIST_LOCK
- if (&tasklist_lock)
- read_unlock(&tasklist_lock);
-#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-#ifdef EXPORTED_TASKLIST_LOCK
- else
+
+ /* If we can't lock the tasklist, either with its explicit lock,
+ * or by using the RCU lock, then we can't safely work out the
+ * type of a keyring. So, we have to rely on the weak reference.
+ * If that's not available, then keyring based PAGs won't work.
+ */
+
+#if defined(EXPORTED_TASKLIST_LOCK) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) && defined(EXPORTED_RCU_READ_LOCK))
+ if (__key_type_keyring == NULL) {
+# ifdef EXPORTED_TASKLIST_LOCK
+ if (&tasklist_lock)
+ read_lock(&tasklist_lock);
+# endif
+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) && defined(EXPORTED_RCU_READ_LOCK))
+# ifdef EXPORTED_TASKLIST_LOCK
+ else
+# endif
+ rcu_read_lock();
+# endif
+#if defined(EXPORTED_FIND_TASK_BY_PID)
+ p = find_task_by_pid(1);
+#else
+ p = find_task_by_vpid(1);
#endif
- rcu_read_unlock();
+ if (p && task_user(p)->session_keyring)
+ __key_type_keyring = task_user(p)->session_keyring->type;
+# ifdef EXPORTED_TASKLIST_LOCK
+ if (&tasklist_lock)
+ read_unlock(&tasklist_lock);
+# endif
+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) && defined(EXPORTED_RCU_READ_LOCK))
+# ifdef EXPORTED_TASKLIST_LOCK
+ else
+# endif
+ rcu_read_unlock();
+# endif
+ }
#endif
register_key_type(&key_type_afs_pag);