]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.13.15/usb-gadget-f_fs-fix-use-after-free-in-ffs_free_inst.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.13.15 / usb-gadget-f_fs-fix-use-after-free-in-ffs_free_inst.patch
CommitLineData
a8f08d76
GKH
1From cdafb6d8b8da7fde266f79b3287ac221aa841879 Mon Sep 17 00:00:00 2001
2From: Andrew Gabbasov <andrew_gabbasov@mentor.com>
3Date: Wed, 8 Nov 2017 10:13:15 -0700
4Subject: usb: gadget: f_fs: Fix use-after-free in ffs_free_inst
5
6From: Andrew Gabbasov <andrew_gabbasov@mentor.com>
7
8commit cdafb6d8b8da7fde266f79b3287ac221aa841879 upstream.
9
10KASAN enabled configuration reports an error
11
12BUG: KASAN: use-after-free in ffs_free_inst+... [usb_f_fs] at addr ...
13Write of size 8 by task ...
14
15This is observed after "ffs-test" is run and interrupted. If after that
16functionfs is unmounted and g_ffs module is unloaded, that use-after-free
17occurs during g_ffs module removal.
18
19Although the report indicates ffs_free_inst() function, the actual
20use-after-free condition occurs in _ffs_free_dev() function, which
21is probably inlined into ffs_free_inst().
22
23This happens due to keeping the ffs_data reference in device structure
24during functionfs unmounting, while ffs_data itself is freed as no longer
25needed. The fix is to clear that reference in ffs_closed() function,
26which is a counterpart of ffs_ready(), where the reference is stored.
27
28Fixes: 3262ad824307 ("usb: gadget: f_fs: Stop ffs_closed NULL pointer dereference")
29Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
30Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
31Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
32Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33
34---
35 drivers/usb/gadget/function/f_fs.c | 1 +
36 1 file changed, 1 insertion(+)
37
38--- a/drivers/usb/gadget/function/f_fs.c
39+++ b/drivers/usb/gadget/function/f_fs.c
40@@ -3669,6 +3669,7 @@ static void ffs_closed(struct ffs_data *
41 goto done;
42
43 ffs_obj->desc_ready = false;
44+ ffs_obj->ffs_data = NULL;
45
46 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) &&
47 ffs_obj->ffs_closed_callback)