Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
kernel_linux
提交
b2d09ae4
K
kernel_linux
项目概览
OpenHarmony
/
kernel_linux
上一次同步 4 年多
通知
15
Star
8
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kernel_linux
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b2d09ae4
编写于
6月 09, 2017
作者:
J
John Johansen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
apparmor: move ptrace checks to using labels
Signed-off-by:
N
John Johansen
<
john.johansen@canonical.com
>
上级
ca916e8e
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
58 addition
and
80 deletion
+58
-80
security/apparmor/domain.c
security/apparmor/domain.c
+10
-7
security/apparmor/include/apparmor.h
security/apparmor/include/apparmor.h
+1
-0
security/apparmor/include/ipc.h
security/apparmor/include/ipc.h
+5
-5
security/apparmor/ipc.c
security/apparmor/ipc.c
+21
-66
security/apparmor/lsm.c
security/apparmor/lsm.c
+21
-2
未找到文件。
security/apparmor/domain.c
浏览文件 @
b2d09ae4
...
...
@@ -51,14 +51,16 @@ void aa_free_domain_entries(struct aa_domain *domain)
/**
* may_change_ptraced_domain - check if can change profile on ptraced task
* @to_profile: profile to change to (NOT NULL)
* @to_label: profile to change to (NOT NULL)
* @info: message if there is an error
*
* Check if current is ptraced and if so if the tracing task is allowed
* to trace the new domain
*
* Returns: %0 or error if change not allowed
*/
static
int
may_change_ptraced_domain
(
struct
aa_profile
*
to_profile
)
static
int
may_change_ptraced_domain
(
struct
aa_label
*
to_label
,
const
char
**
info
)
{
struct
task_struct
*
tracer
;
struct
aa_label
*
tracerl
=
NULL
;
...
...
@@ -74,13 +76,14 @@ static int may_change_ptraced_domain(struct aa_profile *to_profile)
if
(
!
tracer
||
unconfined
(
tracerl
))
goto
out
;
error
=
aa_may_ptrace
(
labels_profile
(
tracerl
),
to_profile
,
PTRACE_MODE_ATTACH
);
error
=
aa_may_ptrace
(
tracerl
,
to_label
,
PTRACE_MODE_ATTACH
);
out:
rcu_read_unlock
();
aa_put_label
(
tracerl
);
if
(
error
)
*
info
=
"ptrace prevents transition"
;
return
error
;
}
...
...
@@ -477,7 +480,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
}
if
(
bprm
->
unsafe
&
LSM_UNSAFE_PTRACE
)
{
error
=
may_change_ptraced_domain
(
new_profile
);
error
=
may_change_ptraced_domain
(
&
new_profile
->
label
,
&
info
);
if
(
error
)
goto
audit
;
}
...
...
@@ -661,7 +664,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, int flags)
}
}
error
=
may_change_ptraced_domain
(
hat
);
error
=
may_change_ptraced_domain
(
&
hat
->
label
,
&
info
);
if
(
error
)
{
info
=
"ptraced"
;
error
=
-
EPERM
;
...
...
@@ -782,7 +785,7 @@ int aa_change_profile(const char *fqname, int flags)
}
/* check if tracing task is allowed to trace target domain */
error
=
may_change_ptraced_domain
(
target
);
error
=
may_change_ptraced_domain
(
&
target
->
label
,
&
info
);
if
(
error
)
{
info
=
"ptrace prevents transition"
;
goto
audit
;
...
...
security/apparmor/include/apparmor.h
浏览文件 @
b2d09ae4
...
...
@@ -27,6 +27,7 @@
#define AA_CLASS_NET 4
#define AA_CLASS_RLIMITS 5
#define AA_CLASS_DOMAIN 6
#define AA_CLASS_PTRACE 9
#define AA_CLASS_LABEL 16
#define AA_CLASS_LAST AA_CLASS_LABEL
...
...
security/apparmor/include/ipc.h
浏览文件 @
b2d09ae4
...
...
@@ -4,7 +4,7 @@
* This file contains AppArmor ipc mediation function definitions.
*
* Copyright (C) 1998-2008 Novell/SUSE
* Copyright 2009-201
0
Canonical Ltd.
* Copyright 2009-201
7
Canonical Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
...
...
@@ -19,10 +19,10 @@
struct
aa_profile
;
int
aa_may_ptrace
(
struct
aa_profile
*
tracer
,
struct
aa_profile
*
tracee
,
unsigned
int
mode
);
#define AA_PTRACE_TRACE MAY_WRITE
#define AA_PTRACE_READ MAY_READ
int
aa_
ptrace
(
struct
task_struct
*
tracer
,
struct
task_struct
*
tracee
,
unsigned
int
mode
);
int
aa_
may_ptrace
(
struct
aa_label
*
tracer
,
struct
aa_label
*
tracee
,
u32
request
);
#endif
/* __AA_IPC_H */
security/apparmor/ipc.c
浏览文件 @
b2d09ae4
...
...
@@ -4,7 +4,7 @@
* This file contains AppArmor ipc mediation
*
* Copyright (C) 1998-2008 Novell/SUSE
* Copyright 2009-201
0
Canonical Ltd.
* Copyright 2009-201
7
Canonical Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
...
...
@@ -25,88 +25,43 @@
static
void
audit_ptrace_cb
(
struct
audit_buffer
*
ab
,
void
*
va
)
{
struct
common_audit_data
*
sa
=
va
;
audit_log_format
(
ab
,
" peer="
);
aa_label_xaudit
(
ab
,
labels_ns
(
aad
(
sa
)
->
label
),
aad
(
sa
)
->
peer
,
FLAGS_NONE
,
GFP_ATOMIC
);
}
/**
* aa_audit_ptrace - do auditing for ptrace
* @profile: profile being enforced (NOT NULL)
* @target: profile being traced (NOT NULL)
* @error: error condition
*
* Returns: %0 or error code
*/
static
int
aa_audit_ptrace
(
struct
aa_profile
*
profile
,
struct
aa_profile
*
target
,
int
error
)
static
int
cross_ptrace_perm
(
struct
aa_profile
*
tracer
,
struct
aa_profile
*
tracee
,
u32
request
,
struct
common_audit_data
*
sa
)
{
DEFINE_AUDIT_DATA
(
sa
,
LSM_AUDIT_DATA_NONE
,
OP_PTRACE
);
/* policy uses the old style capability check for ptrace */
if
(
profile_unconfined
(
tracer
)
||
tracer
==
tracee
)
return
0
;
aad
(
&
sa
)
->
peer
=
&
target
->
label
;
aad
(
&
sa
)
->
error
=
error
;
aad
(
sa
)
->
label
=
&
tracer
->
label
;
aad
(
sa
)
->
peer
=
&
tracee
->
label
;
aad
(
sa
)
->
request
=
0
;
aad
(
sa
)
->
error
=
aa_capable
(
&
tracer
->
label
,
CAP_SYS_PTRACE
,
1
);
return
aa_audit
(
AUDIT_APPARMOR_AUTO
,
profile
,
&
sa
,
audit_ptrace_cb
);
return
aa_audit
(
AUDIT_APPARMOR_AUTO
,
tracer
,
sa
,
audit_ptrace_cb
);
}
/**
* aa_may_ptrace - test if tracer task can trace the tracee
* @tracer:
profile
of the task doing the tracing (NOT NULL)
* @tracee: task to be traced
* @
mode: whether PTRACE_MODE_READ || PTRACE_MODE_ATTACH
* @tracer:
label
of the task doing the tracing (NOT NULL)
* @tracee: task
label
to be traced
* @
request: permission request
*
* Returns: %0 else error code if permission denied or error
*/
int
aa_may_ptrace
(
struct
aa_
profile
*
tracer
,
struct
aa_profile
*
tracee
,
u
nsigned
int
mode
)
int
aa_may_ptrace
(
struct
aa_
label
*
tracer
,
struct
aa_label
*
tracee
,
u
32
request
)
{
/* TODO: currently only based on capability, not extended ptrace
* rules,
* Test mode for PTRACE_MODE_READ || PTRACE_MODE_ATTACH
*/
DEFINE_AUDIT_DATA
(
sa
,
LSM_AUDIT_DATA_NONE
,
OP_PTRACE
);
if
(
profile_unconfined
(
tracer
)
||
tracer
==
tracee
)
return
0
;
/* log this capability request */
return
aa_capable
(
&
tracer
->
label
,
CAP_SYS_PTRACE
,
1
);
return
xcheck_labels_profiles
(
tracer
,
tracee
,
cross_ptrace_perm
,
request
,
&
sa
);
}
/**
* aa_ptrace - do ptrace permission check and auditing
* @tracer: task doing the tracing (NOT NULL)
* @tracee: task being traced (NOT NULL)
* @mode: ptrace mode either PTRACE_MODE_READ || PTRACE_MODE_ATTACH
*
* Returns: %0 else error code if permission denied or error
*/
int
aa_ptrace
(
struct
task_struct
*
tracer
,
struct
task_struct
*
tracee
,
unsigned
int
mode
)
{
/*
* tracer can ptrace tracee when
* - tracer is unconfined ||
* - tracer is in complain mode
* - tracer has rules allowing it to trace tracee currently this is:
* - confined by the same profile ||
* - tracer profile has CAP_SYS_PTRACE
*/
struct
aa_label
*
tracer_l
=
aa_get_task_label
(
tracer
);
int
error
=
0
;
if
(
!
unconfined
(
tracer_l
))
{
struct
aa_label
*
tracee_l
=
aa_get_task_label
(
tracee
);
error
=
aa_may_ptrace
(
labels_profile
(
tracer_l
),
labels_profile
(
tracee_l
),
mode
);
error
=
aa_audit_ptrace
(
labels_profile
(
tracer_l
),
labels_profile
(
tracee_l
),
error
);
aa_put_label
(
tracee_l
);
}
aa_put_label
(
tracer_l
);
return
error
;
}
security/apparmor/lsm.c
浏览文件 @
b2d09ae4
...
...
@@ -104,12 +104,31 @@ static void apparmor_cred_transfer(struct cred *new, const struct cred *old)
static
int
apparmor_ptrace_access_check
(
struct
task_struct
*
child
,
unsigned
int
mode
)
{
return
aa_ptrace
(
current
,
child
,
mode
);
struct
aa_label
*
tracer
,
*
tracee
;
int
error
;
tracer
=
begin_current_label_crit_section
();
tracee
=
aa_get_task_label
(
child
);
error
=
aa_may_ptrace
(
tracer
,
tracee
,
mode
==
PTRACE_MODE_READ
?
AA_PTRACE_READ
:
AA_PTRACE_TRACE
);
aa_put_label
(
tracee
);
end_current_label_crit_section
(
tracer
);
return
error
;
}
static
int
apparmor_ptrace_traceme
(
struct
task_struct
*
parent
)
{
return
aa_ptrace
(
parent
,
current
,
PTRACE_MODE_ATTACH
);
struct
aa_label
*
tracer
,
*
tracee
;
int
error
;
tracee
=
begin_current_label_crit_section
();
tracer
=
aa_get_task_label
(
parent
);
error
=
aa_may_ptrace
(
tracer
,
tracee
,
AA_PTRACE_TRACE
);
aa_put_label
(
tracer
);
end_current_label_crit_section
(
tracee
);
return
error
;
}
/* Derived from security/commoncap.c:cap_capget */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录