namjaejeon / ksmbd

ksmbd kernel server(SMB/CIFS server)
https://github.com/cifsd-team/ksmbd
273 stars 62 forks source link

smb: server: smb1: add missing path_put() calls in find_first() #452

Closed mmakassikis closed 1 year ago

mmakassikis commented 1 year ago

Error paths after ksmbd_vfs_dentry_open() were missing path_put() calls. Additionally, a path_put() is needed in the normal codepath.

'struct path' reference count is incremented twice in find_first():

One reference count must remain so that dir_fp is valid when it's looked up in find_next().

path_put() must be called once. It must be called a second time if:

namjaejeon commented 1 year ago

@mmakassikis Okay, old code seems doesn't have problem. there seems to be no leak from dentry and mnt of path in first_first and find_next.

        path_put(&(dir_fp->filp->f_path)); <--- this path_put for ksmbd_vfs_kern_path()
        if (le16_to_cpu(req_params->SearchFlags) &
                CIFS_SEARCH_CLOSE_AT_END)
            ksmbd_close_fd(work, dir_fp->volatile_id); <-- ksmbd_close_fd->fput->dput(), mntput() of path for ksmbd_vfs_dentry_open()
mmakassikis commented 1 year ago

@namjaejeon

I didn't realize ksmbd_close_fd() was indirectly calling path_put(). Disregard this patch as it is wrong.

Thanks for reviewing.