Skip to contentSkip to conversation

Sequence of actions resulting in data loss

Samba Ralph Boehme 3 participants 7 messages Aug 1, 2025 – Aug 7, 2025 13 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

...adding linux-cifs to the loop...

Quoted 6 lines · Jean-Baptiste Denis via samba
$ make test
echo 'new script version' > myscript.replacement
./reproducer
sleep for 5 seconds...
(main) failed to rename myscript.replacement to myscript: No such file or directory
(readf) failed to open file './myscript': No such file or directory

so it seems to be something in the cifs kernel client doing this. Can you somewhere post a network trace that covers this?

@Steve: do you have some fallback logig in the client that is triggered if a rename fails with STATUS_ACCESS_DENIED and then removed the (existing) rename destination?

Thanks!
-slow

#14 lore raw
Quoted 7 lines · Jean-Baptiste Denis
Quoted 2 lines · Ralph Boehme

so it seems to be something in the cifs kernel client doing this. Can you somewhere post a network trace that covers this?

Here it is:

https://dl.pasteur.fr/fop/aAxGNfJR/file_delete_reproducer_c.pcap

yeah, it seems to be the cifs kernel client.

@Steve: is that really what you want to do in this case? Just delete the rename destination? The application didn't request this...

-slow

Signature · 4 lines
SerNet Samba Team Lead https://sernet.de/
Samba Team Member      https://samba.org/
Samba Support and Dev  https://samba.plus/services/
SAMBA+ packages        https://samba.plus/products/samba
#15 lore raw
Quoted 7 lines · Ralph Boehme
Quoted 6 lines · Jean-Baptiste Denis
Quoted 1 line · Ralph Boehme

so it seems to be something in the cifs kernel client doing this. Can you somewhere

 > post a network trace that covers this?

Here it is:

Quoted 8 lines
Quoted 1 line

https://dl.pasteur.fr/fop/aAxGNfJR/file_delete_reproducer_c.pcap

yeah, it seems to be the cifs kernel client.

@Steve: is that really what you want to do in this case? Just delete the rename destination? The application didn't request this...

-slow

If I understand correctly, SMB has no atomic operation to replace/overwrite a file through a SetInfo FILE_INFO/SMB2_FILE_RENAME_INFO operation, so it's accomplished by the two-step process of 1) removing the target file; and 2) renaming the source filename to the target filename.

However, while a file is held open, SMB prevents immediate deletion of the file, and instead sets a 'Delete on Close' flag; the file is later deleted when all open files have been closed.

With this reproducer, executing 'bash X.sh' opens the file, and keeps it open until the script exits; since 'X.sh' sleeps 5 seconds, the file is still open when 'reproducer2' executes 'mv' one second later.

Here, the client fails to simply rename the file, since it still exists:

59    1.163170722    Create Request File: x;SetInfo Request FILE_INFO/SMB2_FILE_RENAME_INFO NewName:X.sh;Close Request 63    1.166060791    Create Response File: x;SetInfo Response, Error: STATUS_ACCESS_DENIED;Close Response 65    1.166444945    Create Request File: x;SetInfo Request FILE_INFO/SMB2_FILE_RENAME_INFO NewName:X.sh;Close Request 66    1.168169687    Create Response File: x;SetInfo Response, Error: STATUS_ACCESS_DENIED;Close Response 67    1.168425699    Create Request File: x;SetInfo Request FILE_INFO/SMB2_FILE_RENAME_INFO NewName:X.sh;Close Request 68    1.170065571    Create Response File: x;SetInfo Response, Error: STATUS_ACCESS_DENIED;Close Response 69    1.170309883    Create Request File: x;SetInfo Request FILE_INFO/SMB2_FILE_RENAME_INFO NewName:X.sh;Close Request 70    1.171888290    Create Response File: x;SetInfo Response, Error: STATUS_ACCESS_DENIED;Close Response

so the client has to fall back to the Remove+Rename sequence:

the Remove:
71    1.172324565    Create Request File: X.sh;Close Request
    Create Request (0x05)
        Create Options: 0x00201000
            .... .... .... .... ...1 .... .... .... = Delete On Close: The file should be deleted when it is closed 72    1.174431365    Create Response File: X.sh;Close Response

the Rename:
73      1.174738312     Create Request File: x;SetInfo Request FILE_INFO/SMB2_FILE_RENAME_INFO NewName:X.sh;Close Request 74      1.176391700     Create Response File: x;SetInfo Response, Error: STATUS_DELETE_PENDING;Close Response

So the client succeeded in setting the 'Delete on Close' flag to remove the file, but another process still has the file open, so the file was not actually removed yet.

Four-ish seconds later, 'sleep 5' completes, 'X.sh' exits, the client closes the file:
79      5.118570743     Close Request File: X.sh
80      5.119961726     Close Response

and the file is finally deleted on the server.

'reproducer2.sh' then wakes, and executes 'cat X.sh', which now fails due to the file removal actually completing:

88      5.130503738     Create Request File: X.sh
89      5.131341391     Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND

Unfortunately, the end result is that the 'mv' fails, the target is removed, and the source file still exists with its original name.

With the SMB semantics, I don't think there's a way around this condition.  "Rename & overwrite existing target name" isn't atomic, there's no equivalent to the nfs 'silly-rename' of the target filename, and there's no "Oh, nevermind, unset that 'Delete on Close' flag" to backtrack the removal (and if there was, we couldn't guarantee that we're unsetting the flag that only *we* set).

Frank

Signature · 4 lines
Frank Sorenson
[email protected]
Principal Software Maintenance Engineer, filesystems
Red Hat
#16 lore raw
Quoted 2 lines · Frank Sorenson
Quoted 1 line

If I understand correctly, SMB has no atomic operation to replace/

overwrite a file through a SetInfo FILE_INFO/SMB2_FILE_RENAME_INFO operation,

it has.

Quoted 1 line

so it's accomplished by the two-step process of 1) removing the target file; and 2) renaming the source filename to the target filename.

no. This is not needed.

-slow

Signature · 4 lines
SerNet Samba Team Lead https://sernet.de/
Samba Team Member      https://samba.org/
Samba Support and Dev  https://samba.plus/services/
SAMBA+ packages        https://samba.plus/products/samba
#17 lore raw
Quoted 4 lines · Ralph Boehme
Quoted 2 lines · Frank Sorenson
Quoted 1 line

If I understand correctly, SMB has no atomic operation to replace/

overwrite a file through a SetInfo FILE_INFO/SMB2_FILE_RENAME_INFO operation,

Quoted 8 lines

it has.

Quoted 1 line

so it's accomplished by the two-step process of 1) removing the target file; and 2) renaming the source filename to the target filename.

no. This is not needed.

-slow

Okay, thanks for correcting me.

Signature · 4 lines
Frank Sorenson
[email protected]
Principal Software Maintenance Engineer, filesystems
Red Hat

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 9 lines · Michael Tokarev
Quoted 8 lines · Ralph Boehme via samba
Quoted 4 lines · Jean-Baptiste Denis via samba

Sorry about that and thank you for warning me.

pcap: https://dl.pasteur.fr/fop/vkuc87yJ/file_delete_reproducer.pcap.zst
reproducer: https://dl.pasteur.fr/fop/doQKcwvv/reproducer3.sh

looks like the client is doing it:

Quoted 8 lines
Quoted 5 lines

after the server rightly refuses the rename in packets 102-109 (the client tries multiple times), in packet 110 the client it sets delete- on-close on the the X.sh and a bit later after the last open handle to X.sh is closed, the server rightly deletes the file.

The deletion might be done by the mv command or it might be some code in the cifs kernel client triggered by the rename failure.

I guess the next step would be to write a minimal C POSIX programm that replicates this to have full control over the application. If that still fails it must be something in the cifs client in the kernel.

BTW, this is exactly the scenario which I reported back in Mar-2024,
https://lists.samba.org/archive/samba/2024-March/248344.html

tell Steve! :)

@Steve: are you aware of this issue?

Cheers!
-slow

Signature · 4 lines
SerNet Samba Team Lead https://sernet.de/
Samba Team Member      https://samba.org/
Samba Support and Dev  https://samba.plus/services/
SAMBA+ packages        https://samba.plus/products/samba