i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler
Subsystems (9)
Sasha Levin
maintainerPATCH 2/7 i2c: i801: Add support for Intel Birch Stream SoC
In reply to Sasha LevinFrom: Jarkko Nikula <[email protected]>
[ Upstream commit 8c56f9ef25a33e51f09a448d25cf863b61c9658d ]
Add SMBus PCI ID on Intel Birch Stream SoC.
--- Documentation/i2c/busses/i2c-i801.rst | 1 + drivers/i2c/busses/Kconfig | 1 + drivers/i2c/busses/i2c-i801.c | 3 +++ 3 files changed, 5 insertions(+)
Documentation/i2c/busses/i2c-i801.rst +1 -0
@@ -47,6 +47,7 @@ Supported adapters: * Intel Alder Lake (PCH) * Intel Raptor Lake (PCH) * Intel Meteor Lake (SOC and PCH) + * Intel Birch Stream (SOC) Datasheets: Publicly available at the Intel website
drivers/i2c/busses/Kconfig +1 -0
@@ -158,6 +158,7 @@ config I2C_I801 Alder Lake (PCH) Raptor Lake (PCH) Meteor Lake (SOC and PCH) + Birch Stream (SOC) This driver can also be built as a module. If so, the module will be called i2c-i801.
drivers/i2c/busses/i2c-i801.c +3 -0
@@ -79,6 +79,7 @@* Meteor Lake-P (SOC) 0x7e22 32 hard yes yes yes * Meteor Lake SoC-S (SOC) 0xae22 32 hard yes yes yes * Meteor Lake PCH-S (PCH) 0x7f23 32 hard yes yes yes +* Birch Stream (SOC) 0x5796 32 hard yes yes yes * * Features supported by this driver: * Software PEC no
@@ -231,6 +232,7 @@#define PCI_DEVICE_ID_INTEL_JASPER_LAKE_SMBUS 0x4da3#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_P_SMBUS 0x51a3#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_M_SMBUS 0x54a3 +#define PCI_DEVICE_ID_INTEL_BIRCH_STREAM_SMBUS 0x5796#define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4#define PCI_DEVICE_ID_INTEL_RAPTOR_LAKE_S_SMBUS 0x7a23#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_S_SMBUS 0x7aa3
@@ -1044,6 +1046,7 @@ static const struct pci_device_id i801_ids[] = { { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_P_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_SOC_S_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_PCH_S_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, + { PCI_DEVICE_DATA(INTEL, BIRCH_STREAM_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, { 0, } };
Signature · 1 line
2.42.0
Sasha Levin
maintainerPATCH 3/7 i2c: fix memleak in i2c_new_client_device()
In reply to Sasha LevinFrom: Wolfram Sang <[email protected]>
[ Upstream commit 6af79f7fe748fe6a3c5c3a63d7f35981a82c2769 ]
Yang Yingliang reported a memleak:
===
I got memory leak as follows when doing fault injection test:
unreferenced object 0xffff888014aec078 (size 8):
comm "xrun", pid 356, jiffies 4294910619 (age 16.332s) hex dump (first 8 bytes):
31 2d 30 30 31 63 00 00 1-001c..
backtrace:
[<00000000eb56c0a9>] __kmalloc_track_caller+0x1a6/0x300
[<000000000b220ea3>] kvasprintf+0xad/0x140
[<00000000b83203e5>] kvasprintf_const+0x62/0x190
[<000000002a5eab37>] kobject_set_name_vargs+0x56/0x140
[<00000000300ac279>] dev_set_name+0xb0/0xe0
[<00000000b66ebd6f>] i2c_new_client_device+0x7e4/0x9a0If device_register() returns error in i2c_new_client_device(), the name allocated by i2c_dev_set_name() need be freed. As comment of device_register() says, it should use put_device() to give up the reference in the error path.
===
I think this solution is less intrusive and more robust than he originally proposed solutions, though.
--- drivers/i2c/i2c-core-base.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/i2c/i2c-core-base.c +9 -4
@@ -931,8 +931,9 @@ int i2c_dev_irq_from_resources(const struct resource *resources,struct i2c_client *i2c_new_client_device (struct i2c_adapter *adap,struct i2c_board_info const *info) { -struct i2c_client *client; -int status; +struct i2c_client *client; +bool need_put = false; +int status; client =kzalloc (sizeof *client,GFP_KERNEL );if (!client)
@@ -970,7 +971,6 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf client->dev.fwnode = info->fwnode;device_enable_async_suspend (&client->dev); -i2c_dev_set_name (adap, client, info);if (info->swnode) { status =device_add_software_node (&client->dev, info->swnode);
@@ -982,6 +982,7 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf } } +i2c_dev_set_name (adap, client, info); status =device_register (&client->dev);if (status) goto out_remove_swnode;
@@ -993,6 +994,7 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf out_remove_swnode:device_remove_software_node (&client->dev); + need_put = true; out_err_put_of_node:of_node_put (info->of_node); out_err:
@@ -1000,7 +1002,10 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf"Failed to register i2c client %s at 0x%02x (%d)\n" , client->name, client->addr, status); out_err_silent: -kfree (client); +if (need_put) +put_device (&client->dev); +else +kfree (client);return ERR_PTR (status); }EXPORT_SYMBOL_GPL (i2c_new_client_device);
Signature · 1 line
2.42.0
Sasha Levin
maintainerPATCH 4/7 i2c: sun6i-p2wi: Prevent potential division by zero
In reply to Sasha LevinFrom: 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 5/7 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
@@ -1313,6 +1313,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",
@@ -1411,7 +1412,8 @@ static int virtblk_probe(struct virtio_device *vdev)/* No real sector limit. */ blk_queue_max_hw_sectors (q,UINT_MAX ); - 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 1/7 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 6/7 vhost-vdpa: clean iotlb map during reset for older userspace
From: Si-Wei Liu <[email protected]>
[ Upstream commit bc91df5c70ac720eca18bd1f4a288f2582713d3e ]
Using .compat_reset op from the previous patch, the buggy .reset behaviour can be kept as-is on older userspace apps, which don't ack the IOTLB_PERSIST backend feature. As this compatibility quirk is limited to those drivers that used to be buggy in the past, it won't affect change the behaviour or affect ABI on the setups with API compliant driver.
The separation of .compat_reset from the regular .reset allows vhost-vdpa able to know which driver had broken behaviour before, so it can apply the corresponding compatibility quirk to the individual driver whenever needed. Compared to overloading the existing .reset with flags, .compat_reset won't cause any extra burden to the implementation of every compliant driver.
[mst: squashed in two fixup commits]
Message-Id: <[email protected]>
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- drivers/vhost/vdpa.c | 20 ++++++++++++++++---- drivers/virtio/virtio_vdpa.c | 2 +- include/linux/vdpa.h | 7 +++++-- 3 files changed, 22 insertions(+), 7 deletions(-)
drivers/vhost/vdpa.c +16 -4
@@ -210,13 +210,24 @@ static void vhost_vdpa_unsetup_vq_irq(struct vhost_vdpa *v, u16 qid)irq_bypass_unregister_producer (&vq->call_ctx.producer); } -static int vhost_vdpa_reset (struct vhost_vdpa *v) +static int _compat_vdpa_reset (struct vhost_vdpa *v) {struct vdpa_device *vdpa = v->vdpa; +u32 flags =0 ; - v->in_batch =0 ; +if (v->vdev.vqs) { + flags |= !vhost_backend_has_feature (v->vdev.vqs[0 ], +VHOST_BACKEND_F_IOTLB_PERSIST ) ? +VDPA_RESET_F_CLEAN_MAP :0 ; + } + +return vdpa_reset (vdpa, flags); +} -return vdpa_reset (vdpa); +static int vhost_vdpa_reset (struct vhost_vdpa *v) +{ + v->in_batch =0 ; +return _compat_vdpa_reset (v); }static long vhost_vdpa_bind_mm (struct vhost_vdpa *v)
@@ -295,7 +306,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)vhost_vdpa_unsetup_vq_irq (v, i);if (status ==0 ) { - ret =vdpa_reset (vdpa); + ret =_compat_vdpa_reset (v);if (ret)return ret; }else
@@ -1272,6 +1283,7 @@ static void vhost_vdpa_cleanup(struct vhost_vdpa *v)vhost_vdpa_free_domain (v);vhost_dev_cleanup (&v->vdev);kfree (v->vdev.vqs); + v->vdev.vqs =NULL ; }static int vhost_vdpa_open (struct inode *inode,struct file *filep)
drivers/virtio/virtio_vdpa.c +1 -1
@@ -100,7 +100,7 @@ static void virtio_vdpa_reset(struct virtio_device *vdev) {struct vdpa_device *vdpa =vd_get_vdpa (vdev); -vdpa_reset (vdpa); +vdpa_reset (vdpa,0 ); }static bool virtio_vdpa_notify (struct virtqueue *vq)
include/linux/vdpa.h +5 -2
@@ -481,14 +481,17 @@ static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev)return vdev->dma_dev; } -static inline int vdpa_reset (struct vdpa_device *vdev) +static inline int vdpa_reset (struct vdpa_device *vdev,u32 flags) {const struct vdpa_config_ops *ops = vdev->config;int ret;down_write (&vdev->cf_lock); vdev->features_valid = false; - ret = ops->reset (vdev); +if (ops->compat_reset && flags) + ret = ops->compat_reset (vdev, flags); +else + ret = ops->reset (vdev);up_write (&vdev->cf_lock);return ret; }
Signature · 1 line
2.42.0
Sasha Levin
maintainerPATCH 7/7 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