rtnetlink: ifinfo: perform strict checks also for doit handler
authorJakub Kicinski <jakub.kicinski@netronome.com>
Fri, 18 Jan 2019 18:46:16 +0000 (10:46 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 19 Jan 2019 18:09:58 +0000 (10:09 -0800)
Make RTM_GETLINK's doit handler use strict checks when
NETLINK_F_STRICT_CHK is set.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/rtnetlink.c

index 2b4e61bcd420ebdd1eefefb12042ef05249291da..f5a98082ac7a1c6ca47447f490a2b3618fb569e8 100644 (file)
@@ -3242,6 +3242,53 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
        return ret;
 }
 
+static int rtnl_valid_getlink_req(struct sk_buff *skb,
+                                 const struct nlmsghdr *nlh,
+                                 struct nlattr **tb,
+                                 struct netlink_ext_ack *extack)
+{
+       struct ifinfomsg *ifm;
+       int i, err;
+
+       if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) {
+               NL_SET_ERR_MSG(extack, "Invalid header for get link");
+               return -EINVAL;
+       }
+
+       if (!netlink_strict_get_check(skb))
+               return nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy,
+                                  extack);
+
+       ifm = nlmsg_data(nlh);
+       if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags ||
+           ifm->ifi_change) {
+               NL_SET_ERR_MSG(extack, "Invalid values in header for get link request");
+               return -EINVAL;
+       }
+
+       err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy,
+                                extack);
+       if (err)
+               return err;
+
+       for (i = 0; i <= IFLA_MAX; i++) {
+               if (!tb[i])
+                       continue;
+
+               switch (i) {
+               case IFLA_IFNAME:
+               case IFLA_EXT_MASK:
+               case IFLA_TARGET_NETNSID:
+                       break;
+               default:
+                       NL_SET_ERR_MSG(extack, "Unsupported attribute in get link request");
+                       return -EINVAL;
+               }
+       }
+
+       return 0;
+}
+
 static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
                        struct netlink_ext_ack *extack)
 {
@@ -3256,7 +3303,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
        int err;
        u32 ext_filter_mask = 0;
 
-       err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, extack);
+       err = rtnl_valid_getlink_req(skb, nlh, tb, extack);
        if (err < 0)
                return err;