5.10.273-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 279/516 drm/amdgpu: fix ACP MFD device leak on init failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit f0013046151b7467e62c471c1c83d63ea255799c ]
acp_hw_init() registers ACP child devices with mfd_add_devices() before attaching them to the ACP power domain and initializing the hardware.
If attaching a child to the power domain fails, or if the ACP reset or clock enable operation times out, the failure path frees only the source cell, resource, and platform-data allocations. The child platform devices already registered by mfd_add_devices() remain registered and are never released.
Remove the children from the power domain and unregister the MFD devices on failures that occur after mfd_add_devices() succeeds. Keep mfd_add_devices() failures on the existing cleanup path since the MFD core already rolls back partially registered children itself.
The issue was identified by a static analysis tool I developed and confirmed by manual review.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +8 -3
@@ -354,7 +354,7 @@ static int acp_hw_init(void *handle) r =device_for_each_child (adev->acp.parent, &adev->acp.acp_genpd->gpd, acp_genpd_add_device);if (r) - goto failure; + goto failure_remove_mfd;/* Assert Soft reset of ACP */ val =cgs_read_register (adev->acp.cgs_device, mmACP_SOFT_RESET);
@@ -371,7 +371,7 @@ static int acp_hw_init(void *handle)if (--count ==0 ) {dev_err (&adev->pdev->dev,"Failed to reset ACP\n" ); r = -ETIMEDOUT ; - goto failure; + goto failure_remove_mfd; }udelay (100 ); }
@@ -389,7 +389,7 @@ static int acp_hw_init(void *handle)if (--count ==0 ) {dev_err (&adev->pdev->dev,"Failed to reset ACP\n" ); r = -ETIMEDOUT ; - goto failure; + goto failure_remove_mfd; }udelay (100 ); }
@@ -399,6 +399,11 @@ static int acp_hw_init(void *handle)cgs_write_register (adev->acp.cgs_device, mmACP_SOFT_RESET, val);return 0 ; +failure_remove_mfd: +device_for_each_child (adev->acp.parent,NULL , + acp_genpd_remove_device); +mfd_remove_devices (adev->acp.parent); + failure:kfree (i2s_pdata);kfree (adev->acp.acp_res);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 280/516 drm/amdgpu/gfx6: fix firmware leak on teardown
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willian Oliveira <[email protected]>
[ Upstream commit cc172e177795c5f87bc2d71768d077e1c10633e8 ]
The firmware requested in gfx_v6_0_init_microcode() is not released when the GFX block is torn down, leaking the firmware resources.
Add gfx_v6_0_free_microcode() and call it from gfx_v6_0_sw_fini() to release the PFP, ME, CE and RLC firmware.
--- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +9 -0
@@ -3219,6 +3219,15 @@ static int gfx_v6_0_sw_fini(void *handle)amdgpu_gfx_rlc_fini (adev); +release_firmware (adev->gfx.pfp_fw); + adev->gfx.pfp_fw =NULL ; +release_firmware (adev->gfx.me_fw); + adev->gfx.me_fw =NULL ; +release_firmware (adev->gfx.ce_fw); + adev->gfx.ce_fw =NULL ; +release_firmware (adev->gfx.rlc_fw); + adev->gfx.rlc_fw =NULL ; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 281/516 usb: octeon-hcd: fix the FIFO-flush timeout computation
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Orgad Shaneh <[email protected]>
[ Upstream commit 4c7a1b9f1f1979f2b3b69428ada12680695159c2 ]
cvmx_wait_tx_rx() computes its 100us deadline from (u64)octeon_get_clock_rate - the address of the function, not its return value; the parentheses have been missing since the CVMX_WAIT_FOR_FIELD32 macro became a function. The cast makes it compile silently, and the resulting deadline is effectively infinite.
On a healthy controller the flush bit clears on the first read and nothing is noticed. On a controller whose PHY did not come up (for example when the reference-clock configuration is wrong for the board), txfflsh/rxfflsh never clear and probe spins forever in __delay() - observed as a hard hang with a soft-lockup splat on a CN5020 board, where the board watchdog then resets the system with no console output.
Call the function, restoring the 100us timeout the code always intended.
--- drivers/staging/octeon-usb/octeon-hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/octeon-usb/octeon-hcd.c +1 -1
@@ -576,7 +576,7 @@ static int cvmx_wait_tx_rx(struct octeon_hcd *usb, int fflsh_type)int result;u64 address =CVMX_USBCX_GRSTCTL (usb->index);u64 done =cvmx_get_cycle () +100 * - (u64 )octeon_get_clock_rate /1000000 ; + (u64 )octeon_get_clock_rate () /1000000 ;union cvmx_usbcx_grstctl c;while (1 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 282/516 usb: ohci-spear: Remove unnecessary NULL check before clk_disable_unprepare()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Ni <[email protected]>
[ Upstream commit a891b9aebcc7406fe2f439d184bac3948fb08645 ]
clk_disable_unprepare() already checks NULL by using IS_ERR_OR_NULL. Remove unneeded NULL check for clk here.
Stable-dep-of: b1b0f8bdbbc8 ("usb: ohci-spear: disable controller wakeup on removal")
--- drivers/usb/host/ohci-spear.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/host/ohci-spear.c +1 -2
@@ -105,8 +105,7 @@ static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)struct spear_ohci *sohci_p =to_spear_ohci (hcd);usb_remove_hcd (hcd); -if (sohci_p->clk) -clk_disable_unprepare (sohci_p->clk); +clk_disable_unprepare (sohci_p->clk);usb_put_hcd (hcd);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 283/516 usb: ohci-spear: disable controller wakeup on removal
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit b1b0f8bdbbc891a4ee7f3b1a878c633e02b7bbeb ]
Probe enables controller wakeup after the OHCI core marks controllers with RemoteWakeupConnected as wakeup-capable. Removal does not undo this, so the wakeup source can remain attached after driver unbind.
Disable controller wakeup after removing the HCD.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/usb/host/ohci-spear.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/host/ohci-spear.c +1 -0
@@ -105,6 +105,7 @@ static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)struct spear_ohci *sohci_p =to_spear_ohci (hcd);usb_remove_hcd (hcd); +device_wakeup_disable (hcd->self.controller);clk_disable_unprepare (sohci_p->clk);usb_put_hcd (hcd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 284/516 usb: cdns3: fix use-after-free in cdns3_gadget_exit()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit ebe9b68c396792c15d0ac690d592e449e74ed804 ]
cdns3_gadget_start() arms two works on system_freezable_wq:pending_status_wq for the deferred ep0 status stage and aligned_buf_wq for realigned request buffers. Both handlers use the cdns3_device the works are embedded in, and cdns3_pending_setup_status_handler() also calls the ep0 request completion.
cdns3_gadget_exit() does not wait for these works. It frees all endpoints and aligned buffers and drops the last reference to the gadget device, which frees priv_dev, so a work queued before the exit can run after the free.
Fix this by waiting for both works after the gadget driver is unbound and the IRQ is freed, when no new work can be queued, and before the endpoints and buffers are released.
This issue was found by an in-house static analysis tool.
--- drivers/usb/cdns3/gadget.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/cdns3/gadget.c +4 -0
@@ -3254,6 +3254,10 @@ void cdns3_gadget_exit(struct cdns3 *cdns)usb_del_gadget (&priv_dev->gadget);devm_free_irq (cdns->dev, cdns->dev_irq, priv_dev); +/* The works can still be queued until the IRQ is freed. */ +cancel_work_sync (&priv_dev->pending_status_wq); +cancel_work_sync (&priv_dev->aligned_buf_wq); +cdns3_free_all_eps (priv_dev);while (!list_empty (&priv_dev->aligned_buf_list)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 285/516 usb: typec: ucsi: acpi: Assume UCSI 1.2 on Acer Nitro ANV15-41
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pannarat Wiriyaarritham <[email protected]>
[ Upstream commit 8c51ea651d043c786c37668c51624bd6b338a0ef ]
The Acer Nitro ANV15-41 exposes a functional UCSI ACPI PPM but reports a UCSI VERSION value of zero.
ucsi_register() rejects a zero version with -ENODEV, leaving the system without registered USB Type-C connectors.
The PPM works correctly when using the UCSI 1.2 layout. With UCSI 1.2 assumed, both Type-C connectors register correctly and USB Power Delivery negotiation works.
Add a DMI-specific UCSI operation for the Acer Nitro ANV15-41 that substitutes UCSI 1.2 only when firmware reports a zero version. Preserve any valid non-zero firmware version.
Tested on an Acer Nitro ANV15-41 with BIOS V1.51.
--- drivers/usb/typec/ucsi/ucsi_acpi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/usb/typec/ucsi/ucsi_acpi.c +18 -0
@@ -9,6 +9,7 @@#include <linux/platform_device.h> #include <linux/module.h> #include <linux/acpi.h> +#include <linux/dmi.h> #include "ucsi.h"
@@ -25,6 +26,16 @@ struct ucsi_acpi {guid_t guid; }; +static const struct dmi_system_id ucsi_acpi_quirks[] = { + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro ANV15-41" ), + }, + }, + { } +}; +static int ucsi_acpi_dsm (struct ucsi_acpi *ua,int func) {union acpi_object *obj;
@@ -45,6 +56,7 @@ static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_len) {struct ucsi_acpi *ua =ucsi_get_drvdata (ucsi); +u16 *version = val;int ret; ret =ucsi_acpi_dsm (ua,UCSI_DSM_FUNC_READ );
@@ -53,6 +65,12 @@ static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset,memcpy (val, (const void __force *)(ua->base + offset), val_len); +if (offset ==UCSI_VERSION && val_len ==sizeof (*version) && !*version && +dmi_check_system (ucsi_acpi_quirks)) { +dev_warn (ua->dev,"UCSI version is zero, assuming 1.2\n" ); + *version =0x0120 ; + } +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 286/516 tty: tty_port: restore TTY_IO_ERROR on activation failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 56964f6a31238fb41d5830bb42520c5b10ff7d8f ]
Make sure to restore the TTY_IO_ERROR flag if activation fails to prevent I/O attempts on a port that is gone or powered down.
This specifically avoids issues like kernel panic due to unclocked accesses or NULL-pointer dereferences when accessing powered down or deregistered ports when a TTY ioctl races with hangup and open.
Note that the flag is set again in tty_port_close() but not restoring it on activation failure leaves a window where drivers fail to handle the ioctl-hangup race.
--- drivers/tty/tty_port.c | 1 + 1 file changed, 1 insertion(+)
drivers/tty/tty_port.c +1 -0
@@ -689,6 +689,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,if (port->ops->activate) {int retval = port->ops->activate (port, tty);if (retval) { +set_bit (TTY_IO_ERROR , &tty->flags);mutex_unlock (&port->mutex);return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 287/516 tty: abort break signalling on hangup
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 845a2737e0f5ffe5ca8d38de556012b0c9472cdd ]
The break ioctls can race with hangup and end up calling into a tty driver for a device that is already gone or powered down.
Drivers must handle this race, but TCSBRK and TCSBRKP should still be aborted to avoid calling back into the driver after a user-controlled timeout (possibly even after the tty has been reopened).
Note that drivers should disable any break state on shutdown so just return on hangup (calling break_ctl() again is racy and will most likely fail for drivers handling the race).
--- drivers/tty/tty_io.c | 36 +++++++++++++++++++++++++++--------- include/linux/tty.h | 1 + 2 files changed, 28 insertions(+), 9 deletions(-)
drivers/tty/tty_io.c +27 -9
@@ -624,6 +624,8 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)tty_ldisc_hangup (tty, cons_filp !=NULL ); +wake_up_interruptible (&tty->break_wait); +spin_lock_irq (&tty->ctrl_lock);clear_bit (TTY_THROTTLED , &tty->flags);clear_bit (TTY_DO_WRITE_WAKEUP , &tty->flags);
@@ -2453,6 +2455,7 @@ static int tiocgetd(struct tty_struct *tty, int __user *p)* send_break - performed time break * @tty: device to break on * @duration: timeout in mS +* @file: file object * * Perform a timed break on hardware that lacks its own driver level * timed break functionality.
@@ -2462,8 +2465,9 @@ static int tiocgetd(struct tty_struct *tty, int __user *p)* */ -static int send_break (struct tty_struct *tty,unsigned int duration) +static int send_break (struct file *file,struct tty_struct *tty,unsigned int duration) { +long timeout;int retval;if (tty->ops->break_ctl ==NULL )
@@ -2477,13 +2481,26 @@ static int send_break(struct tty_struct *tty, unsigned int duration)return -EINTR ; retval = tty->ops->break_ctl (tty,-1 ); -if (!retval) { -msleep_interruptible (duration); - retval = tty->ops->break_ctl (tty,0 ); - }else if (retval == -EOPNOTSUPP ) { -/* some drivers can tell only dynamically */ - retval =0 ; +if (retval) { +if (retval == -EOPNOTSUPP ) { +/* some drivers can tell only dynamically */ + retval =0 ; + } + goto out_unlock; } + + timeout =msecs_to_jiffies (duration); + timeout =wait_event_interruptible_timeout (tty->break_wait, +tty_hung_up_p (file), + timeout); +/* return early on hangup only */ +if (timeout >0 ) { + retval = -EIO ; + goto out_unlock; + } + + retval = tty->ops->break_ctl (tty,0 ); +out_unlock:tty_write_unlock (tty);if (signal_pending (current))
@@ -2710,10 +2727,10 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)* This is used by the tcdrain() termios function. */ if (!arg) -return send_break (tty,250 ); +return send_break (file, tty,250 );return 0 ;case TCSBRKP :/* support for POSIX tcsendbreak() */ -return send_break (tty, arg ? arg*100 :250 ); +return send_break (file, tty, arg ? arg *100 :250 );case TIOCMGET :return tty_tiocmget (tty, p);
@@ -3093,6 +3110,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)init_ldsem (&tty->ldisc_sem);init_waitqueue_head (&tty->write_wait);init_waitqueue_head (&tty->read_wait); +init_waitqueue_head (&tty->break_wait);INIT_WORK (&tty->hangup_work, do_tty_hangup);mutex_init (&tty->atomic_write_lock);spin_lock_init (&tty->ctrl_lock);
include/linux/tty.h +1 -0
@@ -303,6 +303,7 @@ struct tty_struct {struct fasync_struct *fasync;wait_queue_head_t write_wait;wait_queue_head_t read_wait; +wait_queue_head_t break_wait;struct work_struct hangup_work;void *disc_data;void *driver_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 288/516 tty: serial: max3100: shut down timer before freeing port
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit db0949bbd06db0a75b4b1076f1e25194be7d956a ]
max3100_shutdown() stops the polling timer but returns early during system suspend. If the SPI device is unbound before resume, the serial core does not call max3100_shutdown() again, so max3100_remove() frees the port while the timer remains armed. max3100_timeout() may then access the freed port and re-arm the timer.
Add final timer teardown to max3100_remove() and use timer_shutdown_sync() to prevent a racing callback from re-arming it. Also free the IRQ and destroy the workqueue there before freeing the port. Keep timer_delete_sync() in max3100_shutdown() so that a subsequent open() can re-arm the timer.
The workqueue is created before request_irq() and destroyed on both request_irq() failure and normal shutdown. Its presence at remove thus identifies the IRQ left registered when suspend bypasses shutdown.
Free the IRQ before destroying the workqueue, in both max3100_shutdown() and max3100_remove(), and cancel the pending work in between. free_irq() waits for a running interrupt handler to finish and no new handler can start afterwards, so a racing handler cannot queue work on a workqueue that is being destroyed; the force_end_work check in max3100_dowork() only narrows that window, as a handler delayed between the check and queue_work() could still run after the teardown has cleared the workqueue pointer. Cancelling the work also keeps destroy_workqueue() from waiting on a queued work item in case remove() ever runs while the freezable workqueue is still frozen, e.g. device removal during the resume window, before workqueues are thawed.
This issue was found by an in-house static analysis tool.
--- drivers/tty/serial/max3100.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/tty/serial/max3100.c +12 -3
@@ -571,12 +571,11 @@ static void max3100_shutdown(struct uart_port *port)del_timer_sync (&s->timer);if (s->workqueue) { -flush_workqueue (s->workqueue); +free_irq (s->irq, s); +cancel_work_sync (&s->work);destroy_workqueue (s->workqueue); s->workqueue =NULL ; } -if (s->irq) -free_irq (s->irq, s);/* set shutdown mode to save power */ if (s->max3100_hw_suspend)
@@ -835,6 +834,16 @@ static int max3100_remove(struct spi_device *spi)if (max3100s[i] == s) {dev_dbg (&spi->dev,"%s: removing port %d\n" , __func__, i);uart_remove_one_port (&max3100_uart_driver, &max3100s[i]->port); + + s->force_end_work =1 ; +/* Only the timer callback can rearm it after port removal. */ +timer_delete_sync (&s->timer); +if (s->workqueue) { +free_irq (s->irq, s); +cancel_work_sync (&s->work); +destroy_workqueue (s->workqueue); + s->workqueue =NULL ; + }kfree (max3100s[i]); max3100s[i] =NULL ;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 289/516 Input: s6sy761 - fix resume ordering and restore sensing
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Heidelberg <[email protected]>
[ Upstream commit a215720959c5450b3699e243904b39c3f8f68888 ]
System suspend powers the controller off and resume powers it back on, but the resume path enables the interrupt before s6sy761_power_on() checks the boot. The firmware raises its boot-complete event on the interrupt line, the threaded handler consumes it, s6sy761_power_on() then reads an empty event and resume fails with -ENODEV, skipping the touch function setup:
s6sy761 2-0048: PM: dpm_run_callback(): s6sy761_resume [s6sy761] returns -19
Power the chip on first and only then unmask the interrupt. Once resume completes the boot handshake the chip comes back with sensing off, as at probe where input_open() turns it on, so the touchscreen stays dead after resume. Send SENSE_ON again when the input device is open.
Tested on a Pixel 3 XL over several s2idle cycles: resume succeeds and the touch function and sense status match the pre-suspend state.
--- drivers/input/touchscreen/s6sy761.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/input/touchscreen/s6sy761.c +13 -1
@@ -510,10 +510,22 @@ static int __maybe_unused s6sy761_suspend(struct device *dev)static int __maybe_unused s6sy761_resume (struct device *dev) {struct s6sy761_data *sdata =dev_get_drvdata (dev); +int err; + + err =s6sy761_power_on (sdata); +if (err) +return err;enable_irq (sdata->client->irq); -return s6sy761_power_on (sdata); +mutex_lock (&sdata->input->mutex); + +if (sdata->input->users) + err =i2c_smbus_write_byte (sdata->client,S6SY761_SENSE_ON ); + +mutex_unlock (&sdata->input->mutex); + +return err; }static const struct dev_pm_ops s6sy761_pm_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 290/516 tty: vt: fix memory leak in vc_allocate()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingyu Wang <[email protected]>
[ Upstream commit 5b114bfc1dfd88f9d50822d532f7f1fce0f7388a ]
If the screen buffer allocation fails in vc_allocate(), the error handling path jumps to err_free. However, this path fails to release the unicode screen map attached to vc->uni_pagedict_loc.
During the early stages of vc_allocate(), the unicode screen map is either newly allocated via con_set_default_unimap() or shares the default unicode map from a previously initialized console (which increments its refcount). If the subsequent kzalloc() for the screen buffer fails, the err_free path frees the vc structure but leaves the attached uni_pagedict with an elevated refcount. This results in an unreferenced object memory leak, as the reference to the dictionary is lost and its refcount can never reach zero.
This issue was discovered by DevGen (an automated virtual device modeling fuzzer based on Syzkaller). During fuzzing with kernel fault injection (failslab) enabled, the fuzzer forcefully failed the kzalloc() for the screen buffer, exposing this error-handling path leak.
Fix this by checking *vc->uni_pagedict_loc and calling con_free_unimap(vc) in the err_free path before kfree(vc). This safely decrements the refcount and releases the dictionary memory if this was the last reference. The explicit check is added to maintain consistency with other callers.
--- drivers/tty/vt/vt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/vt/vt.c +2 -0
@@ -1161,6 +1161,8 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */return 0 ; err_free:visual_deinit (vc); +if (*vc->vc_uni_pagedir_loc) +con_free_unimap (vc);kfree (vc); vc_cons[currcons].d =NULL ;return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 291/516 serial: fix TIOCMIWAIT race
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 40adffec8c0090533dfaa863ced7901b60bbf1dc ]
The task state must be updated before checking the wakeup condition to avoid missing a racing modem status update.
--- drivers/tty/serial/serial_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/serial_core.c +2 -2
@@ -1240,12 +1240,12 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg)add_wait_queue (&port->delta_msr_wait, &wait);for (;;) { +set_current_state (TASK_INTERRUPTIBLE ); +spin_lock_irq (&uport->lock);memcpy (&cnow, &uport->icount,sizeof (struct uart_icount ));spin_unlock_irq (&uport->lock); -set_current_state (TASK_INTERRUPTIBLE ); - if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 292/516 drm/amd/display: Mark DCE 6.4 as not APU
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit 3a52d587d1fc8e8bf94ba1b07374f7ec91aaffb4 ]
DCE 6.4 is found in Oland chips, which were advertised as low-end gaming GPUs in 2013~2015 and then have been sold as low-end workstation GPUs until 2017~2019.
These are not APUs.
--- drivers/gpu/drm/amd/display/dc/dce60/dce60_resource.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dce60/dce60_resource.c +0 -1
@@ -1359,7 +1359,6 @@ static bool dce64_construct( dc->caps.max_downscale_ratio =200 ; dc->caps.i2c_speed_in_khz =40 ; dc->caps.max_cursor_size =64 ; - dc->caps.is_apu = true;/************************************************* * Create resources *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 293/516 wifi: mac80211: keep fallback association elements alive
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit a10a2f80476d166fd81c361ec0319493671b694e ]
Associating to a non-transmitted MBSSID profile reads freed memory while determining the operating channel and applying HT capabilities.
When an association response omits WMM, HT, or VHT information, ieee80211_assoc_config_link() parses the cached BSS IEs and copies the missing element pointers out of that fallback parse. For a non-transmitted MBSSID profile those pointers refer to merged-profile storage owned by the parse object, and the fallback block frees that object at its end. The copied pointers are used afterwards to determine the operating channel, configure bandwidth, and apply HT capabilities.
Keep the fallback parse result alive until association setup finishes.
--- net/mac80211/mlme.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/mac80211/mlme.c +2 -2
@@ -3284,6 +3284,7 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,u16 capab_info, aid;struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;const struct cfg80211_bss_ies *bss_ies =NULL ; +struct ieee802_11_elems bss_elems = {};struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;bool is_6ghz = cbss->channel->band ==NL80211_BAND_6GHZ ;bool is_s1g = cbss->channel->band ==NL80211_BAND_S1GHZ ;
@@ -3346,7 +3347,6 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && (!elems->vht_cap_elem || !elems->vht_operation)))) {const struct cfg80211_bss_ies *ies; -struct ieee802_11_elems bss_elems;rcu_read_lock (); ies =rcu_dereference (cbss->ies);
@@ -3396,7 +3396,6 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,sdata_info (sdata,"AP bug: VHT operation missing from AssocResp\n" ); } -kfree (bss_elems.nontx_profile); }/*
@@ -3652,6 +3651,7 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, ret = true; out: +kfree (bss_elems.nontx_profile);kfree (bss_ies);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 294/516 thunderbolt: Fix KASAN reported use-after-free when request is canceled
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mika Westerberg <[email protected]>
[ Upstream commit a02188ddc24b7872f0c5e0c5873f827318717803 ]
Alan reported that when doing stress testing sometimes KASAN notices use-after-free during control channel operation (stripped down keeping the relevant parts):
BUG: KASAN: slab-use-after-free in tb_cfg_request_sync+0x240/0x250 [thunderbolt] Read of size 24 at addr ffff88811067f290 by task kworker/u40:2/1760 <TASK> tb_cfg_request_sync+0x240/0x250 [thunderbolt] tb_cfg_read_raw+0x367/0x510 [thunderbolt] tb_cfg_read+0xec/0x240 [thunderbolt] tb_port_get_link_generation+0x258/0x420 [thunderbolt] tb_usb3_consumed_bandwidth+0x1c1/0x2c0 [thunderbolt] tb_tunnel_consumed_bandwidth+0xfd/0x910 [thunderbolt] tb_available_bandwidth+0x5f2/0xeb0 [thunderbolt] tb_recalc_estimated_bandwidth+0x2a0/0x1bc0 [thunderbolt] tb_handle_dp_bandwidth_request+0x1897/0x5e20 [thunderbolt] process_one_work+0x675/0x1230 worker_thread+0x5e6/0xf70 kthread+0x365/0x470 ret_from_fork+0x54d/0x710 ret_from_fork_asm+0x1a/0x30 </TASK> Allocated by task 1760: __kmalloc_cache_noprof+0x1ee/0x550 tb_cfg_read_raw+0x1d3/0x510 [thunderbolt] tb_cfg_read+0xec/0x240 [thunderbolt] tb_port_get_link_generation+0x258/0x420 [thunderbolt] tb_usb3_consumed_bandwidth+0x1c1/0x2c0 [thunderbolt] tb_tunnel_consumed_bandwidth+0xfd/0x910 [thunderbolt] tb_available_bandwidth+0x5f2/0xeb0 [thunderbolt] tb_recalc_estimated_bandwidth+0x2a0/0x1bc0 [thunderbolt] tb_handle_dp_bandwidth_request+0x1897/0x5e20 [thunderbolt] process_one_work+0x675/0x1230 worker_thread+0x5e6/0xf70 kthread+0x365/0x470 ret_from_fork+0x54d/0x710 ret_from_fork_asm+0x1a/0x30 Freed by task 926: kfree+0x18f/0x4a0 tb_cfg_request_put+0xb7/0xe0 [thunderbolt] tb_cfg_request_work+0x82/0x120 [thunderbolt] process_one_work+0x675/0x1230 worker_thread+0x5e6/0xf70 kthread+0x365/0x470 ret_from_fork+0x54d/0x710 ret_from_fork_asm+0x1a/0x30 Second to last potentially related work creation: __queue_work+0x575/0xd00 queue_work_on+0x77/0x80 tb_cfg_request_cancel+0xc7/0x260 [thunderbolt] tb_cfg_request_sync+0x1f6/0x250 [thunderbolt] tb_cfg_read_raw+0x367/0x510 [thunderbolt] tb_cfg_read+0xec/0x240 [thunderbolt] tb_port_get_link_generation+0x258/0x420 [thunderbolt] tb_usb3_consumed_bandwidth+0x1c1/0x2c0 [thunderbolt] tb_tunnel_consumed_bandwidth+0xfd/0x910 [thunderbolt] tb_available_bandwidth+0x5f2/0xeb0 [thunderbolt] tb_recalc_estimated_bandwidth+0x2a0/0x1bc0 [thunderbolt] tb_handle_dp_bandwidth_request+0x1897/0x5e20 [thunderbolt] process_one_work+0x675/0x1230 worker_thread+0x5e6/0xf70 kthread+0x365/0x470 ret_from_fork+0x54d/0x710 ret_from_fork_asm+0x1a/0x30
The last stack trace is helpful because it shows that we are cancelling a request and looking at tb_cfg_request_cancel() what might happen is that tb_cfg_request_work() completes right before tb_cfg_request_cancel() starts and because of this it will call schedule_work() queueing the same work to run again. However, it is already removed from the request_queue and reference count is dropped so when tb_cfg_request_work() triggers again it will access memory that is already released.
Fix this so that we first make sure a cancelled request is not handed away from tb_cfg_request_find() or scheduled to run. Then instead of relying on the worker to clean up the request we will do it in tb_cfg_request_cancel() after the work is canceled from running. Make tb_cfg_request_dequeue() release the request only if it was actually removed from the queue.
--- drivers/thunderbolt/ctl.c | 47 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-)
drivers/thunderbolt/ctl.c +23 -24
@@ -53,7 +53,6 @@ struct tb_ctl { #define tb_ctl_dbg(ctl, format, arg...) \ dev_dbg(&(ctl)->nhi->pdev->dev, format, ## arg) -static DECLARE_WAIT_QUEUE_HEAD (tb_cfg_request_cancel_queue);/* Serializes access to request kref_get/put */ static DEFINE_MUTEX (tb_cfg_request_lock);
@@ -111,11 +110,14 @@ void tb_cfg_request_put(struct tb_cfg_request *req)static int tb_cfg_request_enqueue (struct tb_ctl *ctl,struct tb_cfg_request *req) { +tb_cfg_request_get (req); +WARN_ON (test_bit (TB_CFG_REQUEST_ACTIVE , &req->flags));WARN_ON (req->ctl);mutex_lock (&ctl->request_queue_lock);if (!ctl->running) { +tb_cfg_request_put (req);mutex_unlock (&ctl->request_queue_lock);return -ENOTCONN ; }
@@ -126,28 +128,24 @@ static int tb_cfg_request_enqueue(struct tb_ctl *ctl,return 0 ; } +static bool tb_cfg_request_is_active (struct tb_cfg_request *req) +{ +return test_bit (TB_CFG_REQUEST_ACTIVE , &req->flags); +} +static void tb_cfg_request_dequeue (struct tb_cfg_request *req) {struct tb_ctl *ctl = req->ctl;mutex_lock (&ctl->request_queue_lock); -if (!test_bit (TB_CFG_REQUEST_ACTIVE , &req->flags)) { -mutex_unlock (&ctl->request_queue_lock); -return ; +if (tb_cfg_request_is_active (req)) { +list_del (&req->list); +clear_bit (TB_CFG_REQUEST_ACTIVE , &req->flags); +tb_cfg_request_put (req); } - -list_del (&req->list); -clear_bit (TB_CFG_REQUEST_ACTIVE , &req->flags); -if (test_bit (TB_CFG_REQUEST_CANCELED , &req->flags)) -wake_up (&tb_cfg_request_cancel_queue);mutex_unlock (&ctl->request_queue_lock); } -static bool tb_cfg_request_is_active (struct tb_cfg_request *req) -{ -return test_bit (TB_CFG_REQUEST_ACTIVE , &req->flags); -} -static struct tb_cfg_request *tb_cfg_request_find (struct tb_ctl *ctl,struct ctl_pkg *pkg) {
@@ -157,7 +155,8 @@ tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg)mutex_lock (&pkg->ctl->request_queue_lock);list_for_each_entry (req, &pkg->ctl->request_queue, list) {tb_cfg_request_get (req); -if (req->match (req, pkg)) { +if (!test_bit (TB_CFG_REQUEST_CANCELED , &req->flags) && + req->match (req, pkg)) { found = true;break ; }
@@ -484,8 +483,11 @@ static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame,*/ req =tb_cfg_request_find (pkg->ctl, pkg);if (req) { -if (req->copy (req, pkg)) +mutex_lock (&pkg->ctl->request_queue_lock); +if (!test_bit (TB_CFG_REQUEST_CANCELED , &req->flags) && + req->copy (req, pkg))schedule_work (&req->work); +mutex_unlock (&pkg->ctl->request_queue_lock);tb_cfg_request_put (req); }
@@ -501,7 +503,6 @@ static void tb_cfg_request_work(struct work_struct *work) req->callback (req->callback_data);tb_cfg_request_dequeue (req); -tb_cfg_request_put (req); }/**
@@ -525,10 +526,9 @@ int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req,INIT_WORK (&req->work, tb_cfg_request_work);INIT_LIST_HEAD (&req->list); -tb_cfg_request_get (req); ret =tb_cfg_request_enqueue (ctl, req);if (ret) - goto err_put; +return ret; ret =tb_ctl_tx (ctl, req->request, req->request_size, req->request_type);
@@ -542,9 +542,6 @@ int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req, err_dequeue:tb_cfg_request_dequeue (req); -err_put: -tb_cfg_request_put (req); -return ret; }
@@ -558,9 +555,11 @@ int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req,*/ void tb_cfg_request_cancel (struct tb_cfg_request *req,int err) { +mutex_lock (&req->ctl->request_queue_lock);set_bit (TB_CFG_REQUEST_CANCELED , &req->flags); -schedule_work (&req->work); -wait_event (tb_cfg_request_cancel_queue, !tb_cfg_request_is_active (req)); +mutex_unlock (&req->ctl->request_queue_lock); +cancel_work_sync (&req->work); +tb_cfg_request_dequeue (req); req->result.err = err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 295/516 USB: serial: fix ioctl hangup race
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit ae0e61d95677efa778379853e495d748e6efbf95 ]
The tty ioctls can race with hangup and end up calling into a tty driver for a device that is already gone or powered down.
Serialise the callbacks using the tty port mutex and add the missing checks to make sure the port has not been hung up before accessing port driver data or hardware.
This specifically avoids dereferencing a NULL-pointer if a device is disconnected during lengthy break signalling.
Note that TIOCGICOUNT and TIOCMIWAIT do not access port driver data or hardware and are therefore not affected by the race.
--- drivers/usb/serial/generic.c | 10 ++- drivers/usb/serial/usb-serial.c | 111 +++++++++++++++++++++++++------- drivers/usb/serial/usb_wwan.c | 6 +- 3 files changed, 99 insertions(+), 28 deletions(-)
drivers/usb/serial/generic.c +9 -1
@@ -268,6 +268,7 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);void usb_serial_generic_wait_until_sent (struct tty_struct *tty,long timeout) {struct usb_serial_port *port = tty->driver_data; +struct tty_port *tport = &port->port;unsigned int bps;unsigned long period;unsigned long expire;
@@ -287,7 +288,14 @@ void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout) __func__,jiffies_to_msecs (timeout), jiffies_to_msecs(period)); expire = jiffies + timeout; -while (!port->serial->type->tx_empty (port)) { +for (;;) { +mutex_lock (&tport->mutex); +if (tty_io_error (tty) || port->serial->type->tx_empty (port)) { +mutex_unlock (&tport->mutex); +break ; + } +mutex_unlock (&tport->mutex); +schedule_timeout_interruptible (period);if (signal_pending (current))break ;
drivers/usb/serial/usb-serial.c +88 -23
187 lines not on this page · raw message
drivers/usb/serial/usb_wwan.c +2 -4
@@ -139,7 +139,7 @@ int usb_wwan_get_serial_info(struct tty_struct *tty, ss->line = port->minor; ss->port = port->port_number; - ss->baud_base =tty_get_baud_rate (port->port.tty); + ss->baud_base =tty_get_baud_rate (tty); ss->close_delay =jiffies_to_msecs (port->port.close_delay) /10 ; ss->closing_wait = port->port.closing_wait ==ASYNC_CLOSING_WAIT_NONE ? ASYNC_CLOSING_WAIT_NONE :
@@ -160,8 +160,7 @@ int usb_wwan_set_serial_info(struct tty_struct *tty, ASYNC_CLOSING_WAIT_NONE :msecs_to_jiffies (ss->closing_wait *10 ); -mutex_lock (&port->port.mutex); - +/* core holds the port mutex */ if (!capable (CAP_SYS_ADMIN )) {if ((close_delay != port->port.close_delay) || (closing_wait != port->port.closing_wait))
@@ -173,7 +172,6 @@ int usb_wwan_set_serial_info(struct tty_struct *tty, port->port.closing_wait = closing_wait; } -mutex_unlock (&port->port.mutex);return retval; }EXPORT_SYMBOL (usb_wwan_set_serial_info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 296/516 mtd: block2mtd: Fix divide error when erase_size is zero
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit b5965c4221165045e19736794ca5f48ae3d67142 ]
The erase size is parsed from the "block2mtd" module parameter and can be set to zero. add_device() then evaluates
if (size % erase_size)
with a zero divisor, which triggers a divide error:
divide error: 0000 [#1] PREEMPT SMP PTI
RIP: 0010:add_device drivers/mtd/devices/block2mtd.c:296 [inline] RIP: 0010:block2mtd_setup2+0x592/0xda0 drivers/mtd/devices/block2mtd.c:459 Call Trace: block2mtd_setup+0x27/0xe0 drivers/mtd/devices/block2mtd.c:476 param_attr_store+0x214/0x310 kernel/params.c:589 module_attr_store+0x65/0x90 kernel/params.c:904 kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
...
Reject a zero erase size before performing the modulo operation so the existing "erasesize must be a divisor of device size" error path reports the invalid argument and frees the device.
--- drivers/mtd/devices/block2mtd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/devices/block2mtd.c +1 -1
@@ -269,7 +269,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, goto err_free_block2mtd; } -if ((long )dev->blkdev->bd_inode->i_size % erase_size) { +if (!erase_size || (long )dev->blkdev->bd_inode->i_size % erase_size) {pr_err ("erasesize must be a divisor of device size\n" ); goto err_free_block2mtd; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 297/516 mtd: spinand: Enable QE on all dies
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Han Xu <[email protected]>
[ Upstream commit 63d6cace2c4a7f36c1cb44f1bb5e0f3ef19e5c7f ]
The QUAD ENABLE (QE) bit is stored in a per-die configuration register on some SPI-NAND devices. When a device contains multiple dies, updating the QE bit only on the currently selected die can leave the remaining dies operating in non-quad mode.
Iterate over all targets and update the QE setting on each die during initialization to ensure consistent quad I/O operation across the entire device.
Tested on ISSI IS38SMW04G8B.
--- drivers/mtd/nand/spi/core.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/mtd/nand/spi/core.c +19 -2
@@ -172,7 +172,10 @@ static int spinand_init_cfg_cache(struct spinand_device *spinand)static int spinand_init_quad_enable (struct spinand_device *spinand) { +struct nand_device *nand =spinand_to_nand (spinand); +unsigned int target;bool enable = false; +int ret;if (!(spinand->flags &SPINAND_HAS_QE_BIT ))return 0 ;
@@ -182,8 +185,22 @@ static int spinand_init_quad_enable(struct spinand_device *spinand) spinand->op_templates.update_cache->data.buswidth == 4) enable = true; -return spinand_upd_cfg (spinand,CFG_QUAD_ENABLE , - enable ?CFG_QUAD_ENABLE :0 ); +/* +* QE is a per-die setting on some devices. Program each target +* individually when enabling or disabling quad I/O mode. +*/ +for (target =0 ; target < nand->memorg.ntargets; target++) { + ret =spinand_select_target (spinand, target); +if (ret) +return ret; + + ret =spinand_upd_cfg (spinand,CFG_QUAD_ENABLE , + enable ?CFG_QUAD_ENABLE :0 ); +if (ret) +return ret; + } + +return 0 ; } static int spinand_ecc_enable(struct spinand_device *spinand,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 298/516 wifi: mac80211: account proxy paths against the mesh path limit
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit a5f35d4b112af1415ff06bd501c8cc26cc08aa8b ]
Proxy-path churn can drive the interface path counter negative and let later mesh path additions exceed MESH_MAX_MPATHS.
mesh_path_free_rcu() decrements the interface mpaths counter for entries from both the mesh and proxy path tables, but mpp_path_add() never reserves a slot in that counter. Removing or expiring a proxy path therefore returns a slot that was never charged.
mesh_path_add() uses the same counter to enforce MESH_MAX_MPATHS, so once it falls below the number of installed paths the limit no longer holds.
Reserve the shared quota before allocating a proxy path and release it on every unsuccessful addition. Mesh and proxy paths now share one 1024-entry budget, so mpp_path_add() can return -ENOSPC at that limit.
--- net/mac80211/mesh_pathtbl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/mac80211/mesh_pathtbl.c +9 -2
@@ -449,10 +449,15 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,if (is_multicast_ether_addr (dst))return -ENOTSUPP ; +if (!atomic_add_unless (&sdata->u.mesh.mpaths,1 ,MESH_MAX_MPATHS )) +return -ENOSPC ; + new_mpath =mesh_path_new (sdata, dst,GFP_ATOMIC ); -if (!new_mpath) +if (!new_mpath) { +atomic_dec (&sdata->u.mesh.mpaths);return -ENOMEM ; + }memcpy (new_mpath->mpp, mpp,ETH_ALEN ); tbl = &sdata->u.mesh.mpp_paths;
@@ -465,8 +470,10 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,hlist_add_head_rcu (&new_mpath->walk_list, &tbl->walk_head);spin_unlock_bh (&tbl->walk_lock); -if (ret) +if (ret) {kfree (new_mpath); +atomic_dec (&sdata->u.mesh.mpaths); + } sdata->u.mesh.mpp_paths_generation++;return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 299/516 USB: serial: clean up core error labels
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 96a83c95c3da5ba55ea2cf6ce87de10fc03417a9 ]
Clean up the core error labels by consistently naming them after what they do rather than after from where they are jumped to.
Stable-dep-of: 646e5b28b4fd ("USB: serial: fix driver deregistration order")
--- drivers/usb/serial/usb-serial.c | 34 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-)
drivers/usb/serial/usb-serial.c +16 -18
@@ -187,17 +187,17 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty) serial = port->serial;if (!try_module_get (serial->type->driver.owner)) - goto error_module_get; + goto err_put_serial; retval =usb_autopm_get_interface (serial->interface);if (retval) - goto error_get_interface; + goto err_put_module; init_termios = (driver->termios[idx] ==NULL ); retval =tty_standard_install (driver, tty);if (retval) - goto error_init_termios; + goto err_put_autopm;mutex_unlock (&serial->disc_mutex);
@@ -209,11 +209,11 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)return retval; - error_init_termios: +err_put_autopm:usb_autopm_put_interface (serial->interface); - error_get_interface: +err_put_module:module_put (serial->type->driver.owner); - error_module_get: +err_put_serial:usb_serial_put (serial);mutex_unlock (&serial->disc_mutex);return retval;
@@ -1287,7 +1287,7 @@ static int __init usb_serial_init(void) result =bus_register (&usb_serial_bus_type);if (result) {pr_err ("%s - registering bus driver failed\n" , __func__); - goto exit_bus; + goto err_put_driver; } usb_serial_tty_driver->driver_name ="usbserial" ;
@@ -1308,25 +1308,23 @@ static int __init usb_serial_init(void) result =tty_register_driver (usb_serial_tty_driver);if (result) {pr_err ("%s - tty_register_driver failed\n" , __func__); - goto exit_reg_driver; + goto err_unregister_bus; }/* register the generic driver, if we should */ result =usb_serial_generic_register ();if (result <0 ) {pr_err ("%s - registering generic driver failed\n" , __func__); - goto exit_generic; + goto err_unregister_driver; }return result; -exit_generic: +err_unregister_driver:tty_unregister_driver (usb_serial_tty_driver); - -exit_reg_driver: +err_unregister_bus:bus_unregister (&usb_serial_bus_type); - -exit_bus: +err_put_driver:pr_err ("%s - returning with error %d\n" , __func__, result);put_tty_driver (usb_serial_tty_driver);return result;
@@ -1471,13 +1469,13 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] rc =usb_register (udriver);if (rc) - goto failed_usb_register; + goto err_free_driver;for (sd = serial_drivers; *sd; ++sd) { (*sd)->usb_driver = udriver; rc =usb_serial_register (*sd);if (rc) - goto failed; + goto err_deregister_drivers; }/* Now set udriver's id_table and look for matches */
@@ -1485,11 +1483,11 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] rc =driver_attach (&udriver->drvwrap.driver);return 0 ; - failed: +err_deregister_drivers:while (sd-- > serial_drivers)usb_serial_deregister (*sd);usb_deregister (udriver); -failed_usb_register: +err_free_driver:kfree (udriver);return rc; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 300/516 USB: serial: fix driver deregistration order
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 646e5b28b4fdbc1b828a2398d6ced2c1dd308a46 ]
USB serial driver modules register one driver for the USB bus and one or more drivers for the ports on the USB serial bus.
When unloading a driver module, the USB driver must be deregistered before the USB serial bus drivers so that I/O is stopped before unbinding the ports to avoid use-after-free in completion handlers accessing port data.
Note that the "new_id" attributes must first be removed to prevent new ids from being added and triggering a probe of the USB driver after it has been deregistered.
--- drivers/usb/serial/bus.c | 4 ++++ drivers/usb/serial/usb-serial.c | 21 ++++++++++++++++++--- include/linux/usb/serial.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-)
drivers/usb/serial/bus.c +4 -0
@@ -188,3 +188,7 @@ void usb_serial_bus_deregister(struct usb_serial_driver *driver)free_dynids (driver); } +void usb_serial_bus_remove_new_id (struct usb_serial_driver *driver) +{ +driver_remove_file (&driver->driver, &driver_attr_new_id); +}
drivers/usb/serial/usb-serial.c +18 -3
@@ -1432,7 +1432,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] {int rc;struct usb_driver *udriver; -struct usb_serial_driver *const *sd; +struct usb_serial_driver *const *sd, *const *s;/* * udriver must be registered before any of the serial drivers,
@@ -1484,9 +1484,11 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]return 0 ; err_deregister_drivers: +for (s = serial_drivers; s < sd; ++s) +usb_serial_bus_remove_new_id (*s); +usb_deregister (udriver);while (sd-- > serial_drivers)usb_serial_deregister (*sd); -usb_deregister (udriver); err_free_driver:kfree (udriver);return rc;
@@ -1504,10 +1506,23 @@ EXPORT_SYMBOL_GPL(usb_serial_register_drivers);void usb_serial_deregister_drivers (struct usb_serial_driver *const serial_drivers[]) {struct usb_driver *udriver = (*serial_drivers)->usb_driver; +struct usb_serial_driver *const *sd; + +/* +* udriver must be deregistered before the serial drivers so that +* I/O is stopped before unbinding the ports. +* +* Remove the new_id attributes to prevent ids from being added and +* triggering a probe of udriver after it has been deregistered. +*/ +for (sd = serial_drivers; *sd; ++sd) +usb_serial_bus_remove_new_id (*sd); + +usb_deregister (udriver);for (; *serial_drivers; ++serial_drivers)usb_serial_deregister (*serial_drivers); -usb_deregister (udriver); +kfree (udriver); }EXPORT_SYMBOL_GPL (usb_serial_deregister_drivers);
include/linux/usb/serial.h +1 -0
@@ -378,6 +378,7 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,int usb_serial_bus_register (struct usb_serial_driver *device);void usb_serial_bus_deregister (struct usb_serial_driver *device); +void usb_serial_bus_remove_new_id (struct usb_serial_driver *driver);extern struct bus_type usb_serial_bus_type;extern struct tty_driver *usb_serial_tty_driver;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 301/516 bnxt_en: fix DMA mapping length for padded small packets
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a51d233ccd4889aadb71dace863525cc2b00271e ]
Stefan Fleischmann reported Intel IOMMU DMA Read faults on BCM57412 NetXtreme-E NICs when transmitting packets on VLAN/macvlan interfaces:
DMAR: [DMA Read NO_PASID] Request device [18:00.0] fault addr 0xfc499000
[fault reason 0x06] PTE Read access is not set
bnxt_en 0000:18:00.0 eno1np0: Abandoning msg {0xb4 0x41a} len: 0 due to firmware status: 0x2000001
...
NETDEV WATCHDOG: eno1np0 (bnxt_en): transmit queue 0 timed out
The fault address (0xfc499000) is on an exact 4KB page boundary, pointing to a DMA read buffer overrun.
In bnxt_start_xmit(), packets smaller than BNXT_MIN_PKT_SIZE (52 bytes), such as 42-byte untagged ARP frames, are padded:
if (length < BNXT_MIN_PKT_SIZE) {
pad = BNXT_MIN_PKT_SIZE - length;
if (skb_pad(skb, pad))
goto tx_kick_pending;
length = BNXT_MIN_PKT_SIZE;
}
mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
...
dma_unmap_len_set(tx_buf, len, len);However, 'len' was initialized earlier to skb_headlen(skb) (e.g. 42 bytes) and is left unadjusted after padding. Consequently, dma_map_single() and dma_unmap_len_set() map and track only 42 bytes.
Later, the hardware TX buffer descriptor is programmed with the padded length:
txbd->tx_bd_len_flags_type =
cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
TX_BD_FLAGS_PACKET_END);The NIC DMA engine is thus instructed to read 52 bytes from a region where only 42 bytes were DMA-mapped. If skb->data ends near the boundary of a 4KB page (within 'pad' bytes of the next page), the hardware DMA read overruns into the unmapped adjacent page, triggering an IOMMU fault.
This issue was exposed after commit 447cbe95ebb9 ("vlan: fix skb_under_panic and races when toggling HW VLAN offload") because reserving extra VLAN headroom rounded LL_RESERVED_SPACE from 48 up to 64 bytes, shifting skb->data offsets and potentially causing small frames to land right against page boundaries.
Fix this by using skb_put_padto(skb, BNXT_MIN_PKT_SIZE) in bnxt_start_xmit(), before skb_shinfo(skb)->nr_frags is sampled, because padding might linearize the skb.
This ensures skb->len and skb_headlen(skb) reflect the padded size so that dma_map_single() maps the full buffer and the descriptor length is consistent. This also removes the temporary 'pad' variable and masking logic.
The padding is done after the SW USO branch, otherwise bnxt_sw_udp_gso_xmit() would account the padding as UDP payload and send it in extra segments.
Note that SW USO segments are still not padded: with IPv4, a segment carrying less than 10 bytes of UDP payload (small gso_size, or a short last segment) is sent as a frame shorter than BNXT_MIN_PKT_SIZE. This is a separate issue, left for a followup patch.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -13
@@ -429,7 +429,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)struct netdev_queue *txq;int i;dma_addr_t mapping; -unsigned int length, pad =0 ; +unsigned int length;u32 len, free_size, vlan_tag_flags, cfa_action, flags;u16 prod, last_frag;struct pci_dev *pdev = bp->pdev;
@@ -447,6 +447,14 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) txr = &bp->tx_ring[bp->tx_ring_map[i]]; prod = txr->tx_prod; +/* Must be done before skb_shinfo(skb)->nr_frags is sampled, +* because skb_put_padto() might linearize the skb. +*/ +if (skb_put_padto (skb,BNXT_MIN_PKT_SIZE )) { +/* SKB already freed. */ + goto tx_kick_pending; + } + free_size =bnxt_tx_avail (bp, txr);if (unlikely (free_size <skb_shinfo (skb)->nr_frags +2 )) {/* We must have raced with NAPI cleanup */
@@ -554,14 +562,6 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) } normal_tx: -if (length <BNXT_MIN_PKT_SIZE ) { - pad =BNXT_MIN_PKT_SIZE - length; -if (skb_pad (skb, pad)) -/* SKB already freed. */ - goto tx_kick_pending; - length =BNXT_MIN_PKT_SIZE ; - } - mapping =dma_map_single (&pdev->dev, skb->data, len,DMA_TO_DEVICE );if (unlikely (dma_mapping_error (&pdev->dev, mapping)))
@@ -636,10 +636,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) txbd->tx_bd_len_flags_type =cpu_to_le32 (flags); } - flags &= ~TX_BD_LEN ; - txbd->tx_bd_len_flags_type = -cpu_to_le32 (((len + pad) <<TX_BD_LEN_SHIFT ) | flags | -TX_BD_FLAGS_PACKET_END ); + txbd->tx_bd_len_flags_type |=cpu_to_le32 (TX_BD_FLAGS_PACKET_END );netdev_tx_sent_queue (txq, skb->len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 302/516 tty: introduce and use tty_port_tty_vhangup() helper
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 2b5eac0f8c6e79bc152c8804f9f88d16717013ab ]
This code (tty_get -> vhangup -> tty_put) is repeated on few places. Introduce a helper similar to tty_port_tty_hangup() (asynchronous) to handle even vhangup (synchronous).
And use it on those places.
In fact, reuse the tty_port_tty_hangup()'s code and call tty_vhangup() depending on a new bool parameter.
[ Ting-Han: adjust context in uart_remove_one_port(), which is still
called that and keeps its "ret" variable in this version; the tty_port prototypes live in include/linux/tty.h here, so add the inline helpers there instead of include/linux/tty_port.h ]
--- drivers/isdn/capi/capi.c | 8 +------- drivers/staging/greybus/uart.c | 7 +------ drivers/tty/serial/serial_core.c | 7 +------ drivers/tty/tty_port.c | 12 ++++++++---- drivers/usb/class/cdc-acm.c | 7 +------ drivers/usb/serial/usb-serial.c | 7 +------ include/linux/tty.h | 13 ++++++++++++- net/bluetooth/rfcomm/tty.c | 7 +------ 8 files changed, 26 insertions(+), 42 deletions(-)
drivers/isdn/capi/capi.c +1 -7
@@ -303,15 +303,9 @@ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np)static void capincci_free_minor (struct capincci *np) {struct capiminor *mp = np->minorp; -struct tty_struct *tty;if (mp) { - tty =tty_port_tty_get (&mp->port); -if (tty) { -tty_vhangup (tty); -tty_kref_put (tty); - } - +tty_port_tty_vhangup (&mp->port);capiminor_free (mp); } }
drivers/staging/greybus/uart.c +1 -6
@@ -929,7 +929,6 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev) {struct gb_tty *gb_tty =gb_gbphy_get_data (gbphy_dev);struct gb_connection *connection = gb_tty->connection; -struct tty_struct *tty;int ret; ret =gbphy_runtime_get_sync (gbphy_dev);
@@ -942,11 +941,7 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)wake_up_all (&gb_tty->wioctl);mutex_unlock (&gb_tty->mutex); - tty =tty_port_tty_get (&gb_tty->port); -if (tty) { -tty_vhangup (tty); -tty_kref_put (tty); - } +tty_port_tty_vhangup (&gb_tty->port);gb_connection_disable_rx (connection);tty_unregister_device (gb_tty_driver, gb_tty->minor);
drivers/tty/serial/serial_core.c +1 -6
@@ -3053,7 +3053,6 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)struct uart_state *state = drv->state + uport->line;struct tty_port *port = &state->port;struct uart_port *uart_port; -struct tty_struct *tty;int ret =0 ;BUG_ON (in_interrupt ());
@@ -3083,11 +3082,7 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)*/ tty_port_unregister_device (port, drv->tty_driver, uport->line); - tty =tty_port_tty_get (port); -if (tty) { -tty_vhangup (port->tty); -tty_kref_put (tty); - } +tty_port_tty_vhangup (port);/* * If the port is used as a console, unregister it
drivers/tty/tty_port.c +8 -4
@@ -369,15 +369,19 @@ EXPORT_SYMBOL(tty_port_hangup);* @port: tty port * @check_clocal: hang only ttys with CLOCAL unset? */ -void tty_port_tty_hangup (struct tty_port *port,bool check_clocal) +void __tty_port_tty_hangup (struct tty_port *port,bool check_clocal,bool async) {struct tty_struct *tty =tty_port_tty_get (port); -if (tty && (!check_clocal || !C_CLOCAL (tty))) -tty_hangup (tty); +if (tty && (!check_clocal || !C_CLOCAL (tty))) { +if (async) +tty_hangup (tty); +else +tty_vhangup (tty); + }tty_kref_put (tty); } -EXPORT_SYMBOL_GPL (tty_port_tty_hangup); +EXPORT_SYMBOL_GPL (__tty_port_tty_hangup);/** * tty_port_tty_wakeup - helper to wake up a tty
drivers/usb/class/cdc-acm.c +1 -6
@@ -1578,7 +1578,6 @@ static int acm_probe(struct usb_interface *intf,static void acm_disconnect (struct usb_interface *intf) {struct acm *acm =usb_get_intfdata (intf); -struct tty_struct *tty;int i;/* sibling interface is already cleaning up */
@@ -1605,11 +1604,7 @@ static void acm_disconnect(struct usb_interface *intf)usb_set_intfdata (acm->data,NULL );mutex_unlock (&acm->mutex); - tty =tty_port_tty_get (&acm->port); -if (tty) { -tty_vhangup (tty); -tty_kref_put (tty); - } +tty_port_tty_vhangup (&acm->port);cancel_delayed_work_sync (&acm->dwork);
drivers/usb/serial/usb-serial.c +1 -6
@@ -1144,7 +1144,6 @@ static void usb_serial_disconnect(struct usb_interface *interface)struct usb_serial *serial =usb_get_intfdata (interface);struct device *dev = &interface->dev;struct usb_serial_port *port; -struct tty_struct *tty;usb_serial_console_disconnect (serial);
@@ -1155,11 +1154,7 @@ static void usb_serial_disconnect(struct usb_interface *interface)for (i =0 ; i < serial->num_ports; ++i) { port = serial->port[i]; - tty =tty_port_tty_get (&port->port); -if (tty) { -tty_vhangup (tty); -tty_kref_put (tty); - } +tty_port_tty_vhangup (&port->port);usb_serial_port_poison_urbs (port);wake_up_interruptible (&port->port.delta_msr_wait);cancel_work_sync (&port->work);
include/linux/tty.h +12 -1
@@ -623,7 +623,8 @@ extern int tty_port_carrier_raised(struct tty_port *port);extern void tty_port_raise_dtr_rts (struct tty_port *port);extern void tty_port_lower_dtr_rts (struct tty_port *port);extern void tty_port_hangup (struct tty_port *port); -extern void tty_port_tty_hangup (struct tty_port *port,bool check_clocal); +extern void __tty_port_tty_hangup (struct tty_port *port,bool check_clocal, +bool async);extern void tty_port_tty_wakeup (struct tty_port *port);extern int tty_port_block_til_ready (struct tty_port *port,struct tty_struct *tty,struct file *filp);
@@ -641,6 +642,16 @@ static inline int tty_port_users(struct tty_port *port)return port->count + port->blocked_open; } +static inline void tty_port_tty_hangup (struct tty_port *port,bool check_clocal) +{ +__tty_port_tty_hangup (port, check_clocal, true); +} + +static inline void tty_port_tty_vhangup (struct tty_port *port) +{ +__tty_port_tty_hangup (port, false, false); +} +extern int tty_register_ldisc (int disc,struct tty_ldisc_ops *new_ldisc);extern int tty_unregister_ldisc (int disc);extern int tty_set_ldisc (struct tty_struct *tty,int disc);
net/bluetooth/rfcomm/tty.c +1 -6
@@ -437,7 +437,6 @@ static int __rfcomm_release_dev(void __user *arg) {struct rfcomm_dev_req req;struct rfcomm_dev *dev; -struct tty_struct *tty;if (copy_from_user (&req, arg,sizeof (req)))return -EFAULT ;
@@ -463,11 +462,7 @@ static int __rfcomm_release_dev(void __user *arg)rfcomm_dlc_close (dev->dlc,0 );/* Shut down TTY synchronously before freeing rfcomm_dev */ - tty =tty_port_tty_get (&dev->port); -if (tty) { -tty_vhangup (tty); -tty_kref_put (tty); - } +tty_port_tty_vhangup (&dev->port);if (!test_and_set_bit (RFCOMM_TTY_OWNED , &dev->status))tty_port_put (&dev->port);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 303/516 tty: port: fix tty_port_tty_vhangup() race
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit b48820de8c1a596c5b99775524dfce73c6576c5d ]
Drivers rely on tty_port_tty_vhangup() to synchronously hang up their ports before tearing down resources as part of deregistration (e.g. on physical disconnect).
If tty_port_tty_vhangup() races with another hangup it may however return before the port has been shut down. This is in turn can lead to use-after-free and NULL-pointer dereferences in racing ioctls (including a synchronous hangup) and in processing of racing asynchronous hangups (carrier loss).
Add the missing serialisation to tty_port_tty_vhangup() and tty_port_hangup() so that the former does not return until the port has been shut down also when there is a racing hangup.
Note that serial core does not use tty_port_hangup(), but it already holds the port mutex when clearing port->tty and shutting down the port in uart_hangup().
[ Ting-Han: use mutex_lock()/spin_lock_irqsave() instead of guard(),
scoped_guard() and the tty_port_tty class, matching the existing code in this version of tty_port.c; tty_port_shutdown() has no kernel-doc here, so there is none to move ]
--- drivers/tty/tty_port.c | 54 +++++++++++++++++++++++++++++------------- include/linux/tty.h | 14 ++--------- 2 files changed, 40 insertions(+), 28 deletions(-)
drivers/tty/tty_port.c +38 -16
@@ -312,11 +312,12 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) }EXPORT_SYMBOL (tty_port_tty_set); -static void tty_port_shutdown (struct tty_port *port,struct tty_struct *tty) +static void tty_port_shutdown_locked (struct tty_port *port,struct tty_struct *tty) { -mutex_lock (&port->mutex); +lockdep_assert_held (&port->mutex); +if (port->console) - goto out; +return ;if (tty_port_initialized (port)) {tty_port_set_initialized (port,0 );
@@ -330,7 +331,12 @@ static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)if (port->ops->shutdown) port->ops->shutdown (port); } -out: +} + +static void tty_port_shutdown (struct tty_port *port,struct tty_struct *tty) +{ +mutex_lock (&port->mutex); +tty_port_shutdown_locked (port, tty);mutex_unlock (&port->mutex); }
@@ -348,6 +354,7 @@ void tty_port_hangup(struct tty_port *port)struct tty_struct *tty;unsigned long flags; +mutex_lock (&port->mutex);spin_lock_irqsave (&port->lock, flags); port->count =0 ; tty = port->tty;
@@ -356,7 +363,8 @@ void tty_port_hangup(struct tty_port *port) port->tty =NULL ;spin_unlock_irqrestore (&port->lock, flags);tty_port_set_active (port,0 ); -tty_port_shutdown (port, tty); +tty_port_shutdown_locked (port, tty); +mutex_unlock (&port->mutex);tty_kref_put (tty);wake_up_interruptible (&port->open_wait);wake_up_interruptible (&port->delta_msr_wait);
@@ -364,24 +372,38 @@ void tty_port_hangup(struct tty_port *port)EXPORT_SYMBOL (tty_port_hangup);/** -* tty_port_tty_hangup - helper to hang up a tty -* +* tty_port_tty_hangup - helper to hang up a tty asynchronously * @port: tty port -* @check_clocal: hang only ttys with CLOCAL unset? +* @check_clocal: hang only ttys with %CLOCAL unset? */ -void __tty_port_tty_hangup (struct tty_port *port,bool check_clocal,bool async) +void tty_port_tty_hangup (struct tty_port *port,bool check_clocal) {struct tty_struct *tty =tty_port_tty_get (port); -if (tty && (!check_clocal || !C_CLOCAL (tty))) { -if (async) -tty_hangup (tty); -else -tty_vhangup (tty); - } +if (tty && (!check_clocal || !C_CLOCAL (tty))) +tty_hangup (tty);tty_kref_put (tty); } -EXPORT_SYMBOL_GPL (__tty_port_tty_hangup); +EXPORT_SYMBOL_GPL (tty_port_tty_hangup); + +/** +* tty_port_tty_vhangup - helper to hang up a tty synchronously +* @port: tty port +*/ +void tty_port_tty_vhangup (struct tty_port *port) +{ +struct tty_struct *tty; + +mutex_lock (&port->mutex); + tty =tty_port_tty_get (port); +mutex_unlock (&port->mutex); + +if (tty) { +tty_vhangup (tty); +tty_kref_put (tty); + } +} +EXPORT_SYMBOL_GPL (tty_port_tty_vhangup);/** * tty_port_tty_wakeup - helper to wake up a tty
include/linux/tty.h +2 -12
@@ -623,8 +623,8 @@ extern int tty_port_carrier_raised(struct tty_port *port);extern void tty_port_raise_dtr_rts (struct tty_port *port);extern void tty_port_lower_dtr_rts (struct tty_port *port);extern void tty_port_hangup (struct tty_port *port); -extern void __tty_port_tty_hangup (struct tty_port *port,bool check_clocal, -bool async); +extern void tty_port_tty_hangup (struct tty_port *port,bool check_clocal); +extern void tty_port_tty_vhangup (struct tty_port *port);extern void tty_port_tty_wakeup (struct tty_port *port);extern int tty_port_block_til_ready (struct tty_port *port,struct tty_struct *tty,struct file *filp);
@@ -642,16 +642,6 @@ static inline int tty_port_users(struct tty_port *port)return port->count + port->blocked_open; } -static inline void tty_port_tty_hangup (struct tty_port *port,bool check_clocal) -{ -__tty_port_tty_hangup (port, check_clocal, true); -} - -static inline void tty_port_tty_vhangup (struct tty_port *port) -{ -__tty_port_tty_hangup (port, false, false); -} -extern int tty_register_ldisc (int disc,struct tty_ldisc_ops *new_ldisc);extern int tty_unregister_ldisc (int disc);extern int tty_set_ldisc (struct tty_struct *tty,int disc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 304/516 wifi: mac80211: keep paired old chanctx alive
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 3412e9a800786d1dec4a58367db1cba275e7ef11 ]
An in-place replacement keeps reciprocal replace_ctx pointers between the old WILL_BE_REPLACED chanctx and the new REPLACES_OTHER chanctx. However, the early free paths only consider assigned and reserved link users when deciding whether to free the old chanctx.
That lets the old chanctx be freed too early while the replacement partner still points back to it, either when the last assigned link is released or when that link successfully reassigns to another existing context. Later unreserve and switch-finalization paths can then follow a stale replace_ctx pointer.
Keep a paired old chanctx alive until the replacement pair has been torn down. Apply the same check to both __ieee80211_link_release_channel() and ieee80211_link_use_reserved_reassign(). If the replacement is later abandoned, ieee80211_link_unreserve_chanctx() already tears down the pairing before freeing the old chanctx once no users remain.
--- net/mac80211/chan.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/mac80211/chan.c +12 -2
@@ -846,6 +846,7 @@ void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,int ieee80211_vif_unreserve_chanctx (struct ieee80211_sub_if_data *sdata) {struct ieee80211_chanctx *ctx = sdata->reserved_chanctx; +struct ieee80211_chanctx *old_ctx =NULL ;lockdep_assert_held (&sdata->local->chanctx_mtx);
@@ -860,6 +861,7 @@ int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata)if (WARN_ON (!ctx->replace_ctx))return -EINVAL ; + old_ctx = ctx->replace_ctx;WARN_ON (ctx->replace_ctx->replace_state !=IEEE80211_CHANCTX_WILL_BE_REPLACED );WARN_ON (ctx->replace_ctx->replace_ctx != ctx);
@@ -870,6 +872,10 @@ int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata)list_del_rcu (&ctx->list);kfree_rcu (ctx, rcu_head); + +if (ieee80211_chanctx_refcount (sdata->local, + old_ctx) ==0 ) +ieee80211_free_chanctx (sdata->local, old_ctx); }else {ieee80211_free_chanctx (sdata->local, ctx); }
@@ -1078,7 +1084,9 @@ ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata)ieee80211_check_fast_xmit_iface (sdata); -if (ieee80211_chanctx_refcount (local, old_ctx) ==0 ) +if (ieee80211_chanctx_refcount (local, old_ctx) ==0 && + !(old_ctx->replace_state ==IEEE80211_CHANCTX_WILL_BE_REPLACED && + old_ctx->replace_ctx))ieee80211_free_chanctx (local, old_ctx);if (sdata->vif.bss_conf.chandef.width != sdata->reserved_chandef.width)
@@ -1555,7 +1563,9 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) }ieee80211_assign_vif_chanctx (sdata,NULL ); -if (ieee80211_chanctx_refcount (local, ctx) ==0 ) +if (ieee80211_chanctx_refcount (local, ctx) ==0 && + !(ctx->replace_state ==IEEE80211_CHANCTX_WILL_BE_REPLACED && + ctx->replace_ctx))ieee80211_free_chanctx (local, ctx); sdata->radar_required = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 305/516 wifi: mac80211: count only matching reservations in reserved switch
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 437f3727b4fd715266c296435c116288f82666fd ]
ieee80211_vif_use_reserved_switch() validates a replacement by counting assigned links on ctx->replace_ctx and treating reservations too broadly. A link can still be assigned to the old channel context while holding a reservation that belongs to a different replacement operation.
That can make the current replacement appear complete too early. If another link finalizes first, the function can free the WILL_BE_REPLACED chanctx while the unmatched link and driver still use it, leading to a use-after-free in later beacon generation.
Require an in-place reservation to point at the current replacement context, and require the reserved and assigned contexts to be the matching replacement pair, before counting or moving the link.
--- net/mac80211/chan.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
net/mac80211/chan.c +16 -6
@@ -1154,7 +1154,8 @@ ieee80211_vif_use_reserved_assign(struct ieee80211_sub_if_data *sdata) }static bool -ieee80211_vif_has_in_place_reservation (struct ieee80211_sub_if_data *sdata) +ieee80211_vif_has_in_place_reservation (struct ieee80211_sub_if_data *sdata, +struct ieee80211_chanctx *ctx) {struct ieee80211_chanctx *old_ctx, *new_ctx;
@@ -1163,6 +1164,9 @@ ieee80211_vif_has_in_place_reservation(struct ieee80211_sub_if_data *sdata) new_ctx = sdata->reserved_chanctx; old_ctx =ieee80211_vif_get_chanctx (sdata); +if (new_ctx != ctx) +return false; +if (!old_ctx)return false;
@@ -1175,6 +1179,12 @@ ieee80211_vif_has_in_place_reservation(struct ieee80211_sub_if_data *sdata)if (new_ctx->replace_state !=IEEE80211_CHANCTX_REPLACES_OTHER )return false; +if (new_ctx->replace_ctx != old_ctx) +return false; + +if (old_ctx->replace_ctx != new_ctx) +return false; +return true; }
@@ -1225,7 +1235,7 @@ static int ieee80211_chsw_switch_vifs(struct ieee80211_local *local,list_for_each_entry (sdata, &ctx->reserved_vifs, reserved_chanctx_list) {if (!ieee80211_vif_has_in_place_reservation ( - sdata)) + sdata, ctx))continue ; old_ctx =ieee80211_vif_get_chanctx (sdata);
@@ -1332,7 +1342,7 @@ static int ieee80211_vif_use_reserved_switch(struct ieee80211_local *local)list_for_each_entry (sdata, &ctx->replace_ctx->assigned_vifs, assigned_chanctx_list) { n_assigned++; -if (sdata->reserved_chanctx) { +if (ieee80211_vif_has_in_place_reservation (sdata, ctx)) { n_reserved++;if (sdata->reserved_ready) n_ready++;
@@ -1353,7 +1363,7 @@ static int ieee80211_vif_use_reserved_switch(struct ieee80211_local *local) ctx->conf.radar_enabled = false;list_for_each_entry (sdata, &ctx->reserved_vifs, reserved_chanctx_list) { -if (ieee80211_vif_has_in_place_reservation (sdata) && +if (ieee80211_vif_has_in_place_reservation (sdata, ctx) && !sdata->reserved_ready)return -EAGAIN ;
@@ -1423,7 +1433,7 @@ static int ieee80211_vif_use_reserved_switch(struct ieee80211_local *local) reserved_chanctx_list) {u32 changed =0 ; -if (!ieee80211_vif_has_in_place_reservation (sdata)) +if (!ieee80211_vif_has_in_place_reservation (sdata, ctx))continue ;rcu_assign_pointer (sdata->vif.chanctx_conf, &ctx->conf);
@@ -1476,7 +1486,7 @@ static int ieee80211_vif_use_reserved_switch(struct ieee80211_local *local)list_for_each_entry_safe (sdata, sdata_tmp, &ctx->reserved_vifs, reserved_chanctx_list) {if (WARN_ON (ieee80211_vif_has_in_place_reservation ( - sdata))) + sdata, ctx)))continue ;if (WARN_ON (sdata->reserved_chanctx != ctx))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 306/516 fs: Free any excess xarray nodes in clear_inode()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
[ Upstream commit ee3f011250104129893d8e9599147e457d4d7280 ]
For many years we've had a hard to hit leak of xarray nodes. Hugh documented it well in commit 786b31121a2c. Recently people and syzbot have found ways to force it to happen with madvise. Rather than fix the leaks where they happen, just call xa_destroy() which has the side-effect of cycling the i_pages lock.
--- fs/inode.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
fs/inode.c +10 -5
@@ -556,14 +556,19 @@ EXPORT_SYMBOL(__remove_inode_hash);void clear_inode (struct inode *inode) {/* -* We have to cycle the i_pages lock here because reclaim can be in the -* process of removing the last page (in __delete_from_page_cache()) -* and we must not free the mapping under it. +* We have to cycle the i_pages lock here because reclaim +* can be in the process of removing the last page (in +* __delete_from_page_cache()) and we must not free the mapping +* under it. We also remove nodes which are empty; these +* can occur in two different ways. The first is that radix +* tree expansion can fail partway and the second is that THP +* collapse_file() can allocate some temporary nodes and not +* clean them up. */ -xa_lock_irq (&inode->i_data.i_pages); +xa_destroy (&inode->i_data.i_pages); +BUG_ON (inode->i_data.nrpages);BUG_ON (inode->i_data.nrexceptional); -xa_unlock_irq (&inode->i_data.i_pages);BUG_ON (!list_empty (&inode->i_data.private_list));BUG_ON (!(inode->i_state &I_FREEING ));BUG_ON (inode->i_state &I_CLEAR );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 307/516 mm/hugetlb: fix avoid_reserve to allow taking folio from subpool
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Xu <[email protected]>
commit 58db7c5fbe7daa42098d4965133a864f98ba90ba upstream.
Patch series "mm/hugetlb: Refactor hugetlb allocation resv accounting", v2.
This is a follow up on Ackerley's series here as replacement:
https://lore.kernel.org/r/[email protected]
The goal of this series is to cleanup hugetlb resv accounting, especially during folio allocation, to decouple a few things:
- Hugetlb folios v.s. Hugetlbfs: IOW, the hope is in the future hugetlb folios can be allocated completely without hugetlbfs.
- Decouple VMA v.s. hugetlb folio allocations: allocating a hugetlb folio should not always require a hugetlbfs VMA. For example, either it got allocated from the inode level (see hugetlbfs_fallocate() where it used a pesudo VMA for allocation), or it can be allocated by other kernel subsystems.
It paves way for other users to allocate hugetlb folios out of either system reservations, or subpools (instead of hugetlbfs, as a file system). For longer term, this prepares hugetlb as a separate concept versus hugetlbfs, so that hugetlb folios can be allocated by not only hugetlbfs and other things.
Tests I've done:
- I had a reproducer in patch 1 for the bug I found, this will start to work after patch 1 or the whole set applied.
- Hugetlb regression tests (on x86_64 2MBs), includes:
- All vmtests on hugetlbfs
- libhugetlbfs test suite (which may fail some tests, but no new failures will be introduced by this series, so all such failures happen before this series so shouldn't be relevant).
This patch (of 7):
Since commit 04f2cbe35699 ("hugetlb: guarantee that COW faults for a process that called mmap(MAP_PRIVATE) on hugetlbfs will succeed"), avoid_reserve was introduced for a special case of CoW on hugetlb private mappings, and only if the owner VMA is trying to allocate yet another hugetlb folio that is not reserved within the private vma reserved map.
Later on, in commit d85f69b0b533 ("mm/hugetlb: alloc_huge_page handle areas hole punched by fallocate"), alloc_huge_page() enforced to not consume any global reservation as long as avoid_reserve=true. This operation doesn't look correct, because even if it will enforce the allocation to not use global reservation at all, it will still try to take one reservation from the spool (if the subpool existed). Then since the spool reserved pages take from global reservation, it'll also take one reservation globally.
Logically it can cause global reservation to go wrong.
I wrote a reproducer below, trigger this special path, and every run of such program will cause global reservation count to increment by one, until it hits the number of free pages:
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#define MSIZE (2UL << 20)
int main(int argc, char *argv[])
{
const char *path;
int *buf;
int fd, ret;
pid_t child; if (argc < 2) {
printf("usage: %s <hugetlb_file>\n", argv[0]);
return -1;
}
path = argv[1];
fd = open(path, O_RDWR | O_CREAT, 0666);
if (fd < 0) {
perror("open failed");
return -1;
}
ret = fallocate(fd, 0, 0, MSIZE);
if (ret != 0) {
perror("fallocate");
return -1;
}
buf = mmap(NULL, MSIZE, PROT_READ|PROT_WRITE,
MAP_PRIVATE, fd, 0);
if (buf == MAP_FAILED) {
perror("mmap() failed");
return -1;
}
/* Allocate a page */
*buf = 1;
child = fork();
if (child == 0) {
/* child doesn't need to do anything */
exit(0);
}
/* Trigger CoW from owner */
*buf = 2;
munmap(buf, MSIZE);
close(fd);
unlink(path);
return 0;}
It can only reproduce with a sub-mount when there're reserved pages on the spool, like:
# sysctl vm.nr_hugepages=128 # mkdir ./hugetlb-pool # mount -t hugetlbfs -o min_size=8M,pagesize=2M none ./hugetlb-pool
Then run the reproducer on the mountpoint:
# ./reproducer ./hugetlb-pool/test
Fix it by taking the reservation from spool if available. In general, avoid_reserve is IMHO more about "avoid vma resv map", not spool's.
I copied stable, however I have no intention for backporting if it's not a clean cherry-pick, because private hugetlb mapping, and then fork() on top is too rare to hit.
[ Karl Mehltretter: The upstream changes map directly to this stable tree's
older page-based HugeTLB API. The backport retains this stable tree's SetPagePrivate() reserve marker, plain hugetlb_lock calls and direct -ENOSPC return; the functional changes otherwise match upstream. ]
--- mm/hugetlb.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
mm/hugetlb.c +3 -19
@@ -1137,8 +1137,7 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,static struct page *dequeue_huge_page_vma (struct hstate *h,struct vm_area_struct *vma, -unsigned long address,int avoid_reserve, -long chg) +unsigned long address,long chg) {struct page *page;struct mempolicy *mpol;
@@ -1155,14 +1154,10 @@ static struct page *dequeue_huge_page_vma(struct hstate *h, h->free_huge_pages - h->resv_huge_pages == 0) goto err; -/* If reserves cannot be used, ensure enough pages are in the pool */ -if (avoid_reserve && h->free_huge_pages - h->resv_huge_pages ==0 ) - goto err; - gfp_mask =htlb_alloc_mask (h); nid =huge_node (vma, address, gfp_mask, &mpol, &nodemask); page =dequeue_huge_page_nodemask (h, gfp_mask, nid, nodemask); -if (page && !avoid_reserve &&vma_has_reserves (vma, chg)) { +if (page &&vma_has_reserves (vma, chg)) {SetPagePrivate (page); h->resv_huge_pages--; }
@@ -2350,17 +2345,6 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,vma_end_reservation (h, vma, addr);return ERR_PTR (-ENOSPC ); } - -/* -* Even though there was no reservation in the region/reserve -* map, there could be reservations associated with the -* subpool that can be used. This would be indicated if the -* return value of hugepage_subpool_get_pages() is zero. -* However, if avoid_reserve is specified we still avoid even -* the subpool reservations. -*/ -if (avoid_reserve) - gbl_chg =1 ; }/* If this allocation is not consuming a reservation, charge it now.
@@ -2383,7 +2367,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,* from the global free pool (global change). gbl_chg == 0 indicates * a reservation exists for the allocation. */ - page =dequeue_huge_page_vma (h, vma, addr, avoid_reserve, gbl_chg); + page =dequeue_huge_page_vma (h, vma, addr, gbl_chg);if (!page) {spin_unlock (&hugetlb_lock); page =alloc_buddy_huge_page_with_mpol (h, vma, addr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 308/516 KVM: SVM: Use the active VMCBs MSR bitmap when checking if MSR is intercepted
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 9e06bbb9ade7cdf28d4a3b5b14e5812881c8df85 ]
Use the MSR permission bitmap of the active VMCB instead of assuming that KVM is always using vmcb02's bitmap when L2 is active, as KVM uses msrpm02 if and only if L1 wants to intercept MSR accesses, i.e. if and only if KVM needs to merge msprm01 with msrpm12.
Don't bother tracking the virtual address of the bitmap that's being used, as __va() is cheap on x86, and caching the virtual address would introduce yet another source of potentially stale information.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/svm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +1 -2
@@ -616,8 +616,7 @@ static bool msr_write_intercepted(struct kvm_vcpu *vcpu, u32 msr)u32 offset;u32 *msrpm; - msrpm =is_guest_mode (vcpu) ?to_svm (vcpu)->nested.msrpm: -to_svm (vcpu)->msrpm; + msrpm =__va (__sme_clr (to_svm (vcpu)->vmcb->control.msrpm_base_pa)); offset =svm_msrpm_offset (msr); bit_write =2 * (msr &0x0f ) +1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 309/516 wifi: mac80211: set info->band for 802.3 encap offload frames
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 4febc02cd02f021f2b6d0768332be643ef14a12d ]
Unlike the 802.11 TX paths, ieee80211_8023_xmit() does not set info->band from the channel context on non-MLD interfaces. It stays at 0, so ieee80211_get_tx_rates() uses the wrong band for these frames.
Set it the same way as ieee80211_build_hdr(): drop the frame if there is no channel context, and leave the band at 0 on MLD interfaces.
--- net/mac80211/tx.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/mac80211/tx.c +6 -0
@@ -4272,6 +4272,7 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, {struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);struct ieee80211_local *local = sdata->local; +struct ieee80211_chanctx_conf *chanctx_conf;struct tid_ampdu_tx *tid_tx;u8 tid;
@@ -4317,6 +4318,11 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, sdata =container_of (sdata->bss, struct ieee80211_sub_if_data, u.ap); + chanctx_conf =rcu_dereference (sdata->vif.chanctx_conf); +if (unlikely (!chanctx_conf)) + goto out_free; + info->band = chanctx_conf->def.chan->band; + info->flags |=IEEE80211_TX_CTL_HW_80211_ENCAP ; info->control.vif = &sdata->vif;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 310/516 iio: adc: aspeed: propagate reset deassert errors
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 95e4eb426b4bd666fa2f37886c0ddf74a0cc6167 ]
aspeed_adc_probe() continues to register ADC resources after deasserting the shared reset, even if the reset controller reports a failure.
A failed deassertion leaves the hardware unavailable, so stop probing before installing the cleanup action and enabling the ADC.
--- drivers/iio/adc/aspeed_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/aspeed_adc.c +3 -1
@@ -221,7 +221,9 @@ static int aspeed_adc_probe(struct platform_device *pdev) ret =PTR_ERR (data->rst); goto reset_error; } -reset_control_deassert (data->rst); + ret =reset_control_deassert (data->rst); +if (ret) + goto reset_error; model_data =of_device_get_match_data (&pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 311/516 iio: adc: max1363: sign-extend bipolar differential channel reads
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
[ Upstream commit 91908c0a78baddc8572aa3ab69e62ee2eb496ba4 ]
MAX1363 differential channels are bipolar, but max1363_read_single_chan() masks the raw value to the ADC resolution without sign-extending it. Negative differential readings are therefore reported to userspace as large positive values (e.g. -1 as 4095 on a 12-bit part).
Sign-extend the masked value from the resolution bit for differential channels. Single-ended channels are unipolar and are left unchanged.
--- drivers/iio/adc/max1363.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iio/adc/max1363.c +8 -0
@@ -409,6 +409,14 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, } data = rxbuf[0 ]; } + +/* +* Differential channels are bipolar and the device returns the sample +* in two's complement, so sign-extend it from the resolution bit. +*/ +if (chan->differential) + data =sign_extend32 (data, st->chip_info->bits -1 ); + *val = data; error_ret:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 312/516 HID: core: introduce hid_safe_input_report()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Tissoires <[email protected]>
[ Upstream commit 206342541fc887ae919774a43942dc883161fece ]
hid_input_report() is used in too many places to have a commit that doesn't cross subsystem borders. Instead of changing the API, introduce a new one when things matters in the transport layers:
- usbhid
- i2chid
This effectively revert to the old behavior for those two transport layers.
[Lee: Implement hid_safe_input_report() directly and wrap it from
hid_input_report() as 67eccf151d76 ("HID: add source argument to HID low level functions") is not present. Use int for report type and literal 2 in i2c_hid_get_input() as 56fc4f7bc114 and 1bdbe0dcff2f are not present]
--- drivers/hid/hid-core.c | 26 ++++++++++++++++++++++++-- drivers/hid/i2c-hid/i2c-hid-core.c | 5 +++-- drivers/hid/usbhid/hid-core.c | 11 ++++++----- include/linux/hid.h | 2 ++ 4 files changed, 35 insertions(+), 9 deletions(-)
drivers/hid/hid-core.c +24 -2
@@ -1873,13 +1873,35 @@ EXPORT_SYMBOL_GPL(hid_report_raw_event);* @interrupt: distinguish between interrupt and control transfers * * This is data entry for lower layers. +* Legacy, please use hid_safe_input_report() instead. */ int hid_input_report (struct hid_device *hid,int type,u8 *data,u32 size,int interrupt) +{ +return hid_safe_input_report (hid, type, data, size, size, interrupt); +} +EXPORT_SYMBOL_GPL (hid_input_report); + +/** +* hid_safe_input_report - report data from lower layer (usb, bt...) +* +* @hid: hid device +* @type: HID report type (HID_*_REPORT) +* @data: report contents +* @bufsize: allocated size of the data buffer +* @size: useful size of data parameter +* @interrupt: distinguish between interrupt and control transfers +* +* This is data entry for lower layers. +* Please use this function instead of the non safe version because we provide +* here the size of the buffer, allowing hid-core to make smarter decisions +* regarding the incoming buffer. +*/ +int hid_safe_input_report (struct hid_device *hid,int type,u8 *data, +size_t bufsize,u32 size,int interrupt) {struct hid_report_enum *report_enum;struct hid_driver *hdrv;struct hid_report *report; -size_t bufsize = size;int ret =0 ;if (!hid)
@@ -1924,7 +1946,7 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, u32 size, int iup (&hid->driver_input_lock);return ret; } -EXPORT_SYMBOL_GPL (hid_input_report); +EXPORT_SYMBOL_GPL (hid_safe_input_report);bool hid_match_one_id (const struct hid_device *hdev,const struct hid_device_id *id)
drivers/hid/i2c-hid/i2c-hid-core.c +3 -2
@@ -523,8 +523,9 @@ static void i2c_hid_get_input(struct i2c_hid *ihid)i2c_hid_dbg (ihid,"input: %*ph\n" , ret_size, ihid->inbuf);if (test_bit (I2C_HID_STARTED , &ihid->flags)) -hid_input_report (ihid->hid,HID_INPUT_REPORT , ihid->inbuf +2 , - ret_size -2 ,1 ); +hid_safe_input_report (ihid->hid,HID_INPUT_REPORT , + ihid->inbuf +2 , ihid->bufsize -2 , + ret_size -2 ,1 );return ; }
drivers/hid/usbhid/hid-core.c +6 -5
@@ -281,9 +281,9 @@ static void hid_irq_in(struct urb *urb)break ;usbhid_mark_busy (usbhid);if (!test_bit (HID_RESUME_RUNNING , &usbhid->iofl)) { -hid_input_report (urb->context,HID_INPUT_REPORT , - urb->transfer_buffer, - urb->actual_length,1 ); +hid_safe_input_report (urb->context,HID_INPUT_REPORT , + urb->transfer_buffer, urb->transfer_buffer_length, + urb->actual_length,1 );/* * autosuspend refused while keys are pressed * because most keyboards don't wake up when
@@ -483,9 +483,10 @@ static void hid_ctrl(struct urb *urb)switch (status) {case 0 :/* success */ if (usbhid->ctrl[usbhid->ctrltail].dir ==USB_DIR_IN ) -hid_input_report (urb->context, +hid_safe_input_report (urb->context, usbhid->ctrl[usbhid->ctrltail].report->type, - urb->transfer_buffer, urb->actual_length,0 ); + urb->transfer_buffer, urb->transfer_buffer_length, + urb->actual_length,0 );break ;case -ESHUTDOWN :/* unplug */ unplug =1 ;
include/linux/hid.h +2 -0
@@ -929,6 +929,8 @@ extern void hidinput_disconnect(struct hid_device *);int hid_set_field (struct hid_field *,unsigned ,__s32 );int hid_input_report (struct hid_device *,int type,u8 *,u32 ,int ); +int hid_safe_input_report (struct hid_device *hid,int type,u8 *data, +size_t bufsize,u32 size,int interrupt);int hidinput_find_field (struct hid_device *hid,unsigned int type,unsigned int code,struct hid_field **field);struct hid_field *hidinput_get_led_field (struct hid_device *hid);unsigned int hidinput_count_leds (struct hid_device *hid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 313/516 HID: uhid: convert to hid_safe_input_report()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carlos Llamas <[email protected]>
[ Upstream commit 63a694c51bf120a37550890b8e7736b4888985e9 ]
Commit 0a3fe972a7cb ("HID: core: Mitigate potential OOB by removing bogus memset()"), added a check in hid_report_raw_event() to reject reports if the received data size is smaller than expected. This was intended to prevent OOB errors by no longer allowing zeroing-out of shorter reports due to the lack of buffer size information.
However, this leads to regressions in hid_report_raw_event(), where shorter than expected reports are rejected, even though their buffers are sufficiently large to be zero-padded.
To solve this issue, Benjamin introduced a safer alternative in commit 206342541fc8 ("HID: core: introduce hid_safe_input_report()"), which forwards the buffer size and allows hid_report_raw_event() to safely zero-pad the data.
Convert uhid to use hid_safe_input_report() and pass UHID_DATA_MAX as the buffer size. This prevents the reported regressions [1], allowing hid core to zero-pad the shorter reports safely as expected.
--- drivers/hid/uhid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hid/uhid.c +4 -4
@@ -597,8 +597,8 @@ static int uhid_dev_input(struct uhid_device *uhid, struct uhid_event *ev)if (!uhid->running)return -EINVAL ; -hid_input_report (uhid->hid,HID_INPUT_REPORT , ev->u.input.data, -min_t (size_t, ev->u.input.size,UHID_DATA_MAX ),0 ); +hid_safe_input_report (uhid->hid,HID_INPUT_REPORT , ev->u.input.data,UHID_DATA_MAX , +min_t (size_t, ev->u.input.size,UHID_DATA_MAX ),0 );return 0 ; }
@@ -608,8 +608,8 @@ static int uhid_dev_input2(struct uhid_device *uhid, struct uhid_event *ev)if (!uhid->running)return -EINVAL ; -hid_input_report (uhid->hid,HID_INPUT_REPORT , ev->u.input2.data, -min_t (size_t, ev->u.input2.size,UHID_DATA_MAX ),0 ); +hid_safe_input_report (uhid->hid,HID_INPUT_REPORT , ev->u.input2.data,UHID_DATA_MAX , +min_t (size_t, ev->u.input2.size,UHID_DATA_MAX ),0 );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 314/516 crypto: drbg - Fix ineffective sanity check
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 040ad83b0e8aa065fd2fc641cacba8491a8b186d upstream.
Fix drbg_healthcheck_sanity() to correctly check the return value of drbg_generate(). drbg_generate() returns 0 on success, or a negative errno value on failure. drbg_healthcheck_sanity() incorrectly assumed that it returned a positive value on success.
This didn't make the sanity check fail, but it made it ineffective.
--- crypto/drbg.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
crypto/drbg.c +5 -6
@@ -1975,7 +1975,6 @@ static int drbg_kcapi_seed(struct crypto*/ static inline int __init drbg_healthcheck_sanity (void ) { -int len =0 ;#define OUTBUFLEN 16unsigned char buf[OUTBUFLEN ];struct drbg_state *drbg =NULL ;
@@ -2017,12 +2016,12 @@ static inline int __init drbg_healthchec max_addtllen =drbg_max_addtl (drbg); max_request_bytes =drbg_max_request_bytes (drbg);drbg_string_fill (&addtl, buf, max_addtllen +1 ); -/* overflow addtllen with additonal info string */ - len =drbg_generate (drbg, buf,OUTBUFLEN , &addtl); -BUG_ON (0 < len); +/* overflow addtllen with additional info string */ + ret =drbg_generate (drbg, buf,OUTBUFLEN , &addtl); +BUG_ON (ret ==0 );/* overflow max_bits */ - len =drbg_generate (drbg, buf, (max_request_bytes +1 ),NULL ); -BUG_ON (0 < len); + ret =drbg_generate (drbg, buf, max_request_bytes +1 ,NULL ); +BUG_ON (ret ==0 );/* overflow max addtllen with personalization string */ ret =drbg_seed (drbg, &addtl, false);
Greg Kroah-Hartman
maintainerPATCH 315/516 btrfs: scrub: fix local_root reference leak in scrub_print_warning_inode()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 1fd742c7479961da6d0bb794ef8ac6b7b9442847 upstream.
When paths_from_inode() fails, scrub_print_warning_inode() jumps to err without dropping the reference taken by btrfs_get_fs_root(), leaking a reference to the root every time path resolution fails while printing scrub warnings. Every other error and success path of the function drops the reference.
Drop the reference on the paths_from_inode() failure path too.
--- fs/btrfs/scrub.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/scrub.c +3 -1
@@ -692,8 +692,10 @@ static int scrub_print_warning_inode(u64 } ret =paths_from_inode (inum, ipath); -if (ret <0 ) +if (ret <0 ) { +btrfs_put_root (local_root); goto err; + }/* * we deliberately ignore the bit ipath might have been too small to
Greg Kroah-Hartman
maintainerPATCH 316/516 dm ioctl: dont let data_start run past the buffer
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Palla Raghunath <[email protected]>
commit 9b3fcf519d370df94a56f3b272d9eddffffa5be8 upstream.
struct dm_ioctl has seven bytes of trailing padding, so the smallest buffer userspace is allowed to ask for, offsetof(struct dm_ioctl, data), is seven bytes shorter than sizeof(struct dm_ioctl).
get_result_buffer() sets data_start to sizeof(struct dm_ioctl) without looking at how big the buffer actually is. Ask for the minimum and data_start ends up seven bytes past the end. Callers add it to data_size, and ctl_ioctl() copies that much back to userspace:
BUG: KASAN: slab-out-of-bounds in _copy_to_user+0xad/0xd0 Read of size 312 at addr ffff8880169e4c00 by task repro-dm/140 ctl_ioctl+0x5e3/0xcb0 dm_ctl_ioctl+0x25/0x40 allocated 305-byte region [ffff8880169e4c00, ffff8880169e4d31)
A DM_LIST_DEVICES with data_size set to 305 is enough to hit it, and the seven bytes that leak are whatever sat next to the allocation.
Clamp data_start to the buffer size.
Note that this is not a security bug because the out-of-bounds read can only be triggered by root.
--- drivers/md/dm-ioctl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/md/dm-ioctl.c +8 -2
@@ -496,10 +496,16 @@ static void *get_result_buffer(struct dm { param->data_start =align_ptr (param +1 ) - (void *) param; -if (param->data_start < param_size) +if (param->data_start < param_size) { *len = param_size - param->data_start; -else + }else { +/* +* The buffer can be as small as offsetof(*param, data), which +* is less than sizeof(*param), so don't run off the end of it. +*/ *len =0 ; + param->data_start = param_size; + }return ((void *) param) + param->data_start; }
Greg Kroah-Hartman
maintainerPATCH 317/516 wireguard: noise: reject response consumption after intermediate initiation
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason A. Donenfeld <[email protected]>
commit d0305f8d90029556260c6824b61c493c424eba9e upstream.
Two threads begin processing the identical response message, received twice. The first thread, A, runs. While it's running, the second one, B, gets partway through, and during that slow calculation, or even while blocking on down_write(), A completes and then also a handshake initiation that's already been queued up runs in thread C, which itself takes that same down_write(). The handshake initiation creation succeeds, and sets the state back to waiting-for-response, and calls up_write(), at which point thread B resumes, because either its finished its calculations or was finally allowed to acquire down_write(). Thread B then copies the state back to the peer, and begins a new session, using that state, which is the same session as the one made in thread A.
Thread A Thread B Thread C
down_read()
sA = handshake->state
memcpy(cA, handshake->crypto)up_read()
if (sA != 1)
goto failslow_crypto(cA)
down_read() sB = handshake->state memcpy(cB, handshake->crypto) up_read() if (sB != 1) goto fail slow_crypto(cB)
down_write()
if (sA != handshake->state)
goto fail
memcpy(handshake->crypto, cA)
handshake->state = 2up_write()down_write()
if (handshake->state != 2)
goto fail
derive_session(handshake->crypto)up_write()
down_write() slow_crypto(handshake->crypto) handshake->state = 1 up_write() down_write() if (sB != handshake->state) goto fail memcpy(handshake->crypto, cB) handshake->state = 2 up_write() down_write() if (handshake->state != 2) goto fail derive_session(handshake->crypto) up_write()
This seems basically impossible to hit in a meaningful way in practice, but ensure that it absolutely cannot happen by comparing the ephemeral private key that's on the stack with the latest one that the peer's handshake state has.
--- drivers/net/wireguard/noise.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/wireguard/noise.c +4 -3
@@ -784,10 +784,11 @@ wg_noise_handshake_consume_response(stru/* Success! Copy everything to peer */ down_write (&handshake->lock); -/* It's important to check that the state is still the same, while we -* have an exclusive lock. +/* Check that the state is the same and that this is still the +* initiation we started with, while we have an exclusive lock. */ -if (handshake->state != state) { +if (handshake->state != state || +crypto_memneq (handshake->ephemeral_private, ephemeral_private,NOISE_PUBLIC_KEY_LEN )) {up_write (&handshake->lock); goto fail; }
Greg Kroah-Hartman
maintainerPATCH 318/516 workqueue: Fix NULL current_pwq deref in chained work check
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavankumar Kondeti <[email protected]>
commit 980db94e3eeefdd8a1c46f86412c33a7f7806f51 upstream.
current_wq_worker() only tells us that %current is a kworker. It does not guarantee that the worker is currently executing a work item, as worker->current_pwq is populated only while process_one_work() is running the work function.
is_chained_work() can be reached while queueing on a draining or destroying workqueue. If a kworker outside work-item execution reaches that path, current_wq_worker() returns a worker but worker->current_pwq is NULL, and the chained-work test can fault before it emits the intended warning.
Guard the chained-work test with worker->current_pwq. A kworker without current_pwq is not executing work on the target workqueue, so the helper should return false and let the draining/destroying warning fire.
--- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/workqueue.c +1 -1
@@ -1369,7 +1369,7 @@ static bool is_chained_work(struct workq* Return %true iff I'm a worker executing a work item on @wq. If * I'm @worker, it's safe to dereference it without locking. */ -return worker && worker->current_pwq->wq == wq; +return worker && worker->current_pwq && worker->current_pwq->wq == wq; }/*
Greg Kroah-Hartman
maintainerPATCH 319/516 xen/netfront: dont leak the skb when xennet_fill_frags() fails
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 93ccaf1c26e2133396173b76a071e59024daa622 upstream.
When a response chain has more slots than fit in the skb's frags, xennet_fill_frags() returns an error and xennet_poll() jumps to its error path. That path moves what's left on tmpq to errq to be freed, but the skb being filled was already dequeued from tmpq, so it's never freed. Each chain that overflows leaks the skb and the pages attached to it as frags, and the backend decides how many slots it sends.
Put the skb back on tmpq before taking the error path, like the xennet_set_skb_gso() failure just above it does.
--- drivers/net/xen-netfront.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/xen-netfront.c +3 -1
@@ -1341,8 +1341,10 @@ err: skb->data_len = rx->status; skb->len += rx->status; -if (unlikely (xennet_fill_frags (queue, skb, &tmpq))) +if (unlikely (xennet_fill_frags (queue, skb, &tmpq))) { +__skb_queue_head (&tmpq, skb); goto err; + }if (rx->flags & XEN_NETRXF_csum_blank) skb->ip_summed =CHECKSUM_PARTIAL ;
Greg Kroah-Hartman
maintainerPATCH 320/516 strparser: make sure __strp_recv isnt running before tearing down the parser
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sabrina Dubroca <[email protected]>
commit 0984ebc631792acf8fff105112ee74a6b8f1efcc upstream.
The comment above strp_done() claims that if strp is stopped, strp_recv will no longer be called. That's only true if the caller has a mechanism (eg locking) to guarantee that strp_recv() calls that started before strp_stop() have completed by the time we call strp_done().
This adds a dummy lock_sock/release_sock pair to guarantee that any in-flight strp_recv() (which runs under either bh_lock_sock or lock_sock, depending if it's called from ->sk_data_ready or strp_work) has completed.
Only espintcp can be affected by this race condition, but this patch makes sure no future user of strp can have the bug.
This could crash on strp->sk ("general mode" of strp), but this mode has been here for 9 years and has never been used. It'll be gone soon, no point worrying about it.
Switch the stopped/paused/etc bits to u8's to avoid races between strp_stop() and strp_pause/unpause().
A reproducer has been published and turns the possible UAF into an exploit [1].
--- Documentation/networking/strparser.rst | 2 +- include/net/strparser.h | 10 +++++----- net/strparser/strparser.c | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-)
Documentation/networking/strparser.rst +1 -1
@@ -77,7 +77,7 @@ Functions strp_done is called to release any resources held by the stream parser instance. This must be called after the stream processor - has been stopped. + has been stopped. The socket lock must not be held. ::
include/net/strparser.h +5 -5
@@ -78,11 +78,11 @@ static inline struct strp_msg *strp_msg(struct strparser {struct sock *sk; -u32 stopped :1 ; -u32 paused :1 ; -u32 aborted :1 ; -u32 interrupted :1 ; -u32 unrecov_intr :1 ; +u8 stopped; +u8 paused; +u8 aborted; +u8 interrupted; +u8 unrecov_intr;struct sk_buff **skb_nextp;struct sk_buff *skb_head;
net/strparser/strparser.c +5 -1
@@ -511,12 +511,16 @@ void strp_unpause(struct strparser *strpEXPORT_SYMBOL_GPL (strp_unpause);/* strp must already be stopped so that strp_recv will no longer be called. -* Note that strp_done is not called with the lower socket held. +* Note that strp_done must not be called with the lower socket held. */ void strp_done (struct strparser *strp) {WARN_ON (!strp->stopped); +lock_sock (strp->sk); +/* sync with pending strp_recv */ +release_sock (strp->sk); +cancel_delayed_work_sync (&strp->msg_timer_work);cancel_work_sync (&strp->work);
Greg Kroah-Hartman
maintainerPATCH 321/516 tipc: destroy topsrv workqueues before closing connections
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuqi Xu <[email protected]>
commit 3acdd44385bc7e2e57605e073691ce69cc5a960d upstream.
tipc_topsrv_stop() closed subscriber connections while the topology server's send and receive workqueues were still running. Socket callbacks and subscription events could then queue more work, and in-flight send/recv work could drop the last connection reference during the conn_idr walk.
That race produced several teardown failures: refcount_t addition on 0 from conn_get() on a connection whose release was blocked on idr_lock, a subsequent use-after-free in tipc_conn_close(), queue_work() on an already destroyed workqueue from the listener data-ready callback, and an RCU stall in tipc_topsrv_exit_net() while the walk spun under idr_lock.
Clear srv->listener under idr_lock so it acts as a shutdown flag, skip queue_work() once it is NULL, destroy the workqueues to flush in-flight work, and only then close the remaining connections. Refuse tipc_conn_lookup() after that flag is cleared, and drop idr_lock when the teardown walk finds no connection, so an in-flight subscription event cannot pin idr_in_use while the walk holds the lock.
v3 supersedes the narrower in-thread diff Tung Quang Nguyen posted on 2026-09-23. It keeps his teardown order and adds the lookup refusal and the empty-idr unlock.
--- net/tipc/topsrv.c | 80 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 15 deletions(-)
net/tipc/topsrv.c +65 -15
@@ -54,7 +54,7 @@/** * struct tipc_topsrv - TIPC server structure * @conn_idr: identifier set of connection -* @idr_lock: protect the connection identifier set +* @idr_lock: protect the connection identifier set and listener * @idr_in_use: amount of allocated identifier entry * @net: network namspace instance * @awork: accept work item
@@ -217,6 +217,10 @@ static struct tipc_conn *tipc_conn_lookustruct tipc_conn *con;spin_lock_bh (&s->idr_lock); +if (!s->listener) { +spin_unlock_bh (&s->idr_lock); +return NULL ; + } con =idr_find (&s->conn_idr, conid);if (!connected (con) || !kref_get_unless_zero (&con->kref)) con =NULL ;
@@ -300,10 +304,20 @@ static void tipc_conn_send_to_sock(strucstatic void tipc_conn_send_work (struct work_struct *work) { struct tipc_conn *con = container_of(work, struct tipc_conn, swork); +struct tipc_topsrv *srv; + + srv = con->server; +spin_lock_bh (&srv->idr_lock); +if (!srv->listener) { +spin_unlock_bh (&srv->idr_lock); + goto out; + } +spin_unlock_bh (&srv->idr_lock);if (connected (con))tipc_conn_send_to_sock (con); +out:conn_put (con); }
@@ -333,8 +347,14 @@ void tipc_topsrv_queue_evt(struct net *nlist_add_tail (&e->list, &con->outqueue);spin_unlock_bh (&con->outqueue_lock); -if (queue_work (srv->send_wq, &con->swork)) -return ; +spin_lock_bh (&srv->idr_lock); +if (srv->listener) { +if (queue_work (srv->send_wq, &con->swork)) { +spin_unlock_bh (&srv->idr_lock); +return ; + } + } +spin_unlock_bh (&srv->idr_lock); err:conn_put (con); }
@@ -345,14 +365,20 @@ err:*/ static void tipc_conn_write_space (struct sock *sk) { +struct tipc_topsrv *srv;struct tipc_conn *con;read_lock_bh (&sk->sk_callback_lock); con = sk->sk_user_data;if (connected (con)) { -conn_get (con); -if (!queue_work (con->server->send_wq, &con->swork)) -conn_put (con); + srv = con->server; +spin_lock_bh (&srv->idr_lock); +if (srv->listener) { +conn_get (con); +if (!queue_work (srv->send_wq, &con->swork)) +conn_put (con); + } +spin_unlock_bh (&srv->idr_lock); }read_unlock_bh (&sk->sk_callback_lock); }
@@ -417,8 +443,17 @@ static int tipc_conn_rcv_from_sock(strucstatic void tipc_conn_recv_work (struct work_struct *work) { struct tipc_conn *con = container_of(work, struct tipc_conn, rwork); +struct tipc_topsrv *srv;int count =0 ; + srv = con->server; +spin_lock_bh (&srv->idr_lock); +if (!srv->listener) { +spin_unlock_bh (&srv->idr_lock); + goto out; + } +spin_unlock_bh (&srv->idr_lock); +while (connected (con)) {if (tipc_conn_rcv_from_sock (con))break ;
@@ -429,6 +464,7 @@ static void tipc_conn_recv_work(struct w count =0 ; } } +out:conn_put (con); }
@@ -437,14 +473,20 @@ static void tipc_conn_recv_work(struct w*/ static void tipc_conn_data_ready (struct sock *sk) { +struct tipc_topsrv *srv;struct tipc_conn *con;read_lock_bh (&sk->sk_callback_lock); con = sk->sk_user_data;if (connected (con)) { -conn_get (con); -if (!queue_work (con->server->rcv_wq, &con->rwork)) -conn_put (con); + srv = con->server; +spin_lock_bh (&srv->idr_lock); +if (srv->listener) { +conn_get (con); +if (!queue_work (srv->rcv_wq, &con->rwork)) +conn_put (con); + } +spin_unlock_bh (&srv->idr_lock); }read_unlock_bh (&sk->sk_callback_lock); }
@@ -498,8 +540,12 @@ static void tipc_topsrv_listener_data_reread_lock_bh (&sk->sk_callback_lock); srv = sk->sk_user_data; -if (srv) -queue_work (srv->rcv_wq, &srv->awork); +if (srv) { +spin_lock_bh (&srv->idr_lock); +if (srv->listener) +queue_work (srv->rcv_wq, &srv->awork); +spin_unlock_bh (&srv->idr_lock); + }read_unlock_bh (&sk->sk_callback_lock); }
@@ -696,22 +742,26 @@ static void tipc_topsrv_stop(struct netint id;spin_lock_bh (&srv->idr_lock); + srv->listener =NULL ; +spin_unlock_bh (&srv->idr_lock); +tipc_topsrv_work_stop (srv); + +spin_lock_bh (&srv->idr_lock);for (id =0 ; srv->idr_in_use; id++) { con =idr_find (&srv->conn_idr, id);if (con) { -conn_get (con);spin_unlock_bh (&srv->idr_lock);tipc_conn_close (con); -conn_put (con);spin_lock_bh (&srv->idr_lock); +continue ; } +spin_unlock_bh (&srv->idr_lock); +spin_lock_bh (&srv->idr_lock); }__module_get (lsock->ops->owner);__module_get (lsock->sk->sk_prot_creator->owner); - srv->listener =NULL ;spin_unlock_bh (&srv->idr_lock); -tipc_topsrv_work_stop (srv);sock_release (lsock);idr_destroy (&srv->conn_idr);kfree (srv);
Greg Kroah-Hartman
maintainerPATCH 322/516 tipc: hold a reference to nodes found by link name
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 17e73bae400f6a434dc006e3bee92c94cf781954 upstream.
tipc_node_find_by_name() returns a node after dropping its RCU read lock without taking a reference. The LINK_SET, LINK_GET and LINK_RESET_STATS handlers then lock and access the node, racing with timer-driven cleanup of a down peer. Generic netlink serialization does not exclude the node timer.
The following interleaving can leave a handler using a freed node:
CPU 0: find the node under RCU and release the node read lock CPU 1: tipc_node_timeout() clears the links and unlinks the down node CPU 1: drop the list and timer references, queuing tipc_node_free() CPU 0: leave the RCU read-side critical section
CPU 1: complete the grace period and free the node
CPU 0: acquire the node lock through the stale pointer
LINK_SET also uses the node's media address after releasing the node lock, when passing queued packets to tipc_bearer_xmit().
KASAN on v7.3-rc5 reported:
BUG: KASAN: slab-use-after-free in _raw_read_lock_bh Write of size 4 at addr ffff88807e06f008 by task poc/92 Call Trace: _raw_read_lock_bh kernel/locking/spinlock.c:287 tipc_nl_node_set_link net/tipc/node.c:2475 genl_family_rcv_msg_doit net/netlink/genetlink.c:1114 genl_rcv_msg net/netlink/genetlink.c:1209 netlink_rcv_skb net/netlink/af_netlink.c:2575 Allocated by task 0: tipc_node_create net/tipc/node.c:539 tipc_node_check_dest net/tipc/node.c:1196 tipc_disc_rcv net/tipc/discover.c:252 Freed by task 92: kfree mm/slub.c:6801 rcu_core kernel/rcu/tree.c:2919 Last potentially related work creation: __call_rcu_common.constprop.0 kernel/rcu/tree.c:3181 tipc_node_timeout net/tipc/node.c:814
Acquire a reference to the selected node with kref_get_unless_zero() before leaving RCU, returning NULL if the node has already been released. Release that reference on every caller exit after the last node access, including transmission in LINK_SET. Keep the existing link lookup order and locking so concurrent link removal still takes the existing error paths.
--- net/tipc/node.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/tipc/node.c +9 -1
@@ -2375,8 +2375,11 @@ static struct tipc_node *tipc_node_find_ } }tipc_node_read_unlock (n); -if (found_node) +if (found_node) { +if (!kref_get_unless_zero (&found_node->kref)) + found_node =NULL ;break ; + } }rcu_read_unlock ();
@@ -2461,6 +2464,7 @@ out:tipc_node_read_unlock (node);tipc_bearer_xmit (net, bearer_id, &xmitq, &node->links[bearer_id].maddr,NULL ); +tipc_node_put (node);return res; }
@@ -2512,12 +2516,14 @@ int tipc_nl_node_get_link(struct sk_buff link = node->links[bearer_id].link;if (!link) {tipc_node_read_unlock (node); +tipc_node_put (node); err = -EINVAL ; goto err_free; } err =__tipc_nl_add_link (net, &msg, link,0 );tipc_node_read_unlock (node); +tipc_node_put (node);if (err) goto err_free; }
@@ -2588,11 +2594,13 @@ int tipc_nl_node_reset_link_stats(structif (!link) {spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return -EINVAL ; }tipc_link_reset_stats (link);spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 323/516 Revert "wifi: libertas: reject short monitor TX frames"
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
commit 9727d1c4e1c971fc42b049b645fdda6852758835 upstream.
This reverts commit 13ff543e0b2c713aedeaadadde686686e949dc78.
The 'goto free' just made things worse, causing a spinlock to be handled incorrectly. Revert this for now.
--- drivers/net/wireless/marvell/libertas/tx.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/net/wireless/marvell/libertas/tx.c +0 -7
@@ -116,13 +116,6 @@ netdev_tx_t lbs_hard_start_xmit(struct sif (priv->wdev->iftype ==NL80211_IFTYPE_MONITOR ) {struct tx_radiotap_hdr *rtap_hdr = (void *)skb->data; -if (skb->len <sizeof (*rtap_hdr) +4 +ETH_ALEN ) { -lbs_deb_tx ("tx err: short monitor frame %u\n" , skb->len); - dev->stats.tx_dropped++; - dev->stats.tx_errors++; - goto free; - } -/* set txpd fields from the radiotap header */ txpd->tx_control =cpu_to_le32 (convert_radiotap_rate_to_mv (rtap_hdr->rate));
Greg Kroah-Hartman
maintainerPATCH 324/516 selinux: preserve NATIVE_LABELS on already-initialized sb in set_mnt_opts
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Smalley <[email protected]>
commit 28b7260548af3d35773477993ad4e4de41578dd7 upstream.
When an NFSv4 filesystem exported with security_label is mounted a second time, sget_fc() returns the existing superblock and nfs_get_root() calls security_sb_set_mnt_opts() again on it. Since the superblock is already SB_INITIALIZED, selinux_set_mnt_opts() takes an early exit without setting SECURITY_LSM_NATIVE_LABELS in *set_kern_flags. nfs_get_root() then sees kflags without SECURITY_LSM_NATIVE_LABELS set and clears NFS_CAP_SECURITY_LABEL on the shared nfs_server, silently disabling per-file labeling for both the new and the original mount.
Commit 3815a245b501 ("security/selinux: fix SECURITY_LSM_NATIVE_LABELS on reused superblock") fixed the same problem in selinux_sb_clone_mnt_opts(). The reused-superblock path for a plain second mount now goes through sb_set_mnt_opts rather than sb_clone_mnt_opts, so it needs the same treatment: on both SE_SBINITIALIZED early exits, set SECURITY_LSM_NATIVE_LABELS in *set_kern_flags when the superblock was already using SECURITY_FS_USE_NATVE.
--- security/selinux/hooks.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
security/selinux/hooks.c +8 -1
@@ -640,8 +640,12 @@ static int selinux_set_mnt_opts(struct s* will be used for both mounts) */ if ((sbsec->flags &SE_SBINITIALIZED ) && (sb->s_type->fs_flags &FS_BINARY_MOUNTDATA ) - && !opts) + && !opts) { +if ((kern_flags &SECURITY_LSM_NATIVE_LABELS ) && + sbsec->behavior ==SECURITY_FS_USE_NATIVE ) + *set_kern_flags |=SECURITY_LSM_NATIVE_LABELS ; goto out; + } root_isec =backing_inode_security_novalidate (root);
@@ -693,6 +697,9 @@ static int selinux_set_mnt_opts(struct s/* previously mounted with options, but not on this attempt? */ if ((sbsec->flags &SE_MNTMASK ) && !opts) goto out_double_mount; +if ((kern_flags &SECURITY_LSM_NATIVE_LABELS ) && + sbsec->behavior ==SECURITY_FS_USE_NATIVE ) + *set_kern_flags |=SECURITY_LSM_NATIVE_LABELS ; rc =0 ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 325/516 sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
commit 538b529509c7ab0d909cb65bb7264edca1788d30 upstream.
When an SCTP stream output extension structure (streamoute) has not yet been allocated, sctp_getsockopt_pr_streamstatus() sets the local stack variables params.sprstat_abandoned_unsent = 0 and params.sprstat_abandoned_sent = 0, but then immediately jumps to 'out:', bypassing copy_to_user(). As a result, when an uninitialized user buffer is passed to getsockopt(SCTP_PR_STREAM_STATUS), the kernel returns success (0) without copying the zeroed stats back to user space, leaving uninitialized data in the user buffer.
Refactor the !streamoute check into an if-else chain so that when streamoute is NULL, params is zeroed and falls through to copy_to_user(), copying the zeroed stats to user space and setting retval = 0 once before returning.
Tested in QEMU against Linux 7.3.0-rc3 using an uninitialized sctp_prstatus user struct passed to getsockopt(SCTP_PR_STREAM_STATUS) on a freshly created stream: on the unfixed kernel the user struct contains uninitialized stack garbage; whereas with this fix applied, getsockopt() copies zeroed stats into user space and returns 0.
--- net/sctp/socket.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
net/sctp/socket.c +1 -5
@@ -7405,11 +7405,7 @@ static int sctp_getsockopt_pr_streamstat/* Not allocated yet, means all stats are 0 */ params.sprstat_abandoned_unsent =0 ; params.sprstat_abandoned_sent =0 ; - retval =0 ; - goto out; - } - -if (policy ==SCTP_PR_SCTP_ALL ) { + }else if (policy ==SCTP_PR_SCTP_ALL ) { params.sprstat_abandoned_unsent =0 ; params.sprstat_abandoned_sent =0 ;for (policy =0 ; policy <=SCTP_PR_INDEX (MAX ); policy++) {
Greg Kroah-Hartman
maintainerPATCH 326/516 ibmveth: h_free logical LAN on open-fail after register
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
commit af0524bf4ce1a4cbd2946aa81751582951cfcab5 upstream.
ibmveth_open() registers the logical LAN, then allocates the RX buffer pools. A pool failure jumps to out_free_buffer_pools without h_free_logical_lan(), so PHYP still owns the buffer-list page when it is unmapped. request_irq() failure already issued the hypercall before taking the same label.
Move that h_free to the shared post-register unwind so both paths deregister before the buffer list is unmapped.
--- drivers/net/ethernet/ibm/ibmveth.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +3 -4
@@ -597,10 +597,6 @@ static int ibmveth_open(struct net_devicif (rc !=0 ) {netdev_err (netdev,"unable to request irq 0x%x, rc %d\n" , netdev->irq, rc); -do { - lpar_rc =h_free_logical_lan (adapter->vdev->unit_address); - }while (H_IS_LONG_BUSY (lpar_rc) || (lpar_rc ==H_BUSY )); - goto out_free_buffer_pools; }
@@ -632,6 +628,9 @@ out_free_bounce_buffer: out_free_irq:free_irq (netdev->irq, netdev); out_free_buffer_pools: +do { + lpar_rc =h_free_logical_lan (adapter->vdev->unit_address); + }while (H_IS_LONG_BUSY (lpar_rc) || (lpar_rc ==H_BUSY ));while (--i >=0 ) {if (adapter->rx_buff_pool[i].active) ibmveth_free_buffer_pool(adapter,
Greg Kroah-Hartman
maintainerPATCH 327/516 keys: finalize persistent keyring timeout after link attempt
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 25bf14f817168079f731975b8998fc2af380f29e upstream.
When no keyring exists for the requested UID, KEYCTL_GET_PERSISTENT creates and registers one before linking it to the requested destination. The configured timeout is set only after the destination link succeeds.
A destination restricted with KEYCTL_RESTRICT_KEYRING makes that link fail with -EPERM. With persistent_keyring_expiry set to 60 seconds, /proc/keys still reports the registered keyring's expiry as "perm".
The failed call therefore leaves a quota-exempt keyring in the namespace's hidden register, where it may remain until namespace teardown.
Rename the write-locked helper to key_get_or_create_persistent() and return the key reference through a result parameter. Return 0 when it creates a keyring and 1 when the retry finds an existing one. Return a negative error on failure. Another caller may create the keyring between the initial read-locked lookup and the retry under the write lock.
Set the timeout after permission checking and linking. Do this on success, or on failure if the call allocated the keyring. This leaves a new keyring collectible after failure without starting its timeout while linking is still in progress.
--- security/keys/persistent.c | 55 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 23 deletions(-)
security/keys/persistent.c +32 -23
@@ -33,25 +33,31 @@ static int key_create_persistent_registe }/* -* Create the persistent keyring for the specified user. +* Get or create the persistent keyring for the specified user. * * Called with the namespace's sem locked for writing. +* +* Returns a boolean indicating whether the keyring already existed, +* or a negative error. On success, *persistent_ref holds a reference +* to the keyring. */ -static key_ref_t key_create_persistent (struct user_namespace *ns,kuid_t uid, -struct keyring_index_key *index_key) +static int key_get_or_create_persistent (struct user_namespace *ns,kuid_t uid, +struct keyring_index_key *index_key, +key_ref_t *persistent_ref) {struct key *persistent; -key_ref_t reg_ref, persistent_ref; +key_ref_t reg_ref;if (!ns->persistent_keyring_register) { -long err =key_create_persistent_register (ns); +int err =key_create_persistent_register (ns); +if (err <0 ) -return ERR_PTR (err); +return err; }else { reg_ref =make_key_ref (ns->persistent_keyring_register, true); - persistent_ref =find_key_to_update (reg_ref, index_key); -if (persistent_ref) -return persistent_ref; + *persistent_ref =find_key_to_update (reg_ref, index_key); +if (*persistent_ref) +return 1 ; } persistent = keyring_alloc(index_key->description,
@@ -61,9 +67,10 @@ static key_ref_t key_create_persistent(sKEY_ALLOC_NOT_IN_QUOTA ,NULL , ns->persistent_keyring_register);if (IS_ERR (persistent)) -return ERR_CAST (persistent); +return PTR_ERR (persistent); -return make_key_ref (persistent, true); + *persistent_ref =make_key_ref (persistent, true); +return 0 ; }/*
@@ -78,6 +85,7 @@ static long key_get_persistent(struct uskey_ref_t reg_ref, persistent_ref;char buf[32 ];long ret; +bool created = false;/* Look in the register if it exists */ memset (&index_key,0 ,sizeof (index_key));
@@ -100,23 +108,24 @@ static long key_get_persistent(struct us* also need to create the register. */ down_write (&ns->keyring_sem); - persistent_ref =key_create_persistent (ns, uid, &index_key); + ret =key_get_or_create_persistent (ns, uid, &index_key, + &persistent_ref);up_write (&ns->keyring_sem); -if (!IS_ERR (persistent_ref)) - goto found; - -return PTR_ERR (persistent_ref); +if (ret <0 ) +return ret; + created = ret ==0 ; found: + persistent =key_ref_to_ptr (persistent_ref); ret =key_task_permission (persistent_ref,current_cred (),KEY_NEED_LINK ); -if (ret ==0 ) { - persistent =key_ref_to_ptr (persistent_ref); +if (ret ==0 ) ret =key_link (key_ref_to_ptr (dest_ref), persistent); -if (ret ==0 ) { -key_set_timeout (persistent, persistent_keyring_expiry); - ret = persistent->serial; - } - } + +if (ret ==0 || created) +key_set_timeout (persistent, persistent_keyring_expiry); + +if (ret ==0 ) + ret = persistent->serial;key_ref_put (persistent_ref);return ret;
Greg Kroah-Hartman
maintainerPATCH 328/516 KEYS: Fix add_key() race with keyring restriction
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: 성병찬 <[email protected]>
commit dd3ea3fcba7c75493760cdbccd35f029597e8d5e upstream.
__key_create_or_update() snapshots keyring->restrict_link before taking the destination keyring's semaphore. keyring_restrict() installs a restriction while holding that semaphore.
This allows a writer to observe no restriction, wait for the keyring owner to install a reject-all restriction and return successfully, and then link a key using the stale NULL snapshot. The writer only needs write permission on the destination keyring.
Move the restrict_link read after __key_link_lock() and __key_link_begin(). The read and the subsequent restriction check are then serialized with restriction installation by keyring->sem.
The race was reproduced on v7.2.8 in 19 executions where restriction installation returned before the link completed. All 19 linked the key despite the reject-all restriction. With this change, 312 executions reached the same ordering and every add_key() call failed with -EPERM.
The issue was found by manual concurrency analysis assisted by AI-based analysis and independently verified with a QEMU reproducer and kernel instrumentation.
--- security/keys/key.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
security/keys/key.c +3 -3
@@ -844,9 +844,6 @@ key_ref_t key_create_or_update(key_ref_tkey_check (keyring); -if (!(flags &KEY_ALLOC_BYPASS_RESTRICTION )) - restrict_link = keyring->restrict_link; - key_ref =ERR_PTR (-ENOTDIR );if (keyring->type != &key_type_keyring) goto error_put_type;
@@ -883,6 +880,9 @@ key_ref_t key_create_or_update(key_ref_t goto error_link_end; } +if (!(flags &KEY_ALLOC_BYPASS_RESTRICTION )) + restrict_link = keyring->restrict_link; +if (restrict_link && restrict_link->check) { ret = restrict_link->check (keyring, index_key.type, &prep.payload, restrict_link->key);
Greg Kroah-Hartman
maintainerPATCH 329/516 memstick: core: wait for request completion before freeing card
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raj Ojha <[email protected]>
commit aa0a37b5024d921e96ac4f8f487c8bfbf1f1a582 upstream.
In memstick_alloc_card() and memstick_set_rw_addr(), wait_for_completion_timeout() is used to wait for device identification and address configuration requests to complete.
The memstick subsystem does not provide an abort or cancellation callback in struct memstick_host for in-flight requests. If wait_for_completion_timeout() expires (for instance, when a USB transfer or command retry is delayed), memstick_alloc_card() returns an error and frees the memstick_dev structure via kfree(card).
However, the host controller driver (such as rtsx_usb_ms) is still running the request asynchronously in worker context. When the transfer eventually finishes, the driver writes into host->req->data, which points to memory inside the already freed card structure. This leads to a KASAN slab-use-after-free write:
BUG: KASAN: slab-use-after-free in ms_read_bytes+0x8fe/0x990 Write of size 1 at addr ffff88813c188079 by task kworker/1:5/5239 Workqueue: events rtsx_usb_ms_handle_req Call Trace: ms_read_bytes+0x8fe/0x990 drivers/memstick/host/rtsx_usb_ms.c:450 rtsx_usb_ms_issue_cmd drivers/memstick/host/rtsx_usb_ms.c:477 [inline] rtsx_usb_ms_handle_req+0x557/0x1a00 drivers/memstick/host/rtsx_usb_ms.c:531 process_one_work+0xac7/0x1b10 kernel/workqueue.c:3396 worker_thread+0x5ef/0xe50 kernel/workqueue.c:3560 kthread+0x373/0x450 kernel/kthread.c:436 Allocated by task 1662: memstick_alloc_card drivers/memstick/core/memstick.c:383 [inline] memstick_check+0x2c1/0x10d0 drivers/memstick/core/memstick.c:452 process_one_work+0xac7/0x1b10 kernel/workqueue.c:3396 Freed by task 1662: kfree+0x20c/0x650 mm/slub.c:6792 memstick_alloc_card drivers/memstick/core/memstick.c:420 [inline] memstick_check+0x72b/0x10d0 drivers/memstick/core/memstick.c:452 process_one_work+0xac7/0x1b10 kernel/workqueue.c:3396
Host controller drivers (rtsx_usb_ms, jmb38x_ms, tifm_ms, r592) already implement their own hardware and bus timeouts, and callers in mspro_block and ms_block already rely on wait_for_completion() unconditionally.
Replace wait_for_completion_timeout() with wait_for_completion() in memstick_set_rw_addr() and memstick_alloc_card() so that the card structure is never freed while an asynchronous request is in flight.
--- drivers/memstick/core/memstick.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/memstick/core/memstick.c +2 -6
@@ -369,9 +369,7 @@ int memstick_set_rw_addr(struct memstick { card->next_request = h_memstick_set_rw_addr;memstick_new_req (card->host); -if (!wait_for_completion_timeout (&card->mrq_complete, -msecs_to_jiffies (500 ))) - card->current_mrq.error = -ETIMEDOUT ; +wait_for_completion (&card->mrq_complete);return card->current_mrq.error; }
@@ -405,9 +403,7 @@ static struct memstick_dev *memstick_all card->next_request = h_memstick_read_dev_id;memstick_new_req (host); -if (!wait_for_completion_timeout (&card->mrq_complete, -msecs_to_jiffies (500 ))) - card->current_mrq.error = -ETIMEDOUT ; +wait_for_completion (&card->mrq_complete);if (card->current_mrq.error) goto err_out;
Greg Kroah-Hartman
maintainerPATCH 330/516 memstick: rtsx_usb_ms: complete requests after eject instead of dropping them
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Ngoc Thang <[email protected]>
commit c96ca94425b076dc398d929366e378d1e22ec794 upstream.
memstick_check() can pass its host->removing check just before rtsx_usb_ms_drv_remove() sets eject/removing. Its next request is then silently dropped: rtsx_usb_ms_request() skips schedule_work() once eject is set, and drv_remove's cancel_work_sync() can also cancel a queued handle_req before it picks the request up. Nobody completes card->mrq_complete.
Once memstick core waits for requests without a timeout ("memstick: core:
wait for request completion before freeing card"), this hangs removal:memstick_check() never returns and memstick_remove_host() blocks in flush_workqueue():
INFO: task kworker/u10:3:65 blocked for more than 20 seconds. Workqueue: kmemstick memstick_check __wait_for_common memstick_check INFO: task kworker/1:1:33 blocked for more than 20 seconds. Workqueue: usb_hub_wq hub_event __flush_workqueue memstick_remove_host rtsx_usb_ms_drv_remove
Never drop a request. rtsx_usb_ms_request() always schedules handle_req, and handle_req fails requests with -ENOMEDIUM once eject is set, without touching the device. drv_remove flushes handle_req instead of cancelling it, and cancels it only after memstick_remove_host(), when no new request can arrive, so it cannot run on a freed host.
The host_mutex drain in drv_remove is removed: handle_req always leaves host->req NULL when it finishes, so the drain never had anything to do, and it would now race with handle_req.
--- drivers/memstick/host/rtsx_usb_ms.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-)
drivers/memstick/host/rtsx_usb_ms.c +11 -20
@@ -27,7 +27,6 @@ struct rtsx_usb_ms {struct memstick_host *msh;struct memstick_request *req; -struct mutex host_mutex;struct work_struct handle_req;struct delayed_work poll_card;
@@ -511,6 +510,13 @@ static void rtsx_usb_ms_handle_req(strucstruct memstick_host *msh = host->msh;int rc; +/* Fail requests after eject so their waiters are released. */ +if (host->eject) { +while (!memstick_next_req (msh, &host->req)) + host->req->error = -ENOMEDIUM ; +return ; + } +if (!host->req) {pm_runtime_get_sync (ms_dev (host)); do {
@@ -544,8 +550,7 @@ static void rtsx_usb_ms_request(struct mdev_dbg (ms_dev (host),"--> %s\n" , __func__); -if (!host->eject) -schedule_work (&host->handle_req); +schedule_work (&host->handle_req); } static int rtsx_usb_ms_set_param(struct memstick_host *msh,
@@ -778,7 +783,6 @@ static int rtsx_usb_ms_drv_probe(struct host->power_mode =MEMSTICK_POWER_OFF ;platform_set_drvdata (pdev, host); -mutex_init (&host->host_mutex);INIT_WORK (&host->handle_req, rtsx_usb_ms_handle_req);INIT_DELAYED_WORK (&host->poll_card, rtsx_usb_ms_poll_card);
@@ -809,27 +813,12 @@ static int rtsx_usb_ms_drv_remove(struct {struct rtsx_usb_ms *host =platform_get_drvdata (pdev);struct memstick_host *msh = host->msh; -int err; host->eject = true; msh->removing = true; -cancel_work_sync (&host->handle_req); +flush_work (&host->handle_req);cancel_delayed_work_sync (&host->poll_card); -mutex_lock (&host->host_mutex); -if (host->req) { -dev_dbg (ms_dev (host), -"%s: Controller removed during transfer\n" , -dev_name (&msh->dev)); - host->req->error = -ENOMEDIUM ; -do { - err =memstick_next_req (msh, &host->req); -if (!err) - host->req->error = -ENOMEDIUM ; - }while (!err); - } -mutex_unlock (&host->host_mutex); -/* Balance possible unbalanced usage count * e.g. unconditional module removal */
@@ -838,6 +827,8 @@ static int rtsx_usb_ms_drv_remove(structpm_runtime_disable (ms_dev (host));memstick_remove_host (msh); +/* No card, no new requests; wait for the last failed one to finish. */ +cancel_work_sync (&host->handle_req);dev_dbg (ms_dev (host),": Realtek USB Memstick controller has been removed\n" );memstick_free_host (msh);
Greg Kroah-Hartman
maintainerPATCH 331/516 dm-crypt: reject the lmk IV mode with AEAD ciphers
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ben Cressey <[email protected]>
commit 3195e0daf590683992edb4eed32269e569e04924 upstream.
A "capi:" table line that pairs an AEAD cipher with the lmk IV mode, for example "capi:gcm(aes)-lmk" with the integrity:28:aead option, causes an oops when it is loaded. lmk sets tfms_count to 64, but crypt_alloc_tfms_aead only allocates one transform, so crypt_setkey reads past the end of the tfms_aead array and calls crypto_aead_setkey on the values it finds there.
lmk exists for compatibility with Loop-AES, which uses CBC, so refuse it with an AEAD cipher rather than allocate 64 AEAD transforms. The check cannot go in crypt_iv_lmk_ctr with the other lmk checks, because the IV constructor runs after crypt_set_key.
Note that this is not a security bug because the memory corruption can only be triggered by root.
--- drivers/md/dm-crypt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/md/dm-crypt.c +6 -1
@@ -2869,8 +2869,13 @@ static int crypt_ctr_cipher_new(struct d } } -if (*ivmode && !strcmp (*ivmode,"lmk" )) +if (*ivmode && !strcmp (*ivmode,"lmk" )) { +if (crypt_integrity_aead (cc)) { + ti->error ="AEAD transforms not supported for LMK" ; +return -EINVAL ; + } cc->tfms_count =64 ; + }if (*ivmode && !strcmp (*ivmode,"essiv" )) {if (!*ivopts) {
Greg Kroah-Hartman
maintainerPATCH 332/516 dm-snap: reject the transient exception store for snapshot-merge
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Xinmeng <[email protected]>
commit fcbde6227fcc53c73f08c56b2539e462d545cac6 upstream.
snapshot_merge_next_chunks() calls s->store->type->prepare_merge() without checking it. The transient store ("N") implements neither prepare_merge nor commit_merge, and snapshot_ctr() validates those callbacks only on the handover path (__validate_exception_handover()), so a directly constructed snapshot-merge calls a NULL prepare_merge on resume:
snapshot_merge_resume -> snapshot_merge_next_chunks -> prepare_merge(...)
commit_merge() is NULL for the same reason. Userspace only issues documented device-mapper ioctls (CAP_SYS_ADMIN); this is a misconfiguration the kernel must reject rather than oops on.
Reject the combination in snapshot_ctr() at table-load time (-EINVAL), the same check the handover path already performs; this also covers the commit_merge() call site, which a guard local to the prepare_merge call would miss.
Tested on Linux v6.6.157 KASAN: unpatched, the dmsetup reproducer oopses in snapshot_merge_next_chunks(); with this patch, the table load fails with -EINVAL and no oops. Also present on v6.6.145; still present on the linux-dm tree (555f3d7be91a) and on torvalds/linux master (62f4c998b297) as of 2026-09-22.
Note that this is not a security bug because only root can trigger it.
--- drivers/md/dm-snap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/md/dm-snap.c +14 -0
@@ -1321,6 +1321,20 @@ static int snapshot_ctr(struct dm_target goto bad_store; } +/* +* snapshot-merge requires the optional prepare_merge/commit_merge +* callbacks; the transient exception store does not implement them. +* The handover path checks this in __validate_exception_handover(), +* but a directly constructed snapshot-merge never goes through it. +*/ +if (dm_target_is_snapshot_merge (ti) && + (!s->store->type->prepare_merge || + !s->store->type->commit_merge)) { + ti->error ="Snapshot exception store does not support snapshot-merge." ; + r = -EINVAL ; + goto bad_hash_tables; + } + argv += args_used; argc -= args_used;
Greg Kroah-Hartman
maintainerPATCH 333/516 mmc: cavium-octeon: destroy slot platform devices on remove
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 0f4d4424fc1d651ec3fa63a0a8060ba9087eb0ec upstream.
octeon_mmc_probe() creates host->slot_pdev[i] with of_platform_device_create(), while octeon_mmc_remove() does not destroy the child platform devices.
The probe failure path removes each MMC slot and destroys its associated platform device, but the normal remove path only removes the MMC slot. As a result, the child platform devices remain registered after the Octeon MMC controller is removed.
Destroy each slot platform device during removal after cleaning up the corresponding MMC slot, matching the probe failure cleanup path.
This issue was found by manual code inspection.
--- drivers/mmc/host/cavium-octeon.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/host/cavium-octeon.c +4 -1
@@ -300,9 +300,12 @@ static int octeon_mmc_remove(struct platu64 dma_cfg;int i; -for (i =0 ; i <CAVIUM_MAX_MMC ; i++) +for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot[i])cvm_mmc_of_slot_remove (host->slot[i]); +if (host->slot_pdev[i]) +of_platform_device_destroy (&host->slot_pdev[i]->dev,NULL ); + } dma_cfg =readq (host->dma_base +MIO_EMM_DMA_CFG (host)); dma_cfg &= ~MIO_EMM_DMA_CFG_EN ;
Greg Kroah-Hartman
maintainerPATCH 334/516 mmc: cavium-thunderx: destroy slot platform devices on remove
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 29ee8cf18a21b02cd0b2e35f741b61cd1fe3e14e upstream.
thunder_mmc_probe() creates host->slot_pdev[i] with of_platform_device_create(), while thunder_mmc_remove() does not destroy the child platform devices.
The probe failure path removes each MMC slot and destroys its associated platform device, but the normal remove path only removes the MMC slot. As a result, the child platform devices remain registered after the ThunderX MMC controller is removed.
Destroy each slot platform device during removal after cleaning up the corresponding MMC slot, matching the probe failure cleanup path. Keep an extra device reference around of_platform_device_destroy() as done in the existing error path.
This issue was found by manual code inspection.
--- drivers/mmc/host/cavium-thunderx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/host/cavium-thunderx.c +4 -1
@@ -173,9 +173,12 @@ static void thunder_mmc_remove(struct pcu64 dma_cfg;int i; -for (i =0 ; i <CAVIUM_MAX_MMC ; i++) +for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot[i])cvm_mmc_of_slot_remove (host->slot[i]); +if (host->slot_pdev[i]) +of_platform_device_destroy (&host->slot_pdev[i]->dev,NULL ); + } dma_cfg =readq (host->dma_base +MIO_EMM_DMA_CFG (host)); dma_cfg &= ~MIO_EMM_DMA_CFG_EN ;
Greg Kroah-Hartman
maintainerPATCH 335/516 mmc: mtk-sd: Cancel request timeout work on remove
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yibo Tan <[email protected]>
commit b38af5386a74416e898955443f2e26547b358cb2 upstream.
The driver queues req_timeout while a request is active. msdc_request_done() uses cancel_delayed_work(), which does not wait for a timeout callback that has already started.
The timeout callback calls mmc_request_done(), which wakes the request waiter, and then continues to use host->dev_comp and check the SDIO IRQ. During unbind, msdc_drv_remove() can return and the managed mmc_host can be freed before the callback finishes.
KASAN reported use-after-free accesses in msdc_request_done() and msdc_recheck_sdio_irq() in each of three unbind tests. The same tests completed without a kernel diagnostic after this change.
Call cancel_delayed_work_sync() after mmc_remove_host() has stopped new requests and before the driver releases the host resources.
--- drivers/mmc/host/mtk-sd.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/mtk-sd.c +1 -0
@@ -2611,6 +2611,7 @@ static int msdc_drv_remove(struct platfoplatform_set_drvdata (pdev,NULL );mmc_remove_host (mmc); +cancel_delayed_work_sync (&host->req_timeout);msdc_deinit_hw (host);msdc_gate_clock (host);
Greg Kroah-Hartman
maintainerPATCH 336/516 mmc: sdhci-sprd: disable runtime PM on remove
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit e1c6c10a6a70a69e29b04fcc1ebe4b9bcbc7a49a upstream.
sdhci_sprd_probe() enables runtime PM, while sdhci_sprd_remove() does not perform the corresponding runtime PM cleanup.
The probe failure path disables runtime PM before disabling the clocks, but the normal remove path directly disables clocks that are also managed by the runtime PM callbacks. If the device is runtime suspended, those clocks may already be disabled.
Resume the device before removal, disable runtime PM and drop the temporary runtime PM reference before disabling the clocks.
This issue was found by manual code inspection.
--- drivers/mmc/host/sdhci-sprd.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/host/sdhci-sprd.c +4 -0
@@ -743,6 +743,10 @@ static int sdhci_sprd_remove(struct platstruct sdhci_host *host =platform_get_drvdata (pdev);struct sdhci_sprd_host *sprd_host =TO_SPRD_HOST (host); +pm_runtime_get_sync (&pdev->dev); +pm_runtime_disable (&pdev->dev); +pm_runtime_put_noidle (&pdev->dev); +sdhci_remove_host (host,0 );clk_disable_unprepare (sprd_host->clk_sdio);
Greg Kroah-Hartman
maintainerPATCH 337/516 net/packet: guard the ll header push in packet_rcv_spkt()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quchaosheng <[email protected]>
commit 28bc1ef699610ee09ce3d46a00552f5a0a0144bd upstream.
packet_rcv_spkt() restores the link layer header with
skb_push(skb, skb->data - skb_mac_header(skb));
That subtraction is only meaningful when the device actually has a link layer header. packet_rcv() and tpacket_rcv() both wrap it in dev_has_header(), which is also the predicate the block comment at the top of the file states the restore in terms of; packet_rcv_spkt() does not. commit d549699048b4 ("net/packet: fix packet receive on L3 devices without visible hard header") introduced the helper and changed the two call sites, and this one stayed behind.
A device without a visible ll header can leave skb->mac_header at the 0xFFFF sentinel that __alloc_skb() initialises it to. A CAN skb does:init_can_skb() sets pkt_type and ip_summed but does not reset the headers, and commit 9f10374bb024 ("can: remove private CAN skb headroom infrastructure") dropped the skb_reset_*_header() calls that used to be there. skb_mac_header() is then 0xFFFF, the length becomes a large negative number and skb_push() reports it through skb_under_panic() -- from softirq context, so it is a full system panic even with panic_on_oops=0:
skbuff: skb_under_panic: text:ffffffff8bd21bc1 len:-65455 put:-65471 head:... data:... tail:0x50 end:0x180 dev:can0 kernel BUG at net/core/skbuff.c:214!
RIP: 0010:skb_panic+0x50/0x60 Call Trace: <IRQ> skb_push+0x38/0x40 packet_rcv_spkt+0xe1/0x170 __netif_receive_skb_core.constprop.0+0x7e8/0xd30 ... Kernel panic - not syncing: Fatal exception in interrupt
The socket type is reachable: packet_create() accepts SOCK_PACKET alongside SOCK_RAW and SOCK_DGRAM behind the same CAP_NET_RAW check, and neither the socket length nor a capability check keeps it away from a CAN interface.
The missing skb_reset_*_header() calls in init_can_skb() are a regression in their own right and are being fixed separately, but a packet socket should not turn a link layer that did not initialise its mac header into a kernel panic. Guard the push the way the other two receive paths do.
Tested on v7.3-rc5 under QEMU with a slcan device on a pty, which is the driver RX path: vcan does not reproduce it, because can_send() resets the headers on the way out. One SOCK_PACKET socket bound to can0 and one frame written into the line discipline panics an unpatched kernel with the trace above; the same image with this patch prints no panic and powers off normally. Both kernels are this tree, defconfig plus CONFIG_CAN_SLCAN=y, differing only in this hunk.
--- net/packet/af_packet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/packet/af_packet.c +2 -1
@@ -1922,7 +1922,8 @@ static int packet_rcv_spkt(struct sk_buf spkt = &PACKET_SKB_CB (skb)->sa.pkt; -skb_push (skb, skb->data -skb_mac_header (skb)); +if (dev_has_header (dev)) +skb_push (skb, skb->data -skb_mac_header (skb));/* * The SOCK_PACKET socket receives _all_ frames.
Greg Kroah-Hartman
maintainerPATCH 338/516 net/smc: protect clcsock lifetime in smc_getname
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 64a6b36b0e1855288080bc5f89769f27d6dc03c8 upstream.
smc_getname() dereferences smc->clcsock without holding clcsock_release_lock. Link-group termination can release the CLC socket through smc_close_active_abort() while the SMC socket is still open, for example after shutdown(SHUT_WR).
A getsockname() caller can load smc->clcsock, then the termination worker can clear the pointer and call sock_release() before the caller accesses clcsock->ops or invokes getname(). This causes a use-after-free; if the worker clears the pointer before the load, it causes a NULL dereference. The syscall's file reference keeps the SMC socket alive but does not prevent asynchronous release of its CLC socket.
KASAN reported the following with test-only timing instrumentation:
BUG: KASAN: slab-use-after-free in smc_getname+0x19e/0x1b0 Read of size 8 at addr ffff888109abb4e0 by task poc/103 Call Trace: smc_getname+0x19e/0x1b0 do_getsockname+0xe5/0x170 __sys_getsockname+0x8c/0x100 Allocated by task 95: sock_alloc_inode+0x1e/0x280 sock_alloc+0x3d/0x240 __sock_create+0x7e/0x430 smc_create+0x121/0x240 Freed by task 0: kmem_cache_free+0xcc/0x340 rcu_core+0x50a/0x1850 Last potentially related work creation: evict+0x446/0x6c0 smc_clcsock_release+0xa8/0xd0 smc_close_active_abort+0x26a/0x3a0 __smc_lgr_terminate.part.0+0x137/0x2e0
Hold clcsock_release_lock across the pointer check and the getname() callback to serialize with smc_clcsock_release(). Return -EBADF if the CLC socket has already been released, preserving the existing peer state check and the callback's return value otherwise.
--- net/smc/af_smc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/smc/af_smc.c +6 -1
@@ -1987,6 +1987,7 @@ static int smc_getname(struct socket *so int peer) {struct smc_sock *smc; +int rc = -EBADF ;if (peer && (sock->sk->sk_state !=SMC_ACTIVE ) && (sock->sk->sk_state !=SMC_APPCLOSEWAIT1 ))
@@ -1994,7 +1995,11 @@ static int smc_getname(struct socket *so smc =smc_sk (sock->sk); -return smc->clcsock->ops->getname (smc->clcsock, addr, peer); +mutex_lock (&smc->clcsock_release_lock); +if (smc->clcsock) + rc = smc->clcsock->ops->getname (smc->clcsock, addr, peer); +mutex_unlock (&smc->clcsock_release_lock); +return rc; }static int smc_sendmsg (struct socket *sock,struct msghdr *msg,size_t len)
Greg Kroah-Hartman
maintainerPATCH 339/516 net: usb: ax88179_178a: fix rx frame length for non-last packets
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fredrik Nyberg <[email protected]>
commit 9b6c20f788472d2042717a3c2f1bc60b2b77083e upstream.
Commit 4ce62d5b2f7a ("net: usb: ax88179_178a: stop lying about skb->truesize") replaced skb_clone() with a copy into a new skb for every packet of a bulk-in transfer except the last one. The copy skips the 2-byte IP alignment pseudo header but still copies pkt_len bytes, and pkt_len includes that header. Each of these frames is therefore delivered with two extra trailing bytes: the 0xeeee pseudo header of the next slot when the frame ends on an 8-byte boundary, or slot padding otherwise. The last packet is still trimmed to pkt_len - 2.
IPv4 and IPv6 trim the extra bytes, so most traffic is unaffected. Anything that relies on the frame length is not. MACsec takes the ICV from the last 16 bytes and drops every such frame as InPktsNotValid. In our setup that was 0.2-1.2% of received MACsec frames, depending on how many frames shared a transfer, including service discovery multicast.
Allocate and copy pkt_len - 2 bytes, like the last-packet path.
--- drivers/net/usb/ax88179_178a.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/usb/ax88179_178a.c +3 -3
@@ -1563,11 +1563,11 @@ static int ax88179_rx_fixup(struct usbnereturn 1 ; } - ax_skb =netdev_alloc_skb_ip_align (dev->net, pkt_len); + ax_skb =netdev_alloc_skb_ip_align (dev->net, pkt_len -2 );if (!ax_skb)return 0 ; -skb_put (ax_skb, pkt_len); -memcpy (ax_skb->data, skb->data +2 , pkt_len); +skb_put (ax_skb, pkt_len -2 ); +memcpy (ax_skb->data, skb->data +2 , pkt_len -2 );ax88179_rx_checksum (ax_skb, pkt_hdr);usbnet_skb_return (dev, ax_skb);
Greg Kroah-Hartman
maintainerPATCH 340/516 openvswitch: fix soft lockup in the netlink flow dump
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis V. Lunev <[email protected]>
commit aaaaf87ea99b8766c9a8aa0e71aa42e6bc8a5320 upstream.
A production compute node carrying a few thousand datapath flows hit a soft lockup inside a single netlink flow dump and panicked.
ovs_flow_cmd_dump() calls ovs_flow_stats_get() for every flow it emits, and that releases stats->lock with spin_unlock_bh() once per CPU that has touched the flow. Every release is a local_bh_enable(), and each one runs the pending softirq backlog in the dumping thread's own context.
The skb bounds the flows one callback emits, but not the softirq work it absorbs. On a CPU that carries the box's packet load the backlog refills as fast as it drains, so the dumping thread becomes that CPU's softirq engine. It never sleeps and it has no reschedule point, so under voluntary preemption nothing can take the CPU away from it:
neither the ksoftirqd the kernel woke to take the work over, nor the stopper thread the softlockup detector dispatches to refresh its timestamp.
Hold BH off across the whole callback instead, the way ctnetlink_dump_table() does, so the nested spin_unlock_bh() stop draining softirqs. The loop already runs under rcu_read_lock() and cannot sleep. What it gives up is preemption under CONFIG_PREEMPT, since a BH-off region is not preemptible outside PREEMPT_RT. The region stays short: the skb caps the flows one callback emits, and empty buckets cost no skb space but are each visited once per dump, as the cursor only moves forward. The table grows on insert and shrinks only on flush, so the walk is bounded by the largest flow count the datapath has held. The softirq backlog the callback used to absorb has no bound at all.
--- net/openvswitch/datapath.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/openvswitch/datapath.c +8 -0
@@ -1461,6 +1461,12 @@ static int ovs_flow_cmd_dump(struct sk_breturn -ENODEV ; } +/* +* Not needed for safety. Stops every spin_unlock_bh() in +* ovs_flow_stats_get() from running the softirq backlog. +*/ +local_bh_disable (); + ti =rcu_dereference (dp->table.ti);for (;;) {struct sw_flow *flow;
@@ -1481,6 +1487,8 @@ static int ovs_flow_cmd_dump(struct sk_b cb->args[0 ] = bucket; cb->args[1 ] = obj; } + +local_bh_enable ();rcu_read_unlock ();return skb->len; }
Greg Kroah-Hartman
maintainerPATCH 341/516 regulator: ltc3676: dont read the write-only HRST and CLIRQ registers
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abhishek Ojha <[email protected]>
commit 28c2388ee24cdbefbcc458fa41ef7bffaaa1cc83 upstream.
HRST (0x1e) and CLIRQ (0x1f) are write-only command strobes. Writing HRST triggers a hard reset of the chip and writing CLIRQ clears the interrupt; reading them returns nothing useful, and the read itself fires the command.
The result is that a plain register dump resets the board:
cat /sys/kernel/debug/regmap/2-003c/registers
walks every readable register, hits HRST, and the board reboots.
Split the callback back in two so HRST and CLIRQ stay writable but are no longer readable. The readable range is left unchanged (LTC3676_BUCK1 ... LTC3676_IRQSTAT).
--- drivers/regulator/ltc3676.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/regulator/ltc3676.c +12 -3
@@ -232,7 +232,7 @@ static const struct regulator_desc ltc36 LTC3676_FIXED_REG(LDO4, ldo4, LDOB, 2), }; -static bool ltc3676_readable_writeable_reg (struct device *dev,unsigned int reg) +static bool ltc3676_writeable_reg (struct device *dev,unsigned int reg) {switch (reg) { case LTC3676_BUCK1 ... LTC3676_IRQSTAT:
@@ -243,6 +243,15 @@ static bool ltc3676_readable_writeable_rreturn false; } +static bool ltc3676_readable_reg (struct device *dev,unsigned int reg) +{ +switch (reg) { + case LTC3676_BUCK1 ... LTC3676_IRQSTAT: +return true; + } +return false; +} +static bool ltc3676_volatile_reg (struct device *dev,unsigned int reg) {switch (reg) {
@@ -255,8 +264,8 @@ static bool ltc3676_volatile_reg(structstatic const struct regmap_config ltc3676_regmap_config = { .reg_bits =8 , .val_bits =8 , - .writeable_reg = ltc3676_readable_writeable_reg, - .readable_reg = ltc3676_readable_writeable_reg, + .writeable_reg = ltc3676_writeable_reg, + .readable_reg = ltc3676_readable_reg, .volatile_reg = ltc3676_volatile_reg, .max_register =LTC3676_CLIRQ , .use_single_read = true,
Greg Kroah-Hartman
maintainerPATCH 342/516 scsi: qedi: Initialize callback state before registration
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 85de8b3a5eaa23d153aff4c7c83dddbc949064c9 upstream.
qedi_get_protocol_tlv_data() can be called asynchronously by QED after qedi_ops->register_ops(). It takes stats_lock and reads ll2_mtu, but __qedi_probe() currently registers the callback before initializing the mutex and assigning the default MTU on the normal probe path.
Initialize the callback-visible state before registering qedi_cb_ops. Keep the recovery path from reinitializing state because it reuses the existing qedi context.
--- drivers/scsi/qedi/qedi_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/qedi/qedi_main.c +1 -2
@@ -2671,8 +2671,6 @@ retry_probe:snprintf (host_buf,sizeof (host_buf),"host_%d" , qedi->shost->host_no); qedi_ops->common->set_name (qedi->cdev, host_buf); - qedi_ops->register_ops (qedi->cdev, &qedi_cb_ops, qedi); -memset (¶ms,0 ,sizeof (params)); params.mtu =DEF_PATH_MTU +IPV6_HDR_LEN +TCP_HDR_LEN ; qedi->ll2_mtu =DEF_PATH_MTU ;
@@ -2689,6 +2687,7 @@ retry_probe:spin_lock_init (&qedi->task_idx_lock);mutex_init (&qedi->stats_lock); } + qedi_ops->register_ops (qedi->cdev, &qedi_cb_ops, qedi); qedi_ops->ll2->register_cb_ops (qedi->cdev, &qedi_ll2_cb_ops, qedi); qedi_ops->ll2->start (qedi->cdev, ¶ms);
Greg Kroah-Hartman
maintainerPATCH 343/516 Bluetooth: hci_sock: Serialize dead-device detachment
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 381a0925c556a8d91a80a9b9e3e86651d60ffee3 upstream.
Rebinding an HCI socket after its controller is unregistered can race monitor control replay and crash the kernel. hci_sock_bind() clears hci_pi(sk)->hdev and drops the device reference under only the socket lock, whereas send_monitor_control_replay() holds hci_sk_list.lock for reading.
Replay can observe a non-NULL hdev, then bind can clear it and drop the last reference before create_monitor_ctrl_open() reads hdev->id. This can cause a NULL pointer dereference if the pointer is reloaded, or a use-after-free if the old pointer is retained.
The kernel reported:
KASAN: null-ptr-deref in range [0x0000000000000068-0x000000000000006f] RIP: 0010:create_monitor_ctrl_open+0x579/0x800 Call Trace: hci_sock_bind+0xd96/0x1190 __sys_bind+0x166/0x200 __x64_sys_bind+0x6d/0xb0 do_syscall_64+0xdd/0x4a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f
The same missing serialization lets hci_send_to_sock() select a socket for the old device and queue its frame after bind has detached the socket or installed a new binding.
Take hci_sk_list.lock for writing when clearing the device pointer and resetting the socket state. This waits for existing replay and delivery readers to finish before detachment and prevents later readers from using the old binding. Keep hci_dev_put() outside the critical section because the final device release can sleep.
--- net/bluetooth/hci_sock.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/hci_sock.c +2 -0
@@ -1157,8 +1157,10 @@ static int hci_sock_bind(struct socket **/ hdev =hci_pi (sk)->hdev;if (hdev &&hci_dev_test_flag (hdev,HCI_UNREGISTER )) { +write_lock (&hci_sk_list.lock);hci_pi (sk)->hdev =NULL ; sk->sk_state =BT_OPEN ; +write_unlock (&hci_sk_list.lock);hci_dev_put (hdev); } hdev =NULL ;
Greg Kroah-Hartman
maintainerPATCH 344/516 Bluetooth: RFCOMM: free the skb when the DLC has no owner
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxim Skokov <[email protected]>
commit 9d1afbf60ed53c5b051cd124153e0ae3078c8b93 upstream.
rfcomm_recv_data() hands the skb to d->data_ready() and returns 0 without freeing it, so the callback owns the skb from that point on. The tty implementation frees it when the DLC has been detached from its device:
static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc,
struct sk_buff *skb)
{
struct rfcomm_dev *dev = dlc->owner; if (!dev) {
kfree_skb(skb);
return;
}The socket implementation returns without freeing it, and the skb is leaked.
A connected DLC can have no owner: rfcomm_sock_destruct() clears d->owner, while the DLC itself stays on the session until it is closed. Data frames that arrive in that window still find d->state == BT_CONNECTED in rfcomm_recv_data() and are handed to the callback, one leaked skb each.
The leak does not stop on its own either. The remote runs out of credits only once RFCOMM_RX_THROTTLED is set, and for a socket the only place that sets it is rfcomm_sk_data_ready() itself, below the return. rfcomm_process_dlcs() keeps granting credits, so the remote keeps sending and the leak keeps growing.
Free the skb, as the tty side does.
--- net/bluetooth/rfcomm/sock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/bluetooth/rfcomm/sock.c +4 -1
@@ -50,8 +50,11 @@ static void rfcomm_sock_kill(struct sockstatic void rfcomm_sk_data_ready (struct rfcomm_dlc *d,struct sk_buff *skb) {struct sock *sk = d->owner; -if (!sk) + +if (!sk) { +kfree_skb (skb);return ; + }atomic_add (skb->len, &sk->sk_rmem_alloc);skb_queue_tail (&sk->sk_receive_queue, skb);
Greg Kroah-Hartman
maintainerPATCH 345/516 Bluetooth: RFCOMM: Fix NULL tty_dev dereference in rfcomm_dev_shutdown
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Palla Raghunath <[email protected]>
commit 08e90633377f1b2567ab5ad6810b74c552246a07 upstream.
syzbot hit a NULL pointer dereference in rfcomm_dev_shutdown() when an RFCOMM tty is closed.
rfcomm_dev_add() puts the new device on rfcomm_dev_list first and only then registers the tty device and saves it in dev->tty_dev. If that registration fails, dev->tty_dev is never set at all. The device can be looked up in the meantime, so an open() of /dev/rfcommN gets through rfcomm_tty_install() and attaches to it. When that tty is closed again, rfcomm_dev_shutdown() uses dev->tty_dev without checking it:
Oops: general protection fault, probably for non-canonical address KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047] RIP: 0010:rfcomm_dev_shutdown+0x48/0xb0 net/bluetooth/rfcomm/tty.c:131 Call Trace: tty_port_shutdown+0x1bf/0x220 drivers/tty/tty_port.c:372 tty_port_close+0x4e/0x150 drivers/tty/tty_port.c:705 tty_release+0x359/0x1670 drivers/tty/tty_io.c:1718 __fput+0x418/0xa50 fs/file_table.c:512
rfcomm_dev_destruct() already copes with a NULL dev->tty_dev. Add the same check to rfcomm_dev_shutdown(), so the tty device is only moved when it was actually registered.
--- net/bluetooth/rfcomm/tty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/rfcomm/tty.c +1 -1
@@ -132,7 +132,7 @@ static void rfcomm_dev_shutdown(struct t { struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port); -if (dev->tty_dev->parent) +if (dev->tty_dev && dev->tty_dev->parent)device_move (dev->tty_dev,NULL ,DPM_ORDER_DEV_LAST );/* close the dlc */
Greg Kroah-Hartman
maintainerPATCH 346/516 drm/i915/gem: Prevent overstepping exec array boundary
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Karas <[email protected]>
commit ebe162db655881a38de43301151ff7ac940602b5 upstream.
It is possible for eb_relocate_parse_slow() to call kvfree() on entries outside the original exec array during following scenario inside eb_relocate_parse_slow():
1) eb_copy_relocations() allocates as many as eb->buffer_count copies for exec entries;
2) eb_parse() appends up to two VMAs, right after incrementing eb->buffer_count;
3) cleanup under "out" label uses this incremented buffer_count to release relocation pointers from exec array via kvfree(), not from VMA array.
To amend this problem, ensure that relocation cleanup uses the original exec object count, excluding the VMAs appended by the command parser.
--- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1 -1
@@ -1902,6 +1902,7 @@ static int eb_prefault_relocations(const static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb,struct i915_request *rq) { +const unsigned int count = eb->buffer_count;bool have_copy = false;struct eb_vma *ev;int err =0 ;
@@ -2028,7 +2029,6 @@ err: out:if (have_copy) { -const unsigned int count = eb->buffer_count;unsigned int i;for (i =0 ; i < count; i++) {
Greg Kroah-Hartman
maintainerPATCH 347/516 drm/amdgpu: make Mac FB workaround generic
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit c7f44ec5c4ec760e74351f1843dcb8322f67cbf6 upstream.
Rather than adding a case of every chip where this is seen just check if the FB is at 0 and the ssid is apple. This should cover all chips which fall into this case.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -10
@@ -489,20 +489,17 @@ void amdgpu_gmc_get_vbios_allocations(stcase CHIP_RENOIR : adev->mman.keep_stolen_vga_memory = true;break ; -case CHIP_POLARIS10 : -case CHIP_POLARIS11 : -case CHIP_POLARIS12 : -/* MacBookPros with switchable graphics put VRAM at 0 when -* the iGPU is enabled which results in cursor issues if -* the cursor ends up at 0. Reserve vram at 0 in that case. -*/ -if (adev->gmc.vram_start ==0 ) - adev->mman.keep_stolen_vga_memory = true; -break ;default : adev->mman.keep_stolen_vga_memory = false;break ; } +/* MacBookPros with switchable graphics put VRAM at 0 when +* the iGPU is enabled which results in cursor issues if +* the cursor ends up at 0. Reserve vram at 0 in that case. +*/ +if ((adev->pdev->subsystem_vendor ==PCI_VENDOR_ID_APPLE ) && + (adev->gmc.vram_start ==0 )) + adev->mman.keep_stolen_vga_memory = true;if (!amdgpu_device_ip_get_ip_block (adev,AMD_IP_BLOCK_TYPE_DCE )) { size =0 ;
Greg Kroah-Hartman
maintainerPATCH 348/516 fs: refuse fspick() on internal superblocks
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit 02587a4af82adccaef8e3b3624b4e7f1c401632d upstream.
There's a few instances where a internal superblock is reachable by fspick(). Block that. graft_tree() and fsmount() already refuse them. fanotify refuses mount and superblock marks on them for the same reason.
--- fs/fsopen.c | 3 +++ 1 file changed, 3 insertions(+)
fs/fsopen.c +3 -0
@@ -191,6 +191,9 @@ SYSCALL_DEFINE3(fspick, int, dfd, const ret = -EINVAL ;if (target.mnt->mnt_root != target.dentry) goto err_path; +/* kernel-internal superblocks are nobody's to reconfigure */ +if (target.dentry->d_sb->s_flags &SB_NOUSER ) + goto err_path; fc =fs_context_for_reconfigure (target.dentry,0 ,0 );if (IS_ERR (fc)) {
Greg Kroah-Hartman
maintainerPATCH 349/516 namespace: check a submount for references right before unmounting it
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit 32bf92416614a1e3ff3524fc6b780259c7aad3ef upstream.
shrink_submounts() and mark_mounts_for_expiry() first collect all the mounts they are allowed to unmount and then unmount them.
Whether a mount is busy is decided by propagate_mount_busy() on the tree. But unmounting the first mount changes the tree that the second one propagates into. propagate_umount()
moves a surviving overmount off a copy it unmounts and mounts it where the copy was mounted. If that's where the propagated copy of the second victim is looked up the overmount becomes a candidate of the second umount_tree(). It's childless and so trim_one() commits it without looking at its reference count.
So a synchronous umount pulls out a busy mount that is in use somewhere else and marks it MNT_SYNC_UMOUNT while it has users:
umount2(/tmp/plshrink/p1, 0) = 0 errno 0
cwd is (unreachable)
The same two umounts requested one after the other fail with EBUSY. This needs a mount with MNT_SHRINKABLE, i.e., automounted submounts of NFS, AFS and CIFS or the tracefs mount below debugfs. Bind mounts inherit the flag.
Check each mount right before it is unmounted under the same hold of namespace_sem and mount_lock as the umount itself. Make sure that the algorithm stays linear.
--- fs/namespace.c | 78 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 25 deletions(-)
fs/namespace.c +53 -25
@@ -3126,6 +3126,11 @@ void mark_mounts_for_expiry(struct list_ }while (!list_empty (&graveyard)) { mnt = list_first_entry(&graveyard, struct mount, mnt_expire); +/* an earlier umount_tree() may have moved a busy mount here */ +if (propagate_mount_busy (mnt,1 )) { +list_move (&mnt->mnt_expire, mounts); +continue ; + }touch_mnt_namespace (mnt->mnt_ns);umount_tree (mnt,UMOUNT_PROPAGATE |UMOUNT_SYNC ); }
@@ -3136,16 +3141,36 @@ void mark_mounts_for_expiry(struct list_EXPORT_SYMBOL_GPL (mark_mounts_for_expiry);/* +* Unmount @mnt if it's a shrinkable mount without children that nobody uses. +* +* mount_lock must be held for write +*/ +static bool shrink_submount (struct mount *mnt) +{ +if (propagate_mount_busy (mnt,1 )) +return false; +touch_mnt_namespace (mnt->mnt_ns); +umount_tree (mnt,UMOUNT_PROPAGATE |UMOUNT_SYNC ); +return true; +} + +/* * Ripoff of 'select_parent()' * -* search the list of submounts for a given mountpoint, and move any -* shrinkable submounts to the 'graveyard' list. +* unmount the shrinkable submounts of @parent that aren't busy, children +* before their parent, and say whether anything went +* +* The cursor into the children of @this_parent survives the umount of a +* child mount without child mounts. The mounts that get umounted together with +* it are located under receiving mounts of @this_parent and never under +* @this_parent itself. The one exception is @this_parent getting unmounted +* then the walk starts over. */ -static int select_submounts (struct mount *parent,struct list_head *graveyard) +static bool __shrink_submounts (struct mount *parent) {struct mount *this_parent = parent;struct list_head *next; -int found =0 ; +bool shrunk = false; repeat: next = this_parent->mnt_mounts.next;
@@ -3164,42 +3189,45 @@ resume: this_parent = mnt; goto repeat; } - -if (!propagate_mount_busy (mnt,1 )) { -list_move_tail (&mnt->mnt_expire, graveyard); - found++; - } +if (!shrink_submount (mnt)) +continue ; + shrunk = true; +if (unlikely (this_parent->mnt.mnt_flags &MNT_UMOUNT )) +return true; }/* * All done at this level ... ascend and resume the search */ if (this_parent != parent) { - next = this_parent->mnt_child.next; - this_parent = this_parent->mnt_parent; +struct mount *mnt = this_parent; + + next = mnt->mnt_child.next; + this_parent = mnt->mnt_parent; +/* its children are gone, maybe it can go as well */ +if (shrink_submount (mnt)) { + shrunk = true; +if (unlikely (this_parent->mnt.mnt_flags &MNT_UMOUNT )) +return true; + } goto resume; } -return found; +return shrunk; }/* -* process a list of expirable mountpoints with the intent of discarding any -* submounts of a specific parent mountpoint +* unmount the shrinkable submounts of @mnt that aren't busy +* +* The busy check and the umount of a mount are adjacent. An umount can +* still empty or move a mount in a part of the tree that was walked +* already, so walk again until nothing goes. * * mount_lock must be held for write */ static void shrink_submounts (struct mount *mnt) { -LIST_HEAD (graveyard); -struct mount *m; - -/* extract submounts of 'mountpoint' from the expiration list */ -while (select_submounts (mnt, &graveyard)) { -while (!list_empty (&graveyard)) { - m = list_first_entry(&graveyard, struct mount, - mnt_expire); -touch_mnt_namespace (m->mnt_ns); -umount_tree (m,UMOUNT_PROPAGATE |UMOUNT_SYNC ); - } +for (;;) { +if (!__shrink_submounts (mnt)) +break ; } }
Greg Kroah-Hartman
maintainerPATCH 350/516 dcache: dont put a mountpoint on a dentry thats being removed
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit 75f4197f1e11d2eb75c2d6f916a7d4764db621e5 upstream.
rmdir(), unlink() and rename() call dont_mount() on the victim and then detach_mounts() with the victim's inode locked. do_lock_mount() takes the inode lock of the mountpoint and checks cant_mount() so a mount can't show up after detach_mounts().
But attach_recursive_mnt() makes a second mountpoint for the root of the source mount so that the mounts already located at the destination can be put on top of it. No inode is locked for that one and d_set_mounted() only refuses a dentry that is unlinked. Between detach_mounts() and d_delete() the victim is still hashed:
rmrace: b passed dont_mount() and detach_mounts(), sleeping
T2: move_mount(S, /tmp/plcant/x, BENEATH) = 0 errno 0 ()
T1: rmdir(/tmp/plcant/d/b) = 0 errno 0
109 107 0:61 /d/b//deleted /tmp/plcant/x rw,relatime - tmpfs tmpfs rw
108 109 0:63 / /tmp/plcant/x rw,relatime - tmpfs T rwA bind mount of the directory that's being removed is moved beneath an existing mount while the rmdir() is located between the two calls. The mount ends up on the removed directory and nothing will ever detach it.
Check cant_mount() in d_set_mounted() as well. dont_mount() raises the flag under d_lock before detach_mounts() runs so either the mountpoint is set first and detach_mounts() finds the mount or the flag is seen and the mount is refused.
--- fs/dcache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/dcache.c +3 -1
@@ -1442,6 +1442,8 @@ EXPORT_SYMBOL(path_has_submounts);* * Only one of d_invalidate() and d_set_mounted() must succeed. For * this reason take rename_lock and d_lock on dentry and ancestors. +* Likewise for dont_mount() which marks a dentry that is being removed +* under d_lock. */ int d_set_mounted (struct dentry *dentry) {
@@ -1458,7 +1460,7 @@ int d_set_mounted(struct dentry *dentry)spin_unlock (&p->d_lock); }spin_lock (&dentry->d_lock); -if (!d_unlinked (dentry)) { +if (!d_unlinked (dentry) && !cant_mount (dentry)) { ret = -EBUSY ;if (!d_mountpoint (dentry)) { dentry->d_flags |=DCACHE_MOUNTED ;
Greg Kroah-Hartman
maintainerPATCH 351/516 namespace: refuse an automount below a mount that is in no namespace
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit ba985ce08471c555af2a2fbe217c1bc2e72a6d8c upstream.
It's possible to add autmounts even when the parent mount isn't in the mount namespace of the caller. The only requirement we have is that the parent mount namespace must not be NULL, i.e., unmounted.
Problem is that clone_private_mount() has MNT_NS_INTERNAL which makes that trivially true. So that passes the test and attach_recursive_mnt() accepts that as a mount point and funny enough, count_mounts() dereferences MNT_NS_INTERNAL. The problem is it is an error pointer...
So we can reach this in userspace via fanotify. A filesystem mark on the lower filesystem of an overlay reports paths on the layer clone and reading the event hands out a descriptor on it. For example with debugfs as the lower layer it goes kaboom:
openat(evfd, "tracing", O_DIRECTORY)
Oops: general protection fault KASAN: null-ptr-deref in range [0x1d0-0x1d7] RIP: 0010:count_mounts+0x35/0x200 attach_recursive_mnt finish_automount
And since that sleeping beauty happens under namespace_sem held for writing every mount operation on the system blocks from then on. Congrats.
Use is_mounted() instead which rejects unmounted and internal mounts alike. The open fails with EINVAL just as it did before clone_private_mount() used MNT_NS_INTERNAL.
--- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namespace.c +1 -1
@@ -2893,7 +2893,7 @@ static int do_add_mount(struct mount *neif (!(mnt_flags &MNT_SHRINKABLE ))return -EINVAL ;/* ... and for those we'd better have mountpoint still alive */ -if (!parent->mnt_ns) +if (!is_mounted (&parent->mnt))return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 352/516 staging: rtl8723bs: fix OOB read in OnAssocRsp() IE loop
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandru Hossu <[email protected]>
commit f9654207e92283e0acac5d64fe5f8835383b5a23 upstream.
The IE parsing loop in OnAssocRsp() advances by (pIE->length + 2) each iteration but only guards on i < pkt_len. When a malicious AP sends an AssocResponse whose last IE has only one byte remaining in the frame (the element_id byte lands at pkt_len-1), the loop reads pIE->length from pframe[pkt_len], which is one byte past the allocated receive buffer.
Additionally, even when the header bytes are in bounds, pIE->length itself can extend the data window beyond pkt_len, silently passing a truncated IE to the handler functions.
Add two guards at the top of the loop body:
1. Break if fewer than sizeof(*pIE) bytes remain (can't read header).
2. Break if the IE's declared data extends past pkt_len.
[ mdmitrichenko: adapt to 5.10: struct ndis_80211_var_ie still has the
CamelCase Length field and a one-element data[1] array here, so sizeof(*pIE) is 3 rather than the 2-byte IE header. Use the explicit header size 2, as the existing i += (pIE->Length + 2) does, so that a valid IE ending exactly at pkt_len is not dropped. ]
--- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4 -0
@@ -1682,7 +1682,11 @@ unsigned int OnAssocRsp(struct adapter */* to handle HT, WMM, rate adaptive, update MAC reg */ /* for not to handle the synchronous IO in the tasklet */ for (i = (6 +WLAN_HDR_A3_LEN ); i < pkt_len;) { +if (i +2 > pkt_len) +break ; pIE = (struct ndis_80211_var_ie *)(pframe + i); +if (i +2 + pIE->Length > pkt_len) +break ;switch (pIE->ElementID) {case _VENDOR_SPECIFIC_IE_:
Greg Kroah-Hartman
maintainerPATCH 353/516 drm/aspeed: Balance the display clock enable on teardown
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit ecce445c6489895463b7ddec2af66338287fee4c ]
aspeed_gfx_load() enables the display clock without checking the return value and never disables it on probe failure or removal. devm_clk_get() only releases the clock reference, leaving the enable unbalanced.
Use devm_clk_get_enabled() to handle enable failures and automatically disable and unprepare the clock on probe failure or removal.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/gpu/drm/aspeed/aspeed_gfx_drv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/aspeed/aspeed_gfx_drv.c +2 -3
@@ -138,13 +138,12 @@ static int aspeed_gfx_load(struct drm_device *drm) }reset_control_deassert (priv->rst); - priv->clk =devm_clk_get (drm->dev,NULL ); + priv->clk =devm_clk_get_enabled (drm->dev,NULL );if (IS_ERR (priv->clk)) {dev_err (&pdev->dev, -"missing or invalid clk device tree entry" ); +"failed to get and enable clock\n" );return PTR_ERR (priv->clk); } -clk_prepare_enable (priv->clk);/* Sanitize control registers */ writel (0 , priv->base +CRT_CTRL1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 354/516 drm/vc4: Free the BO cache size list on teardown
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maíra Canal <[email protected]>
[ Upstream commit b41ff8b529278216cba22a5dcdc93fea2a3a9619 ]
vc4_bo_cache_destroy() purges the cached BOs but never frees the size list, leaking it on every unbind.
--- drivers/gpu/drm/vc4/vc4_bo.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/vc4/vc4_bo.c +1 -0
@@ -1049,6 +1049,7 @@ static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)cancel_work_sync (&vc4->bo_cache.time_work);vc4_bo_cache_purge (dev); +kfree (vc4->bo_cache.size_list);for (i =0 ; i < vc4->num_labels; i++) {if (vc4->bo_labels[i].num_allocated) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 355/516 net/sched: em_text: reject unterminated algo before autoload
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit c9728fcf2e7fb4a7a8d08ebd9524c3b02ae1a021 ]
This is a follow-up to commit 9c572a83037a ("net/sched: fix potential stack infoleak in em_text_dump()"), which zero-initialised the dump-side struct. Sashiko pointed at a pre-existing bug that exposed the change-side input-validation gap open.
em_text_change() casts the raw netlink attribute payload to struct tcf_em_text and passes conf->algo, a 16-byte array with no enforced NUL terminator, to textsearch_prepare(). On the TS_AUTOLOAD retry textsearch_prepare() calls request_module("ts_%s", algo); vsnprintf() walks %s until it finds a NUL, so an algo[] with no NUL reads past the array into the adjacent struct fields and payload and feeds those bytes to the usermode helper command line. This is an out-of-bounds read and a kernel memory disclosure.
Reject the attribute when no NUL exists within TC_EM_TEXT_ALGOSIZ bytes, matching the check xt_string has had since 3ab720881b6e.
Conditions to recreate the bug:
- CAP_NET_ADMIN on the target netns (namespace-local via unshare -Urn is enough)
- install clsact on an interface, then add a basic filter with one text ematch whose algo[] is 16 bytes with no NUL (e.g. "A"*16) and pattern_len at least 1
- the add fails with -ENOENT and the kernel invokes modprobe with a module name made of "ts_" plus the 16 bytes and the adjacent payload
--- net/sched/em_text.c | 3 +++ 1 file changed, 3 insertions(+)
net/sched/em_text.c +3 -0
@@ -51,6 +51,9 @@ static int em_text_change(struct net *net, void *data, int len,if (len <sizeof (*conf) || len < (sizeof (*conf) + conf->pattern_len))return -EINVAL ; +if (!memchr (conf->algo,'\0' ,sizeof (conf->algo))) +return -EINVAL ; +if (conf->from_layer > conf->to_layer)return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 356/516 cxgb4/ch_ktls: disable softirqs around tid_list erases
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Hoon Choi <[email protected]>
[ Upstream commit 4c9dc0faca98084922caeb689579d338cf3e1c29 ]
chcr_ktls_cpl_act_open_rpl() inserts into tid_list from the receive path using xa_insert_bh(). The array is shared by the adapter's connections and initialized with XA_FLAGS_LOCK_BH. However, chcr_ktls_dev_del() and the chcr_ktls_dev_add() error path use xa_erase(), which takes the XArray lock without disabling softirqs.
When cleanup runs with softirqs enabled, a receive softirq for another connection on the same CPU can interrupt the erase and spin on the lock held by the interrupted task. Use xa_erase_bh() at both sites to match the insertion path.
--- .../net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +2 -2
@@ -396,7 +396,7 @@ static void chcr_ktls_dev_del(struct net_device *netdev,cxgb4_remove_tid (&tx_info->adap->tids, tx_info->tx_chan, tx_info->tid, tx_info->ip_family); -xa_erase (&u_ctx->tid_list, tx_info->tid); +xa_erase_bh (&u_ctx->tid_list, tx_info->tid); } port_stats = &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
@@ -587,7 +587,7 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,cxgb4_remove_tid (&tx_info->adap->tids, tx_info->tx_chan, tx_info->tid, tx_info->ip_family); -xa_erase (&u_ctx->tid_list, tx_info->tid); +xa_erase_bh (&u_ctx->tid_list, tx_info->tid); put_module:/* release module refcount */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 357/516 nvmet: use the local P2P device on metadata allocation failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Hoon Choi <[email protected]>
[ Upstream commit 4aa9c0f377a4de5e8fddce76b34ee4529639a1ff ]
nvmet_req_alloc_p2pmem_sgls() assigns req->p2p_dev only after the data and metadata SGL allocations succeed. If the data allocation succeeds but the metadata allocation fails, out_free_sg passes req->p2p_dev to pci_p2pmem_free_sgl() before that assignment has taken place.
Pass the local p2p_dev argument instead, so cleanup uses the same PCI device as the successful data allocation.
--- drivers/nvme/target/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/core.c +1 -1
@@ -1027,7 +1027,7 @@ static int nvmet_req_alloc_p2pmem_sgls(struct pci_dev *p2p_dev,return 0 ; out_free_sg: -pci_p2pmem_free_sgl (req->p2p_dev, req->sg); +pci_p2pmem_free_sgl (p2p_dev, req->sg); out_err:return -ENOMEM ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 358/516 ASoC: samsung: i2s: enable op_clk in probe to balance runtime PM
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Szyprowski <[email protected]>
[ Upstream commit 7529254014764ae0b8c33d5c61a58f36c65b1a1c ]
The probe function puts the device into the runtime PM active state with only the "iis" bus clock enabled, but it also sets priv->op_clk to the parent of the RCLK_SRC mux without enabling it. The runtime PM suspend callback disables both clocks, so the first runtime suspend after probe disables op_clk once more than it was enabled.
On Exynos5250 Arndale both clocks resolve to the same EXYNOS_I2S_BUS gate, so this triggers the following warning during boot:
WARNING: drivers/clk/clk.c:1270 at clk_core_disable+0xe4/0x23c, CPU#0: kworker/u8:3/45 i2s_bus already disabled ... Workqueue: pm pm_runtime_work Call trace: ... clk_core_disable from clk_disable+0x28/0x34 clk_disable from i2s_runtime_suspend+0x58/0x68 [snd_soc_i2s] i2s_runtime_suspend [snd_soc_i2s] from genpd_runtime_suspend+0xc4/0x298 genpd_runtime_suspend from __rpm_callback+0x48/0x18c __rpm_callback from rpm_callback+0x4c/0x50 rpm_callback from rpm_suspend+0xf4/0x718 rpm_suspend from pm_runtime_work+0x9c/0xa0 ...
Fix this by enabling op_clk in probe right after getting it, so the clock state matches the runtime PM active state, and by disabling it in remove.
--- sound/soc/samsung/i2s.c | 8 ++++++++ 1 file changed, 8 insertions(+)
sound/soc/samsung/i2s.c +8 -0
@@ -1528,9 +1528,16 @@ static int samsung_i2s_probe(struct platform_device *pdev) goto err_disable_pm; priv->op_clk =clk_get_parent (priv->clk_table[CLK_I2S_RCLK_SRC ]); + ret =clk_prepare_enable (priv->op_clk); +if (ret <0 ) { + priv->op_clk =NULL ; + goto err_unregister_clk; + }return 0 ; +err_unregister_clk: +i2s_unregister_clock_provider (priv); err_disable_pm:pm_runtime_disable (&pdev->dev); err_del_sec:
@@ -1553,6 +1560,7 @@ static int samsung_i2s_remove(struct platform_device *pdev)i2s_unregister_clock_provider (priv);i2s_delete_secondary_device (priv); +clk_disable_unprepare (priv->op_clk);clk_disable_unprepare (priv->clk);pm_runtime_put_noidle (&pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 359/516 flow_dissector: avoid u16 truncation of skb->len when computing thoff
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 99bda1ecbd56905f8bd934b9cdccd3bd251192b1 ]
__skb_flow_dissect() computes key_control->thoff using:
key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
min_t(u16, ...) casts both arguments to u16 before comparing them. Whenever skb->len (or hlen) modulo 65536 is smaller than nhoff, the truncated length wins and thoff is set to a bogus small value, even when the dissection succeeded. For example, an IPv4/TCP frame with skb->len == 65540 and nhoff == 34 gets thoff == 4, so callers such as skb_probe_transport_header() point the transport header inside the Ethernet header.
Such skbs are not exotic:
- At the time of commit d0c081b49137 ("flow_dissector: properly cap thoff field"), AF_PACKET with PACKET_VNET_HDR could already build GSO skbs larger than 64KB (MTU checks are skipped for GSO, and alloc_skb_with_frags() accepted up to MAX_SKB_FRAGS (17) order-0 pages on top of the linear part).
- BIG TCP now makes skbs larger than 64KB common.
- The following patch makes tun_get_user() dissect IFF_TAP frames before eth_type_trans() pulls the Ethernet header, so a GSO frame carrying a 65522..65535 byte L3 packet will be dissected with skb->len in [65536, 65549].
Compare as u32 instead. If the resulting offset cannot be represented in the u16 key_control->thoff, cap it to U16_MAX and report the dissection as failed rather than silently returning a wrong transport offset. thoff is still set on failure, as some callers (such as eth_get_headlen()) use it regardless of the return value.
--- net/core/flow_dissector.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/flow_dissector.c +8 -1
@@ -933,6 +933,7 @@ bool __skb_flow_dissect(const struct net *net,int mpls_lse =0 ;int num_hdrs =0 ;u8 ip_proto =0 ; +u32 thoff;bool ret;if (!data) {
@@ -1475,7 +1476,13 @@ bool __skb_flow_dissect(const struct net *net, ret = true; out: - key_control->thoff =min_t (u16, nhoff, skb ? skb->len : hlen); + thoff =min_t (u32, nhoff, skb ? skb->len : hlen); +if (unlikely (thoff >U16_MAX )) { +/* Cannot be represented in key_control->thoff. */ + thoff =U16_MAX ; + ret = false; + } + key_control->thoff = thoff; key_basic->n_proto = proto; key_basic->ip_proto = ip_proto;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 360/516 flow_dissector: avoid u16 truncation of hlen in bpf_flow_dissect()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit f202578efc738b883cfa04889eb97328914265a7 ]
bpf_flow_dissect() sanitizes the offsets returned by the BPF program with clamp_t(u16, ..., hlen).
If hlen is bigger than 65535, the upper bound is truncated before the comparison. For instance, with hlen == 65536, both nhoff and thoff are forced to zero, even if the program returned sane values.
This is the same class of bug as the one fixed in commit 99bda1ecbd56 ("flow_dissector: avoid u16 truncation of skb->len when computing thoff"). That fix does not cover the BPF path, because __skb_flow_dissect() returns early when a BPF flow dissector handles the packet.
struct bpf_flow_keys stores nhoff and thoff as u16, so cap hlen to U16_MAX before clamping.
Found by sashiko while reviewing the commit above.
--- net/core/flow_dissector.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/flow_dissector.c +2 -0
@@ -884,6 +884,8 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, result =bpf_prog_run_pin_on_cpu (prog, ctx); +/* bpf_flow_keys offsets are u16: do not let @hlen be truncated. */ + hlen =min_t (int, hlen,U16_MAX ); flow_keys->nhoff =clamp_t (u16, flow_keys->nhoff, nhoff, hlen); flow_keys->thoff =clamp_t (u16, flow_keys->thoff, flow_keys->nhoff, hlen);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 361/516 net/mlx5e: Order ICOSQ cc update after CQ doorbell
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit b056ca4d3742d0769f91137bb1ce3215428398f7 ]
mlx5e_poll_ico_cq() requires sq->cc to be updated only after mlx5_cqwq_update_db_record(), otherwise a CQ overrun may occur.
The current implementation updates sq->cc before the CQ doorbell record, violating this ordering requirement.
Update the CQ doorbell record first and use dma_wmb() before updating sq->cc. This ensures that the CQ space is released to the device before the corresponding ICOSQ consumer index is updated by software.
--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +4 -2
@@ -705,10 +705,12 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq) }while (!last_wqe); }while ((++i <MLX5E_TX_CQ_POLL_BUDGET ) && (cqe =mlx5_cqwq_get_cqe (&cq->wq))); - sq->cc = sqcc; -mlx5_cqwq_update_db_record (&cq->wq); +/* ensure cq space is freed before enabling more cqes */ +dma_wmb (); + + sq->cc = sqcc;return i; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 362/516 net: openvswitch: validate transport header presence in set_ipv6_addr
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 3c6a4b11330fe424557538a98fca9f0a4c5bf313 ]
When executing IPv6 address rewrite actions on IPv6 fragments, set_ipv6_addr() calls update_ipv6_checksum(). If parse_ipv6hdr() processes a non-first IPv6 fragment, it sets key->ip.proto to NEXTHDR_FRAGMENT and returns early without calling skb_set_transport_header().
update_ipv6_checksum() unconditionally evaluates skb_transport_offset() on entry before checking l4_proto. Because skb->transport_header is uninitialized, this triggers a warning under CONFIG_DEBUG_NET=y although it is completely harmless.
Fix this by returning early in update_ipv6_checksum() if l4_proto is NEXTHDR_FRAGMENT. This avoids reading the uninitialized transport offset for fragments while preserving the debug warning for any other protocol where the transport header is unexpectedly missing.
See the syzbot trace:
!skb_transport_header_was_set(skb)
WARNING: ./include/linux/skbuff.h:3075 at skb_transport_header include/linux/skbuff.h:3075 [inline], CPU#1: syz-executor463/5635 WARNING: ./include/linux/skbuff.h:3075 at skb_transport_offset include/linux/skbuff.h:3250 [inline], CPU#1: syz-executor463/5635 WARNING: ./include/linux/skbuff.h:3075 at update_ipv6_checksum net/openvswitch/actions.c:361 [inline], CPU#1: syz-executor463/5635 WARNING: ./include/linux/skbuff.h:3075 at set_ipv6_addr+0x462/0x660 net/openvswitch/actions.c:399, CPU#1: syz-executor463/5635 [...] RIP: 0010:skb_transport_header include/linux/skbuff.h:3075 [inline] RIP: 0010:skb_transport_offset include/linux/skbuff.h:3250 [inline] RIP: 0010:update_ipv6_checksum net/openvswitch/actions.c:361 [inline] RIP: 0010:set_ipv6_addr+0x462/0x660 net/openvswitch/actions.c:399 [...] Call Trace: <TASK> set_ipv6 net/openvswitch/actions.c:531 [inline] do_execute_actions+0x557e/0x8600 net/openvswitch/actions.c:1366 ovs_execute_actions+0xde/0x520 net/openvswitch/actions.c:1592 ovs_packet_cmd_execute+0xb4f/0xf10 net/openvswitch/datapath.c:705 genl_family_rcv_msg_doit+0x233/0x340 net/netlink/genetlink.c:1114 genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209 netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2572 genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218 netlink_unicast+0x7bd/0x940 net/netlink/af_netlink.c:1361 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1916 sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
--- net/openvswitch/actions.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/openvswitch/actions.c +6 -1
@@ -379,7 +379,12 @@ static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,static void update_ipv6_checksum (struct sk_buff *skb,u8 l4_proto,__be32 addr[4 ],const __be32 new_addr[4 ]) { -int transport_len = skb->len -skb_transport_offset (skb); +int transport_len; + +if (l4_proto ==NEXTHDR_FRAGMENT ) +return ; + + transport_len = skb->len -skb_transport_offset (skb);if (l4_proto ==NEXTHDR_TCP ) {if (likely (transport_len >=sizeof (struct tcphdr )))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 363/516 can: fix unique skb identifier regression under RPS
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 7093c3b8314a4ef7405c4066a2521398c455efe7 upstream.
Commit d4fb6514ff8e ("can: use skb hash instead of private variable in headroom") moved the per-skb unique identifier used for raw_rcv() duplicate detection into skb->hash.
With RPS enabled, get_rps_cpu() calls skb_get_hash() before the frame reaches the CAN subsystem. Since CAN skbs have no L3/L4 headers, the flow dissector assigns every CAN frame the same non-zero software hash. can_set_skb_uid() only generated a new identifier when skb->hash was 0, so it kept this constant hash. When the SLAB allocator later reused the same skb address, raw_rcv() mistook the next legitimate frame for a duplicate and dropped it.
Fix this by storing the CAN UID in the CAN skb extension (struct can_skb_ext::can_skb_uid) instead of skb->hash, decoupling it from any hash the network stack may compute. can_set_skb_uid() keeps its "assign only if unset" behaviour, which preserves UIDs set before transmission (e.g. by isotp to identify echo frames) across the local loopback path.
Frames whose extension is shared with another clone (e.g. via tc mirred or netem duplicate) are given a private extension copy before the UID is assigned, so that independently received skb clones from real CAN interfaces (skbcnt = 0) don't end up with the same UID.
The limitation that tc mirred/netem skb duplicates might be dropped in raw_rcv for looped back isotp echo frame skbs is accepted. There is no valid use-case for tc mirred or netem together with isotp which is not capable to operate on different CAN interfaces simultaneously. For routing and modifying CAN frames together with isotp use can-gw.
can-gw and vxcan additionally clear the UID of forwarded/duplicated frames so each newly routed frame gets its own unique identifier.
[ backport to 5.10: no CAN skb extensions available, so the UID is kept
in struct can_skb_priv::skbcnt in the headroom (effectively reverting d4fb6514ff8e) and isotp is adapted accordingly. As skb clones share the headroom, the private extension copy for tc mirred/netem duplicates is not applicable. The UID resets in can-gw and vxcan are omitted, as writing to the shared headroom of cloned skbs would also alter the UID of the original skb. This keeps the pre-d4fb6514ff8e behaviour for routed and vxcan forwarded frames. ]
--- drivers/net/can/dev/dev.c | 2 ++ drivers/net/can/slcan.c | 1 + include/linux/can/dev.h | 1 + include/linux/can/skb.h | 2 ++ net/can/af_can.c | 6 ++---- net/can/bcm.c | 2 ++ net/can/isotp.c | 11 +++++++---- net/can/j1939/socket.c | 1 + net/can/j1939/transport.c | 2 ++ net/can/raw.c | 7 ++++--- 10 files changed, 24 insertions(+), 11 deletions(-)
drivers/net/can/dev/dev.c +2 -0
@@ -694,6 +694,7 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)can_skb_reserve (skb);can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ; *cf =skb_put_zero (skb,sizeof (struct can_frame ));
@@ -721,6 +722,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev,can_skb_reserve (skb);can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ; *cfd =skb_put_zero (skb,sizeof (struct canfd_frame ));
drivers/net/can/slcan.c +1 -0
@@ -213,6 +213,7 @@ static void slc_bump(struct slcan *sl)can_skb_reserve (skb);can_skb_prv (skb)->ifindex = sl->dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ;skb_put_data (skb, &cf,sizeof (struct can_frame ));
include/linux/can/dev.h +1 -0
@@ -119,6 +119,7 @@ static inline bool can_skb_headroom_valid(struct net_device *dev,if (skb->ip_summed ==CHECKSUM_NONE ) {/* init headroom */ can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ; skb->ip_summed =CHECKSUM_UNNECESSARY ;
include/linux/can/skb.h +2 -0
@@ -28,10 +28,12 @@/** * struct can_skb_priv - private additional data inside CAN sk_buffs * @ifindex: ifindex of the first interface the CAN frame appeared on +* @skbcnt: atomic counter to have an unique id together with skb pointer * @cf: align to the following CAN frame at skb->data */ struct can_skb_priv {int ifindex; +u32 skbcnt;struct can_frame cf[]; };
net/can/af_can.c +2 -4
@@ -644,10 +644,8 @@ static int can_rcv_filter(struct can_dev_rcv_lists *dev_rcv_lists, struct sk_bufvoid can_set_skb_uid (struct sk_buff *skb) {/* create non-zero unique skb identifier together with *skb */ -while (!(skb->hash)) - skb->hash =atomic_inc_return (&skbcounter); - - skb->sw_hash =1 ; +while (!(can_skb_prv (skb)->skbcnt)) +can_skb_prv (skb)->skbcnt =atomic_inc_return (&skbcounter); }EXPORT_SYMBOL (can_set_skb_uid);
net/can/bcm.c +2 -0
@@ -338,6 +338,7 @@ static void bcm_can_tx(struct bcm_op *op, struct canfd_frame *cf)can_skb_reserve (skb);can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ;skb_put_data (skb, cf, op->cfsiz);
@@ -1576,6 +1577,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk, }can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ; skb->dev = dev;can_skb_set_owner (skb, sk); err =can_send (skb,1 );/* send with loopback */
net/can/isotp.c +7 -4
@@ -287,6 +287,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)can_skb_reserve (nskb);can_skb_prv (nskb)->ifindex = dev->ifindex; +can_skb_prv (nskb)->skbcnt =0 ; nskb->dev = dev;can_skb_set_owner (nskb, sk);
@@ -848,6 +849,7 @@ static void isotp_send_cframe(struct isotp_sock *so)can_skb_reserve (skb);can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ;/* set uid in tx skb to identify CF echo frames */ can_set_skb_uid (skb);
@@ -876,7 +878,7 @@ static void isotp_send_cframe(struct isotp_sock *so)pr_notice_once ("can-isotp: cfecho is %08X != 0\n" , old_cfecho);/* set consecutive frame echo tag */ -WRITE_ONCE (so->cfecho, skb->hash); +WRITE_ONCE (so->cfecho,can_skb_prv (skb)->skbcnt);/* send frame with local echo enabled */ can_send_ret =can_send (skb,1 );
@@ -939,7 +941,7 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)spin_lock (&so->rx_lock);/* so->cfecho may since belong to a new transfer; recheck under lock */ -if (READ_ONCE (so->cfecho) != skb->hash) +if (READ_ONCE (so->cfecho) !=can_skb_prv (skb)->skbcnt) goto out_unlock;/* cancel local echo timeout */
@@ -1161,6 +1163,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)can_skb_reserve (skb);can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ;/* set uid in tx skb to identify CF echo frames */ can_set_skb_uid (skb);
@@ -1202,7 +1205,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) cf->data[ae] |= size;/* set CF echo tag for isotp_rcv_echo() (SF-mode) */ -WRITE_ONCE (so->cfecho, skb->hash); +WRITE_ONCE (so->cfecho,can_skb_prv (skb)->skbcnt); }else {/* send first frame */
@@ -1219,7 +1222,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) so->txfc.bs =0 ;/* set CF echo tag for isotp_rcv_echo() (CF-mode) */ -WRITE_ONCE (so->cfecho, skb->hash); +WRITE_ONCE (so->cfecho,can_skb_prv (skb)->skbcnt); }else {/* standard flow control check */ new_state =ISOTP_WAIT_FIRST_FC ;
net/can/j1939/socket.c +1 -0
@@ -889,6 +889,7 @@ static struct sk_buff *j1939_sk_alloc_skb(struct net_device *ndev,can_skb_reserve (skb);can_skb_prv (skb)->ifindex = ndev->ifindex; +can_skb_prv (skb)->skbcnt =0 ;skb_reserve (skb, offsetof(struct can_frame , data)); ret =memcpy_from_msg (skb_put (skb, size), msg, size);
net/can/j1939/transport.c +2 -0
@@ -608,6 +608,7 @@ sk_buff *j1939_tp_tx_dat_new(struct j1939_priv *priv, skb->dev = priv->ndev;can_skb_reserve (skb);can_skb_prv (skb)->ifindex = priv->ndev->ifindex; +can_skb_prv (skb)->skbcnt =0 ;/* reserve CAN header */ skb_reserve (skb, offsetof(struct can_frame , data));
@@ -1534,6 +1535,7 @@ j1939_session *j1939_session_fresh_new(struct j1939_priv *priv, skb->dev = priv->ndev;can_skb_reserve (skb);can_skb_prv (skb)->ifindex = priv->ndev->ifindex; +can_skb_prv (skb)->skbcnt =0 ; skcb =j1939_skb_to_cb (skb);memcpy (skcb, rel_skcb,sizeof (*skcb));
net/can/raw.c +4 -3
@@ -74,8 +74,8 @@ MODULE_ALIAS("can-proto-1");*/ struct uniqframe { +u32 skbcnt;const struct sk_buff *skb; -u32 hash;unsigned int join_rx_count; };
@@ -135,7 +135,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data)/* eliminate multiple filter matches for the same skb */ if (this_cpu_ptr (ro->uniq)->skb == oskb && -this_cpu_ptr (ro->uniq)->hash == oskb->hash) { +this_cpu_ptr (ro->uniq)->skbcnt ==can_skb_prv (oskb)->skbcnt) {if (ro->join_filters) {this_cpu_inc (ro->uniq->join_rx_count);/* drop frame until all enabled filters matched */
@@ -146,7 +146,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data) } }else {this_cpu_ptr (ro->uniq)->skb = oskb; -this_cpu_ptr (ro->uniq)->hash = oskb->hash; +this_cpu_ptr (ro->uniq)->skbcnt =can_skb_prv (oskb)->skbcnt;this_cpu_ptr (ro->uniq)->join_rx_count =1 ;/* drop first frame to check all enabled filters? */ if (ro->join_filters && ro->count >1 )
@@ -812,6 +812,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)can_skb_reserve (skb);can_skb_prv (skb)->ifindex = dev->ifindex; +can_skb_prv (skb)->skbcnt =0 ; err =memcpy_from_msg (skb_put (skb, size), msg, size);if (err <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 364/516 drm/amd/display: Dont replace a sink mode that shares the native totals
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Betschart <[email protected]>
commit 54c998c55fc9cbc391b350d67b86e0c2a0748f1a upstream.
decide_crtc_timing_for_drm_display_mode() copies the native mode's CRTC timing into the requested mode when clock, htotal and vtotal match. That is meant for the modes amdgpu inserts itself:amdgpu_dm_create_common_mode() duplicates the native mode and changes only hdisplay and vdisplay, so those are sent with the native timing and scaled.
A sink can also offer a real mode with the same clock and totals as its native mode. CTA-861 VIC 102 (4096x2160@60) and VIC 97 (3840x2160@60) both use 594 MHz and 4400x2250. With 3840x2160@60 as the preferred mode, a 4096x2160@60 request goes out with the 3840x2160 timing and the framebuffer scaled into it (dst 3840x2025 at y=67), while the AVI InfoFrame still carries VIC 102. A JVC projector then reports 3840x2160 and shows a corrupted right edge. 4096x2160@24, whose totals differ, is sent and displayed correctly.
Inserted modes keep the native sync positions; a real mode with its own active width does not. Compare those too, so only inserted modes are patched.
[ Adrian: this tree keeps the function in amdgpu_dm.c, with the equal-totals
case as its own else-if; added the sync checks there. Dropped the KUnit test, its file does not exist here. ]
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -1
@@ -4710,11 +4710,16 @@ decide_crtc_timing_for_drm_display_mode(struct drm_display_mode *drm_mode,const struct drm_display_mode *native_mode, bool scale_enabled) { + /* Inserted modes copy the native sync; a sink mode with equal totals may not */ if (scale_enabled) {copy_crtc_timing_for_drm_display_mode (native_mode ,drm_mode ); } else if (native_mode->clock == drm_mode->clock && native_mode->htotal == drm_mode->htotal && - native_mode->vtotal == drm_mode->vtotal) { + native_mode->vtotal == drm_mode->vtotal && + native_mode->hsync_start == drm_mode->hsync_start && + native_mode->hsync_end == drm_mode->hsync_end && + native_mode->vsync_start == drm_mode->vsync_start && + native_mode->vsync_end == drm_mode->vsync_end) {copy_crtc_timing_for_drm_display_mode (native_mode, drm_mode); }else {/* no scaling nor amdgpu inserted, no need to patch */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 365/516 HID: hid-steam: Fix cleanup in probe()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit a9f1da09c69f13ef471db8b22107a28042d230ca ]
There are a number of issues in this code. First of all if steam_create_client_hid() fails then it leads to an error pointer dereference when we call hid_destroy_device(steam->client_hdev).
Also there are a number of leaks. hid_hw_stop() is not called if hid_hw_open() fails for example. And it doesn't call steam_unregister() or hid_hw_close().
[Lee: Move client_hdev creation after steam_register() and omit
mode_switch and rumble_work cancellation as 691ead124a0c and e133dc99fc07 are not present]
--- drivers/hid/hid-steam.c | 43 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-)
drivers/hid/hid-steam.c +23 -20
@@ -751,31 +751,20 @@ static int steam_probe(struct hid_device *hdev,INIT_WORK (&steam->work_connect, steam_work_connect_cb);INIT_LIST_HEAD (&steam->list); - steam->client_hdev =steam_create_client_hid (hdev); -if (IS_ERR (steam->client_hdev)) { - ret =PTR_ERR (steam->client_hdev); - goto client_hdev_fail; - } - steam->client_hdev->driver_data = steam; -/* * With the real steam controller interface, do not connect hidraw. * Instead, create the client_hid and connect that. */ ret =hid_hw_start (hdev,HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDRAW );if (ret) - goto hid_hw_start_fail; - - ret =hid_add_device (steam->client_hdev); -if (ret) - goto client_hdev_add_fail; + goto err_cancel_work; ret =hid_hw_open (hdev);if (ret) {hid_err (hdev,"%s:hid_hw_open\n" , __func__); - goto hid_hw_open_fail; + goto err_hw_stop; }if (steam->quirks &STEAM_QUIRK_WIRELESS ) {
@@ -791,19 +780,33 @@ static int steam_probe(struct hid_device *hdev,hid_err (hdev,"%s:steam_register failed with error %d\n" , __func__, ret); - goto input_register_fail; + goto err_hw_close; } } + steam->client_hdev =steam_create_client_hid (hdev); +if (IS_ERR (steam->client_hdev)) { + ret =PTR_ERR (steam->client_hdev); + goto err_stream_unregister; + } + steam->client_hdev->driver_data = steam; + + ret =hid_add_device (steam->client_hdev); +if (ret) + goto err_destroy; +return 0 ; -input_register_fail: -hid_hw_open_fail: -client_hdev_add_fail: -hid_hw_stop (hdev); -hid_hw_start_fail: +err_destroy:hid_destroy_device (steam->client_hdev); -client_hdev_fail: +err_stream_unregister: +if (steam->connected) +steam_unregister (steam); +err_hw_close: +hid_hw_close (hdev); +err_hw_stop: +hid_hw_stop (hdev); +err_cancel_work:cancel_work_sync (&steam->work_connect); steam_alloc_fail: hid_err(hdev, "%s: failed with error %d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 366/516 HID: hid-steam: Make client_opened a counter
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vicki Pfau <[email protected]>
[ Upstream commit 555b818adb97eca70210a49ba3f1d27882dde092 ]
The client_opened variable was used to track if the hidraw was opened by any clients to silence keyboard/mouse events while opened. However, there was no counting of how many clients were opened, so opening two at the same time and then closing one would fool the driver into thinking it had no remaining opened clients.
[Lee: Adapt steam_client_ll_open() and steam_client_ll_close() as
691ead124a0c and e1147961b214 are not present]
--- drivers/hid/hid-steam.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hid/hid-steam.c +7 -7
@@ -114,7 +114,7 @@ struct steam_device {spinlock_t lock;struct hid_device *hdev, *client_hdev;struct mutex mutex; -bool client_opened; +unsigned long client_opened;struct input_dev __rcu *input;unsigned long quirks;struct work_struct work_connect;
@@ -509,7 +509,7 @@ static void steam_battery_unregister(struct steam_device *steam)static int steam_register (struct steam_device *steam) {int ret; -bool client_opened; +unsigned long client_opened;/* * This function can be called several times in a row with the
@@ -634,7 +634,7 @@ static int steam_client_ll_open(struct hid_device *hdev)struct steam_device *steam = hdev->driver_data;mutex_lock (&steam->mutex); - steam->client_opened = true; + steam->client_opened++;mutex_unlock (&steam->mutex);steam_input_unregister (steam);
@@ -654,12 +654,12 @@ static void steam_client_ll_close(struct hid_device *hdev)spin_unlock_irqrestore (&steam->lock, flags);mutex_lock (&steam->mutex); - steam->client_opened = false; -if (connected) + steam->client_opened--; +if (connected && !steam->client_opened)steam_set_lizard_mode (steam, lizard_mode);mutex_unlock (&steam->mutex); -if (connected) +if (connected && !steam->client_opened)steam_input_register (steam); }
@@ -824,7 +824,7 @@ static void steam_remove(struct hid_device *hdev) }hid_destroy_device (steam->client_hdev); - steam->client_opened = false; + steam->client_opened =0 ;cancel_work_sync (&steam->work_connect);if (steam->quirks &STEAM_QUIRK_WIRELESS ) {hid_info (hdev,"Steam wireless receiver disconnected" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 367/516 HID: steam: Fully unregister controller when hidraw is opened
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vicki Pfau <[email protected]>
[ Upstream commit cd33a91d37eb4d7c6ce56aa7f4688066309808eb ]
To avoid conflicts between anything touching the hidraw and the driver we had previously detached the evdev nodes when the hidraw is opened. However, this isn't sufficient to avoid FEATURE reports from conflicting, so we change to fully unregistering the controller internally, leaving only the hidraw active until it's closed.
This also unifies the unregister and connect callbacks, as now the logic between these two callbacks is identical.
[Lee: Convert steam_client_ll_open() and steam_client_ll_close() to
schedule work_connect directly and omit sensors, rumble_work, mode_switch and unregister_work changes as e133dc99fc07, e1147961b214 and 1d4549fd1115 are not present]
--- drivers/hid/hid-steam.c | 78 ++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 36 deletions(-)
drivers/hid/hid-steam.c +42 -36
@@ -380,6 +380,7 @@ static int steam_battery_register(struct steam_device *steam) &steam->battery_desc, &battery_cfg);if (IS_ERR (battery)) { ret =PTR_ERR (battery); +devm_kfree (&steam->hdev->dev, steam->battery_desc.name);hid_err (steam->hdev,"%s:power_supply_register failed with error %d\n" , __func__, ret);
@@ -504,12 +505,15 @@ static void steam_battery_unregister(struct steam_device *steam)RCU_INIT_POINTER (steam->battery,NULL );synchronize_rcu ();power_supply_unregister (battery); +devm_kfree (&steam->hdev->dev, steam->battery_desc.name); }static int steam_register (struct steam_device *steam) {int ret;unsigned long client_opened; +unsigned long flags; +bool do_add;/* * This function can be called several times in a row with the
@@ -535,38 +539,47 @@ static int steam_register(struct steam_device *steam)if (steam->quirks &STEAM_QUIRK_WIRELESS )steam_battery_register (steam); -mutex_lock (&steam_devices_lock); -if (list_empty (&steam->list)) -list_add (&steam->list, &steam_devices); -mutex_unlock (&steam_devices_lock); + do_add = true; } -mutex_lock (&steam->mutex); +spin_lock_irqsave (&steam->lock, flags); client_opened = steam->client_opened; -if (!client_opened) -steam_set_lizard_mode (steam, lizard_mode); -mutex_unlock (&steam->mutex); +spin_unlock_irqrestore (&steam->lock, flags); -if (!client_opened) +if (!client_opened) { +mutex_lock (&steam->mutex); +steam_set_lizard_mode (steam, lizard_mode); +mutex_unlock (&steam->mutex); ret =steam_input_register (steam); -else - ret =0 ; +if (ret !=0 ) + goto steam_register_input_fail; + } + +if (do_add) { +mutex_lock (&steam_devices_lock); +if (list_empty (&steam->list)) +list_add (&steam->list, &steam_devices); +mutex_unlock (&steam_devices_lock); + } +return 0 ; +steam_register_input_fail:return ret; }static void steam_unregister (struct steam_device *steam) { +if (!steam->serial_no[0 ]) +return ; + +hid_info (steam->hdev,"Steam Controller '%s' disconnected" , + steam->serial_no);steam_battery_unregister (steam);steam_input_unregister (steam); -if (steam->serial_no[0 ]) { -hid_info (steam->hdev,"Steam Controller '%s' disconnected" , - steam->serial_no); -mutex_lock (&steam_devices_lock); -list_del_init (&steam->list); -mutex_unlock (&steam_devices_lock); - steam->serial_no[0 ] =0 ; - } +mutex_lock (&steam_devices_lock); +list_del_init (&steam->list); +mutex_unlock (&steam_devices_lock); + steam->serial_no[0 ] =0 ; }static void steam_work_connect_cb (struct work_struct *work)
@@ -575,19 +588,20 @@ static void steam_work_connect_cb(struct work_struct *work) work_connect);unsigned long flags;bool connected; +bool opened;int ret;spin_lock_irqsave (&steam->lock, flags); + opened = steam->client_opened; connected = steam->connected;spin_unlock_irqrestore (&steam->lock, flags); -if (connected) { +if (connected && !opened) { ret =steam_register (steam); -if (ret) { +if (ret)hid_err (steam->hdev,"%s:steam_register failed with error %d\n" , __func__, ret); - } }else {steam_unregister (steam); }
@@ -632,12 +646,13 @@ static void steam_client_ll_stop(struct hid_device *hdev)static int steam_client_ll_open (struct hid_device *hdev) {struct steam_device *steam = hdev->driver_data; +unsigned long flags; -mutex_lock (&steam->mutex); +spin_lock_irqsave (&steam->lock, flags); steam->client_opened++; -mutex_unlock (&steam->mutex); +spin_unlock_irqrestore (&steam->lock, flags); -steam_input_unregister (steam); +schedule_work (&steam->work_connect);return 0 ; }
@@ -645,22 +660,13 @@ static int steam_client_ll_open(struct hid_device *hdev)static void steam_client_ll_close (struct hid_device *hdev) {struct steam_device *steam = hdev->driver_data; -unsigned long flags; -bool connected;spin_lock_irqsave (&steam->lock, flags); - connected = steam->connected; -spin_unlock_irqrestore (&steam->lock, flags); - -mutex_lock (&steam->mutex); steam->client_opened--; -if (connected && !steam->client_opened) -steam_set_lizard_mode (steam, lizard_mode); -mutex_unlock (&steam->mutex); +spin_unlock_irqrestore (&steam->lock, flags); -if (connected && !steam->client_opened) -steam_input_register (steam); +schedule_work (&steam->work_connect); } static int steam_client_ll_raw_request(struct hid_device *hdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 368/516 HID: steam: Rearrange teardown sequence
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vicki Pfau <[email protected]>
[ Upstream commit ddce9641ce924ed91ec8304577e463823a29ffaf ]
This fixes a narrow window during the teardown sequence where callbacks could still be scheduled during cleanup that would then have a dangling pointer to the now-freed steam struct.
This also puts work canceling for rumble and mode switch in steam_unregister, as that shouldn't persist while the client hdev is open.
[Lee: Omit rumble_work, coalesce_rumble_work and mode_switch
cancellation as e133dc99fc07 and 1d4549fd1115 are not present]
--- drivers/hid/hid-steam.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/hid-steam.c +3 -2
@@ -829,15 +829,16 @@ static void steam_remove(struct hid_device *hdev)return ; } +hid_hw_close (hdev);hid_destroy_device (steam->client_hdev); + steam->client_hdev =NULL ; steam->client_opened =0 ;cancel_work_sync (&steam->work_connect);if (steam->quirks &STEAM_QUIRK_WIRELESS ) {hid_info (hdev,"Steam wireless receiver disconnected" ); } -hid_hw_close (hdev); -hid_hw_stop (hdev);steam_unregister (steam); +hid_hw_stop (hdev); }static void steam_do_connect_event (struct steam_device *steam,bool connected)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 369/516 HID: steam: Refactor registration
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vicki Pfau <[email protected]>
[ Upstream commit 6f9b740c31ba7e061b2ebb330d9a3d63f1358f29 ]
This refactors and simplifies the registration/unregistration flow. Since we now only perform registration when the client isn't opened anymore, the logic for handling that can be removed, and the rest of the function streamlined.
We also remove the previous assumption that we have a serial number to show we're registered, replacing it with a single purpose boolean.
In a previous refactor the code for unregistering a battery if later registration steps failed was accidentally left out. As a result, a lingering power_supply object could get left over after the steam object was torn down. This is also fixed here.
[Lee: Omit sensors, steam_get_attributes(), rumble_work,
coalesce_rumble_work and mode_switch changes as e133dc99fc07, a0fbd9437d7d and 1d4549fd1115 are not present]
--- drivers/hid/hid-steam.c | 70 ++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 39 deletions(-)
drivers/hid/hid-steam.c +31 -39
@@ -119,6 +119,7 @@ struct steam_device {unsigned long quirks;struct work_struct work_connect;bool connected; +bool registered;char serial_no[STEAM_SERIAL_LEN +1 ];struct power_supply_desc battery_desc;struct power_supply __rcu *battery;
@@ -511,9 +512,6 @@ static void steam_battery_unregister(struct steam_device *steam)static int steam_register (struct steam_device *steam) {int ret; -unsigned long client_opened; -unsigned long flags; -bool do_add;/* * This function can be called several times in a row with the
@@ -521,59 +519,53 @@ static int steam_register(struct steam_device *steam)* another client send a get_connection_status command, for example. * The battery and serial number are set just once per device. */ -if (!steam->serial_no[0 ]) { -/* -* Unlikely, but getting the serial could fail, and it is not so -* important, so make up a serial number and go on. -*/ -mutex_lock (&steam->mutex); -if (steam_get_serial (steam) <0 ) -strlcpy (steam->serial_no,"XXXXXXXXXX" , -sizeof (steam->serial_no)); -mutex_unlock (&steam->mutex); - -hid_info (steam->hdev,"Steam Controller '%s' connected" , - steam->serial_no); +if (steam->registered) +return 0 ; -/* ignore battery errors, we can live without it */ -if (steam->quirks &STEAM_QUIRK_WIRELESS ) -steam_battery_register (steam); +/* +* Unlikely, but getting the serial could fail, and it is not so +* important, so make up a serial number and go on. +*/ +mutex_lock (&steam->mutex); +if (steam_get_serial (steam) <0 || !steam->serial_no[0 ]) +strlcpy (steam->serial_no,"XXXXXXXXXX" , +sizeof (steam->serial_no)); +mutex_unlock (&steam->mutex); - do_add = true; - } +hid_info (steam->hdev,"Steam Controller '%s' connected" , + steam->serial_no); -spin_lock_irqsave (&steam->lock, flags); - client_opened = steam->client_opened; -spin_unlock_irqrestore (&steam->lock, flags); +/* ignore battery errors, we can live without it */ +if (steam->quirks &STEAM_QUIRK_WIRELESS ) +steam_battery_register (steam); -if (!client_opened) { -mutex_lock (&steam->mutex); -steam_set_lizard_mode (steam, lizard_mode); -mutex_unlock (&steam->mutex); - ret =steam_input_register (steam); -if (ret !=0 ) - goto steam_register_input_fail; - } +mutex_lock (&steam->mutex); +steam_set_lizard_mode (steam, lizard_mode); +mutex_unlock (&steam->mutex); + ret =steam_input_register (steam); +if (ret !=0 ) + goto steam_register_input_fail; -if (do_add) { -mutex_lock (&steam_devices_lock); -if (list_empty (&steam->list)) -list_add (&steam->list, &steam_devices); -mutex_unlock (&steam_devices_lock); - } + steam->registered = true; +mutex_lock (&steam_devices_lock); +if (list_empty (&steam->list)) +list_add (&steam->list, &steam_devices); +mutex_unlock (&steam_devices_lock);return 0 ; steam_register_input_fail: +steam_battery_unregister (steam);return ret; }static void steam_unregister (struct steam_device *steam) { -if (!steam->serial_no[0 ]) +if (!steam->registered)return ;hid_info (steam->hdev,"Steam Controller '%s' disconnected" , steam->serial_no); + steam->registered = false;steam_battery_unregister (steam);steam_input_unregister (steam);mutex_lock (&steam_devices_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 370/516 HID: steam: Clean up locking
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vicki Pfau <[email protected]>
[ Upstream commit de1d341b9b3ec9655f31fb8b44f784cca5e670ad ]
This cleans up several issues with locking behavior, including RCU accesses not being guarded behind a lock.
[Lee: Use explicit lock/unlock calls instead of guard(), adapt to
steam->mutex, and omit Steam Deck sensors, mode_switch, rumble_work, coalesce_rumble_work and Ibex changes as 691ead124a0c, e133dc99fc07, a0fbd9437d7d, 1d4549fd1115, fcfa7db89f7a and 0a80b4e8ec6a are not present]
--- drivers/hid/hid-steam.c | 61 +++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 20 deletions(-)
drivers/hid/hid-steam.c +41 -20
@@ -114,6 +114,7 @@ struct steam_device {spinlock_t lock;struct hid_device *hdev, *client_hdev;struct mutex mutex; +struct mutex registration_mutex;unsigned long client_opened;struct input_dev __rcu *input;unsigned long quirks;
@@ -294,9 +295,14 @@ static void steam_set_lizard_mode(struct steam_device *steam, bool enable)static int steam_input_open (struct input_dev *dev) {struct steam_device *steam =input_get_drvdata (dev); +unsigned long flags; +bool client_opened; +spin_lock_irqsave (&steam->lock, flags); + client_opened = steam->client_opened; +spin_unlock_irqrestore (&steam->lock, flags);mutex_lock (&steam->mutex); -if (!steam->client_opened && lizard_mode) +if (!client_opened && lizard_mode)steam_set_lizard_mode (steam, false);mutex_unlock (&steam->mutex);return 0 ;
@@ -305,9 +311,14 @@ static int steam_input_open(struct input_dev *dev)static void steam_input_close (struct input_dev *dev) {struct steam_device *steam =input_get_drvdata (dev); +unsigned long flags; +bool client_opened; +spin_lock_irqsave (&steam->lock, flags); + client_opened = steam->client_opened; +spin_unlock_irqrestore (&steam->lock, flags);mutex_lock (&steam->mutex); -if (!steam->client_opened && lizard_mode) +if (!client_opened && lizard_mode)steam_set_lizard_mode (steam, true);mutex_unlock (&steam->mutex); }
@@ -513,40 +524,43 @@ static int steam_register(struct steam_device *steam) {int ret; +mutex_lock (&steam->registration_mutex);/* * This function can be called several times in a row with the * wireless adaptor, without steam_unregister() between them, because * another client send a get_connection_status command, for example. * The battery and serial number are set just once per device. */ -if (steam->registered) +if (steam->registered) { +mutex_unlock (&steam->registration_mutex);return 0 ; + } +mutex_lock (&steam->mutex);/* * Unlikely, but getting the serial could fail, and it is not so * important, so make up a serial number and go on. */ -mutex_lock (&steam->mutex);if (steam_get_serial (steam) <0 || !steam->serial_no[0 ])strlcpy (steam->serial_no,"XXXXXXXXXX" ,sizeof (steam->serial_no)); -mutex_unlock (&steam->mutex);hid_info (steam->hdev,"Steam Controller '%s' connected" , steam->serial_no); +steam_set_lizard_mode (steam, lizard_mode); +mutex_unlock (&steam->mutex); +/* ignore battery errors, we can live without it */ if (steam->quirks &STEAM_QUIRK_WIRELESS )steam_battery_register (steam); -mutex_lock (&steam->mutex); -steam_set_lizard_mode (steam, lizard_mode); -mutex_unlock (&steam->mutex); ret =steam_input_register (steam);if (ret !=0 ) goto steam_register_input_fail; steam->registered = true; +mutex_unlock (&steam->registration_mutex);mutex_lock (&steam_devices_lock);if (list_empty (&steam->list))list_add (&steam->list, &steam_devices);
@@ -555,6 +569,7 @@ static int steam_register(struct steam_device *steam) steam_register_input_fail:steam_battery_unregister (steam); +mutex_unlock (&steam->registration_mutex);return ret; }
@@ -565,9 +580,11 @@ static void steam_unregister(struct steam_device *steam)hid_info (steam->hdev,"Steam Controller '%s' disconnected" , steam->serial_no); +mutex_lock (&steam->registration_mutex); steam->registered = false;steam_battery_unregister (steam);steam_input_unregister (steam); +mutex_unlock (&steam->registration_mutex);mutex_lock (&steam_devices_lock);list_del_init (&steam->list);mutex_unlock (&steam_devices_lock);
@@ -745,6 +762,7 @@ static int steam_probe(struct hid_device *hdev,hid_set_drvdata (hdev, steam);spin_lock_init (&steam->lock);mutex_init (&steam->mutex); +mutex_init (&steam->registration_mutex); steam->quirks = id->driver_data;INIT_WORK (&steam->work_connect, steam_work_connect_cb);INIT_LIST_HEAD (&steam->list);
@@ -835,13 +853,10 @@ static void steam_remove(struct hid_device *hdev)static void steam_do_connect_event (struct steam_device *steam,bool connected) { -unsigned long flags;bool changed; -spin_lock_irqsave (&steam->lock, flags); changed = steam->connected != connected; steam->connected = connected; -spin_unlock_irqrestore (&steam->lock, flags);if (changed &&schedule_work (&steam->work_connect) ==0 ) dbg_hid("%s: connected=%d event already queued\n",
@@ -1008,8 +1023,6 @@ static void steam_do_input_event(struct steam_device *steam,static void steam_do_battery_event (struct steam_device *steam,struct power_supply *battery,u8 *data) { -unsigned long flags; -s16 volts =steam_le16 (data +12 );u8 batt = data[14 ];
@@ -1017,10 +1030,8 @@ static void steam_do_battery_event(struct steam_device *steam,rcu_read_lock (); battery =rcu_dereference (steam->battery);if (likely (battery)) { -spin_lock_irqsave (&steam->lock, flags); steam->voltage = volts; steam->battery_charge = batt; -spin_unlock_irqrestore (&steam->lock, flags);power_supply_changed (battery); }rcu_read_unlock ();
@@ -1033,10 +1044,12 @@ static int steam_raw_event(struct hid_device *hdev,struct steam_device *steam =hid_get_drvdata (hdev);struct input_dev *input;struct power_supply *battery; +unsigned long flags;if (!steam)return 0 ; +spin_lock_irqsave (&steam->lock, flags);if (steam->client_opened)hid_input_report (steam->client_hdev,HID_FEATURE_REPORT , data, size,0 );
@@ -1057,12 +1070,12 @@ static int steam_raw_event(struct hid_device *hdev,*/ if (size !=64 || data[0 ] !=1 || data[1 ] !=0 ) -return 0 ; + goto out;switch (data[2 ]) {case STEAM_EV_INPUT_DATA :if (steam->client_opened) -return 0 ; + goto out;rcu_read_lock (); input =rcu_dereference (steam->input);if (likely (input))
@@ -1100,6 +1113,8 @@ static int steam_raw_event(struct hid_device *hdev, }break ; } +out: +spin_unlock_irqrestore (&steam->lock, flags);return 0 ; }
@@ -1108,6 +1123,8 @@ static int steam_param_set_lizard_mode(const char *val, {struct steam_device *steam;int ret; +bool client_opened; +unsigned long flags; ret =param_set_bool (val, kp);if (ret)
@@ -1115,10 +1132,14 @@ static int steam_param_set_lizard_mode(const char *val,mutex_lock (&steam_devices_lock);list_for_each_entry (steam, &steam_devices, list) { -mutex_lock (&steam->mutex); -if (!steam->client_opened) +spin_lock_irqsave (&steam->lock, flags); + client_opened = steam->client_opened; +spin_unlock_irqrestore (&steam->lock, flags); +if (!client_opened) { +mutex_lock (&steam->mutex);steam_set_lizard_mode (steam, lizard_mode); -mutex_unlock (&steam->mutex); +mutex_unlock (&steam->mutex); + } }mutex_unlock (&steam_devices_lock);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 371/516 tracing: Set the trace clock before registering the histogram trigger
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 6ede78d0563a2a3ae3e46f9c07cedb5d79645429 ]
hist_register_trigger() puts the trigger on the global named_triggers list in cmd_ops->init(), and only then sets the trace clock:
if (data->cmd_ops->init) {
ret = data->cmd_ops->init(data);
if (ret < 0)
goto out;
}
if (hist_data->enable_timestamps) {
ret = tracing_set_clock(file->tr, hist_data->attrs->clock);
if (ret) {
hist_err(tr, HIST_ERR_SET_CLOCK_FAIL, errpos(clock));
goto out;
}The clock string is not checked anywhere before that call, so a named trigger using common_timestamp with an unknown clock fails after it has already become findable. event_hist_trigger_parse() then frees it without taking it off the list, and the next lookup by name reads the freed object:
~# cd /sys/kernel/tracing/events/sched/sched_switch
~# echo 'hist:name=foo:keys=common_pid:ts=common_timestamp:clock=bogus' > trigger
bash: echo: write error: Invalid argument
~# echo 'hist:name=foo:keys=common_pid' > trigger
BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff88800915d760 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0x900 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 63: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160
Set the clock before the trigger is registered, so that nothing which can fail runs after it is published, the way commit 6f86bdeab633 ("tracing: Fix bad hist from corrupting named_triggers list") moved the registration below the rest of the setup.
tracing_set_filter_buffering() is reference counted, so the init failure path has to drop the reference that the clock block now takes first.
[Lee: Call data->ops->init(data->ops, data) and
tracing_set_time_stamp_abs() as b052d70f7c9c ("tracing: Merge struct event_trigger_ops into struct event_command"), 476705419518 ("tracing: Remove redundant trigger_ops params") and b94bc80df648 ("tracing: Use a no_filter_buffering_ref to stop using the filter buffer") are not present]
--- kernel/trace/trace_events_hist.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/trace/trace_events_hist.c +9 -6
@@ -5510,12 +5510,6 @@ static int hist_register_trigger(char *glob, struct event_trigger_ops *ops, data->ops = &event_hist_trigger_named_ops; } -if (data->ops->init) { - ret = data->ops->init (data->ops, data); -if (ret <0 ) - goto out; - } -if (hist_data->enable_timestamps) {char *clock = hist_data->attrs->clock;
@@ -5528,6 +5522,15 @@ static int hist_register_trigger(char *glob, struct event_trigger_ops *ops,tracing_set_time_stamp_abs (file->tr, true); } +if (data->ops->init) { + ret = data->ops->init (data->ops, data); +if (ret <0 ) { +if (hist_data->enable_timestamps) +tracing_set_time_stamp_abs (file->tr, false); + goto out; + } + } +if (named_data)destroy_hist_data (hist_data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 372/516 wifi: brcmfmac: fix P2P device removal race in brcmf_detach()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michele Dionisio <[email protected]>
[ Upstream commit 08a3f02fea636e97a7422d1512f76dacdb5b0887 ]
When the driver is removed while the user space process that created the P2P device (e.g. wpa_supplicant) is still exiting, the P2P device interface is removed twice and the kernel crashes.
The two paths are:
- wpa_supplicant, on exit, sends NL80211_CMD_DEL_INTERFACE for the P2P device. nl80211_del_interface() holds RTNL and the wiphy mutex and calls brcmf_p2p_del_vif(), which disables discovery and waits up to 1.5 s for BRCMF_E_IF_DEL. Then it calls brcmf_remove_interface(), which unregisters the wdev and frees the vif and the ifp.
- brcmf_detach() sets the bus down, so BRCMF_E_IF_DEL never arrives, and calls brcmf_remove_interface(ifp, false) for the same ifp. brcmf_p2p_ifp_removed() reads ifp->vif and then blocks on rtnl_lock(). When brcmf_p2p_del_vif() releases RTNL, it calls cfg80211_unregister_wdev() on the wdev that was already unregistered and freed.
The second list_del_rcu() of wdev->list faults on LIST_POISON2:
brcmfmac: brcmf_p2p_del_vif delete P2P vif
brcmfmac: brcmf_p2p_deinit_discovery enter
brcmfmac: brcmf_p2p_del_vif P2P: GO_NEG_PHASE status cleared
brcmfmac: brcmf_detach Enter
brcmfmac: brcmf_bus_change_state 1 -> 0
brcmfmac: brcmf_remove_interface Enter, bsscfgidx=1, ifidx=0
brcmfmac: brcmf_del_if Enter, bsscfgidx=1, ifidx=0
brcmfmac: brcmf_p2p_ifp_removed P2P: device interface removed [1.5 s later, brcmf_p2p_del_vif() timed out]
brcmfmac: brcmf_remove_interface Enter, bsscfgidx=1, ifidx=0
brcmfmac: brcmf_del_if Enter, bsscfgidx=1, ifidx=0
brcmfmac: brcmf_p2p_ifp_removed P2P: device interface removed
Unable to handle kernel paging request at virtual address dead000000000122 Internal error: Oops: 96000044 [#1] PREEMPT_RT SMP pc : _cfg80211_unregister_wdev+0x6c/0x264 [cfg80211] Call trace: _cfg80211_unregister_wdev+0x6c/0x264 [cfg80211] cfg80211_unregister_wdev+0x10/0x1c [cfg80211] brcmf_p2p_ifp_removed+0x84/0xb0 [brcmfmac] brcmf_remove_interface+0x1f4/0x254 [brcmfmac] brcmf_detach+0x88/0x180 [brcmfmac] brcmf_sdio_remove+0x90/0x7b0 [brcmfmac] brcmf_sdiod_remove+0x20/0xa0 [brcmfmac] brcmf_ops_sdio_remove+0xbc/0x12c [brcmfmac] sdio_bus_remove+0x38/0x144 device_release_driver_internal+0x1e8/0x2c0 device_release_driver+0x14/0x20 brcmf_sdio_bus_remove+0x2c/0x40 [brcmfmac] brcmf_fwvid_unregister_vendor+0xd8/0x170 [brcmfmac] __exit_compat+0x18/0x418 [brcmfmac_cyw] __arm64_sys_delete_module+0x1ac/0x244
The log was taken with debug=0x406 on an i.MX 8M Plus board with a CYW55513 (Sona IF513) on SDIO. The driver is the Ezurio backport of brcmfmac from v6.18.22 on a 5.4-rt kernel. The code involved is the same in mainline.
To reproduce:
1. Start wpa_supplicant on wlan0 and let it associate. It creates the P2P device (iw dev shows "type P2P-device").
2. Stop wpa_supplicant and remove the driver without waiting for wpa_supplicant to exit:
kill $(pidof wpa_supplicant)
rmmod brcmfmac_cyw brcmfmac
The crash is reproducible on that board.
For the interface without a netdev (the P2P device), take RTNL and the wiphy mutex in brcmf_detach() before reading iflist, and remove it with locked=true. If brcmf_p2p_del_vif() runs first, brcmf_detach() finds the slot empty. If brcmf_detach() runs first, nl80211 does not find the wdev any more. The interfaces with a netdev are removed as before, because brcmf_del_if() takes RTNL on its own for the primary interface.
--- .../broadcom/brcm80211/brcmfmac/core.c | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +23 -2
@@ -1476,8 +1476,29 @@ void brcmf_detach(struct device *dev)brcmf_bus_change_state (bus_if,BRCMF_BUS_DOWN );/* make sure primary interface removed last */ for (i =BRCMF_MAX_IFS -1 ; i >-1 ; i--) { -if (drvr->iflist[i]) -brcmf_remove_interface (drvr->iflist[i], false); +struct brcmf_if *ifp = drvr->iflist[i]; + +if (!ifp) +continue ; + +if (ifp->ndev) { +brcmf_remove_interface (ifp, false); +continue ; + } + +/* The P2P device interface has no netdev. Its removal can +* race with NL80211_CMD_DEL_INTERFACE issued by a user space +* process that is exiting (e.g. wpa_supplicant), which ends +* in brcmf_p2p_del_vif() under RTNL. If +* both paths remove the interface, the wdev is unregistered +* twice and the vif is used after being freed. Take the same +* lock and re-read iflist, so only one path removes it. +*/ +rtnl_lock (); + ifp = drvr->iflist[i]; +if (ifp) +brcmf_remove_interface (ifp, true); +rtnl_unlock (); }brcmf_bus_stop (drvr->bus_if);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 373/516 selinux: fix data race on AVC latest_notif
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
[ Upstream commit 1ca924044bf0de879a1648be93a56939652267d3 ]
avc_policy_seqno() reads latest_notif without holding notif_lock, while avc_latest_notif_update() can update it under that lock. KCSAN reports these concurrent accesses during policy boolean updates and permission checks.
Use READ_ONCE() for the lockless read and WRITE_ONCE() for the update. The spinlock continues to serialize the comparison and update against other writers. Reads made while holding notif_lock cannot race with a writer and can remain plain accesses.
This marks both sides of the intentional concurrent access and constrains compiler transformations, without suppressing checking with data_race().
--- security/selinux/avc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
security/selinux/avc.c +3 -2
@@ -588,7 +588,7 @@ static int avc_latest_notif_update(struct selinux_avc *avc, } }else {if (seqno > avc->avc_cache.latest_notif) - avc->avc_cache.latest_notif = seqno; +WRITE_ONCE (avc->avc_cache.latest_notif, seqno); }spin_unlock_irqrestore (¬if_lock, flag);
@@ -1221,7 +1221,8 @@ int avc_has_perm_flags(struct selinux_state *state,u32 avc_policy_seqno (struct selinux_state *state) { -return state->avc->avc_cache.latest_notif; +/* Writers hold notif_lock; readers only sample the sequence number. */ +return READ_ONCE (state->avc->avc_cache.latest_notif); }void avc_disable (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 374/516 EDAC/amd64: Mask UMC chip select to the four implemented selects
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vishal Badole <[email protected]>
[ Upstream commit 7484bc43ba6b8e189b482db5b75e7842890a82b1 ]
For DRAM ECC errors, the chip select value can be found in the MCA_SYND[ErrorInformation] field.
ErrorInformation[2:0] was first documented in Zen1. The 3 bit field implied that up to 8 chip selects may be used.
However, all Zen-based systems have only ever had up to 4 chip selects. So only bits [1:0] would contain a valid chip select value.
Future systems are redefining the field to ErrorInformation[1:0]. This matches the existing 'up to 4 chip selects' implementations. And it frees up the extra bit for other decoding.
Change the current chip select mask from 0x7 to 0x3 to prepare for the decode change.
--- drivers/edac/amd64_edac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/edac/amd64_edac.c +1 -1
@@ -2669,7 +2669,7 @@ static void decode_umc_error(int node_id, struct mce *m) err.err_code =ERR_CHANNEL ; } - err.csrow = m->synd &0x7 ; + err.csrow = m->synd &0x3 ;if (umc_normaddr_to_sysaddr (m->addr, pvt->mc_node_id, err.channel, &sys_addr)) { err.err_code =ERR_NORM_ADDR ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/516 mm/mremap: fix locked_vm leak by splitting VMA for MREMAP_DONTUNMAP
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 597e4b9ab48a3f841080f627722064853d3f650e ]
The MREMAP_DONTUNMAP feature is highly unusual in that it permits mremap() operations that keep the original VMA in place.
Historically this has led to a lot of bugs where non-obvious interactions occur between existing mremap() operations and the original VMA.
Fix another of these - partial copies.
The long-standing mremap() partial VMA logic has the baked-in assumption that the originating VMA is unmapped and thus moved.
However MREMAP_DONTUNMAP defeats this by performing a partial copy instead since it keeps the source VMA around.
An mremap(..., MREMAP_DONTUNMAP) operation disallows resizing of the VMA, but the operation can be performed partially:
|-----------------|
| |
| v
<------> <------>
.new_sz. new_sz
|--.------.--| |------|
| .source. | | dest |
|--.------.--| |------|
<------------>
old_szThe page tables in the specified range are moved, but the original VMA is kept intact.
This interacts poorly with mlock()'d VMAs, as the VMA_LOCKED_BIT flag is cleared for the entire source VMA and set for the entire destination VMA.
This results in an mm->locked_vm leak as the change is therefore not accounted correctly.
The clear solution here is to make the portion of the source VMA which is mremap()'d distinct from the rest of it, a.k.a. split it.
Therefore resolve this issue by splitting it ahead of the rest of the mremap() operation if the VMA is mlock()'d.
This is valid, as the source VMA will lose its VMA_LOCKED_BIT flag, so if a partial remap it will become distinct from the rest of the VMA.
In order to make this change re-expose split_vma() in vma.h for CONFIG_MMU (nommu doesn't compile mremap.c and uses a static helper instead).
Finally, update the sys_map_count check to account for this case.
Note that the early check does not use needs_pre_split() - this is because the VMA has not been looked up by this point, so be conservative and assume that the VMA is mlock()'d in this case for the purposes of the sys_map_count check.
--- mm/mremap.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
mm/mremap.c +13 -0
@@ -366,6 +366,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,if (err)return err; +/* +* To account mlock()'d pages correctly in the MREMAP_DONTUNMAP +* case perform any split ahead of time for an mlock()'d VMA. +*/ +if ((flags &MREMAP_DONTUNMAP ) && (vma->vm_flags &VM_LOCKED )) { +if (vma->vm_start != old_addr) + err =split_vma (mm, vma, old_addr,1 ); +if (!err && vma->vm_end != old_addr + old_len) + err =split_vma (mm, vma, old_addr + old_len,0 ); +if (err) +return err; + } + new_pgoff = vma->vm_pgoff + ((old_addr - vma->vm_start) >>PAGE_SHIFT ); new_vma =copy_vma (&vma, new_addr, new_len, new_pgoff, &need_rmap_locks);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/516 mm/mremap: fix locked_vm leak from MREMAP_DONTUNMAP self-merge
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 838bb60dc21553e32df90f2f3bac5b905376e7aa ]
The MREMAP_DONTUNMAP feature is highly unusual in that it permits mremap() operations that keep the original VMA in place.
Historically this has led to a lot of bugs where non-obvious interactions occur between existing mremap() operations and the original VMA.
Fix another of these - self-merge.
Self-merge occurs when a VMA is moved in front of or behind itself and the attributes of the VMA permit such a merge.
Practically this can only happen for unfaulted anonymous VMAs due to the page offset equality requirement for merge:
|------------|
| |
| v
|...........||-----------||...........|
| || unfaulted || |
|...........||-----------||...........|
^ |
| |
|------------|This becomes problematic if the VMA is configured by the user to mlock-on-fault, i.e. the VMA_LOCKED_BIT, VMA_LOCKONFAULT_BIT VMA flags are set.
MREMAP_DONTUNMAP clears mlock flags for the source VMA and maintains them for the destination VMA.
Self-merge makes this impossible (there is only one VMA) and incorrectly clears the destination VMA's mlock flags.
This causes a leak in mm->locked_vm as clearing this flag does not decrement the counter and the VMA no longer has VMA_LOCKED_BIT set so it is not decremented on unmap.
Resolve this by simply disallowing a self-merge in this case - the source and destination VMAs are kept distinct and then are able to have distinct mlock() flags.
Update to make the now-redundant self-merge check a VM_WARN_ON_ONCE() instead to guard against future regressions.
[ ljs - Converted to work with vma_merge(), tweaked commit msg, removed
redundant self-merge code and comment. ]
--- include/linux/mm.h | 2 +- mm/mmap.c | 23 +++++++++++++++++++---- mm/mremap.c | 16 ++++------------ 3 files changed, 24 insertions(+), 17 deletions(-)
include/linux/mm.h +1 -1
@@ -2562,7 +2562,7 @@ extern void __vma_link_rb(struct mm_struct *, struct vm_area_struct *,extern void unlink_file_vma (struct vm_area_struct *);extern struct vm_area_struct *copy_vma (struct vm_area_struct **,unsigned long addr,unsigned long len,pgoff_t pgoff, -bool *need_rmap_locks); +bool *need_rmap_locks,bool keep_source);extern void exit_mmap (struct mm_struct *); static inline int check_data_rlimit(unsigned long rlim,
mm/mmap.c +19 -4
@@ -3330,7 +3330,7 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)*/ struct vm_area_struct *copy_vma (struct vm_area_struct **vmap,unsigned long addr,unsigned long len,pgoff_t pgoff, -bool *need_rmap_locks) +bool *need_rmap_locks,bool keep_source) {struct vm_area_struct *vma = *vmap;unsigned long vma_start = vma->vm_start;
@@ -3338,6 +3338,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,struct vm_area_struct *new_vma, *prev;struct rb_node **rb_link, *rb_parent;bool faulted_in_anon_vma = true; +bool can_self_merge = false;/* * If anonymous vma has not yet been faulted, update new pgoff
@@ -3346,13 +3347,27 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,if (unlikely (vma_is_anonymous (vma) && !vma->anon_vma)) { pgoff = addr >>PAGE_SHIFT ; faulted_in_anon_vma = false; + can_self_merge = true; }if (find_vma_links (mm, addr, addr + len, &prev, &rb_link, &rb_parent))return NULL ;/* should never get here */ - new_vma =vma_merge (mm, prev, addr, addr + len, vma->vm_flags, - vma->anon_vma, vma->vm_file, pgoff,vma_policy (vma), - vma->vm_userfaultfd_ctx); + +/* +* If the original VMA is kept (MREMAP_DONTUNMAP), the source and +* destination VMA must be treated distinctly. +* +* A merge violates this, so in this case disallow a self-merge. A +* self-merge can only occur if the new range is immediately adjacent to +* the source VMA, so simply do not attempt to merge in that case. +*/ +if (can_self_merge && keep_source && + (addr == vma->vm_end || vma->vm_start == addr + len)) + new_vma =NULL ; +else + new_vma =vma_merge (mm, prev, addr, addr + len, vma->vm_flags, + vma->anon_vma, vma->vm_file, pgoff, +vma_policy (vma), vma->vm_userfaultfd_ctx);if (new_vma) {/* * Source vma may have been merged into new_vma
mm/mremap.c +4 -12
@@ -381,7 +381,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, new_pgoff = vma->vm_pgoff + ((old_addr - vma->vm_start) >>PAGE_SHIFT ); new_vma =copy_vma (&vma, new_addr, new_len, new_pgoff, - &need_rmap_locks); + &need_rmap_locks, flags &MREMAP_DONTUNMAP );if (!new_vma)return -ENOMEM ;
@@ -437,6 +437,9 @@ static unsigned long move_vma(struct vm_area_struct *vma,untrack_pfn_moved (vma);if (unlikely (!err && (flags &MREMAP_DONTUNMAP ))) { +/* Self-merge is disallowed. */ +VM_WARN_ON_ONCE (new_vma == vma); +if (vm_flags &VM_ACCOUNT ) {/* Always put back VM_ACCOUNT since we won't unmap */ vma->vm_flags |=VM_ACCOUNT ;
@@ -444,17 +447,6 @@ static unsigned long move_vma(struct vm_area_struct *vma,vm_acct_memory (new_len >>PAGE_SHIFT ); } -/* -* VMAs can actually be merged back together in copy_vma -* calling merge_vma. This can happen with anonymous vmas -* which have not yet been faulted, so if we were to consider -* this VMA split we'll end up adding VM_ACCOUNT on the -* next VMA, which is completely unrelated if this VMA -* was re-merged. -*/ -if (split && new_vma == vma) - split =0 ; -/* We always clear VM_LOCKED[ONFAULT] on the old vma */ vma->vm_flags &=VM_LOCKED_CLEAR_MASK ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/516 netfilter: nf_tables: fix bidirectional offload regression
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 84443741faab9045d53f022a9ac6a6633067a481 ]
Commit 8f84780b84d6 ("netfilter: flowtable: allow unidirectional rules") made unidirectional flow offload possible, while completely ignoring (and breaking) bidirectional flow offload for nftables.
Add the missing flag that was left out as an exercise for the reader :)
--- net/netfilter/nft_flow_offload.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nft_flow_offload.c +1 -0
@@ -127,6 +127,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, ct->proto.tcp.seen[1 ].flags |=IP_CT_TCP_FLAG_BE_LIBERAL ; } +__set_bit (NF_FLOW_HW_BIDIRECTIONAL , &flow->flags); ret =flow_offload_add (flowtable, flow);if (ret <0 ) goto err_flow_add;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/516 net: bridge: avoid recursive multicast port cleanup
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zixuan Chai <[email protected]>
[ Upstream commit 5158353121bae4f552cb677ce8c5c3ef52f93a0d ]
br_multicast_sg_del_exclude_ports() removes automatically added STAR_EXCL port groups by calling br_multicast_del_pg(). For S,G entries, that deletion calls back into br_multicast_sg_del_exclude_ports(), so a large number of STAR_EXCL ports consumes one kernel stack frame per port and can hit the stack guard page.
Keep the complete port-group deletion path for cleanup, but suppress the S,G exclude-port cleanup while that helper is already walking the same entry. Normal deletion callers retain the existing behavior.
--- net/bridge/br_multicast.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
net/bridge/br_multicast.c +18 -5
@@ -76,6 +76,10 @@ __br_multicast_add_group(struct net_bridge *br, bool blocked);static void br_multicast_find_del_pg (struct net_bridge *br,struct net_bridge_port_group *pg); +static void __br_multicast_del_pg (struct net_bridge_mdb_entry *mp, +struct net_bridge_port_group *pg, +struct net_bridge_port_group __rcu **pp, +bool sg_del_exclude_ports);static struct net_bridge_port_group * br_sg_port_find(struct net_bridge *br,
@@ -361,7 +365,7 @@ static void br_multicast_sg_del_exclude_ports(struct net_bridge_mdb_entry *sgmp)for (pp = &sgmp->ports; (p =mlock_dereference (*pp, sgmp->br)) !=NULL ;) {if (!(p->flags &MDB_PG_FLAGS_PERMANENT )) -br_multicast_del_pg (sgmp, p, pp); +__br_multicast_del_pg (sgmp, p, pp, false);else pp = &p->next; }
@@ -582,9 +586,10 @@ static void br_multicast_destroy_port_group(struct net_bridge_mcast_gc *gc)kfree_rcu (pg, rcu); } -void br_multicast_del_pg (struct net_bridge_mdb_entry *mp, -struct net_bridge_port_group *pg, -struct net_bridge_port_group __rcu **pp) +static void __br_multicast_del_pg (struct net_bridge_mdb_entry *mp, +struct net_bridge_port_group *pg, +struct net_bridge_port_group __rcu **pp, +bool sg_del_exclude_ports) {struct net_bridge *br = pg->key.port->br;struct net_bridge_group_src *ent;
@@ -598,7 +603,8 @@ void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,if (!br_multicast_is_star_g (&mp->addr)) {rhashtable_remove_fast (&br->sg_port_tbl, &pg->rhnode, br_sg_port_rht_params); -br_multicast_sg_del_exclude_ports (mp); +if (sg_del_exclude_ports) +br_multicast_sg_del_exclude_ports (mp); }else {br_multicast_star_g_handle_mode (pg,MCAST_INCLUDE ); }
@@ -609,6 +615,13 @@ void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,mod_timer (&mp->timer, jiffies); } +void br_multicast_del_pg (struct net_bridge_mdb_entry *mp, +struct net_bridge_port_group *pg, +struct net_bridge_port_group __rcu **pp) +{ +__br_multicast_del_pg (mp, pg, pp, true); +} +static void br_multicast_find_del_pg (struct net_bridge *br,struct net_bridge_port_group *pg) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/516 net: team: Remove unused team_mode_op, port_enabled
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Harvey <[email protected]>
[ Upstream commit 014f249121d73909528df320818fba7693d0ec92 ]
This team_mode_op wasn't used by any of the team modes, so remove it.
Stable-dep-of: b7454f1940c5 ("net: team: stop reusing skb after queue override")
--- drivers/net/team/team.c | 2 -- include/linux/if_team.h | 1 - 2 files changed, 3 deletions(-)
drivers/net/team/team.c +0 -2
@@ -939,8 +939,6 @@ static void team_port_enable(struct team *team, team_port_index_hash(team, port->index));team_adjust_ops (team);team_queue_override_port_add (team, port); -if (team->ops.port_enabled) - team->ops.port_enabled (team, port);team_notify_peers (team);team_mcast_rejoin (team);team_lower_state_changed (port);
include/linux/if_team.h +0 -1
@@ -121,7 +121,6 @@ struct team_mode_ops {int (*port_enter)(struct team *team,struct team_port *port);void (*port_leave)(struct team *team,struct team_port *port);void (*port_change_dev_addr)(struct team *team,struct team_port *port); -void (*port_enabled)(struct team *team,struct team_port *port);void (*port_disabled)(struct team *team,struct team_port *port); };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/516 net: team: Rename port_disabled team mode op to port_tx_disabled
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Harvey <[email protected]>
[ Upstream commit cfa477df2cc62ba53cb936669886361152b594a7 ]
This team mode op is only used by the load balance mode, and it only uses it in the tx path.
Stable-dep-of: b7454f1940c5 ("net: team: stop reusing skb after queue override")
--- drivers/net/team/team.c | 4 ++-- drivers/net/team/team_mode_loadbalance.c | 4 ++-- include/linux/if_team.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/team/team.c +2 -2
@@ -963,8 +963,8 @@ static void team_port_disable(struct team *team, {if (!team_port_enabled (port))return ; -if (team->ops.port_disabled) - team->ops.port_disabled (team, port); +if (team->ops.port_tx_disabled) + team->ops.port_tx_disabled (team, port);hlist_del_rcu (&port->hlist);__reconstruct_port_hlist (team, port->index); port->index =-1 ;
drivers/net/team/team_mode_loadbalance.c +2 -2
@@ -672,7 +672,7 @@ static void lb_port_leave(struct team *team, struct team_port *port)free_percpu (lb_port_priv->pcpu_stats); } -static void lb_port_disabled (struct team *team,struct team_port *port) +static void lb_port_tx_disabled (struct team *team,struct team_port *port) {lb_tx_hash_to_port_mapping_null_port (team, port); }
@@ -682,7 +682,7 @@ static const struct team_mode_ops lb_mode_ops = { .exit = lb_exit, .port_enter = lb_port_enter, .port_leave = lb_port_leave, - .port_disabled = lb_port_disabled, + .port_tx_disabled = lb_port_tx_disabled, .receive = lb_receive, .transmit = lb_transmit, };
include/linux/if_team.h +1 -1
@@ -121,7 +121,7 @@ struct team_mode_ops {int (*port_enter)(struct team *team,struct team_port *port);void (*port_leave)(struct team *team,struct team_port *port);void (*port_change_dev_addr)(struct team *team,struct team_port *port); -void (*port_disabled)(struct team *team,struct team_port *port); +void (*port_tx_disabled)(struct team *team,struct team_port *port); };extern int team_modeop_port_enter (struct team *team,struct team_port *port);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/516 net: team: fix NULL pointer dereference in team_xmit during mode change
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 25fe708bbc59289d3d1ea4b126fbc1b460a072a5 ]
__team_change_mode() clears team->ops with memset() before restoring safe dummy handlers via team_adjust_ops(). A concurrent team_xmit() running under RCU on another CPU can read team->ops.transmit during this window and call a NULL function pointer, crashing the kernel.
The race requires a mode change (CAP_NET_ADMIN) concurrent with transmit on the team device.
BUG: kernel NULL pointer dereference, address: 0000000000000000 Oops: 0010 [#1] SMP KASAN NOPTI RIP: 0010:0x0 Call Trace: team_xmit (drivers/net/team/team_core.c:1853) dev_hard_start_xmit (net/core/dev.c:3904) __dev_queue_xmit (net/core/dev.c:4871) packet_sendmsg (net/packet/af_packet.c:3109) __sys_sendto (net/socket.c:2265)
The original code assumed that no ports means no traffic, so mode changes could freely memset()/memcpy() the ops. AF_PACKET with forced carrier breaks that assumption.
Prevent the race instead of making it safe: replace memset()/memcpy() with per-field updates that never touch transmit or receive. Those two handlers are managed solely by team_adjust_ops(), which already installs dummies when tx_en_port_count == 0 (always true during mode change since no ports are present). WRITE_ONCE/READ_ONCE prevent store/load tearing on the handler pointers.
synchronize_net() before exit_op() drains in-flight readers that may still reference old mode state from before port removal switched the handlers to dummies.
Stable-dep-of: b7454f1940c5 ("net: team: stop reusing skb after queue override")
--- drivers/net/team/team.c | 45 +++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-)
drivers/net/team/team.c +32 -13
@@ -534,21 +534,23 @@ static void team_adjust_ops(struct team *team)if (!team->en_port_count || !team_is_mode_set (team) || !team->mode->ops->transmit) - team->ops.transmit = team_dummy_transmit; +WRITE_ONCE (team->ops.transmit, team_dummy_transmit);else - team->ops.transmit = team->mode->ops->transmit; +WRITE_ONCE (team->ops.transmit, team->mode->ops->transmit);if (!team->en_port_count || !team_is_mode_set (team) || !team->mode->ops->receive) - team->ops.receive = team_dummy_receive; +WRITE_ONCE (team->ops.receive, team_dummy_receive);else - team->ops.receive = team->mode->ops->receive; +WRITE_ONCE (team->ops.receive, team->mode->ops->receive); }/* -* We can benefit from the fact that it's ensured no port is present -* at the time of mode change. Therefore no packets are in fly so there's no -* need to set mode operations in any special way. +* team_change_mode() ensures no ports are present during mode change, +* but lockless readers can still reach team_xmit(). Avoid touching +* transmit/receive -- they are already set to dummies by +* team_adjust_ops() since no ports are enabled. synchronize_net() +* drains in-flight readers before destroying old mode state. */ static int __team_change_mode (struct team *team,const struct team_mode *new_mode)
@@ -557,9 +559,21 @@ static int __team_change_mode(struct team *team,if (team_is_mode_set (team)) {void (*exit_op)(struct team *team) = team->ops.exit; -/* Clear ops area so no callback is called any longer */ -memset (&team->ops,0 ,sizeof (struct team_mode_ops )); -team_adjust_ops (team); +/* Clear cold-path ops used only under RTNL. transmit and +* receive are already dummies (no ports) so leave them +* alone -- overwriting them is the source of the race. +*/ + team->ops.init =NULL ; + team->ops.exit =NULL ; + team->ops.port_enter =NULL ; + team->ops.port_leave =NULL ; + team->ops.port_change_dev_addr =NULL ; + team->ops.port_tx_disabled =NULL ; + +/* Wait for in-flight readers before tearing down mode +* state they may reference. +*/ +synchronize_net ();if (exit_op)exit_op (team);
@@ -582,7 +596,12 @@ static int __team_change_mode(struct team *team, } team->mode = new_mode; -memcpy (&team->ops, new_mode->ops,sizeof (struct team_mode_ops )); + team->ops.init = new_mode->ops->init; + team->ops.exit = new_mode->ops->exit; + team->ops.port_enter = new_mode->ops->port_enter; + team->ops.port_leave = new_mode->ops->port_leave; + team->ops.port_change_dev_addr = new_mode->ops->port_change_dev_addr; + team->ops.port_tx_disabled = new_mode->ops->port_tx_disabled;team_adjust_ops (team);return 0 ;
@@ -738,7 +757,7 @@ static rx_handler_result_t team_handle_frame(struct sk_buff **pskb)/* allow exact match delivery for disabled ports */ res =RX_HANDLER_EXACT ; }else { - res = team->ops.receive (team, port, skb); + res =READ_ONCE (team->ops.receive)(team, port, skb); }if (res ==RX_HANDLER_ANOTHER ) {struct team_pcpu_stats *pcpu_stats;
@@ -1736,7 +1755,7 @@ static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev) tx_success =team_queue_override_transmit (team, skb);if (!tx_success) - tx_success = team->ops.transmit (team, skb); + tx_success =READ_ONCE (team->ops.transmit)(team, skb);if (tx_success) {struct team_pcpu_stats *pcpu_stats;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/516 net: team: stop reusing skb after queue override
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit b7454f1940c5e6d92e753853c476a769e452f30a ]
A nonzero dev_queue_xmit() result does not return ownership of the skb. When an override port's qdisc drops it, the queue override helper used to try another port or the mode transmit op with the freed skb.
Return the handoff decision separately from transmit success. Select only the first override port under RCU and stop after handing it the skb, regardless of the lower transmit result. Keep the existing success and drop accounting.
BUG: KASAN: slab-use-after-free in sk_skb_reason_drop Write of size 4 by task poc/5040 sk_skb_reason_drop (net/core/skbuff.c:1240) dev_kfree_skb_any_reason (net/core/dev.c:3470) ab_transmit (drivers/net/team/team_mode_activebackup.c:49) team_xmit (drivers/net/team/team_core.c:1849) __dev_direct_xmit (net/core/dev.c:4934) Freed by task 5040: __tcf_kfree_skb_list (net/sched/sch_generic.c:43) __dev_queue_xmit (net/core/dev.c:4831) team_xmit (drivers/net/team/team_core.c:1846) Kernel panic - not syncing: KASAN: panic_on_warn set ...
--- drivers/net/team/team.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/team/team.c +8 -8
@@ -816,7 +816,8 @@ static struct list_head *__team_get_qom_list(struct team *team, u16 queue_id)/* * note: already called with rcu_read_lock */ -static bool team_queue_override_transmit (struct team *team,struct sk_buff *skb) +static bool team_queue_override_transmit (struct team *team,struct sk_buff *skb, +bool *tx_success) {struct list_head *qom_list;struct team_port *port;
@@ -824,11 +825,11 @@ static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb)if (!team->queue_override_enabled || !skb->queue_mapping)return false; qom_list =__team_get_qom_list (team, skb->queue_mapping); -list_for_each_entry_rcu (port, qom_list, qom_list) { -if (!team_dev_queue_xmit (team, port, skb)) -return true; - } -return false; + port = list_first_or_null_rcu(qom_list, struct team_port, qom_list); +if (!port) +return false; + *tx_success = !team_dev_queue_xmit (team, port, skb); +return true; } static void __team_queue_override_port_del(struct team *team,
@@ -1753,8 +1754,7 @@ static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev)bool tx_success;unsigned int len = skb->len; - tx_success =team_queue_override_transmit (team, skb); -if (!tx_success) +if (!team_queue_override_transmit (team, skb, &tx_success)) tx_success =READ_ONCE (team->ops.transmit)(team, skb);if (tx_success) {struct team_pcpu_stats *pcpu_stats;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/516 Bluetooth: RFCOMM: connect the session socket without rfcomm_mutex
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Gavrilov <[email protected]>
[ Upstream commit ac022970e9fb0a5f7e7d1f6c8e104c1ed924dd1c ]
An RFCOMM connect() issued while a BR/EDR link is being authenticated makes lockdep report a circular dependency, and the reported cycle is a real AB/BA between rfcomm_mutex and hdev->lock.
rfcomm_security_cfm() is called from the HCI event path, which already holds hdev->lock:
hci_rx_work()
hci_event_packet()
hci_cc_read_enc_key_size() [hdev->lock]
hci_encrypt_cfm() [hci_cb_list_lock]
rfcomm_security_cfm() [rfcomm_mutex]while an RFCOMM connect() from userspace takes the same two locks the other way round:
rfcomm_sock_connect()
rfcomm_dlc_open() [rfcomm_mutex]
__rfcomm_dlc_open()
rfcomm_session_create()
kernel_connect()
l2cap_sock_connect()
l2cap_chan_connect() [hdev->lock] WARNING: possible circular locking dependency detected kworker/u131:1/1128 is trying to acquire lock:
rfcomm_mutex, at: rfcomm_security_cfm+0x31/0x3e0 [rfcomm] but task is already holding lock:
hci_cb_list_lock, at: hci_cc_read_enc_key_size+0x1d2/0xcc0
Chain exists of:
rfcomm_mutex --> &hdev->lock --> hci_cb_list_lockhci_auth_complete_evt() and hci_encrypt_change_evt() reach the callback the same way.
Both orders have to be seen in the same boot, which is why a BR/EDR connection alone is not enough to show it: a session set up by the remote side is created by rfcomm_accept_connection() in krfcommd, which calls kernel_accept() and never takes hdev->lock under rfcomm_mutex. Connecting a device that authenticates and encrypts the link and then calling connect() on an RFCOMM socket towards any address - the connect does not have to succeed, the order is recorded before the page timeout
- reports it every time.
Only the session socket has to be connected with the lock held, and it does not: nothing else can see the socket before it is put on the session list. So connect it first and take rfcomm_mutex afterwards, which removes the rfcomm_mutex -> hdev->lock order for good, rather than keeping the HCI event path out of rfcomm_mutex.
rfcomm_session_create() becomes rfcomm_session_connect(), which returns the connected socket without touching the session list, and rfcomm_dlc_open() adds the session once it holds the lock again. If another opener added a session for the same pair while this socket was connecting, that session is used and this socket is dropped. __rfcomm_dlc_open() now takes the session it should use, and its state check runs after the lock is re-acquired, so a DLC that was opened or closed in the meantime is still handled.
Over an existing ACL link the connection can complete before the session reaches the list, and the wakeup from the socket callback is then lost, so krfcommd is woken once the session is visible.
Connecting without the lock opens a window in which the socket can be closed. The DLC is not on a session yet, so rfcomm_dlc_close() finds nothing to do and returns without touching it, and rfcomm_dlc_open() would then attach a DLC whose owner is gone. rfcomm_dlc_close() now marks such a DLC with RFCOMM_CLOSED, and rfcomm_dlc_open() checks the mark once it holds rfcomm_mutex again and drops the socket instead of attaching the DLC. The mark is cleared when an open starts, so a DLC that is reused is not affected. This covers both callers of rfcomm_dlc_open(), the socket and the tty layer.
--- include/net/bluetooth/rfcomm.h | 1 + net/bluetooth/rfcomm/core.c | 134 +++++++++++++++++++++++---------- 2 files changed, 96 insertions(+), 39 deletions(-)
include/net/bluetooth/rfcomm.h +1 -0
@@ -210,6 +210,7 @@ struct rfcomm_dlc {#define RFCOMM_AUTH_REJECT 7#define RFCOMM_DEFER_SETUP 8#define RFCOMM_ENC_DROP 9 +#define RFCOMM_CLOSED 10/* Scheduling flags and events */ #define RFCOMM_SCHED_WAKEUP 31
net/bluetooth/rfcomm/core.c +95 -39
191 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/516 drm/vmwgfx: validate pitch coming from userspace
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zack Rusin <[email protected]>
[ Upstream commit 21bc51cb89ced74d6645a138cc2f21184bc75094 ]
Validate the pitch, alongside the box dimensions before trying to copy data from the underlying surface. Fixes possible out of bounds reads with cursor snooping.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +18 -4
@@ -151,6 +151,7 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,unsigned long kmap_num;SVGA3dCopyBox *box;unsigned box_count; +u64 src_extent;void *virtual;bool dummy;struct vmw_dma_cmd {
@@ -159,6 +160,8 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, } *cmd;int i, ret; +BUILD_BUG_ON (sizeof (*srf->snooper.image) !=4 ); + cmd = container_of(header, struct vmw_dma_cmd, header);/* No snooper installed */
@@ -196,8 +199,19 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,return ; } +if (box->w ==0 || box->h ==0 ) +return ; + + src_extent = (u64)(box->h -1 ) * cmd->dma.guest.pitch + + (u64 )box->w *4 ; +if (src_extent > ((size_t )bo->num_pages <<PAGE_SHIFT )) { +DRM_ERROR ("Cursor snoop source of %llu bytes exceeds the %zu byte buffer\n" , + src_extent, (size_t )bo->num_pages <<PAGE_SHIFT ); +return ; + } + kmap_offset = cmd->dma.guest.ptr.offset >>PAGE_SHIFT ; - kmap_num = (64 *64 *4 ) >>PAGE_SHIFT ; + kmap_num =PFN_UP (src_extent); ret =ttm_bo_reserve (bo, true, false,NULL );if (unlikely (ret !=0 )) {
@@ -211,13 +225,13 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf, virtual =ttm_kmap_obj_virtual (&map, &dummy); -if (box->w ==64 && cmd->dma.guest.pitch ==64 *4 ) { +if (box->w ==64 && box->h ==64 && cmd->dma.guest.pitch ==64 *4 ) {memcpy (srf->snooper.image, virtual,64 *64 *4 ); }else { -/* Image is unsigned pointer. */ +/* The destination stride is in pixels. */ for (i =0 ; i < box->h; i++)memcpy (srf->snooper.image + i *64 , - virtual + i * cmd->dma.guest.pitch, + virtual + (size_t )i * cmd->dma.guest.pitch, box->w *4 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/516 namespace: dont inherit MNT_UMOUNT in clone_mnt()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit e2c6d326216642011da318b9edfd5d57ebd5a56f ]
MNT_UMOUNT gets raised on a mount that umount_tree() or umount_one() has taken out of its namespace. It's never cleared. __detach_mounts() unhooks a mount that carries it instead of unmounting it.
disconnect_mount() lets an unmounted child stay attached only if its parent carries it. propagate_umount() takes it as the sign that a mount is going to be unmounted when it decides what else can be unmounted, where a chain of locked mounts ends and where a for reparenting an overmount.
clone_mnt() copies the flags of the source and only masks MNT_INTERNAL_FLAGS which doesn't include MNT_UMOUNT. A mount that was lazily unmounted but is kept alive by a file descriptor can still be copied when its root is an nsfs or pidfs file because may_copy_tree() accepts those before checking whether the source is mounted at all:
mount --bind /proc/self/ns/net /tmp/x exec 3< /tmp/x umount -l /tmp/x mount --bind /proc/self/fd/3 /tmp/y
The mount on /tmp/y is attached to the caller's namespace with MNT_UMOUNT already set and every copy of it inherits the flag again.
That causes a number of bugs:
- Unlink its mountpoint from a mount namespace where it isn't one. __detach_mounts() takes it for a mount that was unmounted earlier, unhooks it from its parent and drops the reference the namespace holds on it. It stays in the namespace with one reference too few and as its own parent, so it can't be unmounted through the file descriptor anymore and the namespace never finds it again. When the namespace goes away it's leaked and points to a freed struct mnt_namespace that may_change_propagation() and anon_ns_root() read on the next propagation change or mount_setattr() through the file descriptor.
- Make it shared and unmount a peer. trace_transfers() follows the flag from the peer into it and strips it from its peer group.
- Let a propagated umount reach it. gather_candidates() marks it with T_UMOUNT_CANDIDATE but never puts it on the candidate list, so the mark is never cleared and every later propagated umount skips it. If it's the parent of a locked mount handle_locked() takes it as the cutoff and commits the locked child that should have stayed and disconnect_mount() leaves that child attached to it, unmounted under a mounted parent, which is what disconnect_mount() exists to prevent. When the namespace goes away umount_tree() visits the child a second time. And once __detach_mounts() has made it its own parent reparent() never finds the end of the chain of unmounted parents.
A clone is a new mount that has never been unmounted. Add MNT_UMOUNT to MNT_INTERNAL_FLAGS so clone_mnt() never copies it. And warn when umount_tree() reaches a mount that already has it set.
--- fs/namespace.c | 4 +++- include/linux/mount.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
fs/namespace.c +3 -1
@@ -1057,7 +1057,7 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root, } mnt->mnt.mnt_flags = old->mnt.mnt_flags; - mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD |MNT_MARKED |MNT_INTERNAL ); + mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD |MNT_MARKED |MNT_INTERNAL |MNT_UMOUNT );atomic_inc (&sb->s_active); mnt->mnt.mnt_sb = sb;
@@ -1492,6 +1492,8 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)/* Gather the mounts to umount */ for (p = mnt; p; p =next_mnt (p, mnt)) { +/* A mount is unmounted once. */ +WARN_ON_ONCE (p->mnt.mnt_flags &MNT_UMOUNT ); p->mnt.mnt_flags |=MNT_UMOUNT ;list_move (&p->mnt_list, &tmp_list); }
include/linux/mount.h +1 -1
@@ -52,7 +52,7 @@ struct fs_context;#define MNT_INTERNAL_FLAGS (MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL | \ MNT_DOOMED | MNT_SYNC_UMOUNT | MNT_MARKED | \ - MNT_CURSOR) + MNT_CURSOR | MNT_UMOUNT)#define MNT_INTERNAL 0x4000
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/516 namespace: check the mounts before reading their parents in pivot_root()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 6b7c001eb5857fa09041f47673666060a2e5fc1c ]
path_pivot_root() reads the parents of new_root and of the caller's root and checks whether they are shared before it checks that either mount is in the caller's mount namespace. Only namespace_sem is held. That's fine for a mount that is in the caller's mount namespace.
But new_root can be a file descriptor to a mount that has been unmounted and that only the file descriptor keeps alive. If that mount stayed attached to its parent when it was unmounted nothing pins the parent for it. The final mntput() of the parent unhooks the children under mount_lock alone and frees the parent afterwards:
pivot_root() close(fd), last ref on the parent
------------ ---------------------------------
ex_parent = new_mnt->mnt_parent
mntput_no_expire_slowpath()
__umount_mnt(new_mnt)
cleanup_mnt()
call_rcu() IS_MNT_SHARED(ex_parent)
BUG: KASAN: slab-use-after-free in path_pivot_root+0xf1a/0x1840 Read of size 4 at addr ffff8881047382f8 by task pivot_widen/157 path_pivot_root+0xf1a/0x1840 __x64_sys_pivot_root+0x165/0x190
The same goes for the caller's root via chroot(). Both outcomes of the check end in EINVAL so nothing but the read itself goes wrong. It's the same thing commit bb4609405752 ("statmount: read the parent of an unmounted mount under mount_lock") fixed for statmount().
Check that both mounts are in the caller's namespace before their parents are read. Every path returns EINVAL either way.
--- fs/namespace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/namespace.c +3 -2
@@ -3886,14 +3886,15 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, new_mnt =real_mount (new.mnt); root_mnt =real_mount (root.mnt); old_mnt =real_mount (old.mnt); +/* only a mounted mount has a parent that namespace_sem pins */ +if (!check_mnt (root_mnt) || !check_mnt (new_mnt)) + goto out4; ex_parent = new_mnt->mnt_parent; root_parent = root_mnt->mnt_parent;if (IS_MNT_SHARED (old_mnt) ||IS_MNT_SHARED (ex_parent) ||IS_MNT_SHARED (root_parent)) goto out4; -if (!check_mnt (root_mnt) || !check_mnt (new_mnt)) - goto out4;if (new_mnt->mnt.mnt_flags &MNT_LOCKED ) goto out4; error = -ENOENT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/516 highmem: round down the address passed to kunmap_flush_on_unmap()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
commit 88d7b12068b95731c280af8ce88e8ee9561f96de upstream.
We already round down the address in kunmap_local_indexed() which is the other implementation of __kunmap_local(). The only implementation of kunmap_flush_on_unmap() is PA-RISC which is expecting a page-aligned address. This may be causing PA-RISC to be flushing the wrong addresses currently.
[ 5.10 has no include/linux/highmem-internal.h and no
kmap_local API, so __kunmap_local() does not exist. Therefore, I applied the __kunmap_atomic() hunk to include/linux/highmem.h ]
--- include/linux/highmem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/highmem.h +1 -1
@@ -218,7 +218,7 @@ static inline void __kunmap_atomic(void *addr)* handles re-enabling faults and preemption */ #ifdef ARCH_HAS_FLUSH_ON_KUNMAP -kunmap_flush_on_unmap (addr); +kunmap_flush_on_unmap (PTR_ALIGN_DOWN (addr,PAGE_SIZE ));#endif }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/516 dm: fix reading free memory in do_resume
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit c9417c1c5269e2bd0570fbe53e4ec03a8d31f008 ]
When do_resume calls dm_table_get_mode(new_map), the call is done without holding any locks (it only holds a reference to the md). It may be possible that another concurrent ioctl on the same device will swap table after dm_swap_table and before dm_table_get_mode. In this case, dm_table_get_mode(new_map) reads freed memory.
This race condition was triggered by syzbot.
This commit fixes the race by reading mode of the new table before dm_swap_table. Note that new_map is also passed to dm_ima_need_measure, but this function doesn't attempt to dereference it, so this call should be safe.
Note that this is not a security bug because only root can trigger it and the commonly used tools such as lvm or cryptsetup do not call the ioctls concurrently, so that they can't trigger it acceidentally.
--- drivers/md/dm-ioctl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/dm-ioctl.c +4 -1
@@ -1065,6 +1065,8 @@ static int do_resume(struct dm_ioctl *param)/* Do we need to load a new map ? */ if (new_map) { +fmode_t new_map_mode; +/* Suspend if it isn't already suspended */ if (param->flags &DM_SKIP_LOCKFS_FLAG ) suspend_flags &= ~DM_SUSPEND_LOCKFS_FLAG ;
@@ -1091,6 +1093,7 @@ static int do_resume(struct dm_ioctl *param) } } + new_map_mode =dm_table_get_mode (new_map); old_map =dm_swap_table (md, new_map);if (IS_ERR (old_map)) {dm_sync_table (md);
@@ -1099,7 +1102,7 @@ static int do_resume(struct dm_ioctl *param)return PTR_ERR (old_map); } -if (dm_table_get_mode (new_map) &FMODE_WRITE ) +if (new_map_mode &FMODE_WRITE )set_disk_ro (dm_disk (md),0 );else set_disk_ro (dm_disk (md),1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/516 pmdomain: rockchip: fix clock leak on domain probe failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Lin <[email protected]>
[ Upstream commit d8b3847770661b7109146e6479eeadcdab9cecf0 ]
When of_clk_get() failed in the middle of the loop, the references of the clocks acquired so far were leaked instead of being released by the error path.
--- drivers/soc/rockchip/pm_domains.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/rockchip/pm_domains.c +1 -1
@@ -435,7 +435,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,dev_err (pmu->dev,"%pOFn: failed to get clk at index %d: %d\n" , node, i, error); -return error; + goto err_put_clocks; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/516 pmdomain: rockchip: dont ignore clock lookup errors on attach
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Lin <[email protected]>
[ Upstream commit 4c66c423593e26273ea0d644906ed007630c6f6d ]
rockchip_pd_attach_dev() treated every of_clk_get() error as the end of the clock list, so a clock that exists but is not available yet (e.g. -EPROBE_DEFER) was silently skipped and the device ended up without pm_clk management. Only -ENOENT means there are no more clocks.
--- drivers/soc/rockchip/pm_domains.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/soc/rockchip/pm_domains.c +13 -1
@@ -356,7 +356,19 @@ static int rockchip_pd_attach_dev(struct generic_pm_domain *genpd, } i =0 ; -while ((clk =of_clk_get (dev->of_node, i++)) && !IS_ERR (clk)) { +while (1 ) { + clk =of_clk_get (dev->of_node, i++); +if (IS_ERR (clk)) { + error =PTR_ERR (clk); +if (error == -ENOENT ) +break ; + +dev_err (dev,"failed to get clock %d: %d\n" , i -1 , + error); +pm_clk_destroy (dev); +return error; + } +dev_dbg (dev,"adding clock '%pC' to list of PM clocks\n" , clk); error =pm_clk_add_clk (dev, clk);if (error) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/516 pmdomain: rockchip: propagate subdomain add errors
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Lin <[email protected]>
[ Upstream commit 4c0d69d677cf5b0065ebbb3ceb8ba66fddbec630 ]
rockchip_pm_add_subdomain() ignored the return value of its recursive call, so a failure deeper in the hierarchy was silently dropped and probe still succeeded with an incomplete domain tree.
--- drivers/soc/rockchip/pm_domains.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soc/rockchip/pm_domains.c +3 -1
@@ -618,7 +618,9 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu, parent_domain->name, child_domain->name); } -rockchip_pm_add_subdomain (pmu, np); + error =rockchip_pm_add_subdomain (pmu, np); +if (error) + goto err_out; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/516 optee: register TEE devices only once fully initialized
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shao-Fu Chen <[email protected]>
[ Upstream commit c108feca0a096f8db25d1b69130035025e9e936d ]
optee_probe() called tee_device_register() on both the client and the supplicant device before the rest of struct optee had been initialized.
tee_device_register() calls cdev_device_add(), which does two things at
once: it creates /dev/tee0 and /dev/teepriv0, and it links the device into the tee class so that class_find_device() can find it. From that moment on the device is reachable both from user space via tee_open() and from kernel space via tee_client_open_context(). The only gate in teedev_open() is tee_device_get(), which merely checks that teedev->desc is non-NULL, which was already set by tee_device_alloc(). Therefore, there is effectively no gate at all.
A context opened in that window can run against a struct optee where
- optee->call_queue.mutex is not initialized by optee_cq_init()
- optee->supp mutex and completions is not initialized by optee_supp_init()
- optee->rpmb_dev_mutex is not initialized yet,
- the message argument cache is not initialized by optee_shm_arg_cache_init()
- optee->ctx is still NULL
Any open session or invoke during this window takes uninitialized mutexes and dereferences a NULL pointer.
Fix it by moving both tee_device_register() calls down to the point where all of struct optee is set up.
--- drivers/tee/optee/core.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/tee/optee/core.c +14 -12
@@ -707,14 +707,6 @@ static int optee_probe(struct platform_device *pdev) } optee->supp_teedev = teedev; - rc =tee_device_register (optee->teedev); -if (rc) - goto err; - - rc =tee_device_register (optee->supp_teedev); -if (rc) - goto err; -mutex_init (&optee->call_queue.mutex);INIT_LIST_HEAD (&optee->call_queue.waiters);optee_wait_queue_init (&optee->wait_queue);
@@ -744,14 +736,24 @@ static int optee_probe(struct platform_device *pdev)platform_set_drvdata (pdev, optee); + rc =tee_device_register (optee->teedev); +if (rc) + goto err_remove; + + rc =tee_device_register (optee->supp_teedev); +if (rc) + goto err_remove; + rc =optee_enumerate_devices (PTA_CMD_GET_DEVICES ); -if (rc) { -optee_remove (pdev); -return rc; - } +if (rc) + goto err_remove;pr_info ("initialized driver\n" );return 0 ; + +err_remove: +optee_remove (pdev); +return rc; err:if (optee) {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/516 scsi: ch: Do not keep references to data transfer element devices
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahmed Abdelhaleem Ahmed <[email protected]>
[ Upstream commit 27c0f718d3b3c99e6d315308e95d987d0382a8a8 ]
ch_readconfig() looks up the scsi_device of every data transfer element whose SCSI id the changer reports in READ ELEMENT STATUS, and stores it in ch->dt[]. scsi_device_lookup() takes a reference, and nothing ever drops
it: ch_destroy() frees the array with kfree(). ch->dt[] is read nowhere else - it only supplies the vendor, model and revision printed in the same loop.
Once such a drive is removed, its scsi_device can never be released. It stays on the host's device list at its address, so a new device there is refused by anything that walks the list - target_core_pscsi reports "scsi_device_get() failed for H:C:T:L" - and the low-level driver's module can no longer be unloaded. Only a reboot recovers.
It shows with any changer that reports its drives' ids; with the mhvtl virtual library (IBM 3573-TL personality), each create and remove of a library with four drives leaves four references behind, counted by the module's use count in lsmod. With ch not bound the count is unchanged, and with this patch applied it is unchanged too.
Drop the reference as soon as the name has been printed, and remove the now unused dt[] array. That also removes the array leaked when ch_probe() fails after ch_readconfig().
The same leak was reported with an RFC patch in 2022, which was not merged.
--- drivers/scsi/ch.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/scsi/ch.c +9 -21
@@ -110,7 +110,6 @@ typedef struct {int minor;char name[8 ];struct scsi_device *device; -struct scsi_device **dt;/* ptrs to data transfer elements */ u_int firsts[CH_TYPES ];u_int counts[CH_TYPES ];u_int unit_attention;
@@ -356,16 +355,10 @@ ch_readconfig(scsi_changer *ch) vendor_labels[i]); } -/* look up the devices of the data transfer elements */ - ch->dt =kcalloc (ch->counts[CHET_DT ],sizeof (*ch->dt), -GFP_KERNEL ); - -if (!ch->dt) { -kfree (buffer); -return -ENOMEM ; - } - +/* report the devices of the data transfer elements */ for (elem =0 ; elem < ch->counts[CHET_DT ]; elem++) { +struct scsi_device *sdev; + id =-1 ; lun =0 ;if (elem <CH_DT_MAX &&-1 != dt_id[elem]) {
@@ -381,10 +374,8 @@ ch_readconfig(scsi_changer *ch)VPRINTK (KERN_INFO ,"dt 0x%x: " ,elem+ch->firsts[CHET_DT ]);if (data[6 ] &0x80 ) {VPRINTK (KERN_CONT ,"not this SCSI bus\n" ); - ch->dt[elem] =NULL ; }else if (0 == (data[6 ] &0x30 )) {VPRINTK (KERN_CONT ,"ID/LUN unknown\n" ); - ch->dt[elem] =NULL ; }else { id = ch->device->id; lun =0 ;
@@ -394,18 +385,16 @@ ch_readconfig(scsi_changer *ch) }if (-1 != id) {VPRINTK (KERN_CONT ,"ID %i, LUN %i, " ,id,lun); - ch->dt[elem] = -scsi_device_lookup (ch->device->host, - ch->device->channel, - id,lun); -if (!ch->dt[elem]) { + sdev =scsi_device_lookup (ch->device->host, + ch->device->channel, + id, lun); +if (!sdev) {/* should not happen */ VPRINTK (KERN_CONT ,"Huh? device not found!\n" ); }else {VPRINTK (KERN_CONT ,"name: %8.8s %16.16s %4.4s\n" , - ch->dt[elem]->vendor, - ch->dt[elem]->model, - ch->dt[elem]->rev); + sdev->vendor, sdev->model, sdev->rev); +scsi_device_put (sdev); } } }
@@ -569,7 +558,6 @@ static void ch_destroy(struct kref *ref)scsi_changer *ch =container_of (ref, scsi_changer, ref); ch->device =NULL ; -kfree (ch->dt);kfree (ch); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/516 drm/fb-helper: defer setup when fbdev_probe() fails, not just on -EAGAIN
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Ngoc Thang <[email protected]>
[ Upstream commit 755c94d178b7e972bb766199d34e4ba4f63a89eb ]
__drm_fb_helper_initial_config_and_unlock() calls drm_client_modeset_probe() first, which already fills in each mode_set->mode/num_connectors for every connected output, and only afterwards calls drm_fb_helper_single_fb_probe() to create fb_helper->fb and wire it into those mode_sets via drm_setup_crtcs_fb().
If drm_fb_helper_single_fb_probe() fails with anything other than -EAGAIN (e.g. dev->driver->fbdev_probe() itself fails), the function bails out before drm_setup_crtcs_fb() runs and before setting fb_helper->deferred_setup. The client is left with mode_sets that have a mode and connectors but mode_set->fb == NULL, and nothing marks this fb_helper as needing a retry.
__drm_fb_helper_restore_fbdev_mode_unlocked() only skips committing when fb_helper->deferred_setup is set, so a later .restore() call (drm_lastclose() on process exit, in this report) commits the stale mode_set through drm_client_modeset_commit() -> drm_client_modeset_commit_atomic() -> __drm_atomic_helper_set_config(), which hits WARN_ON(!set->fb).
Mark fb_helper->deferred_setup on any drm_fb_helper_single_fb_probe() failure, not just -EAGAIN, so restore keeps skipping the commit until a later hotplug event successfully re-probes and re-populates mode_set->fb. The real error code is still returned to the caller unchanged.
--- drivers/gpu/drm/drm_fb_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +4 -4
@@ -1802,11 +1802,11 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper,drm_client_modeset_probe (&fb_helper->client, width, height); ret =drm_fb_helper_single_fb_probe (fb_helper, bpp_sel);if (ret <0 ) { -if (ret == -EAGAIN ) { - fb_helper->preferred_bpp = bpp_sel; - fb_helper->deferred_setup = true; + fb_helper->preferred_bpp = bpp_sel; +/* modesets are probed but fb_helper->fb isn't; defer restore too */ + fb_helper->deferred_setup = true; +if (ret == -EAGAIN ) ret =0 ; - }mutex_unlock (&fb_helper->lock);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/516 drm/i915/gt: Unmask interrupts only when ACTIVE is true
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Karas <[email protected]>
[ Upstream commit 5346b1cec6afa4f9b4b49a9f84e3cfef95a3f7bb ]
There is a small race window between intel_rps_boost() reading a stale ACTIVE state and queuing rps->work, where ACTIVE may be changed via asynchronous calls triggered by wakeref drop. This means that rps_work() could be triggered after the GT has been parked, so unmasking RPS PM interrupts would happen without holding PM wakelock. This sequence of events may be observed during live_rc6_ctx_wa() selftest:
1) live_rc6_ctx_wa()
-> intel_engine_pm_put()
-> wakeref_put()
ASYNC1) wakeref_put() callback
-> __engine_park()
-> intel_gt_pm_put_async()
-> intel_gt_pm_put_async_untracked()
-> intel_wakeref_put_async()ASYNC2) wakeref_put_async() callback
-> __gt_park()
-> intel_rps_park()
-> intel_rps_clear_active() [clear ACTIVE]
WITH INTERRUPTS:
-> rps_disable_interrupts()
-> cancel_work_sync(rps->work)
-> rps_reset_interrupts() [rps->pm_iir = 0]
WITHOUT INTERRUPTS (TIMER mode):
-> rps_stop_timer()
-> cancel_work_sync(rps->work)2) live_rc6_ctx_wa()
-> intel_gt_wait_for_idle()
-> intel_gt_retire_requests_timeout()
-> dma_fence_wait_timeout()
-> ops->wait() [i915_fence_wait()]
-> i915_request_wait_timeout()
-> intel_rps_boost()
-> intel_rps_is_active() [check ACTIVE]
[OPEN RACE WINDOW]
-> queue_work(rps->work)
-> retire_requests()
-> i915_request_retire()
-> intel_rps_dec_waiters() [from 1 to 0]If ASYNC1 and ASYNC2 would execute during [OPEN RACE WINDOW], then:
3) rps_work() executes from the workqueue and may satisfy "(!pm_iir && !client_boost)" test (in TIMER mode rps->pm_iir is zeroed by an earlier rps_work() call or never gets a new value after previous intel_rps_unpark() event), so it jumps to "out" label, bypassing intel_rps_is_active() guard and executes gen6_gt_pm_unmask_irq();
4) GT is parked and runtime PM wakelock is dropped, so only a raw reference in __gt_park() -> intel_display_power_put_async() remains for 100ms, then the MMIO write in gen6_gt_pm_unmask_irq() detects missing wakelock via assert_rpm_wakelock_held() and emits "RPM wakelock ref not held during HW access" tainting kernel.
Commit 3e7abf814193 ("drm/i915: Extract GT render power state management") dropped the "if (rps->interrupts_enabled)" guard that gen6_pm_rps_work() had around this unmask in i915_irq.c. INTEL_RPS_ACTIVE brackets the same window, since it is set in intel_rps_unpark() before rps_enable_interrupts() and rps_start_timer() and cleared in intel_rps_park() before rps_stop_timer() and rps_disable_interrupts().
Skip unmasking when RPS is no longer active (reaching unmask operation is independent of INTERRUPT mode). This does not prevent RPS operation from resuming on the next unpark. In interrupt mode, intel_rps_unpark() calls rps_enable_interrupts(), which enables and unmasks the PM interrupts. In timer mode, it calls rps_start_timer(), restarting periodic engine-busyness evaluation. The timer generates software RPS events and queues rps_work() directly, independently of PM interrupt delivery. Neither mode requires the late worker to unmask interrupts while the GT is parked
--- drivers/gpu/drm/i915/gt/intel_rps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_rps.c +2 -1
@@ -1702,7 +1702,8 @@ static void rps_work(struct work_struct *work) out:spin_lock_irq (>->irq_lock); -gen6_gt_pm_unmask_irq (gt, rps->pm_events); +if (intel_rps_is_active (rps)) +gen6_gt_pm_unmask_irq (gt, rps->pm_events);spin_unlock_irq (>->irq_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/516 namespace: unhash a dentry before detaching the mounts on it
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 528b383dc35d1e5caf64ddf5d35f983ae543b0d0 ]
unlink(), rmdir() and rename() remove the entry from the filesystem, call detach_mounts() on the entry with the inode locked and then call d_delete() once the inode is unlocked.
The thing is that between detach_mounts() and d_delete() the dentry is still hashed and positive. But after detach_mounts() nothing covers the dentry anymore. A lookup that finds this dentry in the dcache can uncover what the mounts hid.
That's a problem when unlinking files or directories that are mountpoints in other mount namespaces. Everybody who had the underlying entry covered can race the detach_mount() call until d_delete() has run.
The race window isn't all that small. It encompasses namespace_unlock() with a full synchronize_rcu_expedited() grace period and the inode_unlock() of the entry.
In my experiments three walkers that kept trying read an overmounted file in 11938 of the 16140 unlinks that removed its mountpoint from a bind mount of the filesystem within a minute.
Fun fact, d_invalidate() has the same ordering problem but gets it right. It unhashes the dentry first and detaches the mounts afterwards. Let's do the same in __detach_mounts():
- A lookup that hasn't found the dentry yet misses it in the dcache and waits for the directory lock that the caller holds until the name is gone for good.
- A lockless lookup that found it already fails the mount_lock check while the dentry still counts as a mountpoint and the d_seq check once it doesn't, and retries.
This fixes the lockless path. We still need to fix the reference count lookup in a follow-up patch.
So d_drop() the dentry. The dentry stays positive and held but can't be found anymore. Then proceed with the detach and unlink.
Reproducer:
The reads were counted with the program below, three walkers for 60 s in a VM with 4 CPUs. The race window is stretched with the debug patch pasted here. fs.detach_race_walk_us sleeps in lookup_fast() once it found a mountpoint dentry and before its mounts are crossed. fs.detach_race_unlink_us sleeps in vfs_unlink() between detach_mounts() and d_delete().
// SPDX-License-Identifier: GPL-2.0 /* * unlink_covered: unlink a file that is a mountpoint in a detached copy of * its mount, against lookups that open it through that copy. * * A is a tmpfs with the file f1 (content SECRET_F) and the plain file * MARK_A. A' is an open_tree(OPEN_TREE_CLONE) copy of A with MARK_A bound * on A'/f1, held through an O_PATH fd on its root once the tree fd is * closed. Walkers open f1 through that fd while the driver unlinks A/f1, * where nothing is mounted on it. A walker may read MARK_A or get ENOENT. * A read of SECRET_F is a hit: the name was found after its mount was * gone. The lockless walks use openat2(RESOLVE_CACHED). * * usage: unlink_covered [-t seconds] [-w walkers] */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include <errno.h> #include <fcntl.h> #include <pthread.h> #include <stdatomic.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/syscall.h> #include <linux/openat2.h> #ifndef __NR_open_tree #define __NR_open_tree 428 #endif #ifndef __NR_move_mount #define __NR_move_mount 429 #endif #ifndef __NR_openat2 #define __NR_openat2 437 #endif #ifndef OPEN_TREE_CLONE #define OPEN_TREE_CLONE 1 #endif #ifndef OPEN_TREE_CLOEXEC #define OPEN_TREE_CLOEXEC O_CLOEXEC #endif #ifndef MOVE_MOUNT_F_EMPTY_PATH #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 #endif #define WORK "/tmp/uc" #define ADIR WORK "/A"
static int duration = 60, nwalkers = 3;
static atomic_int stop, writer_waiting;
static pthread_rwlock_t cur_lock = PTHREAD_RWLOCK_INITIALIZER;
static int cur_fd = -1; /* the root of A', -1 while there is none */
static atomic_long n_unlink, n_walk, n_mark, n_enoent, n_other, n_secret,
n_secret_cached;
static void die(const char *what)
{
fprintf(stderr, "FATAL %s: %s\n", what, strerror(errno));
exit(2);
} static void put_file(int dfd, const char *name, const char *content) {
int fd = openat(dfd, name, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC,
0644);
if (fd < 0 || write(fd, content, strlen(content)) < 0)
die(name);
close(fd);
}
/* "plain/../" @n times, then f1: a longer walk that checks nothing on its way */
static char *longpath(int n)
{
char *p = malloc(n * 9 + 3), *q = p;
for (int i = 0; i < n; i++, q += 9)
memcpy(q, "plain/../", 9);
strcpy(q, "f1");
return p;
}
static void try_read(int dfd, const char *path, int cached)
{
struct open_how how = { .flags = O_RDONLY | O_CLOEXEC,
.resolve = RESOLVE_CACHED };
char buf[32] = "";
long n;
int fd;
if (cached)
fd = syscall(__NR_openat2, dfd, path, &how, sizeof(how));
else
fd = openat(dfd, path, O_RDONLY | O_CLOEXEC);
atomic_fetch_add(&n_walk, 1);
if (fd < 0) {
if (errno == ENOENT)
atomic_fetch_add(&n_enoent, 1);
else if (!cached || errno != EAGAIN)
atomic_fetch_add(&n_other, 1);
return;
}
n = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (n >= 6 && !strncmp(buf, "SECRET", 6)) {
if (cached)
atomic_fetch_add(&n_secret_cached, 1);
if (!atomic_fetch_add(&n_secret, 1))
printf("HIT: read \"%s\" through %s (%s walk)\n", buf,
path, cached ? "lockless" : "any");
} else {
atomic_fetch_add(&n_mark, 1);
}
}
static void *walker(void *arg)
{
unsigned int r = (long)arg * 2654435761u;
while (!atomic_load(&stop)) {
char *p_long, *p_short;
int dfd;
while (atomic_load(&writer_waiting) && !atomic_load(&stop))
usleep(20);
pthread_rwlock_rdlock(&cur_lock);
dfd = cur_fd;
if (dfd < 0) {
pthread_rwlock_unlock(&cur_lock);
usleep(100);
continue;
}
r = r * 1103515245u + 12345u;
p_long = longpath(1 + (r >> 8) % 400);
p_short = longpath(0);
try_read(dfd, p_long, 0);
try_read(dfd, p_short, 0);
try_read(dfd, p_long, 1);
pthread_rwlock_unlock(&cur_lock);
free(p_long);
free(p_short);
}
return NULL;
} /* hand the walkers a new A' (or none), close the old one */ static void publish(int fd)
{
int old;
atomic_fetch_add(&writer_waiting, 1);
pthread_rwlock_wrlock(&cur_lock);
old = cur_fd;
cur_fd = fd;
pthread_rwlock_unlock(&cur_lock);
atomic_fetch_sub(&writer_waiting, 1);
if (old >= 0)
close(old);
}
static void *driver(void *arg __attribute__((unused)))
{
int a;
if (mkdir(ADIR, 0755) && errno != EEXIST)
die("mkdir A");
if (mount("A", ADIR, "tmpfs", 0, "size=4M"))
die("mount A");
a = open(ADIR, O_PATH | O_DIRECTORY | O_CLOEXEC);
if (a < 0 || mkdirat(a, "plain", 0755))
die("A/plain");
put_file(a, "MARK_A", "MARK_A");
while (!atomic_load(&stop)) {
int t, m, fd_a;
put_file(a, "f1", "SECRET_F");
t = syscall(__NR_open_tree, a, "",
OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC | AT_EMPTY_PATH);
if (t < 0)
die("open_tree A");
m = syscall(__NR_open_tree, a, "MARK_A",
OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
if (m < 0)
die("open_tree MARK_A");
if (syscall(__NR_move_mount, m, "", t, "f1",
MOVE_MOUNT_F_EMPTY_PATH))
die("move_mount");
close(m);
fd_a = openat(t, ".", O_PATH | O_DIRECTORY | O_CLOEXEC);
if (fd_a < 0)
die("open A'");
publish(fd_a);
usleep(200 + rand() % 1000);
close(t); /* A' is unmounted, fd_a holds it */
usleep(200 + rand() % 1000);
if (unlinkat(a, "f1", 0)) /* through A, a plain file there */
die("unlink f1");
atomic_fetch_add(&n_unlink, 1);
usleep(rand() % 300);
publish(-1);
}
close(a);
umount2(ADIR, MNT_DETACH);
return NULL;
}
int main(int argc, char **argv)
{
pthread_t d, *w;
int c, i;
setvbuf(stdout, NULL, _IOLBF, 0);
while ((c = getopt(argc, argv, "t:w:")) != -1) {
switch (c) {
case 't':
duration = atoi(optarg);
break;
case 'w':
nwalkers = atoi(optarg);
break;
default:
fprintf(stderr, "usage: unlink_covered [-t seconds] [-w walkers]\n");
return 2;
}
}
if (unshare(CLONE_NEWNS) ||
mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL))
die("unshare");
if (mkdir(WORK, 0755) && errno != EEXIST)
die("mkdir");
w = calloc(nwalkers, sizeof(*w));
for (i = 0; i < nwalkers; i++)
if (pthread_create(&w[i], NULL, walker, (void *)(long)i))
die("pthread_create");
if (pthread_create(&d, NULL, driver, NULL))
die("pthread_create");
sleep(duration);
atomic_store(&stop, 1);
pthread_join(d, NULL);
for (i = 0; i < nwalkers; i++)
pthread_join(w[i], NULL);
printf("unlink_covered: %d s, %d walkers: unlinks %ld walks %ld mark %ld enoent %ld other %ld SECRET %ld (lockless %ld)\n",
duration, nwalkers, atomic_load(&n_unlink), atomic_load(&n_walk),
atomic_load(&n_mark), atomic_load(&n_enoent),
atomic_load(&n_other), atomic_load(&n_secret),
atomic_load(&n_secret_cached));
return atomic_load(&n_secret) ? 1 : 0;
}# diff --git a/fs/namei.c b/fs/namei.c
# --- a/fs/namei.c
# +++ b/fs/namei.c
# @@ -35,6 +35,7 @@
# #include <linux/fcntl.h>
# #include <linux/device_cgroup.h>
# #include <linux/fs_struct.h>
# +#include <linux/delay.h>
# #include <linux/posix_acl.h>
# #include <linux/hash.h>
# #include <linux/bitops.h>
# @@ -1205,9 +1206,26 @@ static int sysctl_protected_symlinks __read_mostly;
# static int sysctl_protected_hardlinks __read_mostly;
# static int sysctl_protected_fifos __read_mostly;
# static int sysctl_protected_regular __read_mostly;
# +/* debug: widen the two windows of the detach_mounts() race */
# +static int sysctl_detach_race_walk_us __read_mostly;
# +static int sysctl_detach_race_unlink_us __read_mostly;
#
# #ifdef CONFIG_SYSCTL
# static const struct ctl_table namei_sysctls[] = {
# + {
# + .procname = "detach_race_walk_us",
# + .data = &sysctl_detach_race_walk_us,
# + .maxlen = sizeof(int),
# + .mode = 0644,
# + .proc_handler = proc_dointvec,
# + },
# + {
# + .procname = "detach_race_unlink_us",
# + .data = &sysctl_detach_race_unlink_us,
# + .maxlen = sizeof(int),
# + .mode = 0644,
# + .proc_handler = proc_dointvec,
# + },
# {
# .procname = "protected_symlinks",
# .data = &sysctl_protected_symlinks,
# @@ -1878,6 +1896,10 @@ static struct dentry *lookup_fast(struct nameidata *nd)
# dentry = __d_lookup(parent, &nd->last);
# if (unlikely(!dentry))
# return NULL;
# + /* debug: between finding a mountpoint and crossing its mounts */
# + if (unlikely(sysctl_detach_race_walk_us) && d_mountpoint(dentry))
# + usleep_range(sysctl_detach_race_walk_us,
# + sysctl_detach_race_walk_us + 10);
# status = d_revalidate(nd->inode, &nd->last, dentry, nd->flags);
# }
# if (unlikely(status <= 0)) {
# @@ -5693,6 +5715,10 @@ int vfs_unlink(struct mnt_idmap *idmap, struct inode *dir,
# if (!error) {
# dont_mount(dentry);
# detach_mounts(dentry);
# + /* debug: the mounts are gone, d_delete() is still to come */
# + if (unlikely(sysctl_detach_race_unlink_us))
# + usleep_range(sysctl_detach_race_unlink_us,
# + sysctl_detach_race_unlink_us + 10);
# }
# }
# }--- fs/namespace.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/namespace.c +5 -0
@@ -1668,6 +1668,9 @@ static int do_umount(struct mount *mnt, int flags)* detach_mounts allows lazily unmounting those mounts instead of * leaking them. * +* The dentry is unhashed before the mounts go so that no lookup finds +* what they covered. The caller removes it for good afterwards. +* * The caller may hold dentry->d_inode->i_mutex. */ void __detach_mounts (struct dentry *dentry)
@@ -1681,6 +1684,8 @@ void __detach_mounts(struct dentry *dentry)if (!mp) goto out_unlock; +/* the name goes first, what covered it goes second */ +d_drop (dentry); event++;while (!hlist_empty (&mp->m_list)) { mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/516 namespace: dont copy an unmounted mount tree
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 8bacbf6be959973b28b691713a872c12eae69eec ]
may_copy_tree() accepts a mount whose root is an nsfs or pidfs file before it checks whether that mount is mounted. This exception exists for nsfs and pidfs mounts. They are part of no mount namespace so neither check_mnt() nor is_mounted() would let them through and bind-mounting a nsfsfd or a pidfd wouldn't work.
Problem is that exception also admits a bind mount of such a file when it was lazily unmounted and is only kept alive by a file descriptor:
mount --bind /proc/self/ns/net /tmp/x exec 3< /tmp/x umount -l /tmp/x mount --rbind /proc/self/fd/3 /tmp/y
With MS_REC or AT_RECURSIVE copy_tree() doesn't stop at the unmounted mount. It copies every mount that stayed attached to it as well. So if you have a bunch of overmounts over the nsfsfd or the pidfd the whole unmounted stack is copied. That's a bug.
So refuse to walk an unmounted tree. Copying its root alone stays possible. So a bind mount of a namespace that is gone can still be recreated from a file descriptor on the old one. The file descriptor pins that mount and its root and __has_locked_children() only reads the direct children which don't leave the parent's list without namespace_sem. The internal mounts carry MNT_NS_INTERNAL instead of NULL and are still walked. Copying an unmounted tree recursively fails with EINVAL.
--- fs/namespace.c | 3 +++ 1 file changed, 3 insertions(+)
fs/namespace.c +3 -0
@@ -2367,6 +2367,9 @@ static struct mount *__do_loopback(struct path *old_path, int recurse)if (!check_mnt (old) && old_path->dentry->d_op != &ns_dentry_operations)return mnt; +if (recurse && !old->mnt_ns) +return ERR_PTR (-EINVAL ); +if (!recurse &&has_locked_children (old, old_path->dentry))return mnt;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/516 fcntl: refuse F_SET_RW_HINT on an immutable inode
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit b0d1022b9bdb1e98aa7fb3244fdd50a58c61766c ]
An immutable inode is never written to so write hints are pointless. Refuse the hint on an immutable inode the way setattr(), fallocate() and etxattr() refuse their changes.
--- fs/fcntl.c | 3 +++ 1 file changed, 3 insertions(+)
fs/fcntl.c +3 -0
@@ -306,6 +306,9 @@ static long fcntl_rw_hint(struct file *file, unsigned int cmd,return -EFAULT ;return 0 ;case F_SET_RW_HINT : +/* nothing is ever written to it */ +if (IS_IMMUTABLE (inode)) +return -EPERM ;if (copy_from_user (&h, argp,sizeof (h)))return -EFAULT ; hint = (enum rw_hint ) h;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/516 namespace: handle mount locking for automounts correctly
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 33aadc7c72055fca93cb5a3691d836ebf8b31c9b ]
If mounts are propagated across user namespaces, attach_recursive_mnt() locks every copy of the source mount to protect overmounts from vanishing and revealing the underlying files or directories.
The user namespace is taken from the caller's mount namespaces since this is where the mounts end up. Except, that's not always true. Automounts may legitimately get popped in by tasks located in a different mount and user namespace during path lookup.
Then check doesn't make sense at that point. The copy in the namespace of the parent - which may be the host's - is now locked and the host cannot change the flags of its own mounts anymore.
Here's the reproducer:
- host has debugfs mounted nosuid,nodev,noexec and shared
- tracefs automount below it is not yet active
- hand a child process a directory descriptor on that mount
- child process enters auser and mount namespace
- child process' namespace now holds a locked copy of the host's debugfs mount that receives propagation from it
- child process stats "tracing/." through the descriptor
- lookup runs on the host's mount so the automount lands below the host's mount
- propagation puts a copy below the child's copy
- both try to clear the flags on the mount they got, with a bind remount:
host, on its own automount: MS_REMOUNT|MS_BIND = EPERM
child, on the copy in its namespace: MS_REMOUNT|MS_BIND = 0So the lock landed on the host's mount instead of the child's copy. Congrats. So we need to compare with the owner of the namespace the mount actually gets mounted on. For all regular cases that is the caller's mount namespace and so nothing changes.
Detached trees in anonymous mount namespaces by be handed over via SCM_RIGHTS or inherited in other ways on purpose so the attaching task's mount namespace is authoritative, not the creator of the detached tree.
--- fs/namespace.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
fs/namespace.c +17 -1
@@ -2151,14 +2151,30 @@ static int attach_recursive_mnt(struct mount *source_mnt,struct mountpoint *dest_mp, bool moving) { -struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;HLIST_HEAD (tree_list );struct mnt_namespace *ns = dest_mnt->mnt_ns; +struct user_namespace *user_ns = ns->user_ns;struct mountpoint *smp;struct mount *child, *p;struct hlist_node *n;int err; +/* +* A caller in an unprivileged mount namespaces may trigger an +* automount and propagate locked mounts into privileged mount +* namespaces. Take ownership from the target mount namespace. +* It's equivalent for everything but the automount case. +* +* Detached trees in anonymous mount namespaces by be handed +* over via SCM_RIGHTS or inherited in other ways on purpose +* the attaching task's mount namespace is authoritative, not +* the creator of the detached tree. +*/ +if (is_anon_ns (ns)) + user_ns = current->nsproxy->mnt_ns->user_ns; +else + user_ns = ns->user_ns; +/* Preallocate a mountpoint in case the new mounts need * to be tucked under other mounts. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/516 devm-helpers: Fix devm_delayed_work_autocancel() kerneldoc
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matti Vaittinen <[email protected]>
[ Upstream commit a943d76352dbb4707a5e5537bbe696c00f5ddd36 ]
The kerneldoc for devm_delayed_work_autocancel() contains invalid parameter description.
Fix the parameter description. And while at it - make it more obvous that this function operates on delayed_work. That helps differentiating with resource-managed INIT_WORK description (which should follow in near future)
--- include/linux/devm-helpers.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
include/linux/devm-helpers.h +7 -6
@@ -32,13 +32,14 @@ static inline void devm_delayed_work_drop(void *res) }/** -* devm_delayed_work_autocancel - Resource-managed work allocation -* @dev: Device which lifetime work is bound to -* @pdata: work to be cancelled when driver is detached +* devm_delayed_work_autocancel - Resource-managed delayed work allocation +* @dev: Device which lifetime work is bound to +* @w: Work item to be queued +* @worker: Worker function * -* Initialize work which is automatically cancelled when driver is detached. -* A few drivers need delayed work which must be cancelled before driver -* is detached to avoid accessing removed resources. +* Initialize delayed work which is automatically cancelled when driver is +* detached. A few drivers need delayed work which must be cancelled before +* driver is detached to avoid accessing removed resources. * devm_delayed_work_autocancel() can be used to omit the explicit * cancelleation when driver is detached. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/516 netfilter: nf_tables: fix crash when nf_trace is enabled
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 399a14ec7993d605740de7b2cd5c0ce8407d12ed ]
do not access info->pkt when info->trace is not 1. nft_traceinfo is not initialized, except when tracing is enabled.
The 'nft_trace_enabled' static key cannot be used for this, we must always check info->trace first.
Pass nft_pktinfo directly to avoid this.
--- net/netfilter/nf_tables_core.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
net/netfilter/nf_tables_core.c +10 -11
@@ -34,25 +34,23 @@ static noinline void __nft_trace_packet(struct nft_traceinfo *info,nft_trace_notify (info); } -static inline void nft_trace_packet (struct nft_traceinfo *info, +static inline void nft_trace_packet (const struct nft_pktinfo *pkt, +struct nft_traceinfo *info,const struct nft_chain *chain,const struct nft_rule *rule,enum nft_trace_types type) {if (static_branch_unlikely (&nft_trace_enabled)) { -const struct nft_pktinfo *pkt = info->pkt; - info->nf_trace = pkt->skb->nf_trace; info->rule = rule;__nft_trace_packet (info, chain, type); } } -static inline void nft_trace_copy_nftrace (struct nft_traceinfo *info) +static inline void nft_trace_copy_nftrace (const struct nft_pktinfo *pkt, +struct nft_traceinfo *info) {if (static_branch_unlikely (&nft_trace_enabled)) { -const struct nft_pktinfo *pkt = info->pkt; -if (info->trace) info->nf_trace = pkt->skb->nf_trace; }
@@ -96,7 +94,6 @@ static noinline void __nft_trace_verdict(struct nft_traceinfo *info,const struct nft_chain *chain, const struct nft_regs *regs) { - const struct nft_pktinfo *pkt = info->pkt; enum nft_trace_types type;switch (regs->verdict.code) {
@@ -110,7 +107,9 @@ static noinline void __nft_trace_verdict(struct nft_traceinfo *info,break ;default : type =NFT_TRACETYPE_RULE ; - info->nf_trace = pkt->skb->nf_trace; + +if (info->trace) + info->nf_trace = info->pkt->skb->nf_trace;break ; }
@@ -261,10 +260,10 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)switch (regs.verdict.code) {case NFT_BREAK : regs.verdict.code =NFT_CONTINUE ; -nft_trace_copy_nftrace (&info); +nft_trace_copy_nftrace (pkt, &info);continue ;case NFT_CONTINUE : -nft_trace_packet (&info, chain, rule, +nft_trace_packet (pkt, &info, chain, rule,NFT_TRACETYPE_RULE );continue ; }
@@ -306,7 +305,7 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv) goto next_rule; } -nft_trace_packet (&info, basechain,NULL ,NFT_TRACETYPE_POLICY ); +nft_trace_packet (pkt, &info, basechain,NULL ,NFT_TRACETYPE_POLICY );if (static_branch_unlikely (&nft_counters_enabled))nft_update_chain_stats (basechain, pkt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/516 xfrm: prevent policy_hthresh.work from racing with netns teardown
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tahera Fahimi <[email protected]>
An XFRM_MSG_NEWSPDINFO request can queue the per-net work item policy_hthresh.work onto the system workqueue. xfrm_hash_rebuild() retrieves the enclosing struct net from the work item, so the callback can dereference freed memory if it runs after net namespace teardown.
Mainline commit 29fe3a61bcdc ("xfrm: prevent policy_hthresh.work from racing with netns teardown") fixes this issue using disable_work_sync(). That API is not available in Linux 5.10, so the mainline change cannot be directly backported.
Provide the same guarantee with an XFRM-local work_disabled flag. Protect the flag and schedule_work() with the existing policy_hthresh seqlock so teardown can atomically stop new queueing attempts. Then use cancel_work_sync() to synchronize work that was queued before the flag was set. This ensures policy_hthresh.work cannot outlive its struct net.
--- include/net/netns/xfrm.h | 1 + net/xfrm/xfrm_policy.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
include/net/netns/xfrm.h +1 -0
@@ -23,6 +23,7 @@ struct xfrm_policy_hash {struct xfrm_policy_hthresh {struct work_struct work;seqlock_t lock; +bool work_disabled;u8 lbits4;u8 rbits4;u8 lbits6;
net/xfrm/xfrm_policy.c +18 -1
@@ -1378,7 +1378,10 @@ static void xfrm_hash_rebuild(struct work_struct *work)void xfrm_policy_hash_rebuild (struct net *net) { -schedule_work (&net->xfrm.policy_hthresh.work); +write_seqlock (&net->xfrm.policy_hthresh.lock); +if (!net->xfrm.policy_hthresh.work_disabled) +schedule_work (&net->xfrm.policy_hthresh.work); +write_sequnlock (&net->xfrm.policy_hthresh.lock); }EXPORT_SYMBOL (xfrm_policy_hash_rebuild);
@@ -4129,6 +4132,7 @@ static int __net_init xfrm_policy_init(struct net *net) net->xfrm.policy_hthresh.rbits6 =128 ;seqlock_init (&net->xfrm.policy_hthresh.lock); + net->xfrm.policy_hthresh.work_disabled = false;INIT_LIST_HEAD (&net->xfrm.policy_all);INIT_LIST_HEAD (&net->xfrm.inexact_bins);
@@ -4154,6 +4158,19 @@ static void xfrm_policy_fini(struct net *net)unsigned int sz;int dir; +/* Prevent new policy hash rebuilds before draining the work item. +* +* The upstream fix uses disable_work_sync(), which is unavailable +* in v6.6. Protecting work_disabled and schedule_work() with the +* same seqlock closes the check-to-queue race, while the subsequent +* cancel_work_sync() drains work that was queued or running before +* teardown disabled it. +*/ +write_seqlock (&net->xfrm.policy_hthresh.lock); + net->xfrm.policy_hthresh.work_disabled = true; +write_sequnlock (&net->xfrm.policy_hthresh.lock); +cancel_work_sync (&net->xfrm.policy_hthresh.work); +flush_work (&net->xfrm.policy_hash_work);#ifdef CONFIG_XFRM_SUB_POLICY xfrm_policy_flush (net,XFRM_POLICY_TYPE_SUB , false);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/516 xfs: hoist recovered bmap intent checks out of xfs_bui_item_recover
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit bc525cf455dac810d28f9edd379805dc249bc5a9 ]
When we recover a bmap intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_bmap_item.c | 74 +++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 27 deletions(-)
fs/xfs/xfs_bmap_item.c +47 -27
@@ -418,6 +418,49 @@ const struct xfs_defer_op_type xfs_bmap_update_defer_type = { .cancel_item = xfs_bmap_update_cancel_item, }; +/* Is this recovered BUI ok? */ +static inline bool +xfs_bui_validate ( +struct xfs_mount *mp, +struct xfs_bui_log_item *buip) +{ +struct xfs_map_extent *bmap; +xfs_fsblock_t startblock_fsb; +xfs_fsblock_t inode_fsb; + +/* Only one mapping operation per BUI... */ +if (buip->bui_format.bui_nextents !=XFS_BUI_MAX_FAST_EXTENTS ) +return false; + + bmap = &buip->bui_format.bui_extents[0 ]; + startblock_fsb =XFS_BB_TO_FSB (mp, +XFS_FSB_TO_DADDR (mp, bmap->me_startblock)); + inode_fsb =XFS_BB_TO_FSB (mp,XFS_FSB_TO_DADDR (mp, +XFS_INO_TO_FSB (mp, bmap->me_owner))); + +if (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS ) +return false; + +switch (bmap->me_flags &XFS_BMAP_EXTENT_TYPE_MASK ) { +case XFS_BMAP_MAP : +case XFS_BMAP_UNMAP : +break ; +default : +return false; + } + +if (startblock_fsb ==0 || + bmap->me_len ==0 || + inode_fsb ==0 || + startblock_fsb >= mp->m_sb.sb_dblocks || + bmap->me_len >= mp->m_sb.sb_agblocks || + inode_fsb >= mp->m_sb.sb_dblocks || + (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )) +return false; + +return true; +} +/* * Process a bmap update intent item that was recovered from the log. * We need to update some inode's bmbt.
@@ -434,47 +477,24 @@ xfs_bui_item_recover(struct xfs_mount *mp = lip->li_mountp;struct xfs_map_extent *bmap;struct xfs_bud_log_item *budp; -xfs_fsblock_t startblock_fsb; -xfs_fsblock_t inode_fsb;xfs_filblks_t count;xfs_exntst_t state;unsigned int bui_type;int whichfork;int error =0 ; -/* Only one mapping operation per BUI... */ -if (buip->bui_format.bui_nextents !=XFS_BUI_MAX_FAST_EXTENTS ) +if (!xfs_bui_validate (mp, buip)) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + &buip->bui_format,sizeof (buip->bui_format));return -EFSCORRUPTED ; + } -/* -* First check the validity of the extent described by the -* BUI. If anything is bad, then toss the BUI. -*/ bmap = &buip->bui_format.bui_extents[0 ]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, bmap->me_startblock)); - inode_fsb =XFS_BB_TO_FSB (mp,XFS_FSB_TO_DADDR (mp, -XFS_INO_TO_FSB (mp, bmap->me_owner))); state = (bmap->me_flags &XFS_BMAP_EXTENT_UNWRITTEN ) ?XFS_EXT_UNWRITTEN :XFS_EXT_NORM ; whichfork = (bmap->me_flags &XFS_BMAP_EXTENT_ATTR_FORK ) ?XFS_ATTR_FORK :XFS_DATA_FORK ; bui_type = bmap->me_flags &XFS_BMAP_EXTENT_TYPE_MASK ; -switch (bui_type) { -case XFS_BMAP_MAP : -case XFS_BMAP_UNMAP : -break ; -default : -return -EFSCORRUPTED ; - } -if (startblock_fsb ==0 || - bmap->me_len ==0 || - inode_fsb ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - bmap->me_len >= mp->m_sb.sb_agblocks || - inode_fsb >= mp->m_sb.sb_dblocks || - (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )) -return -EFSCORRUPTED ;/* Grab the inode. */ error =xfs_iget (mp,NULL , bmap->me_owner,0 ,0 , &ip);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/516 xfs: improve the code that checks recovered bmap intent items
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 67d8679bd3913d2c4ec5f32ade778881b93af766 ]
The code that validates recovered bmap intent items is kind of a mess -- it doesn't use the standard xfs type validators, and it doesn't check for things that it should. Fix the validator function to use the standard validation helpers and look for more types of obvious errors.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_bmap_item.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
fs/xfs/xfs_bmap_item.c +13 -13
@@ -425,18 +425,12 @@ xfs_bui_validate( struct xfs_bui_log_item *buip) {struct xfs_map_extent *bmap; -xfs_fsblock_t startblock_fsb; -xfs_fsblock_t inode_fsb;/* Only one mapping operation per BUI... */ if (buip->bui_format.bui_nextents !=XFS_BUI_MAX_FAST_EXTENTS )return false; bmap = &buip->bui_format.bui_extents[0 ]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, bmap->me_startblock)); - inode_fsb =XFS_BB_TO_FSB (mp,XFS_FSB_TO_DADDR (mp, -XFS_INO_TO_FSB (mp, bmap->me_owner)));if (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )return false;
@@ -449,13 +443,19 @@ xfs_bui_validate(return false; } -if (startblock_fsb ==0 || - bmap->me_len ==0 || - inode_fsb ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - bmap->me_len >= mp->m_sb.sb_agblocks || - inode_fsb >= mp->m_sb.sb_dblocks || - (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )) +if (!xfs_verify_ino (mp, bmap->me_owner)) +return false; + +if (bmap->me_startoff + bmap->me_len <= bmap->me_startoff) +return false; + +if (bmap->me_startblock + bmap->me_len <= bmap->me_startblock) +return false; + +if (!xfs_verify_fsbno (mp, bmap->me_startblock)) +return false; + +if (!xfs_verify_fsbno (mp, bmap->me_startblock + bmap->me_len -1 ))return false;return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/516 xfs: hoist recovered rmap intent checks out of xfs_rui_item_recover
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit dda7ba65bf03b6f3a7502b9f85c2524a5ae5aa2e ]
When we recover a rmap intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_rmap_item.c | 67 ++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 25 deletions(-)
fs/xfs/xfs_rmap_item.c +42 -25
@@ -460,6 +460,42 @@ const struct xfs_defer_op_type xfs_rmap_update_defer_type = { .cancel_item = xfs_rmap_update_cancel_item, }; +/* Is this recovered RUI ok? */ +static inline bool +xfs_rui_validate_map ( +struct xfs_mount *mp, +struct xfs_map_extent *rmap) +{ +xfs_fsblock_t startblock_fsb; +bool op_ok; + + startblock_fsb =XFS_BB_TO_FSB (mp, +XFS_FSB_TO_DADDR (mp, rmap->me_startblock)); +switch (rmap->me_flags &XFS_RMAP_EXTENT_TYPE_MASK ) { +case XFS_RMAP_EXTENT_MAP : +case XFS_RMAP_EXTENT_MAP_SHARED : +case XFS_RMAP_EXTENT_UNMAP : +case XFS_RMAP_EXTENT_UNMAP_SHARED : +case XFS_RMAP_EXTENT_CONVERT : +case XFS_RMAP_EXTENT_CONVERT_SHARED : +case XFS_RMAP_EXTENT_ALLOC : +case XFS_RMAP_EXTENT_FREE : + op_ok = true; +break ; +default : + op_ok = false; +break ; + } +if (!op_ok || startblock_fsb ==0 || + rmap->me_len ==0 || + startblock_fsb >= mp->m_sb.sb_dblocks || + rmap->me_len >= mp->m_sb.sb_agblocks || + (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS )) +return false; + +return true; +} +/* * Process an rmap update intent item that was recovered from the log. * We need to update the rmapbt.
@@ -475,10 +511,8 @@ xfs_rui_item_recover(struct xfs_trans *tp;struct xfs_btree_cur *rcur =NULL ;struct xfs_mount *mp = lip->li_mountp; -xfs_fsblock_t startblock_fsb;enum xfs_rmap_intent_type type;xfs_exntst_t state; -bool op_ok;int i;int whichfork;int error =0 ;
@@ -489,30 +523,13 @@ xfs_rui_item_recover(* just toss the RUI. */ for (i =0 ; i < ruip->rui_format.rui_nextents; i++) { - rmap = &ruip->rui_format.rui_extents[i]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, rmap->me_startblock)); -switch (rmap->me_flags &XFS_RMAP_EXTENT_TYPE_MASK ) { -case XFS_RMAP_EXTENT_MAP : -case XFS_RMAP_EXTENT_MAP_SHARED : -case XFS_RMAP_EXTENT_UNMAP : -case XFS_RMAP_EXTENT_UNMAP_SHARED : -case XFS_RMAP_EXTENT_CONVERT : -case XFS_RMAP_EXTENT_CONVERT_SHARED : -case XFS_RMAP_EXTENT_ALLOC : -case XFS_RMAP_EXTENT_FREE : - op_ok = true; -break ; -default : - op_ok = false; -break ; - } -if (!op_ok || startblock_fsb ==0 || - rmap->me_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - rmap->me_len >= mp->m_sb.sb_agblocks || - (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS )) +if (!xfs_rui_validate_map (mp, + &ruip->rui_format.rui_extents[i])) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + &ruip->rui_format, +sizeof (ruip->rui_format));return -EFSCORRUPTED ; + } } error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/516 xfs: improve the code that checks recovered rmap intent items
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit c447ad62dc906f4b5f788e8ff20c1768ab2eab2c ]
The code that validates recovered rmap intent items is kind of a mess -- it doesn't use the standard xfs type validators, and it doesn't check for things that it should. Fix the validator function to use the standard validation helpers and look for more types of obvious errors.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_rmap_item.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
fs/xfs/xfs_rmap_item.c +18 -12
@@ -466,11 +466,9 @@ xfs_rui_validate_map( struct xfs_mount *mp, struct xfs_map_extent *rmap) { - xfs_fsblock_t startblock_fsb; -bool op_ok; +if (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS ) +return false; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, rmap->me_startblock));switch (rmap->me_flags &XFS_RMAP_EXTENT_TYPE_MASK ) {case XFS_RMAP_EXTENT_MAP :case XFS_RMAP_EXTENT_MAP_SHARED :
@@ -480,17 +478,25 @@ xfs_rui_validate_map(case XFS_RMAP_EXTENT_CONVERT_SHARED :case XFS_RMAP_EXTENT_ALLOC :case XFS_RMAP_EXTENT_FREE : - op_ok = true;break ;default : - op_ok = false; -break ; +return false; } -if (!op_ok || startblock_fsb ==0 || - rmap->me_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - rmap->me_len >= mp->m_sb.sb_agblocks || - (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS )) + +if (!XFS_RMAP_NON_INODE_OWNER (rmap->me_owner) && + !xfs_verify_ino (mp, rmap->me_owner)) +return false; + +if (rmap->me_startoff + rmap->me_len <= rmap->me_startoff) +return false; + +if (rmap->me_startblock + rmap->me_len <= rmap->me_startblock) +return false; + +if (!xfs_verify_fsbno (mp, rmap->me_startblock)) +return false; + +if (!xfs_verify_fsbno (mp, rmap->me_startblock + rmap->me_len -1 ))return false;return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/516 xfs: hoist recovered refcount intent checks out of xfs_cui_item_recover
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit ed64f8343aafa62e762c74dfb400f640b6fa6c15 ]
When we recover a refcount intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_refcount_item.c | 59 ++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 21 deletions(-)
fs/xfs/xfs_refcount_item.c +38 -21
@@ -417,6 +417,38 @@ const struct xfs_defer_op_type xfs_refcount_update_defer_type = { .cancel_item = xfs_refcount_update_cancel_item, }; +/* Is this recovered CUI ok? */ +static inline bool +xfs_cui_validate_phys ( +struct xfs_mount *mp, +struct xfs_phys_extent *refc) +{ +xfs_fsblock_t startblock_fsb; +bool op_ok; + + startblock_fsb =XFS_BB_TO_FSB (mp, +XFS_FSB_TO_DADDR (mp, refc->pe_startblock)); +switch (refc->pe_flags &XFS_REFCOUNT_EXTENT_TYPE_MASK ) { +case XFS_REFCOUNT_INCREASE : +case XFS_REFCOUNT_DECREASE : +case XFS_REFCOUNT_ALLOC_COW : +case XFS_REFCOUNT_FREE_COW : + op_ok = true; +break ; +default : + op_ok = false; +break ; + } +if (!op_ok || startblock_fsb ==0 || + refc->pe_len ==0 || + startblock_fsb >= mp->m_sb.sb_dblocks || + refc->pe_len >= mp->m_sb.sb_agblocks || + (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS )) +return false; + +return true; +} +/* * Process a refcount update intent item that was recovered from the log. * We need to update the refcountbt.
@@ -433,11 +465,9 @@ xfs_cui_item_recover(struct xfs_trans *tp;struct xfs_btree_cur *rcur =NULL ;struct xfs_mount *mp = lip->li_mountp; -xfs_fsblock_t startblock_fsb;xfs_fsblock_t new_fsb;xfs_extlen_t new_len;unsigned int refc_type; -bool op_ok;bool requeue_only = false;enum xfs_refcount_intent_type type;int i;
@@ -449,26 +479,13 @@ xfs_cui_item_recover(* just toss the CUI. */ for (i =0 ; i < cuip->cui_format.cui_nextents; i++) { - refc = &cuip->cui_format.cui_extents[i]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, refc->pe_startblock)); -switch (refc->pe_flags &XFS_REFCOUNT_EXTENT_TYPE_MASK ) { -case XFS_REFCOUNT_INCREASE : -case XFS_REFCOUNT_DECREASE : -case XFS_REFCOUNT_ALLOC_COW : -case XFS_REFCOUNT_FREE_COW : - op_ok = true; -break ; -default : - op_ok = false; -break ; - } -if (!op_ok || startblock_fsb ==0 || - refc->pe_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - refc->pe_len >= mp->m_sb.sb_agblocks || - (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS )) +if (!xfs_cui_validate_phys (mp, + &cuip->cui_format.cui_extents[i])) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + &cuip->cui_format, +sizeof (cuip->cui_format));return -EFSCORRUPTED ; + } }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/516 xfs: improve the code that checks recovered refcount intent items
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 0d79781a1aa6a6a567e63294012eee2384f406f2 ]
The code that validates recovered refcount intent items is kind of a mess -- it doesn't use the standard xfs type validators, and it doesn't check for things that it should. Fix the validator function to use the standard validation helpers and look for more types of obvious errors.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_refcount_item.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
fs/xfs/xfs_refcount_item.c +11 -12
@@ -423,27 +423,26 @@ xfs_cui_validate_phys( struct xfs_mount *mp, struct xfs_phys_extent *refc) { - xfs_fsblock_t startblock_fsb; -bool op_ok; +if (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS ) +return false; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, refc->pe_startblock));switch (refc->pe_flags &XFS_REFCOUNT_EXTENT_TYPE_MASK ) {case XFS_REFCOUNT_INCREASE :case XFS_REFCOUNT_DECREASE :case XFS_REFCOUNT_ALLOC_COW :case XFS_REFCOUNT_FREE_COW : - op_ok = true;break ;default : - op_ok = false; -break ; +return false; } -if (!op_ok || startblock_fsb ==0 || - refc->pe_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - refc->pe_len >= mp->m_sb.sb_agblocks || - (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS )) + +if (refc->pe_startblock + refc->pe_len <= refc->pe_startblock) +return false; + +if (!xfs_verify_fsbno (mp, refc->pe_startblock)) +return false; + +if (!xfs_verify_fsbno (mp, refc->pe_startblock + refc->pe_len -1 ))return false;return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/516 xfs: dont nest icloglock inside ic_callback_lock
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Chinner <[email protected]>
[ Upstream commit 6be001021f0b307c8c1544e8b3ac87de20d711de ]
It's completely unnecessary because callbacks are added to iclogs without holding the icloglock, hence no amount of ordering between the icloglock and ic_callback_lock will order the removal of callbacks from the iclog.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
5.10:
Fixed conflict due to the following missing commit:
956f6daa84bf ("xfs: add iclog state trace events")
--- fs/xfs/xfs_log.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
fs/xfs/xfs_log.c +4 -14
@@ -2721,10 +2721,7 @@ static voidxlog_state_do_iclog_callbacks ( struct xlog *log, struct xlog_in_core *iclog) - __releases(&log->l_icloglock) - __acquires(&log->l_icloglock) { - spin_unlock(&log->l_icloglock); spin_lock(&iclog->ic_callback_lock);while (!list_empty (&iclog->ic_callbacks)) {LIST_HEAD (tmp);
@@ -2736,12 +2733,6 @@ xlog_state_do_iclog_callbacks(spin_lock (&iclog->ic_callback_lock); } -/* -* Pick up the icloglock while still holding the callback lock so we -* serialise against anyone trying to add more callbacks to this iclog -* now we've finished processing. -*/ -spin_lock (&log->l_icloglock);spin_unlock (&iclog->ic_callback_lock); }
@@ -2782,13 +2773,12 @@ xlog_state_do_callback( iclog = iclog->ic_next;continue ; } +spin_unlock (&log->l_icloglock); -/* -* Running callbacks will drop the icloglock which means -* we'll have to run at least one more complete loop. -*/ - cycled_icloglock = true;xlog_state_do_iclog_callbacks (log, iclog); + cycled_icloglock = true; + +spin_lock (&log->l_icloglock);if (XLOG_FORCED_SHUTDOWN (log))wake_up_all (&iclog->ic_force_wait);else
Signature · 1 line
2.53.0