[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210727205855.411487-58-keescook@chromium.org>
Date: Tue, 27 Jul 2021 13:58:48 -0700
From: Kees Cook <keescook@...omium.org>
To: linux-hardening@...r.kernel.org
Cc: Kees Cook <keescook@...omium.org>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
Keith Packard <keithpac@...zon.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-wireless@...r.kernel.org,
netdev@...r.kernel.org, dri-devel@...ts.freedesktop.org,
linux-staging@...ts.linux.dev, linux-block@...r.kernel.org,
linux-kbuild@...r.kernel.org, clang-built-linux@...glegroups.com
Subject: [PATCH 57/64] netfilter: conntrack: Use struct_group() to zero struct nf_conn
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.
Replace the empty __nfct_init_offset member with a struct_group() to
mark the region of struct nf_conn that should be initialized to zero,
allowing memset() to correctly reason about the size of the write.
Signed-off-by: Kees Cook <keescook@...omium.org>
---
include/net/netfilter/nf_conntrack.h | 20 ++++++++++----------
net/netfilter/nf_conntrack_core.c | 4 +---
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index cc663c68ddc4..51004fce2937 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -101,24 +101,24 @@ struct nf_conn {
struct hlist_node nat_bysource;
#endif
/* all members below initialized via memset */
- struct { } __nfct_init_offset;
-
- /* If we were expected by an expectation, this will be it */
- struct nf_conn *master;
+ struct_group(init,
+ /* If we were expected by an expectation, this will be it */
+ struct nf_conn *master;
#if defined(CONFIG_NF_CONNTRACK_MARK)
- u_int32_t mark;
+ u_int32_t mark;
#endif
#ifdef CONFIG_NF_CONNTRACK_SECMARK
- u_int32_t secmark;
+ u_int32_t secmark;
#endif
- /* Extensions */
- struct nf_ct_ext *ext;
+ /* Extensions */
+ struct nf_ct_ext *ext;
- /* Storage reserved for other modules, must be the last member */
- union nf_conntrack_proto proto;
+ /* Storage reserved for other modules, must be the last member */
+ union nf_conntrack_proto proto;
+ );
};
static inline struct nf_conn *
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 5c03e5106751..b05eb64ec788 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1527,9 +1527,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(&ct->init, 0, sizeof(ct->init));
nf_ct_zone_add(ct, zone);
--
2.30.2
Powered by blists - more mailing lists