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

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