All of lore.kernel.org
 help / color / mirror / Atom feed
From: Henrique Carvalho <henrique.carvalho@suse.com>
To: Paulo Alcantara <pc@manguebit.com>
Cc: smfrench@gmail.com, ematsumiya@suse.de, sprasad@microsoft.com,
	paul@darkrain42.org, bharathsm@microsoft.com,
	linux-cifs@vger.kernel.org
Subject: Re: [PATCH v3] smb: client: fix race in smb2_close_cached_fid()
Date: Tue, 27 May 2025 16:18:56 -0300	[thread overview]
Message-ID: <aDYQILpDA0EqzsX7@precision> (raw)
In-Reply-To: <44fb26b3d061287bf1cf8ec458adc8a2@manguebit.com>

On Tue, May 27, 2025 at 04:06:01PM -0300, Paulo Alcantara wrote:
> Henrique Carvalho <henrique.carvalho@suse.com> writes:
> 
> > find_or_create_cached_dir() could grab a new reference after kref_put()
> > had seen the refcount drop to zero but before cfid_list_lock is acquired
> > in smb2_close_cached_fid(), leading to use-after-free.
> >
> > Switch to kref_put_lock() so cfid_release() runs with cfid_list_lock
> > held, closing that gap.
> 
> Does this mean that SMB2_close() will be called with @cfid_list_lock
> held?  If so, that's wrong.

What I mean here is "Switch to kref_put_lock() so
smb2_close_cached_fid() *IS CALLED* with cfid_list_lock held". Poor
wording on my part.

The lock will be released after cfid is removed from list.

My argument is that cfid can still be found before locking
cfid_list_lock in smb2_close_cached_fid. Here is the current code:

    static void
    smb2_close_cached_fid(struct kref *ref)
    {
            struct cached_fid *cfid = container_of(ref, struct cached_fid,
                                                   refcount);
            int rc;
    
+           /* kref is 0, but cfid can still be found here */
    
            spin_lock(&cfid->cfids->cfid_list_lock);
            if (cfid->on_list) {
                    list_del(&cfid->entry);
                    cfid->on_list = false;
                    cfid->cfids->num_entries--;
            }
            spin_unlock(&cfid->cfids->cfid_list_lock);
    
            dput(cfid->dentry);
            cfid->dentry = NULL;
    
            if (cfid->is_open) {
                    rc = SMB2_close(0, cfid->tcon, cfid->fid.persistent_fid,
                               cfid->fid.volatile_fid);
                    if (rc) /* should we retry on -EBUSY or -EAGAIN? */
                            cifs_dbg(VFS, "close cached dir rc %d\n", rc);
            }
     [...]




  reply	other threads:[~2025-05-27 19:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-27 18:42 [PATCH v3] smb: client: fix race in smb2_close_cached_fid() Henrique Carvalho
2025-05-27 19:06 ` Paulo Alcantara
2025-05-27 19:18   ` Henrique Carvalho [this message]
2025-05-27 19:29     ` Paulo Alcantara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aDYQILpDA0EqzsX7@precision \
    --to=henrique.carvalho@suse.com \
    --cc=bharathsm@microsoft.com \
    --cc=ematsumiya@suse.de \
    --cc=linux-cifs@vger.kernel.org \
    --cc=paul@darkrain42.org \
    --cc=pc@manguebit.com \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.