netfilter: nf_tables: fix null deref due to zeroed list head
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: nf_tables: fix null deref due to zeroed list head
In nf_tables_updtable, if nf_tables_table_enable returns an error, nft_trans_destroy is called to free the transaction object.
nft_trans_destroy() calls list_del(), but the transaction was never placed on a list -- the list head is all zeroes, this results in a null dereference:
BUG: KASAN: null-ptr-deref in nft_trans_destroy+0x26/0x59 Call Trace: nft_trans_destroy+0x26/0x59 nf_tables_newtable+0x4bc/0x9bc [..]
Its sane to assume that nft_trans_destroy() can be called on the transaction object returned by nft_trans_alloc(), so make sure the list head is initialised.
--- net/netfilter/nf_tables_api.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_tables_api.c +1 -0
@@ -153,6 +153,7 @@ static struct nft_trans *nft_trans_alloc_gfp(const struct nft_ctx *ctx,if (trans ==NULL )return NULL ; +INIT_LIST_HEAD (&trans->list); trans->msg_type = msg_type; trans->ctx = *ctx;
Signature · 1 line
2.35.1
Quoted 13 lines · Florian Westphal
In
nf_tables_updtable, ifnf_tables_table_enablereturns an error,nft_trans_destroyis called to free the transaction object.
nft_trans_destroy()callslist_del(), but the transaction was never placed on a list -- the list head is all zeroes, this results in a null dereference:BUG: KASAN: null-ptr-deref in nft_trans_destroy+0x26/0x59 Call Trace: nft_trans_destroy+0x26/0x59 nf_tables_newtable+0x4bc/0x9bc [..]
Quoted 3 lines
Its sane to assume that
nft_trans_destroy()can be called on the transaction object returned bynft_trans_alloc(), so make sure the list head is initialised.
Applied to nf.git, thanks