Blame SOURCES/0166-tee-rewrite-num_params-access-in-tee_fetch_buf_data.patch

69e740
From 3a68f90c2a5a208b475cc2014f85ae04541ec5b6 Mon Sep 17 00:00:00 2001
69e740
From: Eugene Syromyatnikov <evgsyr@gmail.com>
69e740
Date: Fri, 20 Aug 2021 21:31:01 +0200
69e740
Subject: [PATCH 150/150] tee: rewrite num_params access in tee_fetch_buf_data
69e740
69e740
Pointer to num_params field of the fetched structure is passed in a
69e740
separate function argument which provokes covscan complaints about
69e740
uninitialised accesses and also tingles my aliasing rules senses.
69e740
Rewrite to access it via the arg_struct argument which is fetched
69e740
earlier in the function flow.
69e740
69e740
* src/tee.c (TEE_FETCH_BUF_DATA): Change &arg_.num_params
69e740
to offsetof(typeof(arg_), num_params).
69e740
(tee_fetch_buf_data): Accept offset of the num_params field instead
69e740
of pointer to it; reconstruct the num_params pointer using it.
69e740
---
69e740
 src/tee.c | 5 +++--
69e740
 1 file changed, 3 insertions(+), 2 deletions(-)
69e740
69e740
diff --git a/src/tee.c b/src/tee.c
69e740
index f9eda52..d7e9b15 100644
69e740
--- a/src/tee.c
69e740
+++ b/src/tee.c
69e740
@@ -33,7 +33,7 @@ struct tee_ioctl_shm_register_fd_data {
69e740
 
69e740
 #define TEE_FETCH_BUF_DATA(buf_, arg_, params_) \
69e740
 	tee_fetch_buf_data(tcp, arg, &buf_, sizeof(arg_), \
69e740
-			   &arg_, &arg_.num_params, \
69e740
+			   &arg_, offsetof(typeof(arg_), num_params), \
69e740
 			   params_)
69e740
 
69e740
 /* session id is printed as 0x%x in libteec */
69e740
@@ -56,7 +56,7 @@ tee_fetch_buf_data(struct tcb *const tcp,
69e740
 		   struct tee_ioctl_buf_data *buf,
69e740
 		   size_t arg_size,
69e740
 		   void *arg_struct,
69e740
-		   unsigned *num_params,
69e740
+		   size_t num_params_offs,
69e740
 		   uint64_t *params)
69e740
 {
69e740
 	if (umove_or_printaddr(tcp, arg, buf))
69e740
@@ -69,6 +69,7 @@ tee_fetch_buf_data(struct tcb *const tcp,
69e740
 		tee_print_buf(buf);
69e740
 		return RVAL_IOCTL_DECODED;
69e740
 	}
69e740
+	uint32_t *num_params = (uint32_t *) (arg_struct + num_params_offs);
69e740
 	if (entering(tcp) &&
69e740
 	    (arg_size + TEE_IOCTL_PARAM_SIZE(*num_params) != buf->buf_len)) {
69e740
 		/*
69e740
-- 
69e740
2.1.4
69e740