ipv6: Extension header infrastructure
Subsystems (7)
v6 cover ipv6: Extension header infrastructure
This patchset improves the IPv6 extension header infrastructure to make extension headers more usable and scalable.
- Reorganize extension header files to separate out common API components
- Create common TLV handler that will can be used in other use cases (e.g. segment routing TLVs, UDP options)
- Allow registration of TLV handlers
- Elaborate on the TLV tables to include more characteristics
- Add a netlink interface to set TLV parameters (such as alignment requirements, authorization to send, etc.)
- Enhance validation of TLVs being sent. Validation is strict (unless overridden by admin) following the sending clause of the robustness principle
- Allow non-privileged users to set Hop-by-Hop and Destination Options if authorized by the admin
v2:
- Fix build errors from missing include file.
v3:
- Fix kbuild issue for ipv6_opt_hdr declared inside parameter list in ipeh.h
v4:
- Resubmit
v5:
- Fix reverse christmas tree issue
v6:
- Address comments from Simon Horman
- Remove new EXTHDRS Kconfig symbol, just use IPV6 for now
- Split out introduction of parse_error for TLV parsing loop into its own patch
- Fix drop counters in HBH and destination options processing
- Add extack error messages in netlink code
- Added range of permissions in include/uapi/linux/ipeh.h
- Check that min data length is <= max data length when setting TLV attributes
Tom Herbert (9):
ipeh: Fix destopts and hopopts counters on drop
ipeh: Create exthdrs_options.c and ipeh.h
ipeh: Move generic EH functions to exthdrs_common.c
ipeh: Generic TLV parser
ipeh: Add callback to ipeh_parse_tlv to handle errors
ip6tlvs: Registration of TLV handlers and parameters
ip6tlvs: Add TX parameters
ip6tlvs: Add netlink interface
ip6tlvs: Validation of TX Destination and Hop-by-Hop options
include/net/ipeh.h | 209 ++++++++ include/net/ipv6.h | 12 +- include/uapi/linux/in6.h | 6 + include/uapi/linux/ipeh.h | 53 ++ net/dccp/ipv6.c | 2 +- net/ipv6/Makefile | 3 +- net/ipv6/calipso.c | 6 +- net/ipv6/datagram.c | 51 +- net/ipv6/exthdrs.c | 504 ++---------------- net/ipv6/exthdrs_common.c | 1212 ++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/exthdrs_options.c | 342 +++++++++++++ net/ipv6/ipv6_sockglue.c | 39 +- net/ipv6/raw.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- net/ipv6/udp.c | 2 +- net/l2tp/l2tp_ip6.c | 2 +- net/sctp/ipv6.c | 2 +- 17 files changed, 1938 insertions(+), 511 deletions(-) create mode 100644 include/net/ipeh.h create mode 100644 include/uapi/linux/ipeh.h create mode 100644 net/ipv6/exthdrs_common.c create mode 100644 net/ipv6/exthdrs_options.c
Signature · 1 line
2.7.4
PATCH v6 1/9 ipeh: Fix destopts and hopopts counters on drop
From: Tom Herbert <[email protected]>
For destopts, bump IPSTATS_MIB_INHDRERRORS when limit of length of extension header is exceeded.
For hop-by-hop options, bump IPSTATS_MIB_INHDRERRORS in same situations as for when destopts are dropped.
--- net/ipv6/exthdrs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/ipv6/exthdrs.c +6 -1
@@ -288,9 +288,9 @@ static int ipv6_destopt_rcv(struct sk_buff *skb)if (!pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || !pskb_may_pull (skb, (skb_transport_offset (skb) + ((skb_transport_header (skb)[1 ] +1 ) <<3 )))) { +fail_and_free:__IP6_INC_STATS (dev_net (dst->dev), idev,IPSTATS_MIB_INHDRERRORS ); -fail_and_free:kfree_skb (skb);return -1 ; }
@@ -820,8 +820,10 @@ static const struct tlvtype_proc tlvprochopopt_lst[] = {int ipv6_parse_hopopts (struct sk_buff *skb) { +struct inet6_dev *idev =__in6_dev_get (skb->dev);struct inet6_skb_parm *opt =IP6CB (skb);struct net *net =dev_net (skb->dev); +struct dst_entry *dst =skb_dst (skb);int extlen;/*
@@ -834,6 +836,8 @@ int ipv6_parse_hopopts(struct sk_buff *skb) !pskb_may_pull(skb, (sizeof(struct ipv6hdr) + ((skb_transport_header(skb)[1] + 1) << 3)))) { fail_and_free: +__IP6_INC_STATS (dev_net (dst->dev), idev, +IPSTATS_MIB_INHDRERRORS );kfree_skb (skb);return -1 ; }
@@ -850,6 +854,7 @@ int ipv6_parse_hopopts(struct sk_buff *skb) opt->nhoff =sizeof (struct ipv6hdr );return 1 ; } +__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );return -1 ; }
Signature · 1 line
2.7.4
Willem de Bruijn
maintainerRe: [PATCH v6 net-next 1/9] ipeh: Fix destopts and hopopts counters on drop
Quoted 41 lines · Tom Herbert
From: Tom Herbert <[email protected]>
For destopts, bump
IPSTATS_MIB_INHDRERRORSwhen limit of length of extension header is exceeded.For hop-by-hop options, bump
IPSTATS_MIB_INHDRERRORSin same situations as for when destopts are dropped.Signed-off-by Tom Herbert <[email protected]>--- net/ipv6/exthdrs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/ipv6/exthdrs.c +3
-1@@ -288,9 +288,9 @@ static int ipv6_destopt_rcv(struct sk_buff *skb)if (!pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || !pskb_may_pull (skb, (skb_transport_offset (skb) + ((skb_transport_header (skb)[1 ] +1 ) <<3 )))) { +fail_and_free:__IP6_INC_STATS (dev_net (dst->dev), idev,IPSTATS_MIB_INHDRERRORS ); -fail_and_free:kfree_skb (skb);return -1 ; }@@ -820,8 +820,10 @@ static const struct tlvtype_proc tlvprochopopt_lst[] = {int ipv6_parse_hopopts (struct sk_buff *skb) { +struct inet6_dev *idev =__in6_dev_get (skb->dev);struct inet6_skb_parm *opt =IP6CB (skb);struct net *net =dev_net (skb->dev); +struct dst_entry *dst =skb_dst (skb);int extlen;/*
net/ipv6/exthdrs.c int ipv6_parse_hopopts(struct sk_buff *skb) · line 840
Quoted 5 lines
net/ipv6/exthdrs.c +2
-0@@ -834,6 +836,8 @@ int ipv6_parse_hopopts(struct sk_buff *skb) !pskb_may_pull(skb, (sizeof(struct ipv6hdr) + ((skb_transport_header(skb)[1] + 1) << 3)))) { fail_and_free: +__IP6_INC_STATS (dev_net (dst->dev), idev, +IPSTATS_MIB_INHDRERRORS );
ip6_rcv_core, the only caller of ipv6_parse_hopopts, checks skb_valid_dst(skb) before deref. Does this need the same?
Re: [PATCH v6 net-next 1/9] ipeh: Fix destopts and hopopts counters on drop
Quoted 41 lines · Willem de Bruijn
Quoted 39 lines · Tom Herbert
From: Tom Herbert <[email protected]>
For destopts, bump
IPSTATS_MIB_INHDRERRORSwhen limit of length of extension header is exceeded.For hop-by-hop options, bump
IPSTATS_MIB_INHDRERRORSin same situations as for when destopts are dropped.Signed-off-by Tom Herbert <[email protected]>--- net/ipv6/exthdrs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/ipv6/exthdrs.c +3
-1@@ -288,9 +288,9 @@ static int ipv6_destopt_rcv(struct sk_buff *skb)if (!pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || !pskb_may_pull (skb, (skb_transport_offset (skb) + ((skb_transport_header (skb)[1 ] +1 ) <<3 )))) { +fail_and_free:__IP6_INC_STATS (dev_net (dst->dev), idev,IPSTATS_MIB_INHDRERRORS ); -fail_and_free:kfree_skb (skb);return -1 ; }@@ -820,8 +820,10 @@ static const struct tlvtype_proc tlvprochopopt_lst[] = {int ipv6_parse_hopopts (struct sk_buff *skb) { +struct inet6_dev *idev =__in6_dev_get (skb->dev);struct inet6_skb_parm *opt =IP6CB (skb);struct net *net =dev_net (skb->dev); +struct dst_entry *dst =skb_dst (skb);int extlen;
Quoted 10 lines
net/ipv6/exthdrs.c int ipv6_parse_hopopts(struct sk_buff *skb) · line 840
Quoted 7 lines
net/ipv6/exthdrs.c +2
-0/* @@ -834,6 +836,8 @@ int ipv6_parse_hopopts(struct sk_buff *skb) !pskb_may_pull(skb, (sizeof(struct ipv6hdr) + ((skb_transport_header(skb)[1] + 1) << 3)))) { fail_and_free: +__IP6_INC_STATS (dev_net (dst->dev), idev, +IPSTATS_MIB_INHDRERRORS );
ip6_rcv_core, the only caller ofipv6_parse_hopopts, checksskb_valid_dst(skb)before deref. Does this need the same?
Hi Willem,
Actually, it looks like ipv6_parse_hopopts is doing things the right way. __IP6_INC_STATS is called from ip6_rcv_core if ipv6_parse_hopopts and the net is always taken from skb->dev (not dst) in HBH path. I'll fix destopts to do the same.
Tom
Willem de Bruijn
maintainerRe: [PATCH v6 net-next 1/9] ipeh: Fix destopts and hopopts counters on drop
Quoted 55 lines · Tom Herbert
Quoted 41 lines · Willem de Bruijn
Quoted 39 lines · Tom Herbert
From: Tom Herbert <[email protected]>
For destopts, bump
IPSTATS_MIB_INHDRERRORSwhen limit of length of extension header is exceeded.For hop-by-hop options, bump
IPSTATS_MIB_INHDRERRORSin same situations as for when destopts are dropped.Signed-off-by Tom Herbert <[email protected]>--- net/ipv6/exthdrs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/ipv6/exthdrs.c +3
-1@@ -288,9 +288,9 @@ static int ipv6_destopt_rcv(struct sk_buff *skb)if (!pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || !pskb_may_pull (skb, (skb_transport_offset (skb) + ((skb_transport_header (skb)[1 ] +1 ) <<3 )))) { +fail_and_free:__IP6_INC_STATS (dev_net (dst->dev), idev,IPSTATS_MIB_INHDRERRORS ); -fail_and_free:kfree_skb (skb);return -1 ; }@@ -820,8 +820,10 @@ static const struct tlvtype_proc tlvprochopopt_lst[] = {int ipv6_parse_hopopts (struct sk_buff *skb) { +struct inet6_dev *idev =__in6_dev_get (skb->dev);struct inet6_skb_parm *opt =IP6CB (skb);struct net *net =dev_net (skb->dev); +struct dst_entry *dst =skb_dst (skb);int extlen;Quoted 10 lines
net/ipv6/exthdrs.c int ipv6_parse_hopopts(struct sk_buff *skb) · line 840
Quoted 7 lines
net/ipv6/exthdrs.c +2
-0/* @@ -834,6 +836,8 @@ int ipv6_parse_hopopts(struct sk_buff *skb) !pskb_may_pull(skb, (sizeof(struct ipv6hdr) + ((skb_transport_header(skb)[1] + 1) << 3)))) { fail_and_free: +__IP6_INC_STATS (dev_net (dst->dev), idev, +IPSTATS_MIB_INHDRERRORS );
ip6_rcv_core, the only caller ofipv6_parse_hopopts, checksskb_valid_dst(skb)before deref. Does this need the same?
Quoted 6 lines
Hi Willem,
Actually, it looks like
ipv6_parse_hopoptsis doing things the right way.__IP6_INC_STATSis called fromip6_rcv_coreifipv6_parse_hopoptsand the net is always taken fromskb->dev(not dst) in HBH path. I'll fix destopts to do the same.
I don't entirely follow. The above code uses dev_net(dst->dev). Using local variable net, derived from dev_net(skb->dev), here definitely sounds good to me, if that's what you meant.
Re: [PATCH v6 net-next 1/9] ipeh: Fix destopts and hopopts counters on drop
Quoted 59 lines · Willem de Bruijn
Quoted 57 lines · Tom Herbert
Quoted 41 lines · Willem de Bruijn
Quoted 39 lines · Tom Herbert
From: Tom Herbert <[email protected]>
For destopts, bump
IPSTATS_MIB_INHDRERRORSwhen limit of length of extension header is exceeded.For hop-by-hop options, bump
IPSTATS_MIB_INHDRERRORSin same situations as for when destopts are dropped.Signed-off-by Tom Herbert <[email protected]>--- net/ipv6/exthdrs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/ipv6/exthdrs.c +3
-1@@ -288,9 +288,9 @@ static int ipv6_destopt_rcv(struct sk_buff *skb)if (!pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || !pskb_may_pull (skb, (skb_transport_offset (skb) + ((skb_transport_header (skb)[1 ] +1 ) <<3 )))) { +fail_and_free:__IP6_INC_STATS (dev_net (dst->dev), idev,IPSTATS_MIB_INHDRERRORS ); -fail_and_free:kfree_skb (skb);return -1 ; }@@ -820,8 +820,10 @@ static const struct tlvtype_proc tlvprochopopt_lst[] = {int ipv6_parse_hopopts (struct sk_buff *skb) { +struct inet6_dev *idev =__in6_dev_get (skb->dev);struct inet6_skb_parm *opt =IP6CB (skb);struct net *net =dev_net (skb->dev); +struct dst_entry *dst =skb_dst (skb);int extlen;Quoted 10 lines
net/ipv6/exthdrs.c int ipv6_parse_hopopts(struct sk_buff *skb) · line 840
Quoted 7 lines
net/ipv6/exthdrs.c +2
-0/* @@ -834,6 +836,8 @@ int ipv6_parse_hopopts(struct sk_buff *skb) !pskb_may_pull(skb, (sizeof(struct ipv6hdr) + ((skb_transport_header(skb)[1] + 1) << 3)))) { fail_and_free: +__IP6_INC_STATS (dev_net (dst->dev), idev, +IPSTATS_MIB_INHDRERRORS );
ip6_rcv_core, the only caller ofipv6_parse_hopopts, checksskb_valid_dst(skb)before deref. Does this need the same?Hi Willem,
Quoted 8 lines
Quoted 4 lines
Actually, it looks like
ipv6_parse_hopoptsis doing things the right way.__IP6_INC_STATSis called fromip6_rcv_coreifipv6_parse_hopoptsand the net is always taken fromskb->dev(not dst) in HBH path. I'll fix destopts to do the same.I don't entirely follow. The above code uses
dev_net(dst->dev). Using local variable net, derived fromdev_net(skb->dev), here definitely sounds good to me, if that's what you meant.
Yes, I'm thinking to just do dev_net(skb->dev) in all cases of __IP6_INC_STATS for hopopts and destopts.
Tom
PATCH v6 2/9 ipeh: Create exthdrs_options.c and ipeh.h
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Create exthdrs_options.c to hold code related to specific Hop-by-Hop and Destination extension header options. Move related functions in exthdrs.c to the new file.
Create include net/ipeh.h to contain common definitions for IP extension headers.
--- include/net/ipeh.h | 22 +++++ include/net/ipv6.h | 1 + net/ipv6/Makefile | 2 +- net/ipv6/exthdrs.c | 204 --------------------------------------------- net/ipv6/exthdrs_options.c | 201 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 225 insertions(+), 205 deletions(-) create mode 100644 include/net/ipeh.h create mode 100644 net/ipv6/exthdrs_options.c
include/net/ipeh.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _NET_IPEH_H +#define _NET_IPEH_H + +#include <linux/skbuff.h> + +/* +* Parsing tlv encoded headers. +* +* Parsing function "func" returns true, if parsing succeed +* and false, if it failed. +* It MUST NOT touch skb->h. +*/ +struct tlvtype_proc { +int type; +bool (*func)(struct sk_buff *skb,int offset); +}; + +extern const struct tlvtype_proc tlvprocdestopt_lst[]; +extern const struct tlvtype_proc tlvprochopopt_lst[]; + +#endif /* _NET_IPEH_H */
include/net/ipv6.h +1 -0
@@ -20,6 +20,7 @@#include <net/flow_dissector.h> #include <net/snmp.h> #include <net/netns/hash.h> +#include <net/ipeh.h> #define SIN6_LEN_RFC2133 24
net/ipv6/Makefile +1 -1
@@ -10,7 +10,7 @@ ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \ route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o udplite.o \ raw.o icmp.o mcast.o reassembly.o tcp_ipv6.o ping.o \ exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o \ - udp_offload.o seg6.o fib6_notifier.o + udp_offload.o seg6.o fib6_notifier.o exthdrs_options.o ipv6-offload := ip6_offload.o tcpv6_offload.o exthdrs_offload.o
net/ipv6/exthdrs.c +0 -204
228 lines not on this page · raw message
net/ipv6/exthdrs_options.c new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 3/9 ipeh: Move generic EH functions to exthdrs_common.c
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Move generic functions in exthdrs.c to new exthdrs_common.c so that exthdrs.c only contains functions that are specific to IPv6 processing, and exthdrs_common.c contains functions that are generic. These functions include those that will be used with IPv4 extension headers. Generic extension header related functions are prefixed by ipeh_.
--- include/net/ipeh.h | 12 ++++ include/net/ipv6.h | 9 --- net/dccp/ipv6.c | 2 +- net/ipv6/Makefile | 1 + net/ipv6/calipso.c | 6 +- net/ipv6/exthdrs.c | 138 -------------------------------------------- net/ipv6/exthdrs_common.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/ipv6_sockglue.c | 2 +- net/ipv6/raw.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- net/ipv6/udp.c | 2 +- net/l2tp/l2tp_ip6.c | 2 +- net/sctp/ipv6.c | 2 +- 13 files changed, 167 insertions(+), 157 deletions(-) create mode 100644 net/ipv6/exthdrs_common.c
include/net/ipeh.h +12 -0
@@ -19,4 +19,16 @@ struct tlvtype_proc {extern const struct tlvtype_proc tlvprocdestopt_lst[];extern const struct tlvtype_proc tlvprochopopt_lst[]; +struct ipv6_txoptions ; +struct ipv6_opt_hdr ; + +struct ipv6_txoptions *ipeh_dup_options (struct sock *sk, +struct ipv6_txoptions *opt); +struct ipv6_txoptions *ipeh_renew_options (struct sock *sk, +struct ipv6_txoptions *opt, +int newtype, +struct ipv6_opt_hdr *newopt); +struct ipv6_txoptions *ipeh_fixup_options (struct ipv6_txoptions *opt_space, +struct ipv6_txoptions *opt); +#endif /* _NET_IPEH_H */
include/net/ipv6.h +0 -9
@@ -429,15 +429,6 @@ int ip6_ra_control(struct sock *sk, int sel);int ipv6_parse_hopopts (struct sk_buff *skb); -struct ipv6_txoptions *ipv6_dup_options (struct sock *sk, -struct ipv6_txoptions *opt); -struct ipv6_txoptions *ipv6_renew_options (struct sock *sk, -struct ipv6_txoptions *opt, -int newtype, -struct ipv6_opt_hdr *newopt); -struct ipv6_txoptions *ipv6_fixup_options (struct ipv6_txoptions *opt_space, -struct ipv6_txoptions *opt); -bool ipv6_opt_accepted (const struct sock *sk,const struct sk_buff *skb,const struct inet6_skb_parm *opt); struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
net/dccp/ipv6.c +1 -1
@@ -515,7 +515,7 @@ static struct sock *dccp_v6_request_recv_sock(const struct sock *sk,if (!opt) opt =rcu_dereference (np->opt);if (opt) { - opt =ipv6_dup_options (newsk, opt); + opt =ipeh_dup_options (newsk, opt);RCU_INIT_POINTER (newnp->opt, opt); }inet_csk (newsk)->icsk_ext_hdr_len =0 ;
net/ipv6/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_IPV6_SIT) += sit.o obj-$(CONFIG_IPV6_TUNNEL) += ip6_tunnel.o obj-$(CONFIG_IPV6_GRE) += ip6_gre.o obj-$(CONFIG_IPV6_FOU) += fou6.o +obj-$(CONFIG_IPV6) += exthdrs_common.o obj-y += addrconf_core.o exthdrs_core.o ip6_checksum.o ip6_icmp.o obj-$(CONFIG_INET) += output_core.o protocol.o $(ipv6-offload)
net/ipv6/calipso.c +3 -3
@@ -785,7 +785,7 @@ static int calipso_opt_update(struct sock *sk, struct ipv6_opt_hdr *hop) {struct ipv6_txoptions *old =txopt_get (inet6_sk (sk)), *txopts; - txopts =ipv6_renew_options (sk, old,IPV6_HOPOPTS , hop); + txopts =ipeh_renew_options (sk, old,IPV6_HOPOPTS , hop);txopt_put (old);if (IS_ERR (txopts))return PTR_ERR (txopts);
@@ -1207,7 +1207,7 @@ static int calipso_req_setattr(struct request_sock *req,if (IS_ERR (new))return PTR_ERR (new); - txopts =ipv6_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new); + txopts =ipeh_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new);kfree (new);
@@ -1244,7 +1244,7 @@ static void calipso_req_delattr(struct request_sock *req)if (calipso_opt_del (req_inet->ipv6_opt->hopopt, &new))return ;/* Nothing to do */ - txopts =ipv6_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new); + txopts =ipeh_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new);if (!IS_ERR (txopts)) { txopts =xchg (&req_inet->ipv6_opt, txopts);
net/ipv6/exthdrs.c +0 -138
144 lines not on this page · raw message
net/ipv6/exthdrs_common.c new file +144 -0
144 lines not on this page · raw message
net/ipv6/ipv6_sockglue.c +1 -1
@@ -427,7 +427,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, opt =rcu_dereference_protected (np->opt,lockdep_sock_is_held (sk)); - opt =ipv6_renew_options (sk, opt, optname, new); + opt =ipeh_renew_options (sk, opt, optname, new);kfree (new);if (IS_ERR (opt)) { retv =PTR_ERR (opt);
net/ipv6/raw.c +1 -1
@@ -889,7 +889,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) }if (flowlabel) opt =fl6_merge_options (&opt_space, flowlabel, opt); - opt =ipv6_fixup_options (&opt_space, opt); + opt =ipeh_fixup_options (&opt_space, opt); fl6.flowi6_proto = proto; fl6.flowi6_mark = ipc6.sockc.mark;
net/ipv6/tcp_ipv6.c +1 -1
@@ -1250,7 +1250,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *if (!opt) opt =rcu_dereference (np->opt);if (opt) { - opt =ipv6_dup_options (newsk, opt); + opt =ipeh_dup_options (newsk, opt);RCU_INIT_POINTER (newnp->opt, opt); }inet_csk (newsk)->icsk_ext_hdr_len =0 ;
net/ipv6/udp.c +1 -1
@@ -1391,7 +1391,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) }if (flowlabel) opt =fl6_merge_options (&opt_space, flowlabel, opt); - opt =ipv6_fixup_options (&opt_space, opt); + opt =ipeh_fixup_options (&opt_space, opt); ipc6.opt = opt; fl6.flowi6_proto = sk->sk_protocol;
net/l2tp/l2tp_ip6.c +1 -1
@@ -590,7 +590,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) }if (flowlabel) opt =fl6_merge_options (&opt_space, flowlabel, opt); - opt =ipv6_fixup_options (&opt_space, opt); + opt =ipeh_fixup_options (&opt_space, opt); ipc6.opt = opt; fl6.flowi6_proto = sk->sk_protocol;
net/sctp/ipv6.c +1 -1
@@ -441,7 +441,7 @@ static void sctp_v6_copy_ip_options(struct sock *sk, struct sock *newsk)rcu_read_lock (); opt =rcu_dereference (np->opt);if (opt) { - opt =ipv6_dup_options (newsk, opt); + opt =ipeh_dup_options (newsk, opt);if (!opt)pr_err ("%s: Failed to copy ip options\n" , __func__); }
Signature · 1 line
2.7.4
PATCH v6 4/9 ipeh: Generic TLV parser
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Create a generic TLV parser. This will be used with various extension headers that carry options including Destination, Hop-by-Hop, Segment Routing TLVs, and other cases of simple stateless TLV parsing.
--- include/net/ipeh.h | 11 ++++ net/ipv6/exthdrs.c | 142 ++-------------------------------------------- net/ipv6/exthdrs_common.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 136 deletions(-)
include/net/ipeh.h +11 -0
@@ -31,4 +31,15 @@ struct ipv6_txoptions *ipeh_renew_options(struct sock *sk,struct ipv6_txoptions *ipeh_fixup_options (struct ipv6_txoptions *opt_space,struct ipv6_txoptions *opt); +/* The generic TLV parser assumes that the type value of PAD1 is 0, and PADN +* is 1. This is true for IPv6 Destination and Hop-by-Hop Options. For Segment +* Routing TLVs, PAD1 is also 0, however PADN is 4 so the latter necessitates +* some change to the parser to support Segment Routing TLVs. +*/ +#define IPEH_TLV_PAD1 0 +#define IPEH_TLV_PADN 1 + +bool ipeh_parse_tlv (const struct tlvtype_proc *procs,struct sk_buff *skb, +int max_count,int off,int len); +#endif /* _NET_IPEH_H */
net/ipv6/exthdrs.c +6 -136
160 lines not on this page · raw message
net/ipv6/exthdrs_common.c +137 -0
140 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 5/9 ipeh: Add callback to ipeh_parse_tlv to handle errors
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Add a callback function to ipeh_parse_tlv so that the caller can handler parsing errors in an appropriate way.
The enum ipeh_parse_errors contains the various errors and the particular error is an argument of the callback.
ipv6_parse_error is the callback function for parsing IPv6 TLVs. This mostly subsumes the functionality of ip6_tlvopt_unknown which is removed.
The callback is called at various points in ipeh_parse_tlv when an error is encountered. If the callback returns false then the packet is discarded, else on true being returned the error is not fatal and TLV processing continues (for instance, an unknown TLV is to be ignored).
--- include/net/ipeh.h | 17 +++++++++- net/ipv6/exthdrs.c | 59 ++++++++++++++++++++++++++++++++-- net/ipv6/exthdrs_common.c | 80 ++++++++++++++++++----------------------------- 3 files changed, 103 insertions(+), 53 deletions(-)
include/net/ipeh.h +16 -1
@@ -31,6 +31,19 @@ struct ipv6_txoptions *ipeh_renew_options(struct sock *sk,struct ipv6_txoptions *ipeh_fixup_options (struct ipv6_txoptions *opt_space,struct ipv6_txoptions *opt); +/* Generic extension header TLV parser */ + +enum ipeh_parse_errors { +IPEH_PARSE_ERR_PAD1 ,/* Excessive PAD1 */ +IPEH_PARSE_ERR_PADN ,/* Excessive PADN */ +IPEH_PARSE_ERR_PADNZ ,/* Non-zero padding data */ +IPEH_PARSE_ERR_EH_TOOBIG ,/* Length of EH exceeds limit */ +IPEH_PARSE_ERR_OPT_TOOBIG ,/* Option size exceeds limit */ +IPEH_PARSE_ERR_OPT_TOOMANY ,/* Option count exceeds limit */ +IPEH_PARSE_ERR_OPT_UNK_DISALW ,/* Unknown option disallowed */ +IPEH_PARSE_ERR_OPT_UNK ,/* Unknown option */ +}; +/* The generic TLV parser assumes that the type value of PAD1 is 0, and PADN * is 1. This is true for IPv6 Destination and Hop-by-Hop Options. For Segment * Routing TLVs, PAD1 is also 0, however PADN is 4 so the latter necessitates
@@ -40,6 +53,8 @@ struct ipv6_txoptions *ipeh_fixup_options(struct ipv6_txoptions *opt_space,#define IPEH_TLV_PADN 1bool ipeh_parse_tlv (const struct tlvtype_proc *procs,struct sk_buff *skb, -int max_count,int off,int len); +int max_count,int off,int len, +bool (*parse_error)(struct sk_buff *skb, +int off,enum ipeh_parse_errors error));#endif /* _NET_IPEH_H */
net/ipv6/exthdrs.c +57 -2
77 lines not on this page · raw message
net/ipv6/exthdrs_common.c +30 -50
133 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 6/9 ip6tlvs: Registration of TLV handlers and parameters
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Create a single TLV parameter table that holds meta information for IPv6 Hop-by-Hop and Destination TLVs. The data structure is composed of a 256 element array of u8's (one entry for each TLV type to allow O(1) lookup). Each entry provides an offset into an array of TLV proc data structures which follows the array of u8s. The TLV proc data structure contains parameters and handler functions for receiving and transmitting TLVs. The zero'th element in the TLV proc array provides default parameters for TLVs.
A class attribute indicates the type of extension header in which the TLV may be used (e.g. Hop-by-Hop options, Destination options, or Destination options before the routing header).
Functions are defined to manipulate entries in the TLV parameter table.
* tlv_{set|unset}_proc set a TLV proc entry (ops and parameters)
* tlv_{set|unset}_params set parameters only
Receive TLV lookup and processing is modified to be a lookup in the TLV parameter table. An init table containing parameters for TLVs supported by the kernel is used to initialize the TLV table.
--- include/net/ipeh.h | 107 +++++++++++++++++-- include/net/ipv6.h | 3 + include/uapi/linux/ipeh.h | 16 +++ net/ipv6/exthdrs.c | 14 ++- net/ipv6/exthdrs_common.c | 260 ++++++++++++++++++++++++++++++++++++++++++--- net/ipv6/exthdrs_options.c | 63 +++++++---- 6 files changed, 414 insertions(+), 49 deletions(-) create mode 100644 include/uapi/linux/ipeh.h
include/net/ipeh.h +100 -7
@@ -11,13 +11,105 @@* and false, if it failed. * It MUST NOT touch skb->h. */ -struct tlvtype_proc { -int type; -bool (*func)(struct sk_buff *skb,int offset); +struct tlv_ops { +bool (*func)(unsigned int class,struct sk_buff *skb,int offset); }; -extern const struct tlvtype_proc tlvprocdestopt_lst[]; -extern const struct tlvtype_proc tlvprochopopt_lst[]; +struct tlv_rx_params { +unsigned char class :4 ; +}; + +struct tlv_tx_params { +}; + +struct tlv_params { +struct tlv_rx_params r; +struct tlv_tx_params t; +}; + +struct tlv_proc { +struct tlv_ops ops; +struct tlv_params params; +}; + +struct tlv_type { +struct tlv_proc proc; +}; + +struct tlv_proc_init { +int type; +struct tlv_proc proc; +}; + +struct tlv_param_table_data { +unsigned char entries[256 ]; +unsigned char count; +struct rcu_head rcu; +struct tlv_type types[0 ]; +}; + +struct tlv_param_table { +struct tlv_param_table_data __rcu *data; +}; + +extern struct tlv_param_table ipv6_tlv_param_table; + +int __ipeh_tlv_set (struct tlv_param_table *tlv_param_table, +unsigned char type,const struct tlv_params *params, +const struct tlv_ops *ops); + +static inline int ipeh_tlv_set_params (struct tlv_param_table *tlv_param_table, +unsigned char type, +const struct tlv_params *params) +{ +return __ipeh_tlv_set (tlv_param_table, type, params,NULL ); +} + +static inline int ipeh_tlv_set_proc (struct tlv_param_table *tlv_param_table, +unsigned char type, +const struct tlv_proc *proc) +{ +return __ipeh_tlv_set (tlv_param_table, type, + &proc->params, &proc->ops); +} + +int __ipeh_tlv_unset (struct tlv_param_table *tlv_param_table, +unsigned char type,bool params_only); + +static inline int ipeh_tlv_unset_params (struct tlv_param_table *tlv_param_table, +unsigned char type) +{ +return __ipeh_tlv_unset (tlv_param_table, type, true); +} + +static inline int ipeh_tlv_unset_proc (struct tlv_param_table *tlv_param_table, +unsigned char type) +{ +return __ipeh_tlv_unset (tlv_param_table, type, false); +} + +/* ipeh_tlv_get_proc_by_type assumes rcu_read_lock is held */ +static inline struct tlv_proc *ipeh_tlv_get_proc_by_type ( +struct tlv_param_table *tlv_param_table,unsigned char type) +{ +struct tlv_param_table_data *tpt = +rcu_dereference (tlv_param_table->data); + +return &tpt->types[tpt->entries[type]].proc; +} + +/* ipeh_tlv_get_proc assumes rcu_read_lock is held */ +static inline struct tlv_proc *ipeh_tlv_get_proc ( +struct tlv_param_table *tlv_param_table, +const __u8 *tlv) +{ +return ipeh_tlv_get_proc_by_type (tlv_param_table, tlv[0 ]); +} + +int ipeh_exthdrs_init (struct tlv_param_table *tlv_param_table, +const struct tlv_proc_init *init_params, +int num_init_params); +void ipeh_exthdrs_fini (struct tlv_param_table *tlv_param_table);struct ipv6_txoptions ;struct ipv6_opt_hdr ;
@@ -52,8 +144,9 @@ enum ipeh_parse_errors {#define IPEH_TLV_PAD1 0#define IPEH_TLV_PADN 1 -bool ipeh_parse_tlv (const struct tlvtype_proc *procs,struct sk_buff *skb, -int max_count,int off,int len, +bool ipeh_parse_tlv (unsigned int class, +struct tlv_param_table *tlv_param_table, +struct sk_buff *skb,int max_count,int off,int len,bool (*parse_error)(struct sk_buff *skb,int off,enum ipeh_parse_errors error));
include/net/ipv6.h +3 -0
@@ -429,6 +429,9 @@ int ip6_ra_control(struct sock *sk, int sel);int ipv6_parse_hopopts (struct sk_buff *skb); +int ipv6_exthdrs_options_init (void ); +void ipv6_exthdrs_options_exit (void ); +bool ipv6_opt_accepted (const struct sock *sk,const struct sk_buff *skb,const struct inet6_skb_parm *opt); struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
include/uapi/linux/ipeh.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* ipeh.h - IP extension header TLV management */ + +#ifndef _UAPI_LINUX_IPEH_H +#define _UAPI_LINUX_IPEH_H + +/* Flags for EH type that can use a TLV option */ +#define IPEH_TLV_CLASS_FLAG_HOPOPT BIT(0) +#define IPEH_TLV_CLASS_FLAG_RTRDSTOPT BIT(1) +#define IPEH_TLV_CLASS_FLAG_DSTOPT BIT(2) + +#define IPEH_TLV_CLASS_FLAG_MASK (IPEH_TLV_CLASS_FLAG_HOPOPT | \ + IPEH_TLV_CLASS_FLAG_RTRDSTOPT | \ + IPEH_TLV_CLASS_FLAG_DSTOPT) + +#endif /* _UAPI_LINUX_IPEH_H */
net/ipv6/exthdrs.c +11 -3
@@ -47,6 +47,7 @@#ifdef CONFIG_IPV6_SEG6_HMAC #include <net/seg6_hmac.h> #endif +#include <uapi/linux/ipeh.h> #include <linux/uaccess.h>
@@ -139,7 +140,8 @@ static int ipv6_destopt_rcv(struct sk_buff *skb) dstbuf = opt->dst1;#endif -if (ipeh_parse_tlv (tlvprocdestopt_lst, skb, +if (ipeh_parse_tlv (IPEH_TLV_CLASS_FLAG_DSTOPT , + &ipv6_tlv_param_table, skb, init_net.ipv6.sysctl.max_dst_opts_cnt,2 , extlen -2 , ipv6_parse_error)) { skb->transport_header += extlen;
@@ -522,8 +524,13 @@ int __init ipv6_exthdrs_init(void)if (ret) goto out_destopt; + ret =ipv6_exthdrs_options_init (); +if (ret) + goto out_nodata; out:return ret; +out_nodata: +inet6_del_protocol (&nodata_protocol,IPPROTO_NONE ); out_destopt:inet6_del_protocol (&destopt_protocol,IPPROTO_DSTOPTS ); out_rthdr:
@@ -533,6 +540,7 @@ int __init ipv6_exthdrs_init(void)void ipv6_exthdrs_exit (void ) { +ipv6_exthdrs_options_exit ();inet6_del_protocol (&nodata_protocol,IPPROTO_NONE );inet6_del_protocol (&destopt_protocol,IPPROTO_DSTOPTS );inet6_del_protocol (&rthdr_protocol,IPPROTO_ROUTING );
@@ -567,8 +575,8 @@ int ipv6_parse_hopopts(struct sk_buff *skb) goto fail_and_free; opt->flags |=IP6SKB_HOPBYHOP ; -if (ipeh_parse_tlv (tlvprochopopt_lst, skb, - init_net.ipv6.sysctl.max_hbh_opts_cnt, +if (ipeh_parse_tlv (IPEH_TLV_CLASS_FLAG_HOPOPT , &ipv6_tlv_param_table, + skb, init_net.ipv6.sysctl.max_hbh_opts_cnt,2 , extlen -2 , ipv6_parse_error)) { skb->transport_header += extlen; opt =IP6CB (skb);
net/ipv6/exthdrs_common.c +243 -17
292 lines not on this page · raw message
net/ipv6/exthdrs_options.c +41 -22
107 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 7/9 ip6tlvs: Add TX parameters
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Define a number of transmit parameters for TLV Parameter table definitions. These will be used for validating TLVs that are set on a socket.
--- include/net/ipeh.h | 18 ++++++++++++++++ include/uapi/linux/ipeh.h | 8 +++++++ net/ipv6/exthdrs_common.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- net/ipv6/exthdrs_options.c | 45 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 1 deletion(-)
include/net/ipeh.h +18 -0
@@ -20,6 +20,17 @@ struct tlv_rx_params { };struct tlv_tx_params { +unsigned char admin_perm :2 ; +unsigned char user_perm :2 ; +unsigned char class :3 ; +unsigned char rsvd :1 ; +unsigned char align_mult :4 ; +unsigned char align_off :4 ; +unsigned char data_len_mult :4 ; +unsigned char data_len_off :4 ; +unsigned char min_data_len; +unsigned char max_data_len; +unsigned short preferred_order; };struct tlv_params {
@@ -54,6 +65,13 @@ struct tlv_param_table {extern struct tlv_param_table ipv6_tlv_param_table; +/* Preferred TLV ordering for HBH and Dest options (placed by increasing order) +*/ +#define IPEH_TLV_PREF_ORDER_HAO 10 +#define IPEH_TLV_PREF_ORDER_ROUTERALERT 20 +#define IPEH_TLV_PREF_ORDER_JUMBO 30 +#define IPEH_TLV_PREF_ORDER_CALIPSO 40 +int __ipeh_tlv_set (struct tlv_param_table *tlv_param_table,unsigned char type,const struct tlv_params *params,const struct tlv_ops *ops);
include/uapi/linux/ipeh.h +8 -0
@@ -13,4 +13,12 @@ IPEH_TLV_CLASS_FLAG_RTRDSTOPT | \ IPEH_TLV_CLASS_FLAG_DSTOPT) +/* TLV permissions values */ +enum { +IPEH_TLV_PERM_NONE , +IPEH_TLV_PERM_WITH_CHECK , +IPEH_TLV_PERM_NO_CHECK , +IPEH_TLV_PERM_MAX =IPEH_TLV_PERM_NO_CHECK +}; +#endif /* _UAPI_LINUX_IPEH_H */
net/ipv6/exthdrs_common.c +52 -1
93 lines not on this page · raw message
net/ipv6/exthdrs_options.c +45 -0
69 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 8/9 ip6tlvs: Add netlink interface
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Add a netlink interface to manage the TX TLV parameters. Managed parameters include those for validating and sending TLVs being sent such as alignment, TLV ordering, length limits, etc.
--- include/net/ipeh.h | 16 +++ include/net/ipv6.h | 1 + include/uapi/linux/in6.h | 6 + include/uapi/linux/ipeh.h | 29 +++++ net/ipv6/exthdrs_common.c | 279 +++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/exthdrs_options.c | 81 ++++++++++++- 6 files changed, 410 insertions(+), 2 deletions(-)
include/net/ipeh.h +16 -0
@@ -3,6 +3,7 @@#define _NET_IPEH_H#include <linux/skbuff.h> +#include <net/genetlink.h> /* * Parsing tlv encoded headers.
@@ -106,6 +107,21 @@ static inline int ipeh_tlv_unset_proc(struct tlv_param_table *tlv_param_table,return __ipeh_tlv_unset (tlv_param_table, type, false); } +extern const struct nla_policy ipeh_tlv_nl_policy[]; + +int ipeh_tlv_nl_cmd_set (struct tlv_param_table *tlv_param_table, +struct genl_family *tlv_nl_family, +struct sk_buff *skb,struct genl_info *info); +int ipeh_tlv_nl_cmd_unset (struct tlv_param_table *tlv_param_table, +struct genl_family *tlv_nl_family, +struct sk_buff *skb,struct genl_info *info); +int ipeh_tlv_nl_cmd_get (struct tlv_param_table *tlv_param_table, +struct genl_family *tlv_nl_family, +struct sk_buff *skb,struct genl_info *info); +int ipeh_tlv_nl_dump (struct tlv_param_table *tlv_param_table, +struct genl_family *tlv_nl_family, +struct sk_buff *skb,struct netlink_callback *cb); +/* ipeh_tlv_get_proc_by_type assumes rcu_read_lock is held */ static inline struct tlv_proc *ipeh_tlv_get_proc_by_type (struct tlv_param_table *tlv_param_table,unsigned char type)
include/net/ipv6.h +1 -0
@@ -14,6 +14,7 @@#include <linux/jhash.h> #include <linux/refcount.h> #include <linux/jump_label_ratelimit.h> +#include <net/genetlink.h> #include <net/if_inet6.h> #include <net/ndisc.h> #include <net/flow.h>
include/uapi/linux/in6.h +6 -0
@@ -297,4 +297,10 @@ struct in6_flowlabel_req {* ... * MRT6_MAX */ + +/* NETLINK_GENERIC related info for IPv6 TLVs */ + +#define IPV6_TLV_GENL_NAME "ipv6-tlv" +#define IPV6_TLV_GENL_VERSION 0x1 +#endif /* _UAPI_LINUX_IN6_H */
include/uapi/linux/ipeh.h +29 -0
@@ -21,4 +21,33 @@ enum {IPEH_TLV_PERM_MAX =IPEH_TLV_PERM_NO_CHECK }; +/* NETLINK_GENERIC related info for IP TLVs */ + +enum { +IPEH_TLV_ATTR_UNSPEC , +IPEH_TLV_ATTR_TYPE ,/* u8, > 1 */ +IPEH_TLV_ATTR_ORDER ,/* u16 */ +IPEH_TLV_ATTR_ADMIN_PERM ,/* u8, perm value (0 to 2) */ +IPEH_TLV_ATTR_USER_PERM ,/* u8, perm value (0 to 2) */ +IPEH_TLV_ATTR_CLASS ,/* u8, 3 bit flags */ +IPEH_TLV_ATTR_ALIGN_MULT ,/* u8, 1 to 16 */ +IPEH_TLV_ATTR_ALIGN_OFF ,/* u8, 0 to 15 */ +IPEH_TLV_ATTR_MIN_DATA_LEN ,/* u8 (option data length) */ +IPEH_TLV_ATTR_MAX_DATA_LEN ,/* u8 (option data length) */ +IPEH_TLV_ATTR_DATA_LEN_MULT ,/* u8, 1 to 16 */ +IPEH_TLV_ATTR_DATA_LEN_OFF ,/* u8, 0 to 15 */ + + __IPEH_TLV_ATTR_MAX, +}; + +#define IPEH_TLV_ATTR_MAX (__IPEH_TLV_ATTR_MAX - 1) + +enum { +IPEH_TLV_CMD_SET , +IPEH_TLV_CMD_UNSET , +IPEH_TLV_CMD_GET , + + __IPEH_TLV_CMD_MAX, +}; +#endif /* _UAPI_LINUX_IPEH_H */
net/ipv6/exthdrs_common.c +279 -0
285 lines not on this page · raw message
net/ipv6/exthdrs_options.c +79 -2
98 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 9/9 ip6tlvs: Validation of TX Destination and Hop-by-Hop options
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Validate Destination and Hop-by-Hop options being set for transmit. This uses the information in the TLV parameters table to validate various aspects of both individual TLVs as well as a list of TLVs in an extension header.
There are two levels of validation that can be performed: simple checks and deep checks. Simple checks validate only the most basic properties such as that the TLV list fits into the EH. Deep checks do a fine grained validation that includes perferred ordering, length limits, and length alignment.
With proper permissions set in the TLV parameter table, this patch allows non-privileged users to send TLVs. Given that TLVs are open ended and potentially a source of DOS attack, deep checks are performed to limit the format that a non-privileged user can send. If deep checks are enabled, a canonical format for sending TLVs is enforced (in adherence with the robustness principle). A TLV must be well ordered with respect to the preferred order for the TLV. Each TLV must be aligned as described in the parameter table. Minimal padding (one padding TLV) is used to align TLVs. The length of the extension header as well as the count of non-padding TLVs is checked against max_*_opts_len and max_*_opts_cnt. For individual TLVs, length limits and length alignment is checked.
--- include/net/ipeh.h | 22 +++ net/ipv6/datagram.c | 51 ++++-- net/ipv6/exthdrs_common.c | 395 ++++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/ipv6_sockglue.c | 39 ++--- 4 files changed, 468 insertions(+), 39 deletions(-)
include/net/ipeh.h +22 -0
@@ -157,6 +157,28 @@ struct ipv6_txoptions *ipeh_renew_options(struct sock *sk,struct ipv6_txoptions *ipeh_fixup_options (struct ipv6_txoptions *opt_space,struct ipv6_txoptions *opt); +int ipeh_opt_validate_tlvs (struct net *net, +struct tlv_param_table *tlv_param_table, +struct ipv6_opt_hdr *opt, +unsigned int optname,bool admin, +unsigned int max_len,unsigned int max_cnt); +int ipeh_opt_validate_single_tlv (struct net *net, +struct tlv_param_table *tlv_param_table, +unsigned int optname,const __u8 *tlv, +size_t len,bool deleting,bool admin); +int ipeh_opt_check_perm (struct net *net, +struct tlv_param_table *tlv_param_table, +struct ipv6_txoptions *txopt,int optname,bool admin); + +struct ipv6_txoptions *ipeh_txopt_from_opt (struct sock *sk, +struct tlv_param_table + *tlv_param_table, +struct ipv6_txoptions *opt, +int optname,char __user *optval, +unsigned int optlen, +unsigned int max_len, +unsigned int max_cnt); +/* Generic extension header TLV parser */ enum ipeh_parse_errors {
net/ipv6/datagram.c +38 -13
96 lines not on this page · raw message
net/ipv6/exthdrs_common.c +395 -0
407 lines not on this page · raw message
net/ipv6/ipv6_sockglue.c +13 -26
@@ -395,40 +395,27 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,case IPV6_RTHDR :case IPV6_DSTOPTS : { +unsigned int max_len =-1U , max_cnt =-1U ;struct ipv6_txoptions *opt; -struct ipv6_opt_hdr *new =NULL ; -/* hop-by-hop / destination options are privileged option */ - retv = -EPERM ; -if (optname !=IPV6_RTHDR && !ns_capable (net->user_ns,CAP_NET_RAW )) +switch (optname) { +case IPV6_HOPOPTS : + max_len = net->ipv6.sysctl.max_hbh_opts_len; + max_cnt = net->ipv6.sysctl.max_hbh_opts_cnt;break ; - -/* remove any sticky options header with a zero option -* length, per RFC3542. -*/ -if (optlen ==0 ) - optval =NULL ; -else if (!optval) - goto e_inval; -else if (optlen <sizeof (struct ipv6_opt_hdr ) || - optlen &0x7 || optlen >8 *255 ) - goto e_inval; -else { - new =memdup_user (optval, optlen); -if (IS_ERR (new)) { - retv =PTR_ERR (new); +case IPV6_RTHDRDSTOPTS : +case IPV6_DSTOPTS : + max_len = net->ipv6.sysctl.max_dst_opts_len; + max_cnt = net->ipv6.sysctl.max_dst_opts_cnt;break ; - } -if (unlikely (ipv6_optlen (new) > optlen)) { -kfree (new); - goto e_inval; - } } opt =rcu_dereference_protected (np->opt,lockdep_sock_is_held (sk)); - opt =ipeh_renew_options (sk, opt, optname, new); -kfree (new); + opt =ipeh_txopt_from_opt (sk, &ipv6_tlv_param_table, opt, + optname, optval, optlen, max_len, + max_cnt); +if (IS_ERR (opt)) { retv =PTR_ERR (opt);break ;
Signature · 1 line
2.7.4