From: Paulo Alcantara <pc@manguebit.org>
To: ronnie sahlberg <ronniesahlberg@gmail.com>
Cc: Ralph Boehme <slow@samba.org>,
smfrench@gmail.com, Jean-Baptiste Denis <jbdenis@pasteur.fr>,
Frank Sorenson <sorenson@redhat.com>,
Olga Kornievskaia <okorniev@redhat.com>,
Benjamin Coddington <bcodding@redhat.com>,
Scott Mayhew <smayhew@redhat.com>,
linux-cifs@vger.kernel.org
Subject: Re: [PATCH v2] smb: client: fix data loss due to broken rename(2)
Date: Wed, 03 Sep 2025 17:55:04 -0300 [thread overview]
Message-ID: <2aabde07717d77556ef8a02a1716f881@manguebit.org> (raw)
In-Reply-To: <CAN05THQ0hGERkn+KVjbX_1z0AzZ4EeSBfjiQ_Ap=1+Ni4FGkQA@mail.gmail.com>
ronnie sahlberg <ronniesahlberg@gmail.com> writes:
> On Thu, 4 Sept 2025 at 06:28, Paulo Alcantara <pc@manguebit.org> wrote:
>>
>> ronnie sahlberg <ronniesahlberg@gmail.com> writes:
>>
>> > On Thu, 4 Sept 2025 at 05:55, ronnie sahlberg <ronniesahlberg@gmail.com> wrote:
>> >>
>> >> On Thu, 4 Sept 2025 at 04:46, Paulo Alcantara <pc@manguebit.org> wrote:
>> >> >
>> >> > Ralph Boehme <slow@samba.org> writes:
>> >> >
>> >> > > Hi Paulo,
>> >> > >
>> >> > > On 9/2/25 9:09 PM, Paulo Alcantara wrote:
>> >> > >> Ralph Boehme <slow@samba.org> writes:
>> >> > >>
>> >> > >>> Why not simply fail the rename instead of trying to implement some
>> >> > >>> clever but complex and error prone fallback?
>> >> > >>
>> >> > >> We're doing this for SMB1 for a very long time and haven't heard of any
>> >> > >> issues so far. I've got a "safer" version [1] that does everything a
>> >> > >> single compound request but then implemented this non-compound version
>> >> > >> due to an existing Azure bug that seems to limit the compound in 4
>> >> > >> commands, AFAICT. Most applications depend on such behavior working,
>> >> > >> which is renaming open files.
>> >> > >
>> >> > > maybe I'm barking of the wrong tree, but you *can* rename open files:
>> >> > >
>> >> > > $ bin/smbclient -U 'USER%PASS' //IP/C\$
>> >> > > smb: \> cd Users\administrator.WINCLUSTER\Desktop\
>> >> > > smb: \Users\administrator.WINCLUSTER\Desktop\> open
>> >> > > t-ph-oplock-b-downgraded-s.cab
>> >> > > open file
>> >> > > \Users\administrator.WINCLUSTER\Desktop\t-ph-oplock-b-downgraded-s.cab:
>> >> > > for read/write fnum 1
>> >> > > smb: \Users\administrator.WINCLUSTER\Desktop\> rename
>> >> > > t-ph-oplock-b-downgraded-s.cab renamed
>> >> > > smb: \Users\administrator.WINCLUSTER\Desktop\>
>> >> > >
>> >> > > ...given the open is with SHARE_DELETE (had to tweak smbclient to
>> >> > > actually allow that).
>> >> >
>> >> > Interesting.
>> >> >
>> >> > cifs.ko will get STATUS_ACCESS_DENIED when attempting to rename the open
>> >> > file. The file was open with SHARE_READ|SHARE_WRITE|SHARE_DELETE, BTW.
>> >> >
>> >> > Also, note that cifs.ko will not reuse the open handle, rather it will
>> >> > send a compound request of create+set_info(rename)+close to the file
>> >> > which will fail with STATUS_ACCESS_DENIED.
>> >> >
>> >> > What am I missing?
>> >> >
>> >> > > If the rename destination is open and the server rightly fails the
>> >> > > rename for that reason, then masking that error is a mistake imho.
>> >> > >
>> >> > > When doing
>> >> > >
>> >> > > $ mv a b
>> >> > >
>> >> > > the user asked to rename a, he did NOT ask to rename b which becomes
>> >> > > important, because if you do
>> >> > >
>> >> > > rename("b", ".renamehackXXXX")
>> >> > >
>> >> > > under the hood and then reattempt the rename
>> >> > >
>> >> > > rename("a", "b")
>> >> > >
>> >> > > and then the user subsequently does
>> >> > >
>> >> > > $ mv b ..
>> >> > > $ cd ..
>> >> > > $ rmdir DIR
>> >> > >
>> >> > > where DIR is the directory all of the above was performed inside, the
>> >> > > rmdir will fail with ENOTEMPTY and *now* the user is confused.
>> >> >
>> >> > Yes, I understand your point. That's really confusing.
>> >> >
>> >> > How can we resolve above cases without performing the silly renames
>> >> > then?
>> >> >
>> >>
>> >> I think you can't. CIFS, without the posix extensions, is basically
>> >> not posix and never will be.
>> >> You can make it close but it will never be perfect and you will have
>> >> to decide on how/what posix semantics you need to give up.
>> >>
>> >> What compounds the issue is that cifs on linux (without the posix
>> >> extensions) will also always be a second class citizen.
>> >> Genuine windows clients own this protocol and they expect their own
>> >> non-posix semantics for their vfs, so you can't do anything that
>> >> impacts windows clients, they are the first class citizen here.
>> >>
>> >> The two main issues I see with the silly renames are the "-ENOTEMPTY"
>> >> error when trying to delete the "empty" directory, but also
>> >> that you can not hide them from windows clients. And what happens if
>> >> the windows clients start accessing them?
>> >>
>> >> I think the only real solution is to say "if you need posix semantics
>> >> then you need to use the posix extensions".
>> >
>> > Another potential issue is about QUERY_INFO.
>> > Many of the information classes in FSCC return the filename as as part
>> > of the data.
>> > What filename should be returned for a silly renamed file?
>> >
>> > Maybe it doesn't matter but maybe there is some obscure windows
>> > application out there that do care and gets surprised.
>>
>> I don't think that matters as file deletion is pending on the server and
>> QUERY_INFO won't work.
>>
>> What am I missing?
>
> You missed nothing. I didn't think it through.
>
> But another potential issue is the possibility of a DOS from malicious
> windows clients.
> If the files are "hidden" from linux clients.
> How would a linux client recover if a maliciious windows client just
> creates an ordinary file with a filename that matches the "silly
> rename prefix".
> The file can not be seen or deleted from linux clients and thus the
> directory becomes undeletable too?
Yes, that's a good point. Thanks!
One way to solve that would be doing something similar as AFS currently
does, which is finding the next non-existing silly filename that could
used by calling lookup_noperm() and then incrementing @sillycounter
until it gets the first negative dentry.
next prev parent reply other threads:[~2025-09-03 20:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-02 16:54 [PATCH v2] smb: client: fix data loss due to broken rename(2) Paulo Alcantara
2025-09-02 18:57 ` Ralph Boehme
[not found] ` <CAH2r5mvqJXfgQwKLSWrfBDw8Rc88ys8a_cWB5DtD19HSDmFn5w@mail.gmail.com>
2025-09-02 19:05 ` Ralph Boehme
2025-09-02 19:39 ` Paulo Alcantara
2025-09-03 15:48 ` Ralph Boehme
2025-09-03 16:19 ` Paulo Alcantara
2025-09-04 6:04 ` Ralph Boehme
2025-09-02 19:09 ` Paulo Alcantara
2025-09-03 16:10 ` Ralph Boehme
2025-09-03 18:45 ` Paulo Alcantara
2025-09-03 19:55 ` ronnie sahlberg
2025-09-03 20:10 ` ronnie sahlberg
2025-09-03 20:28 ` Paulo Alcantara
2025-09-03 20:44 ` ronnie sahlberg
2025-09-03 20:55 ` Paulo Alcantara [this message]
2025-09-03 20:18 ` Paulo Alcantara
2025-09-03 19:13 ` Paulo Alcantara
[not found] ` <notmuch-sha1-4fd369d43684b0739d61e9e931e63ca8c7e2a82c>
2025-09-02 19:10 ` 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=2aabde07717d77556ef8a02a1716f881@manguebit.org \
--to=pc@manguebit.org \
--cc=bcodding@redhat.com \
--cc=jbdenis@pasteur.fr \
--cc=linux-cifs@vger.kernel.org \
--cc=okorniev@redhat.com \
--cc=ronniesahlberg@gmail.com \
--cc=slow@samba.org \
--cc=smayhew@redhat.com \
--cc=smfrench@gmail.com \
--cc=sorenson@redhat.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.