OSDN Git Service

mfd: rn5t618: Mark ADC control register volatile
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / crypto / crypto_user.c
index 237f379..b6ea453 100644 (file)
@@ -54,6 +54,9 @@ static struct crypto_alg *crypto_alg_match(struct crypto_user_alg *p, int exact)
        list_for_each_entry(q, &crypto_alg_list, cra_list) {
                int match = 0;
 
+               if (crypto_is_larval(q))
+                       continue;
+
                if ((q->cra_flags ^ p->cru_type) & p->cru_mask)
                        continue;
 
@@ -246,38 +249,43 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
 drop_alg:
        crypto_mod_put(alg);
 
-       if (err)
+       if (err) {
+               kfree_skb(skb);
                return err;
+       }
 
        return nlmsg_unicast(crypto_nlsk, skb, NETLINK_CB(in_skb).portid);
 }
 
 static int crypto_dump_report(struct sk_buff *skb, struct netlink_callback *cb)
 {
-       struct crypto_alg *alg;
+       const size_t start_pos = cb->args[0];
+       size_t pos = 0;
        struct crypto_dump_info info;
-       int err;
-
-       if (cb->args[0])
-               goto out;
-
-       cb->args[0] = 1;
+       struct crypto_alg *alg;
+       int res;
 
        info.in_skb = cb->skb;
        info.out_skb = skb;
        info.nlmsg_seq = cb->nlh->nlmsg_seq;
        info.nlmsg_flags = NLM_F_MULTI;
 
+       down_read(&crypto_alg_sem);
        list_for_each_entry(alg, &crypto_alg_list, cra_list) {
-               err = crypto_report_alg(alg, &info);
-               if (err)
-                       goto out_err;
+               if (pos >= start_pos) {
+                       res = crypto_report_alg(alg, &info);
+                       if (res == -EMSGSIZE)
+                               break;
+                       if (res)
+                               goto out;
+               }
+               pos++;
        }
-
+       cb->args[0] = pos;
+       res = skb->len;
 out:
-       return skb->len;
-out_err:
-       return err;
+       up_read(&crypto_alg_sem);
+       return res;
 }
 
 static int crypto_dump_report_done(struct netlink_callback *cb)
@@ -455,6 +463,7 @@ static const int crypto_msg_min[CRYPTO_NR_MSGTYPES] = {
        [CRYPTO_MSG_NEWALG      - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
        [CRYPTO_MSG_DELALG      - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
        [CRYPTO_MSG_UPDATEALG   - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
+       [CRYPTO_MSG_GETALG      - CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
        [CRYPTO_MSG_DELRNG      - CRYPTO_MSG_BASE] = 0,
 };
 
@@ -494,22 +503,26 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
        if ((type == (CRYPTO_MSG_GETALG - CRYPTO_MSG_BASE) &&
            (nlh->nlmsg_flags & NLM_F_DUMP))) {
                struct crypto_alg *alg;
-               u16 dump_alloc = 0;
+               unsigned long dump_alloc = 0;
 
                if (link->dump == NULL)
                        return -EINVAL;
 
+               down_read(&crypto_alg_sem);
                list_for_each_entry(alg, &crypto_alg_list, cra_list)
                        dump_alloc += CRYPTO_REPORT_MAXSIZE;
+               up_read(&crypto_alg_sem);
 
                {
                        struct netlink_dump_control c = {
                                .dump = link->dump,
                                .done = link->done,
-                               .min_dump_alloc = dump_alloc,
+                               .min_dump_alloc = min(dump_alloc, 65535UL),
                        };
-                       return netlink_dump_start(crypto_nlsk, skb, nlh, &c);
+                       err = netlink_dump_start(crypto_nlsk, skb, nlh, &c);
                }
+
+               return err;
        }
 
        err = nlmsg_parse(nlh, crypto_msg_min[type], attrs, CRYPTOCFGA_MAX,