CVE-2018-19824漏洞学习

简介

在Linux内核4.19.6以前,本地用户能够经过在Sound / USB /card.c.的usb_audio_probe中错误处理一个恶意USB声音设备(没有接口)来利用ALSA驱动程序中的一个UAF。若是USB声卡报告0个接口,将触发一个错误条件,函数usb_audio_probe错误输出。在错误路径中,存在一个在空闲后使用的漏洞,即首先释放卡的内存对象,而后减小活动芯片的数量。将减量移动到atomic_dec之上能够修复UAF。linux

补丁分析

补丁在这里:https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/commit/?id=5f8cf712582617d523120df67d392059eaf2fc4bgit

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 2bfe4e8..a105947 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -682,9 +682,12 @@ static int usb_audio_probe(struct usb_interface *intf,
 
  __error:
     if (chip) {
+        /* chip->active is inside the chip->card object,
+         * decrement before memory is possibly returned.
+         */
+        atomic_dec(&chip->active);
         if (!chip->num_interfaces)
             snd_card_free(chip->card);
-        atomic_dec(&chip->active);
     }
     mutex_unlock(&register_mutex);
     return err;

只是将atomic_dec(&chip->active)这个函数移动了一个位置。UAF出在snd_card_free之中。这个漏洞貌似仍是比较容易理解,一般咱们编写程序的时候都会注意到,退出路径中,先减小索引,若是索引为0则释放对象。可是这里却能够直接进入释放阶段,只要chip->num_interfaces为0。根据这个函数的注释,在音频设备中若是有过个控制接口这个函数会被调用屡次。那这个意思就是应该当作USB总线上链接多个不一样的设备ide

相关文章
相关标签/搜索