From patchwork Thu Oct 24 20:52:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 11210765 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11CB713B1 for ; Thu, 24 Oct 2019 20:53:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E434421A4C for ; Thu, 24 Oct 2019 20:53:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="LKpCiclB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728632AbfJXUxi (ORCPT ); Thu, 24 Oct 2019 16:53:38 -0400 Received: from sonic311-22.consmr.mail.bf2.yahoo.com ([74.6.131.196]:43004 "EHLO sonic311-22.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728621AbfJXUxi (ORCPT ); Thu, 24 Oct 2019 16:53:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1571950417; bh=SzhkUBMInZW21eDTVaDgtuRnxZhqJtkvtFFiFP3irFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=LKpCiclBQSq8FB1ctpS3DF/mhXKOQ/DMzf/msNtJ3FTnS1PujSrZiQRtahHjY/osqW3pRaF7B97qDZlX8AHASr0+7K17chVTXmC6n3IXW/GIBp0rn1dVsmK6f3imxzre06Tyar7pB23YkpoJ09mRm4gBm1BgrJ+YgD1KguXILH+vrD5D250iqK2BDdzMTGeCK1mspm0jvetDgNddv34W2x08jJfLYY5qY0x5WjCLNqyeCl+2dCBxP2Dbk9EbCggYW8jGubXVJvgkC26ZvP/BklNrWu9BVobIMpX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7aUQLgfbjxFG4j3Pqrp5hogSMsqePxV.rUjetknr srVZoBXVUWi.R3dJ3DH1mkedRG1j7jnCjX0_Bm3graKh._oJ9l8K.3.A99KIu0lh6zf8m1ds3IAh vlc.sPxgu3ACl.SUDdj6Mm2Dhct.Y1SOeDj8l7Tdor6uZ1.Z8b0avRtYYAbHOQvwjn2c1LOwVxjq C8CIB5zaysxVivaVHzEn3p6deHWhUkBk4d4HYjajt2gh3Uw3VSwQvHaUnpYQA5Rqb78namUpFdwk 2BkIb2wADqku6dHyMi11YrnmRm1gotLZoyZcqrKz4eypIaQG99E77k_0yEQFN2dDUA_qjq9dhrtP n5B.dtJF0zxn2gDxArrfSHDCjQKGei9u2kPjOQN5yvw9k5czKEZmuQTQVpA177bc1bODfKijumm1 QC7yHGYeWxJhoXYuliH0QBw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.bf2.yahoo.com with HTTP; Thu, 24 Oct 2019 20:53:37 +0000 Received: by smtp403.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0cc137411481ced1a298f2ec2316752a; Thu, 24 Oct 2019 20:53:33 +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, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH v10 08/25] LSM: Use lsmblob in security_ipc_getsecid Date: Thu, 24 Oct 2019 13:52:11 -0700 Message-Id: <20191024205228.6922-9-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191024205228.6922-1-casey@schaufler-ca.com> References: <20191024205228.6922-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org There may be more than one LSM that provides IPC data for auditing. Change security_ipc_getsecid() to fill in a lsmblob structure instead of the u32 secid. The audit data structure containing the secid will be updated later, so there is a bit of scaffolding here. Reviewed-by: Kees Cook Reviewed-by: John Johansen Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 5 ++++- security/security.c | 12 +++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 6add7925bfba..a1659fba6afe 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -409,7 +409,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); void security_task_to_inode(struct task_struct *p, struct inode *inode); int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); -void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid); +void security_ipc_getsecid(struct kern_ipc_perm *ipcp, struct lsmblob *blob); int security_msg_msg_alloc(struct msg_msg *msg); void security_msg_msg_free(struct msg_msg *msg); int security_msg_queue_alloc(struct kern_ipc_perm *msq); @@ -1094,9 +1094,10 @@ static inline int security_ipc_permission(struct kern_ipc_perm *ipcp, return 0; } -static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, + struct lsmblob *blob) { - *secid = 0; + lsmblob_init(blob, 0); } static inline int security_msg_msg_alloc(struct msg_msg *msg) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index d31914088a82..148733ec3c72 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2268,11 +2268,14 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat) void __audit_ipc_obj(struct kern_ipc_perm *ipcp) { struct audit_context *context = audit_context(); + struct lsmblob blob; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm = 0; - security_ipc_getsecid(ipcp, &context->ipc.osid); + security_ipc_getsecid(ipcp, &blob); + /* scaffolding on the [0] - change "osid" to a lsmblob */ + context->ipc.osid = blob.secid[0]; context->type = AUDIT_IPC; } diff --git a/security/security.c b/security/security.c index 121e395a39ff..e4b50ae05f6c 100644 --- a/security/security.c +++ b/security/security.c @@ -1734,10 +1734,16 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) return call_int_hook(ipc_permission, 0, ipcp, flag); } -void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +void security_ipc_getsecid(struct kern_ipc_perm *ipcp, struct lsmblob *blob) { - *secid = 0; - call_void_hook(ipc_getsecid, ipcp, secid); + struct security_hook_list *hp; + + lsmblob_init(blob, 0); + hlist_for_each_entry(hp, &security_hook_heads.ipc_getsecid, list) { + if (WARN_ON(hp->lsmid->slot < 0 || hp->lsmid->slot >= lsm_slot)) + continue; + hp->hook.ipc_getsecid(ipcp, &blob->secid[hp->lsmid->slot]); + } } int security_msg_msg_alloc(struct msg_msg *msg)