From patchwork Wed Nov 27 21:37:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 11264941 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 2387A112B for ; Wed, 27 Nov 2019 21:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01D1220869 for ; Wed, 27 Nov 2019 21:37:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="JbjyYRC1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727231AbfK0Vhp (ORCPT ); Wed, 27 Nov 2019 16:37:45 -0500 Received: from sonic311-30.consmr.mail.ne1.yahoo.com ([66.163.188.211]:39146 "EHLO sonic311-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728303AbfK0Vho (ORCPT ); Wed, 27 Nov 2019 16:37:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1574890663; bh=nOGEMAW5jBKyAP5FeUHiTRQqQX9FokxNc+64zG2jbZY=; h=From:To:Subject:Date:In-Reply-To:References:From:Subject; b=JbjyYRC17SdYnn9A01ZI5eBUv8I3WVWCk9ElkB9dXStkrMukSXNLOamDMTz5Rgv5IynaCuESKttaUruDGdwHkMA7f/CDbFcrXnd4QdH+vWIDZyoUhOPdt+SH9CVTm8BozIOwn8Krp4MwsBt+0MYmLFGQU/Lxo/BXijDhSZeifSZ/Gzf6E1pNQVQHwJZ+ONSw2udtKIAqKdtdXTKU70GO1jaFnntxitqVPO5CjV2a2S8RjdpMpnTedbCv9Hm27fXqEZEqE7mNFShnrndFwenhw/zAjIpwK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3X.4HXHxLEy3b_imCgOH2oYXOpauFT0ozvmmumWk2t_N tvCTBAFOTCqKm6gz3ZOkSURXBT5BGjIIVTSaqYN_1dhFBNuGp3mrS7nZYc2_rJunxR83d_04w1Vj AyjyA9IZWiLEqbxFDqxqDwEg2Gye9AaHMlH2qOpqkJhpq2TaJjMIOc3WCKkh0iebxwkVR.fc5jkU P_45nvKepgOOv8rzOD6drXJlcgp_vTwIBoYJXBxtijQBydHpegmeFEZj5jl_H.8XC3n4eua.PdJt xnhUKCkDl.W2keDKa.v40w7fWHooay.hDPBmrvrMLWN4uhxkJnaGKJLbAdxbj9leEQN4YM5nwX0i kjGVOCEmRxAJUraVFsPi0l_Muyf1rc3VSzslBXRr0_4Xr7.eYAG_VqbiObx94GHNbb7vZe2FJnh1 um_sACqtIzK2mW4xOiIURv5yCkV1ZJWawKU97VxNfhRusXj8Za_h0 Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Wed, 27 Nov 2019 21:37:43 +0000 Received: by smtp411.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 1acf01b6929c230fae5ce1ab34c8a381; Wed, 27 Nov 2019 21:37:41 +0000 (UTC) From: Casey Schaufler To: linux-integrity@vger.kernel.org, zohar@linux.ibm.com Subject: [v11-ima PATCH 08/25] LSM: Use lsmblob in security_ipc_getsecid Date: Wed, 27 Nov 2019 13:37:01 -0800 Message-Id: <20191127213718.18267-9-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127213718.18267-1-casey@schaufler-ca.com> References: <20191127213718.18267-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@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 2160c160e62c..6dda1ddcae31 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -463,7 +463,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); @@ -1171,9 +1171,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 04803c3099b2..ce8bf2d8f8d2 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2285,11 +2285,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 0fc75a31a6bb..b60c6a51f622 100644 --- a/security/security.c +++ b/security/security.c @@ -1783,10 +1783,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)