From: Jeya R <jeyr@codeaurora.org>
To: linux-arm-msm@vger.kernel.org, srinivas.kandagatla@linaro.org
Cc: Jeya R <jeyr@codeaurora.org>,
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 [thread overview]
Message-ID: <1632485951-13473-5-git-send-email-jeyr@codeaurora.org> (raw)
In-Reply-To: <1632485951-13473-1-git-send-email-jeyr@codeaurora.org>
Reject session if domain is secure and device non-secure. Also check if
opened device node is proper.
Signed-off-by: Jeya R <jeyr@codeaurora.org>
---
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
next prev parent reply other threads:[~2021-09-24 12:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-24 12:19 [PATCH 0/4] Add secure domains support Jeya R
2021-09-24 12:19 ` [PATCH 1/4] dt-bindings: devicetree documentation for secure domain Jeya R
2021-09-29 14:06 ` Srinivas Kandagatla
2021-09-24 12:19 ` [PATCH 2/4] misc: fastrpc: Add secure device node support Jeya R
2021-09-24 12:19 ` [PATCH 3/4] misc: fastrpc: Set channel as secure Jeya R
2021-09-29 14:07 ` Srinivas Kandagatla
2021-09-24 12:19 ` Jeya R [this message]
2021-09-29 14:06 ` [PATCH 4/4] misc: fastrpc: reject non-secure node for secure domain Srinivas Kandagatla
2021-09-29 14:06 ` [PATCH 0/4] Add secure domains support Srinivas Kandagatla
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1632485951-13473-5-git-send-email-jeyr@codeaurora.org \
--to=jeyr@codeaurora.org \
--cc=fastrpc.upstream@qti.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.kandagatla@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox