Commit 3b350356 authored by Eric Dumazet's avatar Eric Dumazet Committed by Stefan Bader

inet: frags: fix ip6frag_low_thresh boundary

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

commit 3d234012 upstream.

Giving an integer to proc_doulongvec_minmax() is dangerous on 64bit arches,
since linker might place next to it a non zero value preventing a change
to ip6frag_low_thresh.

ip6frag_low_thresh is not used anymore in the kernel, but we do not
want to prematuraly break user scripts wanting to change it.

Since specifying a minimal value of 0 for proc_doulongvec_minmax()
is moot, let's remove these zero values in all defrag units.

Fixes: 6e00f7dd ("ipv6: frags: fix /proc/sys/net/ipv6/ip6frag_low_thresh")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reported-by: default avatarMaciej Żenczykowski <maze@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 1313c893
...@@ -410,7 +410,6 @@ int lowpan_frag_rcv(struct sk_buff *skb, u8 frag_type) ...@@ -410,7 +410,6 @@ int lowpan_frag_rcv(struct sk_buff *skb, u8 frag_type)
} }
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
static long zero;
static struct ctl_table lowpan_frags_ns_ctl_table[] = { static struct ctl_table lowpan_frags_ns_ctl_table[] = {
{ {
...@@ -427,7 +426,6 @@ static struct ctl_table lowpan_frags_ns_ctl_table[] = { ...@@ -427,7 +426,6 @@ static struct ctl_table lowpan_frags_ns_ctl_table[] = {
.maxlen = sizeof(unsigned long), .maxlen = sizeof(unsigned long),
.mode = 0644, .mode = 0644,
.proc_handler = proc_doulongvec_minmax, .proc_handler = proc_doulongvec_minmax,
.extra1 = &zero,
.extra2 = &init_net.ieee802154_lowpan.frags.high_thresh .extra2 = &init_net.ieee802154_lowpan.frags.high_thresh
}, },
{ {
......
...@@ -58,14 +58,6 @@ ...@@ -58,14 +58,6 @@
static int sysctl_ipfrag_max_dist __read_mostly = 64; static int sysctl_ipfrag_max_dist __read_mostly = 64;
static const char ip_frag_cache_name[] = "ip4-frags"; static const char ip_frag_cache_name[] = "ip4-frags";
struct ipfrag_skb_cb
{
struct inet_skb_parm h;
int offset;
};
#define FRAG_CB(skb) ((struct ipfrag_skb_cb *)((skb)->cb))
/* Describe an entry in the "incomplete datagrams" queue. */ /* Describe an entry in the "incomplete datagrams" queue. */
struct ipq { struct ipq {
struct inet_frag_queue q; struct inet_frag_queue q;
...@@ -353,13 +345,13 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) ...@@ -353,13 +345,13 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
* this fragment, right? * this fragment, right?
*/ */
prev = qp->q.fragments_tail; prev = qp->q.fragments_tail;
if (!prev || FRAG_CB(prev)->offset < offset) { if (!prev || prev->ip_defrag_offset < offset) {
next = NULL; next = NULL;
goto found; goto found;
} }
prev = NULL; prev = NULL;
for (next = qp->q.fragments; next != NULL; next = next->next) { for (next = qp->q.fragments; next != NULL; next = next->next) {
if (FRAG_CB(next)->offset >= offset) if (next->ip_defrag_offset >= offset)
break; /* bingo! */ break; /* bingo! */
prev = next; prev = next;
} }
...@@ -370,7 +362,7 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) ...@@ -370,7 +362,7 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
* any overlaps are eliminated. * any overlaps are eliminated.
*/ */
if (prev) { if (prev) {
int i = (FRAG_CB(prev)->offset + prev->len) - offset; int i = (prev->ip_defrag_offset + prev->len) - offset;
if (i > 0) { if (i > 0) {
offset += i; offset += i;
...@@ -387,8 +379,8 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) ...@@ -387,8 +379,8 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
err = -ENOMEM; err = -ENOMEM;
while (next && FRAG_CB(next)->offset < end) { while (next && next->ip_defrag_offset < end) {
int i = end - FRAG_CB(next)->offset; /* overlap is 'i' bytes */ int i = end - next->ip_defrag_offset; /* overlap is 'i' bytes */
if (i < next->len) { if (i < next->len) {
/* Eat head of the next overlapped fragment /* Eat head of the next overlapped fragment
...@@ -396,7 +388,7 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) ...@@ -396,7 +388,7 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
*/ */
if (!pskb_pull(next, i)) if (!pskb_pull(next, i))
goto err; goto err;
FRAG_CB(next)->offset += i; next->ip_defrag_offset += i;
qp->q.meat -= i; qp->q.meat -= i;
if (next->ip_summed != CHECKSUM_UNNECESSARY) if (next->ip_summed != CHECKSUM_UNNECESSARY)
next->ip_summed = CHECKSUM_NONE; next->ip_summed = CHECKSUM_NONE;
...@@ -420,7 +412,13 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) ...@@ -420,7 +412,13 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
} }
} }
FRAG_CB(skb)->offset = offset; /* Note : skb->ip_defrag_offset and skb->dev share the same location */
dev = skb->dev;
if (dev)
qp->iif = dev->ifindex;
/* Makes sure compiler wont do silly aliasing games */
barrier();
skb->ip_defrag_offset = offset;
/* Insert this fragment in the chain of fragments. */ /* Insert this fragment in the chain of fragments. */
skb->next = next; skb->next = next;
...@@ -431,11 +429,6 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) ...@@ -431,11 +429,6 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
else else
qp->q.fragments = skb; qp->q.fragments = skb;
dev = skb->dev;
if (dev) {
qp->iif = dev->ifindex;
skb->dev = NULL;
}
qp->q.stamp = skb->tstamp; qp->q.stamp = skb->tstamp;
qp->q.meat += skb->len; qp->q.meat += skb->len;
qp->ecn |= ecn; qp->ecn |= ecn;
...@@ -511,7 +504,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev, ...@@ -511,7 +504,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
} }
WARN_ON(!head); WARN_ON(!head);
WARN_ON(FRAG_CB(head)->offset != 0); WARN_ON(head->ip_defrag_offset != 0);
/* Allocate a new buffer for the datagram. */ /* Allocate a new buffer for the datagram. */
ihlen = ip_hdrlen(head); ihlen = ip_hdrlen(head);
...@@ -678,7 +671,7 @@ struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user) ...@@ -678,7 +671,7 @@ struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
EXPORT_SYMBOL(ip_check_defrag); EXPORT_SYMBOL(ip_check_defrag);
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
static long zero; static int dist_min;
static struct ctl_table ip4_frags_ns_ctl_table[] = { static struct ctl_table ip4_frags_ns_ctl_table[] = {
{ {
...@@ -695,7 +688,6 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = { ...@@ -695,7 +688,6 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
.maxlen = sizeof(unsigned long), .maxlen = sizeof(unsigned long),
.mode = 0644, .mode = 0644,
.proc_handler = proc_doulongvec_minmax, .proc_handler = proc_doulongvec_minmax,
.extra1 = &zero,
.extra2 = &init_net.ipv4.frags.high_thresh .extra2 = &init_net.ipv4.frags.high_thresh
}, },
{ {
...@@ -724,7 +716,7 @@ static struct ctl_table ip4_frags_ctl_table[] = { ...@@ -724,7 +716,7 @@ static struct ctl_table ip4_frags_ctl_table[] = {
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec_minmax, .proc_handler = proc_dointvec_minmax,
.extra1 = &zero .extra1 = &dist_min,
}, },
{ } { }
}; };
......
...@@ -64,7 +64,6 @@ struct nf_ct_frag6_skb_cb ...@@ -64,7 +64,6 @@ struct nf_ct_frag6_skb_cb
static struct inet_frags nf_frags; static struct inet_frags nf_frags;
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
static long zero;
static struct ctl_table nf_ct_frag6_sysctl_table[] = { static struct ctl_table nf_ct_frag6_sysctl_table[] = {
{ {
...@@ -80,7 +79,6 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = { ...@@ -80,7 +79,6 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
.maxlen = sizeof(unsigned long), .maxlen = sizeof(unsigned long),
.mode = 0644, .mode = 0644,
.proc_handler = proc_doulongvec_minmax, .proc_handler = proc_doulongvec_minmax,
.extra1 = &zero,
.extra2 = &init_net.nf_frag.frags.high_thresh .extra2 = &init_net.nf_frag.frags.high_thresh
}, },
{ {
......
...@@ -547,7 +547,6 @@ static const struct inet6_protocol frag_protocol = { ...@@ -547,7 +547,6 @@ static const struct inet6_protocol frag_protocol = {
}; };
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
static int zero;
static struct ctl_table ip6_frags_ns_ctl_table[] = { static struct ctl_table ip6_frags_ns_ctl_table[] = {
{ {
...@@ -563,8 +562,7 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = { ...@@ -563,8 +562,7 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
.data = &init_net.ipv6.frags.low_thresh, .data = &init_net.ipv6.frags.low_thresh,
.maxlen = sizeof(unsigned long), .maxlen = sizeof(unsigned long),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec_minmax, .proc_handler = proc_doulongvec_minmax,
.extra1 = &zero,
.extra2 = &init_net.ipv6.frags.high_thresh .extra2 = &init_net.ipv6.frags.high_thresh
}, },
{ {
......
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