Skip to content

Commit 67a2821

Browse files
author
Abhilash Kumar
committed
msm: camera: utils: Validate buffer offset properly during dump
This change adds validation for the buffer in the patch descriptor, so that during dumping the information, illegal access is prevented. CRs-Fixed: 4021530 Change-Id: I044c64a446e38a71e0e4781fc0ea5eae6a53dc5e Signed-off-by: Abhilash Kumar <krabhi@qti.qualcomm.com>
1 parent 460d527 commit 67a2821

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

camera/drivers/cam_utils/cam_packet_util.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
33
* Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
4-
* Copyright (c) 2022-2025, Qualcomm Innovation Center, Inc. All rights reserved.
4+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
55
*/
66

77
#include <linux/types.h>
@@ -263,6 +263,7 @@ void cam_packet_util_dump_patch_info(struct cam_packet *packet,
263263
int32_t hdl;
264264
uintptr_t cpu_addr = 0;
265265
uint32_t *dst_cpu_addr;
266+
uint32_t dst_offset = 0;
266267
uint32_t flags, buf_fd;
267268
uint32_t value = 0;
268269

@@ -320,16 +321,26 @@ void cam_packet_util_dump_patch_info(struct cam_packet *packet,
320321
return;
321322
}
322323

324+
dst_offset = patch_desc[i].dst_offset;
325+
326+
if ((dst_buf_len < sizeof(uint32_t)) ||
327+
((dst_buf_len - sizeof(uint32_t)) < (size_t)dst_offset)) {
328+
CAM_ERR(CAM_UTIL,
329+
"Invalid dst buf patch at: %d src buf hdl 0x%llx src_buf address 0x%llx dst_buf_len 0x%zx, dst_offset 0x%x",
330+
i, patch_desc[i].src_buf_hdl, iova_addr, dst_buf_len, dst_offset);
331+
cam_mem_put_cpu_buf(patch_desc[i].dst_buf_hdl);
332+
return;
333+
}
334+
323335
dst_cpu_addr = (uint32_t *)cpu_addr;
324-
dst_cpu_addr = (uint32_t *)((uint8_t *)dst_cpu_addr +
325-
patch_desc[i].dst_offset);
336+
dst_cpu_addr = (uint32_t *)((uint8_t *)dst_cpu_addr + dst_offset);
326337
value = *dst_cpu_addr;
327338
CAM_INFO(CAM_UTIL,
328339
"i = %d src_buf 0x%llx src_hdl 0x%x src_buf_with_offset 0x%llx src_size 0x%llx src_flags: %x dst %p dst_offset %u dst_hdl 0x%x value 0x%x",
329340
i, iova_addr, patch_desc[i].src_buf_hdl,
330341
(iova_addr + patch_desc[i].src_offset),
331342
src_buf_size, flags, dst_cpu_addr,
332-
patch_desc[i].dst_offset,
343+
dst_offset,
333344
patch_desc[i].dst_buf_hdl, value);
334345

335346
if (!(*dst_cpu_addr))

0 commit comments

Comments
 (0)