6.12.112-rc1 review
Greg Kroah-Hartman
maintainerPATCH 222/877 mmc: core: Fix OF node reference leak on card add failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhu Ling <[email protected]>
commit 08b54e16d547d5c1aa61bf7a3595bb1620975eeb upstream.
mmc_of_find_child_device() returns a device node with its reference count incremented. mmc_add_card() stores the reference before calling device_add(), while the card is marked present only after device_add() succeeds.
If device_add() fails, the callers release the card through mmc_remove_card(). However, mmc_remove_card() only drops the OF node reference for a present card, leaking the reference on this error path.
Move of_node_put() outside the present-card conditional so the reference is released for both registered cards and card-add failures.
--- drivers/mmc/core/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/bus.c +1 -1
@@ -399,8 +399,8 @@ void mmc_remove_card(struct mmc_card *ca mmc_hostname(card->host), card->rca); }device_del (&card->dev); -of_node_put (card->dev.of_node); } +of_node_put (card->dev.of_node);if (host->cqe_enabled) { host->cqe_ops->cqe_disable (host);
Greg Kroah-Hartman
maintainerPATCH 223/877 mmc: hsq: Fix use-after-free in retry work
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 5d132990475f02cfa1debe03d50b479432864ebd upstream.
mmc_hsq_pump_requests() queues retry_work when request_atomic() returns -EBUSY; today sdhci-sprd is the only consumer that implements request_atomic(). The work is embedded in a devm-allocated mmc_hsq, but is never cancelled during driver removal. Work still pending at unbind can therefore run after the devm allocation has been released and dereference hsq->mmc and hsq->mrq.
Use devm_work_autocancel() to cancel and drain retry_work before the devm allocation is released. By the time devres cleanup begins, mmc_remove_host() has already stopped the host, so no new requests can arm the work.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mmc_hsq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/host/mmc_hsq.c +7 -1
@@ -7,6 +7,7 @@* Author: Baolin Wang <[email protected]> */ +#include <linux/devm-helpers.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> #include <linux/module.h>
@@ -345,6 +346,7 @@ static const struct mmc_cqe_ops mmc_hsq_int mmc_hsq_init (struct mmc_hsq *hsq,struct mmc_host *mmc) { +int ret;int i; hsq->num_slots =HSQ_NUM_SLOTS ; hsq->next_tag =HSQ_INVALID_TAG ;
@@ -363,7 +365,11 @@ int mmc_hsq_init(struct mmc_hsq *hsq, stfor (i =0 ; i <HSQ_NUM_SLOTS ; i++) hsq->tag_slot[i] =HSQ_INVALID_TAG ; -INIT_WORK (&hsq->retry_work, mmc_hsq_retry_handler); + ret =devm_work_autocancel (mmc_dev (mmc), &hsq->retry_work, + mmc_hsq_retry_handler); +if (ret) +return ret; +spin_lock_init (&hsq->lock);init_waitqueue_head (&hsq->wait_queue);
Greg Kroah-Hartman
maintainerPATCH 224/877 mmc: mmci: Fix use-after-free in busy-timeout work
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 2b19cf3e50cddaff07b657dae1a8f30f06032852 upstream.
ux500_busy_complete() can queue ux500_busy_timeout_work for an R1b command, but mmci_remove() never cancels it. The work can subsequently dereference the devm-allocated mmci_host after it has been released.
Mask the controller interrupts and disable the delayed work during removal. This drains any queued instance and stops an IRQ handler that is still in progress from queueing the work again once it has been disabled.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mmci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/host/mmci.c +3 -0
@@ -2520,6 +2520,9 @@ static void mmci_remove(struct amba_deviwritel (0 , host->base +MMCICOMMAND );writel (0 , host->base +MMCIDATACTRL ); +if (variant->busy_detect) +disable_delayed_work_sync (&host->ux500_busy_timeout_work); +mmci_dma_release (host);clk_disable_unprepare (host->clk);mmc_free_host (mmc);
Greg Kroah-Hartman
maintainerPATCH 225/877 mmc: mxcmmc: cancel data work and watchdog on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit d3a421c82412344022982d5b91ba23194a0a6f29 upstream.
mxcmci_remove() frees the host through the devm tail, but neither it nor mmc_remove_host() drains the driver's own asynchronous state. host->watchdog, a 10 s timer armed on the DMA path in mxcmci_setup_data(), is deleted only by the DMA- and IRQ-complete paths, which the remove path does not explicitly drain; it can therefore fire after the host is freed and dereference it in mxcmci_watchdog(). host->datawork, armed from the IRQ handler on the PIO path, is not cancelled by the remove path either.
Free the devm-registered IRQ, then cancel datawork and delete the watchdog in mxcmci_remove(), before dma_release_channel(). Freeing the IRQ first keeps a trailing handler from re-arming datawork between the cancel and the host free. Both callbacks are non-self-rearming.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mxcmmc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/host/mxcmmc.c +4 -0
@@ -1182,6 +1182,10 @@ static void mxcmci_remove(struct platformmc_remove_host (mmc); +devm_free_irq (&pdev->dev,platform_get_irq (pdev,0 ), host); +cancel_work_sync (&host->datawork); +timer_delete_sync (&host->watchdog); +if (host->pdata && host->pdata->exit) host->pdata->exit (&pdev->dev, mmc);
Greg Kroah-Hartman
maintainerPATCH 226/877 mmc: rtsx_pci_sdmmc: ignore broken write-protect on ThinkPad X260
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Maillard <[email protected]>
commit 9c182bc5d7817437a7d04ab96133f9191846d93d upstream.
The Realtek RTS522A card reader in the Lenovo ThinkPad X260 (subsystem 17aa:504a) incorrectly reports inserted SD cards as write-protected.
This causes the MMC core to expose the card as read-only:
mmcblk0: mmc0:aaaa SN256 238 GiB (ro)
and /sys/block/mmcblk0/ro reports 1.
Setting MMC_CAP2_NO_WRITE_PROTECT makes the card writable again. Limit the quirk to the affected Lenovo subsystem.
--- drivers/mmc/host/rtsx_pci_sdmmc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mmc/host/rtsx_pci_sdmmc.c +5 -0
@@ -1503,6 +1503,11 @@ static void realtek_init_host(struct rea mmc->caps = mmc->caps |MMC_CAP_AGGRESSIVE_PM ; mmc->caps2 =MMC_CAP2_NO_PRESCAN_POWERUP |MMC_CAP2_FULL_PWR_CYCLE |MMC_CAP2_NO_SDIO ; + +if (pcr->pci->device ==0x522a && + pcr->pci->subsystem_vendor ==PCI_VENDOR_ID_LENOVO && + pcr->pci->subsystem_device ==0x504a ) + mmc->caps2 |=MMC_CAP2_NO_WRITE_PROTECT ; mmc->max_current_330 =400 ; mmc->max_current_180 =800 ; mmc->ops = &realtek_pci_sdmmc_ops;
Greg Kroah-Hartman
maintainerPATCH 227/877 mmc: sdhci-of-aspeed: Remove children before releasing SDC resources
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 4396d70bb7fec531bcf934fed016b2f3300c670b upstream.
Probe failure and removal leave SDHCI child devices registered after the parent clock and managed resources are released.
Unregister the OF children in reverse order before disabling the parent clock on both paths. Use of_platform_device_destroy() because manual child creation does not set the flag required by of_platform_depopulate().
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/mmc/host/sdhci-of-aspeed.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-of-aspeed.c +4 -1
@@ -561,12 +561,14 @@ static int aspeed_sdc_probe(struct platfif (!cpdev) {of_node_put (child); ret = -ENODEV ; - goto err_clk; + goto err_children; } }return 0 ; +err_children: +device_for_each_child_reverse (&pdev->dev,NULL , of_platform_device_destroy); err_clk:clk_disable_unprepare (sdc->clk);return ret;
@@ -576,6 +578,7 @@ static void aspeed_sdc_remove(struct pla {struct aspeed_sdc *sdc =dev_get_drvdata (&pdev->dev); +device_for_each_child_reverse (&pdev->dev,NULL , of_platform_device_destroy);clk_disable_unprepare (sdc->clk); }
Greg Kroah-Hartman
maintainerPATCH 228/877 mmc: sdio_uart: fix xmit_fifo leak when the port table is full
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
commit 53823e25793a97d07e6e98e0904bbf74cac8bc76 upstream.
sdio_uart_add_port() allocates the transmit fifo before claiming a slot in sdio_uart_table[]. When all UART_NR slots are taken, it returns -EBUSY with the fifo still allocated, but the probe error path only kfree()s the port, leaking the transmit fifo.
Free the fifo in the failure path of sdio_uart_add_port() itself so the function retains nothing on error.
--- drivers/mmc/core/sdio_uart.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/core/sdio_uart.c +3 -0
@@ -104,6 +104,9 @@ static int sdio_uart_add_port(struct sdi }spin_unlock (&sdio_uart_table_lock); +if (ret) +kfifo_free (&port->xmit_fifo); +return ret; }
Greg Kroah-Hartman
maintainerPATCH 229/877 mmc: sh_mmcif: initialize IRQ-thread mutex before requesting interrupt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit d5ea0d226e8f0801d78702142a124d78c317d822 upstream.
The threaded IRQ handler can run before devm_request_threaded_irq() returns, but thread_lock was initialized afterwards. Initialize it before requesting either interrupt.
--- drivers/mmc/host/sh_mmcif.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mmc/host/sh_mmcif.c +1 -2
@@ -1461,6 +1461,7 @@ static int sh_mmcif_probe(struct platfor host->pd = pdev;spin_lock_init (&host->lock); +mutex_init (&host->thread_lock); mmc->ops = &sh_mmcif_ops;sh_mmcif_init_ocr (host);
@@ -1521,8 +1522,6 @@ static int sh_mmcif_probe(struct platfor } } -mutex_init (&host->thread_lock); - ret =mmc_add_host (mmc);if (ret <0 ) goto err_clk;
Greg Kroah-Hartman
maintainerPATCH 230/877 mmc: spi: reset bytes_xfered before retrying CRC failures
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 8b0cc8707f65e0f51912e764e1b309b2559db1ec upstream.
mmc_spi_data_do() updates data->bytes_xfered after each block has been transferred successfully. If a later block in the same data request fails with a CRC error, data->bytes_xfered may therefore contain the number of bytes completed before the failing block.
mmc_spi_request() has a private recovery path for such CRC failures. It sends STOP_TRANSMISSION, clears data->error and jumps back to crc_recover to issue the same command and data request again. However, it does not clear data->bytes_xfered before the retry.
If the retry succeeds, the request is completed with the bytes from the failed attempt still included in data->bytes_xfered. For a multi-block request this can make the completed request report more bytes than were transferred by the successful retry, and can even exceed the request size when most blocks completed before the CRC error.
This is most likely to be observed on MMC-over-SPI systems where long multi-block transfers occasionally hit a data CRC error but the mmc_spi-internal retry succeeds. The data itself is retried, but the completion accounting is not.
Clear data->bytes_xfered together with data->error before repeating the request so the final completion reports only the bytes transferred by the successful attempt.
--- drivers/mmc/host/mmc_spi.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/mmc_spi.c +1 -0
@@ -952,6 +952,7 @@ crc_recover: status =mmc_spi_command_send (host, mrq, &stop,0 ); crc_retry--; mrq->data->error =0 ; + mrq->data->bytes_xfered =0 ; goto crc_recover; }
Greg Kroah-Hartman
maintainerPATCH 231/877 mmc: sdhci_am654: Move tuning_loop to local variable
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit ff894dced1a7ad7523f9c65dbdb53d02474cca0f upstream.
The tuning_loop field in struct sdhci_am654_data is only used within sdhci_am654_platform_execute_tuning() as a loop counter that is initialized to 0 in sdhci_am654_init(). Since it shouldn't persist across function calls, otherwise every failure expends its "budget", move it to a local variable and remove the struct field along with the now-unnecessary initialization.
--- drivers/mmc/host/sdhci_am654.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci_am654.c +2 -5
@@ -152,7 +152,6 @@ struct sdhci_am654_data {u32 flags;u32 quirks;bool dll_enable; -u32 tuning_loop;#define SDHCI_AM654_QUIRK_FORCE_CDTEST BIT(0)#define SDHCI_AM654_QUIRK_DISABLE_HS400 BIT(1)
@@ -552,13 +551,14 @@ static int sdhci_am654_platform_execute_struct sdhci_am654_data *sdhci_am654 =sdhci_pltfm_priv (pltfm_host);unsigned char timing = host->mmc->ios.timing;struct device *dev =mmc_dev (host->mmc); +unsigned int tuning_loop =0 ;int itapdly;do { itapdly =sdhci_am654_do_tuning (host, opcode);if (itapdly >=0 )break ; - }while (++sdhci_am654->tuning_loop <RETRY_TUNING_MAX ); + }while (++tuning_loop <RETRY_TUNING_MAX );if (itapdly <0 ) {dev_err (dev,"Failed to find itapdly, fail tuning\n" );
@@ -776,9 +776,6 @@ static int sdhci_am654_init(struct sdhciregmap_update_bits (sdhci_am654->base,CTL_CFG_3 ,TUNINGFORSDR50_MASK ,TUNINGFORSDR50_MASK ); -/* Use to re-execute tuning */ - sdhci_am654->tuning_loop =0 ; - ret =sdhci_setup_host (host);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 232/877 mmc: sdhci_am654: Reset command and data lines on failed tuning
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit 7197d9107d9545730153b82ea5a411c5208b443f upstream.
The CMD/DATA reset after tuning should be performed regardless of whether tuning succeeded or failed, since tuning data may remain in the buffer in either case. Move the error return after the reset so that the controller is always cleaned up.
--- drivers/mmc/host/sdhci_am654.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mmc/host/sdhci_am654.c +1 -3
@@ -418,15 +418,13 @@ static int sdhci_am654_execute_tuning(ststruct sdhci_host *host =mmc_priv (mmc);int err =sdhci_execute_tuning (mmc, opcode); -if (err) -return err;/* * Tuning data remains in the buffer after tuning. * Do a command and data reset to get rid of it */ sdhci_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA ); -return 0 ; +return err; }static u32 sdhci_am654_cqhci_irq (struct sdhci_host *host,u32 intmask)
Greg Kroah-Hartman
maintainerPATCH 233/877 mmc: sdhci_am654: Clear ITAPDLY on tuning failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit c9f47cc8c37f7659897142ffe216c250fbc1d4ed upstream.
When tuning fails, stale ITAPDLY values can persist and interfere with subsequent I/O accesses, for example in DDR50 mode in cards with no tuning support. Move the ITAPDLY enable setting out of the tuning loop to after successful tuning, and explicitly clear ITAPDLY (delay and enable) when tuning fails so that we are sure only working values are actually left in hardware.
--- drivers/mmc/host/sdhci_am654.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci_am654.c +7 -5
@@ -503,7 +503,6 @@ static int sdhci_am654_do_tuning(struct {struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host);struct sdhci_am654_data *sdhci_am654 =sdhci_pltfm_priv (pltfm_host); -unsigned char timing = host->mmc->ios.timing;struct window fail_window[ITAPDLY_LENGTH ];struct device *dev =mmc_dev (host->mmc);u8 curr_pass, itap;
@@ -512,11 +511,8 @@ static int sdhci_am654_do_tuning(structmemset (fail_window,0 ,sizeof (fail_window)); -/* Enable ITAPDLY */ - sdhci_am654->itap_del_ena[timing] =0x1 ; -for (itap =0 ; itap <ITAPDLY_LENGTH ; itap++) { -sdhci_am654_write_itapdly (sdhci_am654, itap, sdhci_am654->itap_del_ena[timing]); +sdhci_am654_write_itapdly (sdhci_am654, itap,0x1 ); curr_pass = !mmc_send_tuning (host->mmc, opcode,NULL );
@@ -560,10 +556,16 @@ static int sdhci_am654_platform_execute_if (itapdly <0 ) {dev_err (dev,"Failed to find itapdly, fail tuning\n" ); +sdhci_am654_write_itapdly (sdhci_am654,0 ,0 ); + sdhci_am654->itap_del_ena[timing] =0 ; + sdhci_am654->itap_del_sel[timing] =0 ;return -1 ; }dev_dbg (dev,"Passed tuning, final itapdly=%d\n" , itapdly); + +/* Enable ITAPDLY */ + sdhci_am654->itap_del_ena[timing] =0x1 ;sdhci_am654_write_itapdly (sdhci_am654, itapdly, sdhci_am654->itap_del_ena[timing]);/* Save ITAPDLY */ sdhci_am654->itap_del_sel[timing] = itapdly;
Greg Kroah-Hartman
maintainerPATCH 234/877 mmc: sdhci_am654: Fallback to DT-provided itap delay on DDR50 tuning failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit 308d05225281d86150d88141990d6caf8c902349 upstream.
DDR50 mode is not required to support the tuning command CMD19, meaning that calibration may fail on cards that do not implement it, in which case a known-good itap delay value should be programmed into the host controller.
Do this by reading the (already defined) itap delay DT property for DDR50 and, if tuning fails for this mode, fall back to the DT-provided itap delay value. If the DT does not provide a value for DDR50 fallback then this simply disables using itapdly.
--- drivers/mmc/host/sdhci_am654.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci_am654.c +21 -5
@@ -127,7 +127,7 @@ static const struct timing_data td[] = {NULL , MMC_CAP_UHS_SDR104}, [MMC_TIMING_UHS_DDR50] = {"ti,otap-del-sel-ddr50", -NULL , +"ti,itap-del-sel-ddr50" , MMC_CAP_UHS_DDR50}, [MMC_TIMING_MMC_DDR52] = {"ti,otap-del-sel-ddr52", "ti,itap-del-sel-ddr52",
@@ -145,6 +145,8 @@ struct sdhci_am654_data {u32 otap_del_sel[ARRAY_SIZE (td)];u32 itap_del_sel[ARRAY_SIZE (td)];u32 itap_del_ena[ARRAY_SIZE (td)]; +u32 itap_del_sel_dt_ddr50; +u32 itap_del_ena_dt_ddr50;int clkbuf_sel;int trm_icp;int drv_strength;
@@ -555,10 +557,19 @@ static int sdhci_am654_platform_execute_ }while (++tuning_loop <RETRY_TUNING_MAX );if (itapdly <0 ) { -dev_err (dev,"Failed to find itapdly, fail tuning\n" ); -sdhci_am654_write_itapdly (sdhci_am654,0 ,0 ); - sdhci_am654->itap_del_ena[timing] =0 ; - sdhci_am654->itap_del_sel[timing] =0 ; +if (timing ==MMC_TIMING_UHS_DDR50 ) { +dev_dbg (dev,"Failed DDR50 tuning, fallback to DT ITAP\n" ); + sdhci_am654->itap_del_sel[timing] = sdhci_am654->itap_del_sel_dt_ddr50; + sdhci_am654->itap_del_ena[timing] = sdhci_am654->itap_del_ena_dt_ddr50; + }else { +dev_err (dev,"Failed to find itapdly, fail tuning\n" ); + sdhci_am654->itap_del_ena[timing] =0 ; + sdhci_am654->itap_del_sel[timing] =0 ; + } + +sdhci_am654_write_itapdly (sdhci_am654, + sdhci_am654->itap_del_sel[timing], + sdhci_am654->itap_del_ena[timing]);return -1 ; }
@@ -728,6 +739,11 @@ static int sdhci_am654_get_otap_delay(st } } + sdhci_am654->itap_del_sel_dt_ddr50 = + sdhci_am654->itap_del_sel[MMC_TIMING_UHS_DDR50 ]; + sdhci_am654->itap_del_ena_dt_ddr50 = + sdhci_am654->itap_del_ena[MMC_TIMING_UHS_DDR50 ]; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 235/877 Input: adp5588-keys - cache GPIO state before registering the gpiochip
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alvin Šipraga <[email protected]>
commit 21efadc62272cabee9bec27777ae75d84a9ca8a8 upstream.
So as not to clobber any pre-programmed GPIO state in the execution of its gpiochip ops, the driver caches things during probe time. However, since those ops can be called both during and immediately after the call to devm_gpiochip_add_data(), it is imperative that things are cached before that. That's not the case right now, so reorder the two steps to prevent any clobbering.
In the concrete example which motivated this change, a bootloader was preconfiguring an important GPIO output to HIGH before booting the kernel. Linux would then inadvertently set that output to LOW while configuring a GPIO hog on a discrete GPIO line within the same 8-bit bank (because the cached value was 0=LOW).
--- drivers/input/keyboard/adp5588-keys.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/input/keyboard/adp5588-keys.c +6 -6
@@ -446,12 +446,6 @@ static int adp5588_gpio_add(struct adp55mutex_init (&kpad->gpio_lock); - error =devm_gpiochip_add_data (dev, &kpad->gc, kpad); -if (error) { -dev_err (dev,"gpiochip_add failed: %d\n" , error); -return error; - } -for (i =0 ; i <=ADP5588_BANK (ADP5588_MAXGPIO ); i++) { kpad->dat_out[i] =adp5588_read (kpad->client,GPIO_DAT_OUT1 + i);
@@ -459,6 +453,12 @@ static int adp5588_gpio_add(struct adp55 kpad->pull_dis[i] =adp5588_read (kpad->client,GPIO_PULL1 + i); } + error =devm_gpiochip_add_data (dev, &kpad->gc, kpad); +if (error) { +dev_err (dev,"gpiochip_add failed: %d\n" , error); +return error; + } +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 236/877 Input: atkbd - skip deactivate for Xiaomi Redmi Book Pro 16 2026
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Turtanov <[email protected]>
commit aefbda23eeba234c3ff0f135dc5be6e294bd25a6 upstream.
The internal keyboard of the Xiaomi Redmi Book Pro 16 2026 (board TM2425) does not work: atkbd_probe() succeeds and every command is ACKed, but no scancodes ever arrive afterwards.
Testing on the hardware through serio_raw shows that ATKBD_CMD_RESET_DIS (0xF5) is the culprit. After 0xF5 the embedded controller keeps ACKing commands but stops delivering scancodes, and neither ATKBD_CMD_ENABLE (0xF4) nor ATKBD_CMD_RESET_BAT (0xFF) bring them back. Only re-enabling the keyboard interface at the controller level (i8042 command 0xAE, or rewriting the command byte as i8042_port_close() does) revives it. Running the init sequence without 0xF5 (0xED 0x00, 0xF3 0x00, 0xF4) keeps the keyboard working.
'i8042.dumbkbd=1' also works around this, but then the driver never writes to the keyboard and the LEDs cannot be controlled. Use the existing atkbd_deactivate_fixup quirk instead, as done for the sibling TM2424 by commit 3a046db33bb9 ("Input: atkbd - skip deactivate for Xiaomi Book Pro 14's internal keyboard"). Tested on v7.2: keyboard, Caps Lock LED and s2idle suspend/resume all work.
DMI: XIAOMI REDMI Book Pro 16 2026/TM2425, BIOS RMAPT6B0P0909 05/22/2026
--- drivers/input/keyboard/atkbd.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/input/keyboard/atkbd.c +8 -0
@@ -1975,6 +1975,14 @@ static const struct dmi_system_id atkbd_ }, .callback = atkbd_deactivate_fixup, }, + { + /* Xiaomi Redmi Book Pro 16 2026 (TM2425) */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "XIAOMI"), + DMI_MATCH(DMI_PRODUCT_NAME, "REDMI Book Pro 16 2026"), + }, + .callback = atkbd_deactivate_fixup, + }, { } };
Greg Kroah-Hartman
maintainerPATCH 237/877 Input: cyttsp5 - clamp the HID report size before memcpy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit 85f080fb87ed5cd3e46121be677f52c82f26a0ab upstream.
The size field comes from the device and is used as the memcpy() length into response_buf, which is CY_MAX_INPUT bytes.
--- drivers/input/touchscreen/cyttsp5.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/touchscreen/cyttsp5.c +1 -0
@@ -711,6 +711,7 @@ static irqreturn_t cyttsp5_handle_irq(in size =2 ; }else { report_id = ts->input_buf[2 ]; + size =min (size,CY_MAX_INPUT ); }switch (report_id) {
Greg Kroah-Hartman
maintainerPATCH 238/877 Input: evdev - zero absinfo before partial copy in EVIOCSABS
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
commit 8b852965b8eaf910c314dc346967ed82c8d4f235 upstream.
The EVIOCSABS handler copies at most the user supplied ioctl size into an uninitialized on-stack struct input_absinfo:
if (copy_from_user(&abs, p, min_t(size_t, size, sizeof(struct input_absinfo))))
The size comes from _IOC_SIZE() of the ioctl command and is therefore fully controlled by userspace. A short size leaves the trailing part of the structure holding whatever was on the kernel stack, and the whole structure is then stored into the device:
dev->absinfo[t] = abs;
EVIOCGABS hands that back to userspace, disclosing the stale stack bytes. Only the resolution field is currently cleared, which covers the legacy struct layout but not an arbitrarily short size.
Zero the structure before the copy so any part not supplied by the caller reads back as zero. The existing resolution fixup is kept, since it also handles a size that partially overlaps that field.
--- drivers/input/evdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/evdev.c +2 -0
@@ -1229,6 +1229,8 @@ static long evdev_do_ioctl(struct file * t =_IOC_NR (cmd) &ABS_MAX ; +memset (&abs,0 ,sizeof (abs)); +if (copy_from_user (&abs, p,min_t (size_t, size,sizeof (struct input_absinfo ))))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 239/877 Input: i8042 - add quirk for Acer Aspire Go 15 AG15-42P
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Sommers <[email protected]>
commit 25e424eb4ae1a662d9c3573218d06ac32f797fc5 upstream.
On the Acer Aspire Go 15 (AG15-42P), the internal keyboard drops out ~5 seconds after boot on both Linux and Linux-LTS kernels. Keystrokes on the built-in keyboard stop registering while the trackpad and external keyboards remain functional.
Testing confirms that booting with the i8042.reset kernel parameter resolves the issue and keeps the internal keyboard responsive.
Add SERIO_QUIRK_RESET_ALWAYS to i8042_dmi_quirk_table for the Acer Aspire AG15-42P to automatically apply this quirk on boot.
--- drivers/input/serio/i8042-acpipnpio.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/serio/i8042-acpipnpio.h +7 -0
@@ -261,6 +261,13 @@ static const struct dmi_system_id i8042_ { .matches = {DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Aspire AG15-42P"), + }, + .driver_data = (void *)(SERIO_QUIRK_RESET_ALWAYS ) + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), DMI_MATCH(DMI_PRODUCT_NAME, "Aspire ES1-132"), }, .driver_data = (void *)(SERIO_QUIRK_RESET_ALWAYS )
Greg Kroah-Hartman
maintainerPATCH 240/877 Input: rmi_smbus - fix out-of-bounds read in rmi_smb_write_block()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 51cfe54f815ae175c7d1126b983d4d7c89715004 upstream.
When chunking writes into SMBus blocks in rmi_smb_write_block(), the loop calculates block_len using the original total length (len) instead of the remaining length (cur_len).
If len is greater than 32 bytes (SMB_MAX_COUNT), block_len remains 32 for every iteration, even on the final partial chunk where fewer than 32 bytes remain. This causes smb_block_write() to read 32 bytes from the advanced data buffer pointer, reading past the end of the input buffer.
Fix this by calculating block_len using cur_len and advancing the buffer and address pointers by block_len.
--- drivers/input/rmi4/rmi_smbus.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/input/rmi4/rmi_smbus.c +5 -5
@@ -140,7 +140,7 @@ static int rmi_smb_write_block(struct rmu8 commandcode;struct rmi_smb_xport *rmi_smb = container_of(xport, struct rmi_smb_xport, xport); -int cur_len = (int )len; +size_t cur_len = len;mutex_lock (&rmi_smb->page_mutex);
@@ -148,7 +148,7 @@ static int rmi_smb_write_block(struct rm/* * break into 32 bytes chunks to write get command code */ -int block_len =min_t (int, len,SMB_MAX_COUNT ); +int block_len =min_t (size_t, cur_len,SMB_MAX_COUNT ); retval =rmi_smb_get_command_code (xport, rmiaddr, block_len, false, &commandcode);
@@ -161,9 +161,9 @@ static int rmi_smb_write_block(struct rm goto exit;/* prepare to write next block of bytes */ - cur_len -=SMB_MAX_COUNT ; - databuff +=SMB_MAX_COUNT ; - rmiaddr +=SMB_MAX_COUNT ; + cur_len -= block_len; + databuff += block_len; + rmiaddr += block_len; } exit:mutex_unlock (&rmi_smb->page_mutex);
Greg Kroah-Hartman
maintainerPATCH 241/877 Input: soc_button_array - fix MS Surface Pro 11 probe failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit ed22ad5fdbdbf9b4cb4ad3003f60314b5a5eb89d upstream.
On the MS Surface Pro 11 soc_button_array probing races with the GPIO driver probing. If soc_button_array wins the race then gpiod_get() returns EPROBE_DEFER, which should normally take care of retrying later, but the soc_button_array code deliberately ignores EPROBE_DEFER causing it to fail its probe() which causes the volume and power buttons to now work.
The ignoring of EPROBE_DEFER is there to deal with a problem specific to older Bay Trail (BYT) and Cherry Trail (CHT) tablets which often use this driver. Modify the error handling to only ignore EPROBE_DEFER on BYT and CHT platforms and propagate EPROBE_DEFER normally on other platforms.
--- drivers/input/misc/soc_button_array.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/input/misc/soc_button_array.c +11 -3
@@ -16,6 +16,7 @@#include <linux/gpio/consumer.h> #include <linux/gpio_keys.h> #include <linux/gpio.h> +#include <linux/platform_data/x86/soc.h> #include <linux/platform_device.h> static bool use_low_level_irq;
@@ -160,7 +161,7 @@ soc_button_device_create(struct platformstruct gpio_keys_platform_data *gpio_keys_pdata;const struct dmi_system_id *dmi_id;int invalid_acpi_index =-1 ; -int error, gpio, irq; +int error, gpio, irq =0 ;int n_buttons =0 ;for (info = button_info; info->name; info++)
@@ -191,8 +192,9 @@ soc_button_device_create(struct platform error =soc_button_lookup_gpio (&pdev->dev, info->acpi_index, &gpio, &irq);if (error || irq <0 ) {/* -* Skip GPIO if not present. Note we deliberately -* ignore -EPROBE_DEFER errors here. On some devices +* Propagate -EPROBE_DEFER, skip button on other errors. +* +* -EPROBE_DEFER is ignored on Bay & Cherry Trail. Here * Intel is using so called virtual GPIOs which are not * GPIOs at all but some way for AML code to check some * random status bits without need a custom opregion.
@@ -201,6 +203,12 @@ soc_button_device_create(struct platform* we do not have a driver for these so they will never * show up, therefore we ignore -EPROBE_DEFER. */ +if ((error == -EPROBE_DEFER || irq == -EPROBE_DEFER ) && + !(soc_intel_is_byt () ||soc_intel_is_cht ())) { + error = -EPROBE_DEFER ; + goto err_free_mem; + } +continue ; }
Greg Kroah-Hartman
maintainerPATCH 242/877 Input: soc_button_array - check btns_desc->package.count
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit fb5022278b6ea7f1838e3ef78028d5d5e3375f65 upstream.
Check that btns_desc->package.count is not 0 before accessing btns_desc->package.elements[0].
--- drivers/input/misc/soc_button_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/soc_button_array.c +1 -1
@@ -377,7 +377,7 @@ static struct soc_button_info *soc_butto } } -if (!btns_desc) { +if (!btns_desc || !btns_desc->package.count) {dev_err (dev,"ACPI Button Descriptors not found\n" ); button_info =ERR_PTR (-ENODEV ); goto out;
Greg Kroah-Hartman
maintainerPATCH 243/877 Input: synaptics - disable InterTouch on ThinkPad T440p (board id 2722)
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphaël Larocque <[email protected]>
commit 26eb3d92c7a4d7adb1ae1740ca6e8e100b11d1ec upstream.
The Lenovo ThinkPad T440p (PNP ID LEN0036, board id 2722) has a Synaptics touchpad whose SMBus companion is not ready at boot and takes roughly 200 seconds to appear. During this window the touchpad and TrackPoint are completely unresponsive on approximately 50% of boots, making the machine unusable until the companion finally registers.
The device is in the topbuttonpad_pnp_ids[] SMBus allowlist, so the kernel attempts to use SMBus/RMI4 mode by default. When the companion is not ready, psmouse_smbus_init() leaves breadcrumbs and returns -EAGAIN, the PS/2 fallback path is taken, but the device does not function properly until the companion appears and RMI4 takes over.
Disable SMBus InterTouch for board id 2722 so the touchpad and TrackPoint work immediately via PS/2 from boot. Users can still force SMBus with psmouse.synaptics_intertouch=1 if needed.
--- drivers/input/mouse/synaptics.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/input/mouse/synaptics.c +8 -0
@@ -1837,6 +1837,14 @@ static int synaptics_setup_intertouch(streturn -ENXIO ; } + +/* Disable intertouch on known-broken board revisions */ +if (info->board_id ==2722 ) { +psmouse_info (psmouse, +"Disabling intertouch for board id %u\n" , + info->board_id); +return -ENXIO ; + } }psmouse_info (psmouse,"Trying to set up SMBus access\n" );
Greg Kroah-Hartman
maintainerPATCH 244/877 Input: synaptics-rmi4 - fix GPF in suspend and resume when unbound
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit fe10579b6dc3f0dac61e51e1797cacbba5039ac2 upstream.
Transport drivers (such as rmi_i2c and rmi_spi) invoke rmi_driver_suspend() and rmi_driver_resume() on their child rmi_dev device during system power management events. However, transport drivers are fully registered and operational even if the physical RMI driver failed to bind or probe the rmi_dev device.
When rmi_driver_suspend() or rmi_driver_resume() is called on an unbound rmi_dev, dev_get_drvdata() returns NULL. Calling rmi_disable_irq() or rmi_enable_irq() without driver data attached causes a NULL pointer dereference and General Protection Fault when attempting to lock data->enabled_mutex.
Fix this by checking if driver data is attached to rmi_dev in rmi_driver_suspend() and rmi_driver_resume(), exiting early if no driver data is present.
--- drivers/input/rmi4/rmi_driver.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/input/rmi4/rmi_driver.c +13 -0
@@ -946,6 +946,15 @@ int rmi_driver_suspend(struct rmi_device {int retval; +/* +* Transport driver will try to suspend RMI device even if physical +* driver did not bind to the RMI device, because transport device +* (I2C, SPI) is fully registered and operational. Exit early if +* there is no driver data attached to the RMI device. +*/ +if (!dev_get_drvdata (&rmi_dev->dev)) +return 0 ; + retval =rmi_suspend_functions (rmi_dev);if (retval) dev_warn(&rmi_dev->dev, "Failed to suspend functions: %d\n",
@@ -960,6 +969,10 @@ int rmi_driver_resume(struct rmi_device {int retval; +/* Skip if not fully bound to RMI driver */ +if (!dev_get_drvdata (&rmi_dev->dev)) +return 0 ; +rmi_enable_irq (rmi_dev, clear_wake); retval =rmi_resume_functions (rmi_dev);
Greg Kroah-Hartman
maintainerPATCH 245/877 Input: zero ff_effect before compat copy in input_ff_effect_from_user
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
commit f84819ef8d66931ee3998fee3c4f03230f4cb6cc upstream.
In the compat path input_ff_effect_from_user() aliases the caller's native struct ff_effect with the smaller struct ff_effect_compat and copies only the compat sized prefix:
compat_effect = (struct ff_effect_compat *)effect; if (copy_from_user(compat_effect, buffer, sizeof(struct ff_effect_compat)))
The tail of the native structure is never written. Callers pass an uninitialized on-stack object, for example evdev_do_ioctl() for EVIOCSFF, so those bytes keep their previous stack contents. input_ff_upload() then stores the full native structure in ff->effects[id], from where a uinput based force feedback daemon can read it back via UI_BEGIN_FF_UPLOAD, disclosing kernel stack memory to userspace.
Zero the effect before the compat copy.
--- drivers/input/input-compat.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/input-compat.c +2 -0
@@ -75,6 +75,8 @@ int input_ff_effect_from_user(const char*/ compat_effect = (struct ff_effect_compat *)effect; +memset (effect,0 ,sizeof (*effect)); +if (copy_from_user (compat_effect, buffer,sizeof (struct ff_effect_compat )))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 246/877 hwmon: (hp-wmi-sensors) Fix use-after-free in fungible_show()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit e6cb0b4d4ecb8e71fd2200d907ab2e9663356f69 upstream.
nsensor->current_state is dynamically replaced as the sensor's state changes. update_numeric_sensor_from_wobj() does this by freeing the old string and installing a new one:
if (strcmp(trimmed, nsensor->current_state)) {
new_string = hp_wmi_strdup(dev, trimmed);
if (new_string) {
devm_kfree(dev, nsensor->current_state);
nsensor->current_state = new_string;
}
}This function is only ever called from hp_wmi_update_info() while state->lock is held, so the free-and-replace itself is properly serialized against concurrent updates.
fungible_show(), however, reads the same pointer after the lock has already been dropped:
err = hp_wmi_update_info(state, info);
if (err)
return err;
switch (prop) {
...
case HP_WMI_PROPERTY_CURRENT_STATE:
seq_printf(seqf, "%s\n", nsensor->current_state);
break;hp_wmi_update_info() takes state->lock internally and releases it before returning, so by the time fungible_show() dereferences nsensor->current_state in seq_printf(), no lock is held. Two processes reading a sensor's current_state debugfs entry at overlapping times (or one reading it while another read of the same sensor triggers a refresh) can race: one thread's seq_printf() can be part-way through printing the string at the moment another thread's call into update_numeric_sensor_from_wobj() frees it with devm_kfree() and installs a new pointer, causing a use-after-free read.
Take state->lock around the read in fungible_show() as well, so it can never run concurrently with the free-and-replace in update_numeric_sensor_from_wobj().
--- drivers/hwmon/hp-wmi-sensors.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/hp-wmi-sensors.c +2 -0
@@ -1247,7 +1247,9 @@ static int fungible_show(struct seq_filebreak ;case HP_WMI_PROPERTY_CURRENT_STATE : +mutex_lock (&state->lock);seq_printf (seqf,"%s\n" , nsensor->current_state); +mutex_unlock (&state->lock);break ;case HP_WMI_PROPERTY_UNIT_MODIFIER :
Greg Kroah-Hartman
maintainerPATCH 247/877 hwmon: (pmbus/core) increase number of phases and add new mask
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuno Sá <[email protected]>
commit 06bd6794b5fd2163880ac3bfe973d4cc61f359f3 upstream.
Increase the number of phases to 16 as a new upcoming device supports such a number.
While at it, add a new mask for controlling the source of the output voltage.
Note (groeck):
This patch was meant to prepare for support of MAX20826 and compatible devices, which support more than 10 phases per page. However, Sashiko reports that the mp2975 driver already supports up to 14 phases, and the mp2856 driver supports up to 12 phases. This already has the potential for out-of-bounds writes when probing the affected chips, making this patch a bug fix.
--- drivers/hwmon/pmbus/pmbus.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus.h +2 -1
@@ -241,6 +241,7 @@ enum pmbus_regs {/* * OPERATION */ +#define PB_OPERATION_CONTROL_V_SRC GENMASK(5, 4)#define PB_OPERATION_CONTROL_ON BIT(7)/*
@@ -385,7 +386,7 @@ enum pmbus_sensor_classes { };#define PMBUS_PAGES 32/* Per PMBus specification */ -#define PMBUS_PHASES 10/* Maximum number of phases per page */ +#define PMBUS_PHASES 16/* Maximum number of phases per page */ /* Functionality bit mask */ #define PMBUS_HAVE_VIN BIT(0)
Greg Kroah-Hartman
maintainerPATCH 248/877 hwmon: (pmbus/tps53679) Fix TPS53676 phase page decoding
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 1d12fb94ac0975566545871dda100df34df5f845 upstream.
tps53676_identify() reads the USER_DATA_03 phase configuration to count the phases assigned to each channel and derive the number of PMBus pages. In each 16-bit phase descriptor the channel (PAGE) is encoded in bit 4 and the firing order in bits 3:0, but the code tested bit 3 (0x08), which is part of the firing-order field.
TPS53676 supports up to seven phases, so firing-order bit 3 is never set. As a result the existing test classifies every enabled phase as channel A. On a dual-channel configuration the phases assigned to channel B are therefore miscounted as channel A and page 1 is not exposed.
Test the PAGE field (bit 4) instead.
--- drivers/hwmon/pmbus/tps53679.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/tps53679.c +1 -1
@@ -168,7 +168,7 @@ static int tps53676_identify(struct i2c_return -EIO ;for (i =0 ; i <2 *TPS53676_MAX_PHASES ; i +=2 ) {if (buf[i +1 ] &0x80 ) { -if (buf[i] &0x08 ) +if (buf[i] &BIT (4 )) phases_b++;else phases_a++;
Greg Kroah-Hartman
maintainerPATCH 249/877 hwmon: (pmbus/tps53679) Select page 0 for single-page TPS53676
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 089070b51ccbac411462a30a454690274c6e4270 upstream.
tps53676_identify() derives the number of PMBus pages but does not ensure that page 0 is selected for single-page configurations. pmbus_set_page() does not update the PAGE register when info->pages is 1, so if boot firmware leaves PAGE set to another value subsequent register accesses may target the wrong page.
For single-page devices, select page 0 explicitly.
--- drivers/hwmon/pmbus/tps53679.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/hwmon/pmbus/tps53679.c +9 -0
@@ -181,6 +181,15 @@ static int tps53676_identify(struct i2c_if (phases_b >0 ) { info->pages =2 ; info->phases[1 ] = phases_b; + }else { +/* +* pmbus_set_page() does not update the PAGE register on +* single-page devices, so select page 0 explicitly in case +* the boot firmware left the device on another page. +*/ + ret =i2c_smbus_write_byte_data (client,PMBUS_PAGE ,0 ); +if (ret <0 ) +return ret; }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 250/877 hwmon: (w83791d) remove fan/pwm 4-5 sysfs group on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 0ff9c7775e51ac6d47b1bb5c46f06b1434fe58a8 upstream.
When the fan/pwm 4-5 pins are not used as GPIO, w83791d_probe() creates the w83791d_group_fanpwm45 sysfs group on the I2C client device.
The probe error path removes this group when a later initialization step fails, but the normal remove path only removes w83791d_group. As a result, the optional fan/pwm 4-5 sysfs files can remain after the driver is unbound.
The callbacks associated with these files access the driver data, which is devm allocated and released after driver unbind. Leaving the sysfs files behind can therefore result in accesses to stale driver data.
Remove w83791d_group_fanpwm45 during normal teardown as well.
This issue was found by manual code inspection.
--- drivers/hwmon/w83791d.c | 1 + 1 file changed, 1 insertion(+)
drivers/hwmon/w83791d.c +1 -0
@@ -1415,6 +1415,7 @@ static void w83791d_remove(struct i2c_clstruct w83791d_data *data =i2c_get_clientdata (client);hwmon_device_unregister (data->hwmon_dev); +sysfs_remove_group (&client->dev.kobj, &w83791d_group_fanpwm45);sysfs_remove_group (&client->dev.kobj, &w83791d_group); }
Greg Kroah-Hartman
maintainerPATCH 251/877 hwmon: (w83793) release probe data through kref
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit c702a5f18b780e477eccbbab558e590e9673e4cb upstream.
w83793_probe() initializes data->kref to manage the lifetime of the driver data. The normal remove path drops the driver-owned reference with kref_put(), while watchdog users take and release additional references through the same kref.
However, the probe error path still frees data directly with kfree(). This bypasses the kref-managed lifetime and discards the initial reference without a matching kref_put(), leaving the reference accounting unbalanced.
Drop the probe-owned reference with kref_put() instead and let w83793_release_resources() perform the final free, matching the normal remove path.
This issue was found by manual code inspection.
--- drivers/hwmon/w83793.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/w83793.c +3 -1
@@ -1928,7 +1928,9 @@ exit_remove:for (i =0 ; i <ARRAY_SIZE (w83793_temp); i++)device_remove_file (dev, &w83793_temp[i].dev_attr); free_mem: -kfree (data); +mutex_lock (&watchdog_data_mutex); +kref_put (&data->kref, w83793_release_resources); +mutex_unlock (&watchdog_data_mutex); exit:return err; }
Greg Kroah-Hartman
maintainerPATCH 252/877 watchdog: da9063: fix suspend/resume handling of HW_RUNNING watchdog
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Jun <[email protected]>
commit 7cb575b71ab98194d2e040bded3a7281e089c5ed upstream.
da9063_wdt_suspend() and da9063_wdt_resume() only check watchdog_active(), when the watchdog is left running by the driver sets WDOG_HW_RUNNING in da9063_wdt_probe() but userspace never opens the device, so WDOG_ACTIVE remains cleared, the wdt_disable() will not be executed in da9063_wdt_suspend. In this case, the suspend callback is a no-op and the watchdog keeps counting during system suspend, leading to an unexpected system reset.
Check WDOG_HW_RUNNING and wdd,can fix this issue.
--- drivers/watchdog/da9063_wdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/da9063_wdt.c +2 -2
@@ -271,7 +271,7 @@ static int __maybe_unused da9063_wdt_susif (!use_sw_pm)return 0 ; -if (watchdog_active (wdd)) +if (watchdog_active (wdd) ||watchdog_hw_running (wdd))return da9063_wdt_stop (wdd);return 0 ;
@@ -284,7 +284,7 @@ static int __maybe_unused da9063_wdt_resif (!use_sw_pm)return 0 ; -if (watchdog_active (wdd)) +if (watchdog_active (wdd) ||watchdog_hw_running (wdd))return da9063_wdt_start (wdd);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 253/877 watchdog: digicolor: Avoid division by zero
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 400cb663ca019bae6eb878f06f1094ddf7c0b0df upstream.
clk_get_rate() could return 0. Avoid a division by zero panic.
Since get_timeleft() cannot propagate errors, check the clock rate early in probe() and cache the rate in the driver data as it is unlikely to change at runtime.
--- drivers/watchdog/digicolor_wdt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/watchdog/digicolor_wdt.c +9 -4
@@ -25,6 +25,7 @@ struct dc_wdt {void __iomem *base;struct clk *clk;spinlock_t lock; +unsigned long rate; };static unsigned timeout;
@@ -61,7 +62,7 @@ static int dc_wdt_start(struct watchdog_ {struct dc_wdt *wdt =watchdog_get_drvdata (wdog); -dc_wdt_set (wdt, wdog->timeout *clk_get_rate (wdt->clk)); +dc_wdt_set (wdt, wdog->timeout * wdt->rate);return 0 ; }
@@ -79,7 +80,7 @@ static int dc_wdt_set_timeout(struct wat {struct dc_wdt *wdt =watchdog_get_drvdata (wdog); -dc_wdt_set (wdt, t *clk_get_rate (wdt->clk)); +dc_wdt_set (wdt, t * wdt->rate); wdog->timeout = t;return 0 ;
@@ -90,7 +91,7 @@ static unsigned int dc_wdt_get_timeleft(struct dc_wdt *wdt =watchdog_get_drvdata (wdog);uint32_t count =readl_relaxed (wdt->base +TIMER_A_COUNT ); -return count /clk_get_rate (wdt->clk); +return count / wdt->rate; }static const struct watchdog_ops dc_wdt_ops = {
@@ -130,7 +131,11 @@ static int dc_wdt_probe(struct platform_ wdt->clk =devm_clk_get (dev,NULL );if (IS_ERR (wdt->clk))return PTR_ERR (wdt->clk); - dc_wdt_wdd.max_timeout =U32_MAX /clk_get_rate (wdt->clk); + + wdt->rate =clk_get_rate (wdt->clk); +if (!wdt->rate) +return -EINVAL ; + dc_wdt_wdd.max_timeout =U32_MAX / wdt->rate; dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout; dc_wdt_wdd.parent = dev;
Greg Kroah-Hartman
maintainerPATCH 254/877 watchdog: msc313e: Fix premature reset during timeout update
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 22737cfced627ffcb4b5c36d63bb3d4476f63213 upstream.
Updating the 32-bit hardware timeout requires writing to two 16-bit registers sequentially. If the watchdog is actively running, this non-atomic update might trigger a premature system reset.
Clear the watchdog counter before updating the registers to prevent the timer from timing out prematurely against an intermediate threshold.
--- drivers/watchdog/msc313e_wdt.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/watchdog/msc313e_wdt.c +6 -0
@@ -47,6 +47,9 @@ static void msc313e_wdt_set_hw_timeout(s {u32 t = timeout *clk_get_rate (priv->clk); +/* Clear before to prevent premature reset during non-atomic updates. */ +writew (1 , priv->base +REG_WDT_CLR ); +writew (t &0xffff , priv->base +REG_WDT_MAX_PRD_L );writew ((t >>16 ) &0xffff , priv->base +REG_WDT_MAX_PRD_H );writew (1 , priv->base +REG_WDT_CLR );
@@ -77,6 +80,9 @@ static int msc313e_wdt_stop(struct watch {struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); +/* Clear before to prevent premature reset during non-atomic updates. */ +writew (1 , priv->base +REG_WDT_CLR ); +writew (0 , priv->base +REG_WDT_MAX_PRD_L );writew (0 , priv->base +REG_WDT_MAX_PRD_H );writew (0 , priv->base +REG_WDT_CLR );
Greg Kroah-Hartman
maintainerPATCH 255/877 watchdog: msc313e: Propagate error code in resume()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 1d9763f34a85680db1e8233d654fdb85e5f897cc upstream.
If msc313e_wdt_start() fails during system resume, the error is currently ignored. Consequently, the watchdog isn't running without the user's knowledge.
Propagate the error code and print a message if msc313e_wdt_start() fails.
--- drivers/watchdog/msc313e_wdt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/watchdog/msc313e_wdt.c +7 -3
@@ -198,11 +198,15 @@ static int __maybe_unused msc313e_wdt_sustatic int __maybe_unused msc313e_wdt_resume (struct device *dev) {struct msc313e_wdt_priv *priv =dev_get_drvdata (dev); +int ret =0 ; -if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev)) -msc313e_wdt_start (&priv->wdev); +if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev)) { + ret =msc313e_wdt_start (&priv->wdev); +if (ret) +dev_err (dev,"Failed to restart watchdog (err=%d)\n" , ret); + } -return 0 ; +return ret; } static SIMPLE_DEV_PM_OPS(msc313e_wdt_pm_ops, msc313e_wdt_suspend, msc313e_wdt_resume);
Greg Kroah-Hartman
maintainerPATCH 256/877 watchdog: rtd119x: Avoid division by zero
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 5af7d2cbd20f893def03c8310a460ade66a5d822 upstream.
clk_get_rate() could return 0. Avoid a division by zero panic.
--- drivers/watchdog/rtd119x_wdt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/rtd119x_wdt.c +6 -1
@@ -98,6 +98,7 @@ static int rtd119x_wdt_probe(struct plat {struct device *dev = &pdev->dev;struct rtd119x_watchdog_device *data; +unsigned long rate; data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL );if (!data)
@@ -111,10 +112,14 @@ static int rtd119x_wdt_probe(struct platif (IS_ERR (data->clk))return PTR_ERR (data->clk); + rate =clk_get_rate (data->clk); +if (!rate) +return -EINVAL ; + data->wdt_dev.info = &rtd119x_wdt_info; data->wdt_dev.ops = &rtd119x_wdt_ops; data->wdt_dev.timeout =120 ; - data->wdt_dev.max_timeout =0xffffffff /clk_get_rate (data->clk); + data->wdt_dev.max_timeout =0xffffffff / rate; data->wdt_dev.min_timeout =1 ; data->wdt_dev.parent = dev;
Greg Kroah-Hartman
maintainerPATCH 257/877 watchdog: sp5100_tco: Fix pci_dev reference leak in sp5100_tco_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 88f113634028ca90a857031837d8061d1a9e1a7b upstream.
sp5100_tco_init() stores the PCI device matched by for_each_pci_dev() in the global sp5100_tco_pci and keeps its reference for the lifetime of the driver, but neither sp5100_tco_exit() nor the error paths of sp5100_tco_init() call pci_dev_put(), leaking the reference on driver registration failure and on every module load/unload cycle.
Drop the reference when the platform driver or device registration fails and when the module is unloaded.
--- drivers/watchdog/sp5100_tco.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/watchdog/sp5100_tco.c +5 -1
@@ -605,8 +605,10 @@ static int __init sp5100_tco_init(void)pr_info ("SP5100/SB800 TCO WatchDog Timer Driver\n" ); err =platform_driver_register (&sp5100_tco_driver); -if (err) +if (err) { +pci_dev_put (sp5100_tco_pci);return err; + } sp5100_tco_platform_device =platform_device_register_simple (TCO_DRIVER_NAME ,-1 ,NULL ,0 );
@@ -619,6 +621,7 @@ static int __init sp5100_tco_init(void) unreg_platform_driver:platform_driver_unregister (&sp5100_tco_driver); +pci_dev_put (sp5100_tco_pci);return err; }
@@ -626,6 +629,7 @@ static void __exit sp5100_tco_exit(void) {platform_device_unregister (sp5100_tco_platform_device);platform_driver_unregister (&sp5100_tco_driver); +pci_dev_put (sp5100_tco_pci); }module_init (sp5100_tco_init);
Greg Kroah-Hartman
maintainerPATCH 258/877 watchdog: starfive-wdt: Fix runtime PM leak in starfive_wdt_pm_start()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 8f0ca55016a7647109ae2bc91bcb346fc8b13785 upstream.
starfive_wdt_pm_start() takes a runtime PM reference with pm_runtime_get_sync(), which increments the usage counter even when it fails, and returns the error without dropping it again. The watchdog core does not invoke the stop callback when start fails, so the reference taken on the error path is leaked.
Use pm_runtime_resume_and_get() instead, which keeps the usage counter balanced when the resume fails.
--- drivers/watchdog/starfive-wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/starfive-wdt.c +1 -1
@@ -371,7 +371,7 @@ static void starfive_wdt_stop(struct stastatic int starfive_wdt_pm_start (struct watchdog_device *wdd) {struct starfive_wdt *wdt =watchdog_get_drvdata (wdd); -int ret =pm_runtime_get_sync (wdd->parent); +int ret =pm_runtime_resume_and_get (wdd->parent);if (ret <0 )return ret;
Greg Kroah-Hartman
maintainerPATCH 259/877 wifi: brcmsmac: fix UAF in brcms_free_timer()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
commit 1eeca1d5e0920fbdad6449768fd2d4364e714180 upstream.
brcms_free_timer() calls brcms_del_timer() which uses the non-synchronous cancel_delayed_work() to cancel the timer's underlying delayed work. If the work callback (_brcms_timer) is already running, cancel_delayed_work() returns false without waiting, and brcms_free_timer() proceeds to kfree(t) while the callback still accesses t through container_of().
Add an explicit cancel_delayed_work_sync() after brcms_del_timer() to guarantee that any in-flight callback has completed before the timer structure is freed.
--- drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c +4 -0
@@ -1569,6 +1569,10 @@ void brcms_free_timer(struct brcms_timer/* delete the timer in case it is active */ brcms_del_timer (t); +/* Ensure the callback has finished before freeing the timer +* structure, since brcms_del_timer() uses non-synchronous cancel. +*/ +cancel_delayed_work_sync (&t->dly_wrk);if (wl->timers == t) { wl->timers = wl->timers->next;
Greg Kroah-Hartman
maintainerPATCH 260/877 wifi: iwlegacy: fix broadcast stations deallocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislaw Gruszka <[email protected]>
commit b5526b780f8b297a76030410b96ba29153afb98f upstream.
On the error path of __il4965_up(), il_dealloc_bcast_stations() clears only IL_STA_UCODE_ACTIVE, leaving IL_STA_BCAST set. This causes the same broadcast stations to be deallocated again by __il4965_down().
This can occur when RF_KILL is toggled during driver startup.
To fix clear the entire 'used' field, since we will not do any other operations on the station.
--- drivers/net/wireless/intel/iwlegacy/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intel/iwlegacy/common.c +1 -1
@@ -2327,7 +2327,7 @@ il_dealloc_bcast_stations(struct il_privif (!(il->stations[i].used &IL_STA_BCAST ))continue ; - il->stations[i].used &= ~IL_STA_UCODE_ACTIVE ; + il->stations[i].used =0 ; il->num_stations--;BUG_ON (il->num_stations <0 );kfree (il->stations[i].lq);
Greg Kroah-Hartman
maintainerPATCH 261/877 wifi: libertas_tf: fix UAF in lbtf_free_adapter()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
commit bbb9a0ab96d44a64529aafc7a16de460a1712f6a upstream.
lbtf_free_adapter() calls lbtf_free_cmd_buffer() to free the command buffers before calling timer_delete_sync() to wait for the command timer callback. If the timer callback (command_timer_fn) is already running when lbtf_free_cmd_buffer() frees the command array, the callback dereferences priv->cur_cmd->cmdbuf which points to freed memory.
Swap the order so that timer_delete_sync() runs first, ensuring any in-flight callback has completed before the command buffers are freed.
--- drivers/net/wireless/marvell/libertas_tf/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/libertas_tf/main.c +1 -1
@@ -173,8 +173,8 @@ static int lbtf_init_adapter(struct lbtfstatic void lbtf_free_adapter (struct lbtf_private *priv) {lbtf_deb_enter (LBTF_DEB_MAIN ); -lbtf_free_cmd_buffer (priv);timer_delete_sync (&priv->command_timer); +lbtf_free_cmd_buffer (priv);lbtf_deb_leave (LBTF_DEB_MAIN ); }
Greg Kroah-Hartman
maintainerPATCH 262/877 wifi: rsi: fix heap OOB write on key removal
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit e6c5ed7a98d7bc8b0f7918246f1c90ddb3f79dfa upstream.
When a key is removed (data == NULL), rsi_hal_load_key() runs:
memset(&set_key[FRAME_DESC_SZ], 0, frame_len - FRAME_DESC_SZ);
set_key is a struct rsi_set_key *, so the subscript is scaled by sizeof(struct rsi_set_key) (160 bytes): &set_key[FRAME_DESC_SZ] is skb->data + 2560, and the memset writes 144 zero bytes starting 2.4KB past the end of the 160-byte skb data buffer, corrupting unrelated heap objects. The intended byte offset would have been (u8 *)set_key + FRAME_DESC_SZ.
The write fires on every DISABLE_KEY callback, so plain disconnects, roams and interface teardowns trigger it on real networks.
The memset is redundant: the whole buffer is zeroed right after allocation, so the frame sent to the device is byte-identical without it. Drop the else branch; normal operation is unaffected.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/net/wireless/rsi/rsi_91x_mgmt.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/wireless/rsi/rsi_91x_mgmt.c +0 -2
@@ -852,8 +852,6 @@ int rsi_hal_load_key(struct rsi_common *memcpy (set_key->tx_mic_key, &data[16 ],8 );memcpy (set_key->rx_mic_key, &data[24 ],8 ); } - }else { -memset (&set_key[FRAME_DESC_SZ ],0 , frame_len -FRAME_DESC_SZ ); }skb_put (skb, frame_len);
Greg Kroah-Hartman
maintainerPATCH 263/877 wifi: wlcore: release runtime PM ref on regdomain config failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 8a1f3cf89ddcc700e25afe42cfad333059adcc94 upstream.
wlcore_regdomain_config() gets a runtime PM reference before sending the regulatory-domain command. When wlcore_cmd_regdomain_config_locked() fails, the function queues recovery and returns without dropping that reference.
Release the reference after handling the command result so both success and failure paths balance the preceding pm_runtime_resume_and_get(). The recovery worker takes a separate runtime PM reference and cannot release the reference held here.
--- drivers/net/wireless/ti/wlcore/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/wireless/ti/wlcore/main.c +1 -3
@@ -3718,10 +3718,8 @@ void wlcore_regdomain_config(struct wl12 goto out; ret =wlcore_cmd_regdomain_config_locked (wl); -if (ret <0 ) { +if (ret <0 )wl12xx_queue_recovery_work (wl); - goto out; - }pm_runtime_mark_last_busy (wl->dev);pm_runtime_put_autosuspend (wl->dev);
Greg Kroah-Hartman
maintainerPATCH 264/877 wifi: wilc1000: fix out-of-bounds read in P2P public action frames
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memis <[email protected]>
commit ba6cb7c0868a412c2eb68e8efd5aa38bfb258a14 upstream.
wilc_wfi_p2p_rx() and mgmt_tx() start parsing a frame once ieee80211_is_public_action() returns true. That helper only verifies the frame is long enough for the action category field, that is offsetofend(struct ieee80211_mgmt, u.action.category), 25 bytes. Both functions then read the P2P public action header up to oui_subtype at offset 30 and pass "size - ie_offset" to cfg80211_find_vendor_ie(), where ie_offset is offsetof(struct ieee80211_mgmt, u) + sizeof(*d), i.e. 32.
A public action frame of 25 to 31 bytes passes the check but is shorter than that 32 byte header, so oui_subtype can be read out of bounds, and because the length is unsigned, "size - ie_offset" underflows to a value close to 4 GiB. cfg80211_find_vendor_ie() takes an unsigned int length, so even the size_t subtraction in mgmt_tx() is truncated to the same value. It then walks far past the buffer searching for a vendor element until it reaches unmapped memory.
In the receive path the frame arrives over the air and needs no association, so a nearby unauthenticated device can crash the host while it is in P2P listen. Reject frames shorter than the P2P public action header in both paths before dereferencing it.
--- drivers/net/wireless/microchip/wilc1000/cfg80211.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +14 -0
@@ -1066,6 +1066,13 @@ void wilc_wfi_p2p_rx(struct wilc_vif *viif (!ieee80211_is_public_action ((struct ieee80211_hdr *)buff, size)) goto out_rx_mgmt; +/* ieee80211_is_public_action() only validates up to the category +* byte, so reject frames too short for the P2P public action header +* before dereferencing it or computing size - ie_offset. +*/ +if (size < ie_offset) + goto out_rx_mgmt; + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);if (d->oui_subtype !=GO_NEG_REQ && d->oui_subtype !=GO_NEG_RSP && d->oui_subtype !=P2P_INV_REQ && d->oui_subtype !=P2P_INV_RSP )
@@ -1214,6 +1221,13 @@ static int mgmt_tx(struct wiphy *wiphy, goto out_set_timeout; } +/* ieee80211_is_public_action() only validates up to the category +* byte, so reject frames too short for the P2P public action header +* before dereferencing it or computing len - ie_offset. +*/ +if (len < ie_offset) + goto out_set_timeout; + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);if (d->oui_type !=WLAN_OUI_TYPE_WFA_P2P || d->oui_subtype !=GO_NEG_CONF ) {
Greg Kroah-Hartman
maintainerPATCH 265/877 wifi: wilc1000: fix RX buffer OOB-write in wilc_wlan_handle_isr_ext()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit c1ba7f7f18465e259cf1b4d9c73fc73853d7f790 upstream.
wilc_wlan_handle_isr_ext() takes the RX transfer size from the device-reported interrupt status register (a 15-bit field shifted left by 2, up to 131068 bytes) and reads that many bytes from the device into rx_buffer, which is only WILC_RX_BUFF_SIZE (96K) large. The wrap check only handles the current offset; the size itself is never compared against the buffer, so a bogus SDIO device can make the driver OOB-write rx_buffer by up to ~32K with data it controls.
The oversized transfer also leaves rx_buffer_offset past the end of the buffer, after which the unsigned wrap check stops working and the overflow can repeat.
Drop any transfer whose size exceeds the RX buffer, acknowledging the data interrupt and re-arming the RX engine so the bogus frame is discarded and reception can continue. This also restores the rx_buffer_offset <= WILC_RX_BUFF_SIZE invariant the wrap check relies on.
This is not expected to change driver behavior in most cases:
without this check, an oversized transfer would most likely corrupt neighboring kernel memory instead of completing anyway, and the drop path performs the same interrupt acknowledgment and RX engine re-arming as the normal path, so subsequent transfers are received unaffected.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/net/wireless/microchip/wilc1000/wlan.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/wireless/microchip/wilc1000/wlan.c +9 -0
@@ -1035,6 +1035,15 @@ static void wilc_wlan_handle_isr_ext(strif (size <=0 )return ; +/* A size exceeding the RX buffer is bogus; drop the transfer +* instead of overflowing the buffer. +*/ +if (size >WILC_RX_BUFF_SIZE ) { + wilc->hif_func->hif_clear_int_ext (wilc, +DATA_INT_CLR |ENABLE_RX_VMM ); +return ; + } +if (WILC_RX_BUFF_SIZE - offset < size) offset =0 ;
Greg Kroah-Hartman
maintainerPATCH 266/877 wifi: p54: validate curve data length in the calibration curve converters
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit ce858fa6b8a214dee5adb82358885fa024cdd887 upstream.
p54_convert_rev0() and p54_convert_rev1() read calibration curve data from the device-supplied EEPROM entry using channel and points-per-channel counts taken verbatim from that same entry, so an entry that declares more data than it carries drives an out-of-bounds read past the EEPROM buffer (verified with a KASAN reproducer of the conversion loop). The sibling converters p54_convert_output_limits() and p54_convert_db() already validate their counts against the entry length; this path was missed.
Reject the entry when the counts do not fit in the entry data.
--- drivers/net/wireless/intersil/p54/eeprom.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/wireless/intersil/p54/eeprom.c +15 -4
@@ -418,17 +418,22 @@ free: }static int p54_convert_rev0 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev0 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +2 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kmalloc (sizeof (*priv->curve_data) + cd_len,GFP_KERNEL );if (!priv->curve_data)
@@ -470,17 +475,22 @@ static int p54_convert_rev0(struct ieee8 }static int p54_convert_rev1 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev1 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +3 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kzalloc (cd_len +sizeof (*priv->curve_data),GFP_KERNEL );if (!priv->curve_data)
@@ -767,6 +777,7 @@ int p54_parse_eeprom(struct ieee80211_hwcase PDR_PRISM_PA_CAL_CURVE_DATA : {struct pda_pa_curve_data *curve_data = (struct pda_pa_curve_data *)entry->data; +if (data_len <sizeof (*curve_data)) { err = -EINVAL ; goto err;
@@ -774,10 +785,10 @@ int p54_parse_eeprom(struct ieee80211_hwswitch (curve_data->cal_method_rev) {case 0 : - err =p54_convert_rev0 (dev, curve_data); + err =p54_convert_rev0 (dev, curve_data, data_len);break ;case 1 : - err =p54_convert_rev1 (dev, curve_data); + err =p54_convert_rev1 (dev, curve_data, data_len);break ;default : wiphy_err(dev->wiphy,
Greg Kroah-Hartman
maintainerPATCH 267/877 wifi: p54: require a full exp_if record in PDR_INTERFACE_LIST
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit d8efd84f49379ed28624098821f80e992657d935 upstream.
The PDR_INTERFACE_LIST loop only checks that the record start is within the entry before reading an entire struct exp_if from it. A truncated trailing record makes the if_id/variant reads cross the entry boundary into the heap beyond the EEPROM buffer (verified with a KASAN reproducer of the loop). The variant also feeds the synth front-end selection, so this is not only a leak.
Advance only while a full record still fits in the entry.
--- drivers/net/wireless/intersil/p54/eeprom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/intersil/p54/eeprom.c +2 -1
@@ -816,7 +816,8 @@ int p54_parse_eeprom(struct ieee80211_hwbreak ;case PDR_INTERFACE_LIST : tmp = entry->data; -while ((u8 *)tmp < entry->data + data_len) { +while ((u8 *)tmp +sizeof (struct exp_if ) <= + entry->data + data_len) {struct exp_if *exp_if = tmp;if (exp_if->if_id ==cpu_to_le16 (IF_ID_ISL39000 )) synth =le16_to_cpu (exp_if->variant);
Greg Kroah-Hartman
maintainerPATCH 268/877 wifi: mwifiex: bound the pairwise-cipher OUI walk to the IE length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit e667aee1c192d67d27c803007bfa9c6e0873e959 upstream.
mwifiex_search_oui_in_ie() reads a pairwise-cipher (PTK) count from a beacon/probe-response RSN or WPA information element and then walks that many 4-byte OUIs, comparing each with memcmp(). The count comes straight from the (attacker-supplied) IE and is never checked against the element's own length, and the callers admit the element on element_id alone (has_ieee_hdr() / has_vendor_hdr(), no length check). A crafted RSN/WPA IE with a large pairwise count therefore makes the walk read up to 255 * 4 bytes past the element -- an out-of-bounds read of the kmemdup()'d beacon buffer, reachable from any AP whose beacon/probe response is processed during scan-result parsing.
Pass the number of IE bytes available at the OUI list and bound the walk to the element. Keep the length signed and reject a negative value before any unsigned arithmetic, so a small or zero IE length cannot underflow to a large size_t and defeat the bound.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/wireless/marvell/mwifiex/scan.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +22 -3
@@ -104,12 +104,24 @@ has_vendor_hdr(struct ieee_types_vendor_* a given oui in PTK. */ static u8 -mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui) +mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui,int ie_len) { +const size_t ptk_body_offset = offsetof(struct ie_body , ptk_body);u8 count; +/* ie_len is the number of bytes available at iebody. Keep it signed +* and reject a negative (underflowed) length before the unsigned +* comparisons below, so a small or zero IE length cannot wrap. +*/ +if (ie_len <0 || (size_t )ie_len < ptk_body_offset) +return MWIFIEX_OUI_NOT_PRESENT ; + count = iebody->ptk_cnt[0 ]; +/* Reject an OUI count whose list would run past the element. */ +if (ptk_body_offset + count *sizeof (iebody->ptk_body) > (size_t )ie_len) +return MWIFIEX_OUI_NOT_PRESENT ; +/* There could be multiple OUIs for PTK hence 1) Take the length. 2) Check all the OUIs for AES.
@@ -143,11 +155,14 @@ mwifiex_is_rsn_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_ieee_hdr (bss_desc->bcn_rsn_ie,WLAN_EID_RSN )) { +int ie_len = (int )bss_desc->bcn_rsn_ie->ieee_hdr.len - +RSN_GTK_OUI_OFFSET ; + iebody = (struct ie_body *) (((u8 *) bss_desc->bcn_rsn_ie->data) +RSN_GTK_OUI_OFFSET ); oui = &mwifiex_rsn_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
@@ -169,10 +184,14 @@ mwifiex_is_wpa_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_vendor_hdr (bss_desc->bcn_wpa_ie,WLAN_EID_VENDOR_SPECIFIC )) { +int ie_len = (int )bss_desc->bcn_wpa_ie->vend_hdr.len - + (int )sizeof (bss_desc->bcn_wpa_ie->vend_hdr.oui) - +WPA_GTK_OUI_OFFSET ; + iebody = (struct ie_body *)((u8 *)bss_desc->bcn_wpa_ie->data +WPA_GTK_OUI_OFFSET ); oui = &mwifiex_wpa_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
Greg Kroah-Hartman
maintainerPATCH 269/877 wifi: mwifiex: validate scan response extents
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit 3687d7d48070838cc2953431b3a27717cab0aaf6 upstream.
mwifiex_ret_802_11_scan() subtracts the fixed response fields and the firmware-provided BSS length from resp->size without first proving that either extent fits. A short response or oversized BSS length can therefore underflow tlv_buf_size and make the TLV parser walk beyond the command response.
Compute the fixed extent from the selected normal or background scan response. Validate that the fixed fields and BSS data fit before deriving the TLV extent and entering the parser.
--- drivers/net/wireless/marvell/mwifiex/scan.c | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +19 -10
@@ -2117,6 +2117,7 @@ int mwifiex_ret_802_11_scan(struct mwifiu32 bytes_left;u32 idx;u32 tlv_buf_size; +size_t fixed_size;struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;struct chan_band_param_set *chan_band;u8 is_bgscan_resp;
@@ -2132,6 +2133,14 @@ int mwifiex_ret_802_11_scan(struct mwifielse scan_rsp = &resp->params.scan_resp; + scan_resp_size =le16_to_cpu (resp->size); + fixed_size = scan_rsp->bss_desc_and_tlv_buffer - (u8 *)resp; +if (scan_resp_size < fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: response is too short\n" ); + ret =-1 ; + goto check_next_scan; + }if (scan_rsp->number_of_sets >MWIFIEX_MAX_AP ) { mwifiex_dbg(adapter, ERROR,
@@ -2149,8 +2158,6 @@ int mwifiex_ret_802_11_scan(struct mwifi"info: SCAN_RESP: bss_descript_size %d\n" , bytes_left); - scan_resp_size =le16_to_cpu (resp->size); -mwifiex_dbg (adapter,INFO ,"info: SCAN_RESP: returned %d APs before parsing\n" , scan_rsp->number_of_sets);
@@ -2158,15 +2165,17 @@ int mwifiex_ret_802_11_scan(struct mwifi bss_info = scan_rsp->bss_desc_and_tlv_buffer;/* -* The size of the TLV buffer is equal to the entire command response -* size (scan_resp_size) minus the fixed fields (sizeof()'s), the -* BSS Descriptions (bss_descript_size as bytesLef) and the command -* response header (S_DS_GEN) +* The TLV buffer follows the command-specific fixed fields and the BSS +* descriptions. Background-scan responses have an additional fixed +* field before scan_rsp, which is included in fixed_size. */ - tlv_buf_size = scan_resp_size - (bytes_left - +sizeof (scan_rsp->bss_descript_size) - +sizeof (scan_rsp->number_of_sets) - +S_DS_GEN ); +if (bytes_left > scan_resp_size - fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: BSS data exceeds response\n" ); + ret =-1 ; + goto check_next_scan; + } + tlv_buf_size = scan_resp_size - fixed_size - bytes_left; tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp-> bss_desc_and_tlv_buffer +
Greg Kroah-Hartman
maintainerPATCH 270/877 wifi: mwifiex: prevent authentication frame length truncation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
commit fa00193eb991f92b007aefe7afb6a7566976dacf upstream.
mwifiex_cfg80211_authenticate() derives the authentication frame length from req->ie_len and req->auth_data_len, both of type size_t, but stores it in a u16.
NL80211_ATTR_AUTH_DATA only has a minimum length policy. Since nla_len is a u16, a single attribute can carry up to 65531 bytes of payload, so the sum can exceed U16_MAX before it is assigned to pkt_len. The truncated pkt_len determines the skb frame area, while the copy length remains req->auth_data_len - 4, resulting in a heap buffer overflow.
For example, with auth_data_len equal to 65510 and no IEs, the sum is 65546. It is truncated to 10 and then reduced by four to 6. The driver appends only six bytes to the skb with skb_put(), but then copies 65506 user-provided bytes into the authentication body.
Reaching this path requires CAP_NET_ADMIN in the user namespace owning the network namespace, an up station netdev, and a suitable BSS/SAE authentication request.
Compute the length in size_t, reject values that cannot be represented by the firmware's u16 frame length field, and only then assign it to pkt_len.
--- drivers/net/wireless/marvell/mwifiex/cfg80211.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/cfg80211.c +10 -2
@@ -4278,6 +4278,7 @@ mwifiex_cfg80211_authenticate(struct wipstruct mwifiex_adapter *adapter = priv->adapter;struct sk_buff *skb;u16 pkt_len, auth_alg; +size_t frame_len;int ret;struct mwifiex_ieee80211_mgmt *mgmt;struct mwifiex_txinfo *tx_info;
@@ -4350,10 +4351,17 @@ mwifiex_cfg80211_authenticate(struct wipmwifiex_cancel_scan (adapter); - pkt_len = (u16 )req->ie_len + req->auth_data_len + + frame_len = req->ie_len + req->auth_data_len +MWIFIEX_MGMT_HEADER_LEN +MWIFIEX_AUTH_BODY_LEN ;if (req->auth_data_len >=4 ) - pkt_len -=4 ; + frame_len -=4 ; + +if (frame_len >U16_MAX ) { +mwifiex_dbg (priv->adapter,ERROR , +"auth frame too long: %zu bytes\n" , frame_len); +return -EINVAL ; + } + pkt_len = frame_len; skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN + MWIFIEX_MGMT_FRAME_HEADER_SIZE +
Greg Kroah-Hartman
maintainerPATCH 271/877 wifi: mwifiex: validate action frame fixed fields
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
commit 1c25bfad93e69ce13f744a2fb919f02ea396a985 upstream.
mwifiex_process_mgmt_packet() accepts an rx_pkt_length as small as a four-address struct ieee80211_hdr plus the two-byte firmware length prefix. After stripping the prefix, mwifiex_parse_mgmt_packet() can receive a frame equal to sizeof(struct ieee80211_hdr).
For action frames, the parser reads the category byte immediately after that header and, for a public action frame, reads the following action code byte without verifying that either field is present. A truncated frame can therefore make the parser consume up to two bytes past the firmware-declared frame length. If those bytes look like a TDLS discovery response, the malformed frame can spuriously update peer signal state.
Require the category and public action-code fields before reading them. Use sizeof(*ieee_hdr) so the checks and field accesses directly match the firmware four-address layout being parsed before address4 is removed.
--- drivers/net/wireless/marvell/mwifiex/util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/util.c +8 -2
@@ -335,10 +335,16 @@ mwifiex_parse_mgmt_packet(struct mwifiexswitch (stype) {case IEEE80211_STYPE_ACTION : - category = *(payload +sizeof (struct ieee80211_hdr )); +if (len <sizeof (*ieee_hdr) +1 ) +return -1 ; + + category = *(payload +sizeof (*ieee_hdr));switch (category) {case WLAN_CATEGORY_PUBLIC : - action_code = *(payload +sizeof (struct ieee80211_hdr ) +if (len <sizeof (*ieee_hdr) +2 ) +return -1 ; + + action_code = *(payload +sizeof (*ieee_hdr) +1 );if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) { addr2 = ieee_hdr->addr2;
Greg Kroah-Hartman
maintainerPATCH 272/877 wifi: mac80211: avoid WARN in set_bitrate_mask when sdata not in driver
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rik van Riel <[email protected]>
commit da2ca406f45a6e21760243152ed8d2e8e72915c2 upstream.
ieee80211_set_bitrate_mask() checks if the interface is running via ieee80211_sdata_running(), but it does not check if the interface is still present in the driver.
When sdata is running but IEEE80211_SDATA_IN_DRIVER is not set, the call reaches drv_set_bitrate_mask() in driver-ops.h which hits
wlan1: Failed check-sdata-in-driver check, flags: 0x0
WARNING: net/mac80211/driver-ops.h:884 at drv_set_bitrate_mask
Syzkaller triggers this via wext SIOCSIWRATE ioctl. The Call Trace shows wext_ioctl_dispatch() in wext-core.c dispatching the ioctl, calling ioctl_standard_call() for SIOCSIWRATE, which calls cfg80211_wext_siwrate() in wext-compat.c. That builds a bitrate mask and calls rdev_set_bitrate_mask() which ends up in ieee80211_set_bitrate_mask() in cfg.c. The interface is marked running via SDATA_STATE_RUNNING but flags is 0, so check_sdata_in_driver() fails.
When the interface is being torn down, or when wext ioctl is issued during interface bringup before drv_add_interface() sets IN_DRIVER, the running check passes while IN_DRIVER is clear.
Check IEEE80211_SDATA_IN_DRIVER in ieee80211_set_bitrate_mask() before calling the driver, returning -ENETDOWN. This avoids the WARN_ONCE in driver-ops.h and matches other cfg.c operations that bail early when not in driver.
This change should be safe because wiphy mutex is held in cfg80211_wext_siwrate() via guard(wiphy), and IN_DRIVER is set/cleared under RTNL and wiphy paths in drv_add_interface() and drv_remove_interface() in driver-ops.c, so the check is race-free against driver add/remove. Returning -ENETDOWN is the same error other not-running paths use and does not introduce new locking.
--- net/mac80211/cfg.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/cfg.c +3 -0
@@ -3426,6 +3426,9 @@ static int ieee80211_set_bitrate_mask(stif (!ieee80211_sdata_running (sdata))return -ENETDOWN ; +if (!(sdata->flags &IEEE80211_SDATA_IN_DRIVER )) +return -ENETDOWN ; +/* * If active validate the setting and reject it if it doesn't leave * at least one basic rate usable, since we really have to be able
Greg Kroah-Hartman
maintainerPATCH 273/877 drm/gud: fix out-of-bounds write in gud_plane_atomic_check()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sajal Gupta <[email protected]>
commit 59ced288fcba9e91bd38e61a972ad782c4edb7d0 upstream.
The plane property loop uses req->properties[num_properties + i] as write index while simultaneously incrementing num_properties inside the loop. At iteration i, num_properties has also incremented by i, so the write is done at initial_num_properties + 2*i, skipping every other index and advancing by 2 per iteration.
With just 2 connector and 32 plane properties the last write happens at index 64, one slot past the end of the 64-slot (indices 0–63) allocation. A USB device can trigger OOB by advertising the maximum number of properties.
Fix by dropping the redundant + i; num_properties is already the correct running index, as gud_connector_fill_properties() fills the preceding slots.
--- drivers/gpu/drm/gud/gud_pipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/gud/gud_pipe.c +2 -2
@@ -544,8 +544,8 @@ int gud_pipe_check(struct drm_simple_dis goto out; } - req->properties[num_properties + i].prop =cpu_to_le16 (prop); - req->properties[num_properties + i].val =cpu_to_le64 (val); + req->properties[num_properties].prop =cpu_to_le16 (prop); + req->properties[num_properties].val =cpu_to_le64 (val); num_properties++; }
Greg Kroah-Hartman
maintainerPATCH 274/877 drm/msm/adreno: fix autosuspend cleanup during teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 6fbbf1e152f34ad3913e4a6476680aba672c5068 upstream.
adreno_gpu_init() calls pm_runtime_use_autosuspend(), but adreno_gpu_cleanup() does not call the matching pm_runtime_dont_use_autosuspend() during teardown.
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without calling pm_runtime_dont_use_autosuspend() during teardown, this reference is not dropped and usage_count remains unbalanced.
The documentation for pm_runtime_use_autosuspend() also notes that it is important to undo it with pm_runtime_dont_use_autosuspend() at driver exit time, unless runtime PM was initially enabled with devm_pm_runtime_enable().
Add the missing pm_runtime_dont_use_autosuspend() call to adreno_gpu_cleanup().
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/745110/
--- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -0
@@ -1141,6 +1141,8 @@ void adreno_gpu_cleanup(struct adreno_gpfor (i =0 ; i <ARRAY_SIZE (adreno_gpu->info->fw); i++)release_firmware (adreno_gpu->fw[i]); +pm_runtime_dont_use_autosuspend (&gpu->pdev->dev); +if (priv &&pm_runtime_enabled (&priv->gpu_pdev->dev))pm_runtime_disable (&priv->gpu_pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 275/877 drm/msm/hdmi_phy: fix runtime PM cleanup on probe failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit f4fae975db08a9aeec0b15e145c7d4d0fe02a0ec upstream.
msm_hdmi_phy_probe() enables runtime PM before enabling the PHY resources and initializing the PLL, but failures from either operation return without calling the matching pm_runtime_disable().
The remove path disables runtime PM, but it is not called when probe fails. As a result, runtime PM remains enabled after an unsuccessful probe.
Route failures after pm_runtime_enable() through a common error path and disable runtime PM before returning.
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/753043/
--- drivers/gpu/drm/msm/hdmi/hdmi_phy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/hdmi/hdmi_phy.c +6 -2
@@ -164,13 +164,13 @@ static int msm_hdmi_phy_probe(struct pla ret =msm_hdmi_phy_resource_enable (phy);if (ret) -return ret; + goto err_pm_disable; ret =msm_hdmi_phy_pll_init (pdev, phy->cfg->type);if (ret) {DRM_DEV_ERROR (dev,"couldn't init PLL\n" );msm_hdmi_phy_resource_disable (phy); -return ret; + goto err_pm_disable; }msm_hdmi_phy_resource_disable (phy);
@@ -178,6 +178,10 @@ static int msm_hdmi_phy_probe(struct plaplatform_set_drvdata (pdev, phy);return 0 ; + +err_pm_disable: +pm_runtime_disable (dev); +return ret; }static void msm_hdmi_phy_remove (struct platform_device *pdev)
Greg Kroah-Hartman
maintainerPATCH 276/877 smb: client: cancel reconnect work in clean_demultiplex_info()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit c65eae6f61d1778ff7a82e4aae4080e26f486af1 upstream.
clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:
cifs_demultiplex_thread()
cifs_readv_from_socket()
cifs_reconnect()
__cifs_reconnect()
cifs_queue_server_reconn()
mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
clean_demultiplex_info()
cancel_delayed_work_sync(&server->echo) // echo canceled
// reconnect NOT canceled
kfree_sensitive(server) // server freed ...later, on cifsiod_wq:
smb2_reconnect_server()
server->srv_count // UAF read of freed server
Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -982,6 +982,7 @@ clean_demultiplex_info(struct TCP_Serverspin_unlock (&server->srv_lock);cancel_delayed_work_sync (&server->echo); +cancel_delayed_work_sync (&server->reconnect);spin_lock (&server->srv_lock); server->tcpStatus = CifsExiting;
Greg Kroah-Hartman
maintainerPATCH 277/877 smb: client: fix rlist race and missing initialization
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit 5f270f091256da1338c3631083e15d7f83cc05e1 upstream.
TCP_Server_Info.rlist is allocated via kzalloc which zeros both ->next and ->prev to NULL instead of pointing to itself, making list_empty() always return false and list_add() dereference a NULL ->prev pointer.
Also, cifs_signal_cifsd_for_reconnect() can be called concurrently from multiple cifsd threads, allowing the same server's rlist node to be added twice into the local list, corrupting it.
--- fs/smb/client/connect.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/connect.c +7 -0
@@ -187,6 +187,8 @@ cifs_signal_cifsd_for_reconnect(struct T nserver = ses->chans[i].server;if (!nserver)continue ; +if (!list_empty (&nserver->rlist)) +continue ; nserver->srv_count++;list_add (&nserver->rlist, &reco); }
@@ -195,11 +197,15 @@ cifs_signal_cifsd_for_reconnect(struct T } } +spin_lock (&cifs_tcp_ses_lock);list_for_each_entry_safe (server, nserver, &reco, rlist) {list_del_init (&server->rlist);set_need_reco (server); +spin_unlock (&cifs_tcp_ses_lock);cifs_put_tcp_session (server,0 ); +spin_lock (&cifs_tcp_ses_lock); } +spin_unlock (&cifs_tcp_ses_lock); }/*
@@ -1768,6 +1774,7 @@ cifs_get_tcp_session(struct smb3_fs_contspin_lock_init (&tcp_ses->mid_lock);INIT_LIST_HEAD (&tcp_ses->tcp_ses_list);INIT_LIST_HEAD (&tcp_ses->smb_ses_list); +INIT_LIST_HEAD (&tcp_ses->rlist);INIT_DELAYED_WORK (&tcp_ses->echo, cifs_echo_request);INIT_DELAYED_WORK (&tcp_ses->reconnect, smb2_reconnect_server);mutex_init (&tcp_ses->reconnect_mutex);
Greg Kroah-Hartman
maintainerPATCH 278/877 smb: client: reject short Next offsets in parse_server_interfaces()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 1b3221bb121079ad79a1f3c3aa360ba649832e7a upstream.
In parse_server_interfaces(), the server-supplied Next offset is validated against bytes_left, but not against the size of the interface structure itself.
A small, non-zero Next value can pass the bounds check but advance the pointer by less than sizeof(*p). This causes the next iteration of the loop to read misaligned, overlapping structure fields.
Fix this by ensuring the Next offset is at least sizeof(*p).
--- fs/smb/client/smb2ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/smb2ops.c +3 -3
@@ -786,9 +786,9 @@ next_iface:break ; }/* Validate that Next doesn't point beyond the buffer */ -if (next > bytes_left) { -cifs_dbg (VFS ,"%s: invalid Next pointer %zu > %zd\n" , - __func__, next, bytes_left); +if (next <sizeof (*p) || next > bytes_left) { +cifs_dbg (VFS ,"%s: invalid Next pointer %zu out of range [%zu, %zd]\n" , + __func__, next,sizeof (*p), bytes_left); rc = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 279/877 smb: client: fix smbd_connection leak on cifs_get_tcp_session() error
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit e75c96157d45e498970158c8f7373d90102e33b9 upstream.
When an RDMA connection is successfully established via smbd_get_connection() but cifs_get_tcp_session() later fails (e.g. kthread_create() returns an error), the error path frees tcp_ses without first destroying the smbd_connection.
Fix this by calling smbd_destroy() in the out_err cleanup path before kfree(tcp_ses). smbd_destroy() safely handles the case where smbd_conn is NULL, so it can be called unconditionally.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -1885,6 +1885,7 @@ out_err:kfree (tcp_ses->leaf_fullpath);if (tcp_ses->ssocket)sock_release (tcp_ses->ssocket); +smbd_destroy (tcp_ses);kfree (tcp_ses); }return ERR_PTR (rc);
Greg Kroah-Hartman
maintainerPATCH 280/877 smb: client: fix unaligned access in WSL reparse point parser
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit e1aeaf79dea51e6065da56924bc07e22d59012ac upstream.
When wsl_to_fattr() parses WSL extended attributes, it computes a payload pointer from ea->ea_data + ea_name_length + 1. Since the smb2_file_full_ea_info struct is __packed and all WSL xattr names are 6 bytes long, the value pointer always lands at an odd byte offset, never satisfying __le32 or __le64 alignment requirements.
The code then casts this pointer to __le32 * or __le64 * and dereferences it directly, which may cause alignment faults on some architectures.
Replace all such casts with get_unaligned_le32() and get_unaligned_le64() in reparse_mkdev(), wsl_make_kuid(), wsl_make_kgid() and wsl_to_fattr().
--- fs/smb/client/reparse.c | 4 ++-- fs/smb/client/reparse.h | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-)
fs/smb/client/reparse.c +2 -2
@@ -726,9 +726,9 @@ static bool wsl_to_fattr(struct cifs_ope fattr->cf_gid =wsl_make_kgid (cifs_sb, v); else if (!strncmp(name, SMB2_WSL_XATTR_MODE, nlen)) {/* File type in reparse point tag and in xattr mode must match. */ -if (S_DT (fattr->cf_mode) !=S_DT (le32_to_cpu (*(__le32 *)v))) +if (S_DT (fattr->cf_mode) !=S_DT (get_unaligned_le32 (v)))return false; - fattr->cf_mode = (umode_t )le32_to_cpu (*(__le32 *)v); + fattr->cf_mode = (umode_t )get_unaligned_le32 (v); } else if (!strncmp(name, SMB2_WSL_XATTR_DEV, nlen)) { fattr->cf_rdev =reparse_mkdev (v); have_xattr_dev = true;
fs/smb/client/reparse.h +4 -3
@@ -9,6 +9,7 @@#include <linux/fs.h> #include <linux/stat.h> #include <linux/uidgid.h> +#include <linux/unaligned.h> #include "fs_context.h" #include "cifsglob.h"
@@ -22,7 +23,7 @@static inline dev_t reparse_mkdev (void *ptr) { -u64 v =le64_to_cpu (*(__le64 *)ptr); +u64 v =get_unaligned_le64 (ptr);return MKDEV (v &0xffffffff , v >>32 ); }
@@ -30,7 +31,7 @@ static inline dev_t reparse_mkdev(void *static inline kuid_t wsl_make_kuid (struct cifs_sb_info *cifs_sb,void *ptr) { -u32 uid =le32_to_cpu (*(__le32 *)ptr); +u32 uid =get_unaligned_le32 (ptr);if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_OVERR_UID )return cifs_sb->ctx->linux_uid;
@@ -40,7 +41,7 @@ static inline kuid_t wsl_make_kuid(strucstatic inline kgid_t wsl_make_kgid (struct cifs_sb_info *cifs_sb,void *ptr) { -u32 gid =le32_to_cpu (*(__le32 *)ptr); +u32 gid =get_unaligned_le32 (ptr);if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_OVERR_GID )return cifs_sb->ctx->linux_gid;
Greg Kroah-Hartman
maintainerPATCH 281/877 smb: client: fix next_buffer UAF and NextCommand bounds in compound PDUs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 05762c5bc1cfdcac36747994fde2c04387a457f1 upstream.
Fix several related bounds checking and pointer lifecycle issues in receive_encrypted_standard()'s handling of compound encrypted frames:
- Clear next_buffer after assigning it to server->bigbuf. A stale next_buffer pointer can lead to a use-after-free on subsequent error paths.
- Update pdu_length to the decrypted plaintext size (buf_size). Using the pre-decryption length allows NextCommand to point into stale ciphertext residue.
- Reject next_cmd values smaller than MID_HEADER_SIZE(server).
- Fix an integer overflow in the upper bound check by verifying pdu_length - next_cmd < MID_HEADER_SIZE(server), ensuring the trailing slice is large enough for a header.
--- fs/smb/client/smb2ops.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +10 -1
@@ -5237,6 +5237,7 @@ receive_encrypted_standard(struct TCP_Se length =decrypt_raw_data (server, buf, buf_size,NULL , false);if (length)return length; + pdu_length = buf_size; next_is_large = server->large_buf; one_more:
@@ -5249,8 +5250,15 @@ one_more: }if (next_cmd) { -if (WARN_ON_ONCE (next_cmd > pdu_length)) +if (next_cmd <MID_HEADER_SIZE (server) || + next_cmd > pdu_length || + pdu_length - next_cmd <MID_HEADER_SIZE (server)) { +unsigned int max_next = pdu_length > (unsigned int )MID_HEADER_SIZE (server) ? + pdu_length - (unsigned int )MID_HEADER_SIZE (server) :0 ; +cifs_server_dbg (VFS ,"invalid NextCommand offset %u out of range [%zu, %u]\n" , + next_cmd,MID_HEADER_SIZE (server), max_next);return -1 ; + }if (next_is_large) next_buffer = (char *)cifs_buf_get ();else
@@ -5286,6 +5294,7 @@ one_more: server->bigbuf = buf = next_buffer; else server->smallbuf = buf = next_buffer; + next_buffer =NULL ; goto one_more; }else if (ret !=0 ) {/*
Greg Kroah-Hartman
maintainerPATCH 282/877 smb: client: fix potential OOB read in smb3_enum_snapshots()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 4775c3b7a597907e0b97556c7986fda238a377ae upstream.
If snapshot_array_size is smaller than GMT_TOKEN_SIZE, smb3_enum_snapshots() sets ret_data_len tosizeof(struct smb_snapshot_array) without verifying the actual length of the server's reply.
Because SMB2_ioctl() places no lower bound on the server-supplied OutputCount and allocates retbuf to exactly that length, a short reply results in ret_data_len exceeding the size of retbuf. The subsequent copy_to_user() then reads past the end of retbuf, leaking adjacent slab memory to userspace. The subsequent clamp check is ineffective as it only reduces ret_data_len.
Fix this by rejecting replies shorter thansizeof(struct smb_snapshot_array) with -EIO. Note that the bound is set to the 12-byte struct size rather than the 16-byte MIN_SNAPSHOT_ARRAY_SIZE defined in MS-SMB2 3.3.5.15.1, because 12 bytes is exactly what copy_to_user() attempts to read.
--- fs/smb/client/smb2ops.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +7 -1
@@ -2422,8 +2422,14 @@ smb3_enum_snapshots(const unsigned int x* and retry the ioctl again with larger array size sufficient * to hold all of the snapshot GMT tokens on the second try. */ -if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) +if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) { +if (ret_data_len <sizeof (struct smb_snapshot_array )) { + rc = -EIO ; +kfree (retbuf); +return rc; + } ret_data_len =sizeof (struct smb_snapshot_array ); + }/* * We return struct SRV_SNAPSHOT_ARRAY, followed by
Greg Kroah-Hartman
maintainerPATCH 283/877 smb: client: fix server->total_read for compound encrypted PDUs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit f73726b83e4756fdaa099e1bc1143293bd57ad79 upstream.
In receive_encrypted_standard(), server->total_read is left at the full decrypted frame size when walking sub-PDUs of a compound encrypted frame. As a result, cifs_handle_standard() passes this full size to smb2_check_message(), causing the PDU length guards to incorrectly validate the entire compound frame instead of the current sub-PDU.
This allows truncated non-last sub-PDUs to bypass length validation, leading to out-of-bounds reads in smb2_get_data_area_len().
Fix this by setting server->total_read to the true length of the current sub-PDU: next_cmd for non-last sub-PDUs, and the remaining pdu_length for the last one.
--- fs/smb/client/smb2ops.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/smb2ops.c +1 -0
@@ -5249,6 +5249,7 @@ receive_encrypted_standard(struct TCP_Se one_more: shdr = (struct smb2_hdr *)buf; next_cmd =le32_to_cpu (shdr->NextCommand); + server->total_read = next_cmd ? next_cmd : pdu_length;if (*num_mids >=MAX_COMPOUND ) {cifs_server_dbg (VFS ,"too many PDUs in compound\n" );
Greg Kroah-Hartman
maintainerPATCH 284/877 smb: client: fix missing lower-bound check on DFS referral string offsets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit e83330c55edc0c3ac08aa6c95e49e4694c65523b upstream.
parse_dfs_referrals() checks that DfsPathOffset and NetworkAddressOffset do not exceed the buffer end, but fails to check that they don't point inside the referral header itself.
If a server provides an offset smaller thansizeof(struct dfs_referral_level_3), the derived string pointer overlaps with the struct fields, causing cifs_strndup_from_utf16() to interpret header data as UTF-16 strings.
Fix this by enforcing that string offsets are at least sizeof(*ref).
--- fs/smb/client/misc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
fs/smb/client/misc.c +10 -2
@@ -1046,7 +1046,11 @@ parse_dfs_referrals(struct get_dfs_refer node->ref_flag =le16_to_cpu (ref->ReferralEntryFlags);/* copy DfsPath */ -if (le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->DfsPathOffset) <sizeof (*ref) || +le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: DfsPathOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->DfsPathOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
@@ -1060,7 +1064,11 @@ parse_dfs_referrals(struct get_dfs_refer }/* copy link target UNC */ -if (le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->NetworkAddressOffset) <sizeof (*ref) || +le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: NetworkAddressOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->NetworkAddressOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
Greg Kroah-Hartman
maintainerPATCH 285/877 smb: client: fix missing iov bounds check in parse_posix_sids()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit b09d092eb24ad0110f16a9b7c1ed5d2a0c1733dc upstream.
In parse_posix_sids(), sidsbuf_end is calculated using the server-supplied out_len without being validated against the actual length of the received iov (iov_len).
If a server provides an inflated out_len, sidsbuf_end will point past the end of the iov. This defeats the bounds guards in posix_info_sid_size(), allowing out-of-bounds reads into adjacent kernel memory.
Fix this by rejecting responses where the calculated sidsbuf_end would exceed the received iov boundaries or cause pointer wraparound.
--- fs/smb/client/smb2inode.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/client/smb2inode.c +11 -0
@@ -71,6 +71,17 @@ static int parse_posix_sids(struct cifs_ sidsbuf = (u8 *)qi +le16_to_cpu (qi->OutputBufferOffset) + qi_len; sidsbuf_end = sidsbuf + out_len - qi_len; +if (sidsbuf_end < sidsbuf) { +cifs_dbg (VFS ,"%s: server-supplied out_len %u caused pointer wraparound\n" , + __func__, out_len); +return -EINVAL ; + } +if (sidsbuf_end > (u8 *)rsp_iov->iov_base + rsp_iov->iov_len) { +cifs_dbg (VFS ,"%s: server-supplied out_len %u overruns iov by %td bytes\n" , + __func__, out_len, + sidsbuf_end - ((u8 *)rsp_iov->iov_base + rsp_iov->iov_len)); +return -EINVAL ; + } owner_len =posix_info_sid_size (sidsbuf, sidsbuf_end);if (owner_len ==-1 )
Greg Kroah-Hartman
maintainerPATCH 286/877 HID: asus: fortify keyboard handshake
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antheas Kapenekakis <[email protected]>
[ Upstream commit e82ae34af29e910c96d33c8b3a90c60e27f1625e ]
Handshaking with an Asus device involves sending it a feature report with the string "ASUS Tech.Inc." and then reading it back to verify the handshake was successful, under the feature ID the interaction will take place.
Currently, the driver only does the first part. Add the readback to verify the handshake was successful. As this could cause breakages, allow the verification to fail with a dmesg error until we verify all devices work with it (they seem to).
Since the response is more than 16 bytes, increase the buffer size to 64 as well to avoid overflow errors. In addition, add the report ID to prints, to help identify failed handshakes.
--- drivers/hid/hid-asus.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)
drivers/hid/hid-asus.c +30 -4
@@ -48,7 +48,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define FEATURE_REPORT_ID 0x0d#define INPUT_REPORT_ID 0x5d#define FEATURE_KBD_REPORT_ID 0x5a -#define FEATURE_KBD_REPORT_SIZE 16 +#define FEATURE_KBD_REPORT_SIZE 64#define FEATURE_KBD_LED_REPORT_ID1 0x5d#define FEATURE_KBD_LED_REPORT_ID2 0x5e
@@ -393,15 +393,41 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bustatic int asus_kbd_init (struct hid_device *hdev,u8 report_id) { +/* +* The handshake is first sent as a set_report, then retrieved +* from a get_report. They should be equal. +*/ const u8 buf[] = { report_id,0x41 ,0x53 ,0x55 ,0x53 ,0x20 ,0x54 ,0x65 ,0x63 ,0x68 ,0x2e ,0x49 ,0x6e ,0x63 ,0x2e ,0x00 };int ret; ret =asus_kbd_set_report (hdev, buf,sizeof (buf)); -if (ret <0 ) -hid_err (hdev,"Asus failed to send init command: %d\n" , ret); +if (ret <0 ) { +hid_err (hdev,"Asus handshake %02x failed to send: %d\n" , + report_id, ret); +return ret; + } -return ret; + u8 *readbuf __free(kfree) = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL); +if (!readbuf) +return -ENOMEM ; + + ret =hid_hw_raw_request (hdev, report_id, readbuf, +FEATURE_KBD_REPORT_SIZE ,HID_FEATURE_REPORT , +HID_REQ_GET_REPORT ); +if (ret <0 ) { +hid_warn (hdev,"Asus handshake %02x failed to receive ack: %d\n" , + report_id, ret); + }else if (memcmp (readbuf, buf,sizeof (buf)) !=0 ) { +hid_warn (hdev,"Asus handshake %02x returned invalid response: %*ph\n" , + report_id,FEATURE_KBD_REPORT_SIZE , readbuf); + } + +/* +* Do not return error if handshake is wrong until this is +* verified to work for all devices. +*/ +return 0 ; } static int asus_kbd_get_functions(struct hid_device *hdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 287/877 ksmbd: fix partial normalized name responses
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit f4fafaf02174c32bce2f9bb4196fadf13f1fd96e upstream.
Windows may request FILE_NORMALIZED_NAME_INFORMATION with an output buffer that only fits the fixed portion of the variable-length response. Treat the fixed portion as FILE_NORMALIZED_NAME_INFORMATION_SIZE so ksmbd returns STATUS_BUFFER_OVERFLOW instead of STATUS_INFO_LENGTH_MISMATCH.
This avoids rejecting valid partial normalized-name responses.
--- fs/smb/server/smb2pdu.c | 3 +++ fs/smb/server/smb2pdu.h | 1 + 2 files changed, 4 insertions(+)
fs/smb/server/smb2pdu.c +3 -0
@@ -5530,6 +5530,9 @@ static int smb2_get_info_file(struct ksmcase FILE_ALTERNATE_NAME_INFORMATION : fixed_len =FILE_ALTERNATE_NAME_INFORMATION_SIZE ;break ; +case FILE_NORMALIZED_NAME_INFORMATION : + fixed_len =FILE_NORMALIZED_NAME_INFORMATION_SIZE ; +break ;case FILE_STREAM_INFORMATION : fixed_len =FILE_STREAM_INFORMATION_SIZE ;break ;
fs/smb/server/smb2pdu.h +1 -0
@@ -219,6 +219,7 @@ struct file_sparse {#define FILE_ALLOCATION_INFORMATION_SIZE 19#define FILE_END_OF_FILE_INFORMATION_SIZE 20#define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8 +#define FILE_NORMALIZED_NAME_INFORMATION_SIZE 8#define FILE_STREAM_INFORMATION_SIZE 32#define FILE_PIPE_INFORMATION_SIZE 23#define FILE_PIPE_LOCAL_INFORMATION_SIZE 24
Greg Kroah-Hartman
maintainerPATCH 288/877 spi: spi-zynqmp-gqspi: stop the controller on shutdown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Itai Handler <[email protected]>
commit e922bad8b2d5028c51a096d083fea41cd0987154 upstream.
The driver has no ->shutdown, and platform_drv_shutdown() has no fallback of its own. Unlike pci_device_shutdown(), which clears bus mastering when kexec_in_progress, nothing on the platform bus disarms a device that can still write to memory. The normal kexec path never calls ->suspend either, so the quiesce in zynqmp_qspi_suspend() is not reached.
A controller that is still executing a DMA read may therefore keep writing to memory across a kexec. QSPIDMA_DST_ADDR still points at memory owned by the kernel that called kexec, DST_SIZE is non-zero and the flash is still clocked, so data can keep landing in RAM while the new kernel is being relocated, and after it has started executing.
That destination is a physical address which means nothing to the new kernel, so the writes can corrupt whatever now occupies it: kernel text or data, page tables, or the initrd. Nothing reports an error and the resulting behaviour is undefined.
This can be observed by reading GQSPI_EN (offset 0x114) and QSPIDMA_DST_ADDR/SIZE/STS/CTRL (offsets 0x800 to 0x80c) early in the new kernel, before the driver probes: without this patch GQSPI_EN reads 1 and QSPIDMA_DST_ADDR still points into the previous kernel's memory.
Add a ->shutdown that stops the controller the way zynqmp_qspi_suspend() already does. spi_controller_suspend() stops the queue, waits for a message that is already executing and makes any later transfer fail with -ESHUTDOWN, so nothing can be cut short by the register write that follows. It may sleep, which is fine here: device_shutdown() runs in process context. Unlike ->suspend this cannot abort on error, because a controller left mastering the bus is worse than a truncated transfer, so a failure to drain is only logged.
GQSPI_EN_OFST is then cleared, as zynqmp_qspi_remove() and zynqmp_qspi_suspend() already do. Skip that write only when pm_runtime_get_if_in_use() returns 0, i.e. runtime suspended: the clocks are gated, so the registers are unreachable and the controller cannot be mastering the bus. A negative return is not the same thing - it is what the CONFIG_PM=n stub always returns, and there probe() has enabled pclk and refclk for good, so the controller is running and must be stopped.
[ itai: context only - the platform_driver callback is still spelled
.remove_new in this tree, renamed back to .remove upstream by commit 494c3dc46776 ("spi: Switch back to struct platform_driver::remove()") ]
--- drivers/spi/spi-zynqmp-gqspi.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/spi/spi-zynqmp-gqspi.c +34 -0
@@ -1385,11 +1385,45 @@ static void zynqmp_qspi_remove(struct platform_device *pdev)clk_disable_unprepare (xqspi->pclk); } +static void zynqmp_qspi_shutdown (struct platform_device *pdev) +{ +struct zynqmp_qspi *xqspi =platform_get_drvdata (pdev); +int ret; + +/* +* Stop the queue and reject any later transfer first, so the write +* below cannot cut into a message that is still being executed. +* Unlike ->suspend this cannot abort on error: a controller left +* mastering the bus is worse than a truncated transfer. +*/ + ret =spi_controller_suspend (xqspi->ctlr); +if (ret) +dev_warn (&pdev->dev,"could not stop the queue: %d\n" , ret); + +/* +* Only a runtime suspended controller can be left alone: its clocks +* are gated, so it cannot be mastering the bus, and its registers +* must not be accessed either. Any other answer means it may be +* running and has to be stopped. In particular, on a kernel built +* without runtime PM this returns -EINVAL, and there the clocks +* enabled in probe() are never gated at all. +*/ + ret =pm_runtime_get_if_in_use (&pdev->dev); +if (!ret) +return ; + +zynqmp_gqspi_write (xqspi,GQSPI_EN_OFST ,0x0 ); + +if (ret >0 ) +pm_runtime_put_noidle (&pdev->dev); +} +MODULE_DEVICE_TABLE (of, zynqmp_qspi_of_match);static struct platform_driver zynqmp_qspi_driver = { .probe = zynqmp_qspi_probe, .remove_new = zynqmp_qspi_remove, + .shutdown = zynqmp_qspi_shutdown, .driver = { .name ="zynqmp-qspi" , .of_match_table = zynqmp_qspi_of_match,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 289/877 smb: client: fix busy dentry warning on unmount after DIO
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zizhi Wo <[email protected]>
[ Upstream commit 75f5c412fa867efa0bf9b646bffe0d912109e84a ]
Commit c68337442f03 ("cifs: Fix busy dentry used after unmounting") fixed the issue in cifs where deferred close of a file led to a dentry reference count not being released in umount, by flushing deferredclose_wq in cifs_kill_sb() to solve it.
However, the cifs DIO path suffers from the same busy-dentry problem caused by a delayed dentry reference-count release:
[dio] [cifsd] [close + umount]
netfs_unbuffered_write_iter_locked
...
cifs_demultiplex_thread
netfs_unbuffered_write
cifs_issue_write netfs_wait_for_in_progress_stream [1]
... netfs_write_subrequest_terminated netfs_subreq_clear_in_progress netfs_wake_collector // wake [1] netfs_put_subrequest netfs_put_request queue_work(system_dfl_wq, xxx) [2] // dio write return cifs_close _cifsFileInfo_put // cfile->count 2->1 --cfile->count [3] // umount cifs_kill_sb kill_anon_super // warning triggered! shrink_dcache_for_umount [4]
[system_dfl_wq] [5]netfs_free_request
...
_cifsFileInfo_put
// cfile->count 1->0
--cfile->count
queue_work(fileinfo_put_wq, xxx)
[fileinfo_put_wq] [6]cifsFileInfo_put_work
cifsFileInfo_put_final
dput
If the umount path is triggered before [5], it results warning:
BUG: Dentry 00000000eab1f070{i=9a917b66ae404fec,n=test} still in use (1)[unmount of cifs cifs]
The existing per-inode ictx->io_count wait in cifs_evict_inode() does not
help: it lives in the inode eviction path, which runs after shrink_dcache_for_umount() has already warned about the busy dentries.
Fix it by adding a per-superblock outstanding-rreq counter that is incremented in cifs_init_request() and decremented in cifs_free_request(). In cifs_kill_sb(), before kill_anon_super(), wait for this counter to reach 0 - which guarantees that all cleanup_work for this sb have run and thus all relevant cfile puts are queued on fileinfo_put_wq or serverclose_wq. Then drain the workqueue so the dentry refs are dropped.
This is a targeted wait, not a flush of the system-wide system_dfl_wq.
--- fs/smb/client/cifs_fs_sb.h | 1 + fs/smb/client/cifsfs.c | 12 ++++++++++++ fs/smb/client/connect.c | 1 + fs/smb/client/file.c | 5 +++++ 4 files changed, 19 insertions(+)
fs/smb/client/cifs_fs_sb.h +1 -0
@@ -55,6 +55,7 @@ struct cifs_sb_info {struct smb3_fs_context *ctx;atomic_t active;unsigned int mnt_cifs_flags; +atomic_t outstanding_rreq;/* nr of rreqs not yet fully deinitialized */ struct delayed_work prune_tlinks;struct rcu_head rcu;
fs/smb/client/cifsfs.c +12 -0
@@ -302,6 +302,18 @@ static void cifs_kill_sb(struct super_block *sb)/* Wait for all opened files to release */ flush_workqueue (deferredclose_wq); +/* +* Wait for all in-flight netfs I/O requests to finish their +* cleanup_work so that any cifsFileInfo final puts they queue +* to fileinfo_put_wq/serverclose_wq have been queued, then +* drain the workqueue so the cfile dentry refs are dropped to +* avoid the busy dentry warning. +*/ +wait_var_event (&cifs_sb->outstanding_rreq, + !atomic_read (&cifs_sb->outstanding_rreq)); +flush_workqueue (serverclose_wq); +flush_workqueue (fileinfo_put_wq); +/* finally release root dentry */ dput (cifs_sb->root); cifs_sb->root =NULL ;
fs/smb/client/connect.c +1 -0
@@ -3399,6 +3399,7 @@ int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb)spin_lock_init (&cifs_sb->tlink_tree_lock); cifs_sb->tlink_tree =RB_ROOT ; +atomic_set (&cifs_sb->outstanding_rreq,0 );cifs_dbg (FYI ,"file mode: %04ho dir mode: %04ho\n" , ctx->file_mode, ctx->dir_mode);
fs/smb/client/file.c +5 -0
@@ -276,6 +276,7 @@ static int cifs_init_request(struct netfs_io_request *rreq, struct file *file)return -EIO ; } +atomic_inc (&cifs_sb->outstanding_rreq);return 0 ; }
@@ -297,9 +298,13 @@ static void cifs_rreq_done(struct netfs_io_request *rreq)static void cifs_free_request (struct netfs_io_request *rreq) { struct cifs_io_request *req = container_of(rreq, struct cifs_io_request, rreq); +struct cifs_sb_info *cifs_sb =CIFS_SB (rreq->inode->i_sb);if (req->cfile)cifsFileInfo_put (req->cfile); + +if (atomic_dec_and_test (&cifs_sb->outstanding_rreq)) +wake_up_var (&cifs_sb->outstanding_rreq); }static void cifs_free_subrequest (struct netfs_io_subrequest *subreq)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 290/877 xfs: dont stash removename operations with unknown ftype
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 865b751e75039fc07838b3200f9740256653da9a ]
LOLLM notices that the behavior of xrep_dir_replay_update changes based on the ftype recorded in the stashed removename information. It also notices that the unlink iops sometimes set that ftype to FT_UNKNOWN because the regular directory tree update code paths don't need to know the ftype of the child.
Unfortunately, this results in incorrect link counts, which eventually trips link count errors in later phases of xfs_scrub, or in xfs_repair. Fix this by creating a second xfs_name with the type set correctly.
--- fs/xfs/scrub/dir_repair.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
fs/xfs/scrub/dir_repair.c +17 -2
@@ -1379,9 +1379,24 @@ xrep_dir_live_update(if (p->delta >0 ) error =xrep_dir_stash_createname (rd, p->name, p->ip->i_ino); -else - error =xrep_dir_stash_removename (rd, p->name, +else { +/* +* xfs_dentry_to_name in unlink or rename-exchange can +* pass us names with ftype FT_UNKNOWN, but we really +* must know the ftype of the child that is being +* removed so that we can do nlink updates correctly +* without holding inode references. +*/ +struct xfs_name name = { + .name = p->name->name, + .len = p->name->len, + .type =xfs_mode_to_ftype ( +VFS_IC (p->ip)->i_mode), + }; + + error =xrep_dir_stash_removename (rd, &name, p->ip->i_ino); + }mutex_unlock (&rd->pscan.lock);if (error) goto out_abort;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 291/877 erofs: fix large folio race in erofs_fscache_req_complete
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenwu Hou <[email protected]>
This patch is for stable only. Commit c37460cd9b2fc ("erofs: remove fscache backend entirely") upstream removed this code.
xas_for_each() iteration can race with reclamation of an unlocked large folio and splitting of its replacement shadow entry. Fix this by advancing past the entire folio before unlocking it.
For example:
CPU A: EROFS completion Other CPUs
---------------------------------- -----------------------------------
Find F at index 0.
Mark F uptodate.
Unlock F.
Reclaim F.
Replace indices 0–3 with a multi-index workingset shadow.
Another reader inserts a smaller folio, e.g. order-0 at index 0. Split the large shadow entry:
index 0: new folio index 1: shadow index 2: shadow index 3: shadow
Find a shadow at index 1.folio_mark_uptodate(folio).
This can cause a kernel panic such as:
[1030374.432778] [ C31] BUG: unable to handle page fault for address: 00001846af017b01 [1030374.432971] [ C31] #PF: supervisor write access in kernel mode [1030374.432973] [ C31] #PF: error_code(0x0002) - not-present page [1030374.433543] [ C31] PGD 5a44f75067 P4D 5a44f75067 PUD 0 [1030374.433546] [ C31] Oops: 0002 [#1] PREEMPT SMP NOPTI [1030374.433549] [ C31] CPU: 31 PID: 2425624 Comm: node Kdump: loaded Tainted: G OE K 6.6.88-**** [1030374.434154] [ C31] Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS ?-20260421_110423-CN.l65g09119.cloud.sqa.na131 04/01/2014 [1030374.434156] [ C31] RIP: 0010:erofs_fscache_req_complete+0xc1/0x1a0 [erofs] [1030374.434764] [ C31] Code: 17 c5 c3 48 89 c7 48 85 c0 0f 84 af 00 00 00 48 81 ff 06 04 00 00 74 1b 48 81 ff 02 04 00 00 0f 84 b9 00 00 00 66 85 ed 75 04 <f0> 80 0f 08 e8 96 04 24 c3 48 8b 54 24 18 f6 c2 03 0f 95 c0 48 85 [1030374.435044] [ C31] RSP: 0000:ffffb8f2fc973cc0 EFLAGS: 00010046 [1030374.435641] [ C31] [1030374.435642] [ C31] RAX: 00001846af017b01 RBX: 000000000000000f RCX: 0000000000000001 [1030374.436885] [ C31] RDX: 000000000000000c RSI: ffffa02ab337d468 RDI: 00001846af017b01 [1030374.437127] [ C31] RBP: 0000000000000000 R08: ffffffffffffffc0 R09: 0000000000000002 [1030374.437672] [ C31] R10: 0000000000000005 R11: 0000000000000191 R12: ffffa0060ec72300 [1030374.437673] [ C31] R13: 0000000008000000 R14: ffffffffc11b1990 R15: 0000000000007000 [1030374.437677] [ C31] FS: 00007f4928cdec80(0000) GS:ffffa07dc5f80000(0000) knlGS:0000000000000000 [1030374.437678] [ C31] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [1030374.437680] [ C31] CR2: 00001846af017b01 CR3: 00000063d5356006 CR4: 0000000000770ee0 [1030374.437681] [ C31] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [1030374.437682] [ C31] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400 [1030374.437684] [ C31] PKRU: 55555558 [1030374.437684] [ C31] Call Trace: [1030374.437687] [ C31] <TASK> [1030374.437692] [ C31] erofs_fscache_req_put+0x27/0x40 [erofs] [1030374.438900] [ C31] cachefiles_read_complete+0x48/0x110 [cachefiles] [1030374.440448] [ C31] iomap_dio_bio_end_io+0x128/0x160 [1030374.440456] [ C31] ? __pfx_stripe_end_io+0x10/0x10 [dm_mod] [1030374.440950] [ C31] clone_endio+0x123/0x1f0 [dm_mod] [1030374.441550] [ C31] blk_mq_end_request_batch+0xf4/0x440 [1030374.441556] [ C31] ? nohz_balancer_kick+0x31/0x270 [1030374.441561] [ C31] ? dma_direct_unmap_sg+0x48/0x1d0 [1030374.441565] [ C31] ? dma_pool_free+0x22/0x60 [1030374.441569] [ C31] ? nvme_pci_complete_batch+0xaf/0xc0 [nvme] [1030374.442070] [ C31] nvme_irq+0x6e/0x80 [nvme] [1030374.442422] [ C31] ? __pfx_nvme_pci_complete_batch+0x10/0x10 [nvme] [1030374.442428] [ C31] __handle_irq_event_percpu+0x46/0x1a0 [1030374.442431] [ C31] handle_irq_event+0x37/0x80 [1030374.442433] [ C31] handle_edge_irq+0x93/0x240 [1030374.442436] [ C31] __common_interrupt+0x3b/0xa0 [1030374.442441] [ C31] common_interrupt+0x3f/0xa0 [1030374.442446] [ C31] asm_common_interrupt+0x22/0x40
--- fs/erofs/fscache.c | 2 ++ 1 file changed, 2 insertions(+)
fs/erofs/fscache.c +2 -0
@@ -67,6 +67,8 @@ static void erofs_fscache_req_complete(struct erofs_fscache_rq *req)continue ;if (!failed)folio_mark_uptodate (folio); +/* Skip the entire folio before unlocking allows it to be split. */ +xas_advance (&xas,folio_next_index (folio) -1 );folio_unlock (folio); }rcu_read_unlock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 292/877 ALSA: hda/realtek: Limit Star Labs internal mic boost
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Rhodes <[email protected]>
[ Upstream commit 186d4adbb40138e7cb7cffc87a81e95630ced123 ]
The 30 dB internal mic boost is too high for laptops, especially with fans. Limit Star Labs internal mic boost to 10 dB.
--- sound/pci/hda/patch_realtek.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/pci/hda/patch_realtek.c +6 -0
@@ -8243,6 +8243,7 @@ enum {ALC245_FIXUP_CLEVO_NOISY_MIC ,ALC269_FIXUP_VAIO_VJFH52_MIC_NO_PRESENCE ,ALC233_FIXUP_MEDION_MTL_SPK , +ALC269_FIXUP_STARLABS_LIMIT_INT_MIC_BOOST ,ALC233_FIXUP_STARLABS_STARFIGHTER ,ALC294_FIXUP_BASS_SPEAKER_15 , ALC283_FIXUP_DELL_HP_RESUME,
@@ -10652,6 +10653,10 @@ static const struct hda_fixup alc269_fixups[] = { { } }, }, + [ALC269_FIXUP_STARLABS_LIMIT_INT_MIC_BOOST] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc269_fixup_limit_int_mic_boost, + }, [ALC233_FIXUP_STARLABS_STARFIGHTER] = { .type = HDA_FIXUP_FUNC, .v.func = alc233_fixup_starlabs_starfighter,
@@ -11770,6 +11775,7 @@ static const struct hda_quirk alc269_fixup_vendor_tbl[] = {SND_PCI_QUIRK_VENDOR (0x104d ,"Sony VAIO" ,ALC269_FIXUP_SONY_VAIO ),SND_PCI_QUIRK_VENDOR (0x17aa ,"Thinkpad" ,ALC269_FIXUP_THINKPAD_ACPI ),SND_PCI_QUIRK_VENDOR (0x19e5 ,"Huawei Matebook" ,ALC255_FIXUP_MIC_MUTE_LED ), + SND_PCI_QUIRK_VENDOR(0x2145, "Star Labs", ALC269_FIXUP_STARLABS_LIMIT_INT_MIC_BOOST), {} };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 293/877 ALSA: hda/realtek: Add StarFighter HDA SSID
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Rhodes <[email protected]>
[ Upstream commit cd401c70df472d3eddd0b6b055726a03c212181a ]
Support the new StarFighter HDA SSID while keeping the existing SSID chained to the same quirk until the new match reaches backports.
--- sound/pci/hda/patch_realtek.c | 3 +++ 1 file changed, 3 insertions(+)
sound/pci/hda/patch_realtek.c +3 -0
@@ -10660,6 +10660,8 @@ static const struct hda_fixup alc269_fixups[] = { [ALC233_FIXUP_STARLABS_STARFIGHTER] = { .type = HDA_FIXUP_FUNC, .v.func = alc233_fixup_starlabs_starfighter, + .chained = true, + .chain_id = ALC269_FIXUP_STARLABS_LIMIT_INT_MIC_BOOST, }, [ALC294_FIXUP_BASS_SPEAKER_15] = { .type = HDA_FIXUP_FUNC,
@@ -11698,6 +11700,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1f66 ,0x0105 ,"Ayaneo Portable Game Player" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x2014 ,0x800a ,"Positivo ARN50" ,ALC269_FIXUP_LIMIT_INT_MIC_BOOST ),SND_PCI_QUIRK (0x2039 ,0x0001 ,"Inspur S14-G1" ,ALC295_FIXUP_CHROME_BOOK ), +SND_PCI_QUIRK (0x2145 ,0x0001 ,"Star Labs StarFighter" ,ALC233_FIXUP_STARLABS_STARFIGHTER ),SND_PCI_QUIRK (0x2782 ,0x0214 ,"VAIO VJFE-CL" ,ALC269_FIXUP_LIMIT_INT_MIC_BOOST ),SND_PCI_QUIRK (0x2782 ,0x0228 ,"Infinix ZERO BOOK 13" ,ALC269VB_FIXUP_INFINIX_ZERO_BOOK_13 ), SND_PCI_QUIRK(0x2782, 0x0232, "CHUWI CoreBook XPro", ALC269VB_FIXUP_CHUWI_COREBOOK_XPRO),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 294/877 netfilter: nf_tables: Tolerate chains with no remaining hooks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Phil Sutter <[email protected]>
commit fc0133428e7ad65aa6b7c8e65ccfe86e469e4512 upstream.
Do not drop a netdev-family chain if the last interface it is registered for vanishes. Users dumping and storing the ruleset upon shutdown to restore it upon next boot may otherwise lose the chain and all contained rules. They will still lose the list of devices, a later patch will fix that. For now, this aligns the event handler's behaviour with that for flowtables.
The controversal situation at netns exit should be no problem here:
event handler will unregister the hooks, core nftables cleanup code will drop the chain itself.
--- include/net/netfilter/nf_tables.h | 2 -- net/netfilter/nf_tables_api.c | 41 ------------------------------- net/netfilter/nft_chain_filter.c | 29 ++++++---------------- 3 files changed, 7 insertions(+), 65 deletions(-)
include/net/netfilter/nf_tables.h +0 -2
@@ -1238,8 +1238,6 @@ static inline bool nft_is_base_chain(const struct nft_chain *chain)return chain->flags &NFT_CHAIN_BASE ; } -int __nft_release_basechain (struct nft_ctx *ctx); -unsigned int nft_do_chain (struct nft_pktinfo *pkt,void *priv);static inline bool nft_use_inc (u32 *use)
net/netfilter/nf_tables_api.c +0 -41
47 lines not on this page · raw message
net/netfilter/nft_chain_filter.c +7 -22
@@ -322,34 +322,19 @@ static void nft_netdev_event(unsigned long event, struct net_device *dev, struct nft_ctx *ctx) {struct nft_base_chain *basechain =nft_base_chain (ctx->chain); -struct nft_hook *hook, *found =NULL ; -int n =0 ; +struct nft_hook *hook;list_for_each_entry (hook, &basechain->hook_list, list) { -if (hook->ops.dev == dev) - found = hook; - - n++; - } -if (!found) -return ; +if (hook->ops.dev != dev) +continue ; -if (n >1 ) {if (!(ctx->chain->table->flags &NFT_TABLE_F_DORMANT )) -nf_unregister_net_hook (ctx->net, &found->ops); +nf_unregister_net_hook (ctx->net, &hook->ops); -list_del_rcu (&found->list); -kfree_rcu (found, rcu); -return ; +list_del_rcu (&hook->list); +kfree_rcu (hook, rcu); +break ; } - -/* UNREGISTER events are also happening on netns exit. -* -* Although nf_tables core releases all tables/chains, only this event -* handler provides guarantee that hook->ops.dev is still accessible, -* so we cannot skip exiting net namespaces. -*/ -__nft_release_basechain (ctx); } static int nf_tables_netdev_event(struct notifier_block *this,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 295/877 netfilter: nf_tables: Simplify chain netdev notifier
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Phil Sutter <[email protected]>
commit 375f222800bc001bb9cbd2baa1daec006430aeba upstream.
With conditional chain deletion gone, callback code simplifies: Instead of filling an nft_ctx object, just pass basechain to the per-chain function. Also plain list_for_each_entry() is safe now.
--- net/netfilter/nft_chain_filter.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
net/netfilter/nft_chain_filter.c +7 -14
@@ -319,17 +319,16 @@ static const struct nft_chain_type nft_chain_filter_netdev = { };static void nft_netdev_event (unsigned long event,struct net_device *dev, -struct nft_ctx *ctx) +struct nft_base_chain *basechain) { -struct nft_base_chain *basechain =nft_base_chain (ctx->chain);struct nft_hook *hook;list_for_each_entry (hook, &basechain->hook_list, list) {if (hook->ops.dev != dev)continue ; -if (!(ctx->chain->table->flags &NFT_TABLE_F_DORMANT )) -nf_unregister_net_hook (ctx->net, &hook->ops); +if (!(basechain->chain.table->flags &NFT_TABLE_F_DORMANT )) +nf_unregister_net_hook (dev_net (dev), &hook->ops);list_del_rcu (&hook->list);kfree_rcu (hook, rcu);
@@ -343,25 +342,20 @@ static int nf_tables_netdev_event(struct notifier_block *this,struct net_device *dev =netdev_notifier_info_to_dev (ptr);struct nft_base_chain *basechain;struct nftables_pernet *nft_net; -struct nft_chain *chain, *nr; +struct nft_chain *chain;struct nft_table *table; -struct nft_ctx ctx = { - .net =dev_net (dev), - };if (event !=NETDEV_UNREGISTER )return NOTIFY_DONE ; - nft_net =nft_pernet (ctx.net); + nft_net =nft_pernet (dev_net (dev));mutex_lock (&nft_net->commit_mutex);list_for_each_entry (table, &nft_net->tables, list) {if (table->family !=NFPROTO_NETDEV && table->family !=NFPROTO_INET )continue ; - ctx.family = table->family; - ctx.table = table; -list_for_each_entry_safe (chain, nr, &table->chains, list) { +list_for_each_entry (chain, &table->chains, list) {if (!nft_is_base_chain (chain))continue ;
@@ -370,8 +364,7 @@ static int nf_tables_netdev_event(struct notifier_block *this, basechain->ops.hooknum != NF_INET_INGRESS)continue ; - ctx.chain = chain; -nft_netdev_event (event, dev, &ctx); +nft_netdev_event (event, dev, basechain); } }mutex_unlock (&nft_net->commit_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 296/877 xfrm: Refactor xfrm_input lock to reduce contention with RSS
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianbo Liu <[email protected]>
[ Upstream commit 10a11861943902fda74f37f456b45183b2bca270 ]
With newer NICs like mlx5 supporting RSS for IPsec crypto offload, packets for a single Security Association (SA) are scattered across multiple CPU cores for parallel processing. The xfrm_state spinlock (x->lock) is held for each packet during xfrm processing.
When multiple connections or flows share the same SA, this parallelism causes high lock contention on x->lock, creating a performance bottleneck and limiting scalability.
The original xfrm_input() function exacerbated this issue by releasing and immediately re-acquiring x->lock. For hardware crypto offload paths, this unlock/relock sequence is unnecessary and introduces significant overhead. This patch refactors the function to relocate the type_offload->input_tail call for the offload path, performing all necessary work while continuously holding the lock. This reordering is safe, since packets which don't pass the checks below will still fail them with the new code.
Performance testing with iperf using multiple parallel streams over a single IPsec SA shows significant improvement in throughput as the number of queues (and thus CPU cores) increases:
+-----------+---------------+--------------+-----------------+ | RX queues | Before (Gbps) | After (Gbps) | Improvement (%) | +-----------+---------------+--------------+-----------------+ | 2 | 32.3 | 34.4 | 6.5 | | 4 | 34.4 | 40.0 | 16.3 | | 6 | 24.5 | 38.3 | 56.3 | | 8 | 23.1 | 38.3 | 65.8 | | 12 | 18.1 | 29.9 | 65.2 | | 16 | 16.0 | 25.2 | 57.5 | +-----------+---------------+--------------+-----------------+
Stable-dep-of: 3cf5cdecd99c ("xfrm: save input state data before secpath resets")
--- net/xfrm/xfrm_input.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
net/xfrm/xfrm_input.c +7 -7
@@ -493,6 +493,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (encap_type ==-1 ) { async =1 ; seq =XFRM_SKB_CB (skb)->seq.input.low; +spin_lock (&x->lock); goto resume; }/* GRO call */
@@ -529,6 +530,8 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)XFRM_INC_STATS (net,LINUX_MIB_XFRMINHDRERROR ); goto drop; } + + nexthdr = x->type_offload->input_tail (x, skb); } goto lock;
@@ -626,11 +629,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) goto drop_unlock; } -spin_unlock (&x->lock); -if (xfrm_tunnel_check (skb, x, family)) {XFRM_INC_STATS (net,LINUX_MIB_XFRMINSTATEMODEERROR ); - goto drop; + goto drop_unlock; } seq_hi =htonl (xfrm_replay_seqhi (x, seq));
@@ -638,9 +639,8 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)XFRM_SKB_CB (skb)->seq.input.low = seq;XFRM_SKB_CB (skb)->seq.input.hi = seq_hi; -if (crypto_done) { - nexthdr = x->type_offload->input_tail (x, skb); - }else { +if (!crypto_done) { +spin_unlock (&x->lock);dev_hold (skb->dev); nexthdr = x->type->input (x, skb);
@@ -651,9 +651,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) }dev_put (skb->dev); +spin_lock (&x->lock); } resume: -spin_lock (&x->lock);if (nexthdr <0 ) {if (nexthdr == -EBADMSG ) { xfrm_audit_state_icvfail(x, skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 297/877 xfrm: Fix dev use-after-free in xfrm async resumption
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dong Chenchen <[email protected]>
[ Upstream commit 8045c0df98d4f14c54e5cb875f1c9c0ce89fe4ff ]
xfrm async resumption hold skb->dev refcnt until after transport_finish. However, xfrm_rcv_cb may modify skb->dev to tunnel dev without taking device reference, such as vti_rcv_cb. The subsequent async resumption will decrement the tunnel device's reference count, which lead to uaf of tunnel dev and refcnt leak of orig dev as below:
unregister_netdevice: waiting for vti1 to become free. Usage count = -2
Stash the original skb->dev to fix refcnt imbalance. The new skb->dev set by xfrm_rcv_cb can race with device teardown. Extend rcu protection over xfrm_rcv_cb and transport_finish to prevent races.
Backport to 6.12: retain the synchronous xfrm_inner_mode_input() error handling. This tree lacks the mode_cbs infrastructure that introduced the -EINPROGRESS branch, so omit the dev_put() conversion for that absent branch. Keep the original-device reference handling and extended RCU protection for the existing receive paths.
This supplies the receive, transport-finish and drop-path context for 3cf5cdecd99c ("xfrm: save input state data before secpath resets"), which applies without further changes.
Stable-dep-of: 3cf5cdecd99c ("xfrm: save input state data before secpath resets")
--- net/ipv4/xfrm4_input.c | 2 -- net/ipv6/xfrm6_input.c | 2 -- net/xfrm/xfrm_input.c | 27 +++++++++++++++------------ 3 files changed, 15 insertions(+), 16 deletions(-)
net/ipv4/xfrm4_input.c +0 -2
@@ -76,8 +76,6 @@ int xfrm4_transport_finish(struct sk_buff *skb, int async)NF_HOOK (NFPROTO_IPV4 ,NF_INET_PRE_ROUTING ,dev_net (dev),NULL , skb, dev,NULL , xfrm4_rcv_encap_finish); -if (async) -dev_put (dev);return 0 ; }
net/ipv6/xfrm6_input.c +0 -2
@@ -71,8 +71,6 @@ int xfrm6_transport_finish(struct sk_buff *skb, int async)NF_HOOK (NFPROTO_IPV6 ,NF_INET_PRE_ROUTING ,dev_net (dev),NULL , skb, dev,NULL , xfrm6_transport_finish2); -if (async) -dev_put (dev);return 0 ; }
net/xfrm/xfrm_input.c +15 -12
@@ -457,6 +457,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) {const struct xfrm_state_afinfo *afinfo;struct net *net =dev_net (skb->dev); +struct net_device *dev = skb->dev;int err;__be32 seq;__be32 seq_hi;
@@ -483,7 +484,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) LINUX_MIB_XFRMINSTATEINVALID);if (encap_type ==-1 ) -dev_put (skb->dev); +dev_put (dev); goto drop; }
@@ -641,16 +642,16 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (!crypto_done) {spin_unlock (&x->lock); -dev_hold (skb->dev); +dev_hold (dev); nexthdr = x->type->input (x, skb);if (nexthdr == -EINPROGRESS ) {if (async) -dev_put (skb->dev); +dev_put (dev);return 0 ; } -dev_put (skb->dev); +dev_put (dev);spin_lock (&x->lock); } resume:
@@ -707,9 +708,12 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) crypto_done = false; }while (!err); +rcu_read_lock (); err =xfrm_rcv_cb (skb, family, x->type->proto,0 ); -if (err) +if (err) { +rcu_read_unlock (); goto drop; + }nf_reset_ct (skb);
@@ -720,8 +724,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (skb_valid_dst (skb))skb_dst_drop (skb);if (async) -dev_put (skb->dev); +dev_put (dev);gro_cells_receive (&gro_cells, skb); +rcu_read_unlock ();return 0 ; }else { xo =xfrm_offload (skb);
@@ -729,23 +734,21 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) xfrm_gro = xo->flags &XFRM_GRO ; err = -EAFNOSUPPORT ; -rcu_read_lock (); afinfo =xfrm_state_afinfo_get_rcu (x->props.family);if (likely (afinfo)) err = afinfo->transport_finish (skb, xfrm_gro || async); -rcu_read_unlock ();if (xfrm_gro) { sp =skb_sec_path (skb);if (sp) sp->olen =0 ;if (skb_valid_dst (skb))skb_dst_drop (skb); -if (async) -dev_put (skb->dev);gro_cells_receive (&gro_cells, skb); -return err; } +if (async) +dev_put (dev); +rcu_read_unlock ();return err; }
@@ -753,7 +756,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)spin_unlock (&x->lock); drop:if (async) -dev_put (skb->dev); +dev_put (dev);xfrm_rcv_cb (skb, family, x && x->type ? x->type->proto : nexthdr,-1 );kfree_skb (skb);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 298/877 xfrm: save input state data before secpath resets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 3cf5cdecd99c9c186a5ea518d93bbf3045b6e3aa ]
xfrm_input() stores the current xfrm_state in the skb secpath while it continues receive-side processing. Some input paths can reset that secpath before xfrm_input() has finished dereferencing the state.
Receive callback users such as VTI and XFRM interfaces can reset the secpath. The VTI receive path does so before checking whether the packet crosses network namespaces, while the XFRM interface path does so only for cross-network-namespace packets. The XFRM_MAX_DEPTH error path can also reset the secpath before the final drop callback reports the current state's protocol.
If secpath_reset() drops the last state reference while the state is concurrently deleted, xfrm_input() can still dereference the freed state when selecting transport_finish() or reporting the drop callback protocol.
Save the state protocol on the stack while the state is still valid, and use the already saved address family for transport_finish(). A larval XFRM_STATE_ACQ state has no type, so retain nexthdr as its protocol. This preserves the existing drop-path fallback while avoiding the post-reset state dereferences without adding an extra state reference to every received packet.
--- net/xfrm/xfrm_input.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
net/xfrm/xfrm_input.c +8 -3
@@ -464,6 +464,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)struct xfrm_state *x =NULL ;xfrm_address_t *daddr;u32 mark = skb->mark; +u8 xfrm_proto = nexthdr;unsigned int family =AF_UNSPEC ;int decaps =0 ;int async =0 ;
@@ -475,6 +476,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (encap_type <0 || (xo && (xo->flags &XFRM_GRO || encap_type ==0 || encap_type ==UDP_ENCAP_ESPINUDP ))) { x =xfrm_input_state (skb); + xfrm_proto = x->type ? x->type->proto : nexthdr;if (unlikely (x->km.state !=XFRM_STATE_VALID )) {if (x->km.state ==XFRM_STATE_ACQ )
@@ -578,11 +580,13 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) x =xfrm_input_state_lookup (net, mark, daddr, spi, nexthdr, family);if (x ==NULL ) { + xfrm_proto = nexthdr;secpath_reset (skb);XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOSTATES );xfrm_audit_state_notfound (skb, family, spi, seq); goto drop; } + xfrm_proto = x->type ? x->type->proto : nexthdr;if (unlikely (x->dir && x->dir !=XFRM_SA_DIR_IN )) {secpath_reset (skb);
@@ -590,6 +594,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)xfrm_audit_state_notfound (skb, family, spi, seq);xfrm_state_put (x); x =NULL ; + xfrm_proto = nexthdr; goto drop; }
@@ -709,7 +714,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) }while (!err);rcu_read_lock (); - err =xfrm_rcv_cb (skb, family, x->type->proto,0 ); + err =xfrm_rcv_cb (skb, family, xfrm_proto,0 );if (err) {rcu_read_unlock (); goto drop;
@@ -734,7 +739,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) xfrm_gro = xo->flags &XFRM_GRO ; err = -EAFNOSUPPORT ; - afinfo =xfrm_state_afinfo_get_rcu (x->props.family); + afinfo =xfrm_state_afinfo_get_rcu (family);if (likely (afinfo)) err = afinfo->transport_finish (skb, xfrm_gro || async);if (xfrm_gro) {
@@ -757,7 +762,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) drop:if (async)dev_put (dev); -xfrm_rcv_cb (skb, family, x && x->type ? x->type->proto : nexthdr,-1 ); +xfrm_rcv_cb (skb, family, xfrm_proto,-1 );kfree_skb (skb);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 299/877 remoteproc: qcom_q6v5_adsp: Fix iommu_unmap() usage
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mostafa Saleh <[email protected]>
[ Upstream commit 0d8e2195bce6f08c1c53c5ef4d7347fe46418101 ]
During adsp_map_carveout, the IOVA is computed by combining the physical address and the SID:
iova = adsp->mem_phys | (sid << 32);
However, adsp_unmap_carveout() uses the physical address and not the IOVA in iommu_unmap(), causing the unmap to fail or leak mappings because the address doesn't match the original IOVA.
Cache the constructed IOVA within the qcom_adsp device struct during mapping and use it during unmapping.
--- drivers/remoteproc/qcom_q6v5_adsp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/remoteproc/qcom_q6v5_adsp.c +4 -4
@@ -104,6 +104,7 @@ struct qcom_adsp {struct completion stop_done;phys_addr_t mem_phys; +unsigned long iova;phys_addr_t mem_reloc;void *mem_region;size_t mem_size;
@@ -333,7 +334,7 @@ static void adsp_unmap_carveout(struct rproc *rproc)struct qcom_adsp *adsp = rproc->priv;if (adsp->has_iommu) -iommu_unmap (rproc->domain, adsp->mem_phys, adsp->mem_size); +iommu_unmap (rproc->domain, adsp->iova, adsp->mem_size); }static int adsp_map_carveout (struct rproc *rproc)
@@ -341,7 +342,6 @@ static int adsp_map_carveout(struct rproc *rproc)struct qcom_adsp *adsp = rproc->priv;struct of_phandle_args args;long long sid; -unsigned long iova;int ret;if (!adsp->has_iommu)
@@ -358,9 +358,9 @@ static int adsp_map_carveout(struct rproc *rproc)of_node_put (args.np);/* Add SID configuration for ADSP Firmware to SMMU */ - iova = adsp->mem_phys | (sid <<32 ); + adsp->iova = adsp->mem_phys | (sid <<32 ); - ret =iommu_map (rproc->domain, iova, adsp->mem_phys, + ret =iommu_map (rproc->domain, adsp->iova, adsp->mem_phys, adsp->mem_size,IOMMU_READ |IOMMU_WRITE ,GFP_KERNEL );if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 300/877 KVM: s390: Fix IRQ injection with SIGP Stop and Store Status
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudio Imbrenda <[email protected]>
[ Upstream commit d343407b728a80b74be3c24b59f15e60289ea527 ]
When __inject_sigp_stop() is called for a Stop and Store Status operation, if the vCPU is running, the interrupt is marked as pending and the status is stored by the thread performing the KVM_RUN IOCTL.
If the vCPU is already stopped, the status is stored immediately.
Storing the status means writing into userspace, which might fault, and __inject_sigp_stop() is called from do_inject_vcpu() which in turn is always called holding a spinlock, which is obviously an issue.
Fix this by returning -EWOULDBLOCK from __inject_sigp_stop(), and adding a bool flag to indicate whether a store status is needed. The callers of do_inject_vcpu() are modified to pass the pointer to the bool flag; whenever a Store Status operation is needed, the callers can now perform it outside the spinlock.
Opportunistically refactor kvm_s390_set_irq_state() to use scoped_guard() and __free().
Message-ID: <[email protected]>
--- arch/s390/kvm/interrupt.c | 70 +++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 32 deletions(-)
arch/s390/kvm/interrupt.c +38 -32
@@ -1586,23 +1586,21 @@ static int __inject_set_prefix(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) }#define KVM_S390_STOP_SUPP_FLAGS (KVM_S390_STOP_FLAG_STORE_STATUS) -static int __inject_sigp_stop (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) +static int __inject_sigp_stop (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq,bool *storestatus) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;struct kvm_s390_stop_info *stop = &li->irq.stop; -int rc =0 ; vcpu->stat.inject_stop_signal++;trace_kvm_s390_inject_vcpu (vcpu->vcpu_id,KVM_S390_SIGP_STOP ,0 ,0 );if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS )return -EINVAL ; -if (is_vcpu_stopped (vcpu)) { -if (irq->u.stop.flags &KVM_S390_STOP_FLAG_STORE_STATUS ) - rc =kvm_s390_store_status_unloaded (vcpu, -KVM_S390_STORE_STATUS_NOADDR ); -return rc; +if (!(irq->u.stop.flags &KVM_S390_STOP_FLAG_STORE_STATUS )) +return 0 ; + *storestatus = true; +return -EWOULDBLOCK ; }if (test_and_set_bit (IRQ_PEND_SIGP_STOP , &li->pending_irqs))
@@ -2142,7 +2140,7 @@ void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu)spin_unlock (&li->lock); } -static int do_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) +static int do_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq,bool *storestatus) {int rc;
@@ -2154,7 +2152,7 @@ static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) rc =__inject_set_prefix (vcpu, irq);break ;case KVM_S390_SIGP_STOP : - rc =__inject_sigp_stop (vcpu, irq); + rc =__inject_sigp_stop (vcpu, irq, storestatus);break ;case KVM_S390_RESTART : rc =__inject_sigp_restart (vcpu);
@@ -2190,11 +2188,16 @@ static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)int kvm_s390_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; +bool storestatus = false;int rc;spin_lock (&li->lock); - rc =do_inject_vcpu (vcpu, irq); + rc =do_inject_vcpu (vcpu, irq, &storestatus);spin_unlock (&li->lock); + +if (rc == -EWOULDBLOCK && storestatus) + rc =kvm_s390_store_status_unloaded (vcpu,KVM_S390_STORE_STATUS_NOADDR ); +if (!rc)kvm_s390_vcpu_wakeup (vcpu);return rc;
@@ -2930,7 +2933,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,int kvm_s390_set_irq_state (struct kvm_vcpu *vcpu,void __user *irqstate,int len) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; -struct kvm_s390_irq *buf; + struct kvm_s390_irq *buf __free(kvfree) = NULL; +bool tmp, storestatus = false;int r =0 ;int n;
@@ -2938,31 +2942,33 @@ int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, void __user *irqstate, int lenif (!buf)return -ENOMEM ; -if (copy_from_user ((void *) buf, irqstate, len)) { - r = -EFAULT ; - goto out_free; - } +if (copy_from_user ((void *)buf, irqstate, len)) +return -EFAULT ; -/* -* Don't allow setting the interrupt state -* when there are already interrupts pending -*/ -spin_lock (&li->lock); -if (li->pending_irqs) { - r = -EBUSY ; - goto out_unlock; - } + scoped_guard(spinlock, &li->lock) { +/* +* Don't allow setting the interrupt state +* when there are already interrupts pending +*/ +if (li->pending_irqs) +return -EBUSY ; -for (n =0 ; n < len /sizeof (*buf); n++) { - r =do_inject_vcpu (vcpu, &buf[n]); -if (r) -break ; +for (n =0 ; n < len /sizeof (*buf); n++) { + tmp = false; + r =do_inject_vcpu (vcpu, &buf[n], &tmp); +if (r == -EWOULDBLOCK && tmp) { + storestatus = true; + r =0 ; + } +if (r) +break ; + } } -out_unlock: -spin_unlock (&li->lock); -out_free: -vfree (buf); +if (storestatus) { + n =kvm_s390_store_status_unloaded (vcpu,KVM_S390_STORE_STATUS_NOADDR ); +return r ? r : n; + }return r; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 301/877 bpf: Fix bpf_skb_change_tail wrt csum partial skbs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 3b55f350c68a0aceff108f47f9d31f47ebffaf7b ]
Cilium generates ICMP "frag needed" replies from BPF when a LB DSR packet exceeds the egress MTU. The reply is built by first trimming the packet down to target size via bpf_skb_change_tail(), and then pushing the ICMP error headers in front of it.
The trim is rejected for skbs which carry a checksum offload, e.g. TCP packets aggregated by GRO on ingress where tcp_gro_complete() leaves the skb as CHECKSUM_PARTIAL. __bpf_skb_min_len() raises the minimum length to the end of the L4 checksum field, so a trim to 42 bytes bails out with -EINVAL given a min_len of 52 in this case, and due to that the ICMP generator fails. This is not the case if GRO is turned off.
Fix this bpf_skb_change_tail() restriction and drop the checksum offload when the new length no longer covers the checksum field. The BPF program rewrites the skb into an ICMP error and computes the checksum itself anyway.
--- net/core/filter.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/core/filter.c +5 -6
@@ -3833,12 +3833,6 @@ static u32 __bpf_skb_min_len(const struct sk_buff *skb)if (offset >0 ) min_len = offset; } -if (skb->ip_summed ==CHECKSUM_PARTIAL ) { - offset =skb_checksum_start_offset (skb) + - skb->csum_offset +sizeof (__sum16); -if (offset >0 ) - min_len = offset; - }return min_len; }
@@ -3855,6 +3849,11 @@ static int bpf_skb_grow_rcsum(struct sk_buff *skb, unsigned int new_len)static int bpf_skb_trim_rcsum (struct sk_buff *skb,unsigned int new_len) { +if (skb->ip_summed ==CHECKSUM_PARTIAL && + new_len <skb_checksum_start_offset (skb) + skb->csum_offset + +sizeof (__sum16)) + skb->ip_summed =CHECKSUM_NONE ; +return __skb_trim_rcsum (skb, new_len); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 302/877 bpf: Disallow bpf_skb_pull_data() for LWT_SEG6LOCAL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit e4a62833adff6ef0fe7c0b90393204fe3c26b5c5 ]
An LWT_SEG6LOCAL program can invalidate its cached SRH with bpf_lwt_seg6_adjust_srh() and then call bpf_skb_pull_data(). The latter may reallocate skb->head, leaving the per-CPU SRH pointer dangling. Post-program SRH validation then writes through that pointer.
Disallow bpf_skb_pull_data() for LWT_SEG6LOCAL programs so the verifier rejects this unsafe helper combination. Other LWT program types continue to expose the helper through lwt_out_func_proto().
--- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/filter.c +2 -0
@@ -8666,6 +8666,8 @@ static const struct bpf_func_proto * lwt_seg6local_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { switch (func_id) { + case BPF_FUNC_skb_pull_data: + return NULL;#if IS_ENABLED (CONFIG_IPV6_SEG6_BPF )case BPF_FUNC_lwt_seg6_store_bytes:return &bpf_lwt_seg6_store_bytes_proto;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 303/877 selftests/ftrace: Fix unique symbol check in kprobe_non_uniq_symbol.tc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Schnelle <[email protected]>
[ Upstream commit d22c3e0088e85be8131f7a9283f759cdbb20726d ]
The current regex also matches symbols in modules, which makes the test fail on s390 where name_show is present only once in the kernel, but also multiple times in modules:
000001b1401cdc20 t name_show000001b0c05e6c40 t name_show [mdev]000001b0c0495f30 t name_show [i2c_core]
Fix this by changing the regular expression to only match the function name.
--- .../selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc +1 -1
@@ -6,7 +6,7 @@ SYMBOL='name_show' # We skip this test on kernel where SYMBOL is unique or does not exist. -if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}" /proc/kallsyms)" -le '1' ]; then +if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}$" /proc/kallsyms)" -le '1' ]; then exit_unsupported fi
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 304/877 bpf: Fix divide-by-zero in btf_struct_walk()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit b0b3dc66529676228cb938cbcad66920f735c223 ]
When an access goes past the struct and the last member is a flexible array, btf_struct_walk() folds the offset back into a single element with (off - moff) % t->size, but never checks that the element type has a size.
BTF takes an empty struct, so this in program BTF
/* event could be empty */
struct event {
#ifdef HAVE_TIMESTAMP
__u64 ts;
#endif
};
struct batch {
int nr;
struct event events[];
};divides by zero at prog load time. Getting there needs a PTR_TO_BTF_ID that is not MEM_ALLOC, e.g. a plain read of a local kptr stashed in a map from a sleepable program.
Oops: divide error: 0000 [#1] SMP KASAN PTI RIP: 0010:btf_struct_walk+0x53f/0x1570 Call Trace: <TASK> btf_struct_access+0x42a/0xcd0 check_ptr_to_btf_access+0x4dc/0x1160 check_mem_access+0x3a45/0x8740 check_load_mem+0x36a/0xd10 do_check_common+0x3ef0/0xb210 bpf_check+0x6d3b/0x8580 bpf_prog_load+0xf7c/0x2720 __sys_bpf+0xa83/0x3690 __x64_sys_bpf+0xc7/0x150 x64_sys_call+0x1f3f/0x27e0 do_syscall_64+0xe5/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK>
Reject a zero-sized element type. The fixed array path in the same function already bails out on the same thing:
btf_struct_walk() ... /* skip empty array */ if (moff == mtrue_end) continue; msize /= total_nelems;
--- kernel/bpf/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
@@ -6851,7 +6851,7 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,if (btf_type_is_int (t))return WALK_SCALAR ; -if (!btf_type_is_struct (t)) +if (!btf_type_is_struct (t) || !t->size) goto error; off = (off - moff) % t->size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 305/877 bpf: Fix out-of-bounds read of sk_protocol in bpf_sock_destroy()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 01b245ba016d44861690594e10f67e026ce8552f ]
sk_protocol lives in struct sock, not in struct sock_common. A timewait or request sock handed to bpf_sock_destroy() by the tcp iterator is neither, so reading sk->sk_protocol runs past the object:
==================================================================
BUG: KASAN: slab-out-of-bounds in bpf_sock_destroy+0xc7/0xe0 Read of size 2 at addr ffff8881047d11b4 by task test_progs/428 Tainted: [W]=WARN Call Trace: <TASK> dump_stack_lvl+0x91/0xf0 print_report+0xd1/0x630 kasan_report+0xf3/0x130 __asan_report_load2_noabort+0x14/0x30 bpf_sock_destroy+0xc7/0xe0 bpf_prog_c3dd61f9d9cd9f37_iter_tcp6_timewait+0x9f/0xb7 bpf_iter_run_prog+0x538/0xde0 bpf_iter_tcp_seq_show+0x26b/0x4b0 bpf_seq_read+0x424/0x1210 vfs_read+0x197/0xe40 ksys_read+0x119/0x240 __x64_sys_read+0x72/0xc0 x64_sys_call+0x647/0x27e0 do_syscall_64+0xe5/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Only check sk_protocol on full socks. tcp_abort() already knows how to deal with TIME_WAIT and NEW_SYN_RECV socks. Also fix the comment, it never matched the code.
--- net/core/filter.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/core/filter.c +9 -4
@@ -12262,8 +12262,9 @@ __bpf_kfunc_start_defs();* @sock: Pointer to socket to be destroyed * * Return: -* On error, may return EPROTONOSUPPORT, EINVAL. -* EPROTONOSUPPORT if protocol specific destroy handler is not supported. +* On error, may return EOPNOTSUPP, or whatever the protocol specific +* destroy handler returns. +* EOPNOTSUPP if protocol specific destroy handler is not supported. * 0 otherwise */ __bpf_kfunc int bpf_sock_destroy(struct sock_common *sock)
@@ -12275,8 +12276,12 @@ __bpf_kfunc int bpf_sock_destroy(struct sock_common *sock)* Supporting protocols will need to acquire sock lock in the BPF context * prior to invoking this kfunc. */ -if (!sk->sk_prot->diag_destroy || (sk->sk_protocol !=IPPROTO_TCP && - sk->sk_protocol !=IPPROTO_UDP )) +if (!sk->sk_prot->diag_destroy) +return -EOPNOTSUPP ; + +if (sk_fullsock (sk) && + sk->sk_protocol !=IPPROTO_TCP && + sk->sk_protocol !=IPPROTO_UDP )return -EOPNOTSUPP ;return sk->sk_prot->diag_destroy (sk,ECONNABORTED );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 306/877 tcp: Skip cond_resched() in inet_csk_listen_stop() under BPF context
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit eaab8cab451b9502ce224cd202550375b894a467 ]
bpf_sock_destroy() runs from the tcp iterator, under rcu_read_lock(). If the sock is a listener that still has children in its accept queue, tcp_abort() ends up in inet_csk_listen_stop() and the cond_resched() there trips the debug check:
BUG: sleeping function called from invalid context at net/ipv4/inet_connection_sock.c:1523
in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 628, name: test_progspreempt_count: 0, expected: 0
RCU nest depth: 1, expected: 0
locks held by test_progs/628: 3, last CPU#3:
#0: ffff8881158cee18 (&p->lock){+.+.}-{4:4}, at: bpf_seq_read+0x56/0x1210 #1: ffff8881106bb858 (sk_lock-AF_INET6){+.+.}-{0:0}, at: bpf_iter_tcp_seq_show+0x32b/0x4b0 #2: ffffffffb435af20 (rcu_read_lock){....}-{1:3}, at: bpf_iter_run_prog+0x46b/0xde0
CPU: 3 UID: 0 PID: 628 Comm: test_progs Tainted: G W 7.2.0+ #65 PREEMPT Tainted: [W]=WARN Call Trace: <TASK> dump_stack_lvl+0xc1/0xf0 dump_stack+0x10/0x20 __might_resched+0x3d2/0x610 inet_csk_listen_stop+0x7b/0xbf0 tcp_abort+0x23b/0x3b0 bpf_sock_destroy+0xfc/0x140 bpf_prog_448133d24601754f_iter_tcp6_server+0x81/0x8a bpf_iter_run_prog+0x538/0xde0 bpf_iter_tcp_seq_show+0x26b/0x4b0 bpf_seq_read+0x424/0x1210 vfs_read+0x197/0xe40 ksys_read+0x119/0x240 __x64_sys_read+0x72/0xc0 x64_sys_call+0x647/0x27e0 do_syscall_64+0xe5/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7fad39b28aca RSP: 002b:00007ffc381c61c0 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 RAX: ffffffffffffffda RBX: 00007ffc381c6a88 RCX: 00007fad39b28aca RDX: 0000000000000032 RSI: 00007ffc381c6250 RDI: 0000000000000014 RBP: 00007ffc381c61e0 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003 R13: 0000000000000000 R14: 000055f077c1bbb0 R15: 00007fad3a0f3000 </TASK>
The commit that added the kfunc already guards lock_sock() in tcp_abort() and udp_abort() with has_current_bpf_ctx(), but missed the listener path. Do the same for the cond_resched(). The loop runs inside the iterator's rcu_read_lock(), it must not reschedule or report a quiescent state there.
--- net/ipv4/inet_connection_sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/inet_connection_sock.c +2 -1
@@ -1541,7 +1541,8 @@ void inet_csk_listen_stop(struct sock *sk)local_bh_enable ();sock_put (child); -cond_resched (); +if (!has_current_bpf_ctx ()) +cond_resched (); }if (queue->fastopenq.rskq_rst_head) {/* Free all the reqs queued in rskq_rst_head. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 307/877 HID: elecom: fix bus type for M-XGL20DLBK
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oscar Priego Verdugo <[email protected]>
[ Upstream commit 8e2a4b458ad25e13422bb059758c30a6562aa9cf ]
The M-XGL20DLBK is matched as a USB device by hid-elecom, but its entry in hid_have_special_driver[] uses HID_BLUETOOTH_DEVICE.
This prevents the special-driver quirk entry from matching the USB device handled by hid-elecom. Use HID_USB_DEVICE there as well.
--- drivers/hid/hid-quirks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-quirks.c +1 -1
@@ -416,7 +416,7 @@ static const struct hid_device_id hid_have_special_driver[] = {#endif #if IS_ENABLED(CONFIG_HID_ELECOM) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XGL20DLBK) }, + { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XGL20DLBK) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1MRBK_01AC) }, { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_00FB) }, { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_018F) },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 308/877 KVM: x86/pmu: Move Intel PMU global MSRs to intel_is_valid_msr()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jim Mattson <[email protected]>
[ Upstream commit 79a71cc2568f4b5d42284da2aa26f3b4f47ce01b ]
Commit c85cdc1cc1ea ("KVM: x86/pmu: Move handling PERF_GLOBAL_CTRL and friends to common x86") moved the existence check for the following Intel PMU MSRs to kvm_pmu_is_valid_msr():
- MSR_CORE_PERF_GLOBAL_STATUS
- MSR_CORE_PERF_GLOBAL_CTRL
- MSR_CORE_PERF_GLOBAL_OVF_CTRL
That commit deemed these MSRs valid whenever pmu->version > 1. It intended to share the check with AMD PerfMonV2 because both vendor implementations require version 2 or greater for global PMU controls. However, as noted in the commit message, AMD uses different MSR indices for its global PMU registers.
Commit 4a2771895ca6 ("KVM: x86/svm/pmu: Add AMD PerfMonV2 support") subsequently added AMD PerfMonV2 support and set pmu->version = 2. Because kvm_pmu_is_valid_msr() validated the Intel MSRs whenever pmu->version > 1, KVM incorrectly permitted AMD guests with PerfMonV2 to access these Intel MSRs without a #GP.
Move the validation of these Intel MSRs to intel_is_valid_msr() and remove the common switch statement from kvm_pmu_is_valid_msr(). AMD already validates its own global PMU MSRs in amd_is_valid_msr().
--- arch/x86/kvm/pmu.c | 8 -------- arch/x86/kvm/vmx/pmu_intel.c | 3 +++ 2 files changed, 3 insertions(+), 8 deletions(-)
arch/x86/kvm/pmu.c +0 -8
@@ -614,14 +614,6 @@ void kvm_pmu_deliver_pmi(struct kvm_vcpu *vcpu)bool kvm_pmu_is_valid_msr (struct kvm_vcpu *vcpu,u32 msr) { -switch (msr) { -case MSR_CORE_PERF_GLOBAL_STATUS : -case MSR_CORE_PERF_GLOBAL_CTRL : -case MSR_CORE_PERF_GLOBAL_OVF_CTRL : -return kvm_pmu_has_perf_global_ctrl (vcpu_to_pmu (vcpu)); -default : -break ; - }return kvm_pmu_call (msr_idx_to_pmc)(vcpu, msr) ||kvm_pmu_call (is_valid_msr)(vcpu, msr); }
arch/x86/kvm/vmx/pmu_intel.c +3 -0
@@ -154,6 +154,9 @@ static bool intel_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr)int ret;switch (msr) { +case MSR_CORE_PERF_GLOBAL_STATUS : +case MSR_CORE_PERF_GLOBAL_CTRL : +case MSR_CORE_PERF_GLOBAL_OVF_CTRL :case MSR_CORE_PERF_FIXED_CTR_CTRL :return kvm_pmu_has_perf_global_ctrl (pmu);case MSR_IA32_PEBS_ENABLE :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 309/877 bpf: Avoid soft lockup in __htab_map_lookup_and_delete_batch()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jose Fernandez (Anthropic) <[email protected]>
[ Upstream commit 85136bf22404474a815fc0ed26ec0d1cbc1bc3f9 ]
__htab_map_lookup_and_delete_batch() has no rescheduling point. The batch count bounds how many entries are copied out, not how many buckets are visited, so one BPF_MAP_LOOKUP_BATCH call can walk the map end to end. The empty-bucket fast path is worse: it stays inside a single rcu_read_lock() / bpf_disable_instrumentation() section for any run of consecutive empty buckets.
That holds up on small maps, but it falls apart at scale. On a 144-CPU arm64 host running a CONFIG_PREEMPT_NONE kernel, periodic BPF_MAP_LOOKUP_BATCH calls against an LRU hash map with 16,777,216 buckets held a CPU inside the batch op for 77+ seconds and triggered the soft lockup watchdog.
Commit 75134f16e7dd ("bpf: Add schedule points in batch ops") fixed this same problem in the generic batch ops, but not in this htab-native path, which every htab-based hash map variant uses for its lookup[_and_delete] batch ops.
Complete that fix here. Leave the critical section after 64 consecutive empty buckets, call cond_resched_tasks_rcu_qs(), and resume at the saved bucket cursor. No locks are held at that point, and resuming from the cursor is already the function's behavior for non-empty buckets. Add the same call to the per-bucket loop after copy_to_user(), where every lock has been dropped. cond_resched_rcu() is not enough here: sleeping with bpf_prog_active elevated makes tracing programs on that CPU silently skip their invocations.
Plain cond_resched() is not enough either. It is a no-op under PREEMPT and PREEMPT_LAZY, the only models arm64 and x86 have offered since commit 7dadeaa6e851 ("sched: Further restrict the preemption modes"). It is also never a Tasks RCU quiescent state, in any model: the reschedule counts as a preemption. The walking task stays a holdout and stalls every synchronize_rcu_tasks() caller, ftrace and BPF trampoline teardown included, until the syscall returns [1]. cond_resched_tasks_rcu_qs() is the usual tool for that [2]. It reports the quiescent state at each yield and still reschedules as cond_resched() does on PREEMPT_NONE and PREEMPT_VOLUNTARY kernels.
--- kernel/bpf/hashtab.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
kernel/bpf/hashtab.c +21 -3
@@ -1706,6 +1706,12 @@ static int htab_lru_percpu_map_lookup_and_delete_elem(struct bpf_map *map, flags); } +/* +* Max consecutive empty buckets to walk in one RCU + +* instrumentation-disabled section before rescheduling. +*/ +#define HTAB_BATCH_EMPTY_RESCHED 64 + static int __htab_map_lookup_and_delete_batch(struct bpf_map *map, const union bpf_attr *attr,
@@ -1727,6 +1733,7 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map,unsigned long flags =0 ;bool locked = false;struct htab_elem *l; +u32 empty_cnt =0 ;struct bucket *b;int ret =0 ;
@@ -1896,12 +1903,21 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, } next_batch: -/* If we are not copying data, we can go to next bucket and avoid -* unlocking the rcu. +/* +* If we are not copying data, we can go to next bucket and avoid +* unlocking the rcu. Bound the walk though: after +* HTAB_BATCH_EMPTY_RESCHED consecutive empty buckets, fully exit +* the critical section (no locks are held here) and reschedule. */ if (!bucket_cnt && (batch +1 < htab->n_buckets)) { batch++; - goto again_nocopy; +if (++empty_cnt <HTAB_BATCH_EMPTY_RESCHED ) + goto again_nocopy; + empty_cnt =0 ; +rcu_read_unlock (); +bpf_enable_instrumentation (); +cond_resched_tasks_rcu_qs (); + goto again; }rcu_read_unlock ();
@@ -1915,11 +1931,13 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, } total += bucket_cnt; + empty_cnt =0 ; batch++;if (batch >= htab->n_buckets) { ret = -ENOENT ; goto after_loop; } +cond_resched_tasks_rcu_qs (); goto again; after_loop:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 310/877 bpf: Fix out-of-bounds read of rtt_min in sock_ops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 75f8cf22463d82bb1fb0239a3d485fc8f4c8ef03 ]
A sockops prog reading skops->rtt_min never checks the sk type: on the tcp_conn_request() path sock_ops->sk is a request_sock (non-full), and the ctx rewrite casts it to a tcp_sock (full) and reads rtt_min past the end of the request_sock, returning dirty adjacent memory.
SEC("sockops")
int prog(struct bpf_sock_ops *skops)
{
switch (skops->op) {
case BPF_SOCK_OPS_RWND_INIT:
leak = skops->rtt_min; /* reads the request_sock OOB */
...
}
}For instance one such read returned rtt_min=0xffff8881, the high half of a leaked kernel pointer.
Guarding that cast is exactly what SOCK_OPS_GET_FIELD() does -- it checks is_locked_tcp_sock and returns 0 when sock_ops->sk is not a locked full socket. Every other tcp_sock field in sock_ops goes through it; rtt_min is the only one open-coded, so it skips the check.
Read rtt_min through SOCK_OPS_GET_FIELD() too. rtt_min is a bit special:
it is a struct minmax and we only want the current min, so pass rtt_min.s[0].v. That is equivalent to the old hand-computed offset
offsetof(struct tcp_sock, rtt_min) + sizeof_field(struct minmax_sample, t)
(s[0] sits at rtt_min + 0 and .v at + sizeof(.t), i.e. what minmax_get() returns), so the loaded field is unchanged and only the full-sock guard is added. The two BUILD_BUG_ON()s that protected the hand-computed offset are no longer needed.
Before patch:
0: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk 1: r1 = *(u32 *)(r1 +2324) ; ((tcp_sock *)sk)->rtt_min.s[0].v
After patch:
0: *(u64 *)(r1 +56) = r9 1: r9 = *(u8 *)(r1 +50) ; is_locked_tcp_sock 2: if r9 == 0 goto pc+4 ; not a locked full sock -> 0 3: r9 = *(u64 *)(r1 +56) 4: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk 5: r1 = *(u32 *)(r1 +2324) ; rtt_min.s[0].v 6: goto pc+2 7: r9 = *(u64 *)(r1 +56) 8: r1 = 0
--- net/core/filter.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
net/core/filter.c +1 -12
@@ -10731,18 +10731,7 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct bpf_sock_ops , rtt_min): - BUILD_BUG_ON(sizeof_field(struct tcp_sock, rtt_min) != - sizeof(struct minmax)); -BUILD_BUG_ON (sizeof (struct minmax ) < -sizeof (struct minmax_sample )); - - *insn++ =BPF_LDX_MEM (BPF_FIELD_SIZEOF ( - struct bpf_sock_ops_kern, sk), - si->dst_reg, si->src_reg, - offsetof(struct bpf_sock_ops_kern , sk)); - *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->dst_reg, - offsetof(struct tcp_sock , rtt_min) + - sizeof_field(struct minmax_sample, t)); + SOCK_OPS_GET_FIELD(rtt_min, rtt_min.s[0].v, struct tcp_sock);break ;case offsetof(struct bpf_sock_ops , bpf_sock_ops_cb_flags):
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 311/877 bpf: Remove migrate_{disable|enable} in ->map_for_each_callback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hou Tao <[email protected]>
[ Upstream commit ea5b229630a631ee6a72e1f58bc40029efc1daf8 ]
BPF program may call bpf_for_each_map_elem(), and it will call the ->map_for_each_callback callback of related bpf map. Considering the running context of bpf program has already disabled migration, remove the unnecessary migrate_{disable|enable} pair in the implementations of ->map_for_each_callback. To ensure the guarantee will not be voilated later, also add cant_migrate() check in the implementations.
Stable-dep-of: 1c21452d02ee ("bpf: Fix UAF due to concurrent consumption of ttrace lists in alloc_bulk")
--- kernel/bpf/arraymap.c | 6 ++---- kernel/bpf/hashtab.c | 11 +++++------ 2 files changed, 7 insertions(+), 10 deletions(-)
kernel/bpf/arraymap.c +2 -4
@@ -735,13 +735,13 @@ static long bpf_for_each_array_elem(struct bpf_map *map, bpf_callback_t callbacku64 ret =0 ;void *val; +cant_migrate (); +if (flags !=0 )return -EINVAL ; is_percpu = map->map_type ==BPF_MAP_TYPE_PERCPU_ARRAY ; array = container_of(map, struct bpf_array, map); -if (is_percpu) -migrate_disable ();for (i =0 ; i < map->max_entries; i++) {if (is_percpu) val =this_cpu_ptr (array->pptrs[i]);
@@ -756,8 +756,6 @@ static long bpf_for_each_array_elem(struct bpf_map *map, bpf_callback_t callbackbreak ; } -if (is_percpu) -migrate_enable ();return num_elems; }
kernel/bpf/hashtab.c +5 -6
@@ -2225,17 +2225,18 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_bool is_percpu;u64 ret =0 ; +cant_migrate (); +if (flags !=0 )return -EINVAL ; is_percpu =htab_is_percpu (htab); roundup_key_size =round_up (map->key_size,8 ); -/* disable migration so percpu value prepared here will be the -* same as the one seen by the bpf program with bpf_map_lookup_elem(). +/* migration has been disabled, so percpu value prepared here will be +* the same as the one seen by the bpf program with +* bpf_map_lookup_elem(). */ -if (is_percpu) -migrate_disable ();for (i =0 ; i < htab->n_buckets; i++) { b = &htab->buckets[i];rcu_read_lock ();
@@ -2261,8 +2262,6 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_rcu_read_unlock (); } out: -if (is_percpu) -migrate_enable ();return num_elems; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 312/877 bpf: Bail out early in __htab_map_lookup_and_delete_elem()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hou Tao <[email protected]>
[ Upstream commit 588c6ead325aecc9894c9925cf1f771b77437bee ]
Use goto statement to bail out early when the target element is not found, instead of using a large else branch to handle the more likely case. This change doesn't affect functionality and simply make the code cleaner.
Stable-dep-of: 1c21452d02ee ("bpf: Fix UAF due to concurrent consumption of ttrace lists in alloc_bulk")
--- kernel/bpf/hashtab.c | 51 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-)
kernel/bpf/hashtab.c +26 -25
@@ -1637,37 +1637,38 @@ static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key, l =lookup_elem_raw (head, hash, key, key_size);if (!l) { ret = -ENOENT ; - }else { -if (is_percpu) { -u32 roundup_value_size =round_up (map->value_size,8 ); -void __percpu *pptr; -int off =0 , cpu; + goto out_unlock; + } - pptr =htab_elem_get_ptr (l, key_size); -for_each_possible_cpu (cpu) { -copy_map_value_long (&htab->map, value + off,per_cpu_ptr (pptr, cpu)); -check_and_init_map_value (&htab->map, value + off); - off += roundup_value_size; - } - }else { -u32 roundup_key_size =round_up (map->key_size,8 ); +if (is_percpu) { +u32 roundup_value_size =round_up (map->value_size,8 ); +void __percpu *pptr; +int off =0 , cpu; -if (flags &BPF_F_LOCK ) -copy_map_value_locked (map, value, l->key + - roundup_key_size, - true); -else -copy_map_value (map, value, l->key + - roundup_key_size); -/* Zeroing special fields in the temp buffer */ -check_and_init_map_value (map, value); + pptr =htab_elem_get_ptr (l, key_size); +for_each_possible_cpu (cpu) { +copy_map_value_long (&htab->map, value + off,per_cpu_ptr (pptr, cpu)); +check_and_init_map_value (&htab->map, value + off); + off += roundup_value_size; } + }else { +u32 roundup_key_size =round_up (map->key_size,8 ); -hlist_nulls_del_rcu (&l->hash_node); -if (!is_lru_map) -free_htab_elem (htab, l); +if (flags &BPF_F_LOCK ) +copy_map_value_locked (map, value, l->key + + roundup_key_size, + true); +else +copy_map_value (map, value, l->key + + roundup_key_size); +/* Zeroing special fields in the temp buffer */ +check_and_init_map_value (map, value); } +hlist_nulls_del_rcu (&l->hash_node); +if (!is_lru_map) +free_htab_elem (htab, l); +out_unlock:htab_unlock_bucket (htab, b, hash, bflags);if (is_lru_map && l)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 313/877 bpf: Factor out htab_elem_value helper()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hou Tao <[email protected]>
[ Upstream commit ba2b31b0f39fca12abbd21c53a92838bbc026023 ]
All hash maps store map key and map value together. The relative offset of the map value compared to the map key is round_up(key_size, 8). Therefore, factor out a common helper htab_elem_value() to calculate the address of the map value instead of duplicating the logic.
Stable-dep-of: 1c21452d02ee ("bpf: Fix UAF due to concurrent consumption of ttrace lists in alloc_bulk")
--- kernel/bpf/hashtab.c | 64 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 34 deletions(-)
kernel/bpf/hashtab.c +30 -34
@@ -195,20 +195,25 @@ static bool htab_is_percpu(const struct bpf_htab *htab) htab->map.map_type ==BPF_MAP_TYPE_LRU_PERCPU_HASH ; } +static inline void *htab_elem_value (struct htab_elem *l,u32 key_size) +{ +return l->key +round_up (key_size,8 ); +} +static inline void htab_elem_set_ptr (struct htab_elem *l,u32 key_size,void __percpu *pptr) { - *(void __percpu **)(l->key +roundup (key_size,8 )) = pptr; + *(void __percpu **)htab_elem_value (l, key_size) = pptr; }static inline void __percpu *htab_elem_get_ptr (struct htab_elem *l,u32 key_size) { -return *(void __percpu **)(l->key +roundup (key_size,8 )); +return *(void __percpu **)htab_elem_value (l, key_size); }static void *fd_htab_map_get_ptr (const struct bpf_map *map,struct htab_elem *l) { -return *(void **)(l->key +roundup (map->key_size,8 )); +return *(void **)htab_elem_value (l, map->key_size); }static struct htab_elem *get_htab_elem (struct bpf_htab *htab,int i)
@@ -235,10 +240,10 @@ static void htab_free_prealloced_timers_and_wq(struct bpf_htab *htab) elem =get_htab_elem (htab, i);if (btf_record_has_field (htab->map.record,BPF_TIMER ))bpf_obj_free_timer (htab->map.record, - elem->key +round_up (htab->map.key_size,8 )); +htab_elem_value (elem, htab->map.key_size));if (btf_record_has_field (htab->map.record,BPF_WORKQUEUE ))bpf_obj_free_workqueue (htab->map.record, - elem->key +round_up (htab->map.key_size,8 )); +htab_elem_value (elem, htab->map.key_size));cond_resched (); } }
@@ -265,7 +270,8 @@ static void htab_free_prealloced_fields(struct bpf_htab *htab)cond_resched (); } }else { -bpf_obj_free_fields (htab->map.record, elem->key +round_up (htab->map.key_size,8 )); +bpf_obj_free_fields (htab->map.record, +htab_elem_value (elem, htab->map.key_size));cond_resched (); }cond_resched ();
@@ -703,7 +709,7 @@ static void *htab_map_lookup_elem(struct bpf_map *map, void *key)struct htab_elem *l =__htab_map_lookup_elem (map, key);if (l) -return l->key +round_up (map->key_size,8 ); +return htab_elem_value (l, map->key_size);return NULL ; }
@@ -742,7 +748,7 @@ static __always_inline void *__htab_lru_map_lookup_elem(struct bpf_map *map,if (l) {if (mark)bpf_lru_node_set_ref (&l->lru_node); -return l->key +round_up (map->key_size,8 ); +return htab_elem_value (l, map->key_size); }return NULL ;
@@ -793,7 +799,7 @@ static void check_and_free_fields(struct bpf_htab *htab,for_each_possible_cpu (cpu)bpf_obj_free_fields (htab->map.record,per_cpu_ptr (pptr, cpu)); }else { -void *map_value = elem->key +round_up (htab->map.key_size,8 ); +void *map_value =htab_elem_value (elem, htab->map.key_size);bpf_obj_free_fields (htab->map.record, map_value); }
@@ -1076,11 +1082,9 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key,htab_elem_set_ptr (l_new, key_size, pptr); }else if (fd_htab_map_needs_adjust (htab)) { size =round_up (size,8 ); -memcpy (l_new->key +round_up (key_size,8 ), value, size); +memcpy (htab_elem_value (l_new, key_size), value, size); }else { -copy_map_value (&htab->map, - l_new->key +round_up (key_size,8 ), - value); +copy_map_value (&htab->map,htab_elem_value (l_new, key_size), value); } l_new->hash = hash;
@@ -1142,7 +1146,7 @@ static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,if (l_old) {/* grab the element lock and update value in place */ copy_map_value_locked (map, - l_old->key +round_up (key_size,8 ), +htab_elem_value (l_old, key_size), value, false);return 0 ; }
@@ -1170,7 +1174,7 @@ static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,* and update element in place */ copy_map_value_locked (map, - l_old->key +round_up (key_size,8 ), +htab_elem_value (l_old, key_size), value, false); ret =0 ; goto err;
@@ -1255,8 +1259,7 @@ static long htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value l_new =prealloc_lru_pop (htab, key, hash);if (!l_new)return -ENOMEM ; -copy_map_value (&htab->map, - l_new->key +round_up (map->key_size,8 ), value); +copy_map_value (&htab->map,htab_elem_value (l_new, map->key_size), value); ret =htab_lock_bucket (htab, b, hash, &flags);if (ret)
@@ -1533,10 +1536,10 @@ static void htab_free_malloced_timers_and_wq(struct bpf_htab *htab)/* We only free timer on uref dropping to zero */ if (btf_record_has_field (htab->map.record,BPF_TIMER ))bpf_obj_free_timer (htab->map.record, - l->key +round_up (htab->map.key_size,8 )); +htab_elem_value (l, htab->map.key_size));if (btf_record_has_field (htab->map.record,BPF_WORKQUEUE ))bpf_obj_free_workqueue (htab->map.record, - l->key +round_up (htab->map.key_size,8 )); +htab_elem_value (l, htab->map.key_size)); }cond_resched_rcu (); }
@@ -1652,15 +1655,12 @@ static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key, off += roundup_value_size; } }else { -u32 roundup_key_size =round_up (map->key_size,8 ); +void *src =htab_elem_value (l, map->key_size);if (flags &BPF_F_LOCK ) -copy_map_value_locked (map, value, l->key + - roundup_key_size, - true); +copy_map_value_locked (map, value, src, true);else -copy_map_value (map, value, l->key + - roundup_key_size); +copy_map_value (map, value, src);/* Zeroing special fields in the temp buffer */ check_and_init_map_value (map, value); }
@@ -1721,12 +1721,12 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, bool is_percpu) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map); -u32 bucket_cnt, total, key_size, value_size, roundup_key_size;void *keys =NULL , *values =NULL , *value, *dst_key, *dst_val;void __user *uvalues =u64_to_user_ptr (attr->batch.values);void __user *ukeys =u64_to_user_ptr (attr->batch.keys);void __user *ubatch =u64_to_user_ptr (attr->batch.in_batch);u32 batch, max_count, size, bucket_size, map_id; +u32 bucket_cnt, total, key_size, value_size;struct htab_elem *node_to_free =NULL ;u64 elem_map_flags, map_flags;struct hlist_nulls_head *head;
@@ -1762,7 +1762,6 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map,return -ENOENT ; key_size = htab->map.key_size; - roundup_key_size =round_up (htab->map.key_size,8 ); value_size = htab->map.value_size; size =round_up (value_size,8 );if (is_percpu)
@@ -1854,7 +1853,7 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, off += size; } }else { - value = l->key + roundup_key_size; + value =htab_elem_value (l, key_size);if (map->map_type ==BPF_MAP_TYPE_HASH_OF_MAPS ) {struct bpf_map **inner_map = value;
@@ -2116,11 +2115,11 @@ static void *bpf_hash_map_seq_next(struct seq_file *seq, void *v, loff_t *pos)static int __bpf_hash_map_seq_show (struct seq_file *seq,struct htab_elem *elem) {struct bpf_iter_seq_hash_map_info *info = seq->private; -u32 roundup_key_size, roundup_value_size;struct bpf_iter__bpf_map_elem ctx = {};struct bpf_map *map = info->map;struct bpf_iter_meta meta;int ret =0 , off =0 , cpu; +u32 roundup_value_size;struct bpf_prog *prog;void __percpu *pptr;
@@ -2130,10 +2129,9 @@ static int __bpf_hash_map_seq_show(struct seq_file *seq, struct htab_elem *elem) ctx.meta = &meta; ctx.map = info->map;if (elem) { - roundup_key_size =round_up (map->key_size,8 ); ctx.key = elem->key;if (!info->percpu_value_buf) { - ctx.value = elem->key + roundup_key_size; + ctx.value =htab_elem_value (elem, map->key_size); }else { roundup_value_size =round_up (map->value_size,8 ); pptr =htab_elem_get_ptr (elem, map->key_size);
@@ -2218,7 +2216,6 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_struct hlist_nulls_head *head;struct hlist_nulls_node *n;struct htab_elem *elem; -u32 roundup_key_size;int i, num_elems =0 ;void __percpu *pptr;struct bucket *b;
@@ -2233,7 +2230,6 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_ is_percpu =htab_is_percpu (htab); - roundup_key_size =round_up (map->key_size,8 );/* migration has been disabled, so percpu value prepared here will be * the same as the one seen by the bpf program with * bpf_map_lookup_elem().
@@ -2249,7 +2245,7 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_ pptr =htab_elem_get_ptr (elem, map->key_size); val =this_cpu_ptr (pptr); }else { - val = elem->key + roundup_key_size; + val =htab_elem_value (elem, map->key_size); } num_elems++; ret = callback_fn((u64)(long)map, (u64)(long)key,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 314/877 bpf: Register dtor for freeing special fields
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit 1df97a7453eec80c1912c2d0360290a3970a7671 ]
There is a race window where BPF hash map elements can leak special fields if the program with access to the map value recreates these special fields between the check_and_free_fields done on the map value and its eventual return to the memory allocator.
Several ways were explored prior to this patch, most notably [0] tried to use a poison value to reject attempts to recreate special fields for map values that have been logically deleted but still accessible to BPF programs (either while sitting in the free list or when reused). While this approach works well for task work, timers, wq, etc., it is harder to apply the idea to kptrs, which have a similar race and failure mode.
Instead, we change bpf_mem_alloc to allow registering destructor for allocated elements, such that when they are returned to the allocator, any special fields created while they were accessible to programs in the mean time will be freed. If these values get reused, we do not free the fields again before handing the element back. The special fields thus may remain initialized while the map value sits in a free list.
When bpf_mem_alloc is retired in the future, a similar concept can be introduced to kmalloc_nolock-backed kmem_cache, paired with the existing idea of a constructor.
Note that the destructor registration happens in map_check_btf, after the BTF record is populated and (at that point) avaiable for inspection and duplication. Duplication is necessary since the freeing of embedded bpf_mem_alloc can be decoupled from actual map lifetime due to logic introduced to reduce the cost of rcu_barrier()s in mem alloc free path in 9f2c6e96c65e ("bpf: Optimize rcu_barrier usage between hash map and bpf_mem_alloc.").
As such, once all callbacks are done, we must also free the duplicated record. To remove dependency on the bpf_map itself, also stash the key size of the map to obtain value from htab_elem long after the map is gone.
[0]: https://lore.kernel.org/bpf/[email protected]
Stable-dep-of: 1c21452d02ee ("bpf: Fix UAF due to concurrent consumption of ttrace lists in alloc_bulk")
--- include/linux/bpf_mem_alloc.h | 6 +++ kernel/bpf/hashtab.c | 87 +++++++++++++++++++++++++++++++++++ kernel/bpf/memalloc.c | 58 ++++++++++++++++++----- 3 files changed, 140 insertions(+), 11 deletions(-)
include/linux/bpf_mem_alloc.h +6 -0
@@ -14,6 +14,8 @@ struct bpf_mem_alloc {struct obj_cgroup *objcg;bool percpu;struct work_struct work; +void (*dtor_ctx_free)(void *ctx); +void *dtor_ctx; };/* 'size != 0' is for bpf_mem_alloc which manages fixed-size objects.
@@ -32,6 +34,10 @@ int bpf_mem_alloc_percpu_init(struct bpf_mem_alloc *ma, struct obj_cgroup *objcg/* The percpu allocation with a specific unit size. */ int bpf_mem_alloc_percpu_unit_init (struct bpf_mem_alloc *ma,int size);void bpf_mem_alloc_destroy (struct bpf_mem_alloc *ma); +void bpf_mem_alloc_set_dtor (struct bpf_mem_alloc *ma, +void (*dtor)(void *obj,void *ctx), +void (*dtor_ctx_free)(void *ctx), +void *ctx);/* Check the allocation size for kmalloc equivalent allocator */ int bpf_mem_alloc_check_size (bool percpu,size_t size);
kernel/bpf/hashtab.c +87 -0
123 lines not on this page · raw message
kernel/bpf/memalloc.c +47 -11
108 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 315/877 bpf: Fix UAF due to concurrent consumption of ttrace lists in alloc_bulk
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pu Lehui <[email protected]>
[ Upstream commit 1c21452d02eec2f008e2c5535820f85adbd7587a ]
Syzkaller repeatedly triggered UAF splats related to nodes in waiting_for_gp_ttrace within the bpf memalloc:
BUG: KASAN: slab-use-after-free in llist_del_first+0x85/0x110 lib/llist.c:61 Read of size 8 at addr ffff8881572cd080 by task syz.4.470/5112 ... llist_del_first+0x85/0x110 lib/llist.c:61 alloc_bulk+0x193/0x460 kernel/bpf/memalloc.c:229 bpf_mem_refill+0x386/0x560 kernel/bpf/memalloc.c:436 Freed by task 14: ... __free_rcu kernel/bpf/memalloc.c:281 [inline] __free_rcu_tasks_trace+0x48/0xd0 kernel/bpf/memalloc.c:291 rcu_tasks_invoke_cbs+0x1ec/0x3e0 kernel/rcu/tasks.h:571 rcu_tasks_one_gp+0x13d/0x220 kernel/rcu/tasks.h:621 rcu_tasks_kthread+0xf3/0x120 kernel/rcu/tasks.h:651
The reason is that the UAF occurs after the RCU Tasks Trace GP expires:
when the __free_rcu() callback runs, there is no synchronization protecting llist_del_all() against concurrent alloc_bulk() operating on waiting_for_gp_ttrace, leading to the race condition below:
CPU0 CPU1
__free_rcu (RCU Tasks Trace callback)alloc_bulk
llist_del_first(&c->waiting_for_gp_ttrace)
entry = smp_load_acquire(&head->first);
do {
if (entry == NULL)
return NULL;
free_all(llist_del_all(&c->waiting_for_gp_ttrace))
llist_for_each_safe(pos, t, llnode)
free_one(pos);
next = READ_ONCE(entry->next); <-- trigger UAF
} while (!try_cmpxchg(&head->first, &entry, next));In addition, there is also a theoretical race condition on the free_by_rcu_ttrace list. This race requires two preconditions: an in-flight Tasks Trace GP keeping c->call_rcu_ttrace_in_progress == 1, and concurrent cross-CPU frees repopulating c->free_by_rcu_ttrace with new nodes. Under these conditions, the following scenario triggers UAF:
// CPU0
// irq work is still busy (on PREEMPT_RT)alloc_bulk()
llist_del_first(&c->free_by_rcu_ttrace)
entry = smp_load_acquire(&head->first);
do {
if (entry == NULL)
return NULL;
// CPU1
bpf_mem_alloc_destroy()
WRITE_ONCE(c->draining, true)
// wait for CPU0
irq_work_sync()
// CPU2
do_call_rcu_ttrace(tgt(CPU0))
if (c->draining) {
llist_del_all(&c->free_by_rcu_ttrace)
free_all()
}// CPU0 continue
next = READ_ONCE(entry->next); <-- trigger UAF
while (!try_cmpxchg(&head->first, &entry, next));Fix this by introducing a raw spinlock to synchronize the concurrent consumption on waiting_for_gp_ttrace and free_by_rcu_ttrace.
--- kernel/bpf/memalloc.c | 50 ++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-)
kernel/bpf/memalloc.c +28 -22
@@ -119,6 +119,7 @@ struct bpf_mem_cache {struct llist_head waiting_for_gp_ttrace;struct rcu_head rcu_ttrace;atomic_t call_rcu_ttrace_in_progress; +raw_spinlock_t lock; };struct bpf_mem_caches {
@@ -214,25 +215,24 @@ static void alloc_bulk(struct bpf_mem_cache *c, int cnt, int node, bool atomic) gfp = __GFP_NOWARN | __GFP_ACCOUNT; gfp |= atomic ?GFP_NOWAIT :GFP_KERNEL ; -for (i =0 ; i < cnt; i++) { -/* -* For every 'c' llist_del_first(&c->free_by_rcu_ttrace); is -* done only by one CPU == current CPU. Other CPUs might -* llist_add() and llist_del_all() in parallel. -*/ - obj =llist_del_first (&c->free_by_rcu_ttrace); -if (!obj) -break ; -add_obj_to_free_list (c, obj); - } -if (i >= cnt) -return ; +/* +* c->lock serializes concurrent llist_del_first() against +* llist_del_all() in __free_rcu() and do_call_rcu_ttrace(). +*/ + scoped_guard(raw_spinlock_irqsave, &c->lock) { +for (i =0 ; i < cnt; i++) { + obj =llist_del_first (&c->free_by_rcu_ttrace); +if (!obj) +break ; +add_obj_to_free_list (c, obj); + } -for (; i < cnt; i++) { - obj =llist_del_first (&c->waiting_for_gp_ttrace); -if (!obj) -break ; -add_obj_to_free_list (c, obj); +for (; i < cnt; i++) { + obj =llist_del_first (&c->waiting_for_gp_ttrace); +if (!obj) +break ; +add_obj_to_free_list (c, obj); + } }if (i >= cnt)return ;
@@ -282,8 +282,12 @@ static int free_all(struct bpf_mem_cache *c, struct llist_node *llnode, bool perstatic void __free_rcu (struct rcu_head *head) { struct bpf_mem_cache *c = container_of(head, struct bpf_mem_cache, rcu_ttrace); +struct llist_node *llnode; + +scoped_guard (raw_spinlock_irqsave, &c->lock) + llnode = llist_del_all(&c->waiting_for_gp_ttrace); -free_all (c,llist_del_all (&c->waiting_for_gp_ttrace), !!c->percpu_size); +free_all (c, llnode, !!c->percpu_size);atomic_set (&c->call_rcu_ttrace_in_progress,0 ); }
@@ -314,7 +318,8 @@ static void do_call_rcu_ttrace(struct bpf_mem_cache *c)if (atomic_xchg (&c->call_rcu_ttrace_in_progress,1 )) {if (unlikely (READ_ONCE (c->draining))) { - llnode =llist_del_all (&c->free_by_rcu_ttrace); +scoped_guard (raw_spinlock_irqsave, &c->lock) + llnode = llist_del_all(&c->free_by_rcu_ttrace);free_all (c, llnode, !!c->percpu_size); }return ;
@@ -549,6 +554,7 @@ int bpf_mem_alloc_init(struct bpf_mem_alloc *ma, int size, bool percpu) c->objcg = objcg; c->percpu_size = percpu_size; c->tgt = c; +raw_spin_lock_init (&c->lock);init_refill_work (c);prefill_mem_cache (c, cpu); }
@@ -571,7 +577,7 @@ int bpf_mem_alloc_init(struct bpf_mem_alloc *ma, int size, bool percpu) c->objcg = objcg; c->percpu_size = percpu_size; c->tgt = c; - +raw_spin_lock_init (&c->lock);init_refill_work (c);prefill_mem_cache (c, cpu); }
@@ -623,7 +629,7 @@ int bpf_mem_alloc_percpu_unit_init(struct bpf_mem_alloc *ma, int size) c->objcg = objcg; c->percpu_size = percpu_size; c->tgt = c; - +raw_spin_lock_init (&c->lock);init_refill_work (c);prefill_mem_cache (c, cpu); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 316/877 bpf, sockmap: Fix self-redirect copied_seq double-counting
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geliang Tang <[email protected]>
[ Upstream commit 490a83d6386eec1d29f470c8d7331677fb46c3b7 ]
When a BPF stream_verdict program redirects an skb back to the same socket (self-redirect with BPF_F_INGRESS), sk_psock_verdict_apply() calls tcp_eat_skb() which advances tcp_sk->copied_seq. However, the skb is then delivered to the socket's psock ingress queue and later read by tcp_bpf_recvmsg_parser(), which also advances copied_seq via the copied_from_self accounting path. This double-counting causes copied_seq to advance by 2x the actual data length, triggering:
TCP recvmsg seq # bug 2: copied BF2E806, seq BF2E7FD, \ rcvnxt BF2E806, fl 0 WARNING: net/ipv4/tcp.c:2745 at tcp_recvmsg_locked+0x72b/0x2640 Call Trace: tcp_recvmsg+0x10a/0x500 sock_recvmsg+0x168/0x1d0 __sys_recvfrom+0x19a/0x2a0 __x64_sys_recvfrom+0xe4/0x1f0 do_syscall_64+0xf7/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f
cleanup rbuf bug: copied BF2E806 seq BF2E806 rcvnxt BF2E806
WARNING: net/ipv4/tcp.c:1609 at tcp_cleanup_rbuf+0xf2/0x1c0 Call Trace: tcp_recvmsg_locked+0x8d1/0x2640 tcp_recvmsg+0x10a/0x500 sock_recvmsg+0x168/0x1d0 __sys_recvfrom+0x19a/0x2a0 __x64_sys_recvfrom+0xe4/0x1f0 do_syscall_64+0xf7/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fix this by converting self-redirect verdict to __SK_PASS at the beginning of sk_psock_verdict_apply(). This bypasses the __SK_REDIRECT case entirely (which calls sk_psock_eat_skb), letting the __SK_PASS path queue the skb to the psock ingress queue. The data is then read via tcp_bpf_recvmsg_parser(), which advances copied_seq exactly once through copied_from_self. Cross-socket redirects continue through __SK_REDIRECT with sk_psock_eat_skb() unchanged.
--- net/core/skmsg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/skmsg.c +4 -0
@@ -1035,6 +1035,10 @@ static int sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb,int err =0 ;u32 len, off; +if (verdict == __SK_REDIRECT &&skb_bpf_ingress (skb) && +skb_bpf_redirect_fetch (skb) == psock->sk) + verdict = __SK_PASS; +switch (verdict) {case __SK_PASS: err = -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 317/877 bpf, arm64: set up the frame pointer for the exception callback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit ef1fb82f12186dd26153b14d9fbcf4ec98db81b3 ]
A program acting as exception boundary saves all callee-saved registers, so build_prologue() takes the exception_cb path and never calls push_callee_regs(). That is the only place find_used_callee_regs() runs, and with it the only place ctx->fp_used is set, so the callback prologue does not emit the
mov x25, sp
that points BPF_REG_FP at the frame the callback runs on. x25 keeps whatever it held when bpf_throw() was called. If the throw came from a subprogram that uses its own BPF stack, that is the subprogram's frame pointer, and since the subprogram never returns it never restores x25 either.
Stack accesses through BPF_REG_FP are rewritten to be stack pointer relative, so those still land in the callback's own frame. Materializing the register does not: a callback that passes the address of a local variable to a helper hands over an address in the dead subprogram's frame. That address is below the callback's stack pointer by then, and the helper's own call chain covers it, so the helper can write over its own return address. 0x1234 below is the value the helper was asked to store:
pc : 0x1234 lr : 0x1234 Call trace: 0x1234 (P) bpf_test_run+0x188/0x3e0 bpf_prog_test_run_skb+0x47c/0x998 __sys_bpf+0xbdc/0xdd8 Kernel panic - not syncing: Oops: Fatal exception in interrupt
Set ctx->fp_used on the exception callback path so that the existing code further down sets x25 from the stack pointer. The epilogue restores it from the main program's save area along with the other callee-saved registers, as it already does. x86 sets the frame pointer for the callback from the argument it is passed, and powerpc computes it from the stack pointer.
--- arch/arm64/net/bpf_jit_comp.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/net/bpf_jit_comp.c +2 -0
@@ -537,6 +537,8 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)* 12 registers are on the stack */ emit (A64_SUB_I (1 ,A64_SP ,A64_FP ,96 ), ctx); +/* The callback may use its own BPF stack, set up fp for it. */ + ctx->fp_used = true; }if (ctx->fp_used)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 318/877 pinctrl: meson: Fix typo in s4 group name
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Anderson <[email protected]>
[ Upstream commit 692f32609a30f75ca3401e25b504bfd06bd5662a ]
One of the i2c pin groups has some junk at the end. The name should be i2c2_scl_h1, and indeed that's the name used by i2c2_pins3 in meson-s4.dtsi.
--- drivers/pinctrl/meson/pinctrl-meson-s4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/meson/pinctrl-meson-s4.c +1 -1
@@ -854,7 +854,7 @@ static const char * const i2c1_groups[] = {static const char *const i2c2_groups[] = {"i2c2_sda_d" ,"i2c2_scl_d" ,"i2c2_sda_h8" ,"i2c2_scl_h9" , -"i2c2_sda_h0" ,"i2c2_scl_h1l," +"i2c2_sda_h0" ,"i2c2_scl_h1" , };static const char *const i2c3_groups[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 319/877 HID: amd_sfh: Validate PCI BAR size before mapping
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Slawomir Stepien <[email protected]>
[ Upstream commit 65bcc5f89704efe5b9d69d4ea2c1002d90c31382 ]
The amd_sfh driver maps PCI BAR 2 using pcim_iomap_regions() and subsequently accesses MMIO registers at offsets up to 0x10958 (e.g., AMD_P2C_MSG3 at 0x1068C). However, the driver never validates that the BAR size is large enough to cover these accesses. If the driver is bound to a device with a smaller BAR 2, this leads to an out-of-bounds memory access and a page fault during the probe function.
For example, a page fault can occur when reading from privdata->mmio + AMD_P2C_MSG3 in mp2_select_ops():
BUG: unable to handle page fault for address: ffffc9000390368c PGD 100000067 P4D 100000067 PUD 1012c1067 PMD 105b64067 PTE 0 Oops: Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:readl arch/x86/include/asm/io.h:59 [inline] RIP: 0010:mp2_select_ops drivers/hid/amd-sfh-hid/amd_sfh_pcie.c:282 [inline] RIP: 0010:amd_mp2_pci_probe+0x337/0x5f0 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c:487 Call Trace: <TASK> local_pci_probe drivers/pci/pci-driver.c:332 [inline] pci_call_probe drivers/pci/pci-driver.c:394 [inline] __pci_device_probe drivers/pci/pci-driver.c:455 [inline] pci_device_probe+0x431/0xc90 drivers/pci/pci-driver.c:489
Fix this by verifying that the length of BAR 2 is at least 128KB before attempting to map it. Since the maximum accessed offset is 0x10958, and PCI BAR sizes are powers of 2, any legitimate hardware will have a BAR size of at least 128KB.
--- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 4 ++++ drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
drivers/hid/amd-sfh-hid/amd_sfh_common.h +4 -0
@@ -12,11 +12,15 @@#include <linux/mutex.h> #include <linux/pci.h> +#include <linux/sizes.h> #include "amd_sfh_hid.h" #define PCI_DEVICE_ID_AMD_MP2 0x15E4#define PCI_DEVICE_ID_AMD_MP2_1_1 0x164A +/* The BAR 2 size must cover the highest register offset (0x10958) */ +#define AMD_SFH_MIN_BAR_SIZE SZ_128K +#define AMD_C2P_MSG (regno) (0x10500 + ((regno) * 4))#define AMD_P2C_MSG (regno) (0x10680 + ((regno) * 4))
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +10 -0
@@ -390,6 +390,16 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *iif (rc)return rc; +if (!(pci_resource_flags (pdev,2 ) &IORESOURCE_MEM )) { +dev_err (&pdev->dev,"BAR 2 is not IORESOURCE_MEM\n" ); +return -ENODEV ; + } + +if (pci_resource_len (pdev,2 ) <AMD_SFH_MIN_BAR_SIZE ) { +dev_err (&pdev->dev,"BAR 2 is too small\n" ); +return -EINVAL ; + } + rc =pcim_iomap_regions (pdev,BIT (2 ),DRIVER_NAME );if (rc)return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 320/877 HID: bpf: fix __hid_bpf_hw_check_params report length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Tissoires <[email protected]>
[ Upstream commit c4afa4862b878d56e0cc1021298794ac1b45bc49 ]
Turns out that USB, I2C and other transport drivers (except uhid which just passes the data) still need to have the report ID in the first byte.
Because they expect the first byte to be the report ID or 0, when the report ID is 0, they strip that first byte before forwarding to the device. This means that the transport layer forwards a buffer of size N-1 to the device, which gets rejected.
--- drivers/hid/bpf/hid_bpf_dispatch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hid/bpf/hid_bpf_dispatch.c +8 -4
@@ -359,7 +359,7 @@ hid_bpf_release_context(struct hid_bpf_ctx *ctx)static int __hid_bpf_hw_check_params (struct hid_bpf_ctx *ctx,__u8 *buf,size_t *buf__sz, -enum hid_report_type rtype) +enum hid_report_type rtype,bool hw_request) {struct hid_report_enum *report_enum;struct hid_report *report;
@@ -391,6 +391,10 @@ __hid_bpf_hw_check_params(struct hid_bpf_ctx *ctx, __u8 *buf, size_t *buf__sz, report_len =hid_report_len (report); +/* unnumbered reports need to have a report ID reserved in the first byte */ +if (hw_request && report_enum->numbered ==0 ) + report_len +=1 ; +if (*buf__sz > report_len) *buf__sz = report_len;
@@ -424,7 +428,7 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,return -EDEADLOCK ;/* check arguments */ - ret =__hid_bpf_hw_check_params (ctx, buf, &size, rtype); + ret =__hid_bpf_hw_check_params (ctx, buf, &size, rtype, true);if (ret)return ret;
@@ -487,7 +491,7 @@ hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz)return -EDEADLOCK ;/* check arguments */ - ret =__hid_bpf_hw_check_params (ctx, buf, &size,HID_OUTPUT_REPORT ); + ret =__hid_bpf_hw_check_params (ctx, buf, &size,HID_OUTPUT_REPORT , true);if (ret)return ret;
@@ -515,7 +519,7 @@ __hid_bpf_input_report(struct hid_bpf_ctx *ctx, enum hid_report_type type, u8 *breturn -EDEADLOCK ;/* check arguments */ - ret =__hid_bpf_hw_check_params (ctx, buf, &size, type); + ret =__hid_bpf_hw_check_params (ctx, buf, &size, type, false);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 321/877 RISC-V: KVM: Preserve firmware counter value across stop/start
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeungJu Cheon <[email protected]>
[ Upstream commit 8b3fd1a8b305321171602bfa7c41212441cf69e4 ]
Firmware events accumulate in kvpmu->fw_event[].value while running, but counter stop only clears fw_event[].started without saving the value back to pmc->counter_val. A subsequent counter start without SBI_PMU_START_FLAG_SET_INIT_VALUE reloads the stale counter_val into fw_event[].value, losing all events counted so far.
Save fw_event[].value into counter_val when actually stopping a running counter, and remove the now redundant synchronization from the snapshot path.
--- arch/riscv/kvm/vcpu_pmu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/riscv/kvm/vcpu_pmu.c +6 -6
@@ -590,10 +590,12 @@ int kvm_riscv_vcpu_pmu_ctr_stop(struct kvm_vcpu *vcpu, unsigned long ctr_base, goto out; } -if (!kvpmu->fw_event[fevent_code].started) +if (!kvpmu->fw_event[fevent_code].started) { sbiret =SBI_ERR_ALREADY_STOPPED ; - - kvpmu->fw_event[fevent_code].started = false; + }else { + kvpmu->fw_event[fevent_code].started = false; + pmc->counter_val = kvpmu->fw_event[fevent_code].value; + } }else if (pmc->perf_event) {if (pmc->started) {/* Stop counting the counter */
@@ -611,9 +613,7 @@ int kvm_riscv_vcpu_pmu_ctr_stop(struct kvm_vcpu *vcpu, unsigned long ctr_base, }if (snap_flag_set && !sbiret) { -if (pmc->cinfo.type ==SBI_PMU_CTR_TYPE_FW ) - pmc->counter_val = kvpmu->fw_event[fevent_code].value; -else if (pmc->perf_event) +if (pmc->perf_event) pmc->counter_val +=perf_event_read_value (pmc->perf_event, &enabled, &running);/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 322/877 RISC-V: KVM: Report snapshot write failure to the guest
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeungJu Cheon <[email protected]>
[ Upstream commit 057dd2639ceae79adced5d8fe52c32d562edcb3a ]
If kvm_vcpu_write_guest() fails while updating the PMU snapshot area on counter stop, the guest may receive SBI_SUCCESS without the snapshot being updated, leaving stale data in shared memory.
Return SBI_ERR_FAILURE when the snapshot write fails.
--- arch/riscv/kvm/vcpu_pmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/riscv/kvm/vcpu_pmu.c +4 -3
@@ -642,9 +642,10 @@ int kvm_riscv_vcpu_pmu_ctr_stop(struct kvm_vcpu *vcpu, unsigned long ctr_base, } } -if (shmem_needs_update) -kvm_vcpu_write_guest (vcpu, kvpmu->snapshot_addr, kvpmu->sdata, -sizeof (struct riscv_pmu_snapshot_data )); +if (shmem_needs_update && +kvm_vcpu_write_guest (vcpu, kvpmu->snapshot_addr, kvpmu->sdata, +sizeof (struct riscv_pmu_snapshot_data ))) + sbiret =SBI_ERR_FAILURE ; out: retdata->err_val = sbiret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 323/877 RISC-V: KVM: Fix perf-backed counter accounting across stop and read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeungJu Cheon <[email protected]>
[ Upstream commit c7e2cc38c56142cdab25e6f73602a8222bf9479b ]
pmu_ctr_read() adds the event count returned by perf_event_read_value() to counter_val, which can accumulate the same count repeatedly across reads. kvm_riscv_vcpu_pmu_ctr_stop() also leaves counter_val stale by not folding the current event count into it.
Make reads of perf-backed counters side-effect free, and use perf_event_pause() when stopping a counter to fold the current event count into counter_val while resetting it. This preserves the counter value across stop/start and lets the snapshot path use counter_val directly.
--- arch/riscv/kvm/vcpu_pmu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/riscv/kvm/vcpu_pmu.c +8 -8
@@ -245,12 +245,13 @@ static int pmu_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx,if (pmc->cinfo.type ==SBI_PMU_CTR_TYPE_FW ) { fevent_code =get_event_code (pmc->event_idx); pmc->counter_val = kvpmu->fw_event[fevent_code].value; + *out_val = pmc->counter_val; }else if (pmc->perf_event) { - pmc->counter_val +=perf_event_read_value (pmc->perf_event, &enabled, &running); + *out_val = pmc->counter_val + +perf_event_read_value (pmc->perf_event, &enabled, &running); }else {return -EINVAL ; } - *out_val = pmc->counter_val;return 0 ; }
@@ -561,7 +562,6 @@ int kvm_riscv_vcpu_pmu_ctr_stop(struct kvm_vcpu *vcpu, unsigned long ctr_base, {struct kvm_pmu *kvpmu =vcpu_to_pmu (vcpu);int i, pmc_index, sbiret =0 ; -u64 enabled, running;struct kvm_pmc *pmc;int fevent_code;bool snap_flag_set = flags &SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT ;
@@ -598,8 +598,11 @@ int kvm_riscv_vcpu_pmu_ctr_stop(struct kvm_vcpu *vcpu, unsigned long ctr_base, } }else if (pmc->perf_event) {if (pmc->started) { -/* Stop counting the counter */ -perf_event_disable (pmc->perf_event); +/* +* Stop the counter and fold the live count into counter_val. +* Reset the event value to avoid redundant accumulation. +*/ + pmc->counter_val +=perf_event_pause (pmc->perf_event, true); pmc->started = false; }else { sbiret =SBI_ERR_ALREADY_STOPPED ;
@@ -613,9 +616,6 @@ int kvm_riscv_vcpu_pmu_ctr_stop(struct kvm_vcpu *vcpu, unsigned long ctr_base, }if (snap_flag_set && !sbiret) { -if (pmc->perf_event) - pmc->counter_val +=perf_event_read_value (pmc->perf_event, - &enabled, &running);/* * The counter and overflow indicies in the snapshot region are w.r.to * cbase. Modify the set bit in the counter mask instead of the pmc_index
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 324/877 KVM: arm64: vgic-its: Free the caches when GITS_BASER changes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 8cd92f77ae4f5371a7d581f8324c24919670b304 ]
A guest that disables the ITS and re-points or shrinks GITS_BASER<n> with VALID still set keeps the devices and collections it mapped against the old table, as KVM frees them only when VALID is cleared. The contents of the table are IMPLEMENTATION DEFINED, so a write that gives GITS_BASER<n> a different address or size may lose whatever the old value described. Free the list whenever the stored value changes, and drop the translation cache with it.
The cache is not empty just because the ITS is disabled: its->enabled is written under the cmd_lock, while vgic_its_resolve_lpi() tests it under the its_lock, so an injection can still cache an entry after the ITS was disabled. Hence the invalidation inside the its_lock section.
Test for a change rather than a write: its_restore_enable() rewrites GITS_BASER<n> from its probe-time cache on resume, and KVM reports GITS_TYPER.HCC as 0, so nothing re-maps the boot CPU's collection afterwards.
--- arch/arm64/kvm/vgic/vgic-its.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +8 -3
@@ -1637,7 +1637,7 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm, unsigned long val) {const struct vgic_its_abi *abi =vgic_its_get_abi (its); -u64 entry_size, table_type; +u64 old, entry_size, table_type;u64 reg, *regptr, clearbits =0 ;/* When GITS_CTLR.Enable is 1, we ignore write accesses. */
@@ -1660,7 +1660,9 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,return ; } - reg =update_64bit_reg (*regptr, addr &7 , len, val); + old = *regptr; + + reg =update_64bit_reg (old, addr &7 , len, val); reg &= ~GITS_BASER_RO_MASK ; reg &= ~clearbits;
@@ -1670,7 +1672,8 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm, *regptr = reg; -if (!(reg &GITS_BASER_VALID )) { +/* The ITS driver rewrites an unchanged GITS_BASER<n> on resume. */ +if (reg != old) {/* Take the its_lock to prevent a race with a save/restore */ mutex_lock (&its->its_lock);switch (table_type) {
@@ -1681,6 +1684,8 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,vgic_its_free_collection_list (kvm, its);break ; } +/* A concurrent injection may have cached a translation. */ +vgic_its_invalidate_cache (its);mutex_unlock (&its->its_lock); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 325/877 KVM: arm64: vgic-its: Add stronger type-checking to the ITS entry sizes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 3b2c81d5feb250dfdcb0ef5825319f36c29f8336 ]
The ITS ABI infrastructure allows for some pretty lax code, where the size of the data doesn't have to match the size of the entry, potentially leading to a collection of interesting bugs.
Commit 7fe28d7e68f9 ("KVM: arm64: vgic-its: Add a data length check in vgic_its_save_*") added some checks, but starts by implicitly casting all writes to a 64bit value, hiding some of the issues.
Instead, introduce macros that will check the data type actually used for dealing with the table entries. The macros are taking a symbolic entry type that is used to fetch the size of the entry type for the current ABI. This immediately catches a couple of low-impact gotchas (zero values that are implicitly 32bit), easy enough to fix.
Given that we currently only have a single ABI, hardcode a couple of BUILD_BUG_ON()s that will fire if we use anything but a 64bit quantity, and some (currently unreachable) fallback code that may become useful one day.
Stable-dep-of: cc5d96036e01 ("KVM: arm64: vgic-its: Skip unreachable devices instead of failing the save")
--- arch/arm64/kvm/vgic/vgic-its.c | 69 ++++++++++++++++++++++++---------- arch/arm64/kvm/vgic/vgic.h | 23 ------------ 2 files changed, 50 insertions(+), 42 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +50 -19
@@ -31,6 +31,41 @@ static int vgic_its_commit_v0(struct vgic_its *its);static int update_lpi_config (struct kvm *kvm,struct vgic_irq *irq,struct kvm_vcpu *filter_vcpu,bool needs_inv); +#define vgic_its_read_entry_lock (i, g, valp, t) \ + ({ \ + int __sz = vgic_its_get_abi(i)->t##_esz; \ + struct kvm *__k = (i)->dev->kvm; \ + int __ret; \ + \ + BUILD_BUG_ON(NR_ITS_ABIS == 1 && \ + sizeof(*(valp)) != ABI_0_ESZ); \ + if (NR_ITS_ABIS > 1 && \ + KVM_BUG_ON(__sz != sizeof(*(valp)), __k)) \ + __ret = -EINVAL; \ + else \ + __ret = kvm_read_guest_lock(__k, (g), \ + valp, __sz); \ + __ret; \ + }) + +#define vgic_its_write_entry_lock (i, g, val, t) \ + ({ \ + int __sz = vgic_its_get_abi(i)->t##_esz; \ + struct kvm *__k = (i)->dev->kvm; \ + typeof(val) __v = (val); \ + int __ret; \ + \ + BUILD_BUG_ON(NR_ITS_ABIS == 1 && \ + sizeof(__v) != ABI_0_ESZ); \ + if (NR_ITS_ABIS > 1 && \ + KVM_BUG_ON(__sz != sizeof(__v), __k)) \ + __ret = -EINVAL; \ + else \ + __ret = vgic_write_guest_lock(__k, (g), \ + &__v, __sz); \ + __ret; \ + }) +/* * Creates a new (reference to a) struct vgic_irq for a given LPI. * If this LPI is already mapped on another ITS, we increase its refcount
@@ -798,7 +833,7 @@ static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its,its_free_ite (kvm, ite); -return vgic_its_write_entry_lock (its, gpa,0 , ite_esz); +return vgic_its_write_entry_lock (its, gpa,0ULL , ite); }return E_ITS_DISCARD_UNMAPPED_INTERRUPT ;
@@ -1147,7 +1182,6 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,bool valid =its_cmd_get_validbit (its_cmd);u8 num_eventid_bits =its_cmd_get_size (its_cmd);gpa_t itt_addr =its_cmd_get_ittaddr (its_cmd); -int dte_esz =vgic_its_get_abi (its)->dte_esz;struct its_device *device;gpa_t gpa;
@@ -1172,7 +1206,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,* is an error, so we are done in any case. */ if (!valid) -return vgic_its_write_entry_lock (its, gpa,0 , dte_esz); +return vgic_its_write_entry_lock (its, gpa,0ULL , dte); device =vgic_its_alloc_device (its, device_id, itt_addr, num_eventid_bits);
@@ -2099,7 +2133,7 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz,* vgic_its_save_ite - Save an interrupt translation entry at @gpa */ static int vgic_its_save_ite (struct vgic_its *its,struct its_device *dev, -struct its_ite *ite,gpa_t gpa,int ite_esz) +struct its_ite *ite,gpa_t gpa) {u32 next_offset;u64 val;
@@ -2110,7 +2144,7 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, ite->collection->collection_id; val =cpu_to_le64 (val); -return vgic_its_write_entry_lock (its, gpa, val, ite_esz); +return vgic_its_write_entry_lock (its, gpa, val, ite); }/**
@@ -2210,7 +2244,7 @@ static int vgic_its_save_itt(struct vgic_its *its, struct its_device *device)if (ite->irq->hw && !kvm_vgic_global_state.has_gicv4_1)return -EACCES ; - ret =vgic_its_save_ite (its, device, ite, gpa, ite_esz); + ret =vgic_its_save_ite (its, device, ite, gpa);if (ret)return ret; }
@@ -2249,10 +2283,9 @@ static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev)* @its: ITS handle * @dev: ITS device * @ptr: GPA -* @dte_esz: device table entry size */ static int vgic_its_save_dte (struct vgic_its *its,struct its_device *dev, -gpa_t ptr,int dte_esz) +gpa_t ptr) {u64 val, itt_addr_field;u32 next_offset;
@@ -2265,7 +2298,7 @@ static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev, (dev->num_eventid_bits - 1)); val =cpu_to_le64 (val); -return vgic_its_write_entry_lock (its, ptr, val, dte_esz); +return vgic_its_write_entry_lock (its, ptr, val, dte); }/**
@@ -2345,10 +2378,8 @@ static int vgic_its_device_cmp(void *priv, const struct list_head *a,*/ static int vgic_its_save_device_tables (struct vgic_its *its) { -const struct vgic_its_abi *abi =vgic_its_get_abi (its);u64 baser = its->baser_device_table;struct its_device *dev; -int dte_esz = abi->dte_esz;if (!(baser &GITS_BASER_VALID ))return 0 ;
@@ -2367,7 +2398,7 @@ static int vgic_its_save_device_tables(struct vgic_its *its)if (ret)return ret; - ret =vgic_its_save_dte (its, dev, eaddr, dte_esz); + ret =vgic_its_save_dte (its, dev, eaddr);if (ret)return ret; }
@@ -2448,7 +2479,7 @@ static int vgic_its_restore_device_tables(struct vgic_its *its)static int vgic_its_save_cte (struct vgic_its *its,struct its_collection *collection, -gpa_t gpa,int esz) +gpa_t gpa) {u64 val;
@@ -2457,7 +2488,7 @@ static int vgic_its_save_cte(struct vgic_its *its, collection->collection_id); val =cpu_to_le64 (val); -return vgic_its_write_entry_lock (its, gpa, val, esz); +return vgic_its_write_entry_lock (its, gpa, val, cte); }/*
@@ -2465,7 +2496,7 @@ static int vgic_its_save_cte(struct vgic_its *its,* Return +1 on success, 0 if the entry was invalid (which should be * interpreted as end-of-table), and a negative error value for generic errors. */ -static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa,int esz) +static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa) {struct its_collection *collection;struct kvm *kvm = its->dev->kvm;
@@ -2473,7 +2504,7 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)u64 val;int ret; - ret =vgic_its_read_entry_lock (its, gpa, &val, esz); + ret =vgic_its_read_entry_lock (its, gpa, &val, cte);if (ret)return ret; val =le64_to_cpu (val);
@@ -2520,7 +2551,7 @@ static int vgic_its_save_collection_table(struct vgic_its *its) max_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ;list_for_each_entry (collection, &its->collection_list, coll_list) { - ret =vgic_its_save_cte (its, collection, gpa, cte_esz); + ret =vgic_its_save_cte (its, collection, gpa);if (ret)return ret; gpa += cte_esz;
@@ -2534,7 +2565,7 @@ static int vgic_its_save_collection_table(struct vgic_its *its)* table is not fully filled, add a last dummy element * with valid bit unset */ -return vgic_its_write_entry_lock (its, gpa,0 , cte_esz); +return vgic_its_write_entry_lock (its, gpa,0ULL , cte); }/*
@@ -2559,7 +2590,7 @@ static int vgic_its_restore_collection_table(struct vgic_its *its) max_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ;while (read < max_size) { - ret =vgic_its_restore_cte (its, gpa, cte_esz); + ret =vgic_its_restore_cte (its, gpa);if (ret <=0 )break ; gpa += cte_esz;
arch/arm64/kvm/vgic/vgic.h +0 -23
@@ -146,29 +146,6 @@ static inline int vgic_write_guest_lock(struct kvm *kvm, gpa_t gpa,return ret; } -static inline int vgic_its_read_entry_lock (struct vgic_its *its,gpa_t eaddr, -u64 *eval,unsigned long esize) -{ -struct kvm *kvm = its->dev->kvm; - -if (KVM_BUG_ON (esize !=sizeof (*eval), kvm)) -return -EINVAL ; - -return kvm_read_guest_lock (kvm, eaddr, eval, esize); - -} - -static inline int vgic_its_write_entry_lock (struct vgic_its *its,gpa_t eaddr, -u64 eval,unsigned long esize) -{ -struct kvm *kvm = its->dev->kvm; - -if (KVM_BUG_ON (esize !=sizeof (eval), kvm)) -return -EINVAL ; - -return vgic_write_guest_lock (kvm, eaddr, &eval, esize); -} -/* * This struct provides an intermediate representation of the fields contained * in the GICH_VMCR and ICH_VMCR registers, such that code exporting the GIC
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 326/877 KVM: arm64: vgic-its: Skip unreachable devices instead of failing the save
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit cc5d96036e01ac330d24b2f0c336d60f82ab4930 ]
vgic_its_save_device_tables() aborts with -EINVAL when a device's entry falls outside the device table, which a guest can arrange on its own: an indirect table lets it clear an L1 entry's valid bit without touching GITS_BASER. That fails a save userspace should be able to issue reliably.
Skip the device instead, and point the saved DTE chain past it, as commit ad1e686e2378d ("KVM: arm64: vgic-its: Point saved ITEs at the next valid entry") does for ITEs. compute_next_devid_offset() takes the next device off the list whether or not it was saved, so the predecessor would otherwise point at an entry the save never wrote. Restore follows that offset while it stays inside the table being scanned: within an L2 block, or anywhere in a flat table. Both need userspace to remove a memslot under the table, since dropping an L1 entry takes the whole block with it and scan_its_table() stops at the block boundary.
--- arch/arm64/kvm/vgic/vgic-its.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +19 -13
@@ -2038,18 +2038,22 @@ static int vgic_its_attr_regs_access(struct kvm_device *dev,return ret; } -static u32 compute_next_devid_offset (struct list_head *h, +static u32 compute_next_devid_offset (struct vgic_its *its,u64 baser,struct its_device *dev) { -struct its_device *next; -u32 next_offset; +struct its_device *next = dev; -if (list_is_last (&dev->dev_list, h)) -return 0 ; - next =list_next_entry (dev, dev_list); - next_offset = next->device_id - dev->device_id; +/* +* Point at the next device vgic_its_save_device_tables() saves. It +* sorts device_list first, so the subtraction cannot underflow. +*/ +list_for_each_entry_continue (next, &its->device_list, dev_list) { +if (vgic_its_check_id (its, baser, next->device_id,NULL )) +return min_t (u32, next->device_id - dev->device_id, +VITS_DTE_MAX_DEVID_OFFSET ); + } -return min_t (u32, next_offset,VITS_DTE_MAX_DEVID_OFFSET ); +return 0 ; }static u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite)
@@ -2281,17 +2285,18 @@ static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev)* vgic_its_save_dte - Save a device table entry at a given GPA * * @its: ITS handle +* @baser: GITS_BASER<dev> the caller is saving against * @dev: ITS device * @ptr: GPA */ -static int vgic_its_save_dte (struct vgic_its *its,struct its_device *dev, -gpa_t ptr) +static int vgic_its_save_dte (struct vgic_its *its,u64 baser, +struct its_device *dev,gpa_t ptr) {u64 val, itt_addr_field;u32 next_offset; itt_addr_field = dev->itt_addr >>8 ; - next_offset =compute_next_devid_offset (&its->device_list, dev); + next_offset =compute_next_devid_offset (its, baser, dev); val = (1ULL << KVM_ITS_DTE_VALID_SHIFT | ((u64)next_offset << KVM_ITS_DTE_NEXT_SHIFT) | (itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) |
@@ -2390,15 +2395,16 @@ static int vgic_its_save_device_tables(struct vgic_its *its)int ret;gpa_t eaddr; +/* Don't fail a save that userspace must be able to issue. */ if (!vgic_its_check_id (its, baser, dev->device_id, &eaddr)) -return -EINVAL ; +continue ; ret =vgic_its_save_itt (its, dev);if (ret)return ret; - ret =vgic_its_save_dte (its, dev, eaddr); + ret =vgic_its_save_dte (its, baser, dev, eaddr);if (ret)return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 327/877 KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 64dc6f1db7e620f2e9337bb181f305fb0561da79 ]
kvm_smccc_set_filter() only rejects a range if its inclusive end, base + nr_functions - 1, is below base. That catches an empty range (nr_functions == 0) at every nonzero base, but at base 0 the end wraps to U32_MAX and KVM tries to insert [0, U32_MAX], which overlaps the reserved Arm Architecture Calls ranges. KVM_ARM_VM_SMCCC_FILTER then returns -EEXIST instead of the -EINVAL that the smccc_filter selftest expects for an empty range.
Reject a zero function count explicitly.
Tested with a userspace reproducer on an arm64 VHE host under QEMU TCG:
EEXIST before, EINVAL after.
--- arch/arm64/kvm/hypercalls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/hypercalls.c +2 -1
@@ -183,7 +183,8 @@ static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user start = filter.base; end = start + filter.nr_functions -1 ; -if (end < start || filter.action >=NR_SMCCC_FILTER_ACTIONS ) +if (!filter.nr_functions || end < start || + filter.action >=NR_SMCCC_FILTER_ACTIONS )return -EINVAL ;mutex_lock (&kvm->arch.config_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 328/877 KVM: arm64: Fix FGT mapping for HFGITR_EL2.nGCSEPP
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Brown <[email protected]>
[ Upstream commit 089e4f3c4862ba3f29dff2361caa8084879194fd ]
The encoding to trap mapping currently maps a FGT on OP_GCSPOPX to HFGITR_EL2.nGCSEPP but as per DDI0601 2026-06 this FGT controls trapping of GCSPUSHX and GCSPOPCX, and not the separate GCSPOPX instruction. Update the mapping to reflect the architecture.
--- arch/arm64/kvm/emulate-nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/emulate-nested.c +1 -1
@@ -1287,7 +1287,7 @@ static const struct encoding_to_trap_config encoding_to_fgt[] __initconst = {SR_FGT (OP_AT_S1E1A ,HFGITR ,ATS1E1A ,1 ),SR_FGT (OP_COSP_RCTX ,HFGITR ,COSPRCTX ,1 ),SR_FGT (OP_GCSPUSHX ,HFGITR , nGCSEPP,0 ), -SR_FGT (OP_GCSPOPX ,HFGITR , nGCSEPP,0 ), +SR_FGT (OP_GCSPOPCX ,HFGITR , nGCSEPP,0 ),SR_FGT (OP_GCSPUSHM ,HFGITR , nGCSPUSHM_EL1,0 ),SR_FGT (OP_BRB_IALL ,HFGITR , nBRBIALL,0 ), SR_FGT(OP_BRB_INJ, HFGITR, nBRBINJ, 0),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 329/877 squashfs: Add dictionary size range check to prevent shift-out-of-bounds
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ran Hongyun <[email protected]>
[ Upstream commit 1f7745fb3580152ca902ef181b605f33cabfb1d0 ]
When an abnormal SquashFS image (COMP_OPTS flag is 1 but dictionary size is 0) is mounted, and performs shift operations using dictionarysize, the shift exponent is -1, causing a shift-out-of-bounds.
Detail as below:squashfs_comp_opts(msblk, buffer, length)
squashfs_xz_comp_opts()
if (comp_opts)
n = ffs(opts->dict_size) - 1;<----opts->dict_size=0, n=-1
if (opts->dict_size != (1 << n) && opts->dict_size !=
(1 << n) + (1 << (n + 1))) <----shift-out-of-boundsFix it by adding a dictionary size range check before the shift operation.
--- fs/squashfs/xz_wrapper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/squashfs/xz_wrapper.c +3 -3
@@ -57,10 +57,10 @@ static void *squashfs_xz_comp_opts(struct squashfs_sb_info *msblk, opts->dict_size =le32_to_cpu (comp_opts->dictionary_size); -/* the dictionary size should be 2^n or 2^n+2^(n+1) */ +/* the dictionary size should be positive and 2^n or 2^n+2^(n+1) */ n =ffs (opts->dict_size) -1 ; -if (opts->dict_size != (1 << n) && opts->dict_size != (1 << n) + - (1 << (n +1 ))) { +if (opts->dict_size <=0 || (opts->dict_size != (1 << n) && + opts->dict_size != (1 << n) + (1 << (n +1 )))) { err = -EIO ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 330/877 scsi: sd_zbc: Reject disks with too many zones
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZHOU Jiaxiang <[email protected]>
[ Upstream commit b6ec0f79745967c751c85df373062c8d15e45fc4 ]
sd_zbc_read_zones() computes the number of zones with 64-bit arithmetic and stores the result in the unsigned int nr_zones field of struct zoned_disk_info, silently truncating counts that exceed 32 bits. The truncated count is later used to size per-zone resources, while the device may still report more zones than fit.
Moreover, sd_zbc_report_zones() counts the reported zones with a signed int zone_idx, which overflows past INT_MAX. Reject devices reporting more than INT_MAX zones at scan time; such a device is not realistic for any medium that exists today, and accepting it produces inconsistent zone bookkeeping.
--- drivers/scsi/sd_zbc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/sd_zbc.c +7 -1
@@ -595,7 +595,7 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)int sd_zbc_read_zones (struct scsi_disk *sdkp,struct queue_limits *lim,u8 buf[SD_BUF_SIZE ]) { -unsigned int nr_zones; +u64 nr_zones;u32 zone_blocks =0 ;int ret;
@@ -627,6 +627,12 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim, goto err; nr_zones =round_up (sdkp->capacity, zone_blocks) >>ilog2 (zone_blocks); +if (nr_zones >INT_MAX ) { +sd_printk (KERN_ERR , sdkp,"Too many zones (%llu)\n" , + nr_zones); + ret = -EINVAL ; + goto err; + } sdkp->early_zone_info.nr_zones = nr_zones; sdkp->early_zone_info.zone_blocks = zone_blocks;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 331/877 Bluetooth: SMP: reject Security Request over BR/EDR
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christiano Amora <[email protected]>
[ Upstream commit f033482d76a9f18080c7a40c5f9c678bd7adc8f3 ]
Bose QC Ultra Headphones (dual-mode, same public address on both transports) occasionally send an SMP Security Request on the BR/EDR SMP fixed channel right after the ACL link is encrypted. The kernel handles it as if it were an LE link: smp_cmd_security_req() has no transport check, smp_ltk_encrypt() looks up an LTK with the ACL connection's dst_type, and hci_find_ltk() matches the peer's LE LTK because the LE public address type is stored as ADDR_LE_DEV_PUBLIC (0), the same value as BDADDR_BREDR. HCI_OP_LE_START_ENC is then issued on the ACL handle, the controller rejects it with Invalid HCI Command Parameters, and hci_cs_le_start_enc() disconnects the link with HCI_ERROR_AUTH_FAILURE. The headphones drop within a second of connecting, before any profile is up; a manual reconnect works.
btmon (MediaTek MT7922, kernel 7.0.12):
Quoted 1 line
HCI Event: Encryption Change (
0x08) plen 4
Status: Success (0x00)
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)
Encryption: Enabled with AES-CCM (0x02)Quoted 1 line
ACL Data RX: Handle 50 flags
0x02dlen 6
BR/EDR SMP: Security Request (0x0b) len 1
Authentication requirement: No bonding, No MITM, SC (0x08)
< HCI Command: LE Start Encryption (0x08|0x0019) plen 28
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Start Encryption (0x08|0x0019) ncmd 1
Status: Invalid HCI Command Parameters (0x12)
< HCI Command: Disconnect (0x01|0x0006) plen 3
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)
Reason: Authentication Failure (0x05)SMP over BR/EDR is limited to cross-transport key derivation; the Security Request procedure (Core Specification Vol 3, Part H, Section 2.4.6, PDU in Section 3.6.7) has no BR/EDR counterpart. Reply with Pairing Failed / Command Not Supported on a non-LE link, before the PDU is parsed, and keep the connection. The reply is sent directly rather than through smp_failure(): rejecting a command on the wrong transport is not an authentication failure, and MGMT_EV_AUTH_FAILED would make bluetoothd disconnect the device.
Tested on the affected host (kernel 7.0.12, MediaTek MT7922, Bose QC Ultra) with the patched module built out of tree: 7 days and 49 reconnects without a drop, against 2 drops in the 3 days before the patch. Every disconnect in that week had a userspace or remote reason.
--- net/bluetooth/smp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/bluetooth/smp.c +17 -0
@@ -2301,6 +2301,23 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)bt_dev_dbg (hdev,"conn %p" , conn); +/* SMP over BR/EDR only covers cross-transport key derivation; the +* Security Request procedure has no BR/EDR counterpart. Reject it +* here, otherwise smp_ltk_encrypt() finds the peer's LE LTK +* (ADDR_LE_DEV_PUBLIC and BDADDR_BREDR are both 0) and issues +* HCI_OP_LE_START_ENC on the ACL handle, which the controller +* rejects and hci_cs_le_start_enc() turns into a disconnect. Reply +* without smp_failure(): this is not an authentication failure, and +* MGMT_EV_AUTH_FAILED would make bluetoothd drop the device. +*/ +if (hcon->type !=LE_LINK ) { +u8 reason =SMP_CMD_NOTSUPP ; + +smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), + &reason); +return 0 ; + } +if (skb->len <sizeof (*rp))return SMP_INVALID_PARAMS ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 332/877 Bluetooth: mgmt: Dequeue pending mesh_send_sync entries on cancel
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit 71af682ba4692c2ed9ace4c3d4ca462ae368c029 ]
In send_cancel(), pending mesh_tx objects are removed from the hdev->mesh_pending list and freed via mesh_send_complete(). However, if a mesh transmission was already queued onto hdev->cmd_sync_work_list via mesh_next(), the queued entry retains a raw pointer to mesh_tx.
When hci_cmd_sync_work later processes the entry, it attempts to execute mesh_send_sync and its destroy callback mesh_send_start_complete using the already freed mesh_tx pointer, leading to a use-after-free.
Fix this by invoking hci_cmd_sync_dequeue() for mesh_send_sync on the target mesh_tx before completing it. If the entry is found and dequeued, its destroy callback will complete and free the object; otherwise, mesh_send_complete() is called directly.
Additionally, ensure the transmission queue advances after cancellation or errors. In mesh_send_start_complete(), call mesh_next() on error unless err is -ECANCELED, because hci_cmd_sync_dequeue() holds hdev->cmd_sync_work_lock and calling mesh_next() synchronously would deadlock. Instead, advance the queue in send_cancel() once the lock is released and if no transmission is in progress.
--- net/bluetooth/mgmt.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/bluetooth/mgmt.c +15 -4
@@ -2290,6 +2290,8 @@ static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err)hci_dev_clear_flag (hdev,HCI_MESH_SENDING );/* Send Complete Error Code for handle */ mesh_send_complete (hdev, mesh_tx, false); +if (err != -ECANCELED ) +mesh_next (hdev,NULL ,0 );return ; }
@@ -2399,19 +2401,28 @@ static int send_cancel(struct hci_dev *hdev, void *data)do { mesh_tx =mgmt_mesh_next (hdev, cmd->sk); -if (mesh_tx) -mesh_send_complete (hdev, mesh_tx, false); +if (mesh_tx) { +if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, + mesh_tx,NULL )) +mesh_send_complete (hdev, mesh_tx, false); + } }while (mesh_tx); }else { mesh_tx =mgmt_mesh_find (hdev, cancel->handle); -if (mesh_tx && mesh_tx->sk == cmd->sk) -mesh_send_complete (hdev, mesh_tx, false); +if (mesh_tx && mesh_tx->sk == cmd->sk) { +if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, + mesh_tx,NULL )) +mesh_send_complete (hdev, mesh_tx, false); + } }mgmt_cmd_complete (cmd->sk, hdev->id,MGMT_OP_MESH_SEND_CANCEL ,0 ,NULL ,0 ); +if (!hci_dev_test_flag (hdev,HCI_MESH_SENDING )) +mesh_next (hdev,NULL ,0 ); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 333/877 cgroup: selftests: Move memcontrol specific helpers out of common cgroup_util.c
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 3a7f9e518c6a83d54c84c101e23ffc8aa12df139 ]
Move a handful of helpers out of cgroup_util.c and into test_memcontrol.c that have nothing to with cgroups in general, in anticipation of making cgroup_util.c a generic library that can be used by other selftests.
Make read_text() and write_text() non-static so test_memcontrol.c can use them.
Stable-dep-of: c774ec8f0a5d ("selftests: cgroup: give the O_TMPFILE open in get_temp_fd() a mode")
--- tools/testing/selftests/cgroup/cgroup_util.c | 82 +------------------ tools/testing/selftests/cgroup/cgroup_util.h | 8 +- .../selftests/cgroup/test_memcontrol.c | 78 ++++++++++++++++++ 3 files changed, 83 insertions(+), 85 deletions(-)
tools/testing/selftests/cgroup/cgroup_util.c +2 -80
@@ -20,7 +20,7 @@#include "../clone3/clone3_selftests.h" /* Returns read len on success, or -errno on failure. */ -static ssize_t read_text (const char *path,char *buf,size_t max_len) +ssize_t read_text (const char *path,char *buf,size_t max_len) {ssize_t len;int fd;
@@ -39,7 +39,7 @@ static ssize_t read_text(const char *path, char *buf, size_t max_len) }/* Returns written len on success, or -errno on failure. */ -static ssize_t write_text (const char *path,char *buf,ssize_t len) +ssize_t write_text (const char *path,char *buf,ssize_t len) {int fd;
@@ -488,84 +488,6 @@ int cg_run_nowait(const char *cgroup,return pid; } -int get_temp_fd (void ) -{ -return open ("." ,O_TMPFILE |O_RDWR |O_EXCL ); -} - -int alloc_pagecache (int fd,size_t size) -{ -char buf[PAGE_SIZE ]; -struct stat st; -int i; - -if (fstat (fd, &st)) - goto cleanup; - - size += st.st_size; - -if (ftruncate (fd, size)) - goto cleanup; - -for (i =0 ; i < size; i +=sizeof (buf)) -read (fd, buf,sizeof (buf)); - -return 0 ; - -cleanup: -return -1 ; -} - -int alloc_anon (const char *cgroup,void *arg) -{ -size_t size = (unsigned long )arg; -char *buf, *ptr; - - buf =malloc (size); -for (ptr = buf; ptr < buf + size; ptr +=PAGE_SIZE ) - *ptr =0 ; - -free (buf); -return 0 ; -} - -int is_swap_enabled (void ) -{ -char buf[PAGE_SIZE ]; -const char delim[] ="\n" ; -int cnt =0 ; -char *line; - -if (read_text ("/proc/swaps" , buf,sizeof (buf)) <=0 ) -return -1 ; - -for (line =strtok (buf, delim); line; line =strtok (NULL , delim)) - cnt++; - -return cnt >1 ; -} - -int set_oom_adj_score (int pid,int score) -{ -char path[PATH_MAX ]; -int fd, len; - -sprintf (path,"/proc/%d/oom_score_adj" , pid); - - fd =open (path,O_WRONLY |O_APPEND ); -if (fd <0 ) -return fd; - - len =dprintf (fd,"%d" , score); -if (len <0 ) { -close (fd); -return len; - } - -close (fd); -return 0 ; -} -int proc_mount_contains (const char *option) {char buf[4 *PAGE_SIZE ];
tools/testing/selftests/cgroup/cgroup_util.h +3 -5
@@ -21,6 +21,9 @@ static inline int values_close(long a, long b, int err)return labs (a - b) <= (a + b) /100 * err; } +extern ssize_t read_text (const char *path,char *buf,size_t max_len); +extern ssize_t write_text (const char *path,char *buf,ssize_t len); +extern int cg_find_unified_root (char *root,size_t len,bool *nsdelegate);extern char *cg_name (const char *root,const char *name);extern char *cg_name_indexed (const char *root,const char *name,int index);
@@ -49,11 +52,6 @@ extern int cg_enter_current_thread(const char *cgroup);extern int cg_run_nowait (const char *cgroup,int (*fn)(const char *cgroup,void *arg),void *arg); -extern int get_temp_fd (void ); -extern int alloc_pagecache (int fd,size_t size); -extern int alloc_anon (const char *cgroup,void *arg); -extern int is_swap_enabled (void ); -extern int set_oom_adj_score (int pid,int score);extern int cg_wait_for_proc_count (const char *cgroup,int count);extern int cg_killall (const char *cgroup);int proc_mount_contains (const char *option);
tools/testing/selftests/cgroup/test_memcontrol.c +78 -0
84 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 334/877 selftests: cgroup: give the O_TMPFILE open in get_temp_fd() a mode
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eva Kurchatova <[email protected]>
[ Upstream commit c774ec8f0a5d02a06d34c27f5a7de7e333b91265 ]
O_TMPFILE, like O_CREAT, needs the third argument. Without it glibc refuses the call at compile time as soon as fortification is on:
In function 'open',
inlined from 'get_temp_fd' at test_memcontrol.c:33:9:
/usr/include/bits/fcntl2.h:52:11: error: call to '__open_missing_mode'
declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
The fortify checks take effect only once the compiler optimises, and cgroup/Makefile builds with "-Wall -pthread" alone, so this goes unnoticed in a plain build. Building the tests with the flags distributions commonly use, -O2 -D_FORTIFY_SOURCE=3, loses test_memcontrol entirely.
--- tools/testing/selftests/cgroup/test_memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/cgroup/test_memcontrol.c +1 -1
@@ -26,7 +26,7 @@ static bool has_recursiveprot;int get_temp_fd (void ) { -return open ("." ,O_TMPFILE |O_RDWR |O_EXCL ); +return open ("." ,O_TMPFILE |O_RDWR |O_EXCL ,0600 ); }int alloc_pagecache (int fd,size_t size)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 335/877 scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 42d1221d321e55afc7bba9109a77aaf5a817c8a3 ]
Protect the megasas_get_ctrl_info() call in megasas_resume() with instance->reset_mutex using scoped_guard().
megasas_get_ctrl_info() may release and reacquire instance->reset_mutex. Hence, calling this function without holding instance->reset_mutex is not safe.
--- drivers/scsi/megaraid/megaraid_sas_base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/megaraid/megaraid_sas_base.c +3 -1
@@ -7873,7 +7873,9 @@ megasas_resume(struct device *dev) goto fail_init_mfi; } -if (megasas_get_ctrl_info (instance) !=DCMD_SUCCESS ) +scoped_guard (mutex, &instance->reset_mutex) + rval = megasas_get_ctrl_info(instance); +if (rval !=DCMD_SUCCESS ) goto fail_init_mfi; tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 336/877 docs: s390/pci: Improve and update PCI documentation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Schnelle <[email protected]>
[ Upstream commit 737c4f4a241ca85c597ca2ef1a6f8446bf681ab5 ]
Update the s390 specific PCI documentation to better reflect current behavior and terms such as the handling of Isolated VFs via commit 25f39d3dcb48 ("s390/pci: Ignore RID for isolated VFs").
Add a descriptions for /sys/firmware/clp/uid_checking which was added in commit b043a81ce3ee ("s390/pci: Expose firmware provided UID Checking state in sysfs") but missed documentation.
Similarly add documentation for the fidparm attribute added by commit 99ad39306a62 ("s390/pci: Expose FIDPARM attribute in sysfs") and add a list of pft values and their names.
Finally improve formatting of the different attribute descriptions by adding a separating colon.
Stable-dep-of: 4525a9110495 ("s390/pci/docs: Fix sriov_numvfs attribute name")
--- Documentation/arch/s390/pci.rst | 152 +++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 51 deletions(-)
Documentation/arch/s390/pci.rst +101 -51
@@ -6,6 +6,7 @@ S/390 PCI Authors: - Pierre Morel + - Niklas Schnelle Copyright, IBM Corp. 2020
@@ -27,14 +28,16 @@ Command line parameters debugfs entries --------------- -The S/390 debug feature (s390dbf) generates views to hold various debug results in sysfs directories of the form: +The S/390 debug feature (s390dbf) generates views to hold various debug results +in sysfs directories of the form: * /sys/kernel/debug/s390dbf/pci_*/ For example: - /sys/kernel/debug/s390dbf/pci_msg/sprintf - Holds messages from the processing of PCI events, like machine check handling + + holds messages from the processing of PCI events, like machine check handling and setting of global functionality, like UID checking. Change the level of logging to be more or less verbose by piping
@@ -47,87 +50,134 @@ Sysfs entries Entries specific to zPCI functions and entries that hold zPCI information. -* /sys/bus/pci/slots/XXXXXXXX +* /sys/bus/pci/slots/XXXXXXXX: - The slot entries are set up using the function identifier (FID) of the - PCI function. The format depicted as XXXXXXXX above is 8 hexadecimal digits - with 0 padding and lower case hexadecimal digits. + The slot entries are set up using the function identifier (FID) of the PCI + function as slot name. The format depicted as XXXXXXXX above is 8 hexadecimal + digits with 0 padding and lower case hexadecimal digits. - /sys/bus/pci/slots/XXXXXXXX/power A physical function that currently supports a virtual function cannot be powered off until all virtual functions are removed with: - echo 0 > /sys/bus/pci/devices/XXXX:XX:XX.X/sriov_numvf + echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvf -* /sys/bus/pci/devices/XXXX:XX:XX.X/ +* /sys/bus/pci/devices/DDDD:BB:dd.f/: - - function_id - A zPCI function identifier that uniquely identifies the function in the Z server. + - function_id: + The zPCI function identifier (FID) is a 32-bit hexadecimal value that + uniquely identifies the PCI function. Unless the hypervisor provides + a virtual FID e.g. on KVM this identifier is unique across the machine even + between different partitions. - - function_handle - Low-level identifier used for a configured PCI function. - It might be useful for debugging. + - function_handle: + This 32-bit hexadecimal value is a low-level identifier used for a PCI + function. Note that the function handle may be changed and become invalid + on PCI events and when enabling/disabling the PCI function. - - pchid - Model-dependent location of the I/O adapter. + - pchid: + This 16-bit hexadecimal value encodes a model-dependent location for + the PCI function. - - pfgid - PCI function group ID, functions that share identical functionality + - pfgid: + PCI function group ID; functions that share identical functionality use a common identifier. A PCI group defines interrupts, IOMMU, IOTLB, and DMA specifics. - - vfn + - vfn: The virtual function number, from 1 to N for virtual functions, 0 for physical functions. - - pft - The PCI function type - - - port - The port corresponds to the physical port the function is attached to. - It also gives an indication of the physical function a virtual function - is attached to. - - - uid - The user identifier (UID) may be defined as part of the machine - configuration or the z/VM or KVM guest configuration. If the accompanying - uid_is_unique attribute is 1 the platform guarantees that the UID is unique - within that instance and no devices with the same UID can be attached - during the lifetime of the system. - - - uid_is_unique - Indicates whether the user identifier (UID) is guaranteed to be and remain - unique within this Linux instance. - - - pfip/segmentX + - pft: + The PCI function type is an s390-specific type attribute. It indicates + a more general, usage oriented, type than PCI Specification + class/vendor/device identifiers. That is PCI functions with the same pft + value may be backed by different hardware implementations. At the same time + apart from unclassified functions (pft is 0x00) the same pft value + generally implies a similar usage model. At the same time the same + PCI hardware device may appear with different pft values when in a + different usage model. For example NETD and NETH VFs may be implemented + by the same PCI hardware device but in NETD the parent Physical Function + is user managed while with NETH it is platform managed. + + Currently the following PFT values are defined: + + - 0x00 (UNC): Unclassified + - 0x02 (ROCE): RoCE Express + - 0x05 (ISM): Internal Shared Memory + - 0x0a (ROC2): RoCE Express 2 + - 0x0b (NVMe): NVMe + - 0x0c (NETH): Network Express hybrid + - 0x0d (CNW): Cloud Network Adapter + - 0x0f (NETD): Network Express direct + + - port: + The port is a decimal value corresponding to the physical port the function + is attached to. Virtual Functions (VFs) share the port with their parent + Physical Function (PF). A value of 0 indicates that the port attribute is + not applicable for that PCI function type. + + - uid: + The user-defined identifier (UID) for a PCI function is a 32-bit + hexadecimal value. It is defined on a per instance basis as part of the + partition, KVM guest, or z/VM guest configuration. If UID Checking is + enabled the platform ensures that the UID is unique within that instance + and no two PCI functions with the same UID will be visible to the instance. + + Independent of this guarantee and unlike the function ID (FID) the UID may + be the same in different partitions within the same machine. This allows to + create PCI configurations in multiple partitions to be identical in the + UID-namespace. + + - uid_is_unique: + A 0 or 1 flag indicating whether the user-defined identifier (UID) is + guaranteed to be and remain unique within this Linux instance. This + platform feature is called UID Checking. + + - pfip/segmentX: The segments determine the isolation of a function. They correspond to the physical path to the function. The more the segments are different, the more the functions are isolated. + - fidparm: + Contains an 8-bit-per-PCI function parameter field in hexadecimal provided + by the platform. The meaning of this field is PCI function type specific. + For NETH VFs a value of 0x01 indicates that the function supports + promiscuous mode. + +* /sys/firmware/clp/uid_checking: + + In addition to the per-device uid_is_unique attribute this presents a + global indication of whether UID Checking is enabled. This allows users + to check for UID Checking even when no PCI functions are configured. + Enumeration and hotplug ======================= The PCI address consists of four parts: domain, bus, device and function, -and is of this form: DDDD:BB:dd.f +and is of this form: DDDD:BB:dd.f. -* When not using multi-functions (norid is set, or the firmware does not - support multi-functions): +* For a PCI function for which the platform does not expose the RID, the + pci=norid kernel parameter is used, or a so-called isolated Virtual Function + which does have RID information but is used without its parent Physical + Function being part of the same PCI configuration: - There is only one function per domain. - - The domain is set from the zPCI function's UID as defined during the - LPAR creation. + - The domain is set from the zPCI function's UID if UID Checking is on; + otherwise the domain ID is generated dynamically and is not stable + across reboots or hot plug. -* When using multi-functions (norid parameter is not set), - zPCI functions are addressed differently: +* For a PCI function for which the platform exposes the RID and which + is not an Isolated Virtual Function: - There is still only one bus per domain. - - There can be up to 256 functions per bus. + - There can be up to 256 PCI functions per bus. - - The domain part of the address of all functions for - a multi-Function device is set from the zPCI function's UID as defined - in the LPAR creation for the function zero. + - The domain part of the address of all functions within the same topology is + that of the configured PCI function with the lowest devfn within that + topology. - - New functions will only be ready for use after the function zero - (the function with devfn 0) has been enumerated. + - Virtual Functions generated by an SR-IOV capable Physical Function only + become visible once SR-IOV is enabled.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 337/877 s390/pci/docs: Fix sriov_numvfs attribute name
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 4525a911049543c23885a540a788d13be318a486 ]
The attribute is sriov_numvfs (drivers/pci/iov.c); the document names it sriov_numvf, which does not exist.
Use sriov_numvfs.
--- Documentation/arch/s390/pci.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/arch/s390/pci.rst +1 -1
@@ -60,7 +60,7 @@ Entries specific to zPCI functions and entries that hold zPCI information. A physical function that currently supports a virtual function cannot be powered off until all virtual functions are removed with: - echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvf + echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvfs * /sys/bus/pci/devices/DDDD:BB:dd.f/:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 338/877 s390/cio: Fix cio_update_schib() to not cache invalid schib
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit 29d9e5835d89223aa913dcf7b942cc1c148bdd25 ]
When pmcw.dnv is 0, the contents of all SCHIB fields are unpredictable. Zero sch->schib in that case to prevent subsequent code from making decisions based on unpredictable data.
--- drivers/s390/cio/cio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/s390/cio/cio.c +7 -4
@@ -453,7 +453,8 @@ EXPORT_SYMBOL_GPL(cio_commit_config);/** * cio_update_schib - Perform stsch and update schib if subchannel is valid. * @sch: subchannel on which to perform stsch -* Return zero on success, -ENODEV otherwise. +* Return zero on success, -ENODEV if the subchannel is not operational, +* -EACCES if the subchannel has no valid device. */ int cio_update_schib (struct subchannel *sch) {
@@ -462,10 +463,12 @@ int cio_update_schib(struct subchannel *sch)if (stsch (sch->schid, &schib))return -ENODEV ; -memcpy (&sch->schib, &schib,sizeof (schib)); - -if (!css_sch_is_valid (&schib)) +if (!css_sch_is_valid (&schib)) { +memset (&sch->schib,0 ,sizeof (sch->schib));return -EACCES ; + } + +memcpy (&sch->schib, &schib,sizeof (schib));return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 339/877 s390/cio: Check pmcw.dnv before pmcw.ena in I/O entry points
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit f6f2985eabdb2bfdc82ce90a1ea3ec53ba795f34 ]
The device number valid (dnv) bit in the PMCW must be checked before acting on any other PMCW fields for IO-type subchannels. A subchannel with dnv=0 has no valid device number associated, making it meaningless to evaluate the enabled (ena) state or issue any I/O instruction against it.
--- drivers/s390/cio/device_ops.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/s390/cio/device_ops.c +12 -0
@@ -142,6 +142,8 @@ int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -198,6 +200,8 @@ int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -379,6 +383,8 @@ int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -413,6 +419,8 @@ int ccw_device_resume(struct ccw_device *cdev)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -548,6 +556,8 @@ int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,int rc; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_VERIFY ) {
@@ -694,6 +704,8 @@ int ccw_device_tm_intrg(struct ccw_device *cdev) {struct subchannel *sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state !=DEV_STATE_ONLINE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 340/877 s390/cio: Guard PMCW field accesses with dnv check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit 9590f4d83880dfb5a81906e48e72779248fbe8f0 ]
When PMCW.DNV is 0, no I/O device is associated with the subchannel. However, several code paths access PMCW fields directly from the cached sch->schib without first invoking the update helper. Add explicit DNV validation before accessing PMCW fields from the cached SCHIB to avoid using invalid data.
--- drivers/s390/cio/chp.c | 3 +++ drivers/s390/cio/device.c | 9 +++++---- drivers/s390/cio/device_fsm.c | 3 +++ drivers/s390/cio/device_ops.c | 9 +++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-)
drivers/s390/cio/chp.c +3 -0
@@ -78,6 +78,9 @@ u8 chp_get_sch_opm(struct subchannel *sch)int opm;int i; +if (!sch->schib.pmcw.dnv) +return 0 ; + opm =0 ;chp_id_init (&chpid);for (i =0 ; i <8 ; i++) {
drivers/s390/cio/device.c +5 -4
@@ -925,7 +925,7 @@ static int ccw_device_move_to_sch(struct ccw_device *cdev,if (!sch_is_pseudo_sch (old_sch)) {spin_lock_irq (&old_sch->lock); - old_enabled = old_sch->schib.pmcw.ena; + old_enabled = old_sch->schib.pmcw.dnv && old_sch->schib.pmcw.ena; rc =0 ;if (old_enabled) rc =cio_disable_subchannel (old_sch);
@@ -944,7 +944,7 @@ static int ccw_device_move_to_sch(struct ccw_device *cdev,CIO_MSG_EVENT (0 ,"device_move(0.%x.%04x,0.%x.%04x)=%d\n" , cdev->private->dev_id.ssid, cdev->private->dev_id.devno, sch->schid.ssid, - sch->schib.pmcw.dev, rc); + sch->schid.sch_no, rc);if (old_enabled) {/* Try to re-enable the old subchannel. */ spin_lock_irq (&old_sch->lock);
@@ -1210,7 +1210,7 @@ static void io_subchannel_quiesce(struct subchannel *sch) cdev =sch_get_cdev (sch);if (cio_is_console (sch->schid)) goto out_unlock; -if (!sch->schib.pmcw.ena) +if (!sch->schib.pmcw.dnv || !sch->schib.pmcw.ena) goto out_unlock; ret =cio_disable_subchannel (sch);if (ret != -EBUSY )
@@ -1257,7 +1257,8 @@ static int recovery_check(struct device *dev, void *data)switch (cdev->private->state) {case DEV_STATE_ONLINE : sch =to_subchannel (cdev->dev.parent); -if ((sch->schib.pmcw.pam & sch->opm) == sch->vpm) +if (sch->schib.pmcw.dnv && + (sch->schib.pmcw.pam & sch->opm) == sch->vpm)break ; fallthrough;case DEV_STATE_DISCONNECTED :
drivers/s390/cio/device_fsm.c +3 -0
@@ -169,6 +169,9 @@ __recover_lost_chpids(struct subchannel *sch, int old_lpm)int mask, i;struct chp_id chpid; +if (!sch->schib.pmcw.dnv) +return ; +chp_id_init (&chpid);for (i =0 ; i<8 ; i++) { mask =0x80 >> i;
drivers/s390/cio/device_ops.c +9 -0
@@ -490,6 +490,8 @@ struct channel_path_desc_fmt0 *ccw_device_get_chp_desc(struct ccw_device *cdev,struct chp_id chpid; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return NULL ;chp_id_init (&chpid); chpid.id = sch->schib.pmcw.chpid[chp_idx];return chp_get_chp_desc (chpid);
@@ -510,6 +512,8 @@ u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx)struct chp_id chpid;u8 *util_str; +if (!sch->schib.pmcw.dnv) +return NULL ;chp_id_init (&chpid); chpid.id = sch->schib.pmcw.chpid[chp_idx]; chp =chpid_to_chp (chpid);
@@ -662,6 +666,9 @@ int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)struct chp_id chpid;int mdc =0 , i; +if (!sch->schib.pmcw.dnv) +return 0 ; +/* Adjust requested path mask to excluded varied off paths. */ if (mask) mask &= sch->lpm;
@@ -798,6 +805,8 @@ int ccw_device_get_chpid(struct ccw_device *cdev, int chp_idx, u8 *chpid)if ((chp_idx <0 ) || (chp_idx >7 ))return -EINVAL ; +if (!sch->schib.pmcw.dnv) +return -ENODEV ; mask =0x80 >> chp_idx;if (!(sch->schib.pmcw.pim & mask))return -ENODEV ;
drivers/s390/cio/vfio_ccw_fsm.c +1 -1
@@ -399,7 +399,7 @@ static void fsm_close(struct vfio_ccw_private *private,spin_lock_irq (&sch->lock); -if (!sch->schib.pmcw.ena) +if (!sch->schib.pmcw.dnv || !sch->schib.pmcw.ena) goto err_unlock; ret =cio_disable_subchannel (sch);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 341/877 fs: avoid repeated scans in evict_inodes()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit 7459c021874246c196f397686e100702f059b9e7 ]
We observed hung tasks when users attempted to unmount a filesystem after its disk had been removed while still in use. During device removal, fs_bdev_mark_dead() calls evict_inodes() while holding s_umount.
Each time evict_inodes() drops s_inode_list_lock to reschedule, it restarts the walk from the head of s_inodes. With many referenced inodes at the head of the list, these restarts repeatedly scan the same inodes without reclaiming them. This can keep s_umount held for a long time, blocking concurrent umount attempts and triggering hung-task reports.
Keep the current inode, already marked I_FREEING, out of the disposal batch until s_inode_list_lock is reacquired. Resume the walk from this inode and dispose of it in a later batch or at the end of the walk.
The zero-refcount and state checks under i_lock allow this walker to claim the inode by setting I_FREEING and removing it from the LRU. Other reclaimers skip the inode, leaving this walker responsible for eviction. Only evict() removes it from s_inodes, so keeping it out of the disposal batch ensures that it remains on the list while the lock is dropped. After reacquiring the lock, reading its current next pointer accounts for concurrent removal of following inodes.
The existing inode lifetime rules prohibit acquiring a reference to an inode marked I_FREEING or I_WILL_FREE. __iget() requires its caller to hold i_lock and establish that taking a reference is valid. Inode lookup and igrab() check these flags under i_lock when acquiring a reference from zero. ihold() requires an existing reference, which would keep i_count nonzero and prevent this walker from claiming the inode. These rules already allow iput_final() and the inode shrinker to release i_lock after setting I_FREEING and before eviction completes.
A temporary __iget() reference would also keep the inode on the list, but its release must preserve last-reference handling. Another user can acquire a reference, update lazy timestamps and drop its reference while the pin is held. If the pin becomes the last reference, dropping it with atomic_dec_and_test() and evicting directly bypasses iput()'s lazytime handling and can lose those timestamp updates.
Releasing the pin with iput() preserves that handling, but does not guarantee eviction. fs_bdev_mark_dead() runs with SB_ACTIVE set, so iput() may retain the inode in cache, whereas evict_inodes() must evict eligible zero-reference inodes. The inode may also have been freed when iput() returns, so the walker cannot then use it to force eviction. Using I_FREEING preserves the existing eviction behavior without introducing an additional last-reference transition.
The xfstests auto group passed on ext4 and XFS with known unrelated failures excluded. No new issues were observed, and the previously reproducible hung task no longer occurs with this patch.
--- fs/inode.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/inode.c +5 -6
@@ -790,7 +790,6 @@ void evict_inodes(struct super_block *sb)struct inode *inode, *next;LIST_HEAD (dispose); -again:spin_lock (&sb->s_inode_list_lock);list_for_each_entry_safe (inode, next, &sb->s_inodes, i_sb_list) {if (atomic_read (&inode->i_count))
@@ -809,19 +808,19 @@ void evict_inodes(struct super_block *sb) inode->i_state |=I_FREEING ;inode_lru_list_del (inode);spin_unlock (&inode->i_lock); -list_add (&inode->i_lru, &dispose);/* -* We can have a ton of inodes to evict at unmount time given -* enough memory, check to see if we need to go to sleep for a -* bit so we don't livelock. +* Keep this inode out of dispose so it stays on s_inodes while +* the list lock is dropped. I_FREEING prevents new references +* and leaves eviction to us, so we can resume the walk from it. */ if (need_resched ()) {spin_unlock (&sb->s_inode_list_lock);cond_resched ();dispose_list (&dispose); - goto again; +spin_lock (&sb->s_inode_list_lock); } +list_add (&inode->i_lru, &dispose); }spin_unlock (&sb->s_inode_list_lock);
Signature · 1 line
2.53.0
Re: [PATCH 6.12 341/877] fs: avoid repeated scans in evict_inodes()
Quoted 58 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit
7459c021874246c196f397686e100702f059b9e7]We observed hung tasks when users attempted to unmount a filesystem after its disk had been removed while still in use. During device removal,
fs_bdev_mark_dead()callsevict_inodes()while holdings_umount.Each time
evict_inodes()dropss_inode_list_lockto reschedule, it restarts the walk from the head ofs_inodes. With many referenced inodes at the head of the list, these restarts repeatedly scan the same inodes without reclaiming them. This can keeps_umountheld for a long time, blocking concurrent umount attempts and triggering hung-task reports.Keep the current inode, already marked
I_FREEING, out of the disposal batch untils_inode_list_lockis reacquired. Resume the walk from this inode and dispose of it in a later batch or at the end of the walk.The zero-refcount and state checks under
i_lockallow this walker to claim the inode by settingI_FREEINGand removing it from the LRU. Other reclaimers skip the inode, leaving this walker responsible for eviction. Onlyevict()removes it froms_inodes, so keeping it out of the disposal batch ensures that it remains on the list while the lock is dropped. After reacquiring the lock, reading its current next pointer accounts for concurrent removal of following inodes.The existing inode lifetime rules prohibit acquiring a reference to an inode marked
I_FREEINGorI_WILL_FREE.__iget()requires its caller to holdi_lockand establish that taking a reference is valid. Inode lookup andigrab()check these flags underi_lockwhen acquiring a reference from zero.ihold()requires an existing reference, which would keepi_countnonzero and prevent this walker from claiming the inode. These rules already allowiput_final()and the inode shrinker to releasei_lockafter settingI_FREEINGand before eviction completes.A temporary
__iget()reference would also keep the inode on the list, but its release must preserve last-reference handling. Another user can acquire a reference, update lazy timestamps and drop its reference while the pin is held. If the pin becomes the last reference, dropping it withatomic_dec_and_test()and evicting directly bypasses iput()'s lazytime handling and can lose those timestamp updates.Releasing the pin with
iput()preserves that handling, but does not guarantee eviction.fs_bdev_mark_dead()runs withSB_ACTIVEset, soiput()may retain the inode in cache, whereasevict_inodes()must evict eligible zero-reference inodes. The inode may also have been freed wheniput()returns, so the walker cannot then use it to force eviction. UsingI_FREEINGpreserves the existing eviction behavior without introducing an additional last-reference transition.The xfstests auto group passed on ext4 and XFS with known unrelated failures excluded. No new issues were observed, and the previously reproducible hung task no longer occurs with this patch.
Quoted 6 lines
Fixes ac05fbb40062 ("inode: don't softlockup when evicting inodes")Signed-off-by Julian Sun <[email protected]>Reviewed-by Jan Kara <[email protected]>Signed-off-by Christian Brauner (Amutable) <[email protected]>Signed-off-by Sasha Levin <[email protected]>
Hi Greg/Sasha,
An AI assisted backport review flagged this, and I checked the upstream code against the 6.12.y tip f4ffa8dc360b.
Upstream 7459c0218742 uses the current inode's successor after relocking:
struct inode *inode;
LIST_HEAD(dispose);
spin_lock(&sb->s_inode_list_lock);
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
/* ... intervening source omitted ... */
if (need_resched()) {
spin_unlock(&sb->s_inode_list_lock);
cond_resched();
dispose_list(&dispose);
spin_lock(&sb->s_inode_list_lock);
}
list_add(&inode->i_lru, &dispose);6.12.y retains the cached-successor iterator:
struct inode *inode, *next;
LIST_HEAD(dispose);
spin_lock(&sb->s_inode_list_lock);
list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
/* ... intervening source omitted ... */
if (need_resched()) {
spin_unlock(&sb->s_inode_list_lock);
cond_resched();
dispose_list(&dispose);
spin_lock(&sb->s_inode_list_lock);
}
list_add(&inode->i_lru, &dispose);I_FREEING protects inode, but the safe iterator's cached next can be
detached or freed while the lock is dropped. The 6.12's invalidate_inodes() differs from upstream's disk-removal trigger.
I think 6.12.y needs the two-line iterator change from 3bc4e4410830d556b0f40dfa6671bfcaeacc1599 ("vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes()") before this backport, thoughts?
thanks,
Harshit
Quoted 41 lines
--- fs/inode.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)fs/inode.c +5
-6@@ -790,7 +790,6 @@ void evict_inodes(struct super_block *sb)struct inode *inode, *next;LIST_HEAD (dispose); -again:spin_lock (&sb->s_inode_list_lock);list_for_each_entry_safe (inode, next, &sb->s_inodes, i_sb_list) {if (atomic_read (&inode->i_count))@@ -809,19 +808,19 @@ void evict_inodes(struct super_block *sb) inode->i_state |=I_FREEING ;inode_lru_list_del (inode);spin_unlock (&inode->i_lock); -list_add (&inode->i_lru, &dispose);/* -* We can have a ton of inodes to evict at unmount time given -* enough memory, check to see if we need to go to sleep for a -* bit so we don't livelock. +* Keep this inode out of dispose so it stays on s_inodes while +* the list lock is dropped. I_FREEING prevents new references +* and leaves eviction to us, so we can resume the walk from it. */ if (need_resched ()) {spin_unlock (&sb->s_inode_list_lock);cond_resched ();dispose_list (&dispose); - goto again; +spin_lock (&sb->s_inode_list_lock); } +list_add (&inode->i_lru, &dispose); }spin_unlock (&sb->s_inode_list_lock);
Greg Kroah-Hartman
maintainerRe: [PATCH 6.12 341/877] fs: avoid repeated scans in evict_inodes()
Quoted 106 lines · Harshit Mogalapalli
Quoted 58 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit
7459c021874246c196f397686e100702f059b9e7]We observed hung tasks when users attempted to unmount a filesystem after its disk had been removed while still in use. During device removal,
fs_bdev_mark_dead()callsevict_inodes()while holdings_umount.Each time
evict_inodes()dropss_inode_list_lockto reschedule, it restarts the walk from the head ofs_inodes. With many referenced inodes at the head of the list, these restarts repeatedly scan the same inodes without reclaiming them. This can keeps_umountheld for a long time, blocking concurrent umount attempts and triggering hung-task reports.Keep the current inode, already marked
I_FREEING, out of the disposal batch untils_inode_list_lockis reacquired. Resume the walk from this inode and dispose of it in a later batch or at the end of the walk.The zero-refcount and state checks under
i_lockallow this walker to claim the inode by settingI_FREEINGand removing it from the LRU. Other reclaimers skip the inode, leaving this walker responsible for eviction. Onlyevict()removes it froms_inodes, so keeping it out of the disposal batch ensures that it remains on the list while the lock is dropped. After reacquiring the lock, reading its current next pointer accounts for concurrent removal of following inodes.The existing inode lifetime rules prohibit acquiring a reference to an inode marked
I_FREEINGorI_WILL_FREE.__iget()requires its caller to holdi_lockand establish that taking a reference is valid. Inode lookup andigrab()check these flags underi_lockwhen acquiring a reference from zero.ihold()requires an existing reference, which would keepi_countnonzero and prevent this walker from claiming the inode. These rules already allowiput_final()and the inode shrinker to releasei_lockafter settingI_FREEINGand before eviction completes.A temporary
__iget()reference would also keep the inode on the list, but its release must preserve last-reference handling. Another user can acquire a reference, update lazy timestamps and drop its reference while the pin is held. If the pin becomes the last reference, dropping it withatomic_dec_and_test()and evicting directly bypasses iput()'s lazytime handling and can lose those timestamp updates.Releasing the pin with
iput()preserves that handling, but does not guarantee eviction.fs_bdev_mark_dead()runs withSB_ACTIVEset, soiput()may retain the inode in cache, whereasevict_inodes()must evict eligible zero-reference inodes. The inode may also have been freed wheniput()returns, so the walker cannot then use it to force eviction. UsingI_FREEINGpreserves the existing eviction behavior without introducing an additional last-reference transition.The xfstests auto group passed on ext4 and XFS with known unrelated failures excluded. No new issues were observed, and the previously reproducible hung task no longer occurs with this patch.
Quoted 6 lines
Fixes ac05fbb40062 ("inode: don't softlockup when evicting inodes")Signed-off-by Julian Sun <[email protected]>Reviewed-by Jan Kara <[email protected]>Signed-off-by Christian Brauner (Amutable) <[email protected]>Signed-off-by Sasha Levin <[email protected]>Hi Greg/Sasha,
An AI assisted backport review flagged this, and I checked the upstream code against the 6.12.y tip
f4ffa8dc360b.Upstream
7459c0218742uses the current inode's successor after relocking:struct inode *inode; LIST_HEAD(dispose); spin_lock(&sb->s_inode_list_lock); list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { /* ... intervening source omitted ... */ if (need_resched()) { spin_unlock(&sb->s_inode_list_lock); cond_resched(); dispose_list(&dispose); spin_lock(&sb->s_inode_list_lock); } list_add(&inode->i_lru, &dispose);6.12.y retains the cached-successor iterator:
struct inode *inode, *next; LIST_HEAD(dispose); spin_lock(&sb->s_inode_list_lock); list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) { /* ... intervening source omitted ... */ if (need_resched()) { spin_unlock(&sb->s_inode_list_lock); cond_resched(); dispose_list(&dispose); spin_lock(&sb->s_inode_list_lock); } list_add(&inode->i_lru, &dispose);
Quoted 8 lines
I_FREEINGprotects inode, but the safe iterator's cached next can be detached or freed while the lock is dropped. The 6.12'sinvalidate_inodes()differs from upstream's disk-removal trigger.I think 6.12.y needs the two-line iterator change from
3bc4e4410830d556b0f40dfa6671bfcaeacc1599("vfs: Remove unnecessarylist_for_each_entry_safe()fromevict_inodes()") before this backport, thoughts?
If it's needed, it needs to be backported here and to older stable kernels, and it needs a manual backport as it doesn't apply cleanly.
thanks,
greg k-h
Re: [PATCH 6.12 341/877] fs: avoid repeated scans in evict_inodes()
Hi Greg,
Quoted 43 lines
Quoted 43 lines
Hi Greg/Sasha,
An AI assisted backport review flagged this, and I checked the upstream code against the 6.12.y tip
f4ffa8dc360b.Upstream
7459c0218742uses the current inode's successor after relocking:struct inode *inode; LIST_HEAD(dispose); spin_lock(&sb->s_inode_list_lock); list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { /* ... intervening source omitted ... */ if (need_resched()) { spin_unlock(&sb->s_inode_list_lock); cond_resched(); dispose_list(&dispose); spin_lock(&sb->s_inode_list_lock); } list_add(&inode->i_lru, &dispose);6.12.y retains the cached-successor iterator:
struct inode *inode, *next; LIST_HEAD(dispose); spin_lock(&sb->s_inode_list_lock); list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) { /* ... intervening source omitted ... */ if (need_resched()) { spin_unlock(&sb->s_inode_list_lock); cond_resched(); dispose_list(&dispose); spin_lock(&sb->s_inode_list_lock); } list_add(&inode->i_lru, &dispose);
I_FREEINGprotects inode, but the safe iterator's cached next can be detached or freed while the lock is dropped. The 6.12'sinvalidate_inodes()differs from upstream's disk-removal trigger.
Quoted 8 lines
Quoted 4 lines
I think 6.12.y needs the two-line iterator change from
3bc4e4410830d556b0f40dfa6671bfcaeacc1599("vfs: Remove unnecessarylist_for_each_entry_safe()fromevict_inodes()") before this backport, thoughts?If it's needed, it needs to be backported here and to older stable kernels, and it needs a manual backport as it doesn't apply cleanly.
Please drop this stable backport.
They retain:
list_for_each_entry_safe(inode, next, &sb->s_inodes,
i_sb_list) {
...
spin_unlock(&sb->s_inode_list_lock);
dispose_list(&dispose);
spin_lock(&sb->s_inode_list_lock);
}The safe iterator cached next before the unlock. A concurrent final iput() can remove and free next while the lock is dropped. The loop then dereferences that freed inode:
inode = next;
next = list_next_entry(next, i_sb_list);I_FREEING protects only inode, not next. This creates a use-after-free risk that can cause a crash or memory corruption.
3bc4e4410830 changes the walk to:
list_for_each_entry(inode, &sb->s_inodes, i_sb_list)
This reads inode's updated successor after relocking. So until we take both the backport and its prereq together I think we better drop this.
thanks,
Harshit
Quoted 4 lines
thanks,
greg k-h
Sasha Levin
maintainerRe: [PATCH 6.12 341/877] fs: avoid repeated scans in evict_inodes()
Quoted 1 line
Please drop this stable backport.
Dropped from the 6.12, 6.6, 6.1, 5.15 and 5.10 queues, thanks.
It stays in 7.2 and 6.18: their bases already have 3bc4e4410830 ("vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes()"), so evict_inodes() there already walks the list with list_for_each_entry().
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 342/877 xsk: Use a 32-bit compare in xsk_map_gen_lookup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 70504de0bb627848667207bec7ccfd647deb8814 ]
xsk_map_gen_lookup() loads a u32 key and compares it with max_entries using BPF_JMP_IMM. BPF immediates are sign-extended to 64 bits, so a max_entries value of 0x80000000 or higher becomes a threshold larger than every zero-extended 32-bit key. An out-of-range index then skips the bounds check and the generated lookup reads past xsk_map[].
Compare with BPF_JMP32_IMM so the check stays in 32-bit unsigned range.
--- net/xdp/xskmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xdp/xskmap.c +1 -1
@@ -124,7 +124,7 @@ static int xsk_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf)struct bpf_insn *insn = insn_buf; *insn++ =BPF_LDX_MEM (BPF_W , ret, index,0 ); - *insn++ =BPF_JMP_IMM (BPF_JGE , ret, map->max_entries,5 ); + *insn++ =BPF_JMP32_IMM (BPF_JGE , ret, map->max_entries,5 ); *insn++ =BPF_ALU64_IMM (BPF_LSH , ret,ilog2 (sizeof (struct xsk_sock *))); *insn++ =BPF_ALU64_IMM (BPF_ADD , mp, offsetof(struct xsk_map , xsk_map)); *insn++ =BPF_ALU64_REG (BPF_ADD , ret, mp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 343/877 bpf: Skip unsettled links in link iterator
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 50e80e2bb5e2be8515205b9c496b9640ddefa434 ]
bpf_link_prime() inserts a link into link_idr before anon_inode_getfile() succeeds and before bpf_link_settle() publishes the ID in link->id. bpf_link_by_id() treats such an ID-zero link as unsettled, but the link iterator takes a reference without this check.
If anon_inode_getfile() then fails, the creator removes the ID and frees its still-private link directly. The iterator is left with a dangling reference and its next bpf_link_put() accesses freed memory.
Treat ID-zero entries as transient in bpf_link_get_curr_or_next(), just as bpf_link_by_id() does.
BUG: KASAN: slab-use-after-free in bpf_link_put Write of size 8 by task exp/384 Call Trace: bpf_link_put kernel/bpf/syscall.c:3372 bpf_link_seq_next kernel/bpf/link_iter.c:33 bpf_seq_read kernel/bpf/bpf_iter.c:158 vfs_read fs/read_write.c:572 ksys_read fs/read_write.c:716 do_syscall_64 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe arch/x86/entry/entry_64.S:121 Kernel panic - not syncing: KASAN: panic_on_warn set ...
--- kernel/bpf/syscall.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +4 -1
@@ -5472,7 +5472,10 @@ struct bpf_link *bpf_link_get_curr_or_next(u32 *id) again: link =idr_get_next (&link_idr, id);if (link) { - link =bpf_link_inc_not_zero (link); +if (link->id) + link =bpf_link_inc_not_zero (link); +else + link =ERR_PTR (-EAGAIN );if (IS_ERR (link)) { (*id)++; goto again;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 344/877 net/sched: cls_u32: fix manual hash table handle IDR aliasing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 0a5f5d9e94dead312d32c366b917c64e552b72f7 ]
A u32 hash table created with an explicit handle ('tc filter add ... handle 801: u32 divisor N') keys its IDR entry on the raw handle, while the destroy paths free it under handle2id(handle). The two key domains disagree for handles in the 0x800..0xFFF htid range:handle2id() folds them back into the auto-allocated id space (1..0x7FF).
A manual table therefore leaves its raw-keyed IDR entry unreachable on delete (a permanent leak), and its delete can drop the idr entry of an unrelated live auto table. A later auto allocation can then hand out a handle that aliases the live manual table; u32_lookup_ht() first-match routes lookups and TCA_U32_LINK for that htid to the wrong table.
Key the divisor-path alloc on handle2id(handle) so allocation and removal share one key domain. A manual handle that maps onto an id already in use is rejected with -ENOSPC, and auto allocation skips ids held by live manual tables.
Conditions to recreate:
ip link add test0 type dummy
tc qdisc add dev test0 clsact
tc filter add dev test0 ingress protocol ip pref 1 \
handle 801: u32 divisor 16 tc filter add dev test0 ingress protocol ip pref 2 u32 divisor 16 tc -d filter show dev test0 ingress | grep 'fh 801:' # unpatched: two live tables with handle 0x80100000 (the pref 2 root # hnode is auto-allocated id 1); patched: the auto hnode takes id 2.
Also tested with a poc with a live u32 table on the block, add/delete a manual table 'handle 901: u32 divisor 1' twice; unpatched, the re-add fails with -ENOSPC because the raw key leaked on the first delete.
--- net/sched/cls_u32.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/sched/cls_u32.c +10 -2
@@ -1000,8 +1000,16 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,return -ENOMEM ; } }else { - err =idr_alloc_u32 (&tp_c->handle_idr, ht, &handle, - handle,GFP_KERNEL ); +/* The IDR is keyed on the mapped id, and that is +* what the destroy paths remove. Ask for it here, +* so a manual handle colliding with the +* auto-allocated id space is rejected (-ENOSPC) +* instead of aliasing a future auto id. +*/ +u32 id =handle2id (handle); + + err =idr_alloc_u32 (&tp_c->handle_idr, ht, &id, id, +GFP_KERNEL );if (err) {kfree (ht);return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 345/877 net/mlx5: devcom, Base component size on linked devices
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit d09e8f64653c93da5793c16be19330968f2a32e6 ]
mlx5_devcom_comp_get_size() returns the component's kref count. That kref is bumped in mlx5_devcom_register_component() under comp_list_lock, before the comp_dev is linked onto comp_dev_list_head under comp->sem. The event broadcast (mlx5_devcom_locked_send_event()) walks that list.
Hence, a caller can read the expected size, but send_event won't be sent to all peers. In the SD group registration path, this lets a member broadcast its role-election event over an incomplete list, electing a primary that never completes the group, is never marked ready, and leaves the group with a stale primary.
Track the number of linked comp_devs in a dedicated counter, maintained under comp->sem together with the list add/remove, and return it from mlx5_devcom_comp_get_size().
--- drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c +4 -1
@@ -29,6 +29,7 @@ struct mlx5_devcom_comp {struct list_head comp_dev_list_head;mlx5_devcom_event_handler_t handler;struct kref ref; +int nr_devs;bool ready;struct rw_semaphore sem;struct lock_class_key lock_key;
@@ -158,6 +159,7 @@ devcom_alloc_comp_dev(struct mlx5_devcom_dev *devc,down_write (&comp->sem);list_add_tail (&devcom->list, &comp->comp_dev_list_head); +WRITE_ONCE (comp->nr_devs, comp->nr_devs +1 );up_write (&comp->sem);return devcom;
@@ -170,6 +172,7 @@ devcom_free_comp_dev(struct mlx5_devcom_comp_dev *devcom)down_write (&comp->sem);list_del (&devcom->list); +WRITE_ONCE (comp->nr_devs, comp->nr_devs -1 );up_write (&comp->sem);kref_put (&devcom->devc->ref, mlx5_devcom_dev_release);
@@ -260,7 +263,7 @@ int mlx5_devcom_comp_get_size(struct mlx5_devcom_comp_dev *devcom) {struct mlx5_devcom_comp *comp = devcom->comp; -return kref_read (&comp->ref); +return READ_ONCE (comp->nr_devs); } int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 346/877 bpf: Restrict CO-RE poisoning to relocatable instructions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit 394ae398337c5f87e567f6cd63b937fc2b2f6ddc ]
CO-RE relocation records can name any instruction offset. When a relocation cannot be resolved, bpf_core_patch_insn() currently poisons its target before checking whether that instruction is a valid relocation target. Malformed metadata can therefore replace jumps, calls, exits, register-source arithmetic, or non-immediate loads instead of failing at the relocation step.
Handle poisoning only after the instruction has passed the same class and operand-form checks used for a resolved relocation. Route invalid forms through the existing diagnostic and return a hard error. Keep poisoning supported instructions, including both halves of a plain ldimm64, so an unresolved relocation in dead code remains valid.
Extend bpf_core_poison_insn() to poison both halves of ldimm64, and return its status directly from each validated instruction case. This avoids routing the success path through a common label and leaves the helper free to report errors.
The shared relocation code applies this restriction to both libbpf and in-kernel CO-RE.
--- tools/lib/bpf/relo_core.c | 58 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 27 deletions(-)
tools/lib/bpf/relo_core.c +31 -27
@@ -965,23 +965,30 @@ static int bpf_core_calc_relo(const char *prog_name, }/* -* Turn instruction for which CO_RE relocation failed into invalid one with +* Turn instruction for which CO-RE relocation failed into invalid one with * distinct signature. */ -static void bpf_core_poison_insn (const char *prog_name,int relo_idx, -int insn_idx,struct bpf_insn *insn) +static int bpf_core_poison_insn (const char *prog_name,int relo_idx, +struct bpf_insn *insn,int insn_idx) { -pr_debug ("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n" , - prog_name, relo_idx, insn_idx); - insn->code =BPF_JMP |BPF_CALL ; - insn->dst_reg =0 ; - insn->src_reg =0 ; - insn->off =0 ; -/* if this instruction is reachable (not a dead code), -* verifier will complain with the following message: -* invalid func unknown#195896080 -*/ - insn->imm =195896080 ;/* => 0xbad2310 => "bad relo" */ +int insn_cnt =is_ldimm64_insn (insn) ?2 :1 ; +int i; + +for (i =0 ; i < insn_cnt; i++) { +pr_debug ("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n" , + prog_name, relo_idx, insn_idx + i); + insn[i].code =BPF_JMP |BPF_CALL ; + insn[i].dst_reg =0 ; + insn[i].src_reg =0 ; + insn[i].off =0 ; +/* +* If this instruction is reachable (not dead code), the verifier +* will complain with "invalid func unknown#195896080". +*/ + insn[i].imm =195896080 ;/* => 0xbad2310 => "bad relo" */ + } + +return 0 ; }static int insn_bpf_size_to_bytes (struct bpf_insn *insn)
@@ -1032,17 +1039,6 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn, class =BPF_CLASS (insn->code); -if (res->poison) { -poison: -/* poison second part of ldimm64 to avoid confusing error from -* verifier about "unknown opcode 00" -*/ -if (is_ldimm64_insn (insn)) -bpf_core_poison_insn (prog_name, relo_idx, insn_idx +1 , insn +1 ); -bpf_core_poison_insn (prog_name, relo_idx, insn_idx, insn); -return 0 ; - } - orig_val = res->orig_val; new_val = res->new_val;
@@ -1050,7 +1046,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,case BPF_ALU :case BPF_ALU64 :if (BPF_SRC (insn->code) !=BPF_K ) -return -EINVAL ; + goto bad_insn; +if (res->poison) +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx);if (res->validate && insn->imm != orig_val) { pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %u, exp %llu -> %llu\n", prog_name, relo_idx,
@@ -1067,6 +1065,8 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,case BPF_LDX :case BPF_ST :case BPF_STX : +if (res->poison) +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx);if (res->validate && insn->off != orig_val) { pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %u, exp %llu -> %llu\n", prog_name, relo_idx, insn_idx, insn->off, (unsigned long long)orig_val,
@@ -1082,7 +1082,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,pr_warn ("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. " "Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\n" , prog_name, relo_idx, insn_idx); - goto poison; +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx); } orig_val = insn->off;
@@ -1125,6 +1125,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,return -EINVAL ; } +if (res->poison) +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx); + imm = (__u32 )insn[0 ].imm | ((__u64 )insn[1 ].imm <<32 );if (res->validate && imm != orig_val) { pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %llu -> %llu\n",
@@ -1142,6 +1145,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,break ; }default : +bad_insn:pr_warn ("prog '%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, dst:0x%x, off:0x%x, imm:0x%x\n" , prog_name, relo_idx, insn_idx, insn->code, insn->src_reg, insn->dst_reg, insn->off, insn->imm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 347/877 libbpf: Reject truncated ldimm64 CO-RE relocations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit b4e875d397da451fb4e9c573ff4b86db53caba05 ]
CO-RE relocation of an ldimm64 instruction operates on two instruction slots. A malformed BPF ELF can end a function after the first slot and attach a CO-RE relocation to it. libbpf allocates the instruction array according to the function symbol size, so the shared relocation code would then access beyond the allocation.
Reject a terminal ldimm64 in libbpf's relocation loop, where the program length is available, before resolving or applying the relocation. Both resolved and unresolved relocations validate the absent second slot, and unresolved relocation poisoning would additionally write past the array.
The in-kernel caller is protected by the verifier's early instruction-stream check before it applies CO-RE relocations.
--- tools/lib/bpf/libbpf.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/lib/bpf/libbpf.c +7 -0
@@ -5983,6 +5983,13 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)return -EINVAL ; insn = &prog->insns[insn_idx]; +if (is_ldimm64_insn (insn) && (size_t )insn_idx +1 >= prog->insns_cnt) { +pr_warn ("prog '%s': relo #%d: insn #%d (LDIMM64) is truncated\n" , + prog->name, i, insn_idx); + err = -EINVAL ; + goto out; + } + err =record_relo_core (prog, rec, insn_idx);if (err) { pr_warn("prog '%s': relo #%d: failed to record relocation: %d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 348/877 netfilter: flowtable: publish HW_DEAD after worker is done
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit d644b23afe1ef509c9961a6d84a093c2587edf02 ]
flow_offload_work_del() sets NF_FLOW_HW_DEAD before the work handler clears NF_FLOW_HW_PENDING. Once a flow is both HW_DYING and HW_DEAD, a concurrent garbage collection pass can remove it and schedule it for RCU freeing.
The offload worker holds neither an RCU read lock nor a reference to the flow. If it is preempted after publishing HW_DEAD, the RCU callback can free the flow before the worker resumes and clears HW_PENDING, resulting in a use-after-free.
Move HW_DEAD publication to the common worker epilogue after the pending bit is cleared, making it the final flow access by destroy work. Order all preceding flow accesses before publishing the bit that allows garbage collection to free the object.
--- net/netfilter/nf_flow_table_offload.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_offload.c +6 -1
@@ -993,7 +993,6 @@ static void flow_offload_work_del(struct flow_offload_work *offload)flow_offload_tuple_del (offload,FLOW_OFFLOAD_DIR_ORIGINAL );if (test_bit (NF_FLOW_HW_BIDIRECTIONAL , &offload->flow->flags))flow_offload_tuple_del (offload,FLOW_OFFLOAD_DIR_REPLY ); -set_bit (NF_FLOW_HW_DEAD , &offload->flow->flags); } static void flow_offload_tuple_stats(struct flow_offload_work *offload,
@@ -1057,6 +1056,12 @@ static void flow_offload_work_handler(struct work_struct *work) }clear_bit (NF_FLOW_HW_PENDING , &offload->flow->flags); +if (offload->cmd ==FLOW_CLS_DESTROY ) { +/* Publish after the worker's last flow access. */ +smp_mb__before_atomic (); +set_bit (NF_FLOW_HW_DEAD , &offload->flow->flags); + } +kfree (offload); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 349/877 netfilter: nfnetlink_queue: hold nfnl mutex in event notifier
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 9461613afc59acef44a0071b0dd5075f6e993ffe ]
We must serialize the release notifier and the config netlink function. A concurrent thread can issue close() which can call the release function while unrelated socket processes UNBIND request for same portid:
Oops: general protection fault, [..] RIP: 0010:__instance_destroy+0x60/0x210 [nfnetlink_queue] Call Trace: nfqnl_recv_config+0x9b0/0xdc0 [nfnetlink_queue] nfnetlink_rcv_msg+0x7c2/0xeb0 ? __pfx_nfnetlink_rcv_msg+0x10/0x10
After this, parallel UNBIND and URELEASE events are impossible.
This change isn't nice, but its the shortest fix given instances are not refcounted and the nfnetlink config callback drops the rcu read lock early due to need for sleeping allocations.
--- net/netfilter/nfnetlink_queue.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_queue.c +5 -3
@@ -1338,6 +1338,7 @@ nfqnl_rcv_nl_event(struct notifier_block *this,if (event ==NETLINK_URELEASE && n->protocol ==NETLINK_NETFILTER ) {int i; +nfnl_lock (NFNL_SUBSYS_QUEUE );/* destroy all instances for this portid */ spin_lock (&q->instances_lock);for (i =0 ; i <INSTANCE_BUCKETS ; i++) {
@@ -1351,6 +1352,7 @@ nfqnl_rcv_nl_event(struct notifier_block *this, } }spin_unlock (&q->instances_lock); +nfnl_unlock (NFNL_SUBSYS_QUEUE ); }return NOTIFY_DONE ; }
@@ -1672,9 +1674,9 @@ static int nfqnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,/* Lookup queue under RCU. After peer_portid check (or for new queue * in BIND case), the queue is owned by the socket sending this message. -* A socket cannot simultaneously send a message and close, so while -* processing this CONFIG message, nfqnl_rcv_nl_event() (triggered by -* socket close) cannot destroy this queue. Safe to use without RCU. +* nfqnl_rcv_nl_event() will block on the nfnl subsys mutex that is +* held by the caller, so the queue cannot be destroyed in parallel, +* even after we drop the RCU read lock. */ rcu_read_lock (); queue =instance_lookup (q, queue_num);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 350/877 netfilter: nft_synproxy: use the family-aware checksum helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit a311a898172743558b82f6035ef2aa8c310a4223 ]
nft_synproxy_do_eval() verifies the TCP checksum before it switches on skb->protocol. It uses nf_ip_checksum(), which constructs an IPv4 pseudo header and relies on the IPv4 header checksum when folding the whole skb. Neither operation is valid for an IPv6 packet.
A correctly checksummed IPv6 segment can therefore fail verification when it reaches the hook as CHECKSUM_NONE or, at NF_INET_LOCAL_IN, CHECKSUM_COMPLETE. nft_synproxy_do_eval() returns NF_DROP before nft_synproxy_eval_v6() can send a SYN-ACK.
nft_synproxy_validate() deliberately admits NFPROTO_IPV6 and NFPROTO_INET, and the xtables counterpart ip6t_SYNPROXY.c already calls nf_ip6_checksum().
Use nf_checksum() with nft_pf() so the checksum helper dispatches to the packet family's implementation.
--- net/netfilter/nft_synproxy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_synproxy.c +2 -1
@@ -117,7 +117,8 @@ static void nft_synproxy_do_eval(const struct nft_synproxy *priv,return ; } -if (nf_ip_checksum (skb,nft_hook (pkt), thoff,IPPROTO_TCP )) { +if (nf_checksum (skb,nft_hook (pkt), thoff,IPPROTO_TCP , +nft_pf (pkt))) { regs->verdict.code =NF_DROP ;return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 351/877 ipvs: revalidate ihl before icmp_send
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
[ Upstream commit e290145564886d6a3038810c621f738c1fe9fa51 ]
While the outer IP header is already pulled into the skb head, we must be careful and revalidate the embedded headers after reading them from the skb frags to prevent possible out-of-bounds access.
One such place reported by Sashiko is ip_vs_in_icmp() where local process can change the ihl field and after pskb_may_pull() we can see larger value. Even if icmp_send() has checks to prevent out-of-bounds access, play safe and add check to drop the packet if the ihl field is changed. As the outer headers are pulled, make sure the transport header is updated too, it was used before commit 7fcc2fe39fed ("net:
icmp: avoid invalid transport header access in icmp_send tracepoint")
--- net/netfilter/ipvs/ip_vs_core.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/ipvs/ip_vs_core.c +6 -0
@@ -1776,6 +1776,12 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,/* Ensure the IP header is present in headroom */ if (!pskb_may_pull (skb, hlen_orig)) goto ignore_tunnel; +skb_set_transport_header (skb, hlen_orig); +/* Before now we may used ihl from skb frag, revalidate it after +* copying it into skb head to prevent out-of-bounds access +*/ +if (ip_hdr (skb)->ihl *4 != hlen_orig) + goto ignore_tunnel;IP_VS_DBG (12 ,"Sending ICMP for %pI4->%pI4: t=%u, c=%u, i=%u\n" , &ip_hdr (skb)->saddr, &ip_hdr (skb)->daddr, type, code,ntohl (info));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 352/877 netfilter: ctnetlink: fix suspicious RCU usage in expect_iter_name
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naman Gulati <[email protected]>
[ Upstream commit 207d591c353201f3bd3e0c89bb7d44a849c8fd59 ]
expect_iter_name() is invoked by nf_ct_expect_iterate_net() under spin_lock_bh(&nf_conntrack_expect_lock). It does not hold rcu_read_lock().
When accessing exp->helper with rcu_dereference() in syzbot's report, lockdep warns:
=============================
WARNING: suspicious RCU usage
syzkaller #0 Not tainted
-----------------------------
net/netfilter/nf_conntrack_netlink.c:3393 suspicious rcu_dereference_check() usage!
locks held by syz-executor381/5628: 2, last CPU#1:
#0: ffffffff9aee42a0 (nfnl_subsys_ctnetlink_exp){+.+.}-{4:4},
at: nfnetlink_rcv_msg+0xa69/0x12b0
#1: ffffffff8ea74d58 (nf_conntrack_expect_lock){+...}-{3:3},
at: nf_ct_expect_iterate_net+0x38/0x180Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lockdep_rcu_suspicious+0x140/0x1d0 expect_iter_name+0xfb/0x100 nf_ct_expect_iterate_net+0xf2/0x180 ctnetlink_del_expect+0x45d/0x640 nfnetlink_rcv_msg+0xcc2/0x12b0 netlink_rcv_skb+0x226/0x4a0 nfnetlink_rcv+0x2b9/0x28c0 netlink_unicast+0x7bd/0x940 netlink_sendmsg+0x813/0xb40 ____sys_sendmsg+0x54e/0x850 ___sys_sendmsg+0x2a5/0x360 __sys_sendmsg+0x2a5/0x360 do_syscall_64+0x166/0x520 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Use rcu_dereference_protected() with lockdep_is_held() on nf_conntrack_expect_lock instead, similar to expect_iter_me() in nf_conntrack_helper.c.
--- net/netfilter/nf_conntrack_netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +2 -1
@@ -3390,7 +3390,8 @@ static bool expect_iter_name(struct nf_conntrack_expect *exp, void *data)struct nf_conntrack_helper *helper;const char *name = data; - helper =rcu_dereference (exp->helper); + helper =rcu_dereference_protected (exp->helper, +lockdep_is_held (&nf_conntrack_expect_lock));if (!helper)return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 353/877 arm64: io: Reject non-user protection in ioremap_prot()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zeng Heng <[email protected]>
[ Upstream commit bb756b11ad63832ebee58caf9e8f9381eaecff9f ]
Mapping a stack-top page via /dev/mem with PROT_NONE and then reading that process's /proc/<pid>/cmdline triggers a spurious WARN in ioremap_prot() through generic_access_phys():
WARNING: ./arch/arm64/include/asm/io.h:275 at generic_access_phys
Call trace:
generic_access_phys+0x1c8/0x228 (P)
__access_remote_vm+0x2b4/0x398
access_remote_vm+0x14/0x30
get_mm_cmdline+0xf8/0x2a0
proc_pid_cmdline_read+0x68/0x120generic_access_phys() passes the protection derived from the user PTE to ioremap_prot(). On arm64, a PROT_NONE mapping is represented by a present-invalid PTE, so pte_present() still returns true and the protection reaches ioremap_prot().
A PROT_NONE mapping does not have PTE_USER, causing the existing WARN_ON_ONCE() in ioremap_prot() to fire even though this is a valid user mapping. Execute-only mappings have the same issue and must not be readable through this path either.
ioremap_prot() should therefore reject protection values without PTE_USER without warning. This makes the access fail cleanly for PROT_NONE and execute-only mappings while retaining the existing user-protection contract.
--- arch/arm64/include/asm/io.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/include/asm/io.h +2 -1
@@ -282,7 +282,8 @@ static inline void __iomem *ioremap_prot(phys_addr_t phys, size_t size,pgprot_t prot;pteval_t user_prot_val =pgprot_val (__pgprot (user_prot)); -if (WARN_ON_ONCE (!(user_prot_val &PTE_USER ))) +/* Reject PROT_NONE and exec-only */ +if (!(user_prot_val &PTE_USER ))return NULL ; prot = __pgprot_modify(PAGE_KERNEL, PTE_ATTRINDX_MASK,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 354/877 ocfs2: make ocfs2_calc_xattr_init() return void
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 525c0edc032b3297d0c1056cf1fa20cf1f9e6184 ]
ocfs2_calc_xattr_init() used to read the default ACL off the parent inode itself, so it could return an error from ocfs2_xattr_get_nolock(). Commit bd7c05fb4a47 ("ocfs2: fix circular locking dependency in ocfs2_init_acl()") moved that lookup before the transaction starts and deleted the error path, but left the now vestigial 'int ret = 0' declaration and both 'return ret' statements behind, along with an unreachable error branch in ocfs2_mknod().
Drop the leftover variable and convert the return type to void, so the callee states that it always succeeds and the caller no longer carries a check that can never trigger.
No functional change.
--- fs/ocfs2/namei.c | 9 ++------- fs/ocfs2/xattr.c | 13 +++++-------- fs/ocfs2/xattr.h | 8 ++++---- 3 files changed, 11 insertions(+), 19 deletions(-)
fs/ocfs2/namei.c +2 -7
@@ -332,13 +332,8 @@ static int ocfs2_mknod(struct mnt_idmap *idmap, goto leave;/* calculate meta data/clusters for setting security and acl xattr */ - status =ocfs2_calc_xattr_init (dir, mode, &si, &want_clusters, - &xattr_credits, &want_meta, - &acl_state); -if (status <0 ) { -mlog_errno (status); - goto leave; - } +ocfs2_calc_xattr_init (dir, mode, &si, &want_clusters, &xattr_credits, + &want_meta, &acl_state);/* Reserve a cluster if creating an extent based directory. */ if (S_ISDIR (mode) && !ocfs2_supports_inline_data (osb)) {
fs/ocfs2/xattr.c +5 -8
@@ -607,12 +607,11 @@ int ocfs2_calc_security_init(struct inode *dir,return ret; } -int ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, -struct ocfs2_security_xattr_info *si, -int *want_clusters,int *xattr_credits, -int *want_meta,struct ocfs2_acl_state *acl_state) +void ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, +struct ocfs2_security_xattr_info *si, +int *want_clusters,int *xattr_credits, +int *want_meta,struct ocfs2_acl_state *acl_state) { -int ret =0 ;struct ocfs2_super *osb =OCFS2_SB (dir->i_sb);int s_size =0 , a_size =0 , acl_len =0 , new_clusters;
@@ -634,7 +633,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, }if (!(s_size + a_size)) -return ret; +return ;/* * The max space of security xattr taken inline is
@@ -700,8 +699,6 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, } } } - -return ret; } static int ocfs2_xattr_extend_allocation(struct inode *inode,
fs/ocfs2/xattr.h +4 -4
@@ -57,10 +57,10 @@ int ocfs2_calc_security_init(struct inode *, int *, int *, struct ocfs2_alloc_context **);struct ocfs2_acl_state ; -int ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, -struct ocfs2_security_xattr_info *si, -int *want_clusters,int *xattr_credits, -int *want_meta,struct ocfs2_acl_state *acl_state); +void ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, +struct ocfs2_security_xattr_info *si, +int *want_clusters,int *xattr_credits, +int *want_meta,struct ocfs2_acl_state *acl_state);/* * xattrs can live inside an inode, as part of an external xattr block,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 355/877 drm/nouveau/clk: fix list cursor use after loop in nvkm_clk_ustate_update
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit aff09d9e37e02dc60bde79035ac15b136d602259 ]
If list_for_each_entry() exits without hitting a break then "pstate" is not a valid pstate pointer. Introduce a "found" variable instead.
The check is reachable from userspace: nvkm_clk_ustate_update() takes the pstate id straight from the 'pstate' debugfs file, so requesting an id that is not in clk->states - or any id at all when the perf tables are broken and the list is empty - makes the pstate->pstate != req test dereference the list head cast to a struct nvkm_pstate, which is an out-of-bounds read.
--- drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c +5 -2
@@ -473,6 +473,7 @@ static int nvkm_clk_ustate_update(struct nvkm_clk *clk, int req) {struct nvkm_pstate *pstate; +bool found = false;int i =0 ;if (!clk->allow_reclock)
@@ -480,12 +481,14 @@ nvkm_clk_ustate_update(struct nvkm_clk *clk, int req)if (req !=-1 && req !=-2 ) {list_for_each_entry (pstate, &clk->states, head) { -if (pstate->pstate == req) +if (pstate->pstate == req) { + found = true;break ; + } i++; } -if (pstate->pstate != req) +if (!found)return -EINVAL ; req = i; }
Signature · 1 line
2.53.0