From patchwork Thu Feb 28 22:18:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10834073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05F8D139A for ; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED7EC2F3D1 for ; Thu, 28 Feb 2019 22:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBEFE2F3FF; Thu, 28 Feb 2019 22:20:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E5242FC96 for ; Thu, 28 Feb 2019 22:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726088AbfB1WUk (ORCPT ); Thu, 28 Feb 2019 17:20:40 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:38657 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729931AbfB1WUH (ORCPT ); Thu, 28 Feb 2019 17:20:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=RkkT8VCXXloma0Fq/QmxeKgnWLosnAsoKiC6R1t6xs0=; h=From:To:Cc:Subject:Date:In-Reply-To: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Zx.kpnxIoGk6.9JZovbSP9fmljt06adbBoC jgBW7AtboDANT8qXeTnOtfVdreYXeHL77NAHKYxsUFen.0iH3Cbv1OKN5D6JyEOEPFK32kqOl.rN mg0mBf5wj27_hgGHnyTbxJI8SDuEhx3kaSpM902y5KlELy8S78iyLPQ5y953.bPjffdhAWB3ET.J dux0BwmCq8bTjRndeUHEy8z_kTxbzGPlAWGFeRdEElFO7sIfOs.au2CnEH9.tHXTmTnVK50HHfhr KVvsAWW643_OzsYPneDxXCvwa__NZbaxs2q6nWxEFwDTDOOqRRQ_gpseQcImuZjLuJzmrQMHqKMQ s2yT_7bkHAvWg.bt3ft_xCfG4yBzL_g1XjW6VLiFIw1QbuRp6fuhew8c0D37ozz5.B6_7iP7dGuV YZciNRm3lXQg4WeTmiThDBIq8IntpvhD4Ez2yDXFfBtBrF3g- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 30/97] Audit: Convert target_sid to an lsm_export structure Date: Thu, 28 Feb 2019 14:18:26 -0800 Message-Id: <20190228221933.2551-31-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Convert target_sid to be an lsm_export structure instead of a u32 secid. Clean out the associated scaffolding. Change the name to target_lsm to be descriptive. Signed-off-by: Casey Schaufler --- kernel/audit.h | 3 ++- kernel/auditsc.c | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/kernel/audit.h b/kernel/audit.h index 06c732e0f301..63883a773aa2 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -146,7 +147,7 @@ struct audit_context { kuid_t target_auid; kuid_t target_uid; unsigned int target_sessionid; - u32 target_sid; + struct lsm_export target_lsm; char target_comm[TASK_COMM_LEN]; struct audit_tree_refs *trees, *first_trees; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index c57c2e346c6d..2ee74d18c90c 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -112,7 +112,7 @@ struct audit_aux_data_pids { kuid_t target_auid[AUDIT_AUX_PIDS]; kuid_t target_uid[AUDIT_AUX_PIDS]; unsigned int target_sessionid[AUDIT_AUX_PIDS]; - u32 target_sid[AUDIT_AUX_PIDS]; + struct lsm_export target_lsm[AUDIT_AUX_PIDS]; char target_comm[AUDIT_AUX_PIDS][TASK_COMM_LEN]; int pid_count; }; @@ -934,14 +934,14 @@ static inline void audit_free_context(struct audit_context *context) } static int audit_log_pid_context(struct audit_context *context, pid_t pid, - kuid_t auid, kuid_t uid, unsigned int sessionid, - u32 sid, char *comm) + kuid_t auid, kuid_t uid, + unsigned int sessionid, + struct lsm_export *l, char *comm) { struct audit_buffer *ab; char *ctx = NULL; u32 len; int rc = 0; - struct lsm_export le; ab = audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID); if (!ab) @@ -950,9 +950,8 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, from_kuid(&init_user_ns, auid), from_kuid(&init_user_ns, uid), sessionid); - if (sid) { - lsm_export_to_all(&le, sid); - if (security_secid_to_secctx(&le, &ctx, &len)) { + if (lsm_export_any(l)) { + if (security_secid_to_secctx(l, &ctx, &len)) { audit_log_format(ab, " obj=(none)"); rc = 1; } else { @@ -1401,7 +1400,7 @@ static void audit_log_exit(void) axs->target_auid[i], axs->target_uid[i], axs->target_sessionid[i], - axs->target_sid[i], + &axs->target_lsm[i], axs->target_comm[i])) call_panic = 1; } @@ -1410,7 +1409,7 @@ static void audit_log_exit(void) audit_log_pid_context(context, context->target_pid, context->target_auid, context->target_uid, context->target_sessionid, - context->target_sid, context->target_comm)) + &context->target_lsm, context->target_comm)) call_panic = 1; if (context->pwd.dentry && context->pwd.mnt) { @@ -1587,7 +1586,7 @@ void __audit_syscall_exit(int success, long return_code) context->aux = NULL; context->aux_pids = NULL; context->target_pid = 0; - context->target_sid = 0; + lsm_export_init(&context->target_lsm); context->sockaddr_len = 0; context->type = 0; context->fds[0] = -1; @@ -2260,14 +2259,12 @@ int __audit_sockaddr(int len, void *a) void __audit_ptrace(struct task_struct *t) { struct audit_context *context = audit_context(); - struct lsm_export le; context->target_pid = task_tgid_nr(t); context->target_auid = audit_get_loginuid(t); context->target_uid = task_uid(t); context->target_sessionid = audit_get_sessionid(t); - security_task_getsecid(t, &le); - lsm_export_secid(&le, &context->target_sid); + security_task_getsecid(t, &context->target_lsm); memcpy(context->target_comm, t->comm, TASK_COMM_LEN); } @@ -2284,7 +2281,6 @@ int audit_signal_info(int sig, struct task_struct *t) struct audit_aux_data_pids *axp; struct audit_context *ctx = audit_context(); kuid_t uid = current_uid(), auid, t_uid = task_uid(t); - struct lsm_export le; if (auditd_test_task(t) && (sig == SIGTERM || sig == SIGHUP || @@ -2308,8 +2304,7 @@ int audit_signal_info(int sig, struct task_struct *t) ctx->target_auid = audit_get_loginuid(t); ctx->target_uid = t_uid; ctx->target_sessionid = audit_get_sessionid(t); - security_task_getsecid(t, &le); - lsm_export_secid(&le, &ctx->target_sid); + security_task_getsecid(t, &ctx->target_lsm); memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); return 0; } @@ -2330,8 +2325,7 @@ int audit_signal_info(int sig, struct task_struct *t) axp->target_auid[axp->pid_count] = audit_get_loginuid(t); axp->target_uid[axp->pid_count] = t_uid; axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); - security_task_getsecid(t, &le); - lsm_export_secid(&le, &axp->target_sid[axp->pid_count]); + security_task_getsecid(t, &axp->target_lsm[axp->pid_count]); memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); axp->pid_count++;