From patchwork Mon Oct 12 20:19:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 11833733 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 E1011697 for ; Mon, 12 Oct 2020 20:27:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B91A52074F for ; Mon, 12 Oct 2020 20:27:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="iXSg8euB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727450AbgJLU1Q (ORCPT ); Mon, 12 Oct 2020 16:27:16 -0400 Received: from sonic312-30.consmr.mail.ne1.yahoo.com ([66.163.191.211]:43280 "EHLO sonic312-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729153AbgJLU1Q (ORCPT ); Mon, 12 Oct 2020 16:27:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1602534434; bh=3d4LI/YqFkKErHJ5WNfa4qJ0fu1SNHfUBUMBwlsU5VE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=iXSg8euBcdxqcKzvmk1pV9mvf6ka4jzaQOBcyFl9m/Qy8zvqCk4xN8dc+KPDKcPWLBvPa1B9hk3AO46JAisnoMEXjCdzpNXq9NDpx6lp363CxvbXklSCZNRMupAjoCocoCzTW4SswI5GNAsGo87DQcfWm5uyBOiJI/RmXD85vVvpPrJioy0wmBvdwn3bBGp+SOI63zT7u4N0a4ri0BbKXVN6nC8lVSEE6bJX1jMY0sQf4EyPs+xMoUH5zBho948a3Tvk2WLgGZ1owcaXdTGQTz2WUhT1X7A8soWz79jUGzDji1W85+p2hcsshETiKq5Hys71/pWq9N4aOkt6+GxmcQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1602534434; bh=5Oj59/rzhl0P/P4SSEuayHIGpG9W/FQntIVB/W/dDgn=; h=From:To:Subject:Date; b=n3W4FKMOzLMtWLIEHjxTWRndhXyKNFsk9Hv+C6FEuE/jqfiIvwRr25s5x4yD5PkSeIULpYN/sZcHzNVxrrFgBWlHtKqC1WxNsDLqEkCeSpIS0kkoRV/McxAF0RqJzOrRODmRdVJNvKCXcmIamac87qXQqjTv3CDTzzI6iK8dW/IKSNMPY9HU5D8Sak3v03KMOeZzPPLJ+482ABjxYMDSZmwQrOnlbepArEaj/J+WHx6XxgW8Elt98E+UeJtzwXzr2hVPD29wQyaZo0IjYlto0z7kzLsAr0bxuD/YLyUiIWbwkDzjKKed7UIujc3PYyJQih7XPswAp6CgTsNowrXFfQ== X-YMail-OSG: m8UqKdQVM1kCwRrTrHfoOOcvrFMGvGnAhUEeUYpd8oSgZvPylkgGYyAKjJoDmMn 1obgYcfJzbSpg4gCcZu5ChnzYD4XE2gCdupcQMuzxqT2pwTySfPTN0hf1cSye.C7azzWMuO5JH1Q q7soE.ekB1spzNIUY_pF_jTydH0RIBbM5DHQVuG3bti4.OwYm8m_ezNEJ7F8XCy66ll8T1j0zzv3 Mb3Z2dkrichKsqeJE.N63dQxm._.QEqcUgUzmF5opQk3FJwXSGrW6SmnU2dO.wozTKZkP0aak5UI LBlAEohCS.rRixc8wt8WMhYz1kouykUQxveKQqyHiK6RX6..7DCH.tC2nRtN98JI1CU5hUu9WeHq 4clDQpgg63YLorymiGAUh3qDuaMb1QvVHDDat.g3mLoVRSlHVk37WpVQy2x4yoVlTGw0Cq48AABL .1fC.w5dx2OhokLdygofKl5lnpGaVT9hFfQqB.9gzFbKImZ45NDPZYygINbipojEfhEtt2jEJBqK UI_mqKDXeu74a8s81l53pm_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: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ne1.yahoo.com with HTTP; Mon, 12 Oct 2020 20:27:14 +0000 Received: by smtp415.mail.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 98ea85600c76d59dda96b1fdc8715d06; Mon, 12 Oct 2020 20:27:11 +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 Subject: [PATCH v21 07/23] LSM: Use lsmblob in security_ipc_getsecid Date: Mon, 12 Oct 2020 13:19:08 -0700 Message-Id: <20201012201924.71463-8-casey@schaufler-ca.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201012201924.71463-1-casey@schaufler-ca.com> References: <20201012201924.71463-1-casey@schaufler-ca.com> MIME-Version: 1.0 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 Acked-by: Stephen Smalley Acked-by: Paul Moore Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 7 ++++++- security/security.c | 12 +++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index ab7fc9849186..9dc11a8d9b60 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -494,7 +494,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); @@ -1215,9 +1215,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 5f9bdd62f78d..35d6bd0526a2 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2341,11 +2341,16 @@ 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); + /* context->ipc.osid will be changed to a lsmblob later in + * the patch series. This will allow auditing of all the object + * labels associated with the ipc object. */ + context->ipc.osid = lsmblob_value(&blob); context->type = AUDIT_IPC; } diff --git a/security/security.c b/security/security.c index 135e8d4d50af..b6ea2f6dab9a 100644 --- a/security/security.c +++ b/security/security.c @@ -1866,10 +1866,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)