btrfs: fix race between quota disable and quota assign ioctls
[platform/kernel/linux-rpi.git] / net / ipv6 / seg6.c
index e412817..0c7c6fc 100644 (file)
@@ -75,6 +75,65 @@ bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced)
        return true;
 }
 
+struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags)
+{
+       struct ipv6_sr_hdr *srh;
+       int len, srhoff = 0;
+
+       if (ipv6_find_hdr(skb, &srhoff, IPPROTO_ROUTING, NULL, &flags) < 0)
+               return NULL;
+
+       if (!pskb_may_pull(skb, srhoff + sizeof(*srh)))
+               return NULL;
+
+       srh = (struct ipv6_sr_hdr *)(skb->data + srhoff);
+
+       len = (srh->hdrlen + 1) << 3;
+
+       if (!pskb_may_pull(skb, srhoff + len))
+               return NULL;
+
+       /* note that pskb_may_pull may change pointers in header;
+        * for this reason it is necessary to reload them when needed.
+        */
+       srh = (struct ipv6_sr_hdr *)(skb->data + srhoff);
+
+       if (!seg6_validate_srh(srh, len, true))
+               return NULL;
+
+       return srh;
+}
+
+/* Determine if an ICMP invoking packet contains a segment routing
+ * header.  If it does, extract the offset to the true destination
+ * address, which is in the first segment address.
+ */
+void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt)
+{
+       __u16 network_header = skb->network_header;
+       struct ipv6_sr_hdr *srh;
+
+       /* Update network header to point to the invoking packet
+        * inside the ICMP packet, so we can use the seg6_get_srh()
+        * helper.
+        */
+       skb_reset_network_header(skb);
+
+       srh = seg6_get_srh(skb, 0);
+       if (!srh)
+               goto out;
+
+       if (srh->type != IPV6_SRCRT_TYPE_4)
+               goto out;
+
+       opt->flags |= IP6SKB_SEG6;
+       opt->srhoff = (unsigned char *)srh - skb->data;
+
+out:
+       /* Restore the network header back to the ICMP packet */
+       skb->network_header = network_header;
+}
+
 static struct genl_family seg6_genl_family;
 
 static const struct nla_policy seg6_genl_policy[SEG6_ATTR_MAX + 1] = {
@@ -132,6 +191,11 @@ static int seg6_genl_sethmac(struct sk_buff *skb, struct genl_info *info)
                goto out_unlock;
        }
 
+       if (slen > nla_len(info->attrs[SEG6_ATTR_SECRET])) {
+               err = -EINVAL;
+               goto out_unlock;
+       }
+
        if (hinfo) {
                err = seg6_hmac_info_del(net, hmackeyid);
                if (err)