lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211025222415.983883-9-vladimir.oltean@nxp.com>
Date:   Tue, 26 Oct 2021 01:24:08 +0300
From:   Vladimir Oltean <vladimir.oltean@....com>
To:     netdev@...r.kernel.org, Roopa Prabhu <roopa@...dia.com>,
        Nikolay Aleksandrov <nikolay@...dia.com>,
        Ido Schimmel <idosch@...dia.com>
Cc:     Jakub Kicinski <kuba@...nel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Andrew Lunn <andrew@...n.ch>,
        Florian Fainelli <f.fainelli@...il.com>,
        Vivien Didelot <vivien.didelot@...il.com>,
        Vladimir Oltean <olteanv@...il.com>,
        Jiri Pirko <jiri@...dia.com>
Subject: [RFC PATCH net-next 08/15] net: bridge: take the hash_lock inside fdb_add_entry

In preparation of a future change where fdb_add_entry() will do some
work with the &br->hash_lock not held, make the noisy change of taking
that lock inside the function separately.

Signed-off-by: Vladimir Oltean <vladimir.oltean@....com>
---
 net/bridge/br_fdb.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 9c57040d8341..421b8960945a 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -893,19 +893,27 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
 			return -EINVAL;
 	}
 
+	spin_lock_bh(&br->hash_lock);
+
 	fdb = br_fdb_find(br, addr, vid);
 	if (fdb == NULL) {
-		if (!(flags & NLM_F_CREATE))
+		if (!(flags & NLM_F_CREATE)) {
+			spin_unlock_bh(&br->hash_lock);
 			return -ENOENT;
+		}
 
 		fdb = fdb_create(br, source, addr, vid, 0);
-		if (!fdb)
+		if (!fdb) {
+			spin_unlock_bh(&br->hash_lock);
 			return -ENOMEM;
+		}
 
 		modified = true;
 	} else {
-		if (flags & NLM_F_EXCL)
+		if (flags & NLM_F_EXCL) {
+			spin_unlock_bh(&br->hash_lock);
 			return -EEXIST;
+		}
 
 		if (READ_ONCE(fdb->dst) != source) {
 			WRITE_ONCE(fdb->dst, source);
@@ -948,6 +956,8 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
 		fdb_notify(br, fdb, RTM_NEWNEIGH, true);
 	}
 
+	spin_unlock_bh(&br->hash_lock);
+
 	return 0;
 }
 
@@ -980,9 +990,7 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
 		}
 		err = br_fdb_external_learn_add(br, p, addr, vid, true);
 	} else {
-		spin_lock_bh(&br->hash_lock);
 		err = fdb_add_entry(br, p, addr, ndm, nlh_flags, vid, nfea_tb);
-		spin_unlock_bh(&br->hash_lock);
 	}
 
 	return err;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ