From nobody Thu Oct 2 21:27:33 2025 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4450632ED58 for ; Thu, 11 Sep 2025 13:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757598640; cv=none; b=Na2p824cJGkwsjB4iixr5ND4f05LV8O+yEpsrT3TvooN53FSEKAyKhVT5++PtkFWS3UEStNv4s5Uh1Xrjdhr7z6UnYdIjKpxIF1AGbGkeVBKgY5RVro6RHaYOWJJTxm1Bfan3RVwb18YEmmCV2jk3HVExJoHU6piZeh0vfSlTUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757598640; c=relaxed/simple; bh=k5Jww2JK2ae51rsOpo5VdeRKiDm+DOy3GENCcdCVfVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CoccHQZofbdyN/KgkQXJQOh1l0p6BawFkzs82BRzQWWopAnkvwxDjlBFaG3Eh2g18ZDeq3/vJDA3o5fs94BNJV+GysEBD+r+HC5UFC90Mqo8wLvqMA9fXQqW2GcSjS2VyyVM+Pzxs76mkzDXyDVaHvq2H3Q0fHa5vhR5FozSLUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=klE5AKnw; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="klE5AKnw" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-71d60504788so5304027b3.2 for ; Thu, 11 Sep 2025 06:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1757598637; x=1758203437; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yi0r5nq64oj31QVOjln422OWaHa6DWnYy7B2T1z3rUg=; b=klE5AKnwrX8+utdXHXiA/AkI7a/T/OWsh9BQxvyR5kL6lAQOp5BNU6+zSmm1XyYNpm YVuEMTmHTdLAy1xx1lWKCL8Emjs672WyPHsKIjaVckQTGb+9eJvloi/KboUIZwGmDv8z Dgajkj461QdJ6l7AepJR5n99eAFv5qWDnt23t9Fm8U/W/sxqWN1ks0Ug5QczO/VM6yFm ckOryi6LrS9GR7eeY6OSai2Ogj7Abawszlyeg5afPu41CPgsdXsUDV0vp/q7P5HfqVv2 Y8qXV27knPGN76S0KQUBvlCG3yaG/nmngN8G/sX28eOOM18lEj28hRSm1/FeHh9mcikq tSvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757598637; x=1758203437; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yi0r5nq64oj31QVOjln422OWaHa6DWnYy7B2T1z3rUg=; b=YgcPs8U18ylpeZ1fWUnH6+Nrek4IOwQiBFmlx+EVv5Vm1nmGUExWe5ILwBf0mOhwOc 6hqYvqMd6LF2rD5n3O4PC+IRnwFCbyaYZ4ys5SxlTY3PEq8O+tdYpVFH19siaQvIIPdH DOHMFxPUmKcBUlVsfMw9OJzzX4ag/qlxYqXl7kvSGafM2LVxVO+ryloC6AyrVA6lTNxp GmlkD9bPYn3TpxluOqU1RjLJ81URouxgzZ71MEMmwN1w+tpLxCuDuH/fpOXN50wfOMKM 0ZUIDOWvJP4GEDM+aYibCNPFmYy6XUJina1lRgc/szyEYbo/4GcnLr8sK6a+B1yMNcrS i4ig== X-Gm-Message-State: AOJu0Ywdjq6kWji6Kf8KN8aRjJYDVf1ssMRApXvKOY6mfS/7JfF//JXa xZAP+y57Njek0JPVbfLDGHaJ3Zl5ScNFw6QlfB9t9PHVSZ5iO3/KVQmTuku3ewoSEKfufKxXs2z s6uPnSkXavQ== X-Gm-Gg: ASbGncvZw/momlTL0DrltRSjktlY3taAP6l4+KNG0d6/aNCpQlfm/APkT88v+m8gXvo fsYRBGvA11BtDjU30ZByV2jkaHeFLU118h1Rpip4Kv8i9EbwtZfkv9nJTdozKRSGfLqJlTz5zLg ELF24WX0S/Ivv0R8FHw31G6sk5edPh177L/oAr9JoIN6ehWxKHPYN95u9JHmeIN2pNCW3Rhv2lt N3DsjRjkMy01ZuAz6nYrvwmKLkEeToJGX8C9Rb1BsdKG+OrOmOAzrixTHy6rtXz67eoss2A1oOe 6KZAmpGCmGSMzF3GWeSbfhtedP2rHYFNJRkDpiN3Kw8zFT8/ZUw18I0K4nZ9nqIP1MuNVEfITso be/Krpe9u2XHZW3wdxy+VxG+wNO/+2Jpn8ltR4amYu6u0ETun3EGACehqM4mGewVj+oFbF84p0Y 7yAbZgx4ERmA== X-Google-Smtp-Source: AGHT+IFhFq5K/L+li5E/fnG6u0IEPzqvQNG67ywCbR49sqE1DlYxZ0kS6UjsMtnPo2ezjd7bDqomGA== X-Received: by 2002:a05:690c:62c1:b0:726:76f0:4b89 with SMTP id 00721157ae682-727f505434fmr181457897b3.22.1757598636586; Thu, 11 Sep 2025 06:50:36 -0700 (PDT) Received: from rayden.urgonet (h-37-123-177-177.A175.priv.bahnhof.se. [37.123.177.177]) by smtp.gmail.com with ESMTPSA id 00721157ae682-72f7623434csm3526257b3.11.2025.09.11.06.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 06:50:35 -0700 (PDT) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, op-tee@lists.trustedfirmware.org, linux-arm-kernel@lists.infradead.org Cc: Olivier Masse , Thierry Reding , Yong Wu , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T . J . Mercier" , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sumit Garg , Matthias Brugger , AngeloGioacchino Del Regno , azarrabi@qti.qualcomm.com, Simona Vetter , Daniel Stone , Rouven Czerwinski , robin.murphy@arm.com, Jens Wiklander , Sumit Garg Subject: [PATCH v12 4/9] tee: refactor params_from_user() Date: Thu, 11 Sep 2025 15:49:45 +0200 Message-ID: <20250911135007.1275833-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250911135007.1275833-1-jens.wiklander@linaro.org> References: <20250911135007.1275833-1-jens.wiklander@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Break out the memref handling into a separate helper function. No change in behavior. Reviewed-by: Sumit Garg Signed-off-by: Jens Wiklander --- drivers/tee/tee_core.c | 94 ++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 2411d1e2aa7a..4996f194cd9e 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -354,6 +354,55 @@ tee_ioctl_shm_register(struct tee_context *ctx, return ret; } =20 +static int param_from_user_memref(struct tee_context *ctx, + struct tee_param_memref *memref, + struct tee_ioctl_param *ip) +{ + struct tee_shm *shm; + + /* + * If a NULL pointer is passed to a TA in the TEE, + * the ip.c IOCTL parameters is set to TEE_MEMREF_NULL + * indicating a NULL memory reference. + */ + if (ip->c !=3D TEE_MEMREF_NULL) { + /* + * If we fail to get a pointer to a shared + * memory object (and increase the ref count) + * from an identifier we return an error. All + * pointers that has been added in params have + * an increased ref count. It's the callers + * responibility to do tee_shm_put() on all + * resolved pointers. + */ + shm =3D tee_shm_get_from_id(ctx, ip->c); + if (IS_ERR(shm)) + return PTR_ERR(shm); + + /* + * Ensure offset + size does not overflow + * offset and does not overflow the size of + * the referred shared memory object. + */ + if ((ip->a + ip->b) < ip->a || + (ip->a + ip->b) > shm->size) { + tee_shm_put(shm); + return -EINVAL; + } + } else if (ctx->cap_memref_null) { + /* Pass NULL pointer to OP-TEE */ + shm =3D NULL; + } else { + return -EINVAL; + } + + memref->shm_offs =3D ip->a; + memref->size =3D ip->b; + memref->shm =3D shm; + + return 0; +} + static int params_from_user(struct tee_context *ctx, struct tee_param *par= ams, size_t num_params, struct tee_ioctl_param __user *uparams) @@ -361,8 +410,8 @@ static int params_from_user(struct tee_context *ctx, st= ruct tee_param *params, size_t n; =20 for (n =3D 0; n < num_params; n++) { - struct tee_shm *shm; struct tee_ioctl_param ip; + int rc; =20 if (copy_from_user(&ip, uparams + n, sizeof(ip))) return -EFAULT; @@ -385,45 +434,10 @@ static int params_from_user(struct tee_context *ctx, = struct tee_param *params, case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: - /* - * If a NULL pointer is passed to a TA in the TEE, - * the ip.c IOCTL parameters is set to TEE_MEMREF_NULL - * indicating a NULL memory reference. - */ - if (ip.c !=3D TEE_MEMREF_NULL) { - /* - * If we fail to get a pointer to a shared - * memory object (and increase the ref count) - * from an identifier we return an error. All - * pointers that has been added in params have - * an increased ref count. It's the callers - * responibility to do tee_shm_put() on all - * resolved pointers. - */ - shm =3D tee_shm_get_from_id(ctx, ip.c); - if (IS_ERR(shm)) - return PTR_ERR(shm); - - /* - * Ensure offset + size does not overflow - * offset and does not overflow the size of - * the referred shared memory object. - */ - if ((ip.a + ip.b) < ip.a || - (ip.a + ip.b) > shm->size) { - tee_shm_put(shm); - return -EINVAL; - } - } else if (ctx->cap_memref_null) { - /* Pass NULL pointer to OP-TEE */ - shm =3D NULL; - } else { - return -EINVAL; - } - - params[n].u.memref.shm_offs =3D ip.a; - params[n].u.memref.size =3D ip.b; - params[n].u.memref.shm =3D shm; + rc =3D param_from_user_memref(ctx, ¶ms[n].u.memref, + &ip); + if (rc) + return rc; break; default: /* Unknown attribute */ --=20 2.43.0