ANDROID: staging: ion: move buffer kmap from begin/end_cpu_access()
authorHridya Valsaraju <hridya@google.com>
Mon, 26 Jul 2021 03:49:06 +0000 (20:49 -0700)
committerPDO SCM Team <hudsoncm@motorola.com>
Mon, 8 Nov 2021 03:42:54 +0000 (21:42 -0600)
commitbbe661ab6ce7d7f950a51510945b499fbebd49dd
tree599d0781d297f49e399c9b1a99b2ace2da5062ee
parent10887969a11071ece522e6fdd0cc9121b1a637b6
ANDROID: staging: ion: move buffer kmap from begin/end_cpu_access()

Since dma_buf_begin/end_cpu_access() calls always used to bracket
dma_buf_kmap/kunmap calls, ION performed kmap/kunmap invocations for the
buffer during dma_buf_begin/end_cpu_access() calls and cached the
results with a kmap counter.
However, dma_buf_begin/end_cpu_access() invocations can be
triggered from the userspace using the DMA_BUF_IOC_SYNC ioctl as well.
This means that a mapping that was created by a device driver using by a
dma_buf_kmap() call or an ion_map_kernel() call could be unmapped
from userspace if a client accidentally(or maliciously) invoked
DMA_BUF_IOCTL_SYNC IOCTL with 'DMA_BUF_SYNC_END' argument since this
would inturn invoke dma_buf_end_cpu_access() which would then decrement
the kmap counter and invoke kunmap() when the counter gets to 0.

This patch moves the kmap/kunmap operations from the
begin/end_cpu_access() DMA-BUF ops to the map/unmap DMA-BUF ops to
prevent the issue.

Mot-CRs-fixed: (CR)
CVE-Fixed: CVE-2021-0929

Bug: 187527909
Change-Id: I00dc8eefefb1f3aab99e770f90d624011f7740f0
[hridya: minor conflicts during cherry-picking]
Signed-off-by: Hridya Valsaraju <hridya@google.com>
Signed-off-by: Gajjala Chakradhar <gajjalac@motorola.com>
Reviewed-on: https://gerrit.mot.com/2098202
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key
(cherry picked from commit fb16b88a7e0788e2e32bedd952883e7a8831c941)
drivers/staging/android/ion/ion.c