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

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