Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cifs: allow unlock flock and OFD lock across fork

Since commit d0677992d2af ("cifs: add support for flock") added
support for flock, LTP/flock03[1] testcase started to fail.

This testcase is testing flock lock and unlock across fork.
The parent locks file and starts the child process, in which
it unlock the same fd and lock the same file with another fd
again. All the lock and unlock operation should succeed.

Now the child process does not actually unlock the file, so
the following lock fails. Fix this by allowing flock and OFD
lock go through the unlock routine, not skipping if the unlock
request comes from another process.

Patch has been tested by LTP/xfstests on samba and Windows
server, v3.11, with or without cache=none mount option.

[1] https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/flock/flock03.c
Signed-off-by: Murphy Zhou <jencce.kernel@gmail.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Acked-by: Pavel Shilovsky <pshilov@microsoft.com>

authored by

Murphy Zhou and committed by
Steve French
0667059d c7e9f78f

+6 -1
+6 -1
fs/cifs/smb2file.c
··· 152 152 (li->offset + li->length)) 153 153 continue; 154 154 if (current->tgid != li->pid) 155 - continue; 155 + /* 156 + * flock and OFD lock are associated with an open 157 + * file description, not the process. 158 + */ 159 + if (!(flock->fl_flags & (FL_FLOCK | FL_OFDLCK))) 160 + continue; 156 161 if (cinode->can_cache_brlcks) { 157 162 /* 158 163 * We can cache brlock requests - simply remove a lock