From 31078711d6c3639073db97322c6f7d98dacbbefe Mon Sep 17 00:00:00 2001
From: Paul Elder <paul.elder@ideasonboard.com>
Date: Tue, 20 Jul 2021 19:24:47 +0900
Subject: ipa: Use FileDescriptor instead of int in layers above IPC payload

Regarding (de)serialization in isolated IPA calls, we have four layers:
- struct
- byte vector + fd vector
- IPCMessage
- IPC payload

The proxy handles the upper three layers (with help from the
IPADataSerializer), and passes an IPCMessage to the IPC mechanism
(implemented as an IPCPipe), which sends an IPC payload to its worker
counterpart.

When a FileDescriptor is involved, previously it was only a
FileDescriptor in the first layer; in the lower three it was an int. To
reduce the risk of potential fd leaks in the future, keep the
FileDescriptor as-is throughout the upper three layers. Only the IPC
mechanism will deal with ints, if it so wishes, when it does the actual
IPC. IPCPipeUnixSocket does deal with ints for sending fds, so the
conversion between IPCMessage and IPCUnixSocket::Payload converts
between FileDescriptor and int.

Additionally, change the data portion of the serialized form of
FileDescriptor to a 32-bit unsigned integer, for alightnment purposes
and in preparation for conversion to an index into the fd array.

Also update the deserializer of FrameBuffer::Plane accordingly.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Tested-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
---
 test/serialization/ipa_data_serializer_test.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

(limited to 'test')

diff --git a/test/serialization/ipa_data_serializer_test.cpp b/test/serialization/ipa_data_serializer_test.cpp
index bf7e34e2..eca19a66 100644
--- a/test/serialization/ipa_data_serializer_test.cpp
+++ b/test/serialization/ipa_data_serializer_test.cpp
@@ -53,7 +53,7 @@ template<typename T>
 int testPodSerdes(T in)
 {
 	std::vector<uint8_t> buf;
-	std::vector<int32_t> fds;
+	std::vector<FileDescriptor> fds;
 
 	std::tie(buf, fds) = IPADataSerializer<T>::serialize(in);
 	T out = IPADataSerializer<T>::deserialize(buf, fds);
@@ -72,7 +72,7 @@ int testVectorSerdes(const std::vector<T> &in,
 		     ControlSerializer *cs = nullptr)
 {
 	std::vector<uint8_t> buf;
-	std::vector<int32_t> fds;
+	std::vector<FileDescriptor> fds;
 
 	std::tie(buf, fds) = IPADataSerializer<std::vector<T>>::serialize(in, cs);
 	std::vector<T> out = IPADataSerializer<std::vector<T>>::deserialize(buf, fds, cs);
@@ -92,7 +92,7 @@ int testMapSerdes(const std::map<K, V> &in,
 		  ControlSerializer *cs = nullptr)
 {
 	std::vector<uint8_t> buf;
-	std::vector<int32_t> fds;
+	std::vector<FileDescriptor> fds;
 
 	std::tie(buf, fds) = IPADataSerializer<std::map<K, V>>::serialize(in, cs);
 	std::map<K, V> out = IPADataSerializer<std::map<K, V>>::deserialize(buf, fds, cs);
@@ -219,7 +219,7 @@ private:
 		};
 
 		std::vector<uint8_t> buf;
-		std::vector<int32_t> fds;
+		std::vector<FileDescriptor> fds;
 
 		if (testVectorSerdes(vecUint8) != TestPass)
 			return TestFail;
@@ -291,7 +291,7 @@ private:
 			{ { "a", { 1, 2, 3 } }, { "b", { 4, 5, 6 } }, { "c", { 7, 8, 9 } } };
 
 		std::vector<uint8_t> buf;
-		std::vector<int32_t> fds;
+		std::vector<FileDescriptor> fds;
 
 		if (testMapSerdes(mapUintStr) != TestPass)
 			return TestFail;
@@ -359,7 +359,7 @@ private:
 		std::string strEmpty = "";
 
 		std::vector<uint8_t> buf;
-		std::vector<int32_t> fds;
+		std::vector<FileDescriptor> fds;
 
 		if (testPodSerdes(u32min) != TestPass)
 			return TestFail;
-- 
cgit v1.2.1