diff mbox series

[1/6] xfrm: fix refcount leak in __xfrm_policy_check()

Message ID 20220824050213.3643599-2-steffen.klassert@secunet.com (mailing list archive)
State Accepted
Commit 9c9cb23e00ddf45679b21b4dacc11d1ae7961ebe
Delegated to: Netdev Maintainers
Headers show
Series [1/6] xfrm: fix refcount leak in __xfrm_policy_check() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Pull request is its own cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 352 this patch: 352
netdev/cc_maintainers fail 1 blamed authors not CCed: jmorris@namei.org; 3 maintainers not CCed: edumazet@google.com jmorris@namei.org pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 352 this patch: 352
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Steffen Klassert Aug. 24, 2022, 5:02 a.m. UTC
From: Xin Xiong <xiongx18@fudan.edu.cn>

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>
---
 net/xfrm/xfrm_policy.c | 1 +
 1 file changed, 1 insertion(+)

Comments

patchwork-bot+netdevbpf@kernel.org Aug. 24, 2022, 12:10 p.m. UTC | #1
Hello:

This series was applied to netdev/net.git (master)
by Steffen Klassert <steffen.klassert@secunet.com>:

On Wed, 24 Aug 2022 07:02:08 +0200 you wrote:
> From: Xin Xiong <xiongx18@fudan.edu.cn>
> 
> 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.
> 
> [...]

Here is the summary with links:
  - [1/6] xfrm: fix refcount leak in __xfrm_policy_check()
    https://git.kernel.org/netdev/net/c/9c9cb23e00dd
  - [2/6] Revert "xfrm: update SA curlft.use_time"
    https://git.kernel.org/netdev/net/c/717ada9f10f2
  - [3/6] xfrm: fix XFRMA_LASTUSED comment
    https://git.kernel.org/netdev/net/c/36d763509be3
  - [4/6] xfrm: clone missing x->lastused in xfrm_do_migrate
    https://git.kernel.org/netdev/net/c/6aa811acdb76
  - [5/6] af_key: Do not call xfrm_probe_algs in parallel
    https://git.kernel.org/netdev/net/c/ba953a9d89a0
  - [6/6] xfrm: policy: fix metadata dst->dev xmit null pointer dereference
    https://git.kernel.org/netdev/net/c/17ecd4a4db47

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index f1a0bab920a5..4f8bbb825abc 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -3599,6 +3599,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();