From patchwork Fri Jun 21 18:52:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 11010595 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 E0BA714E5 for ; Fri, 21 Jun 2019 18:53:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D33DF28B18 for ; Fri, 21 Jun 2019 18:53:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C71D928B1F; Fri, 21 Jun 2019 18:53:09 +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 6D03F28B24 for ; Fri, 21 Jun 2019 18:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726374AbfFUSxJ (ORCPT ); Fri, 21 Jun 2019 14:53:09 -0400 Received: from sonic309-22.consmr.mail.bf2.yahoo.com ([74.6.129.196]:38995 "EHLO sonic309-22.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfFUSxI (ORCPT ); Fri, 21 Jun 2019 14:53:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1561143187; bh=yCC/VzUj6gjmQev+Yws3dylDQvcIzi1gLYUF2+WQlAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From: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MVN.Mwd.ctVxYs2RCTeMFLsdBsQkm6gmiP4m06D2tqRguKGyDsLTS yYIJP_7dqS2uGwPQSOFer6R1n9sboMtV8Xm9dHXQ_0UZ9QiZLLY6dI.sMUUEVvDYCkdWgGSa36pB CRVOO6eO0JV4zd4.XyAhvlSlqJzZe5FgJS.Wj7XceBThrvp2ZKzIo1QNZqJnfflfUmtaAJF4y4I5 5HwBRnOZB1f.Kjh3B77o0scj2ezYoJt1hYe2rXkVHGQ3BcSnkJ4yVoQqj.CnfTNCeraafA9entip d2Ci9p.4uFdJ1JwHiS64bwluiaZGLG9jwcKO9vGbFTcfTA3mH0007UiWrgdyLOfejq9SGe3AkVk3 F76L.kSV26cWhdnD2SSmrATcpqiY6NX.Z7CAllvtSRVlup8wI6wC.Hp6eVmfPiee_geNGRZC8Mmd 3UpMikpzWQvP1Mkdwq2Xm58Jc5dELwX.Vq3tAAUSJfwACUNyYxqY2ZYe9fjIsFxswkVIdTMrwO3I srPSZ9g4bF.d5Yt99j8ZW6TXMoO7g8w2DrTxS2PnMZOnhAv_12bKMJrycShlFXFLTJ4xKOFe11Io yrPzv40b1mmr9RO5DEZ5jKkpkNqvvMK11G.ibsIpYMjpr8g-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.bf2.yahoo.com with HTTP; Fri, 21 Jun 2019 18:53:07 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 989e9db4908b36ea4a327798a97c8ae5; Fri, 21 Jun 2019 18:53:02 +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 v3 10/24] Use lsmblob in security_ipc_getsecid Date: Fri, 21 Jun 2019 11:52:19 -0700 Message-Id: <20190621185233.6766-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621185233.6766-1-casey@schaufler-ca.com> References: <20190621185233.6766-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Casey Schaufler Reviewed-by: Kees Cook Reviewed-by: John Johansen --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 5 ++++- security/security.c | 9 ++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index c6cddeff8a17..0d5e172341fc 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -413,7 +413,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); @@ -1098,9 +1098,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 5ab07631df75..d55f01041f05 100644 --- a/security/security.c +++ b/security/security.c @@ -1812,10 +1812,13 @@ 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) + hp->hook.ipc_getsecid(ipcp, &blob->secid[hp->slot]); } int security_msg_msg_alloc(struct msg_msg *msg)