Skip to contentSkip to conversation

smb: client: Fix use-after-free in cifs_try_adding_channels()

PATCH Applied Shuangpeng Bai 2 participants 2 messages Aug 2

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

PATCH 1/1 smb: client: Fix use-after-free in cifs_try_adding_channels()

cifs_try_adding_channels() takes a temporary reference to an interface before dropping iface_lock. If cifs_ses_add_channel() fails, it drops that reference and then increments iface->weight_fulfilled.

A concurrent interface list refresh can remove the list reference while channel creation is in progress. In that case, the failure-path kref_put() releases the last reference and frees iface. Updating weight_fulfilled afterward then accesses freed memory.

Increment weight_fulfilled before dropping the temporary reference, keeping iface alive for the final access.

Fixes 6aac002bcfd5 ("cifs: failure to add channel on iface should bump up weight")
---
 fs/smb/client/sess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/sess.c +1 -1
index de2012cc9cf3..7cf7dd104f7c 100644
@@ -233,9 +233,9 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
 				cifs_dbg(VFS, "failed to open extra channel on iface:%pIS rc=%d\n",
 					 &iface->sockaddr,
 					 rc);
-				kref_put(&iface->refcount, release_iface);
 				/* failure to add chan should increase weight */
 				iface->weight_fulfilled++;
+				kref_put(&iface->refcount, release_iface);
 				continue;
 			}
 
Signature · 1 line
2.43.0
Applied
#1 lore raw

merged into cifs-2.6.git for-next

Quoted 39 lines · Shuangpeng Bai

cifs_try_adding_channels() takes a temporary reference to an interface before dropping iface_lock. If cifs_ses_add_channel() fails, it drops that reference and then increments iface->weight_fulfilled.

A concurrent interface list refresh can remove the list reference while channel creation is in progress. In that case, the failure-path kref_put() releases the last reference and frees iface. Updating weight_fulfilled afterward then accesses freed memory.

Increment weight_fulfilled before dropping the temporary reference, keeping iface alive for the final access.

Fixes 6aac002bcfd5 ("cifs: failure to add channel on iface should bump up weight")
---
 fs/smb/client/sess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/sess.c +1 -2
index de2012cc9cf3..7cf7dd104f7c 100644
@@ -233,9 +233,9 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
                                cifs_dbg(VFS, "failed to open extra channel on iface:%pIS rc=%d\n",
                                         &iface->sockaddr,
                                         rc);
-                               kref_put(&iface->refcount, release_iface);
                                /* failure to add chan should increase weight */
                                iface->weight_fulfilled++;
+                               kref_put(&iface->refcount, release_iface);
                                continue;
                        }
 
--

2.43.0

Signature · 3 lines
Thanks,

Steve