Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 084d85e3 authored by Amir Samuelov's avatar Amir Samuelov
Browse files

pft: avoid race closing encrypted files when key removed



Unlikely race might happen when closing encrypted files.
Avoid it by allowing only PFT to close encrypted files
after the key was removed.

Change-Id: Icc7cd000084ecb4c72837a51a30550653e6139a9
Signed-off-by: default avatarAmir Samuelov <amirs@codeaurora.org>
parent 2f0184f7
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1191,6 +1191,28 @@ int pft_file_close(struct file *filp)
		pft_dev->inplace_file = NULL;
	}

	switch (pft_dev->state) {
	case PFT_STATE_DEACTIVATING:
	case PFT_STATE_REMOVING_KEY:
		/*
		 * Do not allow apps to close file when
		 * pft_close_opened_enc_files() is closing files.
		 * Normally, all enterprise apps are closed by PFM
		 * before getting to this state, so the apps files are
		 * norammly closed by now.
		 * pft_close_opened_enc_files() is running in PFM context.
		 */
		if (current_pid() != pft_dev->pfm_pid)
			return -EACCES;
	case PFT_STATE_DEACTIVATED:
	case PFT_STATE_KEY_LOADED:
	case PFT_STATE_KEY_REMOVED:
		break;
	default:
		BUG(); /* State is set by "set state" command */
		break;
	}

	pft_sync_file(filp);
	pft_remove_file(filp);