@@ -868,6 +868,21 @@ static bool posix_locks_conflict(struct file_lock *caller_fl,
868
868
return locks_conflict (caller_fl , sys_fl );
869
869
}
870
870
871
+ /* Determine if lock sys_fl blocks lock caller_fl. Used on xx_GETLK
872
+ * path so checks for additional GETLK-specific things like F_UNLCK.
873
+ */
874
+ static bool posix_test_locks_conflict (struct file_lock * caller_fl ,
875
+ struct file_lock * sys_fl )
876
+ {
877
+ /* F_UNLCK checks any locks on the same fd. */
878
+ if (caller_fl -> fl_type == F_UNLCK ) {
879
+ if (!posix_same_owner (caller_fl , sys_fl ))
880
+ return false;
881
+ return locks_overlap (caller_fl , sys_fl );
882
+ }
883
+ return posix_locks_conflict (caller_fl , sys_fl );
884
+ }
885
+
871
886
/* Determine if lock sys_fl blocks lock caller_fl. FLOCK specific
872
887
* checking before calling the locks_conflict().
873
888
*/
@@ -901,7 +916,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
901
916
retry :
902
917
spin_lock (& ctx -> flc_lock );
903
918
list_for_each_entry (cfl , & ctx -> flc_posix , fl_list ) {
904
- if (!posix_locks_conflict (fl , cfl ))
919
+ if (!posix_test_locks_conflict (fl , cfl ))
905
920
continue ;
906
921
if (cfl -> fl_lmops && cfl -> fl_lmops -> lm_lock_expirable
907
922
&& (* cfl -> fl_lmops -> lm_lock_expirable )(cfl )) {
@@ -2207,7 +2222,8 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock)
2207
2222
if (fl == NULL )
2208
2223
return - ENOMEM ;
2209
2224
error = - EINVAL ;
2210
- if (flock -> l_type != F_RDLCK && flock -> l_type != F_WRLCK )
2225
+ if (cmd != F_OFD_GETLK && flock -> l_type != F_RDLCK
2226
+ && flock -> l_type != F_WRLCK )
2211
2227
goto out ;
2212
2228
2213
2229
error = flock_to_posix_lock (filp , fl , flock );
@@ -2414,7 +2430,8 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 *flock)
2414
2430
return - ENOMEM ;
2415
2431
2416
2432
error = - EINVAL ;
2417
- if (flock -> l_type != F_RDLCK && flock -> l_type != F_WRLCK )
2433
+ if (cmd != F_OFD_GETLK && flock -> l_type != F_RDLCK
2434
+ && flock -> l_type != F_WRLCK )
2418
2435
goto out ;
2419
2436
2420
2437
error = flock64_to_posix_lock (filp , fl , flock );
0 commit comments