From a947b8edbdcec8415a80ca55e9f38801322ffdd3 Mon Sep 17 00:00:00 2001 From: Li Qiang Date: Fri, 17 Jul 2026 23:39:11 +0800 Subject: [PATCH] scsi: ufs: rpmb: Validate request frame length before parsing The RPMB core only verifies that request and response buffers are nonempty. This callback reads req_resp at the end of the first request frame before validating the request length. Require a complete frame before that access. Fixes: b06b8c421485 ("scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices") Signed-off-by: Li Qiang Reviewed-by: Peter Wang Reviewed-by: Bean Huo Link: https://patch.msgid.link/20260717153914.26321-5-liqiang01@kylinos.cn Signed-off-by: Martin K. Petersen --- drivers/ufs/core/ufs-rpmb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/ufs/core/ufs-rpmb.c b/drivers/ufs/core/ufs-rpmb.c index ffad049872b9..431f85b36876 100644 --- a/drivers/ufs/core/ufs-rpmb.c +++ b/drivers/ufs/core/ufs-rpmb.c @@ -69,6 +69,10 @@ static int ufs_rpmb_route_frames(struct device *dev, u8 *req, unsigned int req_l hba = ufs_rpmb->hba; + /* req_resp is at the end of an RPMB frame. */ + if (req_len < sizeof(*frm_out)) + return -EINVAL; + req_type = be16_to_cpu(frm_out->req_resp); switch (req_type) {