lkml.org 
[lkml]   [2022]   [Sep]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.4 12/77] xfrm: fix refcount leak in __xfrm_policy_check()
    Date
    From: Xin Xiong <xiongx18@fudan.edu.cn>

    [ Upstream commit 9c9cb23e00ddf45679b21b4dacc11d1ae7961ebe ]

    The issue happens on an error path in __xfrm_policy_check(). When the
    fetching process of the object `pols[1]` fails, the function simply
    returns 0, forgetting to decrement the reference count of `pols[0]`,
    which is incremented earlier by either xfrm_sk_policy_lookup() or
    xfrm_policy_lookup(). This may result in memory leaks.

    Fix it by decreasing the reference count of `pols[0]` in that path.

    Fixes: 134b0fc544ba ("IPsec: propagate security module errors up from flow_cache_lookup")
    Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
    Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    net/xfrm/xfrm_policy.c | 1 +
    1 file changed, 1 insertion(+)

    diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
    index 28a8cdef8e51f..6f58be5a17711 100644
    --- a/net/xfrm/xfrm_policy.c
    +++ b/net/xfrm/xfrm_policy.c
    @@ -3619,6 +3619,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
    if (pols[1]) {
    if (IS_ERR(pols[1])) {
    XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR);
    + xfrm_pol_put(pols[0]);
    return 0;
    }
    pols[1]->curlft.use_time = ktime_get_real_seconds();
    --
    2.35.1


    \
     
     \ /
      Last update: 2022-09-02 14:40    [W:4.109 / U:0.068 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site