i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler
Subsystems (6)
Sasha Levin
maintainerPATCH 1/4 i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler
From: Jarkko Nikula <[email protected]>
[ Upstream commit 45a832f989e520095429589d5b01b0c65da9b574 ]
Do not loop over ring headers in hci_dma_irq_handler() that are not allocated and enabled in hci_dma_init(). Otherwise out of bounds access will occur from rings->headers[i] access when i >= number of allocated ring headers.
--- drivers/i3c/master/mipi-i3c-hci/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master/mipi-i3c-hci/dma.c +1 -1
@@ -734,7 +734,7 @@ static bool hci_dma_irq_handler(struct i3c_hci *hci, unsigned int mask)unsigned int i;bool handled = false; -for (i =0 ; mask && i <8 ; i++) { +for (i =0 ; mask && i < rings->total; i++) {struct hci_rh_data *rh;u32 status;
Signature · 1 line
2.42.0
Sasha Levin
maintainerPATCH 2/4 i2c: sun6i-p2wi: Prevent potential division by zero
From: Axel Lin <[email protected]>
[ Upstream commit 5ac61d26b8baff5b2e5a9f3dc1ef63297e4b53e7 ]
Make sure we don't OOPS in case clock-frequency is set to 0 in a DT. The variable set here is later used as a divisor.
--- drivers/i2c/busses/i2c-sun6i-p2wi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/i2c/busses/i2c-sun6i-p2wi.c +5 -0
@@ -201,6 +201,11 @@ static int p2wi_probe(struct platform_device *pdev)return -EINVAL ; } +if (clk_freq ==0 ) { +dev_err (dev,"clock-frequency is set to 0 in DT\n" ); +return -EINVAL ; + } +if (of_get_child_count (np) >1 ) {dev_err (dev,"P2WI only supports one slave device\n" );return -EINVAL ;
Signature · 1 line
2.42.0
Sasha Levin
maintainerPATCH 3/4 virtio-blk: fix implicit overflow on virtio_max_dma_size
In reply to Sasha LevinFrom: zhenwei pi <[email protected]>
[ Upstream commit fafb51a67fb883eb2dde352539df939a251851be ]
The following codes have an implicit conversion from size_t to u32:
(u32)max_size = (size_t)virtio_max_dma_size(vdev);
This may lead overflow, Ex (size_t)4G -> (u32)0. Once virtio_max_dma_size() has a larger size than U32_MAX, use U32_MAX instead.
Message-Id: <[email protected]>
--- drivers/block/virtio_blk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +3 -1
@@ -743,6 +743,7 @@ static int virtblk_probe(struct virtio_device *vdev)u16 min_io_size;u8 physical_block_exp, alignment_offset;unsigned int queue_depth; +size_t max_dma_size;if (!vdev->config->get) { dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -844,7 +845,8 @@ static int virtblk_probe(struct virtio_device *vdev)/* No real sector limit. */ blk_queue_max_hw_sectors (q,-1U ); - max_size =virtio_max_dma_size (vdev); + max_dma_size =virtio_max_dma_size (vdev); + max_size = max_dma_size >U32_MAX ?U32_MAX : max_dma_size;/* Host can optionally specify maximum segment size and number of * segments. */
Signature · 1 line
2.42.0
Sasha Levin
maintainerPATCH 4/4 i3c: master: mipi-i3c-hci: Fix a kernel panic for accessing DAT_data.
In reply to Sasha LevinFrom: Billy Tsai <[email protected]>
[ Upstream commit b53e9758a31c683fc8615df930262192ed5f034b ]
The i3c_master_bus_init function may attach the I2C devices before the I3C bus initialization. In this flow, the DAT `alloc_entry`` will be used before the DAT init. Additionally, if the i3c_master_bus_init fails, the DAT cleanup will execute before the device is detached, which will execue DAT free_entry function. The above scenario can cause the driver to use DAT_data when it is NULL.
--- drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/i3c/master/mipi-i3c-hci/dat_v1.c +19 -10
@@ -64,15 +64,17 @@ static int hci_dat_v1_init(struct i3c_hci *hci)return -EOPNOTSUPP ; } -/* use a bitmap for faster free slot search */ - hci->DAT_data =bitmap_zalloc (hci->DAT_entries,GFP_KERNEL ); -if (!hci->DAT_data) -return -ENOMEM ; - -/* clear them */ -for (dat_idx =0 ; dat_idx < hci->DAT_entries; dat_idx++) { -dat_w0_write (dat_idx,0 ); -dat_w1_write (dat_idx,0 ); +if (!hci->DAT_data) { +/* use a bitmap for faster free slot search */ + hci->DAT_data =bitmap_zalloc (hci->DAT_entries,GFP_KERNEL ); +if (!hci->DAT_data) +return -ENOMEM ; + +/* clear them */ +for (dat_idx =0 ; dat_idx < hci->DAT_entries; dat_idx++) { +dat_w0_write (dat_idx,0 ); +dat_w1_write (dat_idx,0 ); + } }return 0 ;
@@ -87,7 +89,13 @@ static void hci_dat_v1_cleanup(struct i3c_hci *hci)static int hci_dat_v1_alloc_entry (struct i3c_hci *hci) {unsigned int dat_idx; +int ret; +if (!hci->DAT_data) { + ret =hci_dat_v1_init (hci); +if (ret) +return ret; + } dat_idx =find_first_zero_bit (hci->DAT_data, hci->DAT_entries);if (dat_idx >= hci->DAT_entries)return -ENOENT ;
@@ -103,7 +111,8 @@ static void hci_dat_v1_free_entry(struct i3c_hci *hci, unsigned int dat_idx) {dat_w0_write (dat_idx,0 );dat_w1_write (dat_idx,0 ); -__clear_bit (dat_idx, hci->DAT_data); +if (hci->DAT_data) +__clear_bit (dat_idx, hci->DAT_data); } static void hci_dat_v1_set_dynamic_addr(struct i3c_hci *hci,
Signature · 1 line
2.42.0