Commit 12a4d42
committed
ALSA: rawmidi: Fix racy buffer resize under concurrent accesses
jira VULN-7721
cve CVE-2020-27786
commit-author Takashi Iwai <tiwai@suse.de>
commit c1f6e3c
The rawmidi core allows user to resize the runtime buffer via ioctl,
and this may lead to UAF when performed during concurrent reads or
writes: the read/write functions unlock the runtime lock temporarily
during copying form/to user-space, and that's the race window.
This patch fixes the hole by introducing a reference counter for the
runtime buffer read/write access and returns -EBUSY error when the
resize is performed concurrently against read/write.
Note that the ref count field is a simple integer instead of
refcount_t here, since the all contexts accessing the buffer is
basically protected with a spinlock, hence we need no expensive atomic
ops. Also, note that this busy check is needed only against read /
write functions, and not in receive/transmit callbacks; the race can
happen only at the spinlock hole mentioned in the above, while the
whole function is protected for receive / transmit callbacks.
Reported-by: butt3rflyh4ck <butterflyhuangxx@gmail.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/CAFcO6XMWpUVK_yzzCpp8_XP7+=oUpQvuBeCbMffEDkpe8jWrfg@mail.gmail.com
Link: https://lore.kernel.org/r/s5heerw3r5z.wl-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit c1f6e3c)
Signed-off-by: Pratham Patel <ppatel@ciq.com>1 parent 63c5b11 commit 12a4d42
2 files changed
+28
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
115 | 126 | | |
116 | 127 | | |
117 | 128 | | |
| |||
661 | 672 | | |
662 | 673 | | |
663 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
664 | 680 | | |
665 | 681 | | |
666 | 682 | | |
| |||
960 | 976 | | |
961 | 977 | | |
962 | 978 | | |
| 979 | + | |
963 | 980 | | |
964 | 981 | | |
| 982 | + | |
965 | 983 | | |
966 | 984 | | |
967 | 985 | | |
| |||
980 | 998 | | |
981 | 999 | | |
982 | 1000 | | |
983 | | - | |
984 | | - | |
985 | | - | |
| 1001 | + | |
| 1002 | + | |
986 | 1003 | | |
| 1004 | + | |
| 1005 | + | |
987 | 1006 | | |
988 | 1007 | | |
989 | 1008 | | |
990 | 1009 | | |
| 1010 | + | |
| 1011 | + | |
991 | 1012 | | |
992 | | - | |
| 1013 | + | |
993 | 1014 | | |
994 | 1015 | | |
995 | 1016 | | |
| |||
1283 | 1304 | | |
1284 | 1305 | | |
1285 | 1306 | | |
| 1307 | + | |
1286 | 1308 | | |
1287 | 1309 | | |
1288 | 1310 | | |
| |||
1314 | 1336 | | |
1315 | 1337 | | |
1316 | 1338 | | |
| 1339 | + | |
1317 | 1340 | | |
1318 | 1341 | | |
1319 | 1342 | | |
| |||
0 commit comments