فهرست منبع

msm: adsprpc: Fail set session info on subsequent calls

Currently there is no check if set session info is invoked
multiple times. Multiple calls to session info leaks memory
and process identifiers. Fail set session info on subsequent
calls.

Change-Id: I2072add44ce2a9c4c4ff544f8e568eeccc1220cf
Signed-off-by: Himateja Reddy <[email protected]>
(cherry picked from commit 1a5889127e7b0ff6974e50d762708bc2ef2d3a6c)
Himateja Reddy 2 سال پیش
والد
کامیت
c16622ebe5
2فایلهای تغییر یافته به همراه19 افزوده شده و 2 حذف شده
  1. 17 2
      dsp/adsprpc.c
  2. 2 0
      dsp/adsprpc_shared.h

+ 17 - 2
dsp/adsprpc.c

@@ -3547,6 +3547,11 @@ static int fastrpc_set_session_info(
 	int err = 0;
 	struct fastrpc_apps *me = &gfa;
 
+	if (fl->set_session_info) {
+		ADSPRPC_ERR("Set session info invoked multiple times\n");
+		err = -EBADR;
+		goto bail;
+	}
 	/*
 	 * Third-party apps don't have permission to open the fastrpc device, so
 	 * it is opened on their behalf by DSP HAL. This is detected by
@@ -5818,9 +5823,8 @@ skip_dump_wait:
 	fl->is_ramdump_pend = false;
 	fl->is_dma_invoke_pend = false;
 	fl->dsp_process_state = PROCESS_CREATE_DEFAULT;
-	VERIFY(err, VALID_FASTRPC_CID(cid));
 	/* Reset the tgid usage to false */
-	if (!err)
+	if (VALID_FASTRPC_CID(cid) && fl->tgid_frpc != -1)
 		frpc_tgid_usage_array[cid][fl->tgid_frpc] = false;
 	is_locked = false;
 	spin_unlock_irqrestore(&fl->apps->hlock, irq_flags);
@@ -6285,6 +6289,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)
 	fl->exit_notif = false;
 	fl->exit_async = false;
 	fl->multi_session_support = false;
+	fl->set_session_info = false;
 	init_completion(&fl->work);
 	init_completion(&fl->dma_invoke);
 	fl->file_close = FASTRPC_PROCESS_DEFAULT_STATE;
@@ -6430,6 +6435,16 @@ int fastrpc_get_info(struct fastrpc_file *fl, uint32_t *info)
 		err = -EBADF;
 		goto bail;
 	}
+	spin_lock(&fl->hlock);
+	if (fl->set_session_info) {
+		spin_unlock(&fl->hlock);
+		ADSPRPC_ERR("Set session info invoked multiple times\n");
+		err = -EBADR;
+		goto bail;
+	}
+	// Set set_session_info to true
+	fl->set_session_info = true;
+	spin_unlock(&fl->hlock);
 	VERIFY(err, VALID_FASTRPC_CID(cid));
 	if (err) {
 		err = -ECHRNG;

+ 2 - 0
dsp/adsprpc_shared.h

@@ -923,6 +923,8 @@ struct fastrpc_file {
 	struct fastrpc_proc_sharedbuf_info sharedbuf_info;
 	/* Flag to indicate 4 session support available */
 	bool multi_session_support;
+	/* Flag to indicate session info is set */
+	bool set_session_info;
 };
 
 int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode,