Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796158625; b=eh7RDBIJW1HctbXs8TfgtzRJA7HHDBDbyfP/zrstaEiWvob6pG0rHv1f8Km/3Dnos5ND SNpnvmpoBYiWY+1TML4xT+NHx23ZW2Esaiw0EJgcrP3itKiT+UKk7fUZOO4qOqErfRneh 5HDnb0Vf4GIVweQ906s9Wdbia4+YLkLLKoL9PhHTUWLDRcDNUSwxg8VA6fllsL8C0dWMN j8P0y/F1DTo6ntMM+rFB107B+VhUF315pIByMviQgGy4OIZ1mQODVI+53yXo6BgR2flo3 xxQ4nQX0GGcxNho6xpI4xjqyW2gggi6DkGTp+n4ir1FlKCagvA5lpgZQCEHc80jnNYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796158625; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=QMF8WWwvXIgd2mbcYaQsslmjhCn53ZZyAyncERCsJNg=; b=UZ34TrLed0F4ys4XjIMfp02VML1G08noPxXkd9LJBMhVZBUJ/ALDXEh5HVVjSpgdPOvR FYp8Xv3HcE1p9QY1xd3BbkxnOwBY0K3oK5xy0Icyt2bzIsBiTIx6cqDQDRzFVfFmUs9gN 3Zkz4dykp9P6L6+lxEeRjewG6o8n/L88TMdJwhqmlMfPW+sXweIR0LyRy1pigNORSH3mS F49p0wrUKynjqjwEdPBslw7UwmLxisdeOUtIhLnO7pWrqraVrBmsQkke9HB7o1qsDNs2e 7ISJYKiVJb6fI/tLJhoJr/BPKZOMCeG1QvogeufgSZThVNJ2XKVK2UY/fM11FnqJtDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=a4UvPLNi; arc=none smtp.remote-ip=74.125.229.8 Received: from mail-dy2-f8.google.com (mail-dy2-f8.google.com [74.125.229.8]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A7BB606A69B for ; Tue, 1 Dec 2026 20:57:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8A7BB606A69B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=a4UvPLNi Received: by mail-dy2-f8.google.com with SMTP id 5a478bee46e88-382afece6d8so2648127eec.1 for ; Tue, 01 Dec 2026 12:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796158625; x=1796763425; 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:content-type; bh=QMF8WWwvXIgd2mbcYaQsslmjhCn53ZZyAyncERCsJNg=; b=a4UvPLNitNbrzSCj7Fe0c89aQqJJdTIs+29k8geyl5G4N0Xfv/O2v/LrFTBvtc1ukU 42+/JKL+VYamajDYi1vxwG9a2OX6GFYPc3xMWe2hFEZPdweK/mDbvYzf5NzkRvthjYd8 hLzc7zvvMRsLkH86IZHaRvMzyPKErACPOgpdNBB+uFvLJqlJ4rmyLHrVAPiFu3v+exWS NtJW4/dnk4lERbP6vEdzcLuplk23ouMftVKTn6OAQ7/3hQ92WK9p9klnQqXfj7Z5of72 hZWpXPn8hxzQsnQRdcc+cEfYdsLX8Q4p8VWNEpE2O4zsILXGNbWfbw4PM3essvW3Rhn4 iFBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796158625; x=1796763425; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QMF8WWwvXIgd2mbcYaQsslmjhCn53ZZyAyncERCsJNg=; b=ZrolQvzIdTxy9WbWAjW+IltVeOvzyOEiSlRD1tYfL1dnZ3He+aGGbOldSH/gejxlUw H9LfRYmY3NJ67Gq0/U3jcOfAih8Q5nmZpMFPwWNyHXFHg7W9hl4TJxbsJUesHCR3U03c Dib76z3iGW6AIJIvX/QIuzQfo4DeHBMfdawuX0r87aS619XGYAgZDIucakvGrJB6GXYd R9RZR06FNIPr8nmsFXwwMMZIVWpWtoh9oQeDlzWS/jHMTLijSmOXUwTyRbfQIvavG1LL r9Pw2ojj2e8AHhC5EA1ACJ/sGeFO+j8dnDxYiZr9ooOovQ7uaIZjyGwzlIziiJGPIAm+ FiWg== X-Forwarded-Encrypted: i=1; AL+hErGbAfJWWZkOoqvEwnPqLVw0OTiWO4hSMFBCUx+xlJsHm7G9NyZvArw0TZpsUQvbnRPoCtFmTiO1aZucBbEV@vger.kernel.org X-Gm-Message-State: APuU4Z8cBdmoIvE+aAGOQKx/GHgpK6Z7PQxMzajF+3SRKb4o86sr5Rzu UfcVuIlq0HV4AZpqEDzk82gots3WtPHi0W3WD+FdwK7+sWSXWKJ9OjPy X-Gm-Gg: AZFdTZfoAxePuieE9FFMyAvLI0GxflboI+5uOmHVa09ThUCKUK6YoDZ/pl+ZngH++iH GLB2OlClNHzCmMO3goQ1A+G/oEJBKWC8D8lX+VJcfz52IAuYSUqSe6AFFsFH2s5JIzcm15iUQdc Pn4Cv6kpinfrjEcNM4uDk6H9dfxCBaImtRzXN58Fu6IAvYFMm6JWF6g65bQ+uKLu9OUAFiEDkO9 7v6XOV8nnU6cJrXubkm1FJ+hf3GkUipxUXiuMSzoZfTR08V2mwXWk+kZhE/54Qp7cPNf7vWV3Ym y/w4A3cZ9oBEOb+eUDKZ2rM30oNymWlk1QvhgSR9oPaJvwG1p26A4UkVOkWHPMJXrBBhbyVnTYy 9HRQ+oVrvYzZpmjbFpNkedKsv/oSeB/lFvqI2ToyiD82EubPfpX5zP2sk/w7FgcdjEbBFx7uyMt jK0mMN81wmsFU99Ljlnj+UrOPS45sEHGw2zG21PmlH5jgm/0zSW2jp67fI43Zjc3VjbK/fdW/aJ nzubPssXKPfSBvfa4J+Nt0TwHjhbad4w/0hBhNhuilIGsgTqi20beBqygENd4rj3Z+JnCEGkibd AXvOo7o4VO+L+5+lhkvB+4BIVH8B9rSMPsZnSMdFHvpw+CWYRRWsWiExs5ne+Z71aIK8LoLf7lw Gt8GYgCpklveyn2uXje+mIIAeW5xHMLP57kszWxryew== X-Received: by 2002:a05:7022:f516:b0:14c:8461:b3ef with SMTP id a92af1059eb24-1b5568fbf43mr31774072c88.24.1796158624469; Tue, 01 Dec 2026 12:57:04 -0800 (PST) Received: from localhost.localdomain ([76.33.234.50]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5567ff27bsm103208079c88.6.2026.12.01.12.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 12:57:04 -0800 (PST) From: Hungyu Lin To: vikash.garodia@oss.qualcomm.com, dikshita.agarwal@oss.qualcomm.com Cc: abhinav.kumar@linux.dev, bod@kernel.org, konrad.dybcio@oss.qualcomm.com, mchehab@kernel.org, hverkuil@kernel.org, stefan.schmidt@linaro.org, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, dennylin0707@gmail.com Subject: [PATCH v3 3/3] media: iris: fix out-of-bounds read in gen1 sequence change event Date: Tue, 1 Dec 2026 20:56:42 +0000 Message-ID: <20261201205642.32436-4-dennylin0707@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201205642.32436-1-dennylin0707@gmail.com> References: <20261201205642.32436-1-dennylin0707@gmail.com> X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit iris_hfi_gen1_read_changed_params() walks the properties of a HFI_EVENT_SESSION_SEQUENCE_CHANGED event. The number of properties comes from the firmware in event_data2 and the payload is never checked against the size of the packet. A count that is larger than what the packet holds makes the loop read past the end of the packet and, if it is large enough, past the end of the response buffer. The values that are read end up in the formats and in the crop rectangle that user space can query. The same code in venus was fixed by commit 06d6770ff0d8 ("media: venus: Fix OOB read due to missing payload bound check"). Do the same here: keep track of the bytes that are left in the packet and put the instance into the error state when a property does not fit. A property type that is not known has no known size, so end the walk there, which is also what the current code ends up doing, instead of reading its payload as the next property type. Fixes: 84e17adae3e3 ("media: iris: add support for dynamic resolution change") Cc: stable@vger.kernel.org Signed-off-by: Hungyu Lin --- .../qcom/iris/iris_hfi_gen1_response.c | 75 ++++++++++++++----- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c b/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c index ffa98139f0eb..f7957dca50b0 100644 --- a/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c +++ b/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c @@ -34,75 +34,105 @@ static void iris_hfi_gen1_read_changed_params(struct iris_inst *inst, struct hfi_framesize *frame_sz; struct vb2_queue *dst_q; struct v4l2_ctrl *ctrl; - u32 full_range, ptype; + u32 full_range, ptype, rem_bytes; + u32 size_read = 0; + + rem_bytes = pkt->shdr.hdr.size - sizeof(*pkt); do { + if (rem_bytes < sizeof(u32)) + goto error; ptype = *((u32 *)data_ptr); + + data_ptr += sizeof(u32); + rem_bytes -= sizeof(u32); + switch (ptype) { case HFI_PROPERTY_PARAM_FRAME_SIZE: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_framesize)) + goto error; + frame_sz = (struct hfi_framesize *)data_ptr; event.width = frame_sz->width; event.height = frame_sz->height; - data_ptr += sizeof(*frame_sz); + size_read = sizeof(struct hfi_framesize); break; case HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_profile_level)) + goto error; + profile_level = (struct hfi_profile_level *)data_ptr; event.profile = profile_level->profile; event.level = profile_level->level; - data_ptr += sizeof(*profile_level); + size_read = sizeof(struct hfi_profile_level); break; case HFI_PROPERTY_PARAM_VDEC_PIXEL_BITDEPTH: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_bit_depth)) + goto error; + pixel_depth = (struct hfi_bit_depth *)data_ptr; event.bit_depth = pixel_depth->bit_depth; - data_ptr += sizeof(*pixel_depth); + size_read = sizeof(struct hfi_bit_depth); break; case HFI_PROPERTY_PARAM_VDEC_PIC_STRUCT: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_pic_struct)) + goto error; + pic_struct = (struct hfi_pic_struct *)data_ptr; event.pic_struct = pic_struct->progressive_only; - data_ptr += sizeof(*pic_struct); + size_read = sizeof(struct hfi_pic_struct); break; case HFI_PROPERTY_PARAM_VDEC_COLOUR_SPACE: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_colour_space)) + goto error; + colour_info = (struct hfi_colour_space *)data_ptr; event.colour_space = colour_info->colour_space; - data_ptr += sizeof(*colour_info); + size_read = sizeof(struct hfi_colour_space); break; case HFI_PROPERTY_CONFIG_VDEC_ENTROPY: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(u32)) + goto error; + event.entropy_mode = *(u32 *)data_ptr; - data_ptr += sizeof(u32); + size_read = sizeof(u32); break; case HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_buffer_requirements)) + goto error; + bufreq = (struct hfi_buffer_requirements *)data_ptr; event.buf_count = bufreq->count_min; - data_ptr += sizeof(*bufreq); + size_read = sizeof(struct hfi_buffer_requirements); break; case HFI_INDEX_EXTRADATA_INPUT_CROP: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_extradata_input_crop)) + goto error; + crop = (struct hfi_extradata_input_crop *)data_ptr; event.input_crop.left = crop->left; event.input_crop.top = crop->top; event.input_crop.width = crop->width; event.input_crop.height = crop->height; - data_ptr += sizeof(*crop); + size_read = sizeof(struct hfi_extradata_input_crop); break; case HFI_PROPERTY_PARAM_VDEC_DPB_COUNTS: - data_ptr += sizeof(u32); + if (rem_bytes < sizeof(struct hfi_dpb_counts)) + goto error; + iris_vpu_dpb_count = (struct hfi_dpb_counts *)data_ptr; event.buf_count = iris_vpu_dpb_count->fw_min_count; - data_ptr += sizeof(*iris_vpu_dpb_count); + size_read = sizeof(struct hfi_dpb_counts); break; default: - break; + goto done; } + data_ptr += size_read; + rem_bytes -= size_read; num_properties_changed--; } while (num_properties_changed > 0); +done: pixmp_ip->width = event.width; pixmp_ip->height = event.height; @@ -170,6 +200,11 @@ static void iris_hfi_gen1_read_changed_params(struct iris_inst *inst, event.bit_depth, event.pic_struct); iris_inst_change_state(inst, IRIS_INST_ERROR); } + + return; + +error: + iris_inst_change_state(inst, IRIS_INST_ERROR); } static void iris_hfi_gen1_event_seq_changed(struct iris_inst *inst, -- 2.43.0