tunnel: check kernel does not provide too large geneve data
Pablo Neira Ayuso
maintainerPATCH 1/2 tunnel: check kernel does not provide too large geneve data
From: Pengpeng Hou <[email protected]>
Make sure kernel does not provide geneve data larger than NFTNL_TUNNEL_GENEVE_DATA_MAXLEN, which might overrun the buffer.
--- src/obj/tunnel.c | 5 +++++ 1 file changed, 5 insertions(+)
src/obj/tunnel.c +5 -0
@@ -596,6 +596,11 @@ nftnl_obj_tunnel_parse_geneve(struct nftnl_tunnel_opts *opts, struct nlattr *attif (tb[NFTA_TUNNEL_KEY_GENEVE_DATA ]) {uint32_t len =mnl_attr_get_payload_len (tb[NFTA_TUNNEL_KEY_GENEVE_DATA ]); +if (len >NFTNL_TUNNEL_GENEVE_DATA_MAXLEN ) { +free (opt); +return -1 ; + } +memcpy (opt->geneve.data,mnl_attr_get_payload (tb[NFTA_TUNNEL_KEY_GENEVE_DATA ]), len);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 2/2 tunnel: validate geneve class and type from setter
From: Pengpeng Hou <[email protected]>
Ensure size is correct, otherwise bail out with EINVAL.
--- src/obj/tunnel.c | 8 ++++++++ 1 file changed, 8 insertions(+)
src/obj/tunnel.c +8 -0
@@ -866,9 +866,17 @@ static int nftnl_tunnel_opt_geneve_set(struct nftnl_tunnel_opt *opt, uint16_t ty {switch (type) {case NFTNL_TUNNEL_GENEVE_CLASS : +if (data_len !=sizeof (uint16_t )) { + errno =EINVAL ; +return -1 ; + }memcpy (&opt->geneve.geneve_class, data, data_len);break ;case NFTNL_TUNNEL_GENEVE_TYPE : +if (data_len !=sizeof (uint8_t )) { + errno =EINVAL ; +return -1 ; + }memcpy (&opt->geneve.type, data, data_len);break ;case NFTNL_TUNNEL_GENEVE_DATA :
Signature · 1 line
2.47.3
Re: [PATCH libnftnl 2/2] tunnel: validate geneve class and type from setter
Quoted 23 lines · Pablo Neira Ayuso
From: Pengpeng Hou <[email protected]>
Ensure size is correct, otherwise bail out with EINVAL.
Fixes 239fbdb8979d ("tunnel: add support to geneve options")Signed-off-by Pengpeng Hou <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>--- src/obj/tunnel.c | 8 ++++++++ 1 file changed, 8 insertions(+)src/obj/tunnel.c +4
-0@@ -866,9 +866,17 @@ static int nftnl_tunnel_opt_geneve_set(struct nftnl_tunnel_opt *opt, uint16_t ty {switch (type) {case NFTNL_TUNNEL_GENEVE_CLASS : +if (data_len !=sizeof (uint16_t )) { + errno =EINVAL ; +return -1 ; + }
src/obj/tunnel.c static int nftnl_tunnel_opt_geneve_set(struct nftnl_tunnel_opt *opt, uint16_t ty · line 882
Quoted 10 lines
src/obj/tunnel.c +4
-0memcpy (&opt->geneve.geneve_class, data, data_len);break ;case NFTNL_TUNNEL_GENEVE_TYPE : +if (data_len !=sizeof (uint8_t )) { + errno =EINVAL ; +return -1 ; + }memcpy (&opt->geneve.type, data, data_len);break ;case NFTNL_TUNNEL_GENEVE_DATA :
Thanks!
Quoted 18 lines · Pablo Neira Ayuso
From: Pengpeng Hou <[email protected]>
Make sure kernel does not provide geneve data larger than
NFTNL_TUNNEL_GENEVE_DATA_MAXLEN, which might overrun the buffer.Fixes 239fbdb8979d ("tunnel: add support to geneve options")Signed-off-by Pengpeng Hou <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>--- src/obj/tunnel.c | 5 +++++ 1 file changed, 5 insertions(+)src/obj/tunnel.c +0
-0@@ -596,6 +596,11 @@ nftnl_obj_tunnel_parse_geneve(struct nftnl_tunnel_opts *opts, struct nlattr *attif (tb[NFTA_TUNNEL_KEY_GENEVE_DATA ]) {
src/obj/tunnel.c nftnl_obj_tunnel_parse_geneve(struct nftnl_tunnel_opts *opts, struct nlattr *att · line 606
Quoted 10 lines
src/obj/tunnel.c +5
-0uint32_t len =mnl_attr_get_payload_len (tb[NFTA_TUNNEL_KEY_GENEVE_DATA ]); +if (len >NFTNL_TUNNEL_GENEVE_DATA_MAXLEN ) { +free (opt); +return -1 ; + } +memcpy (opt->geneve.data,mnl_attr_get_payload (tb[NFTA_TUNNEL_KEY_GENEVE_DATA ]), len);
Thanks!