Blob Blame History Raw
From 178648916e73e00de83150eb0c90c0d3a977a46a Mon Sep 17 00:00:00 2001
From: Marek Majtyka <marekx.majtyka@intel.com>
Date: Fri, 20 Nov 2020 16:14:43 +0100
Subject: [PATCH] xsk: Fix incorrect netdev reference count
Git-commit: 178648916e73e00de83150eb0c90c0d3a977a46a
Patch-mainline: v5.10-rc7
References: git-fixes

Fix incorrect netdev reference count in xsk_bind operation. Incorrect
reference count of the device appears when a user calls bind with the
XDP_ZEROCOPY flag on an interface which does not support zero-copy.
In such a case, an error is returned but the reference count is not
decreased. This change fixes the fault, by decreasing the reference count
in case of such an error.

The problem being corrected appeared in '162c820ed896' for the first time,
and the code was moved to new file location over the time with commit
'c2d3d6a47462'. This specific patch applies to all version starting
from 'c2d3d6a47462'. The same solution should be applied but on different
file (net/xdp/xdp_umem.c) and function (xdp_umem_assign_dev) for versions
from '162c820ed896' to 'c2d3d6a47462' excluded.

Fixes: 162c820ed896 ("xdp: hold device for umem regardless of zero-copy mode")
Signed-off-by: Marek Majtyka <marekx.majtyka@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20201120151443.105903-1-marekx.majtyka@intel.com
Signed-off-by: Jiri Wiesner <jwiesner@suse.de>
---
 net/xdp/xdp_umem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index 77edb2143906..e61498ba25d3 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -136,8 +136,10 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
 err_unreg_umem:
 	if (!force_zc)
 		err = 0; /* fallback to copy mode */
-	if (err)
+	if (err) {
 		xdp_clear_umem_at_qid(dev, queue_id);
+		dev_put(dev);
+	}
 out_rtnl_unlock:
 	rtnl_unlock();
 	return err;
-- 
2.35.3