From: Al Viro <viro@zeniv.linux.org.uk>
To: Paulo Alcantara <pc@manguebit.org>
Cc: brauner@kernel.org, smfrench@gmail.com,
David Howells <dhowells@redhat.com>,
linux-fsdevel@vger.kernel.org, linux-cifs@vger.kernel.org
Subject: Re: [RFC PATCH] smb: client: add support for O_TMPFILE
Date: Sat, 4 Apr 2026 02:52:53 +0100 [thread overview]
Message-ID: <20260404015253.GP3836593@ZenIV> (raw)
In-Reply-To: <20260401011153.1757515-1-pc@manguebit.org>
On Tue, Mar 31, 2026 at 10:11:53PM -0300, Paulo Alcantara wrote:
> d_drop(direntry);
> - d_add(direntry, newinode);
> -
> + inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
> + if (oflags & O_TMPFILE) {
> + set_nlink(newinode, 0);
> + mark_inode_dirty(newinode);
> + d_instantiate(direntry, newinode);
> + } else {
> + d_add(direntry, newinode);
> + }
What d_unhashed(dentry) is going to be when we arrive to that thing
with O_TMPFILE?
> +static void cifs_d_mark_tmpfile(struct file *file,
> + const unsigned char *name,
> + size_t namelen)
> +{
> + struct dentry *dentry = file->f_path.dentry;
> +
> + BUG_ON(dentry->d_name.name != dentry->d_shortname.string ||
> + !hlist_unhashed(&dentry->d_u.d_alias) ||
> + !d_unlinked(dentry) ||
> + namelen > DNAME_INLINE_LEN - 1);
> + spin_lock(&dentry->d_parent->d_lock);
> + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
> + dentry->__d_name.len = sprintf(dentry->d_shortname.string, "%.*s",
> + (int)namelen, name);
That's one hell of an odd way to spell that... What's wrong with using union
shortname_store for an argument? Just memchr() for '\0' to verify it's there
and use the result to calculate the length and plain assignment to d_shortname
for copying...
And in any case, that !hlist_unhashed(....) in there is d_really_is_positive().
> +static int set_tmpfile_name(struct file *file)
> +{
> + struct dentry *dentry = file->f_path.dentry;
> + unsigned char name[CIFS_TMPNAME_LEN + 1];
> + struct dentry *sdentry = NULL;
> +
> + do {
> + dput(sdentry);
> + scnprintf(name, sizeof(name),
> + CIFS_TMPNAME_PREFIX "%0*x",
> + CIFS_TMPNAME_COUNTER_LEN,
> + atomic_inc_return(&cifs_tmpcounter));
> + sdentry = lookup_noperm_unlocked(&QSTR(name), dentry->d_parent);
> + if (IS_ERR(sdentry))
> + return -EBUSY;
> + } while (!d_is_negative(sdentry));
> + dput(sdentry);
That looks racy. Checking it doesn't exist at the moment is fine, but what if
it's created right after that lookup? You are not holding any locks, so even
the same-client race (with plain create()) is possible...
> + cifs_d_mark_tmpfile(file, name, sizeof(name) - 1);
> + return 0;
> +}
next prev parent reply other threads:[~2026-04-04 1:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 1:11 [RFC PATCH] smb: client: add support for O_TMPFILE Paulo Alcantara
2026-04-04 1:52 ` Al Viro [this message]
2026-04-04 15:54 ` 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=20260404015253.GP3836593@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=dhowells@redhat.com \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=pc@manguebit.org \
--cc=smfrench@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox