net: genl: fix error path memory leak in policy dumping
authorJakub Kicinski <kuba@kernel.org>
Tue, 16 Aug 2022 16:19:39 +0000 (09:19 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:40:25 +0000 (11:40 +0200)
commitb0672895d8be5d19d4b05ac83f807026fc791037
treed0dd4bb999eba05f54fc08be630c438d514c17c8
parent232fab59a65af0f0da6ef5318acfc832ad74b4d4
net: genl: fix error path memory leak in policy dumping

commit 249801360db3dec4f73768c502192020bfddeacc upstream.

If construction of the array of policies fails when recording
non-first policy we need to unwind.

netlink_policy_dump_add_policy() itself also needs fixing as
it currently gives up on error without recording the allocated
pointer in the pstate pointer.

Reported-by: syzbot+dc54d9ba8153b216cae0@syzkaller.appspotmail.com
Fixes: 50a896cf2d6f ("genetlink: properly support per-op policy dumping")
Link: https://lore.kernel.org/r/20220816161939.577583-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netlink/genetlink.c
net/netlink/policy.c