netfilter: conntrack: Use memset_startat() to zero struct nf_conn
authorKees Cook <keescook@chromium.org>
Thu, 18 Nov 2021 20:31:13 +0000 (12:31 -0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 30 Nov 2021 21:49:29 +0000 (22:49 +0100)
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.

Use memset_startat() to avoid confusing memset() about writing beyond
the target struct member.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_conntrack_core.c

index 054ee9d25efe174684025d60ea7b72e79c7ca19e..aa657db183183aa517c54de5e7a8bcffbc580074 100644 (file)
@@ -1562,9 +1562,7 @@ __nf_conntrack_alloc(struct net *net,
        ct->status = 0;
        ct->timeout = 0;
        write_pnet(&ct->ct_net, net);
-       memset(&ct->__nfct_init_offset, 0,
-              offsetof(struct nf_conn, proto) -
-              offsetof(struct nf_conn, __nfct_init_offset));
+       memset_after(ct, 0, __nfct_init_offset);
 
        nf_ct_zone_add(ct, zone);