summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJann Horn <jannh@google.com>2024-12-04 17:26:19 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-12-27 14:02:18 +0100
commit93f08e5c393fa648a2e3e7ad2d37dd6a16cd726d (patch)
tree04305957d5459ceee22c2e8907a4149452de75f8 /drivers
parentff561987ff12b6a3233431ff659b5d332e22f153 (diff)
downloadlinux-93f08e5c393fa648a2e3e7ad2d37dd6a16cd726d.tar.gz
linux-93f08e5c393fa648a2e3e7ad2d37dd6a16cd726d.tar.bz2
linux-93f08e5c393fa648a2e3e7ad2d37dd6a16cd726d.zip
udmabuf: fix racy memfd sealing check
commit 9cb189a882738c1d28b349d4e7c6a1ef9b3d8f87 upstream. The current check_memfd_seals() is racy: Since we first do check_memfd_seals() and then udmabuf_pin_folios() without holding any relevant lock across both, F_SEAL_WRITE can be set in between. This is problematic because we can end up holding pins to pages in a write-sealed memfd. Fix it using the inode lock, that's probably the easiest way. In the future, we might want to consider moving this logic into memfd, especially if anyone else wants to use memfd_pin_folios(). Reported-by: Julian Orth <ju.orth@gmail.com> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219106 Closes: https://lore.kernel.org/r/CAG48ez0w8HrFEZtJkfmkVKFDhE5aP7nz=obrimeTgpD+StkV9w@mail.gmail.com Fixes: fbb0de795078 ("Add udmabuf misc device") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn <jannh@google.com> Acked-by: Joel Fernandes (Google) <joel@joelfernandes.org> Acked-by: Vivek Kasireddy <vivek.kasireddy@intel.com> Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20241204-udmabuf-fixes-v2-1-23887289de1c@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/dma-buf/udmabuf.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 614df433c451..c2e227762152 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -394,14 +394,19 @@ static long udmabuf_create(struct miscdevice *device,
goto err;
}
+ /*
+ * Take the inode lock to protect against concurrent
+ * memfd_add_seals(), which takes this lock in write mode.
+ */
+ inode_lock_shared(file_inode(memfd));
ret = check_memfd_seals(memfd);
- if (ret < 0) {
- fput(memfd);
- goto err;
- }
+ if (ret)
+ goto out_unlock;
ret = udmabuf_pin_folios(ubuf, memfd, list[i].offset,
list[i].size);
+out_unlock:
+ inode_unlock_shared(file_inode(memfd));
fput(memfd);
if (ret)
goto err;