Commit 0ed08fa
HID: usbhid: Fix race between usbhid_close() and usbhid_stop()
The syzbot fuzzer discovered a bad race between in the usbhid driver
between usbhid_stop() and usbhid_close(). In particular,
usbhid_stop() does:
usb_free_urb(usbhid->urbin);
...
usbhid->urbin = NULL; /* don't mess up next start */
and usbhid_close() does:
usb_kill_urb(usbhid->urbin);
with no mutual exclusion. If the two routines happen to run
concurrently so that usb_kill_urb() is called in between the
usb_free_urb() and the NULL assignment, it will access the
deallocated urb structure -- a use-after-free bug.
This patch adds a mutex to the usbhid private structure and uses it to
enforce mutual exclusion of the usbhid_start(), usbhid_stop(),
usbhid_open() and usbhid_close() callbacks.
Reported-and-tested-by: syzbot+7bf5a7b0f0a1f9446f4c@syzkaller.appspotmail.com
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: <stable@vger.kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>1 parent b43f977 commit 0ed08fa
2 files changed
Lines changed: 30 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
| 685 | + | |
| 686 | + | |
685 | 687 | | |
686 | 688 | | |
687 | | - | |
688 | | - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
689 | 693 | | |
690 | 694 | | |
691 | 695 | | |
692 | 696 | | |
693 | 697 | | |
694 | | - | |
| 698 | + | |
| 699 | + | |
695 | 700 | | |
696 | 701 | | |
697 | 702 | | |
| |||
725 | 730 | | |
726 | 731 | | |
727 | 732 | | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
728 | 736 | | |
729 | 737 | | |
730 | 738 | | |
731 | 739 | | |
732 | 740 | | |
733 | 741 | | |
734 | 742 | | |
| 743 | + | |
| 744 | + | |
735 | 745 | | |
736 | 746 | | |
737 | 747 | | |
| |||
743 | 753 | | |
744 | 754 | | |
745 | 755 | | |
746 | | - | |
747 | | - | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
748 | 761 | | |
749 | | - | |
750 | | - | |
751 | | - | |
| 762 | + | |
752 | 763 | | |
753 | 764 | | |
754 | 765 | | |
| |||
1057 | 1068 | | |
1058 | 1069 | | |
1059 | 1070 | | |
| 1071 | + | |
| 1072 | + | |
1060 | 1073 | | |
1061 | 1074 | | |
1062 | 1075 | | |
| |||
1177 | 1190 | | |
1178 | 1191 | | |
1179 | 1192 | | |
| 1193 | + | |
| 1194 | + | |
1180 | 1195 | | |
1181 | 1196 | | |
1182 | 1197 | | |
| |||
1187 | 1202 | | |
1188 | 1203 | | |
1189 | 1204 | | |
| 1205 | + | |
1190 | 1206 | | |
1191 | 1207 | | |
1192 | 1208 | | |
| |||
1202 | 1218 | | |
1203 | 1219 | | |
1204 | 1220 | | |
| 1221 | + | |
| 1222 | + | |
1205 | 1223 | | |
1206 | 1224 | | |
1207 | 1225 | | |
| |||
1222 | 1240 | | |
1223 | 1241 | | |
1224 | 1242 | | |
| 1243 | + | |
| 1244 | + | |
1225 | 1245 | | |
1226 | 1246 | | |
1227 | 1247 | | |
| |||
1382 | 1402 | | |
1383 | 1403 | | |
1384 | 1404 | | |
| 1405 | + | |
1385 | 1406 | | |
1386 | 1407 | | |
1387 | 1408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
0 commit comments