OSDN Git Service

rtnetlink: Update ipmr_rtm_dumplink for strict data checking
authorDavid Ahern <dsahern@gmail.com>
Mon, 8 Oct 2018 03:16:34 +0000 (20:16 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 Oct 2018 17:39:04 +0000 (10:39 -0700)
Update ipmr_rtm_dumplink for strict data checking. If the flag is set,
the dump request is expected to have an ifinfomsg struct as the header.
All elements of the struct are expected to be 0 and no attributes can
be appended.

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Christian Brauner <christian@brauner.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ipmr.c

index 5660adc..e7322e4 100644 (file)
@@ -2710,6 +2710,31 @@ static bool ipmr_fill_vif(struct mr_table *mrt, u32 vifid, struct sk_buff *skb)
        return true;
 }
 
+static int ipmr_valid_dumplink(const struct nlmsghdr *nlh,
+                              struct netlink_ext_ack *extack)
+{
+       struct ifinfomsg *ifm;
+
+       if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) {
+               NL_SET_ERR_MSG(extack, "ipv4: Invalid header for ipmr link dump");
+               return -EINVAL;
+       }
+
+       if (nlmsg_attrlen(nlh, sizeof(*ifm))) {
+               NL_SET_ERR_MSG(extack, "Invalid data after header in ipmr link dump");
+               return -EINVAL;
+       }
+
+       ifm = nlmsg_data(nlh);
+       if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags ||
+           ifm->ifi_change || ifm->ifi_index) {
+               NL_SET_ERR_MSG(extack, "Invalid values in header for ipmr link dump request");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static int ipmr_rtm_dumplink(struct sk_buff *skb, struct netlink_callback *cb)
 {
        struct net *net = sock_net(skb->sk);
@@ -2718,6 +2743,13 @@ static int ipmr_rtm_dumplink(struct sk_buff *skb, struct netlink_callback *cb)
        unsigned int e = 0, s_e;
        struct mr_table *mrt;
 
+       if (cb->strict_check) {
+               int err = ipmr_valid_dumplink(cb->nlh, cb->extack);
+
+               if (err < 0)
+                       return err;
+       }
+
        s_t = cb->args[0];
        s_e = cb->args[1];