Commit 4b8cb84d authored by Nazarov Sergey's avatar Nazarov Sergey Committed by Kleber Sacilotto de Souza

net: avoid use IPCB in cipso_v4_error

BugLink: https://bugs.launchpad.net/bugs/1822271

[ Upstream commit 3da1ed7a ]

Extract IP options in cipso_v4_error and use __icmp_send.
Signed-off-by: default avatarSergey Nazarov <s-nazarov@yandex.ru>
Acked-by: default avatarPaul Moore <paul@paul-moore.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Acked-by: default avatarJuerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 3e9bf120
...@@ -546,6 +546,8 @@ static inline int ip_options_echo(struct ip_options *dopt, struct sk_buff *skb) ...@@ -546,6 +546,8 @@ static inline int ip_options_echo(struct ip_options *dopt, struct sk_buff *skb)
} }
void ip_options_fragment(struct sk_buff *skb); void ip_options_fragment(struct sk_buff *skb);
int __ip_options_compile(struct net *net, struct ip_options *opt,
struct sk_buff *skb, __be32 *info);
int ip_options_compile(struct net *net, struct ip_options *opt, int ip_options_compile(struct net *net, struct ip_options *opt,
struct sk_buff *skb); struct sk_buff *skb);
int ip_options_get(struct net *net, struct ip_options_rcu **optp, int ip_options_get(struct net *net, struct ip_options_rcu **optp,
......
...@@ -1805,13 +1805,26 @@ int cipso_v4_validate(const struct sk_buff *skb, unsigned char **option) ...@@ -1805,13 +1805,26 @@ int cipso_v4_validate(const struct sk_buff *skb, unsigned char **option)
*/ */
void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway) void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway)
{ {
unsigned char optbuf[sizeof(struct ip_options) + 40];
struct ip_options *opt = (struct ip_options *)optbuf;
if (ip_hdr(skb)->protocol == IPPROTO_ICMP || error != -EACCES) if (ip_hdr(skb)->protocol == IPPROTO_ICMP || error != -EACCES)
return; return;
/*
* We might be called above the IP layer,
* so we can not use icmp_send and IPCB here.
*/
memset(opt, 0, sizeof(struct ip_options));
opt->optlen = ip_hdr(skb)->ihl*4 - sizeof(struct iphdr);
if (__ip_options_compile(dev_net(skb->dev), opt, skb, NULL))
return;
if (gateway) if (gateway)
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_NET_ANO, 0); __icmp_send(skb, ICMP_DEST_UNREACH, ICMP_NET_ANO, 0, opt);
else else
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_ANO, 0); __icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_ANO, 0, opt);
} }
/** /**
......
...@@ -254,8 +254,9 @@ static void spec_dst_fill(__be32 *spec_dst, struct sk_buff *skb) ...@@ -254,8 +254,9 @@ static void spec_dst_fill(__be32 *spec_dst, struct sk_buff *skb)
* If opt == NULL, then skb->data should point to IP header. * If opt == NULL, then skb->data should point to IP header.
*/ */
int ip_options_compile(struct net *net, int __ip_options_compile(struct net *net,
struct ip_options *opt, struct sk_buff *skb) struct ip_options *opt, struct sk_buff *skb,
__be32 *info)
{ {
__be32 spec_dst = htonl(INADDR_ANY); __be32 spec_dst = htonl(INADDR_ANY);
unsigned char *pp_ptr = NULL; unsigned char *pp_ptr = NULL;
...@@ -472,11 +473,22 @@ int ip_options_compile(struct net *net, ...@@ -472,11 +473,22 @@ int ip_options_compile(struct net *net,
return 0; return 0;
error: error:
if (skb) { if (info)
icmp_send(skb, ICMP_PARAMETERPROB, 0, htonl((pp_ptr-iph)<<24)); *info = htonl((pp_ptr-iph)<<24);
}
return -EINVAL; return -EINVAL;
} }
int ip_options_compile(struct net *net,
struct ip_options *opt, struct sk_buff *skb)
{
int ret;
__be32 info;
ret = __ip_options_compile(net, opt, skb, &info);
if (ret != 0 && skb)
icmp_send(skb, ICMP_PARAMETERPROB, 0, info);
return ret;
}
EXPORT_SYMBOL(ip_options_compile); EXPORT_SYMBOL(ip_options_compile);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment