Rust下的二进制漏洞 CVE-2024-27284 分析

Rust下的二进制漏洞 CVE-2024-27284 分析

Rust被誉为 【能够规避内存漏洞】的语言,在这几年收到很多开发者喜爱。所以在这个语言下能出现的UAF漏洞,自然也有价值研究一下。本文就一个常见开源库中发现的UAF漏洞进行分析。

漏洞背景

漏洞本身来自一个叫做Casandra-rs的开源库。

Cassandra 是一个开源的分布式数据库管理系统,由 Apache 软件基金会开发和维护。它被设计为具有高度可扩展性和容错性的分布式存储系统,用于处理大规模数据集的高吞吐量和低延迟的应用程序。Cassandra 使用一种称为 CQL(Cassandra Query Language)的查询语言,它类似于 SQL,但具有一些特定于 Cassandra 的扩展和功能。CQL 提供了灵活的数据模型和查询选项,可以满足各种应用程序的需求。 —— 来自Apache

当前库是一个Rust写的库,理论上Rust是很少能出问题的,但是在现实场景中,由于对底层逻辑的操作需求,Rust也不得不引入unsafe关键字对一些底层的内容进行操作。然而一旦引入了unsafe,Rust在编译期间进行的检查就会失效,在这个过程中就会导致漏洞的出现。

Patch分析

根据漏洞公告,可以看到漏洞描述如下

Code that attempts to use an item (e.g., a row) returned by an iterator after the iterator has advanced to the next item will be accessing freed memory and experience undefined behaviour. Code that uses the item and then advances the iterator is unaffected. This problem has always existed.

This is a use-after-free bug, so it's rated high severity. If your code uses a pre-3.0.0 version of cassandra-rs, and uses an item returned by a cassandra-rs iterator after calling next() on that iterator, then it is vulnerable. However, such code will almost always fail immediately - so we believe it is unlikely that any code using this pattern would have reached production. For peace of mind, we recommend you upgrade anyway.

根据描述,我们可以直到这个漏洞的几个特征:

  • 漏洞类型为UAF
  • 漏洞和迭代器iter有关
  • 漏洞的触发和next()有关系

同时可以找到程序的patch在这个位置。其中有一段内容比较关键:

## Lending iterator API (version 3.0)

Version 3.0 fixes a soundness issue with the previous API. The iterators in the
underlying Cassandra driver invalidate the current item when `next()` is called,
and this was not reflected in the Rust binding prior to version 3.

To deal with this, the various iterators (`ResultIterator`, `RowIterator`,
`MapIterator`, `SetIterator`, `FieldIterator`, `UserTypeIterator`,
`KeyspaceIterator`, `FunctionIterator`, `AggregateIterator`, `TableIterator`,
`ColumnIterator`) no longer implement `std::iter::Iterator`. Instead, since this
is a [lending
iterator,](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#generic-associated-types-gats)
these types all implement a new `LendingIterator` trait. We define this
ourselves because there is currently no widely-used crate that implements it.

观察修复的内容,可以找到大致有两类修复代码:

一类则是增加了生命周期的声明:

/// A field's metadata
-   pub struct Field {
+   //
+   // Borrowed from wherever the value is borrowed from.
+   pub struct Field<'a> {
        /// The field's name
        pub name: String,
        /// The field's value
-       pub value: Value,
+       pub value: Value<'a>,
}

另一类则是增加了一些关于生命周期和幽灵数据的声明

#[derive(Debug)]
-   pub struct RowIterator(pub *mut _CassIterator);
+   pub struct RowIterator<'a>(*mut _CassIterator, PhantomData<&'a _Row>);

/// skip code

-   impl<'a> Iterator for &'a RowIterator {
-       type Item = Value;
+   impl LendingIterator for RowIterator<'_> {
+       type Item<'a> = Value<'a> where Self: 'a;

-       fn next(&mut self) -> Option<<Self as Iterator>::Item> {
+       fn next(&mut self) -> Option<<Self as LendingIterator>::Item<'_>> {
            unsafe {
                match cass_iterator_next(self.0) {
                    cass_false => None,
                    cass_true => Some(Value::build(cass_iterator_get_column(self.0))),
                }
            }
        }
}

可以看到,这里对类型RowIterator新增了生命周期的定义,并且这个LendingIterator似乎是一个新增的描述概念,作者同样添加到了README中:

## Lending iterator API (version 3.0)

Version 3.0 fixes a soundness issue with the previous API. The iterators in the
underlying Cassandra driver invalidate the current item when `next()` is called,
and this was not reflected in the Rust binding prior to version 3.

To deal with this, the various iterators (`ResultIterator`, `RowIterator`,
`MapIterator`, `SetIterator`, `FieldIterator`, `UserTypeIterator`,
`KeyspaceIterator`, `FunctionIterator`, `AggregateIterator`, `TableIterator`,
`ColumnIterator`) no longer implement `std::iter::Iterator`. Instead, since this
is a [lending
iterator,](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#generic-associated-types-gats)
these types all implement a new `LendingIterator` trait. We define this
ourselves because there is currently no widely-used crate that implements it.

并且修复commit中,作者提到

Make ResultIterator a LendingIterator

换句话说,将这些迭代器修改为LendingIterator,尤其是这个ResultIterator,就能解决问题。那么总结以下,漏洞修复方案大概是:

  • 将迭代器由Iterator修改为LendingIterator
  • 将数据对象增加生命周期,并且对某些结构体增加幽灵成员以增加生命周期

整体修复全是基于Rust特性进行的操作。为了能够更好的了解这个修复过程发生了什么,我们需要了解rust中关于生命周期的一些概念。熟悉的同学可以直接跳到漏洞分析。

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/586920.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【大语言模型LLM】-基于ChatGPT搭建客服助手(1)

&#x1f525;博客主页&#xff1a;西瓜WiFi &#x1f3a5;系列专栏&#xff1a;《大语言模型》 很多非常有趣的模型&#xff0c;值得收藏&#xff0c;满足大家的收集癖&#xff01; 如果觉得有用&#xff0c;请三连&#x1f44d;⭐❤️&#xff0c;谢谢&#xff01; 长期不…

2024年五一杯高校数学建模竞赛(A题)|钢板切割问题 | 建模解析,小鹿学长带队指引全代码文章与思路

我是鹿鹿学长&#xff0c;就读于上海交通大学&#xff0c;截至目前已经帮200人完成了建模与思路的构建的处理了&#xff5e; 本篇文章是鹿鹿学长经过深度思考&#xff0c;独辟蹊径&#xff0c;通过路径优化解决钢板切割问题。结合贪心算法&#xff0c;Floyd-Warshall等多元算法…

STM32G030F6P6TR 芯片TSSOP20 MCU单片机微控制器芯片

STM32G030F6P6TR 在物联网&#xff08;IoT&#xff09;设备中的典型应用案例包括但不限于以下几个方面&#xff1a; 1. 环境监测系统&#xff1a; 使用传感器来监测温度、湿度、气压等环境因素&#xff0c;并通过无线通信模块将数据发送到中央服务器或云端平台进行分析和监控。…

Ansys Speos|进行智能手机镜头杂散光分析

本例的目的是研究智能手机Camera系统的杂散光。杂散光是指光向相机传感器不需要的散光光或镜面光&#xff0c;是在光学设计中无意产生的&#xff0c;会降低相机系统的光学性能。 在本例中&#xff0c;光学透镜系统使用Ansys Zemax OpticStudio (ZOS)进行设计&#xff0c;并使用…

字符串函数、内存函数——补充

目录 前言 1、strchr函数 1-1 函数介绍 1-1-1 函数功能 1-1-2 函数原型 1-1-3 函数参数 1-1-4 所属库 1-1-5 函数返回值 1-2 函数简单使用 1-3 函数使用场景 1-4 函数的使用总结 1-4-1 注意事项 2、strrchr函数 2-1 函数介绍 2-1-1 函数功能 2-1-2 函数原型 2…

ubuntu入门

基础命令 cd 切换命令 ls 查看当前目录下所有的文件 cp a.c b.c 拷贝a.c 到 b.c touch a.c 创建a.c文件 mkdir file 创建文件夹file rm file 删除文件 rmdir 删除test文件夹 rmdir test/ mv 移动文件 mv a.c b.c 把a.c 替换成b.c ifconfig 查看电脑网络信息 rm xx 删…

人工电销机器人在销售行业中的重要性和作用,以及未来市场的发展前景

在追求更高效、更智能的时代&#xff0c;各行各业都在积极寻求新技术、新应用来提升业务流程的效率和质量。对于销售行业而言&#xff0c;人工电销机器人已经成为越来越受欢迎的工具之一。我们将深入探讨人工电销机器人在销售行业中的重要性和作用&#xff0c;以及未来市场的发…

31.Gateway网关-跨域问题

跨域 1.域名不同&#xff1a;www.baidu.com和www.taobao.com,www.taobao.org 2.域名相同&#xff0c;端口不同。localhost:8080和localhost:8081 跨域问题 浏览器禁止请求的发起者与服务端发生跨域ajax请求&#xff0c;请求被浏览器拦截的问题。 解决方案 CORS 浏览器询…

linux安装Redis 7.2.4笔记

一.保姆级安装 1.下载Redis 7.2.4安装包 sudo wget https://download.redis.io/releases/redis-7.2.4.tar.gz2.解压&#xff0c;可以指定 sudo tar -zvxf redis-7.2.4.tar.gz 3.检测并安装 GCC 编译器&#xff1a; yum 是基于 Red Hat 的 Linux 发行版&#xff08;如 CentOS、…

【webrtc】MessageHandler 5: 基于线程的消息处理:以PeerConnection信令线程为例

peerconn的信令是通过post 消息到自己的信令线程消息来处理的PeerConnectionMessageHandler 是具体的处理器G:\CDN\rtcCli\m98\src\pc\peer_connection_message_handler.hMachinery for handling messages posted to oneself PeerConnectionMessageHandler 明确服务于 signalin…

分布式与一致性协议之Raft算法(四)

Raft算法 Raft是如何解决成员变更问题的 在日常工作中&#xff0c;你可能会遇到服务器故障的情况&#xff0c;这时你需要替换集群中的服务器。如果遇到需要改变数据副本数的情况&#xff0c;则需要增加或移除集群中的服务器。总的来说&#xff0c;在日常工作中&#xff0c;集…

进一步了解android studio 里 AGP,gradle等关系

目录 &#xff08;1&#xff09; gradle是什么 &#xff08;2&#xff09; 工程的jdk版本&#xff0c;及引用包的编译版本的关系 实践 问题与解决 编译成功与运行成功 编译成功 运行成功 &#xff08;1&#xff09; gradle是什么 Gradle是一个构建工具&#xff0c;它是…

Mac 版 安装NVM

优质博文IT-BLOG-CN NVM&#xff08;Node Version Manager&#xff09;是一个用于管理多个Node.js版本的工具。它允许开发者在同一台机器上安装和切换不同版本的Node.js&#xff0c;以便在不同的项目中使用不同的Node.js版本。macOS用户可以使用homebrew来安装NVM。 一、安装h…

Swagger3.0(Springdoc)日常使用记录

文章目录 前言一、默认地址二、注解OperationTag 三、SpringBoot基础配置四、Swagger导入apifox五、Swagger其他配置六 knife4j 参考文章 前言 本文并不是Swagger的使用教程&#xff0c;只是记录一下本人的操作&#xff0c;感兴趣的可以看下 一、默认地址 http://localhost:…

Scala 多版本下载指南

Scala&#xff0c;这一功能丰富的编程语言&#xff0c;结合了面向对象和函数式编程的精华&#xff0c;为开发者提供了强大的工具来构建高效、可扩展的应用程序。随着Scala社区的不断壮大和技术的演进&#xff0c;多个版本的Scala被广泛应用于不同的项目与场景中。本文旨在为您提…

Redis集群模式:高可用性与性能的完美结合!

【更多精彩内容,欢迎关注小米的微信公众号“软件求生”】 大家好,我是小米,一个积极活泼、喜好分享技术的29岁程序员。今天我们来聊聊Redis的集群模式,以及它是如何实现高可用的。 什么是Redis集群模式? Redis的集群模式是为了避免单一节点负载过高导致不稳定的一种解决…

Rust Web开发实战:构建高效稳定的服务端应用

如果你厌倦了缓慢、占用大量资源且不稳定的模板化Web开发工具&#xff0c;Rust就是你的解决方案。Rust服务提供了稳定的安全保证、非凡的开发经验&#xff0c;以及能够自动防止常见错误的编译器。 《Rust Web开发》教你使用Rust以及重要的Rust库(如异步运行时的Tokio、用于Web…

3.C++动态内存管理(超全)

目录 1 .C/C 内存分布 2. C语言中动态内存管理方式&#xff1a;malloc/calloc/realloc/free 3. C内存管理方式 3.1 new/delete操作内置类型 3.2 new和delete操作自定义类型 3.3 operator new函数 3.4 定位new表达式(placement-new) &#xff08;了解&#xff09; 4. 常…

公共 IP 地址与私有 IP 地址区别有哪些?

​  IP 地址是分配给互联网上每个设备的唯一数字 ID。 IP 地址可以在 Internet 上公开使用&#xff0c;也可以在局域网 (LAN)上私有使用。本文&#xff0c;我们主要探讨公共 IP 地址和私有 IP 地址之间的区别。 公共IP地址&#xff1a;公共IP地址是用于访问Internet的向外的I…

极简shell制作

&#x1f30e;自定义简单shell制作 &#xff08;ps: 文末有完整代码&#xff09; 文章目录&#xff1a; 自定义简单shell制作 简单配置Linux文件 自定义Shell编写 命令行解释器       获取输入的命令       字符串分割       子进程进行进程替换 内建命令…