Skip to contentSkip to conversation

cifs: fix use after free for iface while disabling secondary channels

PATCH In review Ritvik Budhiraja 2 participants 2 messages Nov 21, 2023 – Nov 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix use after free for iface while disabling secondary channels

We were deferencing iface after it has been released. Fix is to release after all dereference instances have been encountered.

---
 fs/smb/client/sess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/sess.c +1 -1
index 8b2d7c1ca428..816e01c5589b 100644
@@ -332,10 +332,10 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)
 
 		if (iface) {
 			spin_lock(&ses->iface_lock);
-			kref_put(&iface->refcount, release_iface);
 			iface->num_channels--;
 			if (iface->weight_fulfilled)
 				iface->weight_fulfilled--;
+			kref_put(&iface->refcount, release_iface);
 			spin_unlock(&ses->iface_lock);
 		}
 
Signature · 1 line
2.34.1
#1 lore raw

tentatively merged into for-next pending testing

Quoted 31 lines · Ritvik Budhiraja

We were deferencing iface after it has been released. Fix is to release after all dereference instances have been encountered.

---
 fs/smb/client/sess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/sess.c +1 -2
index 8b2d7c1ca428..816e01c5589b 100644
@@ -332,10 +332,10 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)
 
                if (iface) {
                        spin_lock(&ses->iface_lock);
-                       kref_put(&iface->refcount, release_iface);
                        iface->num_channels--;
                        if (iface->weight_fulfilled)
                                iface->weight_fulfilled--;
+                       kref_put(&iface->refcount, release_iface);
                        spin_unlock(&ses->iface_lock);
                }
 
--

2.34.1

Signature · 3 lines
Thanks,

Steve