netfiler: ipset: fix unaligned atomic access
Subsystems (3)
PATCH 1/1 netfiler: ipset: fix unaligned atomic access
When using ip_set with counters and comment, traffic causes the kernel to panic on 32-bit ARM:
Alignment trap: not handling instruction e1b82f9f at [<bf01b0dc>] Unhandled fault: alignment exception (0x221) at 0xea08133c PC is at ip_set_match_extensions+0xe0/0x224 [ip_set]
The problem occurs when we try to update the 64-bit counters - the faulting address above is not 64-bit aligned. The problem occurs due to the way elements are allocated, for example:
set->dsize = ip_set_elem_len(set, tb, 0, 0); map = ip_set_alloc(sizeof(*map) + elements * set->dsize);
If the element has a requirement for a member to be 64-bit aligned, and set->dsize is not a multiple of 8, but is a multiple of four, then every odd numbered elements will be misaligned - and hitting an atomic64_add() on that element will cause the kernel to panic.
ip_set_elem_len() must return a size that is rounded to the maximum alignment of any extension field stored in the element. This change ensures that is the case.
---
Patch against v5.6, where I tripped over this bug. This bug has caused a kernel panic on my new router twice today.
net/netfilter/ipset/ip_set_core.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/ipset/ip_set_core.c +2 -0
@@ -459,6 +459,8 @@ ip_set_elem_len(struct ip_set *set, struct nlattr *tb[], size_t len,for (id =0 ; id <IPSET_EXT_ID_MAX ; id++) {if (!add_extension (id, cadt_flags, tb))continue ; +if (align < ip_set_extensions[id].align) + align = ip_set_extensions[id].align; len =ALIGN (len, ip_set_extensions[id].align); set->offset[id] = len; set->extensions |= ip_set_extensions[id].type;
Signature · 1 line
2.20.1
Gentle ping...
This patch fixes a remotely triggerable kernel oops, and as such can be viewed as a remote denial of service attack depending on the netfilter rule setup.
Quoted 48 lines · Russell King
When using
ip_setwith counters and comment, traffic causes the kernel to panic on 32-bit ARM:Alignment trap: not handling instruction
e1b82f9fat [<bf01b0dc>] Unhandled fault: alignment exception (0x221) at0xea08133cPC is atip_set_match_extensions+0xe0/0x224[ip_set]The problem occurs when we try to update the 64-bit counters - the faulting address above is not 64-bit aligned. The problem occurs due to the way elements are allocated, for example:
set->dsize = ip_set_elem_len(set, tb, 0, 0); map = ip_set_alloc(sizeof(*map) + elements * set->dsize);If the element has a requirement for a member to be 64-bit aligned, and
set->dsizeis not a multiple of 8, but is a multiple of four, then every odd numbered elements will be misaligned - and hitting anatomic64_add()on that element will cause the kernel to panic.
ip_set_elem_len()must return a size that is rounded to the maximum alignment of any extension field stored in the element. This change ensures that is the case.Signed-off-by Russell King <[email protected]>---
Patch against v5.6, where I tripped over this bug. This bug has caused a kernel panic on my new router twice today.net/netfilter/ipset/ip_set_core.c | 2 ++ 1 file changed, 2 insertions(+)net/netfilter/ipset/ip_set_core.c +2
-0@@ -459,6 +459,8 @@ ip_set_elem_len(struct ip_set *set, struct nlattr *tb[], size_t len,for (id =0 ; id <IPSET_EXT_ID_MAX ; id++) {if (!add_extension (id, cadt_flags, tb))continue ; +if (align < ip_set_extensions[id].align) + align = ip_set_extensions[id].align; len =ALIGN (len, ip_set_extensions[id].align); set->offset[id] = len; set->extensions |= ip_set_extensions[id].type;Signature · 1 line
2.20.1
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Pablo Neira Ayuso
maintainerHi Jozsef,
I'll place in this in nf.git unless you have any objection.
Thanks.
Quoted 59 lines · Russell King - ARM Linux admin
Gentle ping...
This patch fixes a remotely triggerable kernel oops, and as such can be viewed as a remote denial of service attack depending on the netfilter rule setup.
Quoted 48 lines · Russell King
When using
ip_setwith counters and comment, traffic causes the kernel to panic on 32-bit ARM:Alignment trap: not handling instruction
e1b82f9fat [<bf01b0dc>] Unhandled fault: alignment exception (0x221) at0xea08133cPC is atip_set_match_extensions+0xe0/0x224[ip_set]The problem occurs when we try to update the 64-bit counters - the faulting address above is not 64-bit aligned. The problem occurs due to the way elements are allocated, for example:
set->dsize = ip_set_elem_len(set, tb, 0, 0); map = ip_set_alloc(sizeof(*map) + elements * set->dsize);If the element has a requirement for a member to be 64-bit aligned, and
set->dsizeis not a multiple of 8, but is a multiple of four, then every odd numbered elements will be misaligned - and hitting anatomic64_add()on that element will cause the kernel to panic.
ip_set_elem_len()must return a size that is rounded to the maximum alignment of any extension field stored in the element. This change ensures that is the case.Signed-off-by Russell King <[email protected]>---
Patch against v5.6, where I tripped over this bug. This bug has caused a kernel panic on my new router twice today.net/netfilter/ipset/ip_set_core.c | 2 ++ 1 file changed, 2 insertions(+)net/netfilter/ipset/ip_set_core.c +2
-0@@ -459,6 +459,8 @@ ip_set_elem_len(struct ip_set *set, struct nlattr *tb[], size_t len,for (id =0 ; id <IPSET_EXT_ID_MAX ; id++) {if (!add_extension (id, cadt_flags, tb))continue ; +if (align < ip_set_extensions[id].align) + align = ip_set_extensions[id].align; len =ALIGN (len, ip_set_extensions[id].align); set->offset[id] = len; set->extensions |= ip_set_extensions[id].type;Signature · 1 line
2.20.1Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Jozsef Kadlecsik
Acked-byHi,
Quoted 1 line · Pablo Neira Ayuso
I'll place in this in nf.git unless you have any objection.
No objection at all and thanks!
Best regards,
Jozsef
Quoted 52 lines · Russell King - ARM Linux admin
Quoted 51 lines
Gentle ping...
This patch fixes a remotely triggerable kernel oops, and as such can be viewed as a remote denial of service attack depending on the netfilter rule setup.
Quoted 44 lines · Russell King
When using
ip_setwith counters and comment, traffic causes the kernel to panic on 32-bit ARM:Alignment trap: not handling instruction
e1b82f9fat [<bf01b0dc>] Unhandled fault: alignment exception (0x221) at0xea08133cPC is atip_set_match_extensions+0xe0/0x224[ip_set]The problem occurs when we try to update the 64-bit counters - the faulting address above is not 64-bit aligned. The problem occurs due to the way elements are allocated, for example:
set->dsize = ip_set_elem_len(set, tb, 0, 0); map = ip_set_alloc(sizeof(*map) + elements * set->dsize);If the element has a requirement for a member to be 64-bit aligned, and
set->dsizeis not a multiple of 8, but is a multiple of four, then every odd numbered elements will be misaligned - and hitting anatomic64_add()on that element will cause the kernel to panic.
ip_set_elem_len()must return a size that is rounded to the maximum alignment of any extension field stored in the element. This change ensures that is the case.Signed-off-by Russell King <[email protected]>---
Patch against v5.6, where I tripped over this bug. This bug has caused a kernel panic on my new router twice today.net/netfilter/ipset/ip_set_core.c | 2 ++ 1 file changed, 2 insertions(+)net/netfilter/ipset/ip_set_core.c +2
-0@@ -459,6 +459,8 @@ ip_set_elem_len(struct ip_set *set, struct nlattr *tb[], size_t len,for (id =0 ; id <IPSET_EXT_ID_MAX ; id++) {if (!add_extension (id, cadt_flags, tb))continue ; +if (align < ip_set_extensions[id].align) + align = ip_set_extensions[id].align; len =ALIGN (len, ip_set_extensions[id].align); set->offset[id] = len; set->extensions |= ip_set_extensions[id].type;
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Signature · 1 line
2.20.1Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
-
E-mail : [email protected], [email protected] PGP key : https://wigner.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 14 lines · Russell King
When using
ip_setwith counters and comment, traffic causes the kernel to panic on 32-bit ARM:Alignment trap: not handling instruction
e1b82f9fat [<bf01b0dc>] Unhandled fault: alignment exception (0x221) at0xea08133cPC is atip_set_match_extensions+0xe0/0x224[ip_set]The problem occurs when we try to update the 64-bit counters - the faulting address above is not 64-bit aligned. The problem occurs due to the way elements are allocated, for example:
set->dsize = ip_set_elem_len(set, tb, 0, 0); map = ip_set_alloc(sizeof(*map) + elements * set->dsize);
Quoted 8 lines
If the element has a requirement for a member to be 64-bit aligned, and
set->dsizeis not a multiple of 8, but is a multiple of four, then every odd numbered elements will be misaligned - and hitting anatomic64_add()on that element will cause the kernel to panic.
ip_set_elem_len()must return a size that is rounded to the maximum alignment of any extension field stored in the element. This change ensures that is the case.
Applied, thanks.
Quoted 20 lines · Pablo Neira Ayuso
Quoted 19 lines · Russell King
When using
ip_setwith counters and comment, traffic causes the kernel to panic on 32-bit ARM:Alignment trap: not handling instruction
e1b82f9fat [<bf01b0dc>] Unhandled fault: alignment exception (0x221) at0xea08133cPC is atip_set_match_extensions+0xe0/0x224[ip_set]The problem occurs when we try to update the 64-bit counters - the faulting address above is not 64-bit aligned. The problem occurs due to the way elements are allocated, for example:
set->dsize = ip_set_elem_len(set, tb, 0, 0); map = ip_set_alloc(sizeof(*map) + elements * set->dsize);If the element has a requirement for a member to be 64-bit aligned, and
set->dsizeis not a multiple of 8, but is a multiple of four, then every odd numbered elements will be misaligned - and hitting anatomic64_add()on that element will cause the kernel to panic.
Quoted 5 lines
Quoted 3 lines
ip_set_elem_len()must return a size that is rounded to the maximum alignment of any extension field stored in the element. This change ensures that is the case.Applied, thanks.
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!