Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[cascardo/linux.git] / net / netlink / attr.c
index 0041395..e4d7bed 100644 (file)
@@ -24,9 +24,9 @@ static u16 nla_attr_minlen[NLA_TYPE_MAX+1] __read_mostly = {
 };
 
 static int validate_nla(struct nlattr *nla, int maxtype,
-                       struct nla_policy *policy)
+                       const struct nla_policy *policy)
 {
-       struct nla_policy *pt;
+       const struct nla_policy *pt;
        int minlen = 0, attrlen = nla_len(nla);
 
        if (nla->nla_type <= 0 || nla->nla_type > maxtype)
@@ -67,6 +67,22 @@ static int validate_nla(struct nlattr *nla, int maxtype,
                }
                break;
 
+       case NLA_BINARY:
+               if (pt->len && attrlen > pt->len)
+                       return -ERANGE;
+               break;
+
+       case NLA_NESTED_COMPAT:
+               if (attrlen < pt->len)
+                       return -ERANGE;
+               if (attrlen < NLA_ALIGN(pt->len))
+                       break;
+               if (attrlen < NLA_ALIGN(pt->len) + NLA_HDRLEN)
+                       return -ERANGE;
+               nla = nla_data(nla) + NLA_ALIGN(pt->len);
+               if (attrlen < NLA_ALIGN(pt->len) + NLA_HDRLEN + nla_len(nla))
+                       return -ERANGE;
+               break;
        default:
                if (pt->len)
                        minlen = pt->len;
@@ -94,7 +110,7 @@ static int validate_nla(struct nlattr *nla, int maxtype,
  * Returns 0 on success or a negative error code.
  */
 int nla_validate(struct nlattr *head, int len, int maxtype,
-                struct nla_policy *policy)
+                const struct nla_policy *policy)
 {
        struct nlattr *nla;
        int rem, err;
@@ -125,7 +141,7 @@ errout:
  * Returns 0 on success or a negative error code.
  */
 int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
-             struct nla_policy *policy)
+             const struct nla_policy *policy)
 {
        struct nlattr *nla;
        int rem, err;