From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F41CB38944E for ; Tue, 7 Jul 2026 06:12:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783404736; cv=none; b=TRNqQbGVBhcmiCQWOQPpdVc9jgHt20lZGdxREwHZijz+QiQIE5FhgQ4DNuxXYgaDptcjYHymbwde157tcXlOqwOlMl/663qB4aduSJ5zHq9itd+d00kaiJm1k4gepCdt0vWx7xKbazKU2P2szedaAp51KGiL/NvR0GVMG7DHS0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783404736; c=relaxed/simple; bh=0eTjauZPn8IfSkvMdjZwIW90QvTg8s8dczcYNWpKwRA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PjVZ/W51E2p2wNs+U8XCjruizwVnhVwKX012eSh0lWVtYif4lvZno2U7USoVS9L6rspM9sVG4f59HJRkSSwXxyTezh55t3fta1zkUtZLFBovT869zKUEos5JrdlP0ACJFB1x/LnAlvwHe1Eat/aphjAiwa7Ndow0pSTlQP8kHI0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=Io0+6HEh; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=eJBUnFND; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="Io0+6HEh"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="eJBUnFND" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66748jJO2585265 for ; Tue, 7 Jul 2026 06:12:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= NNAd+TMb+3/aBq6GaRC6LydMmMiUk++N4aKr66RpLb8=; b=Io0+6HEhzqlLeXEw lfSVfE3QhcSXHUiGH8HhktWjbfgnkH/OOEXNR+w3eDv59Gur2OdikO5l/GULVukl l4vDkmH7LjMADd/7DiivL2rURDpYezJYMzopHTtRxNIKQr0DOSmy03ucZWpITfLy FsABkLx/sIaEZxdeanTAHa5kcWIkh3LD6CRoe2z3HUctBWttulbkwXrGakJnNW69 D9ghJmXWJFSbqwuyjWZcB8IRPQA+Lml+wj1S//l3KQZpsVc1dm6CiFG3Rc+9L3UP kTqiMEXrk/G05FG3U7nLMgge+3SLAdwcQLfTQjx0shwyGg+BGFaQ1ZH+vjCTpof0 RmwGwg== Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4f8t158e31-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 07 Jul 2026 06:12:13 +0000 (GMT) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-8479b7c3adbso6843040b3a.3 for ; Mon, 06 Jul 2026 23:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1783404733; x=1784009533; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NNAd+TMb+3/aBq6GaRC6LydMmMiUk++N4aKr66RpLb8=; b=eJBUnFNDHv5GDqcr6v5agHNgVbyV7Qu35Ke2n6DTknhpjKZB1b8GxqddetS6g3Zcne yRqI1zMQSqPMZmX1RcwRfiP5TRsRYBCEIwTS06sNTTdflqvV0X5lgKdtketHFyMdVA2k oRAF8GRH/ZEq96JGIixCuWq4U1BZenD1WqLUHhBMFiQw/1+mSEFB368iuT9uLUyaqwdu UejCjQK54YPoQsOQFX/MBh6oqqRXuUyQwJbr9fkGZHGxhE971L/LGrhPH9SKPnsX24+r cPNLGIWmn+kqHQ+q1/I9r2fpn7MbBaEsr4TTzLwo2d2FRo3RYuIwORjxtEGJD7fvBcX5 MJ7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783404733; x=1784009533; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=NNAd+TMb+3/aBq6GaRC6LydMmMiUk++N4aKr66RpLb8=; b=jHDDNDTmhpQKCdOpV1GORwWMF9ENXtP14pbNpr+U/zPmbvtu2MsKuPvatdFxUEOuoc NelGYuRdAtHpm7YefTQUlk8fhJAFi2+Zu394zfEk9n/amIuq0SiTtazKENzGdrS86IQM 5wJZx3a3T1tZbPu+qJesBdazyuN7TPimxTiAH4kIYsA5snsyFu+FXd84dCvYHBP/3HkX M6yp+x4i6mWGizUV1aNyLyITO+8sf5Gft2YCpsxlE1Wfq7zcnhaS5AT2GL8ROPEW+RFq 7n+Co/uz3q+4pKvcIncJu5XQHm4aIu2DkSG11RtJ6SvOytrL3GpQTlgetqt3XrqEJ97M YDKA== X-Forwarded-Encrypted: i=1; AHgh+Rp9XK7I0imwFAliCKA2KEmF221MN9K7Fyz3B410/+siogA7t85sNrGn2VJEWcYiZiIEFjPu5CTW0Il7UUE=@vger.kernel.org X-Gm-Message-State: AOJu0Yzv8LW6Dh/P5uvVtoG7ipB4bfJnWsqBj0bhP4o6KX37ujIyixDi kJuF/f5LX+DIKCfQ8iAzvVIbX7gT/tErC/NDWHBwFGnGYYre4UzSKqMlhIEK1GTzN5MnrtacQyN bUDFQev/5ZI1BQkO0V8ZKZgziFUHdpyAv/EA9fk9g2aXUvD4w3lGFDvyxp2VX9cO4e+M= X-Gm-Gg: AfdE7cm/I0Xor8iIRDmran0WpPSF5V6tanc8hlepRJYlebWIXd8K3HgdN7FTvPTOXAP pyw6weIK7LPqx7er7mWRPw8Cuw3VSpDFpG7RUIWSiVH4Oaa83AxAF7K/M/DwGUVN8b1K8lQwJm0 hIzWgkA86qcgXCrHMeNL1b8ufBqJH+PrfCZ5coeL7UDL14lJHH/E4+B/Rd799/gIUNfqCQ8qQJJ aEpt/4c6oTCTiMsBBmqckbQAKR/oM2RZ2jpelok3m7CAZ8kMLm2P8/XKucyG3wQWoOTkCMHhG3k okJ1wG3pjrOaEuNUrw+NBAR8hhDrPkoMQhfYj7+vyTmhUfu+yn5h3T08O40yRXY3u1pF+Hj56A6 fPmaWhFTPeOSseAZFu6mVTn/vK1+SXIfV6Jh6 X-Received: by 2002:a05:6a00:4b15:b0:845:e41f:9696 with SMTP id d2e1a72fcca58-84826bea1c7mr3416684b3a.25.1783404732592; Mon, 06 Jul 2026 23:12:12 -0700 (PDT) X-Received: by 2002:a05:6a00:4b15:b0:845:e41f:9696 with SMTP id d2e1a72fcca58-84826bea1c7mr3416647b3a.25.1783404732003; Mon, 06 Jul 2026 23:12:12 -0700 (PDT) Received: from hu-hdev-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8480da8bab0sm3299321b3a.8.2026.07.06.23.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 23:12:11 -0700 (PDT) From: Harshal Dev Date: Tue, 07 Jul 2026 11:41:29 +0530 Subject: [PATCH 3/6] tee: qcomtee: Allow object invokes from kernel clients Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260707-qcom_uefisecapp_migrate_qcomtee-v1-3-f659cbd5d04c@oss.qualcomm.com> References: <20260707-qcom_uefisecapp_migrate_qcomtee-v1-0-f659cbd5d04c@oss.qualcomm.com> In-Reply-To: <20260707-qcom_uefisecapp_migrate_qcomtee-v1-0-f659cbd5d04c@oss.qualcomm.com> To: Jens Wiklander , Sumit Garg , Amirreza Zarrabi , Bjorn Andersson , Konrad Dybcio Cc: Basant Kumar , Apurupa Pattapu , Arun Kumar Neelakantam , op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Harshal Dev X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783404715; l=6471; i=harshal.dev@oss.qualcomm.com; s=20251124; h=from:subject:message-id; bh=/owlBkDPCA2vuWSbsJZD4eHZ9HPwNyiIkP0LxaPIwKA=; b=qVSk5YQzILNpzM0ym015Ib8Zv8kzB0ZSfQxbEOWG+KWwAhnIrI0UCTiT8HniolJ+5J3peNh0L Nc7cIFaLke2DeX7eI1/LDP0l1lNSmgebtPzhcxrZXgAduWzkonPhTim X-Developer-Key: i=harshal.dev@oss.qualcomm.com; a=ed25519; pk=SHJ8K4SglF5t7KmfMKXl6Mby40WczSeLs4Qus7yFO7c= X-Proofpoint-GUID: unOHF1nC5Y8HgABUxrAas56j_nhufQcx X-Authority-Analysis: v=2.4 cv=HstG3UTS c=1 sm=1 tr=0 ts=6a4c98bd cx=c_pps a=WW5sKcV1LcKqjgzy2JUPuA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=XyePUiwmHbEyLJ1dZiEA:9 a=QEXdDO2ut3YA:10 a=OpyuDcXvxspvyRM73sMx:22 X-Proofpoint-ORIG-GUID: unOHF1nC5Y8HgABUxrAas56j_nhufQcx X-Proofpoint-Spam-Info: AW1haW4tMjYwNzA3MDA1NiBTYWx0ZWRfXwq7SoJ/bcvF1 XX9xJuDdEoPi9IiaSP0fjveOI9Gc3r93f1NA4kpAoQe1RvrqYcvXKUlgOwM4OueqDbdesa63cOK rJH+nu0/AWMqYhbBkFS2XvI3w5ar8Xc= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzA3MDA1NiBTYWx0ZWRfXx4UJ28oWMVnb j4D7IqZtAp0kcF5jdjQXchNbnzAITMueemEj7CfUHkojF+hPy111Z+0h9/eZpUUYbosfdXei898 JvSHeASjdjH3ZmxwetVT4qQ9Y7kHatXZFwP1MTI9JihHqJK5rmv3ytrx4DI6K+ZNc3Gk/pzKqPl PpUJqdJA3uAv/F3OrzSiiK4YM6NkmJ1hXAdN7s4dswDHn/vXdHfUWhWAv2Jk0h9Ex+6I+zylavu RvPDI+3bReFo1K+/v8IjkuPIr+WhO4pJWb1MMIK8v4K3klUrnb3qcRKzSaMqAMhHWn7TKBm+oKv nYMLbYvTLnwhUcd8Jw3opyd2TwXh+RTlcjvtnmJCC8Qoq1qDkfqdHqPTu+07qsji6fChgLWR7sC YzHbiRIRaY98wN7ldDh6xT5GgKqlufYpaZSnpD46/Rb4JoEM1zb6BJdNhj2iw4gzr43H1mI9pZi ai5I7WFQ2A7uxctVixg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-07_01,2026-07-06_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 suspectscore=0 malwarescore=0 bulkscore=0 clxscore=1015 spamscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607070056 From: Amirreza Zarrabi QCOMTEE currently treats UBUF parameters as userspace addresses and applies userspace restrictions when invoking the root object. This is not suitable for object invocation requests issued by kernel clients. Use the kernel_ctx flag to distinguish kernel client requests from userspace requests. For kernel contexts, do not mark UBUF parameters as user addresses, and allow permitted root-object operations to proceed without applying the userspace-only checks. This allows in-kernel users of tee_client_object_invoke_func() to issue object invocation requests through the qcomtee backend. Signed-off-by: Amirreza Zarrabi Signed-off-by: Harshal Dev --- drivers/tee/qcomtee/call.c | 34 +++++++++++++++++++++++----------- drivers/tee/qcomtee/qcomtee_object.h | 5 +++-- include/linux/tee_drv.h | 5 ++++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/tee/qcomtee/call.c b/drivers/tee/qcomtee/call.c index a74a54d67b06..e12c1a6e72d8 100644 --- a/drivers/tee/qcomtee/call.c +++ b/drivers/tee/qcomtee/call.c @@ -202,7 +202,7 @@ int qcomtee_objref_from_arg(struct tee_param *param, struct qcomtee_arg *arg, */ static int qcomtee_params_to_args(struct qcomtee_arg *u, struct tee_param *params, int num_params, - struct tee_context *ctx) + struct qcomtee_object_invoke_ctx *oic) { int i; @@ -210,8 +210,14 @@ static int qcomtee_params_to_args(struct qcomtee_arg *u, switch (params[i].attr) { case TEE_IOCTL_PARAM_ATTR_TYPE_UBUF_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_UBUF_OUTPUT: - u[i].flags = QCOMTEE_ARG_FLAGS_UADDR; - u[i].b.uaddr = params[i].u.ubuf.uaddr; + u[i].flags = oic->kernel_ctx ? 0 : + QCOMTEE_ARG_FLAGS_UADDR; + + if (u[i].flags && QCOMTEE_ARG_FLAGS_UADDR) + u[i].b.uaddr = params[i].u.ubuf.uaddr; + else + u[i].b.addr = params[i].u.ubuf.addr; + u[i].b.size = params[i].u.ubuf.size; if (params[i].attr == @@ -223,7 +229,7 @@ static int qcomtee_params_to_args(struct qcomtee_arg *u, break; case TEE_IOCTL_PARAM_ATTR_TYPE_OBJREF_INPUT: u[i].type = QCOMTEE_ARG_TYPE_IO; - if (qcomtee_objref_to_arg(&u[i], ¶ms[i], ctx)) + if (qcomtee_objref_to_arg(&u[i], ¶ms[i], oic->ctx)) goto out_failed; break; @@ -270,7 +276,7 @@ static int qcomtee_params_to_args(struct qcomtee_arg *u, */ static int qcomtee_params_from_args(struct tee_param *params, struct qcomtee_arg *u, int num_params, - struct tee_context *ctx) + struct qcomtee_object_invoke_ctx *oic) { int i, np; @@ -288,7 +294,8 @@ static int qcomtee_params_from_args(struct tee_param *params, break; case QCOMTEE_ARG_TYPE_OO: /* TEE_IOCTL_PARAM_ATTR_TYPE_OBJREF_OUTPUT */ - if (qcomtee_objref_from_arg(¶ms[np], &u[np], ctx)) + if (qcomtee_objref_from_arg(¶ms[np], &u[np], + oic->ctx)) goto out_failed; break; @@ -304,7 +311,7 @@ static int qcomtee_params_from_args(struct tee_param *params, /* Undo qcomtee_objref_from_arg(). */ for (i = 0; i < np; i++) { if (params[i].attr == TEE_IOCTL_PARAM_ATTR_TYPE_OBJREF_OUTPUT) - qcomtee_context_del_qtee_object(¶ms[i], ctx); + qcomtee_context_del_qtee_object(¶ms[i], oic->ctx); } /* Release any IO and OO objects not processed. */ @@ -357,7 +364,8 @@ static int qcomtee_params_check(struct tee_param *params, int num_params) } /* Check if an operation on ROOT_QCOMTEE_OBJECT from userspace is permitted. */ -static int qcomtee_root_object_check(u32 op, struct tee_param *params, +static int qcomtee_root_object_check(struct qcomtee_object_invoke_ctx *oic, + u32 op, struct tee_param *params, int num_params) { /* Some privileged operations recognized by QTEE. */ @@ -366,6 +374,9 @@ static int qcomtee_root_object_check(u32 op, struct tee_param *params, op == QCOMTEE_ROOT_OP_ADCI_SHUTDOWN) return -EINVAL; + if (oic->kernel_ctx) + return 0; + /* * QCOMTEE_ROOT_OP_REG_WITH_CREDENTIALS is to register with QTEE * by passing a credential object as input OBJREF. TEE_OBJREF_NULL as a @@ -444,7 +455,8 @@ static int qcomtee_object_invoke(struct tee_context *ctx, /* Get an object to invoke. */ if (arg->id == TEE_OBJREF_NULL) { /* Use ROOT if TEE_OBJREF_NULL is invoked. */ - if (qcomtee_root_object_check(arg->op, params, arg->num_params)) + if (qcomtee_root_object_check(oic, arg->op, params, + arg->num_params)) return -EINVAL; object = ROOT_QCOMTEE_OBJECT; @@ -452,7 +464,7 @@ static int qcomtee_object_invoke(struct tee_context *ctx, return -EINVAL; } - ret = qcomtee_params_to_args(u, params, arg->num_params, ctx); + ret = qcomtee_params_to_args(u, params, arg->num_params, oic); if (ret) goto out; @@ -470,7 +482,7 @@ static int qcomtee_object_invoke(struct tee_context *ctx, if (!result) { /* Assume service is UNAVAIL if unable to process the result. */ - if (qcomtee_params_from_args(params, u, arg->num_params, ctx)) + if (qcomtee_params_from_args(params, u, arg->num_params, oic)) result = QCOMTEE_MSG_ERROR_UNAVAIL; } else { /* diff --git a/drivers/tee/qcomtee/qcomtee_object.h b/drivers/tee/qcomtee/qcomtee_object.h index 2528d07e4576..7bd6e23b038c 100644 --- a/drivers/tee/qcomtee/qcomtee_object.h +++ b/drivers/tee/qcomtee/qcomtee_object.h @@ -112,8 +112,9 @@ struct qcomtee_buffer { * @b: address and size if the type of argument is a buffer. * @o: object instance if the type of argument is an object. * - * &qcomtee_arg.flags only accepts %QCOMTEE_ARG_FLAGS_UADDR for now, which - * states that &qcomtee_arg.b contains a userspace address in uaddr. ++ * If %QCOMTEE_ARG_FLAGS_UADDR is set in &qcomtee_arg.flags then it implies ++ * that &qcomtee_arg.b contains a userspace address in uaddr. ++ * Otherwise, &qcomtee_arg.b contains a kernel address in addr. */ struct qcomtee_arg { enum qcomtee_arg_type type; diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index ca99c6b747a8..71d0536db60e 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -83,7 +83,10 @@ struct tee_param_memref { }; struct tee_param_ubuf { - void __user *uaddr; + union { + void *addr; + void __user *uaddr; + }; size_t size; }; -- 2.34.1