mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 03:27:44 -04:00
locks,lockd: fix race in nlmsvc_testlock
posix_test_lock() returns a pointer to a struct file_lock which is unprotected and can be removed while in use by the caller. Move the conflicting lock from the return to a parameter, and copy the conflicting lock. In most cases the caller ends up putting the copy of the conflicting lock on the stack. On i386, sizeof(struct file_lock) appears to be about 100 bytes. We're assuming that's reasonable. Signed-off-by: Andy Adamson <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
This commit is contained in:
parent
2e0af86f61
commit
8dc7c3115b
5 changed files with 28 additions and 27 deletions
|
|
@ -376,8 +376,6 @@ u32
|
|||
nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
|
||||
struct nlm_lock *conflock)
|
||||
{
|
||||
struct file_lock *fl;
|
||||
|
||||
dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n",
|
||||
file->f_file->f_dentry->d_inode->i_sb->s_id,
|
||||
file->f_file->f_dentry->d_inode->i_ino,
|
||||
|
|
@ -385,14 +383,14 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
|
|||
(long long)lock->fl.fl_start,
|
||||
(long long)lock->fl.fl_end);
|
||||
|
||||
if ((fl = posix_test_lock(file->f_file, &lock->fl)) != NULL) {
|
||||
if (posix_test_lock(file->f_file, &lock->fl, &conflock->fl)) {
|
||||
dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n",
|
||||
fl->fl_type, (long long)fl->fl_start,
|
||||
(long long)fl->fl_end);
|
||||
conflock->fl.fl_type,
|
||||
(long long)conflock->fl.fl_start,
|
||||
(long long)conflock->fl.fl_end);
|
||||
conflock->caller = "somehost"; /* FIXME */
|
||||
conflock->oh.len = 0; /* don't return OH info */
|
||||
conflock->svid = fl->fl_pid;
|
||||
conflock->fl = *fl;
|
||||
conflock->svid = conflock->fl.fl_pid;
|
||||
return nlm_lck_denied;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue