LSM/SELinux: Interfaces to allow FS to control mount options
[sfrench/cifs-2.6.git] / security / keys / keyring.c
index 1357207fc9df8d55c783704d4e8f0a79c0465b32..88292e3dee966103fff3f4a9e1cba7b5d22fc5c9 100644 (file)
@@ -49,6 +49,7 @@ static inline unsigned keyring_hash(const char *desc)
 static int keyring_instantiate(struct key *keyring,
                               const void *data, size_t datalen);
 static int keyring_match(const struct key *keyring, const void *criterion);
+static void keyring_revoke(struct key *keyring);
 static void keyring_destroy(struct key *keyring);
 static void keyring_describe(const struct key *keyring, struct seq_file *m);
 static long keyring_read(const struct key *keyring,
@@ -59,11 +60,14 @@ struct key_type key_type_keyring = {
        .def_datalen    = sizeof(struct keyring_list),
        .instantiate    = keyring_instantiate,
        .match          = keyring_match,
+       .revoke         = keyring_revoke,
        .destroy        = keyring_destroy,
        .describe       = keyring_describe,
        .read           = keyring_read,
 };
 
+EXPORT_SYMBOL(key_type_keyring);
+
 /*
  * semaphore to serialise link/link calls to prevent two link calls in parallel
  * introducing a cycle
@@ -240,7 +244,7 @@ static long keyring_read(const struct key *keyring,
  * allocate a keyring and link into the destination keyring
  */
 struct key *keyring_alloc(const char *description, uid_t uid, gid_t gid,
-                         struct task_struct *ctx, int not_in_quota,
+                         struct task_struct *ctx, unsigned long flags,
                          struct key *dest)
 {
        struct key *keyring;
@@ -249,7 +253,7 @@ struct key *keyring_alloc(const char *description, uid_t uid, gid_t gid,
        keyring = key_alloc(&key_type_keyring, description,
                            uid, gid, ctx,
                            (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL,
-                           not_in_quota);
+                           flags);
 
        if (!IS_ERR(keyring)) {
                ret = key_instantiate_and_link(keyring, NULL, 0, dest, NULL);
@@ -704,12 +708,10 @@ int __key_link(struct key *keyring, struct key *key)
                                BUG_ON(size > PAGE_SIZE);
 
                                ret = -ENOMEM;
-                               nklist = kmalloc(size, GFP_KERNEL);
+                               nklist = kmemdup(klist, size, GFP_KERNEL);
                                if (!nklist)
                                        goto error2;
 
-                               memcpy(nklist, klist, size);
-
                                /* replace matched key */
                                atomic_inc(&key->usage);
                                nklist->keys[loop] = key;
@@ -953,3 +955,22 @@ int keyring_clear(struct key *keyring)
 } /* end keyring_clear() */
 
 EXPORT_SYMBOL(keyring_clear);
+
+/*****************************************************************************/
+/*
+ * dispose of the links from a revoked keyring
+ * - called with the key sem write-locked
+ */
+static void keyring_revoke(struct key *keyring)
+{
+       struct keyring_list *klist = keyring->payload.subscriptions;
+
+       /* adjust the quota */
+       key_payload_reserve(keyring, 0);
+
+       if (klist) {
+               rcu_assign_pointer(keyring->payload.subscriptions, NULL);
+               call_rcu(&klist->rcu, keyring_clear_rcu_disposal);
+       }
+
+} /* end keyring_revoke() */