Skip to content

Commit 0a40db9

Browse files
Joel Fernandesgregkh
authored andcommitted
staging: android: ashmem: Fix lockdep issue during llseek
commit cb57469c9573f6018cd1302953dd45d6e05aba7b upstream. ashmem_mutex create a chain of dependencies like so: (1) mmap syscall -> mmap_sem -> (acquired) ashmem_mmap ashmem_mutex (try to acquire) (block) (2) llseek syscall -> ashmem_llseek -> ashmem_mutex -> (acquired) inode_lock -> inode->i_rwsem (try to acquire) (block) (3) getdents -> iterate_dir -> inode_lock -> inode->i_rwsem (acquired) copy_to_user -> mmap_sem (try to acquire) There is a lock ordering created between mmap_sem and inode->i_rwsem causing a lockdep splat [2] during a syzcaller test, this patch fixes the issue by unlocking the mutex earlier. Functionally that's Ok since we don't need to protect vfs_llseek. [1] https://patchwork.kernel.org/patch/10185031/ [2] https://lkml.org/lkml/2018/1/10/48 Acked-by: Todd Kjos <[email protected]> Cc: Arve Hjonnevag <[email protected]> Cc: [email protected] Reported-by: [email protected] Signed-off-by: Joel Fernandes <[email protected]> Acked-by: Greg Hackmann <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8d5ac33 commit 0a40db9

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/staging/android/ashmem.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,23 @@ static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin)
330330
mutex_lock(&ashmem_mutex);
331331

332332
if (asma->size == 0) {
333-
ret = -EINVAL;
334-
goto out;
333+
mutex_unlock(&ashmem_mutex);
334+
return -EINVAL;
335335
}
336336

337337
if (!asma->file) {
338-
ret = -EBADF;
339-
goto out;
338+
mutex_unlock(&ashmem_mutex);
339+
return -EBADF;
340340
}
341341

342+
mutex_unlock(&ashmem_mutex);
343+
342344
ret = vfs_llseek(asma->file, offset, origin);
343345
if (ret < 0)
344-
goto out;
346+
return ret;
345347

346348
/** Copy f_pos from backing file, since f_ops->llseek() sets it */
347349
file->f_pos = asma->file->f_pos;
348-
349-
out:
350-
mutex_unlock(&ashmem_mutex);
351350
return ret;
352351
}
353352

0 commit comments

Comments
 (0)