dpll: Fix potential msg memleak when genlmsg_put_reply failed

JIRA: https://issues.redhat.com/browse/RHEL-19095

commit b6fe6f03716da246b453369f98a553d4ab21447c
Author: Hao Ge <gehao@kylinos.cn>
Date:   Tue Nov 21 09:37:09 2023 +0800

    dpll: Fix potential msg memleak when genlmsg_put_reply failed

    We should clean the skb resource if genlmsg_put_reply failed.

    Fixes: 9d71b54b65b1 ("dpll: netlink: Add DPLL framework base functions")
    Signed-off-by: Hao Ge <gehao@kylinos.cn>
    Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
    Link: https://lore.kernel.org/r/20231121013709.73323-1-gehao@kylinos.cn
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
This commit is contained in:
Michal Schmidt 2023-12-13 10:32:37 +01:00
parent f380f2f1dc
commit 28c7d4d134
1 changed files with 12 additions and 5 deletions

View File

@ -923,9 +923,10 @@ int dpll_nl_pin_id_get_doit(struct sk_buff *skb, struct genl_info *info)
return -ENOMEM;
hdr = genlmsg_put_reply(msg, info, &dpll_nl_family, 0,
DPLL_CMD_PIN_ID_GET);
if (!hdr)
if (!hdr) {
nlmsg_free(msg);
return -EMSGSIZE;
}
pin = dpll_pin_find_from_nlattr(info);
if (!IS_ERR(pin)) {
ret = dpll_msg_add_pin_handle(msg, pin);
@ -953,8 +954,10 @@ int dpll_nl_pin_get_doit(struct sk_buff *skb, struct genl_info *info)
return -ENOMEM;
hdr = genlmsg_put_reply(msg, info, &dpll_nl_family, 0,
DPLL_CMD_PIN_GET);
if (!hdr)
if (!hdr) {
nlmsg_free(msg);
return -EMSGSIZE;
}
ret = dpll_cmd_pin_get_one(msg, pin, info->extack);
if (ret) {
nlmsg_free(msg);
@ -1086,8 +1089,10 @@ int dpll_nl_device_id_get_doit(struct sk_buff *skb, struct genl_info *info)
return -ENOMEM;
hdr = genlmsg_put_reply(msg, info, &dpll_nl_family, 0,
DPLL_CMD_DEVICE_ID_GET);
if (!hdr)
if (!hdr) {
nlmsg_free(msg);
return -EMSGSIZE;
}
dpll = dpll_device_find_from_nlattr(info);
if (!IS_ERR(dpll)) {
@ -1114,8 +1119,10 @@ int dpll_nl_device_get_doit(struct sk_buff *skb, struct genl_info *info)
return -ENOMEM;
hdr = genlmsg_put_reply(msg, info, &dpll_nl_family, 0,
DPLL_CMD_DEVICE_GET);
if (!hdr)
if (!hdr) {
nlmsg_free(msg);
return -EMSGSIZE;
}
ret = dpll_device_get_one(dpll, msg, info->extack);
if (ret) {