lkml.org 
[lkml]   [2023]   [Nov]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v2] dpll: Fix potential msg memleak when genlmsg_put_reply failed
    Date
    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>
    ---
    v1 -> v2: change title due to add some similar fix for some similar cases
    ---
    drivers/dpll/dpll_netlink.c | 17 ++++++++++++-----
    1 file changed, 12 insertions(+), 5 deletions(-)

    diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c
    index a6dc3997bf5c..442a0ebeb953 100644
    --- a/drivers/dpll/dpll_netlink.c
    +++ b/drivers/dpll/dpll_netlink.c
    @@ -1093,9 +1093,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);
    @@ -1123,8 +1124,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);
    @@ -1256,8 +1259,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)) {
    @@ -1284,8 +1289,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) {
    --
    2.25.1
    \
     
     \ /
      Last update: 2023-11-21 02:38    [W:2.362 / U:0.212 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site