文件的open、close、read、write是最基本的文件抽象,描述了对于设备的操作。本文将结合用户态的接口以及内核态的实现剖析文件IO。
我通过open这个系统调用虫洞来到了内核空间,又在老爷爷的指点下来到了sys_open的地盘,即将开始打开文件的工作。
vfs层文件创建链路 📷 vfs层是在客户端执行创建创建,首先是经过内核的syscall的open调用,最后调用的是具体文件系统实现的的dir->i_op->atomic_open函数,这个函数是具体文件系统定义的。如下是vfs层的简要函数的定制和执行路径。 // 定义了系统调用open SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode) { return do_sys_open(AT_FDCW
系统调用 linux下任何进程针对文件类打开和释放资源大部分 都会涉及到系统调用,这里是针对文件相关的系统调用open和close.linux下open一个文件是返回的是一个文件描述符,这个文件描述符关联一个struct file,struct file是通过文件inode初始化而来;close系统调用把进程关联的fd对应的struct file资源给释放了,同时flush这个struct file对应的inode信息到磁盘。整个open和close操作都是通过system call->vfs->ext4这
在Linux shell中执行mount命令,通常可以看到某个做了文件系统的磁盘分区或flash分区或内存文件系统做为所谓的根文件系统被mount到了挂载点/处。
mmap是Linux中常用的系统调用API,用途广泛,Android中也有不少地方用到,比如匿名共享内存,Binder机制等。本文简单记录下Android中mmap调用流程及原理。mmap函数原型如下:
Returns file descriptor on success, or –1 on error 同open相比,多了一个dirfd参数。关于它的用法,参考以下解释:
最近公司 CI 升级,将 docker 基镜像由原先的 debian 切换到了 ubuntu,导致应用一旦成功启动之后,再次执行重启将会持续失败。查看日志,发现打印 ln: failed to access '/tmp/access.log/stdout': Not a directory
通过对 open 系统调用的监测,opensnoop可以展现系统内所有调用了 open 系统调用的进程信息。
eBPF(Extended Berkeley Packet Filter)是一种内核执行环境,它可以让用户在内核中运行一些安全的、高效的程序。它通常用于网络过滤、性能分析、安全监控等场景。eBPF 之所以强大,是因为它能够在内核运行时捕获和修改数据包或者系统调用,从而实现对操作系统行为的监控和调整。
eBPF (Extended Berkeley Packet Filter) 是 Linux 内核上的一个强大的网络和性能分析工具,它允许开发者在内核运行时动态加载、更新和运行用户定义的代码。
朋友安装了一个 MySQL-8.0.32 版本的 MySQL;其中服务端可以正常运行但是客户端运行不了。
这个是从库,没有读业务和其他下游同步,风险可控。但是大家还是要谨慎。我执行这个命令是因为我搜到的菜鸟教程的split命令案例错误导致我生成了大量小文件。没想到大名鼎鼎的菜鸟教程也会有问题,大家还用man或者tldr查看帮助手册吧。
现在很多App不讲武德了,为了防止 openat 、read、kill 等等底层函数被hook,干脆就直接通过syscall的方式来做系统调用,导致无法hook。
对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
在linux下,假设我们想打开文件/dev/tty,我们可以使用系统调用open,比如:
ext4挂载 在linux 5.x的内核中,实际文件系统的挂载采用新的挂载API,引入了struct fs_context用于内部文件系统挂载的信息。 应用端发起mount命令,进入mount系统调用,执行do_mount的函数 // vfs层保留该小节需要的核心字段 struct super_block { // 文件系统类型 struct file_system_type *s_type; // 文件系统super_block的操作函数 const struct super_operations
选自Medium 作者:Franklin He 机器之心编译 参与:Nurhachu Null、路 本文介绍了如何在 Google Colab(Google 提供免费 GPU 的机器学习环境)上运行 StarCraft II 机器学习项目,包括过程中遇到的问题和作者提出的解决方案。 如果你想开始使用 FREE StarCraft II 机器学习环境,请先完善 GPU 硬件,您可以看一下我的 Google Colab notebook:https://colab.research.google.com/dri
RunC是一个基于OCI标准的轻量级容器运行时工具,用来创建和运行容器,该工具被广泛应用于虚拟化环境中,然而不断披露的逃逸漏洞给runC带来了严重的安全风险,如早期的CVE-2019-5736、CVE-2021-30465。就在今年的1月31日,网络安全供应商Synk又披露了runC 命令行工具和BuildKit 组件中的4个安全漏洞,攻击者可以利用这些漏洞逃离容器的边界并发起后续攻击。这些漏洞编号分别为 CVE-2024-21626、CVE-2024-23651、CVE-2024-23652 和 CVE-2024-23653,这些漏洞被 Snyk统称为Leaky Vessels[1][2]。
我们将在最后一章讨论有关系统调用方面的抢占调度,所以这里有必要对系统调用有个基本的了解。
将 eBPF 程序附加到跟踪点以及内核和用户应用探针点的能力,使得应用程序和系统本身的运行时行为具有前所未有的可见性。通过赋予应用程序和系统两方面的检测能力,可以将两种视图结合起来,从而获得强大而独特的洞察力来排除系统性能问题。
描述: auditd是Linux审计系统的用户空间组件, 该守护进程它负责将审计记录写入磁盘,我们可以使用 ausearch 或 aureport 实用程序查看日志。 与此同时,我们可以使用 auditctl 实用程序配置审计系统或加载规则,在 auditd 启动期间审计规则 /etc/audit/audit.rules,由 auditctl 读取并加载到内核中或者还有一个 augenrules 程序,它读取位于 /etc/audit/rules.d/ 中的规则并将它们编译成一个 audit.rules 文件。
内存太高导致free内存低于水位时,会导致网络收包时因free 内存低于水位线频繁触发分配内存失败导致无法ssh登陆机器。 这时候如果发生了重启,或者是sysrq自己触发重启并生成了coredump,可以用来定位问题的原因。
上一篇nginx的文章中,我们理解了整个http正向代理的运行流程原理,主要就是事件机制接入,header解析,body解析,然后遍历各种checker,直到处理成功为止。
eBPF is a revolutionary technology with origins in the Linux kernel that can run sandboxed programs in an operating system kernel. It is used to safely and efficiently extend the capabilities of the kernel without requiring to change kernel source code or load kernel modules.
Introduction FUSE (Filesystem in Userspace) is a very useful mechanism in many applications. The thing is, those applications should not be focused on performance in terms of actual data transfers. FUSE has many advantages implied by userspace sandboxing, but for sure performance wasn't the main design consideration. I'm not telling that it is a bad design or something wrong with FUSE itself. It is just focused on other aspects like security, stability and easiness of creating applications. The problem I'd like to discuss here is that Google decided to use FUSE as a frontend to actual data stored on the non-volatile memory. FUSE has been introduced in Android 4.4 to handle "emulated" storage. Before that, "emulated" storage path was mounted as VFAT. Here's how it looked on old ICS (output of mount command):
kprobe 是一种动态调试机制,用于debugging,动态跟踪,性能分析,动态修改内核行为等,2004年由IBM发布,是名为Dprobes工具集的底层实现机制[1][2],2005年合入Linux kernel。probe的含义是像一个探针,可以不修改分析对象源码的情况下,获取Kernel的运行时信息。
之前使用ftrace的时候需要一系列的配置,使用起来有点繁琐,这里推荐一个ftrace的一个前端工具,它就是trace-cmd
玩过安卓的朋友应该都对 root 这个名词不陌生,曾几何时,一台 root 过的手机是发烧友标配;对于开发者来说,root 后的手机是黑灰产外挂的温床,是想要极力避免和打击的目标;而对于安全研究人员来说,root 则意味着更多 —— Towelroot、PingPongRoot、DirtyC0w、ReVent,那些有趣的漏洞和精妙的利用,承载了不少的汗水和回忆。
在排查linux性能问题的时候我们有时候会发现 整体 CPU使用率 很高,但是绝大多是是在 sys 上的,usr上的CPU时间很少,这种就需要看看是内核空间在干什么了, 是系统在 系统调用太耗时还
eBPF(extended Berkeley Packet Filter) 可谓 Linux 社区的新宠,很多大公司都开始投身于 eBPF 技术,如 Goole、Facebook、Twitter 等。
出现Warning FailedNodeAllocatableEnforcement 85s (x26 over 26m) kubelet Failed to update Node Allocatable Limits ["kubepods"]: openat2 /sys/fs/cgroup/kubepods.slice/cpu.weight: no such file or directory
为了安全,Linux 中分为用户态和内核态两种运行状态。对于普通进程,平时都是运行在用户态下,仅拥有基本的运行能力。当进行一些敏感操作,比如说要打开文件(open)然后进行写入(write)、分配内存(malloc)时,就会切换到内核态。内核态进行相应的检查,如果通过了,则按照进程的要求执行相应的操作,分配相应的资源。这种机制被称为系统调用,用户态进程发起调用,切换到内核态,内核态完成,返回用户态继续执行,是用户态唯一主动切换到内核态的合法手段(exception 和 interrupt 是被动切换)。
之前一个老板说“xxx组的同学是一定要把eBPF用到得心应手”,因为之前是做性能压测相关工作,个人感觉压测其实并不复杂,复杂的是压测后的问题定位,而eBPF则是定位问题的有效工具,我们可以透过eBPF去洞悉内核的运行状态,帮助我们去做故障诊断、网络优化、性能监控、以及安全控制等生产环境中的各种问题。
配置 [root@h102 src]# cd nginx-1.9.5 [root@h102 nginx-1.9.5]# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src [root@h102 nginx-1.9.5]# ./configure checking for OS + Linux 2.6.32-504.el6.x86_64 x86_64 checking for C c
继续我们的 HTTP 核心模块之旅。今天主要是文件相关的一些处理操作,包括 DirectIO、文件缓存以及 sendfile 相关的配置。这三个配置中,大家应该会见过 sendfile ,但是另外两个就比较少见了。包括我之前也从来没见过,不过还好,DirectIO 并不是一个完全的陌生人,文件缓存优化也与操作系统基础知识有关,而 sendfile 一般默认就是开启的,所以大家也不要有太大的压力哦。
bpftrace提供了一种快速利用eBPF实现动态追踪的方法,可以作为简单的命令行工具或者入门级编程工具来使用。本文以bpftrace为例,介绍如何利用eBPF实现内核的动态追踪。
一 用途 (1)function 主要用于跟踪内核函数的调用栈(其被调用过程) (2)function_graph 主要用于跟踪内核函数内部调用流程及耗时 这两个对内核性能分析的作用不大,主要用来梳理内核模块的逻辑 二 使用 (1)function 使用 /sys/kernel/debug/tracing # echo nop > current_tracer ----清空跟踪器 /sys/kernel/debug/tracing # echo drm_open > set_ftrace
当我们执行系统调用的时候,会首先对某些错误情况进行检查,如果失败通常会得到一些 error 信息,通过查看全局变量 errno 可以知道到底是哪一类错误
网络攻击者通常会利用被攻击网站中存在的漏洞,通过在网页中植入非法暗链对网页内容进行篡改等方式,进行非法牟利或者恶意商业攻击等活动。网页被恶意篡改会影响用户正常访问网页内容,还可能会导致严重的经济损失、品牌损失甚至是政治风险。
新配置,就可以配置成功 [root@h102 nginx-1.9.5]# ./configure checking for OS + Linux 2.6.32-504.el6.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) checking for gcc -pipe switch ... fou
原文链接:https://gankra.github.io/blah/c-isnt-a-language/
近日,Rust和Swift资深专家Aria Beingessner发布的一篇文章《C 不再是一种编程语言》在Hacker News上引起了热烈讨论。
本文标题里的观点很“刺激”,它来自国外一位 Swift 和 Rust 专家 Aria Beingessner,他近日撰写了一篇文章《C 不再是一种编程语言》,在技术社区引起了热议。
lustre中inode的operations 不论是本地文件系统还是分布式文件系统,每个inode会有一些operations.针对上层的posix语义的实现。我们这里着重讨论文件的create操作,create涉及的file_operation有ll_file_operations_flock和ll_file_operations. 📷 // lustre客户端的file_oepration的函数 const struct file_operations *ll_select_file_operati
eBPF 源于 BPF,本质上是处于内核中的一个高效与灵活的虚拟机组件,以一种安全的方式在许多内核 hook 点执行字节码,开发者可基于 eBPF 开发性能分析工具、软件定义网络、安全等诸多场景。但是,目前对于开发和使用 eBPF 应用而言还可能存在一些不够方便的地方:
容器安全是一个庞大且牵涉极广的话题,而容器的安全隔离往往是一套纵深防御的体系,牵扯到 AppArmor、Namespace、Capabilities、Cgroup、Seccomp 等多项内核技术和特性,但安全却是一处薄弱则全盘皆输的局面,一个新的内核特性可能就会让看似无懈可击的防线存在突破口。随着云原生技术的快速发展,越来越多的容器运行时组件在新版本中会默认配置 AppArmor 策略,原本我们在《红蓝对抗中的云原生漏洞挖掘及利用实录》介绍的多种容器逃逸手法会逐渐失效;因此我们希望能碰撞出一些攻击手法,进而突破新版本容器环境的安全能力,并使用更契合容器集群的新方式把 “任意文件写” 转化为“远程代码执行”,从而提前布防新战场。
领取专属 10元无门槛券
手把手带您无忧上云