linux-stable/drivers/platform/chrome
Noah Loomans cfd758041d platform/chrome: cros_ec_uart: properly fix race condition
commit 5e700b384e upstream.

The cros_ec_uart_probe() function calls devm_serdev_device_open() before
it calls serdev_device_set_client_ops(). This can trigger a NULL pointer
dereference:

    BUG: kernel NULL pointer dereference, address: 0000000000000000
    ...
    Call Trace:
     <TASK>
     ...
     ? ttyport_receive_buf

A simplified version of crashing code is as follows:

    static inline size_t serdev_controller_receive_buf(struct serdev_controller *ctrl,
                                                      const u8 *data,
                                                      size_t count)
    {
            struct serdev_device *serdev = ctrl->serdev;

            if (!serdev || !serdev->ops->receive_buf) // CRASH!
                return 0;

            return serdev->ops->receive_buf(serdev, data, count);
    }

It assumes that if SERPORT_ACTIVE is set and serdev exists, serdev->ops
will also exist. This conflicts with the existing cros_ec_uart_probe()
logic, as it first calls devm_serdev_device_open() (which sets
SERPORT_ACTIVE), and only later sets serdev->ops via
serdev_device_set_client_ops().

Commit 01f95d42b8 ("platform/chrome: cros_ec_uart: fix race
condition") attempted to fix a similar race condition, but while doing
so, made the window of error for this race condition to happen much
wider.

Attempt to fix the race condition again, making sure we fully setup
before calling devm_serdev_device_open().

Fixes: 01f95d42b8 ("platform/chrome: cros_ec_uart: fix race condition")
Cc: stable@vger.kernel.org
Signed-off-by: Noah Loomans <noah@noahloomans.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20240410182618.169042-2-noah@noahloomans.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-17 11:19:25 +02:00
..
wilco_ec Driver core changes for 6.4-rc1 2023-04-27 11:53:57 -07:00
Kconfig platform/chrome: cros_ec_typec: Alter module name with hyphens 2023-01-09 20:32:53 +00:00
Makefile platform/chrome: cros_ec_typec: Add initial VDM support 2023-01-09 20:32:53 +00:00
chromeos_acpi.c platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER 2023-08-10 11:10:56 +08:00
chromeos_laptop.c platform/chrome: fix double-free in chromeos_laptop_prepare() 2022-08-22 06:56:45 +00:00
chromeos_privacy_screen.c ACPI: make remove callback of ACPI driver void 2022-11-23 19:11:22 +01:00
chromeos_pstore.c
chromeos_tbmc.c
cros_ec.c platform/chrome: cros_ec_lpc: Separate host command and irq disable 2023-11-20 11:59:08 +01:00
cros_ec.h platform/chrome: cros_ec_lpc: Separate host command and irq disable 2023-11-20 11:59:08 +01:00
cros_ec_chardev.c platform/chrome: cros_ec_chardev: fix kernel data leak from ioctl 2023-03-24 10:56:28 +08:00
cros_ec_debugfs.c platform/chrome: cros_ec_debugfs: fix kernel-doc warning 2023-04-24 13:35:12 +08:00
cros_ec_i2c.c platform/chrome: Switch i2c drivers back to use .probe() 2023-05-29 08:37:29 +08:00
cros_ec_ishtp.c
cros_ec_lightbar.c platform/chrome: use sysfs_emit() instead of scnprintf() 2022-12-26 11:14:34 +08:00
cros_ec_lpc.c platform/chrome: cros_ec_lpc: Separate host command and irq disable 2023-11-20 11:59:08 +01:00
cros_ec_lpc_mec.c platform/chrome: cros_ec_lpc_mec: remove cros_ec_lpc_mec_destroy() 2022-11-01 10:33:02 +08:00
cros_ec_lpc_mec.h platform/chrome: cros_ec_lpc_mec: remove cros_ec_lpc_mec_destroy() 2022-11-01 10:33:02 +08:00
cros_ec_proto.c
cros_ec_proto_test.c platform/chrome: kunit: initialize lock for fake ec_dev 2023-11-28 17:19:39 +00:00
cros_ec_rpmsg.c
cros_ec_sensorhub.c
cros_ec_sensorhub_ring.c
cros_ec_sensorhub_trace.h
cros_ec_spi.c platform/chrome: cros_ec_spi: Use %*ph for printing hexdump of a small buffer 2023-06-13 12:28:36 +08:00
cros_ec_sysfs.c platform/chrome: use sysfs_emit_at() instead of scnprintf() 2022-12-26 16:14:53 +08:00
cros_ec_trace.c
cros_ec_trace.h
cros_ec_typec.c platform/chrome: cros_ec_typec: Configure Retimer cable type 2023-08-26 11:11:07 +02:00
cros_ec_typec.h platform/chrome: cros_ec_typec: Move structs to header 2023-01-09 20:32:53 +00:00
cros_ec_uart.c platform/chrome: cros_ec_uart: properly fix race condition 2024-04-17 11:19:25 +02:00
cros_ec_vbc.c
cros_hps_i2c.c platform/chrome: Switch i2c drivers back to use .probe() 2023-05-29 08:37:29 +08:00
cros_kbd_led_backlight.c
cros_kunit_util.c
cros_kunit_util.h
cros_typec_switch.c platform/chrome: cros_typec_switch: Add Pin D support 2023-05-11 21:17:53 +00:00
cros_typec_vdm.c platform/chrome: cros_typec_vdm: Add Attention support 2023-01-31 18:12:18 +00:00
cros_typec_vdm.h platform/chrome: cros_typec_vdm: Add Attention support 2023-01-31 18:12:18 +00:00
cros_usbpd_logger.c
cros_usbpd_notify.c platform/chrome: cros_usbpd_notify: Fix error handling in cros_usbpd_notify_init() 2022-11-25 08:28:28 +00:00