803 Star 2.4K Fork 1.2K

GVPHuawei LiteOS / LiteOS

 / 详情

[Bug report] use-after-free by lwm2m_close()

已完成
创建于  
2021-01-06 06:32

该问题是怎么引起的?

The function lwm2m_close() will destroy all the information about lwm2m link. It calls the function prv_deleteServerList() to free the linked list contextP->serverList and the function prv_deleteTransactionList() to clear the linked list contextP->transactionList as shown in https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/lwm2m/core/liblwm2m.c?_from=gitee_search#L226. When the callback function prv_handleRegistrationReply() is called by the function prv_deleteTransactionList(), it tries to access the memory pointed by the pointer transacP->userData as shown in https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/lwm2m/core/registration.c?_from=gitee_search#L225. However, the pointer transacP->userData points to the memory server aligned by the function prv_register() as shown in https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/lwm2m/core/registration.c?_from=gitee_search#L318 and already freed by the function prv_deleteServerList() before the function prv_deleteTransactionList(). This will lead to a use-after-free fault.

重现步骤

Run the lwm2m demo project under client mode and use the bytes below as the input packet.
0x60, 0x45, 0x00, 0x07, 0xc0, 0xff, 0x77, 0x80, 0x72, 0x6c, 0x64

报错信息

Due to the fact that lacking efficient error checking mechanism, the developer or tester needs to check this fault by debugging.

评论 (1)

SilentDawn 创建了任务
SilentDawn 关联仓库设置为LiteOS/LiteOS
SilentDawn 修改了标题
SilentDawn 修改了描述
展开全部操作日志

Hi, dear SlientDawn, long time no see.
More details about lwm2m spec, pls refer to:
https://support.huaweicloud.com/intl/zh-cn/devg-IoT/iot_02_5024.html;

Actually, when the device call atiny_bind successfully, it will never return. Pls refer to:
https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/agent_tiny/atiny_lwm2m/agenttiny.c?_from=gitee_search#L428.

And the func lwm2m_close() is called by atiny_destroy():
https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/agent_tiny/atiny_lwm2m/agenttiny.c?_from=gitee_searchL349.

However, atiny_destroy() should not be executed because it is executed after atiny_bind():
https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/agent_tiny/atiny_lwm2m/agenttiny.c?_from=gitee_search#L455.

the callback func:prv_handleRegistrationReply() is registered in prv_register():
https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/lwm2m/core/registration.c?_from=gitee_search#L317.

the callback func:prv_handleRegistrationReply() is called in transaction_handleResponse():
https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/lwm2m/core/transaction.c?_from=gitee_search#L364.

and the func: transaction_remove(contextP, transacP) call lwm2m_free(transacP):
https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/lwm2m/core/transaction.c?_from=gitee_search#L366.

In conclusion, the situation you mentioned will not happen.

bing 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
C
1
https://gitee.com/LiteOS/LiteOS.git
git@gitee.com:LiteOS/LiteOS.git
LiteOS
LiteOS
LiteOS

搜索帮助