Skip to content

Commit 7f1f481

Browse files
Jeya Rgregkh
authored andcommitted
misc: fastrpc: check before loading process to the DSP
Reject session if DSP domain is secure, device node is non-secure and signed PD is requested. Secure device node can access DSP without any restriction. Unsigned PD offload is only allowed for the DSP domain that can support unsigned offloading. Signed-off-by: Jeya R <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3abe3ab commit 7f1f481

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

drivers/misc/fastrpc.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ struct fastrpc_channel_ctx {
244244
struct fastrpc_device *secure_fdevice;
245245
struct fastrpc_device *fdevice;
246246
bool secure;
247+
bool unsigned_support;
247248
};
248249

249250
struct fastrpc_device {
@@ -264,6 +265,7 @@ struct fastrpc_user {
264265

265266
int tgid;
266267
int pd;
268+
bool is_secure_dev;
267269
/* Lock for lists */
268270
spinlock_t lock;
269271
/* lock for allocations */
@@ -1052,6 +1054,24 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
10521054
return err;
10531055
}
10541056

1057+
static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_request)
1058+
{
1059+
/* Check if the device node is non-secure and channel is secure*/
1060+
if (!fl->is_secure_dev && fl->cctx->secure) {
1061+
/*
1062+
* Allow untrusted applications to offload only to Unsigned PD when
1063+
* channel is configured as secure and block untrusted apps on channel
1064+
* that does not support unsigned PD offload
1065+
*/
1066+
if (!fl->cctx->unsigned_support || !unsigned_pd_request) {
1067+
dev_err(&fl->cctx->rpdev->dev, "Error: Untrusted application trying to offload to signed PD");
1068+
return true;
1069+
}
1070+
}
1071+
1072+
return false;
1073+
}
1074+
10551075
static int fastrpc_init_create_process(struct fastrpc_user *fl,
10561076
char __user *argp)
10571077
{
@@ -1071,6 +1091,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
10711091
u32 siglen;
10721092
} inbuf;
10731093
u32 sc;
1094+
bool unsigned_module = false;
10741095

10751096
args = kcalloc(FASTRPC_CREATE_PROCESS_NARGS, sizeof(*args), GFP_KERNEL);
10761097
if (!args)
@@ -1081,6 +1102,14 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
10811102
goto err;
10821103
}
10831104

1105+
if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE)
1106+
unsigned_module = true;
1107+
1108+
if (is_session_rejected(fl, unsigned_module)) {
1109+
err = -ECONNREFUSED;
1110+
goto err;
1111+
}
1112+
10841113
if (init.filelen > INIT_FILELEN_MAX) {
10851114
err = -EINVAL;
10861115
goto err;
@@ -1280,6 +1309,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)
12801309
INIT_LIST_HEAD(&fl->user);
12811310
fl->tgid = current->tgid;
12821311
fl->cctx = cctx;
1312+
fl->is_secure_dev = fdevice->secure;
12831313

12841314
fl->sctx = fastrpc_session_alloc(cctx);
12851315
if (!fl->sctx) {
@@ -1958,11 +1988,14 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
19581988
case ADSP_DOMAIN_ID:
19591989
case MDSP_DOMAIN_ID:
19601990
case SDSP_DOMAIN_ID:
1991+
/* Unsigned PD offloading is only supported on CDSP*/
1992+
data->unsigned_support = false;
19611993
err = fastrpc_device_register(rdev, data, secure_dsp, domains[domain_id]);
19621994
if (err)
19631995
goto fdev_error;
19641996
break;
19651997
case CDSP_DOMAIN_ID:
1998+
data->unsigned_support = true;
19661999
/* Create both device nodes so that we can allow both Signed and Unsigned PD */
19672000
err = fastrpc_device_register(rdev, data, true, domains[domain_id]);
19682001
if (err)

include/uapi/misc/fastrpc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ enum fastrpc_map_flags {
4646
FASTRPC_MAP_MAX,
4747
};
4848

49+
enum fastrpc_proc_attr {
50+
/* Macro for Debug attr */
51+
FASTRPC_MODE_DEBUG = (1 << 0),
52+
/* Macro for Ptrace */
53+
FASTRPC_MODE_PTRACE = (1 << 1),
54+
/* Macro for CRC Check */
55+
FASTRPC_MODE_CRC = (1 << 2),
56+
/* Macro for Unsigned PD */
57+
FASTRPC_MODE_UNSIGNED_MODULE = (1 << 3),
58+
/* Macro for Adaptive QoS */
59+
FASTRPC_MODE_ADAPTIVE_QOS = (1 << 4),
60+
/* Macro for System Process */
61+
FASTRPC_MODE_SYSTEM_PROCESS = (1 << 5),
62+
/* Macro for Prvileged Process */
63+
FASTRPC_MODE_PRIVILEGED = (1 << 6),
64+
};
65+
4966
struct fastrpc_invoke_args {
5067
__u64 ptr;
5168
__u64 length;

0 commit comments

Comments
 (0)