Skip to content

Commit e3fe48f

Browse files
committed
Merge tag 'v6.18-rc6-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6
Pull smb client fixes from Steve French: - Fix potential memory leak in mount - Add some missing read tracepoints - Fix locking issue with directory leases * tag 'v6.18-rc6-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6: cifs: Add the smb3_read_* tracepoints to SMB1 cifs: fix memory leak in smb3_fs_context_parse_param error path smb: client: introduce close_cached_dir_locked()
2 parents a07a003 + d5227c8 commit e3fe48f

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

fs/smb/client/cached_dir.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static struct cached_fid *init_cached_dir(const char *path);
1616
static void free_cached_dir(struct cached_fid *cfid);
1717
static void smb2_close_cached_fid(struct kref *ref);
1818
static void cfids_laundromat_worker(struct work_struct *work);
19+
static void close_cached_dir_locked(struct cached_fid *cfid);
1920

2021
struct cached_dir_dentry {
2122
struct list_head entry;
@@ -388,7 +389,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
388389
* lease. Release one here, and the second below.
389390
*/
390391
cfid->has_lease = false;
391-
close_cached_dir(cfid);
392+
close_cached_dir_locked(cfid);
392393
}
393394
spin_unlock(&cfids->cfid_list_lock);
394395

@@ -480,18 +481,52 @@ void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
480481
spin_lock(&cfid->cfids->cfid_list_lock);
481482
if (cfid->has_lease) {
482483
cfid->has_lease = false;
483-
close_cached_dir(cfid);
484+
close_cached_dir_locked(cfid);
484485
}
485486
spin_unlock(&cfid->cfids->cfid_list_lock);
486487
close_cached_dir(cfid);
487488
}
488489

489-
490+
/**
491+
* close_cached_dir - drop a reference of a cached dir
492+
*
493+
* The release function will be called with cfid_list_lock held to remove the
494+
* cached dirs from the list before any other thread can take another @cfid
495+
* ref. Must not be called with cfid_list_lock held; use
496+
* close_cached_dir_locked() called instead.
497+
*
498+
* @cfid: cached dir
499+
*/
490500
void close_cached_dir(struct cached_fid *cfid)
491501
{
502+
lockdep_assert_not_held(&cfid->cfids->cfid_list_lock);
492503
kref_put_lock(&cfid->refcount, smb2_close_cached_fid, &cfid->cfids->cfid_list_lock);
493504
}
494505

506+
/**
507+
* close_cached_dir_locked - put a reference of a cached dir with
508+
* cfid_list_lock held
509+
*
510+
* Calling close_cached_dir() with cfid_list_lock held has the potential effect
511+
* of causing a deadlock if the invariant of refcount >= 2 is false.
512+
*
513+
* This function is used in paths that hold cfid_list_lock and expect at least
514+
* two references. If that invariant is violated, WARNs and returns without
515+
* dropping a reference; the final put must still go through
516+
* close_cached_dir().
517+
*
518+
* @cfid: cached dir
519+
*/
520+
static void close_cached_dir_locked(struct cached_fid *cfid)
521+
{
522+
lockdep_assert_held(&cfid->cfids->cfid_list_lock);
523+
524+
if (WARN_ON(kref_read(&cfid->refcount) < 2))
525+
return;
526+
527+
kref_put(&cfid->refcount, smb2_close_cached_fid);
528+
}
529+
495530
/*
496531
* Called from cifs_kill_sb when we unmount a share
497532
*/

fs/smb/client/cifssmb.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,14 @@ cifs_readv_callback(struct mid_q_entry *mid)
13631363
if (rdata->result == -ENODATA) {
13641364
rdata->result = 0;
13651365
__set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
1366+
trace_smb3_read_err(rdata->rreq->debug_id,
1367+
rdata->subreq.debug_index,
1368+
rdata->xid,
1369+
rdata->req->cfile->fid.persistent_fid,
1370+
tcon->tid, tcon->ses->Suid,
1371+
rdata->subreq.start + rdata->subreq.transferred,
1372+
rdata->subreq.len - rdata->subreq.transferred,
1373+
rdata->result);
13661374
} else {
13671375
size_t trans = rdata->subreq.transferred + rdata->got_bytes;
13681376
if (trans < rdata->subreq.len &&
@@ -1374,6 +1382,13 @@ cifs_readv_callback(struct mid_q_entry *mid)
13741382
}
13751383
if (rdata->got_bytes)
13761384
__set_bit(NETFS_SREQ_MADE_PROGRESS, &rdata->subreq.flags);
1385+
trace_smb3_read_done(rdata->rreq->debug_id,
1386+
rdata->subreq.debug_index,
1387+
rdata->xid,
1388+
rdata->req->cfile->fid.persistent_fid,
1389+
tcon->tid, tcon->ses->Suid,
1390+
rdata->subreq.start + rdata->subreq.transferred,
1391+
rdata->got_bytes);
13771392
}
13781393

13791394
trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value,
@@ -1445,6 +1460,13 @@ cifs_async_readv(struct cifs_io_subrequest *rdata)
14451460
rdata->iov[1].iov_base = (char *)smb + 4;
14461461
rdata->iov[1].iov_len = get_rfc1002_length(smb);
14471462

1463+
trace_smb3_read_enter(rdata->rreq->debug_id,
1464+
rdata->subreq.debug_index,
1465+
rdata->xid,
1466+
rdata->req->cfile->fid.netfid,
1467+
tcon->tid, tcon->ses->Suid,
1468+
rdata->subreq.start, rdata->subreq.len);
1469+
14481470
rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive,
14491471
cifs_readv_callback, NULL, rdata, 0, NULL);
14501472

fs/smb/client/fs_context.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,10 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
18341834
ctx->password = NULL;
18351835
kfree_sensitive(ctx->password2);
18361836
ctx->password2 = NULL;
1837+
kfree(ctx->source);
1838+
ctx->source = NULL;
1839+
kfree(fc->source);
1840+
fc->source = NULL;
18371841
return -EINVAL;
18381842
}
18391843

0 commit comments

Comments
 (0)