blob: a7ab6d687c6ff446a94bf6edc37c460f7b0731c2 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001From c392c159605956c7bd4a264ab4490e2b2704c0cd Mon Sep 17 00:00:00 2001
2From: Pablo Neira Ayuso <pablo@netfilter.org>
3Date: Fri, 13 Jun 2014 12:53:17 +0200
4Subject: [PATCH] conntrackd: build: fix crash when optional kernel modules are
5 not loaded
6
7Upstream-Status: Backport
8
9Fix a possible crash if conntrackd sees DCCP, SCTP and ICMPv6 traffic
10and the corresponding kernel modules that track this traffic are not
11available.
12
13Fixes: http://bugzilla.netfilter.org/show_bug.cgi?id=910
14Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
15---
16 src/build.c | 22 +++++++++++++---------
17 1 file changed, 13 insertions(+), 9 deletions(-)
18
19diff --git a/src/build.c b/src/build.c
20index 5799b51..9ba8b57 100644
21--- a/src/build.c
22+++ b/src/build.c
23@@ -105,14 +105,14 @@ static enum nf_conntrack_attr nat_type[] =
24 ATTR_ORIG_NAT_SEQ_OFFSET_AFTER, ATTR_REPL_NAT_SEQ_CORRECTION_POS,
25 ATTR_REPL_NAT_SEQ_OFFSET_BEFORE, ATTR_REPL_NAT_SEQ_OFFSET_AFTER };
26
27+/* ICMP, UDP and TCP are always loaded with nf_conntrack_ipv4 */
28 static void build_l4proto_tcp(const struct nf_conntrack *ct, struct nethdr *n)
29 {
30- ct_build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT,
31- sizeof(struct nfct_attr_grp_port));
32-
33 if (!nfct_attr_is_set(ct, ATTR_TCP_STATE))
34 return;
35
36+ ct_build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT,
37+ sizeof(struct nfct_attr_grp_port));
38 ct_build_u8(ct, ATTR_TCP_STATE, n, NTA_TCP_STATE);
39 if (CONFIG(sync).tcp_window_tracking) {
40 ct_build_u8(ct, ATTR_TCP_WSCALE_ORIG, n, NTA_TCP_WSCALE_ORIG);
41@@ -122,12 +122,12 @@ static void build_l4proto_tcp(const struct nf_conntrack *ct, struct nethdr *n)
42
43 static void build_l4proto_sctp(const struct nf_conntrack *ct, struct nethdr *n)
44 {
45- ct_build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT,
46- sizeof(struct nfct_attr_grp_port));
47-
48+ /* SCTP is optional, make sure nf_conntrack_sctp is loaded */
49 if (!nfct_attr_is_set(ct, ATTR_SCTP_STATE))
50 return;
51
52+ ct_build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT,
53+ sizeof(struct nfct_attr_grp_port));
54 ct_build_u8(ct, ATTR_SCTP_STATE, n, NTA_SCTP_STATE);
55 ct_build_u32(ct, ATTR_SCTP_VTAG_ORIG, n, NTA_SCTP_VTAG_ORIG);
56 ct_build_u32(ct, ATTR_SCTP_VTAG_REPL, n, NTA_SCTP_VTAG_REPL);
57@@ -135,18 +135,22 @@ static void build_l4proto_sctp(const struct nf_conntrack *ct, struct nethdr *n)
58
59 static void build_l4proto_dccp(const struct nf_conntrack *ct, struct nethdr *n)
60 {
61- ct_build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT,
62- sizeof(struct nfct_attr_grp_port));
63-
64+ /* DCCP is optional, make sure nf_conntrack_dccp is loaded */
65 if (!nfct_attr_is_set(ct, ATTR_DCCP_STATE))
66 return;
67
68+ ct_build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT,
69+ sizeof(struct nfct_attr_grp_port));
70 ct_build_u8(ct, ATTR_DCCP_STATE, n, NTA_DCCP_STATE);
71 ct_build_u8(ct, ATTR_DCCP_ROLE, n, NTA_DCCP_ROLE);
72 }
73
74 static void build_l4proto_icmp(const struct nf_conntrack *ct, struct nethdr *n)
75 {
76+ /* This is also used by ICMPv6 and nf_conntrack_ipv6 is optional */
77+ if (!nfct_attr_is_set(ct, ATTR_ICMP_TYPE))
78+ return;
79+
80 ct_build_u8(ct, ATTR_ICMP_TYPE, n, NTA_ICMP_TYPE);
81 ct_build_u8(ct, ATTR_ICMP_CODE, n, NTA_ICMP_CODE);
82 ct_build_u16(ct, ATTR_ICMP_ID, n, NTA_ICMP_ID);
83--
841.9.1
85