From patchwork Fri Sep 24 12:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeya R X-Patchwork-Id: 12515177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4F32C433EF for ; Fri, 24 Sep 2021 12:19:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8909961164 for ; Fri, 24 Sep 2021 12:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245724AbhIXMVG (ORCPT ); Fri, 24 Sep 2021 08:21:06 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:54009 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245425AbhIXMVC (ORCPT ); Fri, 24 Sep 2021 08:21:02 -0400 Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 24 Sep 2021 05:19:28 -0700 X-QCInternal: smtphost Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/AES256-SHA; 24 Sep 2021 05:19:27 -0700 X-QCInternal: smtphost Received: from ekangupt-linux.qualcomm.com ([10.204.67.11]) by ironmsg02-blr.qualcomm.com with ESMTP; 24 Sep 2021 17:49:15 +0530 Received: by ekangupt-linux.qualcomm.com (Postfix, from userid 2319895) id 443FB3DE5; Fri, 24 Sep 2021 17:49:14 +0530 (IST) From: Jeya R To: linux-arm-msm@vger.kernel.org, srinivas.kandagatla@linaro.org Cc: Jeya R , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, fastrpc.upstream@qti.qualcomm.com Subject: [PATCH 1/4] dt-bindings: devicetree documentation for secure domain Date: Fri, 24 Sep 2021 17:49:08 +0530 Message-Id: <1632485951-13473-2-git-send-email-jeyr@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> References: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add information about secure domain property. Signed-off-by: Jeya R --- Documentation/devicetree/bindings/misc/qcom,fastrpc.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt b/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt index 2a1827a..276c1d1 100644 --- a/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt +++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt @@ -49,6 +49,12 @@ on the dsp. context bank. Defaults to 1 when this property is not specified. +- secure-domains: + Usage: Optional + Value type: + Definition: Specify DSP domain is secure, must be + "qcom,secure-domain" + Example: adsp-pil { From patchwork Fri Sep 24 12:19:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeya R X-Patchwork-Id: 12515181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6565C433FE for ; Fri, 24 Sep 2021 12:19:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A13B61268 for ; Fri, 24 Sep 2021 12:19:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245746AbhIXMVG (ORCPT ); Fri, 24 Sep 2021 08:21:06 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:54009 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245559AbhIXMVE (ORCPT ); Fri, 24 Sep 2021 08:21:04 -0400 Received: from ironmsg08-lv.qualcomm.com ([10.47.202.152]) by alexa-out.qualcomm.com with ESMTP; 24 Sep 2021 05:19:30 -0700 X-QCInternal: smtphost Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by ironmsg08-lv.qualcomm.com with ESMTP/TLS/AES256-SHA; 24 Sep 2021 05:19:29 -0700 X-QCInternal: smtphost Received: from ekangupt-linux.qualcomm.com ([10.204.67.11]) by ironmsg02-blr.qualcomm.com with ESMTP; 24 Sep 2021 17:49:15 +0530 Received: by ekangupt-linux.qualcomm.com (Postfix, from userid 2319895) id 4AD4E4312; Fri, 24 Sep 2021 17:49:14 +0530 (IST) From: Jeya R To: linux-arm-msm@vger.kernel.org, srinivas.kandagatla@linaro.org Cc: Jeya R , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, fastrpc.upstream@qti.qualcomm.com Subject: [PATCH 2/4] misc: fastrpc: Add secure device node support Date: Fri, 24 Sep 2021 17:49:09 +0530 Message-Id: <1632485951-13473-3-git-send-email-jeyr@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> References: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Register and deregister secure device node. Check for device name during device open get proper channel context. Signed-off-by: Jeya R --- drivers/misc/fastrpc.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index beda610..07c41a5 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -79,6 +79,7 @@ #define SENSORS_PD (2) #define miscdev_to_cctx(d) container_of(d, struct fastrpc_channel_ctx, miscdev) +#define securedev_to_cctx(d) container_of(d, struct fastrpc_channel_ctx, securedev) static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", "sdsp", "cdsp"}; @@ -213,6 +214,7 @@ struct fastrpc_channel_ctx { struct idr ctx_idr; struct list_head users; struct miscdevice miscdev; + struct miscdevice securedev; struct kref refcount; }; @@ -1214,10 +1216,23 @@ static int fastrpc_device_release(struct inode *inode, struct file *file) static int fastrpc_device_open(struct inode *inode, struct file *filp) { - struct fastrpc_channel_ctx *cctx = miscdev_to_cctx(filp->private_data); + struct fastrpc_channel_ctx *cctx = NULL; struct fastrpc_user *fl = NULL; + struct miscdevice *currdev = NULL; unsigned long flags; + if (!filp) + return -EFAULT; + + currdev = (struct miscdevice *)(filp->private_data); + if (!currdev) + return -EFAULT; + + if (strstr(currdev->name, "secure") != NULL) + cctx = securedev_to_cctx(filp->private_data); + else + cctx = miscdev_to_cctx(filp->private_data); + fl = kzalloc(sizeof(*fl), GFP_KERNEL); if (!fl) return -ENOMEM; @@ -1640,6 +1655,15 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) kfree(data); return err; } + data->securedev.minor = MISC_DYNAMIC_MINOR; + data->securedev.name = devm_kasprintf(rdev, GFP_KERNEL, + "fastrpc-%s-secure", domains[domain_id]); + data->securedev.fops = &fastrpc_fops; + err = misc_register(&data->securedev); + if (err) { + kfree(data); + return err; + } kref_init(&data->refcount); @@ -1651,7 +1675,11 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) data->domain_id = domain_id; data->rpdev = rpdev; - return of_platform_populate(rdev->of_node, NULL, NULL, rdev); + err = of_platform_populate(rdev->of_node, NULL, NULL, rdev); + dev_info(rdev, "%s done for %s with nodes non-secure(%d), secure(%d)" + "return: %d\n", __func__, domains[domain_id], + data->miscdev.minor, data->securedev.minor, err); + return err; } static void fastrpc_notify_users(struct fastrpc_user *user) @@ -1676,6 +1704,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) spin_unlock_irqrestore(&cctx->lock, flags); misc_deregister(&cctx->miscdev); + misc_deregister(&cctx->securedev); of_platform_depopulate(&rpdev->dev); cctx->rpdev = NULL; From patchwork Fri Sep 24 12:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeya R X-Patchwork-Id: 12515183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF48FC433F5 for ; Fri, 24 Sep 2021 12:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA146610C9 for ; Fri, 24 Sep 2021 12:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245760AbhIXMVH (ORCPT ); Fri, 24 Sep 2021 08:21:07 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:15766 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245562AbhIXMVE (ORCPT ); Fri, 24 Sep 2021 08:21:04 -0400 Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 24 Sep 2021 05:19:31 -0700 X-QCInternal: smtphost Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/AES256-SHA; 24 Sep 2021 05:19:30 -0700 X-QCInternal: smtphost Received: from ekangupt-linux.qualcomm.com ([10.204.67.11]) by ironmsg02-blr.qualcomm.com with ESMTP; 24 Sep 2021 17:49:15 +0530 Received: by ekangupt-linux.qualcomm.com (Postfix, from userid 2319895) id 5ED4D4314; Fri, 24 Sep 2021 17:49:14 +0530 (IST) From: Jeya R To: linux-arm-msm@vger.kernel.org, srinivas.kandagatla@linaro.org Cc: Jeya R , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, fastrpc.upstream@qti.qualcomm.com Subject: [PATCH 3/4] misc: fastrpc: Set channel as secure Date: Fri, 24 Sep 2021 17:49:10 +0530 Message-Id: <1632485951-13473-4-git-send-email-jeyr@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> References: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Set channel as secure based on domain ID and secure domain DT property. All DSP domains other than CDSP are set as secure by default and for CDSP domain, secure flag is set if property is added to DT file. Signed-off-by: Jeya R --- drivers/misc/fastrpc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 07c41a5..631713d 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -216,6 +216,7 @@ struct fastrpc_channel_ctx { struct miscdevice miscdev; struct miscdevice securedev; struct kref refcount; + bool secure; }; struct fastrpc_user { @@ -1646,6 +1647,12 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) if (!data) return -ENOMEM; + if (domain_id != CDSP_DOMAIN_ID) + data->secure = true; + else + data->secure = of_property_read_bool(rdev->of_node, + "qcom,secure-domain"); + data->miscdev.minor = MISC_DYNAMIC_MINOR; data->miscdev.name = devm_kasprintf(rdev, GFP_KERNEL, "fastrpc-%s", domains[domain_id]); From patchwork Fri Sep 24 12:19:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeya R X-Patchwork-Id: 12515179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EA45C433F5 for ; Fri, 24 Sep 2021 12:19:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E101E61107 for ; Fri, 24 Sep 2021 12:19:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245498AbhIXMVF (ORCPT ); Fri, 24 Sep 2021 08:21:05 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:15766 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245499AbhIXMVD (ORCPT ); Fri, 24 Sep 2021 08:21:03 -0400 Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 24 Sep 2021 05:19:30 -0700 X-QCInternal: smtphost Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/AES256-SHA; 24 Sep 2021 05:19:29 -0700 X-QCInternal: smtphost Received: from ekangupt-linux.qualcomm.com ([10.204.67.11]) by ironmsg02-blr.qualcomm.com with ESMTP; 24 Sep 2021 17:49:15 +0530 Received: by ekangupt-linux.qualcomm.com (Postfix, from userid 2319895) id 6F3534318; Fri, 24 Sep 2021 17:49:14 +0530 (IST) From: Jeya R To: linux-arm-msm@vger.kernel.org, srinivas.kandagatla@linaro.org Cc: Jeya R , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, fastrpc.upstream@qti.qualcomm.com Subject: [PATCH 4/4] misc: fastrpc: reject non-secure node for secure domain Date: Fri, 24 Sep 2021 17:49:11 +0530 Message-Id: <1632485951-13473-5-git-send-email-jeyr@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> References: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Reject session if domain is secure and device non-secure. Also check if opened device node is proper. Signed-off-by: Jeya R --- drivers/misc/fastrpc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 631713d..adf2700 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -235,6 +235,7 @@ struct fastrpc_user { spinlock_t lock; /* lock for allocations */ struct mutex mutex; + int dev_minor; }; static void fastrpc_free_map(struct kref *ref) @@ -1013,6 +1014,17 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, return err; } +static int is_session_rejected(struct fastrpc_user *fl) +{ + /* Check if the device node is non-secure and channel is secure*/ + if ((fl->dev_minor == fl->cctx->miscdev.minor) && fl->cctx->secure) { + dev_err(&fl->cctx->rpdev->dev, "Cannot use non-secure device" + "node on secure channel\n"); + return -EACCES; + } + return 0; +} + static int fastrpc_init_create_process(struct fastrpc_user *fl, char __user *argp) { @@ -1033,6 +1045,10 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, } inbuf; u32 sc; + err = is_session_rejected(fl); + if (err) + return err; + args = kcalloc(FASTRPC_CREATE_PROCESS_NARGS, sizeof(*args), GFP_KERNEL); if (!args) return -ENOMEM; @@ -1221,6 +1237,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) struct fastrpc_user *fl = NULL; struct miscdevice *currdev = NULL; unsigned long flags; + int dev_minor = MINOR(inode->i_rdev); if (!filp) return -EFAULT; @@ -1234,6 +1251,12 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) else cctx = miscdev_to_cctx(filp->private_data); + if (!((dev_minor == cctx->miscdev.minor) || + (dev_minor == cctx->securedev.minor))) { + dev_err(&cctx->rpdev->dev, "Device node is not proper\n"); + return -EFAULT; + } + fl = kzalloc(sizeof(*fl), GFP_KERNEL); if (!fl) return -ENOMEM; @@ -1250,6 +1273,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) INIT_LIST_HEAD(&fl->user); fl->tgid = current->tgid; fl->cctx = cctx; + fl->dev_minor = dev_minor; fl->sctx = fastrpc_session_alloc(cctx); if (!fl->sctx) {