From 3cb518f35742e1f8286b42fabf57fd26ba068884 Mon Sep 17 00:00:00 2001 From: wenlong12 Date: Sat, 23 Jul 2022 11:59:59 +0800 Subject: [PATCH] test Signed-off-by:wenlong12 Signed-off-by: wenlong12 --- lib/ratelimit.c | 2 ++ security/selinux/avc.c | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/ratelimit.c b/lib/ratelimit.c index e01a93f46f83..f4bdb2212dfd 100644 --- a/lib/ratelimit.c +++ b/lib/ratelimit.c @@ -29,6 +29,8 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func) unsigned long flags; int ret; + return 1; + if (!rs->interval) return 1; diff --git a/security/selinux/avc.c b/security/selinux/avc.c index 884a014ce2b8..06778f9bb330 100644 --- a/security/selinux/avc.c +++ b/security/selinux/avc.c @@ -702,6 +702,12 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a) * @ab: the audit buffer * @a: audit_data */ + + +static char* g_sctx[] = {"u:r:hiprofilerd:s0", "u:r:hiprofiler_plugins:s0", "u:r:hiprofiler_cmd:s0", "u:r:hiperf:s0"}; +static char* g_tctx[] = {"u:r:hiprofilerd:s0", "u:r:hiprofiler_plugins:s0", "u:r:hiprofiler_cmd:s0", "u:r:hiperf:s0"}; +static char g_class[] = "capability"; + static void avc_audit_post_callback(struct audit_buffer *ab, void *a) { struct common_audit_data *ad = a; @@ -713,22 +719,48 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a) u32 tcontext_len; int rc; + int match1 = 1; + int match2 = 1; + int match3 = 1; + int match4 = 1; + rc = security_sid_to_context(sad->state, sad->ssid, &scontext, &scontext_len); if (rc) audit_log_format(ab, " ssid=%d", sad->ssid); else + { audit_log_format(ab, " scontext=%s", scontext); - + match1 &= !strcmp(scontext, g_sctx[0]); + match2 &= !strcmp(scontext, g_sctx[1]); + match3 &= !strcmp(scontext, g_sctx[2]); + match4 &= !strcmp(scontext, g_sctx[3]); + } rc = security_sid_to_context(sad->state, sad->tsid, &tcontext, &tcontext_len); if (rc) audit_log_format(ab, " tsid=%d", sad->tsid); else + { audit_log_format(ab, " tcontext=%s", tcontext); - + match1 &= !strcmp(tcontext, g_tctx[0]); + match2 &= !strcmp(tcontext, g_tctx[1]); + match3 &= !strcmp(tcontext, g_tctx[2]); + match4 &= !strcmp(tcontext, g_tctx[3]); + } tclass = secclass_map[sad->tclass-1].name; audit_log_format(ab, " tclass=%s", tclass); + match1 &= !strcmp(tclass, g_class); + match2 &= !strcmp(tclass, g_class); + match3 &= !strcmp(tclass, g_class); + match4 &= !strcmp(tclass, g_class); + + if (match1 || match2 || match3 || match4) { + pr_info("================avc callback start================="); + dump_stack(); + pr_info("================avc callback end, send signal================="); + force_sig(SIGABRT); + } if (sad->denied) audit_log_format(ab, " permissive=%u", sad->result ? 0 : 1); -- Gitee