Merge tag 'ecryptfs-3.9-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[firefly-linux-kernel-4.4.55.git] / crypto / crypto_user.c
index f6d9baf77f0a41b76b0fc39aebf26365a1284bca..dfd511fb39eecd48e0305a47fee8c4635aa50ab8 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "internal.h"
 
+#define null_terminated(x)     (strnlen(x, sizeof(x)) < sizeof(x))
+
 static DEFINE_MUTEX(crypto_cfg_mutex);
 
 /* The crypto netlink socket */
@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
        struct crypto_dump_info info;
        int err;
 
-       if (!p->cru_driver_name)
+       if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
+               return -EINVAL;
+
+       if (!p->cru_driver_name[0])
                return -EINVAL;
 
        alg = crypto_alg_match(p, 1);
@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
        struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
        LIST_HEAD(list);
 
+       if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
+               return -EINVAL;
+
        if (priority && !strlen(p->cru_driver_name))
                return -EINVAL;
 
@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
        struct crypto_alg *alg;
        struct crypto_user_alg *p = nlmsg_data(nlh);
 
+       if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
+               return -EINVAL;
+
        alg = crypto_alg_match(p, 1);
        if (!alg)
                return -ENOENT;
@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
        struct crypto_user_alg *p = nlmsg_data(nlh);
        struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
 
+       if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
+               return -EINVAL;
+
        if (strlen(p->cru_driver_name))
                exact = 1;