Skip to content

Commit

Permalink
Add driver doc (#271)
Browse files Browse the repository at this point in the history
* add Elkeid Driver Doc: <Description of Elkeid's Crash caused by fput in low version Kernel>

* fix driver readme

* Fix markdown <br> usage error

* Update Description_of_Elkeid's_Crash_caused_by_fput_in_low_version_Kernel.md
  • Loading branch information
E_Bwill authored Aug 1, 2022
1 parent 60802f0 commit 9c6edac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Description of the problem that Elkeid causes Crash on low version Kernel (Fixed)

## 影响范围
小于 Linux Kernel 3.6 的内核会受到影响。
RHEL系仅影响RHEL6(Kernel Version 2.6.32)。


## 情况说明
重启的直接原因是内核的 BUGON 检测所触发,即 `fs/buffer.c L1298: BUGON(irqs_disabled())`
Elkeid 在 `security_inode_create_pre_handler` 中使用了内核 API 函数 `fput()` ,但 `fput()` 在低版本(Kernel 小于 3.6)存在竞争条件问题,即可能存在多个线程操作同一个文件句柄的情况,在某些正好满足竞争条件的情况下(atomic_long_dec_and_test 为 True),`fput()` 会进一步触发 i/o 操作(ext4文件系统:`ext4_release_file`),结合 Elkeid 上下文(较旧内核中采用的是int 3断点方式),并最终触发上述的 BUGON 条件。该问题需要某些特殊的竞争态条件下才可被触发。
相关内核代码:
[https://elixir.bootlin.com/linux/v2.6.32/source/fs/file_table.c#L227](https://elixir.bootlin.com/linux/v2.6.32/source/fs/file_table.c#L227)
[https://elixir.bootlin.com/linux/v2.6.32/source/fs/file_table.c#L281](https://elixir.bootlin.com/linux/v2.6.32/source/fs/file_table.c#L281)

`fput()` 的实现在3.6内核对此问题进行了修复,全部改成了异步操作,从而规避了些竞争问题,具体讨论:[https://lwn.net/Articles/494158](https://lwn.net/Articles/494158/)

具体commit:[https://github.com/torvalds/linux/commit/4a9d4b024a3102fc083c925c242d98ac27b1c5f6](https://github.com/torvalds/linux/commit/4a9d4b024a3102fc083c925c242d98ac27b1c5f6),所以3.6 及之后的内核是没有此竞争问题。


## 修复情况
Elkeid 已针对存在该问题的低版本内核进行规避:[https://github.com/bytedance/Elkeid/pull/270](https://github.com/bytedance/Elkeid/pull/270)


## 其他受该问题影响场景
受此低版本内核问题影响的其他场景还有(部分):

**ima-appraisal patches**
[https://lwn.net/Articles/494173/](https://lwn.net/Articles/494173/)


**SELinux**[http://realtechtalk.com/Kernel_panic_not_syncing_Attempted_to_kill_init_Pid_1comm_init_Tained_GI2632358el6x86_64_1_Call_Trace_%5Bfffffff8150cfc8%5D_panic0xa00x16f_%5Bfffffff81073ae2%5D_do_exit0x8620x870_%5Bfffffff81182885%5D_fput0x250-1344-articles](http://realtechtalk.com/Kernel_panic_not_syncing_Attempted_to_kill_init_Pid_1comm_init_Tained_GI2632358el6x86_64_1_Call_Trace_%5Bfffffff8150cfc8%5D_panic0xa00x16f_%5Bfffffff81073ae2%5D_do_exit0x8620x870_%5Bfffffff81182885%5D_fput0x250-1344-articles)


**SELinux**
[https://elixir.bootlin.com/linux/v3.4.113/source/security/selinux/hooks.c#L2240](https://elixir.bootlin.com/linux/v3.4.113/source/security/selinux/hooks.c#L2240)


**BUGON**
[https://www.spinics.net/lists/kernel/msg1622221.html](https://www.spinics.net/lists/kernel/msg1622221.html)
4 changes: 2 additions & 2 deletions driver/README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@ Testing Load:
## 已知问题
* 内核模块 hook 点初始化失败 : do_init_module
<br>
在一些老版本的 Ubuntu / CentOS 内核中出现,dmesg 会有如下输出:<br>
<br>在一些老版本的 Ubuntu / CentOS 内核中出现,dmesg 会有如下输出:<br>
do_init_module register_kprobe failed, returned -2.<br>
内核模块仍然可以使用,但没有 do_init_module 数据
* [Description of Elkeid's Crash caused by fput in low version Kernel](DOC/Description_of_Elkeid's_Crash_caused_by_fput_in_low_version_Kernel.md)
## License
Expand Down
6 changes: 3 additions & 3 deletions driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,11 @@ You can use DKMS or Pre-packaged ko file
## Known Bugs
* Hook point init failed : do_init_module
<br>
Some old version of Ubuntu / CentOS kernels may show the dmesg :
* Hook point init failed: do_init_module
<br>Some old version of Ubuntu / CentOS kernels may show the dmesg :
do_init_module register_kprobe failed, returned -2.
* [Description of Elkeid's Crash caused by fput in low version Kernel](DOC/Description_of_Elkeid's_Crash_caused_by_fput_in_low_version_Kernel.md)
## License
Expand Down

0 comments on commit 9c6edac

Please sign in to comment.