Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1692197pxb; Fri, 24 Sep 2021 09:48:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM8HTUNO20dbz2p4JEl3ZLLi80jgDuqSRIkvnavS/9jmsCiFhyl3/nq4/LArrTDN3MBaGT X-Received: by 2002:a17:906:b2d3:: with SMTP id cf19mr12392764ejb.298.1632502115362; Fri, 24 Sep 2021 09:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632502115; cv=none; d=google.com; s=arc-20160816; b=fhaR5/MrHe9S4W3ZELFv5QnGI3PkMP8lz0NeeEjnn4VlKoM928Hlxz8ukLzf2+IjoG 2stVI2kmb9hYPOEP72nQwTEyxbfLvMH/aIYl/NkIt9bf9QOO4A5h6YJ6A9REpkaeMJhZ JTI0+eGIvP0cNkLeSEG8zybK3zB+nk5O03a0UpBpVgqmiaDBq0uBVLm9XTF0DqdabhgK CuyJwKi4BCR/JaSC25gcw2Nj76eOkeU2OSZTeAl1Ou+60wVbrFpn2dj/ge1agR5dcEa8 V9fpxiMVUWcRAXv5bambb1VB/IWuF3a08qf1wJmy+Fq8iKB3n2HApFVH9d3HZgyrKM8x KOJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=vcvUZ1tGYIju1PKVFOYLONY0FZSbIk9LkHsJVsQFir4=; b=BW9695YJIM2sJG6Zftn2eavZffCNeWheerF/gZRU/hxi9ME6gBjyfnqoQ/vu/Wru3b YZxitssywTXhose1iaL0irwSYe9GuoSFx3XQ3Pw8/CSN8InV3qJWFPKdciG8aX9obrZ5 MlmyKgFEjRuQrYp9/bf1/kOHUKc+lcd+un10/VdycdS47ZV0NNmKqCeVnCAYi/uCkAO4 q4yL6MLkDPUvrOZL4mQFbPwbJGTqRUXxiKj7eJ3So/5ylLt9KGo0YvvAegpNZ9wtZAbj JEWKnZX//I29FgxnFdxTLaW0N7rYQCR1g6SZnlqe7R/lxzqSrPadBOPuTqBzRrhrJEE3 r/Kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si9054579ejj.544.2021.09.24.09.48.04; Fri, 24 Sep 2021 09:48:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343489AbhIXMVH (ORCPT + 99 others); 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 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-kernel@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) { -- 2.7.4