Re: [PATCH v2 2/3] smb/server: deny overwriting targets with non-POSIX opens

Namjae Jeon <[email protected]>
Newsgroups org.kernel.vger.linux-cifs
Message-ID <CAKYAXd-A2hup+WnYZj+AaVTzgZ9hHQgg8zKswtw=-VqStE6VFw@mail.gmail.com>
> +bool ksmbd_has_other_nonposix_open(struct dentry *dentry)
> +{
> +       struct ksmbd_file *fp;
> +       struct ksmbd_inode *ci;
> +       struct inode *inode = d_inode(dentry);
> +       bool ret = false;
> +
> +       if (!inode)
> +               return false;
> +
> +       ci = ksmbd_inode_lookup_lock(dentry);
The new check is limited to the target dentry's
ksmbd_inode->m_fp_list. Therefore, it does not cover a struct
ksmbd_file opened through another hardlink dentry, even though
file_inode(fp->filp) == d_inode(dentry). For example, if file2.link is
a hardlink to file2 and file2.link is opened with a non-POSIX context,
an overwrite rename of another file to file2 can miss that open
handle.
This appears to be an existing limitation rather than a regression
introduced by this patch. However, since this patch is intended to
reject overwrites when the target has a non-POSIX ksmbd_file...

> +       if (!ci)
> +               return false;
> +
> +       down_read(&ci->m_lock);
> +       list_for_each_entry(fp, &ci->m_fp_list, node) {
> +               if (READ_ONCE(fp->f_state) != FP_INITED)
> +                       continue;
> +               if (inode != file_inode(fp->filp))
> +                       continue;
> +               if (fp->is_posix_ctxt)
> +                       continue;
> +
> +               ret = true;
> +               break;
> +       }
> +       up_read(&ci->m_lock);
> +       ksmbd_inode_put(ci);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.