net: genl: fix error path memory leak in policy dumping
Subsystems (2)
Jakub Kicinski
maintainerPATCH 1/1 net: genl: fix error path memory leak in policy dumping
If construction of the array of policies fails when recording non-first policy we need to unwind.
--- net/netlink/genetlink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/netlink/genetlink.c +5 -1
@@ -1174,13 +1174,17 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) op.policy, op.maxattr);if (err) -return err; + goto err_free_state; } }if (!ctx->state)return -ENODATA ;return 0 ; + +err_free_state: +netlink_policy_dump_free (ctx->state); +return err; } static void *ctrl_dumppolicy_prep(struct sk_buff *skb,
Signature · 1 line
2.37.2
Quoted 15 lines · Jakub Kicinski
If construction of the array of policies fails when recording non-first policy we need to unwind.
Reported-by [email protected]Fixes 50a896cf2d6f ("genetlink: properly support per-op policy dumping")Signed-off-by Jakub Kicinski <[email protected]>--- net/netlink/genetlink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)net/netlink/genetlink.c +0
-0
net/netlink/genetlink.c static int ctrl_dumppolicy_start(struct netlink_callback *cb) · line 1177
Quoted 5 lines
net/netlink/genetlink.c +1
-1@@ -1174,13 +1174,17 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) op.policy, op.maxattr);if (err) -return err; + goto err_free_state;
There's another call to netlink_policy_dump_add_policy() right above this one. The patch I posted to syzkaller frees the memory inside netlink_policy_dump_add_policy() and the result was OK.
Quoted 16 lines
net/netlink/genetlink.c +4
-0} }if (!ctx->state)return -ENODATA ;return 0 ; + +err_free_state: +netlink_policy_dump_free (ctx->state); +return err; } static void *ctrl_dumppolicy_prep(struct sk_buff *skb,Signature · 1 line
2.37.2
Jakub Kicinski
maintainerQuoted 6 lines · On Mon, 15 Aug 2022 11:20:21 -0700 Jakub Kicinski wrote:
If construction of the array of policies fails when recording non-first policy we need to unwind.
Reported-by [email protected]Fixes 50a896cf2d6f ("genetlink: properly support per-op policy dumping")Signed-off-by Jakub Kicinski <[email protected]>
syzbot says still pooped, indeed there's more leaks in netlink_policy_dump_add_policy() itself. v2 coming...
Jakub Kicinski
maintainerQuoted 11 lines · On Mon, 15 Aug 2022 18:08:58 -0300 Rafael Soares wrote:
Quoted 10 lines · Jakub Kicinski
If construction of the array of policies fails when recording non-first policy we need to unwind.
Reported-by [email protected]Fixes 50a896cf2d6f ("genetlink: properly support per-op policy dumping")Signed-off-by Jakub Kicinski <[email protected]>--- net/netlink/genetlink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 14 lines
net/netlink/genetlink.c static int ctrl_dumppolicy_start(struct netlink_callback *cb) · line 1177
Quoted 10 lines
net/netlink/genetlink.c +1
-1@@ -1174,13 +1174,17 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) op.policy, op.maxattr);if (err) -return err; + goto err_free_state;There's another call to
netlink_policy_dump_add_policy()right above this one. The patch I posted to syzkaller frees the memory insidenetlink_policy_dump_add_policy()and the result was OK.
Oh, sorry, I didn't see this reply. Every single time after the merge window is over the stable folks bombard the mailing systems with their backported patches and bring the mailing lists to their knees :/
Do you see your posting on lore.kernel.org? I presume not. You really need to use ./scripts/get_maintainer and CC relevant folks directly.
This is v2 of my fix I submitted to syzbot for testing:
The earlier call to netlink_policy_dump_add_policy() should not be a problem if the function unwound its state properly.