diff options
Diffstat (limited to 'drivers/misc/fastrpc.c')
| -rw-r--r-- | drivers/misc/fastrpc.c | 41 | 
1 files changed, 32 insertions, 9 deletions
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 4c67e2c5a82e..a7a2bcedb37e 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1238,6 +1238,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,  	struct fastrpc_phy_page pages[1];  	char *name;  	int err; +	bool scm_done = false;  	struct {  		int pgid;  		u32 namelen; @@ -1289,6 +1290,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,  					fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err);  				goto err_map;  			} +			scm_done = true;  		}  	} @@ -1320,10 +1322,11 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,  		goto err_invoke;  	kfree(args); +	kfree(name);  	return 0;  err_invoke: -	if (fl->cctx->vmcount) { +	if (fl->cctx->vmcount && scm_done) {  		u64 src_perms = 0;  		struct qcom_scm_vmperm dst_perms;  		u32 i; @@ -1693,16 +1696,20 @@ static int fastrpc_get_info_from_dsp(struct fastrpc_user *fl, uint32_t *dsp_attr  {  	struct fastrpc_invoke_args args[2] = { 0 }; -	/* Capability filled in userspace */ +	/* +	 * Capability filled in userspace. This carries the information +	 * about the remoteproc support which is fetched from the remoteproc +	 * sysfs node by userspace. +	 */  	dsp_attr_buf[0] = 0; +	dsp_attr_buf_len -= 1;  	args[0].ptr = (u64)(uintptr_t)&dsp_attr_buf_len;  	args[0].length = sizeof(dsp_attr_buf_len);  	args[0].fd = -1;  	args[1].ptr = (u64)(uintptr_t)&dsp_attr_buf[1]; -	args[1].length = dsp_attr_buf_len; +	args[1].length = dsp_attr_buf_len * sizeof(u32);  	args[1].fd = -1; -	fl->pd = USER_PD;  	return fastrpc_internal_invoke(fl, true, FASTRPC_DSP_UTILITIES_HANDLE,  				       FASTRPC_SCALARS(0, 1, 1), args); @@ -1730,7 +1737,7 @@ static int fastrpc_get_info_from_kernel(struct fastrpc_ioctl_capability *cap,  	if (!dsp_attributes)  		return -ENOMEM; -	err = fastrpc_get_info_from_dsp(fl, dsp_attributes, FASTRPC_MAX_DSP_ATTRIBUTES_LEN); +	err = fastrpc_get_info_from_dsp(fl, dsp_attributes, FASTRPC_MAX_DSP_ATTRIBUTES);  	if (err == DSP_UNSUPPORTED_API) {  		dev_info(&cctx->rpdev->dev,  			 "Warning: DSP capabilities not supported on domain: %d\n", domain); @@ -1783,7 +1790,7 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp)  	if (err)  		return err; -	if (copy_to_user(argp, &cap.capability, sizeof(cap.capability))) +	if (copy_to_user(argp, &cap, sizeof(cap)))  		return -EFAULT;  	return 0; @@ -2080,6 +2087,16 @@ err_invoke:  	return err;  } +static int is_attach_rejected(struct fastrpc_user *fl) +{ +	/* Check if the device node is non-secure */ +	if (!fl->is_secure_dev) { +		dev_dbg(&fl->cctx->rpdev->dev, "untrusted app trying to attach to privileged DSP PD\n"); +		return -EACCES; +	} +	return 0; +} +  static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,  				 unsigned long arg)  { @@ -2092,13 +2109,19 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,  		err = fastrpc_invoke(fl, argp);  		break;  	case FASTRPC_IOCTL_INIT_ATTACH: -		err = fastrpc_init_attach(fl, ROOT_PD); +		err = is_attach_rejected(fl); +		if (!err) +			err = fastrpc_init_attach(fl, ROOT_PD);  		break;  	case FASTRPC_IOCTL_INIT_ATTACH_SNS: -		err = fastrpc_init_attach(fl, SENSORS_PD); +		err = is_attach_rejected(fl); +		if (!err) +			err = fastrpc_init_attach(fl, SENSORS_PD);  		break;  	case FASTRPC_IOCTL_INIT_CREATE_STATIC: -		err = fastrpc_init_create_static_process(fl, argp); +		err = is_attach_rejected(fl); +		if (!err) +			err = fastrpc_init_create_static_process(fl, argp);  		break;  	case FASTRPC_IOCTL_INIT_CREATE:  		err = fastrpc_init_create_process(fl, argp);  |