Skip to content

Commit 7bb4d65

Browse files
committed
Merge tag 'v6.18rc4-SMB-client-fixes' of git://git.samba.org/sfrench/cifs-2.6
Pull smb client fixes from Steve French: - Fix change notify packet validation check - Refcount fix (e.g. rename error paths) - Fix potential UAF due to missing locks on directory lease refcount * tag 'v6.18rc4-SMB-client-fixes' of git://git.samba.org/sfrench/cifs-2.6: smb: client: validate change notify buffer before copy smb: client: fix refcount leak in smb2_set_path_attr smb: client: fix potential UAF in smb2_close_cached_fid()
2 parents 0d7bee1 + 4012abe commit 7bb4d65

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

fs/smb/client/cached_dir.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
388388
* lease. Release one here, and the second below.
389389
*/
390390
cfid->has_lease = false;
391-
kref_put(&cfid->refcount, smb2_close_cached_fid);
391+
close_cached_dir(cfid);
392392
}
393393
spin_unlock(&cfids->cfid_list_lock);
394394

395-
kref_put(&cfid->refcount, smb2_close_cached_fid);
395+
close_cached_dir(cfid);
396396
} else {
397397
*ret_cfid = cfid;
398398
atomic_inc(&tcon->num_remote_opens);
@@ -438,12 +438,14 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
438438

439439
static void
440440
smb2_close_cached_fid(struct kref *ref)
441+
__releases(&cfid->cfids->cfid_list_lock)
441442
{
442443
struct cached_fid *cfid = container_of(ref, struct cached_fid,
443444
refcount);
444445
int rc;
445446

446-
spin_lock(&cfid->cfids->cfid_list_lock);
447+
lockdep_assert_held(&cfid->cfids->cfid_list_lock);
448+
447449
if (cfid->on_list) {
448450
list_del(&cfid->entry);
449451
cfid->on_list = false;
@@ -478,7 +480,7 @@ void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
478480
spin_lock(&cfid->cfids->cfid_list_lock);
479481
if (cfid->has_lease) {
480482
cfid->has_lease = false;
481-
kref_put(&cfid->refcount, smb2_close_cached_fid);
483+
close_cached_dir(cfid);
482484
}
483485
spin_unlock(&cfid->cfids->cfid_list_lock);
484486
close_cached_dir(cfid);
@@ -487,7 +489,7 @@ void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
487489

488490
void close_cached_dir(struct cached_fid *cfid)
489491
{
490-
kref_put(&cfid->refcount, smb2_close_cached_fid);
492+
kref_put_lock(&cfid->refcount, smb2_close_cached_fid, &cfid->cfids->cfid_list_lock);
491493
}
492494

493495
/*
@@ -596,7 +598,7 @@ cached_dir_offload_close(struct work_struct *work)
596598

597599
WARN_ON(cfid->on_list);
598600

599-
kref_put(&cfid->refcount, smb2_close_cached_fid);
601+
close_cached_dir(cfid);
600602
cifs_put_tcon(tcon, netfs_trace_tcon_ref_put_cached_close);
601603
}
602604

@@ -762,7 +764,7 @@ static void cfids_laundromat_worker(struct work_struct *work)
762764
* Drop the ref-count from above, either the lease-ref (if there
763765
* was one) or the extra one acquired.
764766
*/
765-
kref_put(&cfid->refcount, smb2_close_cached_fid);
767+
close_cached_dir(cfid);
766768
}
767769
queue_delayed_work(cfid_put_wq, &cfids->laundromat_work,
768770
dir_cache_timeout * HZ);

fs/smb/client/smb2inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,8 @@ static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
12941294
smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
12951295
if (smb2_to_name == NULL) {
12961296
rc = -ENOMEM;
1297+
if (cfile)
1298+
cifsFileInfo_put(cfile);
12971299
goto smb2_rename_path;
12981300
}
12991301
in_iov.iov_base = smb2_to_name;

fs/smb/client/smb2pdu.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4054,9 +4054,12 @@ SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon,
40544054

40554055
smb_rsp = (struct smb2_change_notify_rsp *)rsp_iov.iov_base;
40564056

4057-
smb2_validate_iov(le16_to_cpu(smb_rsp->OutputBufferOffset),
4058-
le32_to_cpu(smb_rsp->OutputBufferLength), &rsp_iov,
4057+
rc = smb2_validate_iov(le16_to_cpu(smb_rsp->OutputBufferOffset),
4058+
le32_to_cpu(smb_rsp->OutputBufferLength),
4059+
&rsp_iov,
40594060
sizeof(struct file_notify_information));
4061+
if (rc)
4062+
goto cnotify_exit;
40604063

40614064
*out_data = kmemdup((char *)smb_rsp + le16_to_cpu(smb_rsp->OutputBufferOffset),
40624065
le32_to_cpu(smb_rsp->OutputBufferLength), GFP_KERNEL);

0 commit comments

Comments
 (0)