[RFC PATCH samba] smbd: deny rename if the destination has non-POSIX opens
Ralph Boehme
slow at samba.org
Wed Aug 5 19:35:08 UTC 2026
On 8/5/26 3:31 PM, ChenXiaoSong wrote:
> From: ChenXiaoSong <chenxiaosong at kylinos.cn>
>
> Check the destination share mode entries with
> has_other_nonposix_opens() before replacing it, and return
> NT_STATUS_ACCESS_DENIED if a non-POSIX open exists.
thanks for looking into this!
I'm afraid though that the issue is more subtle then just adjusting the
check in that place.
In fact, back when I implemented Directory Leases, I added the full
logic to check for open files and possible H-leases on them on
- the src of the rename
- iirc also the parent of the src of the rename
- the parent of the dst
- and the dst
All that logic lives in a few levels avove rename_internals_fsp() inside
smbd_smb2_setinfo_lease_break_check().
The function that deals with the dst is
smbd_smb2_setinfo_rename_dst_check(). That one already correctly uses
has_other_nonposix_opens() while holding a lock on the locking.tdb
record of the destination.
The check with files_forall() inside rename_internals_fsp() is a clutch
that already check for opens in the same process, not globally. And we
can't expand it to be global, as that requires taking the lock on the
locking.tdb record which is prohibitted by the fact that we already have
the lck on the src when rename_internals_fsp() is called. Locking two
records simultaneously is not allowed in Samba, as it could lead to
deadlocks.
So I guess the best we can do is remove the redundant check altogether
from rename_internals_fsp() and rely on the correct logic from
smbd_smb2_setinfo_lease_break_check(). We have to live with the toctou
race window anyway, it just enlarges the window a bit, but only for the
case of open files by the same client. Opens from other clients, are not
detected anyway by the files_forall() as said above.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20260805/d77f49e3/OpenPGP_signature.sig>
More information about the samba-technical
mailing list