From patchwork Mon Dec 13 23:40:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12674925 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEAE5C433F5 for ; Mon, 13 Dec 2021 23:47:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243157AbhLMXr0 (ORCPT ); Mon, 13 Dec 2021 18:47:26 -0500 Received: from sonic315-27.consmr.mail.ne1.yahoo.com ([66.163.190.153]:40282 "EHLO sonic315-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243150AbhLMXrY (ORCPT ); Mon, 13 Dec 2021 18:47:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1639439244; bh=jT4PVItnczWnZdcyjvqnskftXdrHFa03HpMlVEGDCsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=HPp/ARJv5rLx4AeDAKfUvHDj/bAQ44J/AAGJgHnotKwH/ikvRMPZ1oqU/OUK18hbiCErzq7CS+GOXkYQvKaNdyUEvkIhbpjAdJ/ccxWol7qhyYpMr12QdrhTlheYt6Xfqby2KgddzYJ5qYF9OEXZoZoDpagyHEaQOGfUgIc8fiXJDVu0inTeNmIP9kPLkJJr0aexYaCkA+NJ/NmxHOpVvQhOtJ2jxB3OeSYHAl7BurDeKbJnTyjkcLXqqA3kQxyyrTD/6jvMNzp/1EM87SFhG6vQ4NtaeDd5wqsgv70kqGoZb2kO8n39TpO9o8Be/O4IGloMcKZMPPwvFXaNxWyPmQ== X-SONIC-DKIM-SIGN: v=1; a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9iweCWAJD5g8awZGCieY _TGbuCz7nauYutIbmCmNqpwDdd2_bn7PkQVuy72KDDD872fStXFqBvijJYDECPb0VllOnWqJCDZs Ej7ZY5OcbSUV27i1x9ad6tgnMeJ1vLtnUsUxDjd8uiOFDzsMYQQl0xtRNSuLc4N9EtTpnstgmaXW IMvXe2oSS7gNbJSyzPIqctH3CwZZNw622419XB6huuqNCc8ws4CIzwSzv5NDM9K3RMELlDBwOWRo _rU7pW6Qw3NakCn7s5isneFo9EVPvU5oMiD1W88htFjqQd6jJS8snDC0uE3bsY2WbVHqhhDNTL12 LLsgu5jh_r2PuEgotVQknES76z2RaeWAE6.TddRiUf2CQfTPVruxD4J0VAxDQc0GguuZnC6h3swx lz0ZYBfMvPdQm8Rp45leVQEcA6oFCmeAyA6cyRGJSH0KF7CsGOyPOYcxMnWEd9r9lsQu7Puc538z XiFRVtjQhZnctek4dDOiqexiHI8XRh1Gf8J9dhKOMUD.WHseUDpAkdjyYygjFs4V0RsELVoY3WR5 0NPy9o2vxKnfMlxmMfAb_Ox31wDUmLOu577Qwpi1l3NcfnnghZMfm00HCSv0x6VI7YhEPQkYPhc. zEFVK6RsGOr_G12sPhTnU05Rk0m.3NcCG X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Mon, 13 Dec 2021 23:47:24 +0000 Received: by kubenode521.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 8c2b01bd5b69dc97b5d7e5a25e3d4d3e; Mon, 13 Dec 2021 23:47:21 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org Subject: [PATCH v31 06/28] LSM: Use lsmblob in security_audit_rule_match Date: Mon, 13 Dec 2021 15:40:12 -0800 Message-Id: <20211213234034.111891-7-casey@schaufler-ca.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211213234034.111891-1-casey@schaufler-ca.com> References: <20211213234034.111891-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Change the secid parameter of security_audit_rule_match to a lsmblob structure pointer. Pass the entry from the lsmblob structure for the approprite slot to the LSM hook. Change the users of security_audit_rule_match to use the lsmblob instead of a u32. The scaffolding function lsmblob_init() fills the blob with the value of the old secid, ensuring that it is available to the appropriate module hook. The sources of the secid, security_task_getsecid() and security_inode_getsecid(), will be converted to use the blob structure later in the series. At the point the use of lsmblob_init() is dropped. Signed-off-by: Casey Schaufler Acked-by: Paul Moore Cc: linux-audit@redhat.com --- include/linux/security.h | 5 +++-- kernel/auditfilter.c | 6 ++++-- kernel/auditsc.c | 16 +++++++++++----- security/security.c | 5 +++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 9b853796bd4f..5a29b9bfdeda 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -1954,7 +1954,7 @@ static inline int security_key_getsecurity(struct key *key, char **_buffer) int security_audit_rule_init(u32 field, u32 op, char *rulestr, struct audit_lsm_rules *lsmrules); int security_audit_rule_known(struct audit_krule *krule); -int security_audit_rule_match(u32 secid, u32 field, u32 op, +int security_audit_rule_match(struct lsmblob *blob, u32 field, u32 op, struct audit_lsm_rules *lsmrules); void security_audit_rule_free(struct audit_lsm_rules *lsmrules); @@ -1971,7 +1971,8 @@ static inline int security_audit_rule_known(struct audit_krule *krule) return 0; } -static inline int security_audit_rule_match(u32 secid, u32 field, u32 op, +static inline int security_audit_rule_match(struct lsmblob *blob, + u32 field, u32 op, struct audit_lsm_rules *lsmrules) { return 0; diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index c6b25bf0b323..88a8d69d03dd 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1337,6 +1337,7 @@ int audit_filter(int msgtype, unsigned int listtype) for (i = 0; i < e->rule.field_count; i++) { struct audit_field *f = &e->rule.fields[i]; + struct lsmblob blob; pid_t pid; u32 sid; @@ -1370,8 +1371,9 @@ int audit_filter(int msgtype, unsigned int listtype) if (f->lsm_str) { security_task_getsecid_subj(current, &sid); - result = security_audit_rule_match(sid, - f->type, f->op, + lsmblob_init(&blob, sid); + result = security_audit_rule_match( + &blob, f->type, f->op, &f->lsm_rules); } break; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 194a62d86578..e0c71fe27c2f 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -468,6 +468,7 @@ static int audit_filter_rules(struct task_struct *tsk, const struct cred *cred; int i, need_sid = 1; u32 sid; + struct lsmblob blob; unsigned int sessionid; if (ctx && rule->prio <= ctx->prio) @@ -669,8 +670,10 @@ static int audit_filter_rules(struct task_struct *tsk, security_task_getsecid_subj(tsk, &sid); need_sid = 0; } - result = security_audit_rule_match(sid, f->type, - f->op, &f->lsm_rules); + lsmblob_init(&blob, sid); + result = security_audit_rule_match(&blob, + f->type, f->op, + &f->lsm_rules); } break; case AUDIT_OBJ_USER: @@ -683,15 +686,17 @@ static int audit_filter_rules(struct task_struct *tsk, if (f->lsm_str) { /* Find files that match */ if (name) { + lsmblob_init(&blob, name->osid); result = security_audit_rule_match( - name->osid, + &blob, f->type, f->op, &f->lsm_rules); } else if (ctx) { list_for_each_entry(n, &ctx->names_list, list) { + lsmblob_init(&blob, n->osid); if (security_audit_rule_match( - n->osid, f->type, f->op, + &blob, f->type, f->op, &f->lsm_rules)) { ++result; break; @@ -701,7 +706,8 @@ static int audit_filter_rules(struct task_struct *tsk, /* Find ipc objects that match */ if (!ctx || ctx->type != AUDIT_IPC) break; - if (security_audit_rule_match(ctx->ipc.osid, + lsmblob_init(&blob, ctx->ipc.osid); + if (security_audit_rule_match(&blob, f->type, f->op, &f->lsm_rules)) ++result; diff --git a/security/security.c b/security/security.c index 580ef0c40be7..3ad3aa74c59d 100644 --- a/security/security.c +++ b/security/security.c @@ -2680,7 +2680,7 @@ void security_audit_rule_free(struct audit_lsm_rules *lsmrules) } } -int security_audit_rule_match(u32 secid, u32 field, u32 op, +int security_audit_rule_match(struct lsmblob *blob, u32 field, u32 op, struct audit_lsm_rules *lsmrules) { struct security_hook_list *hp; @@ -2691,7 +2691,8 @@ int security_audit_rule_match(u32 secid, u32 field, u32 op, continue; if (lsmrules->rule[hp->lsmid->slot] == NULL) continue; - rc = hp->hook.audit_rule_match(secid, field, op, + rc = hp->hook.audit_rule_match(blob->secid[hp->lsmid->slot], + field, op, &lsmrules->rule[hp->lsmid->slot]); if (rc) return rc;