Skip to content

Commit b3a5db1

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: use u8 for extension sizes again
commit 223b02d ("netfilter: nf_conntrack: reserve two bytes for nf_ct_ext->len") had to increase size of the extension offsets because total size of the extensions had increased to a point where u8 did overflow. 3 years later we've managed to diet extensions a bit and we no longer need u16. Furthermore we can now add a compile-time assertion for this problem. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent faec865 commit b3a5db1

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

include/net/netfilter/nf_conntrack_extend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ enum nf_ct_ext_id {
4343
/* Extensions: optional stuff which isn't permanently in struct. */
4444
struct nf_ct_ext {
4545
struct rcu_head rcu;
46-
u16 offset[NF_CT_EXT_NUM];
47-
u16 len;
46+
u8 offset[NF_CT_EXT_NUM];
47+
u8 len;
4848
char data[0];
4949
};
5050

net/netfilter/nf_conntrack_core.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,12 +1804,45 @@ EXPORT_SYMBOL_GPL(nf_conntrack_set_hashsize);
18041804
module_param_call(hashsize, nf_conntrack_set_hashsize, param_get_uint,
18051805
&nf_conntrack_htable_size, 0600);
18061806

1807+
static unsigned int total_extension_size(void)
1808+
{
1809+
/* remember to add new extensions below */
1810+
BUILD_BUG_ON(NF_CT_EXT_NUM > 9);
1811+
1812+
return sizeof(struct nf_ct_ext) +
1813+
sizeof(struct nf_conn_help)
1814+
#if IS_ENABLED(CONFIG_NF_NAT)
1815+
+ sizeof(struct nf_conn_nat)
1816+
#endif
1817+
+ sizeof(struct nf_conn_seqadj)
1818+
+ sizeof(struct nf_conn_acct)
1819+
#ifdef CONFIG_NF_CONNTRACK_EVENTS
1820+
+ sizeof(struct nf_conntrack_ecache)
1821+
#endif
1822+
#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
1823+
+ sizeof(struct nf_conn_tstamp)
1824+
#endif
1825+
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1826+
+ sizeof(struct nf_conn_timeout)
1827+
#endif
1828+
#ifdef CONFIG_NF_CONNTRACK_LABELS
1829+
+ sizeof(struct nf_conn_labels)
1830+
#endif
1831+
#if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY)
1832+
+ sizeof(struct nf_conn_synproxy)
1833+
#endif
1834+
;
1835+
};
1836+
18071837
int nf_conntrack_init_start(void)
18081838
{
18091839
int max_factor = 8;
18101840
int ret = -ENOMEM;
18111841
int i;
18121842

1843+
/* struct nf_ct_ext uses u8 to store offsets/size */
1844+
BUILD_BUG_ON(total_extension_size() > 255u);
1845+
18131846
seqcount_init(&nf_conntrack_generation);
18141847

18151848
for (i = 0; i < CONNTRACK_LOCKS; i++)

0 commit comments

Comments
 (0)