Skip to contentSkip to conversation

CIFS: fix use-after-free of the lease keys

PATCH In review Aurelien Aptel 3 participants 3 messages Jan 31, 2019

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

PATCH 1/1 CIFS: fix use-after-free of the lease keys

The request buffers are freed right before copying the pointers. Use the func args instead which are identical and still valid.

Simple reproducer (requires KASAN enabled) on a cifs mount:

echo foo > foo ; tail -f foo & rm foo

Cc <[email protected]> # 4.20
Fixes 179e44d49c2f ("smb3: add tracepoint for sending lease break responses to server")
---
 fs/cifs/smb2pdu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/cifs/smb2pdu.c +2 -2
index 846e605175bf..54181387a770 100644
@@ -4435,8 +4435,8 @@ SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
 	rc = cifs_send_recv(xid, ses, &rqst, &resp_buf_type, flags, &rsp_iov);
 	cifs_small_buf_release(req);
 
-	please_key_low = (__u64 *)req->LeaseKey;
-	please_key_high = (__u64 *)(req->LeaseKey+8);
+	please_key_low = (__u64 *)lease_key;
+	please_key_high = (__u64 *)(lease_key+8);
 	if (rc) {
 		cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
 		trace_smb3_lease_err(le32_to_cpu(lease_state), tcon->tid,
Signature · 1 line
2.16.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Aurelien Aptel

The request buffers are freed right before copying the pointers. Use the func args instead which are identical and still valid.

Simple reproducer (requires KASAN enabled) on a cifs mount:

echo foo > foo ; tail -f foo & rm foo

Cc <[email protected]> # 4.20
Fixes 179e44d49c2f ("smb3: add tracepoint for sending lease break responses to server")
---
 fs/cifs/smb2pdu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/cifs/smb2pdu.c +2 -2
index 846e605175bf..54181387a770 100644
@@ -4435,8 +4435,8 @@ SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
 	rc = cifs_send_recv(xid, ses, &rqst, &resp_buf_type, flags, &rsp_iov);
 	cifs_small_buf_release(req);
 
-	please_key_low = (__u64 *)req->LeaseKey;
-	please_key_high = (__u64 *)(req->LeaseKey+8);
+	please_key_low = (__u64 *)lease_key;
+	please_key_high = (__u64 *)(lease_key+8);
 	if (rc) {
 		cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
 		trace_smb3_lease_err(le32_to_cpu(lease_state), tcon->tid,
Signature · 1 line
2.16.4

Thanks!
Paulo

#2 lore raw

Moved into cifs-2.6.git for-next

Quoted 39 lines · Paulo Alcantara
Quoted 30 lines · Aurelien Aptel

The request buffers are freed right before copying the pointers. Use the func args instead which are identical and still valid.

Simple reproducer (requires KASAN enabled) on a cifs mount:

echo foo > foo ; tail -f foo & rm foo

Cc <[email protected]> # 4.20
Fixes 179e44d49c2f ("smb3: add tracepoint for sending lease break responses to server")
---
 fs/cifs/smb2pdu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/cifs/smb2pdu.c +2 -3
index 846e605175bf..54181387a770 100644
@@ -4435,8 +4435,8 @@ SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
      rc = cifs_send_recv(xid, ses, &rqst, &resp_buf_type, flags, &rsp_iov);
      cifs_small_buf_release(req);
 
-     please_key_low = (__u64 *)req->LeaseKey;
-     please_key_high = (__u64 *)(req->LeaseKey+8);
+     please_key_low = (__u64 *)lease_key;
+     please_key_high = (__u64 *)(lease_key+8);
      if (rc) {
              cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
              trace_smb3_lease_err(le32_to_cpu(lease_state), tcon->tid,
--
Quoted 1 line

2.16.4

Thanks!
Paulo

Signature · 3 lines
Thanks,

Steve