【NFC】CVE-2018-9585_nfc_ncif_proc_get_routing未检测长度越界读写

漏洞原理总结:在函数nfc_ncif_proc_get_routing()里,直接获取数据作为长度进行数组拷贝,读取的类型是uint8_t,最大是255 ,拷贝的数组定义长度125,直接溢出

官方描述:In nfc_ncif_proc_get_routing of nfc_ncif.cc, there is a possible out of bounds write due to a missing bounds check. This could lead to local escalation of privilege with no additional execution privileges needed. User interaction is not needed for exploitation.

官方描述翻译:函数nfc_ncif.cc - nfc_ncif_proc_get_routing()里,因为缺少边界检查,存在一个越界写,这可以造成提权并且无需额外的执行权限,利用这个漏洞也不需要用户交互

CVE
参考编号
类型
严重程度
已更新的 AOSP 版本

CVE-2018-9585

A-117554809

EoP

7.0、7.1.1、7.1.2、8.0、8.1、9

补丁

  • https://android.googlesource.com/platform/system/nfc/+/71764b791f262491e3f628c14ce3949863dd6058

Prevent OOB error in nfc_ncif_proc_get_routing()

Test: Tag reading; Card Emulation
Bug: 117554809
Change-Id: Ib49af2eadf870f030a6cddeec390dc498bd5078c
(cherry picked from commit ded496ea745656018dda505c23726b4304180c38)
diff --git a/src/nfc/nfc/nfc_ncif.cc b/src/nfc/nfc/nfc_ncif.cc
index 93666e0..6d6607d 100644
--- a/src/nfc/nfc/nfc_ncif.cc
+++ b/src/nfc/nfc/nfc_ncif.cc
@@ -25,6 +25,7 @@
  ******************************************************************************/
 #include <android-base/stringprintf.h>
 #include <base/logging.h>
+#include <log/log.h>
 #include <metricslogger/metrics_logger.h>
 
 #include "nfc_target.h"
@@ -1235,8 +1236,13 @@
       for (yy = 0; yy < evt_data.num_tlvs; yy++) {
         tl = *(p + 1);
         tl += NFC_TL_SIZE;
-        STREAM_TO_ARRAY(pn, p, tl);
         evt_data.tlv_size += tl;
+        if (evt_data.tlv_size > NFC_MAX_EE_TLV_SIZE) {
+          android_errorWriteLog(0x534e4554, "117554809");
+          LOG(ERROR) << __func__ << "Invalid data format";
+          return;
+        }
+        STREAM_TO_ARRAY(pn, p, tl);
         pn += tl;
       }
       tNFC_RESPONSE nfc_response;

入口简单的取值判断分支,最后调用到nci_proc_rf_management_ntf()

获取op_code,当op_codeNCI_MSG_RF_GET_ROUTING时,调用nfc_ncif_proc_get_routing(),传入的缓冲区指针指向p[3]len字段为p[2],这俩参数未做判断

获取的tlp[8],然后将tl加2,tl的类型是uint8_t,最大是255,加上2之后就是257evt_data.param_tlvs定义的长度为125,所以拷贝数组的时候直接溢出

补丁所做的就是在拷贝前做好evt_data.tlv_size的判断,这个字段表示当前已经拷贝的长度

Last updated