Skip to content

security: add fault injection to LSM hooks

Aleksandr Nogikh linux-security-module lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 2 repliesIn review
  2. v2 RFC2 patches 6 repliesSuperseded
  3. v1 RFC1 patch 2 repliesSuperseded

Changes in v4 from the cover letter

* Changed retval debugfs file type - now it stores a signed integer.
* Made CONFIG_FAIL_LSM_HOOKS depend on CONFIG_SECURITY.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2security: add fault injection capabilitylib/Kconfig.debug security/security.c+72 -31 reply
2/2docs: add fail_lsm_hooks info to fault-injection.rstDocumentation/fault-injection/fault-injection.rst+6 -00 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchMarco ElverTetsuo HandaAndrey KonovalovAlexander Potapenko
1/2R-b R-b R-b R-b
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/2] security: add fault injection to LSM hooks

From: Aleksandr Nogikh <[email protected]>

Fault injection capabilities[Documentation/fault-injection/fault-injection.rst] facilitate testing of the stability of the Linux kernel by providing means to force a number of kernel interfaces to return error codes. This patch series proposes adding such fault injection capability into LSM hooks.

The intent is to make it possible to test whether the existing kernel code properly handles negative return values of LSM hooks. Syzbot
[https://github.com/google/syzkaller/blob/master/docs/syzbot.md] will automatically do that with the aid of instrumentation tools once these changes are merged.

Local fuzzing of a Linux kernel with this patch has almost instantly led to two crashes. I'm not sure whether they correspond to actual issues as this LSM fault injection implementation (and the concept itself) can be wrong. Here they are:

1. "general protection fault in selinux_inode_free_security". This is caused by executing security_inode_free() when a fault was injected to inode_alloc_security() and therefore selinux_inode_alloc_security() was not executed. In this case, the subsequent inode_free_security() call executes list_del_init() on an uninitialized list. Theoretically, this may happen if some other LSM precedes selinux in the hooks list and its inode_alloc_security hook fails.

A fault was injected to this call_int_hook():
https://elixir.bootlin.com/linux/v5.9/source/security/security.c#L975

Below you can find a call trace for the subsequent crash.

__list_del_entry include/linux/list.h:132 [inline]
list_del_init include/linux/list.h:204 [inline]
inode_free_security security/selinux/hooks.c:337 [inline]
selinux_inode_free_security+0xf0/0x290 security/selinux/hooks.c:2839
security_inode_free+0x46/0xc0 security/security.c:1042
security_inode_alloc+0x161/0x1a0 security/security.c:1027
inode_init_always+0x5a7/0xd10 fs/inode.c:171
alloc_inode+0x82/0x230 fs/inode.c:239
new_inode_pseudo+0x14/0xe0 fs/inode.c:928
sock_alloc+0x3c/0x260 net/socket.c:573
__sock_create+0xb9/0x780 net/socket.c:1391
sock_create net/socket.c:1478 [inline]
__sys_socket+0xef/0x200 net/socket.c:1520
__do_sys_socket net/socket.c:1529 [inline]
__se_sys_socket net/socket.c:1527 [inline]
__x64_sys_socket+0x6f/0xb0 net/socket.c:1527
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

2. BUG_ON inside security_skb_classify_flow(). Why is it needed there?
https://elixir.bootlin.com/linux/v5.9/source/security/security.c#L2426

---
v4:
* Changed retval debugfs file type - now it stores a signed integer.
* Made CONFIG_FAIL_LSM_HOOKS depend on CONFIG_SECURITY.

v3:
https://lkml.kernel.org/r/[email protected]
* Submitting this series without an "RFC" tag.
* Updated the cover letter.

v2:
https://lkml.kernel.org/r/[email protected]
* Renamed should_fail_lsm_hook() to lsm_hooks_inject_fail().
* Extended the documentation.

v1:
https://lkml.kernel.org/r/[email protected]

Aleksandr Nogikh (2):
security: add fault injection capability
docs: add fail_lsm_hooks info to fault-injection.rst

 .../fault-injection/fault-injection.rst       |  6 ++
 lib/Kconfig.debug                             |  6 ++
 security/security.c                           | 69 ++++++++++++++++++-
 3 files changed, 78 insertions(+), 3 deletions(-)

base-commit: 3e14f70c05cda4794901ed8f976de3a88deebcc0

Signature · 1 line
2.29.2.222.g5d2a92d10f8-goog