6.18.40-rc1 review
Subsystems (13)
Greg Kroah-Hartman
maintainerPATCH 1257/1611 mm/mm_init: fix uninitialized struct pages for ZONE_DEVICE
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit cd681403a87085562499d60325b7b45d3be11217 upstream.
If DAX memory is hotplugged into an unoccupied subsection of an early section, section_activate() reuses the unoptimized boot memmap. However, compound_nr_pages() still assumes that vmemmap optimization is in effect and initializes only the reduced number of struct pages. As a result, the remaining tail struct pages are left uninitialized, which can later lead to unexpected behavior or crashes.
Fix this by treating early sections as unoptimized when calculating how many struct pages to initialize.
--- mm/mm_init.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
mm/mm_init.c +10 -3
@@ -1072,10 +1072,17 @@ static void __ref __init_zone_device_pag* of how the sparse_vmemmap internals handle compound pages in the lack * of an altmap. See vmemmap_populate_compound_pages(). */ -static inline unsigned long compound_nr_pages (struct vmem_altmap *altmap, +static inline unsigned long compound_nr_pages (unsigned long pfn, +struct vmem_altmap *altmap,struct dev_pagemap *pgmap) { -if (!vmemmap_can_optimize (altmap, pgmap)) +/* +* If DAX memory is hot-plugged into an unoccupied subsection +* of an early section, the unoptimized boot memmap is reused. +* See section_activate(). +*/ +if (early_section (__pfn_to_section (pfn)) || + !vmemmap_can_optimize (altmap, pgmap))return pgmap_vmemmap_nr (pgmap);return VMEMMAP_RESERVE_NR * (PAGE_SIZE /sizeof (struct page ));
@@ -1145,7 +1152,7 @@ void __ref memmap_init_zone_device(struccontinue ;memmap_init_compound (page, pfn, zone_idx, nid, pgmap, -compound_nr_pages (altmap, pgmap)); +compound_nr_pages (pfn, altmap, pgmap)); }pageblock_migratetype_init_range (start_pfn, nr_pages,MIGRATE_MOVABLE );
Greg Kroah-Hartman
maintainerPATCH 1258/1611 kcov: use WRITE_ONCE() for selftest mode stores
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 9a79524d1420e6b79a6868208c264f4518d1318e upstream.
The KCOV selftest enables coverage by setting current->kcov_mode to KCOV_MODE_TRACE_PC without installing a coverage area. If an interrupt records coverage in that window, the access should fault and expose the bug.
When building for QEMU raspi0 (Raspberry Pi Zero, ARMv6, CONFIG_CPU_V6K=y, CONFIG_CURRENT_POINTER_IN_TPIDRURO=y) with GCC 13.3.0, the store that enables the mode is removed. The generated kcov_init() code only stores zero after the wait loop:
mrc 15, 0, r3, cr13, cr0, {3}
str r4, [r3, #2028]
where r4 is zero. There is no store of KCOV_MODE_TRACE_PC before the loop, so the selftest reports success without exercising coverage.
Use WRITE_ONCE() for the temporary mode stores. With the same compiler and config, kcov_init() contains the intended mode store:
mov r3, #2
mrc 15, 0, r2, cr13, cr0, {3}
str r3, [r2, #2028]
Now that the KCOV selftest is actually executed, it may expose KCOV instrumentation issues depending on the kernel config. That is expected for a selftest that was intended to catch coverage from interrupt paths.
--- kernel/kcov.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcov.c +2 -2
@@ -1095,10 +1095,10 @@ static void __init selftest(void)* potentially traced functions in this region. */ start = jiffies; - current->kcov_mode =KCOV_MODE_TRACE_PC ; +WRITE_ONCE (current->kcov_mode,KCOV_MODE_TRACE_PC );while ((jiffies - start) *MSEC_PER_SEC /HZ <300 ) ; - current->kcov_mode =0 ; +WRITE_ONCE (current->kcov_mode,0 ); pr_err("done running self test\n"); }#endif
Greg Kroah-Hartman
maintainerPATCH 1259/1611 mtd: slram: remove failed entries from the device list
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
commit 36f1648644d769c496a8e47e53603e863e358d73 upstream.
register_device() links a new slram_mtdlist entry before allocating all of the state needed by the entry. If a later allocation, memremap(), or mtd_device_register() fails, the partially initialized entry remains on the global list. A later cleanup can then dereference or free invalid state from that failed entry.
Unwind the partially initialized entry and clear the list tail on each failure path after the entry has been linked.
--- drivers/mtd/devices/slram.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/mtd/devices/slram.c +16 -6
@@ -129,6 +129,7 @@ static int slram_write(struct mtd_info *static int register_device (char *name,unsigned long start,unsigned long length) {slram_mtd_list_t **curmtd; +int ret = -ENOMEM ; curmtd = &slram_mtdlist;while (*curmtd) {
@@ -155,14 +156,15 @@ static int register_device(char *name, uif (!(*curmtd)->mtdinfo) {E ("slram: Cannot allocate new MTD device.\n" ); -return (-ENOMEM ); + goto err_free_list; }if (!(((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start =memremap (start, length,MEMREMAP_WB |MEMREMAP_WT |MEMREMAP_WC ))) {E ("slram: memremap failed\n" ); -return -EIO ; + ret = -EIO ; + goto err_free_priv; } ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end = ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start + length;
@@ -183,10 +185,8 @@ static int register_device(char *name, uif (mtd_device_register ((*curmtd)->mtdinfo,NULL ,0 )) {E ("slram: Failed to register new device\n" ); -memunmap (((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start); -kfree ((*curmtd)->mtdinfo->priv); -kfree ((*curmtd)->mtdinfo); -return (-EAGAIN ); + ret = -EAGAIN ; + goto err_unmap; }T ("slram: Registered device %s from %luKiB to %luKiB\n" , name, (start /1024 ), ((start + length) /1024 ));
@@ -194,6 +194,16 @@ static int register_device(char *name, u ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start, ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end);return (0 ); + +err_unmap: +memunmap (((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start); +err_free_priv: +kfree ((*curmtd)->mtdinfo->priv); +err_free_list: +kfree ((*curmtd)->mtdinfo); +kfree (*curmtd); + *curmtd =NULL ; +return ret; }static void unregister_devices (void )
Greg Kroah-Hartman
maintainerPATCH 1260/1611 9p: skip nlink update in cacheless mode to fix WARN_ON
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
commit 574aa0b4799470ac814479f1138d19efe6262255 upstream.
v9fs_dec_count() unconditionally calls drop_nlink() on regular files, even when the inode's nlink is already zero. In cacheless mode the client refetches inode metadata from the server (the source of truth) on every operation, so by the time v9fs_remove() returns, the locally cached nlink may already reflect the post-unlink value:
1. Client initiates unlink, server processes it and sets nlink to 0
2. Client refetches inode metadata (nlink=0) before unlink returns
3. Client's v9fs_remove() completes successfully
4. Client calls v9fs_dec_count() which calls drop_nlink() on nlink=0
This race is easily triggered under heavy unlink workloads, such as stress-ng's unlink stressor, producing the following warning:
WARNING: fs/inode.c:417 at drop_nlink+0x4c/0xc8 Call trace: drop_nlink+0x4c/0xc8 v9fs_remove+0x1e0/0x250 [9p] v9fs_vfs_unlink+0x20/0x38 [9p] vfs_unlink+0x13c/0x258 ...
In cacheless mode the server is authoritative and the inode is on its way out, so locally adjusting nlink buys nothing. Skip v9fs_dec_count() entirely when neither CACHE_META nor CACHE_LOOSE is set, which both avoids the warning and removes a class of nlink races (two concurrent unlinkers observing nlink > 0 and both calling drop_nlink()) that an nlink == 0 guard alone would only narrow rather than close.
Message-ID: <[email protected]>
--- fs/9p/vfs_inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/9p/vfs_inode.c +9 -0
@@ -488,10 +488,19 @@ static int v9fs_at_to_dotl_flags(int fla* - ext4 (with dir_nlink feature enabled) sets nlink to 1 if a dir has more * than EXT4_LINK_MAX (65000) links. * +* In cacheless mode the server is the source of truth for nlink and the +* inode is going away immediately, so locally adjusting i_nlink buys +* nothing and races with concurrent metadata fetches that may already +* have observed the post-unlink value (nlink == 0). +* * @inode: inode whose nlink is being dropped */ static void v9fs_dec_count (struct inode *inode) { +struct v9fs_session_info *v9ses =v9fs_inode2v9ses (inode); + +if (!(v9ses->cache & (CACHE_META |CACHE_LOOSE ))) +return ;if (!S_ISDIR (inode->i_mode) || inode->i_nlink >2 )drop_nlink (inode); }
Greg Kroah-Hartman
maintainerPATCH 1261/1611 power: supply: bq257xx: Fix VSYSMIN clamping logic
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
commit b6c6b9260a92dacef6edef8e93bc2767b86b1dfe upstream.
The minimal system voltage (VSYSMIN) is meant to protect the battery from dangerous over-discharge. When the device tree provides a value for the minimum design voltage of the battery, the user should not be allowed to set a lower VSYSMIN, as that would defeat the purpose of this protection.
Flip the clamping logic when setting VSYSMIN to ensure that battery design voltage is respected.
--- drivers/power/supply/bq257xx_charger.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/power/supply/bq257xx_charger.c +3 -4
@@ -128,9 +128,8 @@ static int bq25703_get_min_vsys(struct b* @vsys: voltage value to set in uV. * * This function takes a requested minimum system voltage value, clamps -* it between the minimum supported value by the charger and a user -* defined minimum system value, and then writes the value to the -* appropriate register. +* it between the user defined minimum system value and the maximum supported +* value by the charger, and then writes the value to the appropriate register. * * Return: Returns 0 on success or error if an error occurs. */
@@ -139,7 +138,7 @@ static int bq25703_set_min_vsys(struct bunsigned int reg;int vsys_min = pdata->vsys_min; - vsys =clamp (vsys,BQ25703_MINVSYS_MIN_UV , vsys_min); + vsys =clamp (vsys, vsys_min,BQ25703_MINVSYS_MAX_UV ); reg = ((vsys -BQ25703_MINVSYS_MIN_UV ) /BQ25703_MINVSYS_STEP_UV ); reg =FIELD_PREP (BQ25703_MINVSYS_MASK , reg);
Greg Kroah-Hartman
maintainerPATCH 1262/1611 scsi: smartpqi: Use shost_to_hba() in pqi_scan_finished()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Wilck <[email protected]>
commit 57db1307afb1f83d45f5ff53b93f8d040100d13e upstream.
shost_to_hba() is used everywhere except to obtain pqi_ctrl_info from shosti, except in pqi_scan_finished(), where shost_priv() is used. This causes one pointer dereference to be missed, as shost->hostdata is a pointer in smartpqi. Fix it.
--- drivers/scsi/smartpqi/smartpqi_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +1 -1
@@ -2644,7 +2644,7 @@ static int pqi_scan_finished(struct Scsi {struct pqi_ctrl_info *ctrl_info; - ctrl_info =shost_priv (shost); + ctrl_info =shost_to_hba (shost);return !mutex_is_locked (&ctrl_info->scan_mutex); }
Greg Kroah-Hartman
maintainerPATCH 1263/1611 scsi: sas: Skip opt_sectors when DMA reports no real optimization hint
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ionut Nechita <[email protected]>
commit be8fcd4a8217a916344c88a4b1b84f5736dda17e upstream.
sas_host_setup() unconditionally sets shost->opt_sectors from dma_opt_mapping_size().
When the IOMMU is disabled or in passthrough mode and no DMA ops provide an opt_mapping_size callback, dma_opt_mapping_size() returns min(dma_max_mapping_size(), SIZE_MAX) which equals dma_max_mapping_size() — a hard upper bound, not an optimization hint.
On a Dell PowerEdge R750 with mpt3sas (Broadcom SAS3816, FW 33.15.00.00) and intel_iommu=off the following values are observed:
dma_opt_mapping_size() = dma_max_mapping_size() (no real hint)
shost->max_sectors = 32767
opt_sectors = min(32767, huge >> 9) = 32767
optimal_io_size = 32767 << 9 = 16776704
→ round_down(16776704, 4096) = 16773120The SAS disk (SAMSUNG MZILT800HBHQ0D3) does not report an Optimal Transfer Length in VPD page B0, so sdkp->opt_xfer_blocks remains 0.
sd_revalidate_disk() then uses min_not_zero(0, opt_sectors) = opt_sectors, propagating the bogus value into the block device's optimal_io_size (visible as OPT-IO = 16773120 in lsblk --topology).
mkfs.xfs picks up optimal_io_size and minimum_io_size and computes:
swidth = 16773120 / 4096 = 4095
sunit = 8192 / 4096 = 2
Since 4095 % 2 != 0, XFS rejects the geometry:
SB stripe unit sanity check failed
This makes it impossible to create XFS filesystems (e.g. for /var/lib/docker) during system bootstrap.
Fix this by introducing a sas_dma_setup_opt_sectors() helper that sets opt_sectors only when dma_opt_mapping_size() is strictly less than dma_max_mapping_size(), indicating a genuine DMA optimization constraint.
The helper computes min(opt_sectors, max_sectors) first, then rounds down to a power of two so that filesystem geometry calculations always produce clean results.
When the two DMA values are equal, no backend provided a real hint, so opt_sectors stays at 0 ("no preference").
[mkp: implemented hch's suggestion]
--- drivers/scsi/scsi_transport_sas.c | 41 +++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-)
drivers/scsi/scsi_transport_sas.c +36 -5
@@ -27,6 +27,7 @@#include <linux/module.h> #include <linux/jiffies.h> #include <linux/err.h> +#include <linux/log2.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/blkdev.h>
@@ -220,12 +221,45 @@ static int sas_bsg_initialize(struct Scs* SAS host attributes */ +/* +* Set shost->opt_sectors from the DMA optimal mapping size, but only +* when dma_opt_mapping_size() is strictly less than dma_max_mapping_size(), +* indicating a genuine optimization hint from an IOMMU or DMA backend. +* When the two are equal (e.g. IOMMU disabled / passthrough), no real +* hint exists, so leave opt_sectors at 0 to avoid bogus optimal_io_size +* values that break filesystem geometry (e.g. mkfs.xfs stripe alignment). +*/ +static void sas_dma_setup_opt_sectors (struct Scsi_Host *shost) +{ +struct device *dma_dev = shost->dma_dev; +size_t opt =dma_opt_mapping_size (dma_dev); +size_t max =dma_max_mapping_size (dma_dev); +unsigned int opt_sectors; + +/* opt >= max means no real hint was provided by the DMA layer */ +if (opt >= max) +return ; + +/* Clamp to max_sectors to avoid overflow in sector arithmetic */ + opt_sectors = min_t(unsigned int, opt >> SECTOR_SHIFT, + shost->max_sectors); + +/* Guard against zero before rounddown_pow_of_two() */ +if (!opt_sectors) +return ; + +/* +* Round down to power-of-two so filesystem geometry calculations +* (e.g. XFS stripe width/unit) always produce clean divisors. +*/ + shost->opt_sectors =rounddown_pow_of_two (opt_sectors); +} +static int sas_host_setup (struct transport_container *tc,struct device *dev,struct device *cdev) {struct Scsi_Host *shost =dev_to_shost (dev);struct sas_host_attrs *sas_host =to_sas_host_attrs (shost); -struct device *dma_dev = shost->dma_dev;INIT_LIST_HEAD (&sas_host->rphy_list);mutex_init (&sas_host->lock);
@@ -237,10 +271,7 @@ static int sas_host_setup(struct transpodev_printk (KERN_ERR , dev,"fail to a bsg device %d\n" , shost->host_no); -if (dma_dev->dma_mask) { - shost->opt_sectors = min_t(unsigned int, shost->max_sectors, -dma_opt_mapping_size (dma_dev) >>SECTOR_SHIFT ); - } +sas_dma_setup_opt_sectors (shost);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1264/1611 openrisc: Add full instruction cache invalidate functions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stafford Horne <[email protected]>
commit 1be031de802ba486a7605b52eda825f128b026e2 upstream.
Add functions to invalidate all cache lines which we will use for static_key patching.
On OpenRISC there is no instruction to invalidate an entire cache so we loop and invalidate cache lines one by one. This is not extremely expensive on OpenRISC as we usually have only a few hundred cache lines.
I considered using the invalidate cache page or range functions. However, tracking which ranges need invalidation would have been more expensive than flushing all pages.
--- arch/openrisc/include/asm/cacheflush.h | 4 ++++ arch/openrisc/kernel/smp.c | 21 +++++++++++++++++++++ arch/openrisc/mm/cache.c | 16 ++++++++++++++++ 3 files changed, 41 insertions(+)
arch/openrisc/include/asm/cacheflush.h +4 -0
@@ -26,6 +26,7 @@ extern void local_icache_page_inv(structextern void local_dcache_range_flush (unsigned long start,unsigned long end);extern void local_dcache_range_inv (unsigned long start,unsigned long end);extern void local_icache_range_inv (unsigned long start,unsigned long end); +extern void local_icache_all_inv (void );/* * Data cache flushing always happen on the local cpu. Instruction cache
@@ -35,10 +36,13 @@ extern void local_icache_range_inv(unsig#ifndef CONFIG_SMP #define dcache_page_flush (page) local_dcache_page_flush(page)#define icache_page_inv (page) local_icache_page_inv(page) +#define icache_all_inv () local_icache_all_inv()#else /* CONFIG_SMP */ #define dcache_page_flush (page) local_dcache_page_flush(page)#define icache_page_inv (page) smp_icache_page_inv(page) +#define icache_all_inv () smp_icache_all_inv()extern void smp_icache_page_inv (struct page *page); +extern void smp_icache_all_inv (void );#endif /* CONFIG_SMP */ /*
arch/openrisc/kernel/smp.c +21 -0
@@ -326,3 +326,24 @@ void smp_icache_page_inv(struct page *paon_each_cpu (ipi_icache_page_inv, page,1 ); }EXPORT_SYMBOL (smp_icache_page_inv); + +static void ipi_icache_all_inv (void *arg) +{ +local_icache_all_inv (); +} + +void smp_icache_all_inv (void ) +{ +if (num_online_cpus () <2 ) { +local_icache_all_inv (); +return ; + } + +/* +* Ensure stores complete before we request remote icaches +* to invalidate. +*/ +mb (); + +on_each_cpu (ipi_icache_all_inv,NULL ,1 ); +}
arch/openrisc/mm/cache.c +16 -0
@@ -63,6 +63,22 @@ void local_icache_page_inv(struct page * }EXPORT_SYMBOL (local_icache_page_inv); +void local_icache_all_inv (void ) +{ +if (cpu_cache_is_present (SPR_UPR_ICP )) { +unsigned long iccfgr =mfspr (SPR_ICCFGR ); +unsigned long sets =1 << ((iccfgr &SPR_ICCFGR_NCS ) >>3 ); +unsigned long block_size =16 << ((iccfgr &SPR_ICCFGR_CBS ) >>7 ); +unsigned long paddr =0 ; +unsigned long end = sets * block_size; + +while (paddr < end) { +mtspr (SPR_ICBIR , paddr); + paddr += block_size; + } + } +} +void local_dcache_range_flush (unsigned long start,unsigned long end) {cache_loop (start, end,SPR_DCBFR ,SPR_UPR_DCP );
Greg Kroah-Hartman
maintainerPATCH 1265/1611 ocfs2: use kzalloc for quota recovery bitmap allocation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 93c8c6ea90be9e9df8fe14048ad4e3caad0770a6 upstream.
ocfs2 quota recovery allocates a bitmap buffer with kmalloc and does not fully initialize it. This can lead to use of uninitialized bits during quota recovery from a corrupted filesystem image.
Use kzalloc instead to ensure the bitmap is zero-initialized.
--- fs/ocfs2/quota_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/quota_local.c +1 -1
@@ -302,7 +302,7 @@ static int ocfs2_add_recovery_chunk(struif (!rc)return -ENOMEM ; rc->rc_chunk = chunk; - rc->rc_bitmap =kmalloc (sb->s_blocksize,GFP_NOFS ); + rc->rc_bitmap =kzalloc (sb->s_blocksize,GFP_NOFS );if (!rc->rc_bitmap) {kfree (rc);return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 1266/1611 mtd: rawnand: pl353: fix probe resource allocation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bastien Curutchet <[email protected]>
commit 19ed11aee966d91beebdef9d32ce926474872f79 upstream.
During probe(), the devm_ioremap() is called with the parent device instead of the current one. So when the module is unloaded, the register area isn't released.
Target the pl35x device in the devm_ioremap() instead of its parent.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/pl35x-nand-controller.c +1 -1
@@ -1152,7 +1152,7 @@ static int pl35x_nand_probe(struct platf nfc->controller.ops = &pl35x_nandc_ops;INIT_LIST_HEAD (&nfc->chips); - nfc->conf_regs =devm_ioremap_resource (&smc_amba->dev, &smc_amba->res); + nfc->conf_regs =devm_ioremap_resource (nfc->dev, &smc_amba->res);if (IS_ERR (nfc->conf_regs))return PTR_ERR (nfc->conf_regs);
Greg Kroah-Hartman
maintainerPATCH 1267/1611 net/9p: fix infinite loop in p9_client_rpc on fatal signal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasiliy Kovalev <[email protected]>
commit 6b4f48728faa8bb514368f7eacda05565dea8696 upstream.
When p9_client_rpc() is called with type P9_TFLUSH and the transport has no peer (e.g. fd transport backed by pipes with no 9p server), a fatal signal causes an infinite loop:
again:
err = io_wait_event_killable(req->wq, ...)
/* SIGKILL wakes the task, returns -ERESTARTSYS */
if (err == -ERESTARTSYS && c->status == Connected &&
type == P9_TFLUSH) {
sigpending = 1;
clear_thread_flag(TIF_SIGPENDING);
goto again;
}clear_thread_flag() clears TIF_SIGPENDING before jumping back to io_wait_event_killable(). signal_pending_state() checks TIF_SIGPENDING, finds it zero, and the task goes to sleep again. The task can only wake on the next signal delivery that calls signal_wake_up() and sets TIF_SIGPENDING again. When that happens the loop repeats, clears TIF_SIGPENDING, and sleeps again indefinitely.
This is triggered in practice by coredump_wait(): when a thread in a multi-threaded process causes a coredump (e.g. via SIGSYS from Syscall User Dispatch), coredump_wait() sends SIGKILL to all other threads and waits for them to call mm_release(). If one of those threads is blocked in p9_client_rpc() over an fd transport with no peer, it enters the P9_TFLUSH loop and never calls mm_release(), so coredump_wait() stalls forever:
INFO: task syz.0.18:676 blocked for more than 143 seconds.
Not tainted 6.12.77+ #1
task:syz.0.18 state:D stack:27600 pid:676 tgid:673 ppid:630 flags:0x00000004
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5344 [inline]
__schedule+0xcb4/0x5d50 kernel/sched/core.c:6724
__schedule_loop kernel/sched/core.c:6801 [inline]
schedule+0xe5/0x350 kernel/sched/core.c:6816
schedule_timeout+0x253/0x290 kernel/time/timer.c:2593
do_wait_for_common kernel/sched/completion.c:95 [inline]
__wait_for_common+0x409/0x600 kernel/sched/completion.c:116
wait_for_common kernel/sched/completion.c:127 [inline]
wait_for_completion_state+0x1d/0x40 kernel/sched/completion.c:264
coredump_wait fs/coredump.c:448 [inline]
do_coredump+0x854/0x4350 fs/coredump.c:629
get_signal+0x1425/0x2730 kernel/signal.c:2903
arch_do_signal_or_restart+0x81/0x880 arch/x86/kernel/signal.c:337
exit_to_user_mode_loop kernel/entry/common.c:111 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
syscall_exit_to_user_mode+0xf9/0x160 kernel/entry/common.c:218
do_syscall_64+0x102/0x220 arch/x86/entry/common.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>Fix: check fatal_signal_pending() before clearing TIF_SIGPENDING in the P9_TFLUSH retry loop. At that point TIF_SIGPENDING is still set, so fatal_signal_pending() works correctly. If a fatal signal is pending, jump to recalc_sigpending to restore TIF_SIGPENDING and return -ERESTARTSYS to the caller.
The same defect is present in stable kernels back to 5.4. On those kernels the infinite loop is broken earlier by a second SIGKILL from the parent process (e.g. kill_and_wait() retrying after a timeout), resulting in a zombie process and a shutdown delay rather than a permanent D-state hang, but the underlying flaw is the same.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Message-ID: <[email protected]>
--- net/9p/client.c | 2 ++ 1 file changed, 2 insertions(+)
net/9p/client.c +2 -0
@@ -723,6 +723,8 @@ again:if (err == -ERESTARTSYS && c->status == Connected && type ==P9_TFLUSH ) { +if (fatal_signal_pending (current)) + goto recalc_sigpending; sigpending =1 ;clear_thread_flag (TIF_SIGPENDING ); goto again;
Greg Kroah-Hartman
maintainerPATCH 1268/1611 mtd: rawnand: fix condition in nand_select_target()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arseniy Krasnov <[email protected]>
commit 8507c2cc9e4fa402401819f44d1e8a5ef4d11d8b upstream.
'cs' here must be in range [0:nanddev_ntargets[.
--- drivers/mtd/nand/raw/nand_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -174,7 +174,7 @@ void nand_select_target(struct nand_chip* cs should always lie between 0 and nanddev_ntargets(), when that's * not the case it's a bug and the caller should be fixed. */ -if (WARN_ON (cs >nanddev_ntargets (&chip->base))) +if (WARN_ON (cs >=nanddev_ntargets (&chip->base)))return ; chip->cur_cs = cs;
Greg Kroah-Hartman
maintainerPATCH 1269/1611 ocfs2: avoid moving extents to occupied clusters
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
commit 22920541c35a9f23f219038ba5874c843a7c4419 upstream.
For non-auto OCFS2_IOC_MOVE_EXT operations, userspace supplies a physical me_goal. ocfs2_move_extent() initializes new_phys_cpos from that goal and expects ocfs2_probe_alloc_group() to replace it with a free run in the target block group.
The probe currently leaves *phys_cpos unchanged if the scan reaches the end of the group without finding a free run. An occupied goal at the last bit can therefore survive the probe and be passed to __ocfs2_move_extent(), which copies file data into a cluster still owned by another inode before the bitmap is updated.
When the probe does find a free run, it also subtracts move_len from the ending bit. The start of an N-bit run ending at i is i - N + 1, so the current calculation can report the bit immediately before the free run.
Clear *phys_cpos before scanning and use the correct free-run start. Callers already treat a zero result as -ENOSPC, so failed probes no longer continue with an occupied caller-controlled goal.
--- fs/ocfs2/move_extents.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ocfs2/move_extents.c +3 -1
@@ -534,6 +534,8 @@ static void ocfs2_probe_alloc_group(struu32 base_cpos =ocfs2_blocks_to_clusters (inode->i_sb,le64_to_cpu (gd->bg_blkno)); + *phys_cpos =0 ; +for (i = base_bit; i <le16_to_cpu (gd->bg_bits); i++) { used =ocfs2_test_bit (i, (unsigned long *)gd->bg_bitmap);
@@ -555,7 +557,7 @@ static void ocfs2_probe_alloc_group(stru last_free_bits++;if (last_free_bits == move_len) { - i -= move_len; + i = i - move_len +1 ; *goal_bit = i; *phys_cpos = base_cpos + i;break ;
Greg Kroah-Hartman
maintainerPATCH 1270/1611 ocfs2: fix NULL h_transaction deref in ocfs2_assure_trans_credits
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
commit f9ab30c96b0f00c20c6dac93681bdae3a033d229 upstream.
[BUG]
A direct write over unwritten extents can panic the kernel in ocfs2_assure_trans_credits() when the journal aborts during DIO completion. The crash is a general protection fault from a NULL pointer dereference.
[CAUSE]ocfs2_dio_end_io_write() loops over a direct write's unwritten extents, marking each written under a single journal handle. If the journal aborts (for example after an I/O error) while the extent tree is being updated, the handle is left aborted with its transaction pointer cleared. The extent merge treats that failure as not critical and reports success, so the loop keeps using the handle. ocfs2_assure_trans_credits() reads the handle's remaining credits without first checking whether the handle is aborted, and that read dereferences the cleared transaction pointer.
[FIX]
A journal abort is recorded in the handle itself, so callers are expected to test the handle rather than rely on a returned error. Make ocfs2_assure_trans_credits() do that, as the other ocfs2 journal helpers already do, and return -EROFS when the handle is aborted.
--- fs/ocfs2/journal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ocfs2/journal.c +5 -1
@@ -476,8 +476,12 @@ bail:*/ int ocfs2_assure_trans_credits (handle_t *handle,int nblocks) { -int old_nblks =jbd2_handle_buffer_credits (handle); +int old_nblks; +if (is_handle_aborted (handle)) +return -EROFS ; + + old_nblks =jbd2_handle_buffer_credits (handle);trace_ocfs2_assure_trans_credits (old_nblks);if (old_nblks >= nblocks)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 1271/1611 ocfs2: fix UBSAN array-index-out-of-bounds in ocfs2_sum_rightmost_rec
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
commit 452a8467be8143747292218212671deeb186d2ae upstream.
[BUG]
On-disk corruption setting l_next_free_rec to 0 in an inode's embedded extent list triggers a UBSAN panic on the next write to that file.
[CAUSE]ocfs2_sum_rightmost_rec() computes
i = le16_to_cpu(el->l_next_free_rec) - 1
and accesses el->l_recs[i] without validating i. When l_next_free_rec is 0, i becomes -1; when l_next_free_rec exceeds l_count, i falls past the end of the array. Either case violates the __counted_by_le(l_count) annotation on l_recs[] and triggers UBSAN.
[FIX]
Validate the inode's embedded extent list when the inode is read, in ocfs2_validate_inode_block(): l_count must be non-zero and no larger than the inode block can hold, and l_next_free_rec must not exceed l_count. A corrupt list is rejected at read time, before the b-tree code can index l_recs[] out of bounds.
--- fs/ocfs2/inode.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
fs/ocfs2/inode.c +32 -0
@@ -1536,6 +1536,38 @@ int ocfs2_validate_inode_block(struct su } } +if (ocfs2_dinode_has_extents (di)) { +struct ocfs2_extent_list *el = &di->id2.i_list; +u16 count =le16_to_cpu (el->l_count); +u16 next_free =le16_to_cpu (el->l_next_free_rec); + +if (count ==0 ) { + rc =ocfs2_error (sb, +"Invalid dinode %llu: extent list l_count is zero\n" , + (unsigned long long )bh->b_blocknr); + goto bail; + } +/* +* The exact capacity depends on i_xattr_inline_size, another +* unvalidated on-disk field. Inline xattrs only shrink the +* list, so the no-xattr maximum is a safe upper bound that a +* valid l_count never exceeds. +*/ +if (count >ocfs2_extent_recs_per_inode (sb)) { + rc =ocfs2_error (sb, +"Invalid dinode %llu: extent list l_count %u exceeds max %u\n" , + (unsigned long long )bh->b_blocknr, count, +ocfs2_extent_recs_per_inode (sb)); + goto bail; + } +if (next_free > count) { + rc =ocfs2_error (sb, +"Invalid dinode %llu: extent list l_next_free_rec %u exceeds l_count %u\n" , + (unsigned long long )bh->b_blocknr, next_free, count); + goto bail; + } + } + rc =0 ; bail:
Greg Kroah-Hartman
maintainerPATCH 1272/1611 ocfs2: add journal NULL check in ocfs2_checkpoint_inode()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
commit a291c77c034b7a81849ce9b71cc9ecda9e587d89 upstream.
During unmount, ocfs2_journal_shutdown() frees the journal and sets osb->journal to NULL. Later, when VFS evicts remaining cached inodes, ocfs2_evict_inode() -> ocfs2_clear_inode() -> ocfs2_checkpoint_inode() -> ocfs2_ci_fully_checkpointed() dereferences osb->journal, causing a NULL pointer dereference.
Fix this by adding a NULL check for osb->journal in ocfs2_checkpoint_inode(). If the journal is NULL, it has already been fully flushed and destroyed during shutdown, so there is nothing to checkpoint.
--- fs/ocfs2/journal.h | 3 +++ 1 file changed, 3 insertions(+)
fs/ocfs2/journal.h +3 -0
@@ -196,6 +196,9 @@ static inline void ocfs2_checkpoint_inodif (ocfs2_mount_local (osb))return ; +if (!osb->journal) +return ; +if (!ocfs2_ci_fully_checkpointed (INODE_CACHE (inode))) {/* WARNING: This only kicks off a single * checkpoint. If someone races you and adds more
Greg Kroah-Hartman
maintainerPATCH 1273/1611 ocfs2: reject dinodes with non-canonical i_mode type
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 5366a017099c6a3c443be908a05f26fd72af12a1 upstream.
Patch series "ocfs2: harden inode validators against forged metadata", v2.
This series adds three structural checks to OCFS2 dinode validation so malformed on-disk fields are rejected before ocfs2_populate_inode() copies them into the in-core inode.
The checks cover:
- i_mode values whose type bits do not name a canonical POSIX file
type;
- non-device dinodes whose id1.dev1.i_rdev field is non-zero; and
- non-inline dinodes that claim non-zero i_size while i_clusters is zero, covering directories unconditionally and regular files on non-sparse volumes.
The normal read path reports these through ocfs2_error(), matching the existing suballoc-slot, inline-data, chain-list, and refcount checks. The online filecheck path uses the same structural predicates but keeps its own reporting contract, returning OCFS2_FILECHECK_ERR_INVALIDINO instead of calling ocfs2_error().
This patch (of 3):
ocfs2_validate_inode_block() currently accepts any non-zero i_mode value. ocfs2_populate_inode() then copies that mode verbatim into inode->i_mode and dispatches on i_mode & S_IFMT to the file/dir/symlink/special_file iops; an unrecognised type falls through to ocfs2_special_file_iops and init_special_inode().
Reject dinodes whose type bits do not name one of the seven canonical POSIX file types. Use fs_umode_to_ftype(), the same generic file-type conversion helper OCFS2 already uses for directory entries, so the accepted inode type set matches the kernel file-type vocabulary instead of open-coding a local switch.
Apply the same structural check to the online filecheck read path. filecheck keeps its own error namespace, so it reports malformed i_mode through the filecheck logger and OCFS2_FILECHECK_ERR_INVALIDINO instead of calling ocfs2_error(), but it must not allow a malformed dinode to proceed into ocfs2_populate_inode().
--- fs/ocfs2/inode.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
fs/ocfs2/inode.c +33 -2
@@ -64,7 +64,12 @@ static int ocfs2_filecheck_read_inode_blstatic int ocfs2_filecheck_validate_inode_block (struct super_block *sb,struct buffer_head *bh);static int ocfs2_filecheck_repair_inode_block (struct super_block *sb, -struct buffer_head *bh); +struct buffer_head *bh); + +static bool ocfs2_valid_inode_mode (umode_t mode) +{ +return fs_umode_to_ftype (mode) !=FT_UNKNOWN ; +}void ocfs2_set_inode_flags (struct inode *inode) {
@@ -1505,6 +1510,24 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* Reject dinodes whose i_mode does not name one of the seven +* canonical POSIX file types. ocfs2_populate_inode() copies +* i_mode verbatim into inode->i_mode and then dispatches via +* switch (mode & S_IFMT) to file/dir/symlink/special_file iops; +* an unrecognised type falls into ocfs2_special_file_iops with +* init_special_inode(), which interprets i_rdev. Constrain the +* type here so the dispatch only ever sees a value mkfs.ocfs2 / +* VFS can produce. +*/ +if (!ocfs2_valid_inode_mode (le16_to_cpu (di->i_mode))) { + rc =ocfs2_error (sb, +"Invalid dinode #%llu: mode 0%o has unknown file type\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1633,6 +1656,15 @@ static int ocfs2_filecheck_validate_inod (unsigned long long )bh->b_blocknr, le32_to_cpu(di->i_fs_generation)); rc = -OCFS2_FILECHECK_ERR_GENERATION ; + goto bail; + } + +if (!ocfs2_valid_inode_mode (le16_to_cpu (di->i_mode))) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: mode 0%o has unknown file type\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
@@ -1820,4 +1852,3 @@ const struct ocfs2_caching_operations oc .co_io_lock = ocfs2_inode_cache_io_lock, .co_io_unlock = ocfs2_inode_cache_io_unlock, }; -
Greg Kroah-Hartman
maintainerPATCH 1274/1611 ocfs2: reject dinodes whose i_rdev disagrees with the file type
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 51407c2d249987a466416890a5c931a2354a46aa upstream.
id1.dev1.i_rdev is the device-number arm of the ocfs2_dinode id1 union. It is only meaningful for character and block device inodes. For any other user-visible file type the on-disk value must be zero.
ocfs2_populate_inode() currently copies id1.dev1.i_rdev into inode->i_rdev before the S_IFMT switch decides whether the inode is a special file. A non-device inode with a non-zero i_rdev can therefore publish stale or attacker-controlled device state into the in-core inode.
System inodes legitimately use other arms of the same union, so keep the cross-check restricted to non-system inodes. Factor that predicate into a helper and use it in both the normal validator and online filecheck path; filecheck reports the malformed dinode through OCFS2_FILECHECK_ERR_INVALIDINO instead of ocfs2_error().
--- fs/ocfs2/inode.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
fs/ocfs2/inode.c +55 -0
@@ -71,6 +71,16 @@ static bool ocfs2_valid_inode_mode(umodereturn fs_umode_to_ftype (mode) !=FT_UNKNOWN ; } +static bool ocfs2_dinode_has_unexpected_rdev (struct ocfs2_dinode *di) +{ +umode_t mode =le16_to_cpu (di->i_mode); + +if (le32_to_cpu (di->i_flags) &OCFS2_SYSTEM_FL ) +return false; + +return !S_ISCHR (mode) && !S_ISBLK (mode) && di->id1.dev1.i_rdev !=0 ; +} +void ocfs2_set_inode_flags (struct inode *inode) {unsigned int flags =OCFS2_I (inode)->ip_attr;
@@ -1528,6 +1538,41 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* id1.dev1.i_rdev is the device-number arm of the id1 union and +* is only meaningful for character and block device inodes. For +* any other regular user-visible file type the on-disk value +* must be zero. ocfs2_populate_inode() currently runs +* +* inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev)); +* +* unconditionally, before the S_IFMT switch decides whether the +* inode is a special file. As a result, an i_rdev value present +* on a non-device inode is silently published into the in-core +* inode; a subsequent forced re-read or in-core mode mutation +* (cluster peer with raw write access to the shared LUN, +* on-disk corruption, or a separately forged dinode) can then +* expose the attacker-controlled device number to +* init_special_inode() without ever showing an unusual i_mode +* at validation time. +* +* System inodes (OCFS2_SYSTEM_FL) legitimately use the bitmap1 +* and journal1 arms of the same union (allocator i_used / +* i_total counters and the journal ij_flags / +* ij_recovery_generation pair); those bytes are not an i_rdev +* and must not be checked here. Restrict the cross-check to +* non-system inodes, which is the full attacker-controllable +* surface. +*/ +if (ocfs2_dinode_has_unexpected_rdev (di)) { + rc =ocfs2_error (sb, +"Invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode), + (unsigned long long )le64_to_cpu (di->id1.dev1.i_rdev)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1665,6 +1710,16 @@ static int ocfs2_filecheck_validate_inod (unsigned long long )bh->b_blocknr, le16_to_cpu(di->i_mode)); rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; + goto bail; + } + +if (ocfs2_dinode_has_unexpected_rdev (di)) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode), + (unsigned long long )le64_to_cpu (di->id1.dev1.i_rdev)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
Greg Kroah-Hartman
maintainerPATCH 1275/1611 ocfs2: reject non-inline dinodes with i_size and zero i_clusters
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 7ebc672fab7a76e1e47e0f2fc1ee48118d27fde4 upstream.
On a volume mounted without OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC, a non-inline regular file with non-zero i_size and zero i_clusters is structurally malformed: the extent map declares no allocated clusters yet the size header claims content exists. Keep rejecting that shape, but express it through a shared predicate so the same invariant is available to normal inode reads and online filecheck.
The same zero-cluster shape is also malformed for non-inline directories. ocfs2 directory growth allocates backing storage before advancing i_size, and ocfs2_dir_foreach_blk_el() later walks until ctx->pos reaches i_size_read(inode). A forged directory dinode with a huge i_size and no clusters would repeatedly fail on holes while advancing through the claimed size.
Sparse regular files remain exempt: on sparse-alloc volumes, truncate can legitimately grow i_size without allocating clusters. System inodes and inline-data dinodes also retain their separate storage rules.
Mirror the check in ocfs2_filecheck_validate_inode_block() as well. filecheck reports through its own error namespace, so malformed size/cluster state is logged as a filecheck invalid-inode result rather than via ocfs2_error(), but it must not proceed into ocfs2_populate_inode().
--- fs/ocfs2/inode.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
fs/ocfs2/inode.c +60 -0
@@ -81,6 +81,24 @@ static bool ocfs2_dinode_has_unexpected_return !S_ISCHR (mode) && !S_ISBLK (mode) && di->id1.dev1.i_rdev !=0 ; } +static bool ocfs2_dinode_has_size_without_clusters (struct super_block *sb, +struct ocfs2_dinode *di) +{ +umode_t mode =le16_to_cpu (di->i_mode); + +if (le32_to_cpu (di->i_flags) &OCFS2_SYSTEM_FL ) +return false; +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) +return false; +if (!le64_to_cpu (di->i_size) ||le32_to_cpu (di->i_clusters)) +return false; + +if (S_ISDIR (mode)) +return true; + +return !ocfs2_sparse_alloc (OCFS2_SB (sb)) &&S_ISREG (mode); +} +void ocfs2_set_inode_flags (struct inode *inode) {unsigned int flags =OCFS2_I (inode)->ip_attr;
@@ -1573,6 +1591,33 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* Non-inline directories must not have i_size without allocated +* clusters: directory growth adds storage before advancing i_size, +* and readdir walks i_size block-by-block. A forged directory +* with zero clusters and a huge i_size would repeatedly fault on +* holes while advancing through the claimed size. +* +* Non-inline regular files have the same invariant on non-sparse +* volumes. Sparse regular files are different: truncate can +* legitimately grow i_size without allocating clusters, so keep +* the sparse-alloc carveout for S_IFREG only. System inodes and +* inline-data dinodes have their own storage rules. +*/ +if (ocfs2_dinode_has_size_without_clusters (sb, di)) { +if (S_ISDIR (le16_to_cpu (di->i_mode))) + rc =ocfs2_error (sb, +"Invalid dinode #%llu: directory i_size %llu with i_clusters 0 and no inline-data flag\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); +else + rc =ocfs2_error (sb, +"Invalid dinode #%llu: regular file i_size %llu with i_clusters 0 and no inline-data flag on non-sparse volume\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1720,6 +1765,21 @@ static int ocfs2_filecheck_validate_inodle16_to_cpu (di->i_mode), (unsigned long long)le64_to_cpu(di->id1.dev1.i_rdev)); rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; + goto bail; + } + +if (ocfs2_dinode_has_size_without_clusters (sb, di)) { +if (S_ISDIR (le16_to_cpu (di->i_mode))) +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: directory i_size %llu with i_clusters 0 and no inline-data flag\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); +else +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: regular file i_size %llu with i_clusters 0 and no inline-data flag on non-sparse volume\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
Greg Kroah-Hartman
maintainerPATCH 1276/1611 fpga: dfl: add bounds check in dfh_get_param_size()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Alba Vives <[email protected]>
commit 9e8bc49f91f3f81d957c4f1c1f09fe94e2f88f6a upstream.
dfh_get_param_size() can return a parameter size larger than the feature region because the loop bounds check is evaluated before incrementing size. If the EOP (End of Parameters) bit is set in the same iteration, the inflated size is returned without re-validation against max.
This can cause create_feature_instance() to call memcpy_fromio() with a size exceeding the ioremap'd region when a malicious FPGA device provides crafted DFHv1 parameter headers.
Add a bounds check after the size increment to ensure the accumulated size never exceeds the feature boundary.
--- drivers/fpga/dfl.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/fpga/dfl.c +2 -0
@@ -1133,6 +1133,8 @@ static int dfh_get_param_size(void __iomreturn -EINVAL ; size += next *sizeof (u64); +if (size > max) +return -EINVAL ;if (FIELD_GET (DFHv1_PARAM_HDR_NEXT_EOP, v))return size;
Greg Kroah-Hartman
maintainerPATCH 1277/1611 bus: mhi: host: pci_generic: Fix the physical function check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
commit 32845111e8ea6ef5e837b6d25080e69e99bd4561 upstream.
Commit b4d01c5b9a9d ("bus: mhi: host: pci_generic: Read SUBSYSTEM_VENDOR_ID for VF's to check status") added the check for physical function by checking for 'pdev->is_physfn. But 'pdev->is_physfn' is only set for the physical function of a SR-IOV capable device. But for the non-SR-IOV device this variable will be 0. So this check ended up breaking the health check functionality for all non-SR-IOV devices.
Fix it by checking for '!pdev->is_virtfn' to make sure that the check is only skipped for virtual functions.
--- drivers/bus/mhi/host/pci_generic.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/bus/mhi/host/pci_generic.c +10 -10
@@ -1197,7 +1197,7 @@ static void mhi_pci_recovery_work(structdev_warn (&pdev->dev,"device recovery started\n" ); -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete (&mhi_pdev->health_check_timer);pm_runtime_forbid (&pdev->dev);
@@ -1227,7 +1227,7 @@ static void mhi_pci_recovery_work(structset_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status); -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD );return ;
@@ -1318,7 +1318,7 @@ static int mhi_pci_probe(struct pci_dev mhi_cntrl_config = info->config;/* Initialize health check monitor only for Physical functions */ -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_setup (&mhi_pdev->health_check_timer, health_check,0 ); mhi_cntrl = &mhi_pdev->mhi_cntrl;
@@ -1340,7 +1340,7 @@ static int mhi_pci_probe(struct pci_dev mhi_cntrl->mru = info->mru_default; mhi_cntrl->name = info->name; -if (pdev->is_physfn) +if (!pdev->is_virtfn) mhi_pdev->reset_on_remove = info->reset_on_remove;if (info->edl_trigger)
@@ -1389,7 +1389,7 @@ static int mhi_pci_probe(struct pci_devset_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status);/* start health check */ -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD );/* Allow runtime suspend only if both PME from D3Hot and M3 are supported */
@@ -1417,7 +1417,7 @@ static void mhi_pci_remove(struct pci_depci_disable_sriov (pdev); -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete_sync (&mhi_pdev->health_check_timer);cancel_work_sync (&mhi_pdev->recovery_work);
@@ -1449,7 +1449,7 @@ static void mhi_pci_reset_prepare(structdev_info (&pdev->dev,"reset\n" ); -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete (&mhi_pdev->health_check_timer);/* Clean up MHI state */
@@ -1495,7 +1495,7 @@ static void mhi_pci_reset_done(struct pc }set_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status); -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD ); }
@@ -1561,7 +1561,7 @@ static int __maybe_unused mhi_pci_runtiif (test_and_set_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status))return 0 ; -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete (&mhi_pdev->health_check_timer);cancel_work_sync (&mhi_pdev->recovery_work);
@@ -1614,7 +1614,7 @@ static int __maybe_unused mhi_pci_runtim }/* Resume health check */ -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD );/* It can be a remote wakeup (no mhi runtime_get), update access time */
Greg Kroah-Hartman
maintainerPATCH 1278/1611 bus: mhi: ep: Protect mhi_ep_handle_syserr() in the error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
commit 519ddf194b158b91439319f6b977b8a465fda0fb upstream.
All the callers of mhi_ep_handle_syserr() except mhi_ep_process_cmd_ring() are holding the 'state_lock' to avoid the race in setting the MHI state. So do the same in mhi_ep_process_cmd_ring() for sanity.
--- drivers/bus/mhi/ep/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bus/mhi/ep/main.c +2 -0
@@ -232,7 +232,9 @@ static int mhi_ep_process_cmd_ring(struct mhi_ep_ring *ring, struct mhi_ring_ele ret =mhi_ep_create_device (mhi_cntrl, ch_id);if (ret) {dev_err (dev,"Error creating device for channel (%u)\n" , ch_id); +mutex_lock (&mhi_cntrl->state_lock);mhi_ep_handle_syserr (mhi_cntrl); +mutex_unlock (&mhi_cntrl->state_lock);return ret; } }
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 1279/1611 net: thunderbolt: Fix frags[] overflow by bounding frame_count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 55d9895f89970501fe126d1026b586b04a224c27 upstream.
tbnet_poll() assembles a multi-frame ThunderboltIP packet into one skb. The first frame goes into the skb linear area and every further frame is added as a page fragment.
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, hdr_size, frame_size, TBNET_RX_PAGE_SIZE - hdr_size);
A packet of frame_count frames therefore ends up with frame_count - 1 fragments. tbnet_check_frame() only bounds the peer supplied frame_count to TBNET_RING_SIZE / 4 (64), which is far above MAX_SKB_FRAGS (17 by default). A peer that sends a packet of 19 or more small frames pushes nr_frags past MAX_SKB_FRAGS, so skb_add_rx_frag() writes past skb_shinfo()->frags[] and corrupts memory after the shared info.
Tighten the start of packet bound to MAX_SKB_FRAGS + 1 so a packet can never produce more fragments than frags[] can hold. This matches the recent skb frags overflow fixes in other receive paths, for example f0813bcd2d9d ("net:
wwan: t7xx: fix potential skb->frags overflow in RX path") and 600dc40554dc ("net: usb: cdc-phonet: fix skb frags[] overflow in rx_complete()").
--- drivers/net/thunderbolt/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/thunderbolt/main.c +6 -2
@@ -786,8 +786,12 @@ static bool tbnet_check_frame(struct tbnreturn true; } -/* Start of packet, validate the frame header */ -if (frame_count ==0 || frame_count >TBNET_RING_SIZE /4 ) { +/* Start of packet, validate the frame header. tbnet_poll() puts the +* first frame in the skb linear area and every further frame in a page +* fragment, so a packet may not span more than MAX_SKB_FRAGS + 1 frames +* without overflowing skb_shinfo()->frags[]. +*/ +if (frame_count ==0 || frame_count >MAX_SKB_FRAGS +1 ) { net->stats.rx_length_errors++;return false; }
Greg Kroah-Hartman
maintainerPATCH 1280/1611 fpga: microchip-spi: fix zero header_size OOB read in mpf_ops_parse_header()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Alba Vives <[email protected]>
commit 43a1974da6bc7ce8f4d1dc1d03d56997428c29c3 upstream.
mpf_ops_parse_header() reads header_size from the bitstream at MPF_HEADER_SIZE_OFFSET (24). When header_size is zero, the expression *(buf + header_size - 1) reads one byte before the buffer start.
Since initial_header_size is set to 71 in mpf_ops, the fpga-mgr core guarantees the buffer is large enough to reach MPF_HEADER_SIZE_OFFSET. The only real gap is the zero header_size case, which cannot be resolved by providing a larger buffer, so return -EINVAL.
--- drivers/fpga/microchip-spi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/fpga/microchip-spi.c +3 -0
@@ -116,6 +116,9 @@ static int mpf_ops_parse_header(struct f } header_size = *(buf +MPF_HEADER_SIZE_OFFSET ); +if (!header_size) +return -EINVAL ; +if (header_size > count) { info->header_size = header_size;return -EAGAIN ;
Greg Kroah-Hartman
maintainerPATCH 1281/1611 s390/pkey: Check length in PKEY_VERIFYPROTK ioctl
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Holger Dengler <[email protected]>
commit b3d4ab2d7df9426f7f1d3671d7e2108f2ca6e970 upstream.
Explicitly check the buffer length request structure provided by user-space and fail, if it exceeds the buffer size.
--- drivers/s390/crypto/pkey_api.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/s390/crypto/pkey_api.c +7 -0
@@ -335,6 +335,13 @@ static int pkey_ioctl_verifyprotk(structif (copy_from_user (&kvp, uvp,sizeof (kvp)))return -EFAULT ; +if (kvp.protkey.len >sizeof (kvp.protkey.protkey)) { +PKEY_DBF_ERR ("%s protkey length %u exceeds protkey buffer size\n" , + __func__, kvp.protkey.len); +memzero_explicit (&kvp,sizeof (kvp)); +return -EINVAL ; + } + keytype =pkey_aes_bitsize_to_keytype (8 * kvp.protkey.len);if (!keytype) { PKEY_DBF_ERR("%s unknown/unsupported protkey length %u\n",
Greg Kroah-Hartman
maintainerPATCH 1282/1611 s390/pkey: Check length in pkey_pckmo handler implementation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Holger Dengler <[email protected]>
commit 1ac287e2af9a9112fe271427ef45eceb26bce8b4 upstream.
Explicitly check the length of the target buffer in the pkey_pckmo implementation of the key_to_protkey() handler function. The handler function fails, if the generated output data exceeds the length of the provided target buffer.
--- drivers/s390/crypto/pkey_pckmo.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/s390/crypto/pkey_pckmo.c +4 -0
@@ -257,6 +257,10 @@ static int pckmo_key2protkey(const u8 *k goto out;break ; } +if (t->len > *protkeylen) { + rc = -EINVAL ; + goto out; + }memcpy (protkey, t->protkey, t->len); *protkeylen = t->len; *protkeytype = t->keytype;
Greg Kroah-Hartman
maintainerPATCH 1283/1611 mtd: spi-nor: swp: Improve locking user experience
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit e1d456b26bf23e30db305a6184e8abd9ab68bbf2 upstream.
In the case of the first block being locked (or the few first blocks), if the user want to fully unlock the device it has two possibilities:
- either it asks to unlock the entire device, and this works;
- or it asks to unlock just the block(s) that are currently locked, which fails.
It fails because the conditions "can_be_top" and "can_be_bottom" are true. Indeed, in this case, we unlock everything, so the TB bit does not matter. However in the current implementation, use_top would be true (as this is the favourite option) and lock_len, which in practice should be reduced down to 0, is set to "nor->params->size - (ofs + len)" which is a positive number. This is wrong.
An easy way is to simply add an extra condition. In the unlock() path, if we can achieve the same result from both sides, it means we unlock everything and lock_len must simply be 0. A comment is added to clarify that logic.
--- drivers/mtd/spi-nor/swp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/swp.c +9 -2
@@ -282,8 +282,15 @@ static int spi_nor_sr_unlock(struct spi_/* Prefer top, if both are valid */ use_top = can_be_top; -/* lock_len: length of region that should remain locked */ -if (use_top) +/* +* lock_len: length of region that should remain locked. +* +* When can_be_top and can_be_bottom booleans are true, both adjacent +* regions are unlocked, thus the entire flash can be unlocked. +*/ +if (can_be_top && can_be_bottom) + lock_len =0 ; +else if (use_top) lock_len = nor->params->size - (ofs + len);else lock_len = ofs;
Greg Kroah-Hartman
maintainerPATCH 1284/1611 mtd: spi-nor: spansion: use die erase for multi-die devices only
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takahiro Kuwano <[email protected]>
commit 306e443156b82a2a14a3f33da908c303be45529c upstream.
Die erase opcode is supported in multi-die devices only. For single die devices, default chip erase opcode must be used.
In s25hx_t_late_init(), die erase opcode is set only when the device is multi-die.
--- drivers/mtd/spi-nor/spansion.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/spansion.c +3 -1
@@ -674,7 +674,9 @@ static int s25hx_t_late_init(struct spi_ params->ready = cypress_nor_sr_ready_and_clear;cypress_nor_ecc_init (nor); - params->die_erase_opcode =SPINOR_OP_CYPRESS_DIE_ERASE ; +if (params->n_dice >1 ) + params->die_erase_opcode =SPINOR_OP_CYPRESS_DIE_ERASE ; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1285/1611 mtd: rawnand: Pause continuous reads at block boundaries
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit 8e4531667d718e2e9b193928cf9b2497fa0d01ef upstream.
Some chips do not support sequential cached reads past block boundaries, like Winbond. In practice when using UBI, this should very rarely happen, but let's make sure it never happens.
--- drivers/mtd/nand/raw/nand_base.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/mtd/nand/raw/nand_base.c +12 -12
@@ -1215,32 +1215,32 @@ static int nand_lp_exec_read_page_op(strreturn nand_exec_op (chip, &op); } -static unsigned int rawnand_last_page_of_lun (unsigned int pages_per_lun,unsigned int lun) +static unsigned int rawnand_last_page_of_block (unsigned int ppb,unsigned int block) { -/* lun is expected to be very small */ -return (lun * pages_per_lun) + pages_per_lun -1 ; +/* block is expected to be very small */ +return (block * ppb) + ppb -1 ; }static void rawnand_cap_cont_reads (struct nand_chip *chip) {struct nand_memory_organization *memorg; -unsigned int ppl, first_lun, last_lun; +unsigned int ppb, first_block, last_block; memorg =nanddev_get_memorg (&chip->base); - ppl = memorg->pages_per_eraseblock * memorg->eraseblocks_per_lun; - first_lun = chip->cont_read.first_page / ppl; - last_lun = chip->cont_read.last_page / ppl; - -/* Prevent sequential cache reads across LUN boundaries */ -if (first_lun != last_lun) - chip->cont_read.pause_page =rawnand_last_page_of_lun (ppl, first_lun); + ppb = memorg->pages_per_eraseblock; + first_block = chip->cont_read.first_page / ppb; + last_block = chip->cont_read.last_page / ppb; + +/* Prevent sequential cache reads across block boundaries */ +if (first_block != last_block) + chip->cont_read.pause_page =rawnand_last_page_of_block (ppb, first_block);else chip->cont_read.pause_page = chip->cont_read.last_page;if (chip->cont_read.first_page == chip->cont_read.pause_page) { chip->cont_read.first_page++; chip->cont_read.pause_page =min (chip->cont_read.last_page, -rawnand_last_page_of_lun (ppl, first_lun +1 )); +rawnand_last_page_of_block (ppb, first_block +1 )); }if (chip->cont_read.first_page >= chip->cont_read.last_page)
Greg Kroah-Hartman
maintainerPATCH 1286/1611 openrisc: Fix jump_label smp syncing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stafford Horne <[email protected]>
commit aca063c9024522e4e5b9a9d1927433f6a01785a3 upstream.
The original commit 8c30b0018f9d ("openrisc: Add jump label support") copies from arm64 and does not properly consider how icache invalidation on remote cores works in OpenRISC. On OpenRISC remote icaches need to be invalidated otherwise static key's may remain state after updating.
Fix SMP cache syncing by:
1. Properly invalidate remote core icaches on SMP systems by using icache_all_inv. The old code uses kick_all_cpus_sync() which runs a no-op IPI function call on remote CPU's which does execute a lot of code and flushes many cache lines in the process, but does not flush all and it's not correct on OpenRISC.
2. For architectures that do not have WRITETHROUGH caches be sure to flush the dcache after patching.
To test this I first reproduced the issue using a custom test module [0]. The test confirmed that some icache lines maintained stale static_key code sequences after calling static_branch_enable(). After this patch there are no longer jump_label coherency issues.
[0] https://github.com/stffrdhrn/or1k-utils/tree/master/tests/smp_static_key_test
--- arch/openrisc/kernel/jump_label.c | 2 +- arch/openrisc/kernel/patching.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
arch/openrisc/kernel/jump_label.c +1 -1
@@ -47,5 +47,5 @@ bool arch_jump_label_transform_queue(strvoid arch_jump_label_transform_apply (void ) { -kick_all_cpus_sync (); +icache_all_inv (); }
arch/openrisc/kernel/patching.c +3 -0
@@ -49,6 +49,9 @@ static int __patch_insn_write(void *addr waddr =patch_map (addr,FIX_TEXT_POKE0 ); ret =copy_to_kernel_nofault (waddr, &insn,OPENRISC_INSN_SIZE ); +if (!IS_ENABLED (CONFIG_DCACHE_WRITETHROUGH )) +local_dcache_range_flush ((unsigned long )waddr, + (unsigned long )waddr +OPENRISC_INSN_SIZE );local_icache_range_inv ((unsigned long )waddr, (unsigned long )waddr +OPENRISC_INSN_SIZE );
Greg Kroah-Hartman
maintainerPATCH 1287/1611 mtd: maps: vmu-flash: fix NULL pointer dereference in initialization
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fuchs <[email protected]>
commit 357e3b8e3a8769ba36eb8ec5e053e4825f1a9329 upstream.
The mtd_info contains a struct device, which must be linked to its parent. Without this, the initialization of the MTD fails with a NULL pointer dereference.
--- drivers/mtd/maps/vmu-flash.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/maps/vmu-flash.c +1 -0
@@ -547,6 +547,7 @@ static void vmu_queryblocks(struct maple mpart->partition = card->partition; mtd_cur->priv = mpart; mtd_cur->owner =THIS_MODULE ; + mtd_cur->dev.parent = &mdev->dev; pcache =kzalloc (sizeof (struct vmu_cache ),GFP_KERNEL );if (!pcache)
Greg Kroah-Hartman
maintainerPATCH 1288/1611 taskstats: retain dead thread stats in TGID queries
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
commit b3e4fbb04220efc3bc022bcf31b5689d39c6b111 upstream.
Patch series "taskstats: fix TGID dead-thread stat retention", v3.
This series fixes a taskstats TGID aggregation bug where fields added in the TGID query path were not preserved after thread exit, and adds a kselftest covering the regression.
The first patch keeps the cached TGID aggregate used for dead threads in step with the fields already accumulated for live threads, and also fixes the final TGID exit notification emitted when group_dead is true.
The second patch adds a kselftest that verifies TGID CPU stats do not regress after a worker thread exits and has been reaped.
This patch (of 2):
fill_stats_for_tgid() builds TGID stats from two sources: the cached aggregate in signal->stats and a scan of the live threads in the group.
However, fill_tgid_exit() only accumulates delay accounting into signal->stats. This means that once a thread exits, TGID queries lose the fields that fill_stats_for_tgid() adds for live threads.
This gap was introduced incrementally by two earlier changes that extended fill_stats_for_tgid() but did not make the corresponding update to fill_tgid_exit():
- commit 8c733420bdd5 ("taskstats: add e/u/stime for TGID command") added ac_etime, ac_utime, and ac_stime to the TGID query path.
- commit b663a79c1915 ("taskstats: add context-switch counters") added nvcsw and nivcsw to the TGID query path.
As a result, those fields were accounted for live threads in TGID queries, but were dropped from the cached TGID aggregate after thread exit. The final TGID exit notification emitted when group_dead is true also copies that cached aggregate, so it loses the same fields.
Factor the per-task TGID accumulation into tgid_stats_add_task() and use it in both fill_stats_for_tgid() and fill_tgid_exit(). This keeps the cached aggregate used for dead threads aligned with the live-thread accumulation used by TGID queries.
--- kernel/taskstats.c | 62 ++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 29 deletions(-)
kernel/taskstats.c +33 -29
@@ -210,13 +210,39 @@ static int fill_stats_for_pid(pid_t pid,return 0 ; } +static void tgid_stats_add_task (struct taskstats *stats, +struct task_struct *tsk,u64 now_ns) +{ +u64 delta, utime, stime; + +/* +* Each accounting subsystem calls its functions here to +* accumulate its per-task stats for tsk, into the per-tgid structure +* +* per-task-foo(stats, tsk); +*/ +delayacct_add_tsk (stats, tsk); + +/* calculate task elapsed time in nsec */ + delta = now_ns - tsk->start_time; +/* Convert to micro seconds */ +do_div (delta,NSEC_PER_USEC ); + stats->ac_etime += delta; + +task_cputime (tsk, &utime, &stime); + stats->ac_utime +=div_u64 (utime,NSEC_PER_USEC ); + stats->ac_stime +=div_u64 (stime,NSEC_PER_USEC ); + + stats->nvcsw += tsk->nvcsw; + stats->nivcsw += tsk->nivcsw; +} +static int fill_stats_for_tgid (pid_t tgid,struct taskstats *stats) {struct task_struct *tsk, *first;unsigned long flags;int rc = -ESRCH ; -u64 delta, utime, stime; -u64 start_time; +u64 now_ns;/* * Add additional stats from live tasks except zombie thread group
@@ -233,30 +259,12 @@ static int fill_stats_for_tgid(pid_t tgielse memset (stats,0 ,sizeof (*stats)); - start_time =ktime_get_ns (); + now_ns =ktime_get_ns ();for_each_thread (first, tsk) {if (tsk->exit_state)continue ; -/* -* Accounting subsystem can call its functions here to -* fill in relevant parts of struct taskstsats as follows -* -* per-task-foo(stats, tsk); -*/ -delayacct_add_tsk (stats, tsk); - -/* calculate task elapsed time in nsec */ - delta = start_time - tsk->start_time; -/* Convert to micro seconds */ -do_div (delta,NSEC_PER_USEC ); - stats->ac_etime += delta; - -task_cputime (tsk, &utime, &stime); - stats->ac_utime +=div_u64 (utime,NSEC_PER_USEC ); - stats->ac_stime +=div_u64 (stime,NSEC_PER_USEC ); - stats->nvcsw += tsk->nvcsw; - stats->nivcsw += tsk->nivcsw; +tgid_stats_add_task (stats, tsk, now_ns); }unlock_task_sighand (first, &flags);
@@ -275,18 +283,14 @@ out:static void fill_tgid_exit (struct task_struct *tsk) {unsigned long flags; +u64 now_ns;spin_lock_irqsave (&tsk->sighand->siglock, flags);if (!tsk->signal->stats) goto ret; -/* -* Each accounting subsystem calls its functions here to -* accumalate its per-task stats for tsk, into the per-tgid structure -* -* per-task-foo(tsk->signal->stats, tsk); -*/ -delayacct_add_tsk (tsk->signal->stats, tsk); + now_ns =ktime_get_ns (); +tgid_stats_add_task (tsk->signal->stats, tsk, now_ns); ret:spin_unlock_irqrestore (&tsk->sighand->siglock, flags);return ;
Greg Kroah-Hartman
maintainerPATCH 1289/1611 irqchip/crossbar: Use correct index in crossbar_domain_free()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bhargav Joshi <[email protected]>
commit 043db005a8d6932dc7d217c86307e9af0bc10ddc upstream.
crossbar_domain_free() resets the domain data and then uses the nulled out irq_data->hwirq member as index to reset the irq_map[] entry and to write the relevant crossbar register with a safe entry. That means it never frees the correct index and keeps the crossbar register connection to the source interrupt active.
If it would not reset the domain data, then this would be even worse as irq_data->hwirq holds the source interrupt number, but both the map and register index need the corresponding GIC SPI number and not the source interrupt number. This might even result in an out of bounds access as the source interrupt number can be higher than the maximal index space.
Fix this by using the GIC SPI index from the parent domain's irq_data.
--- drivers/irqchip/irq-crossbar.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/irqchip/irq-crossbar.c +7 -2
@@ -158,9 +158,14 @@ static void crossbar_domain_free(structfor (i =0 ; i < nr_irqs; i++) {struct irq_data *d =irq_domain_get_irq_data (domain, virq + i); +/* +* irq_map[] is indexed by GIC SPI number. The parent domain's +* hwirq contains the GIC interrupt number (GIC SPI + +* GIC_IRQ_START). +*/ + cb->irq_map[d->parent_data->hwirq -GIC_IRQ_START ] =IRQ_FREE ; + cb->write (d->parent_data->hwirq -GIC_IRQ_START , cb->safe_map);irq_domain_reset_irq_data (d); - cb->irq_map[d->hwirq] =IRQ_FREE ; - cb->write (d->hwirq, cb->safe_map); }raw_spin_unlock (&cb->lock);irq_domain_free_irqs_parent (domain, virq, nr_irqs);
Greg Kroah-Hartman
maintainerPATCH 1290/1611 tpm: restore timeout for key creation commands
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baoli Zhang <[email protected]>
commit de59d78e64039baa5fed455ddb905ba8263e7ede upstream.
Commit 207696b17f38 ("tpm: use a map for tpm2_calc_ordinal_duration()") inadvertently reduced the timeout for TPM2 key creation commands (CREATE_PRIMARY, CREATE, CREATE_LOADED) from 300 seconds to 30 seconds.
This causes intermittent timeout failures, with several failures observed across hundreds of test runs on some Intel platforms using Infineon SLB9670 and SLB9672 TPM modules. Restore the timeout to 300 seconds to avoid spurious failures.
--- drivers/char/tpm/tpm2-cmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm2-cmd.c +3 -3
@@ -59,9 +59,9 @@ static const struct { {TPM2_CC_HIERARCHY_CHANGE_AUTH, 2000}, {TPM2_CC_GET_CAPABILITY, 750}, {TPM2_CC_NV_READ, 2000}, - {TPM2_CC_CREATE_PRIMARY, 30000}, - {TPM2_CC_CREATE, 30000}, - {TPM2_CC_CREATE_LOADED, 30000}, + {TPM2_CC_CREATE_PRIMARY, 300000}, + {TPM2_CC_CREATE, 300000}, + {TPM2_CC_CREATE_LOADED, 300000}, };/**
Greg Kroah-Hartman
maintainerPATCH 1291/1611 tpm: tpm_tis_spi: Use wait_woken() in wait_for_tmp_stat()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit c0c9cfb3b75def8bf200a2d4db09015806acfeaf upstream.
wait_event_interruptible_timeout() evaluates its condition after setting the current task state to TASK_INTERRUPTIBLE.
With CONFIG_DEBUG_ATOMIC_SLEEP this triggers a warning when the IRQ wait path is used:
tpm_tis_status()
tpm_tis_spi_read_bytes()
tpm_tis_spi_transfer_full()
spi_bus_lock()
mutex_lock()Address this with the following measures:
1. Call wait_tpm_stat_cond() only while tasking is running.
2. Use wait_woken() to wait for changes.
--- drivers/char/tpm/tpm_tis_core.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/char/tpm/tpm_tis_core.c +21 -14
@@ -66,8 +66,8 @@ static int wait_for_tpm_stat(struct tpm_ bool check_cancel) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev); +DEFINE_WAIT_FUNC (wait, woken_wake_function);unsigned long stop; -long rc;u8 status;bool canceled = false;u8 sts_mask;
@@ -87,23 +87,30 @@ static int wait_for_tpm_stat(struct tpm_/* process status changes with irq support */ if (sts_mask) { ret = -ETIME ; +add_wait_queue (queue, &wait); again: +if (wait_for_tpm_stat_cond (chip, sts_mask, check_cancel, + &canceled)) { + ret = canceled ? -ECANCELED :0 ; + goto out; + } + timeout = stop - jiffies;if ((long )timeout <=0 ) -return -ETIME ; - rc =wait_event_interruptible_timeout (*queue, -wait_for_tpm_stat_cond (chip, sts_mask, check_cancel, - &canceled), - timeout); -if (rc >0 ) { -if (canceled) -return -ECANCELED ; - ret =0 ; - } -if (rc == -ERESTARTSYS &&freezing (current)) { -clear_thread_flag (TIF_SIGPENDING ); - goto again; + goto out; + +if (signal_pending (current)) { +if (freezing (current)) { +clear_thread_flag (TIF_SIGPENDING ); + goto again; + } + goto out; } + +wait_woken (&wait,TASK_INTERRUPTIBLE , timeout); + goto again; +out: +remove_wait_queue (queue, &wait); }if (ret)
Greg Kroah-Hartman
maintainerPATCH 1292/1611 tpm: tpm2-sessions: wait for async KPP completion in tpm_buf_append_salt
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 73851a7c43dfa52d2ed9415889b33daf85da0ed9 upstream.
tpm_buf_append_salt() in drivers/char/tpm/tpm2-sessions.c calls crypto_kpp_generate_public_key() and crypto_kpp_compute_shared_secret() without installing a completion callback, discards both return values, and immediately frees the kpp_request via kpp_request_free(). When the resolved ecdh-nist-p256 KPP backend is asynchronous (atmel-ecc, HPRE, keembay-ocs), either operation returns -EINPROGRESS and the deferred completion worker dereferences the freed request.
The path fires automatically from the hwrng_fillfn kernel thread via tpm_get_random -> tpm2_get_random -> tpm2_start_auth_session -> tpm_buf_append_salt on every entropy poll, without any userland action.
Install crypto_req_done as the completion callback, wrap both KPP operations in crypto_wait_req(), and propagate errors to the caller. The wait is a no-op for synchronous backends.
--- drivers/char/tpm/tpm2-sessions.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-)
drivers/char/tpm/tpm2-sessions.c +34 -11
@@ -490,15 +490,17 @@ static void tpm2_KDFe(u8 z[EC_PT_SZ], cosha256_final (&sctx, out); } -static void tpm_buf_append_salt (struct tpm_buf *buf,struct tpm_chip *chip, -struct tpm2_auth *auth) +static int tpm_buf_append_salt (struct tpm_buf *buf,struct tpm_chip *chip, +struct tpm2_auth *auth) {struct crypto_kpp *kpp;struct kpp_request *req; +DECLARE_CRYPTO_WAIT (wait);struct scatterlist s[2 ], d[1 ];struct ecdh p = {0 };u8 encoded_key[EC_PT_SZ ], *x, *y;unsigned int buf_len; +int rc;/* secret is two sized points */ tpm_buf_append_u16 (buf, (EC_PT_SZ +2 )*2 );
@@ -521,14 +523,15 @@ static void tpm_buf_append_salt(struct t kpp =crypto_alloc_kpp ("ecdh-nist-p256" ,CRYPTO_ALG_INTERNAL ,0 );if (IS_ERR (kpp)) {dev_err (&chip->dev,"crypto ecdh allocation failed\n" ); -return ; +return PTR_ERR (kpp); } buf_len =crypto_ecdh_key_len (&p);if (sizeof (encoded_key) < buf_len) {dev_err (&chip->dev,"salt buffer too small needs %d\n" , buf_len); - goto out; + rc = -EINVAL ; + goto err_free_kpp; }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */
@@ -536,11 +539,17 @@ static void tpm_buf_append_salt(struct t/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL ); -if (!req) - goto out; +if (!req) { + rc = -ENOMEM ; + goto err_free_kpp; + } +kpp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait);kpp_request_set_input (req,NULL ,0 );kpp_request_set_output (req, s,EC_PT_SZ *2 ); -crypto_kpp_generate_public_key (req); + rc =crypto_wait_req (crypto_kpp_generate_public_key (req), &wait); +if (rc) + goto err_free_req;/* * we're not done: now we have to compute the shared secret * which is our private key multiplied by the tpm_key public
@@ -552,8 +561,9 @@ static void tpm_buf_append_salt(struct tkpp_request_set_input (req, s,EC_PT_SZ *2 );sg_init_one (d, auth->salt,EC_PT_SZ );kpp_request_set_output (req, d,EC_PT_SZ ); -crypto_kpp_compute_shared_secret (req); -kpp_request_free (req); + rc =crypto_wait_req (crypto_kpp_compute_shared_secret (req), &wait); +if (rc) + goto err_free_req;/* * pass the shared secret through KDFe for salt. Note salt
@@ -563,8 +573,16 @@ static void tpm_buf_append_salt(struct t*/ tpm2_KDFe (auth->salt,"SECRET" , x, chip->null_ec_key_x, auth->salt); - out: +kpp_request_free (req);crypto_free_kpp (kpp); +return 0 ; + +err_free_req: +kpp_request_free (req); + +err_free_kpp: +crypto_free_kpp (kpp); +return rc; }/**
@@ -1019,7 +1037,12 @@ int tpm2_start_auth_session(struct tpm_ctpm_buf_append (&buf, auth->our_nonce,sizeof (auth->our_nonce));/* append encrypted salt and squirrel away unencrypted in auth */ -tpm_buf_append_salt (&buf, chip, auth); + rc =tpm_buf_append_salt (&buf, chip, auth); +if (rc) { +tpm2_flush_context (chip, null_key); +tpm_buf_destroy (&buf); + goto out; + }/* session type (HMAC, audit or policy) */ tpm_buf_append_u8 (&buf,TPM2_SE_HMAC );
Greg Kroah-Hartman
maintainerPATCH 1293/1611 sunrpc: fix uninitialized xprt_create_args structure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
commit 17d90b68c3a3d7d7e95b49e1fe9381a723f637a8 upstream.
The xprt_create_args structure is allocated on the stack without initialization in rpc_sysfs_xprt_switch_add_xprt_store(). While some fields are manually populated, critical fields like srcaddr, bc_xps, and flags contain uninitialized stack garbage.
This can lead to:
1. Kernel panic when xs_setup_xprt() dereferences garbage srcaddr
2. Information leak if srcaddr points to sensitive stack data
3. Unpredictable behavior if flags has random bits set
The fix is to zero-initialize the structure to ensure all unused fields are NULL/0, preventing the transport setup code from acting on garbage data.
--- net/sunrpc/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/sysfs.c +1 -1
@@ -326,7 +326,7 @@ static ssize_t rpc_sysfs_xprt_switch_add {struct rpc_xprt_switch *xprt_switch =rpc_sysfs_xprt_switch_kobj_get_xprt (kobj); -struct xprt_create xprt_create_args; +struct xprt_create xprt_create_args = {};struct rpc_xprt *xprt, *new;if (!xprt_switch)
Greg Kroah-Hartman
maintainerPATCH 1294/1611 dmaengine: tegra: Fix burst size calculation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kartik Rajput <[email protected]>
commit 4651df83b6c796daead3447e8fd874322918ee4f upstream.
Currently, the Tegra GPC DMA hardware requires the transfer length to be a multiple of the max burst size configured for the channel. When a client requests a transfer where the length is not evenly divisible by the configured max burst size, the DMA hangs with partial burst at the end.
Fix this by reducing the burst size to the largest power-of-2 value that evenly divides the transfer length. For example, a 40-byte transfer with a 16-byte max burst will now use an 8-byte burst (40 / 8 = 5 complete bursts) instead of causing a hang.
This issue was observed with the PL011 UART driver where TX DMA transfers of arbitrary lengths were stuck.
--- drivers/dma/tegra186-gpc-dma.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/dma/tegra186-gpc-dma.c +7 -0
@@ -825,6 +825,13 @@ static unsigned int get_burst_size(struc* len to calculate the optimum burst size */ burst_byte = burst_size ? burst_size * slave_bw : len; + +/* +* Find the largest burst size that evenly divides the transfer length. +* The hardware requires the transfer length to be a multiple of the +* burst size - partial bursts are not supported. +*/ + burst_byte =min (burst_byte,1U <<__ffs (len)); burst_mmio_width = burst_byte /4 ;if (burst_mmio_width <TEGRA_GPCDMA_MMIOSEQ_BURST_MIN )
Greg Kroah-Hartman
maintainerPATCH 1295/1611 dmaengine: dw-edma: Add spinlock to protect DONE_INT_MASK and ABORT_INT_MASK
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Li <[email protected]>
commit 8ffba0171c6bbce5f093c6dba5a02c0805b31203 upstream.
The DONE_INT_MASK and ABORT_INT_MASK registers are shared by all DMA channels, and modifying them requires a read-modify-write sequence. Because this operation is not atomic, concurrent calls to dw_edma_v0_core_start() can introduce race conditions if two channels update these registers simultaneously.
Add a spinlock to serialize access to these registers and prevent race conditions.
--- drivers/dma/dw-edma/dw-edma-core.h | 2 +- drivers/dma/dw-edma/dw-edma-v0-core.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/dma/dw-edma/dw-edma-core.h +1 -1
@@ -108,7 +108,7 @@ struct dw_edma {struct dw_edma_chan *chan; -raw_spinlock_t lock;/* Only for legacy */ +raw_spinlock_t lock;/* Protect v0 shared registers */ struct dw_edma_chip *chip;
drivers/dma/dw-edma/dw-edma-v0-core.c +6 -0
@@ -364,6 +364,7 @@ static void dw_edma_v0_core_start(struct {struct dw_edma_chan *chan = chunk->chan;struct dw_edma *dw = chan->dw; +unsigned long flags;u32 tmp;dw_edma_v0_core_write_chunk (chunk);
@@ -408,6 +409,8 @@ static void dw_edma_v0_core_start(struct } }/* Interrupt unmask - done, abort */ +raw_spin_lock_irqsave (&dw->lock, flags); + tmp =GET_RW_32 (dw, chan->dir, int_mask); tmp &= ~FIELD_PREP (EDMA_V0_DONE_INT_MASK ,BIT (chan->id)); tmp &= ~FIELD_PREP (EDMA_V0_ABORT_INT_MASK ,BIT (chan->id));
@@ -416,6 +419,9 @@ static void dw_edma_v0_core_start(struct tmp =GET_RW_32 (dw, chan->dir, linked_list_err_en); tmp |=FIELD_PREP (EDMA_V0_LINKED_LIST_ERR_MASK ,BIT (chan->id));SET_RW_32 (dw, chan->dir, linked_list_err_en, tmp); + +raw_spin_unlock_irqrestore (&dw->lock, flags); +/* Channel control */ SET_CH_32 (dw, chan->dir, chan->id, ch_control1, (DW_EDMA_V0_CCS |DW_EDMA_V0_LLE ));
Greg Kroah-Hartman
maintainerPATCH 1296/1611 platform/x86: dell-laptop: fix missing cleanups in init error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 6e9cab2247e5b243ae2d907ce7c948a8a9c8d61a upstream.
dell_init() initializes several resources after dell_setup_rfkill(), including the optional touchpad LED, keyboard backlight LED, battery hook, debugfs directory and dell-laptop notifier.
If a later LED or backlight registration fails, the error path only tears down the battery hook and rfkill resources. This leaves the notifier, debugfs directory, keyboard backlight LED and optional touchpad LED registered after dell_init() returns an error.
Add the missing cleanup calls before tearing down rfkill.
--- drivers/platform/x86/dell/dell-laptop.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/platform/x86/dell/dell-laptop.c +5 -0
@@ -2551,7 +2551,12 @@ fail_backlight:if (mute_led_registered)led_classdev_unregister (&mute_led_cdev); fail_led: +dell_laptop_unregister_notifier (&dell_laptop_notifier); +debugfs_remove_recursive (dell_laptop_dir);dell_battery_exit (); +kbd_led_exit (); +if (quirks && quirks->touchpad_led) +touchpad_led_exit ();dell_cleanup_rfkill (); fail_rfkill:platform_device_del (platform_device);
Greg Kroah-Hartman
maintainerPATCH 1297/1611 platform/x86: ISST: Restore SST-PP control to all domains
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
commit 2565a28cdcdcb035e151d285efcba26bccb3726e upstream.
The SST-PP control offset is only restored to power domain 0 after resume. During suspend, control values are read and stored for all power domains.
Use pd_info->sst_base instead of power_domain_info->sst_base, which only points to power domain 0 base address.
--- drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +1 -1
@@ -1786,7 +1786,7 @@ void tpmi_sst_dev_resume(struct auxiliarmemcpy_toio (cp_base +SST_CLOS_ASSOC_0_OFFSET , pd_info->saved_clos_assocs,sizeof (pd_info->saved_clos_assocs)); -writeq (pd_info->saved_pp_control, power_domain_info->sst_base + +writeq (pd_info->saved_pp_control, pd_info->sst_base + pd_info->sst_header.pp_offset +SST_PP_CONTROL_OFFSET ); } }
Greg Kroah-Hartman
maintainerPATCH 1298/1611 platform/x86/amd/pmc: Check for intermediate wakeup in function
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Gibson <[email protected]>
commit 3bdd6fc11fbfa8249483f4b716ead51e43e3a0cd upstream.
Refactor code introduced by commit 9f5595d5f03f ("pmc: Require at least 2.5 seconds between HW sleep cycles") to allow adding different conditions for that delay in an upcoming change.
--- drivers/platform/x86/amd/pmc/pmc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/pmc/pmc.c +14 -3
@@ -598,6 +598,19 @@ static int amd_pmc_verify_czn_rtc(structreturn rc; } +static bool amd_pmc_intermediate_wakeup_need_delay (struct amd_pmc_dev *pdev) +{ +/* +* Starting a new HW sleep cycle right after waking from one +* can cause electrical problems triggering the over voltage protection. +* That is avoided by delaying the next suspend a bit, see also +* https://lore.kernel.org/all/[email protected]/ +*/ +struct smu_metrics table; + +return get_metrics_table (pdev, &table) ==0 && table.s0i3_last_entry_status; +} +static void amd_pmc_s2idle_prepare (void ) {struct amd_pmc_dev *pdev = &pmc;
@@ -632,11 +645,9 @@ static void amd_pmc_s2idle_prepare(void)static void amd_pmc_s2idle_check (void ) {struct amd_pmc_dev *pdev = &pmc; -struct smu_metrics table;int rc; -/* Avoid triggering OVP */ -if (!get_metrics_table (pdev, &table) && table.s0i3_last_entry_status) +if (amd_pmc_intermediate_wakeup_need_delay (pdev))msleep (2500 );/* Dump the IdleMask before we add to the STB */
Greg Kroah-Hartman
maintainerPATCH 1299/1611 platform/x86/amd/pmc: Delay suspend for some Lenovo Laptops
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Gibson <[email protected]>
commit 9b9e60dd31da054a37d601e9fcabdfd8a2bff354 upstream.
Some IdeaPad Slim 3 devices and similar with AMD CPUs have a nonfunctional keyboard and lid switch after s2idle.
It helps to delay suspend by 2.5 seconds so the EC has some time to do whatever it needs to get done before suspend - unfortunately at least on my 16ABR8 waking it with a timer (wakealarm) still triggers the issue, but at least normal resume via keypress or lid works fine. On the 14ARP10 wakealarm has been reported to also work fine with this patch.
This issue has been reported for many different devices, this patch has been tested with the Zen3-based IdeaPad Slim 3 16ABR8 (82XR) and the Zen3+-based IdeaPad Slim 3 14ARP10 (83K6) and IdeaPad Slim 3 15ARP10 (83MM).
--- drivers/platform/x86/amd/pmc/pmc-quirks.c | 39 ++++++++++++++++++++++++++++++ drivers/platform/x86/amd/pmc/pmc.c | 24 +++++++++++++++++- drivers/platform/x86/amd/pmc/pmc.h | 1 3 files changed, 63 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/pmc/pmc-quirks.c +39 -0
@@ -18,6 +18,7 @@struct quirk_entry {u32 s2idle_bug_mmio;bool spurious_8042; +bool need_suspend_delay; };static struct quirk_entry quirk_s2idle_bug = {
@@ -33,6 +34,10 @@ static struct quirk_entry quirk_s2idle_s .spurious_8042 = true, }; +static struct quirk_entry quirk_s2idle_need_suspend_delay = { + .need_suspend_delay = true, +}; +static const struct dmi_system_id fwbug_list[] = { { .ident ="L14 Gen2 AMD" ,
@@ -203,6 +208,35 @@ static const struct dmi_system_id fwbug_ DMI_MATCH(DMI_PRODUCT_NAME, "82XQ"), } }, +/* https://bugzilla.kernel.org/show_bug.cgi?id=221383 */ + { + .ident = "Zen3-based IdeaPad Slim and similar", + .driver_data = &quirk_s2idle_need_suspend_delay, + .matches = { +DMI_MATCH (DMI_BOARD_VENDOR ,"LENOVO" ), +/* +* Note: there are also some Zen2-based 82X* devices that +* need different quirks, they're already handled above +*/ + DMI_MATCH(DMI_PRODUCT_NAME, "82X"), + } + }, + { + .ident ="Zen3+-based IdeaPad Slim and similar" , + .driver_data = &quirk_s2idle_need_suspend_delay, + .matches = { +DMI_MATCH (DMI_BOARD_VENDOR ,"LENOVO" ), + DMI_MATCH(DMI_PRODUCT_NAME, "83K"), + } + }, + { + .ident ="IdeaPad Slim 3 15ARP10 (83MM)" , + .driver_data = &quirk_s2idle_need_suspend_delay, + .matches = { +DMI_MATCH (DMI_BOARD_VENDOR ,"LENOVO" ), + DMI_MATCH(DMI_PRODUCT_NAME, "83MM"), + } + }, /* https://bugzilla.kernel.org/show_bug.cgi?id=221273 */ { .ident = "Thinkpad L14 Gen3",
@@ -356,6 +390,11 @@ void amd_pmc_process_restore_quirks(struamd_pmc_skip_nvme_smi_handler (dev->quirks->s2idle_bug_mmio); } +bool amd_pmc_quirk_need_suspend_delay (struct amd_pmc_dev *dev) +{ +return dev->quirks && dev->quirks->need_suspend_delay; +} +void amd_pmc_quirks_init (struct amd_pmc_dev *dev) {const struct dmi_system_id *dmi_id;
drivers/platform/x86/amd/pmc/pmc.c +23 -1
@@ -611,6 +611,27 @@ static bool amd_pmc_intermediate_wakeup_return get_metrics_table (pdev, &table) ==0 && table.s0i3_last_entry_status; } +static bool amd_pmc_want_suspend_delay (struct amd_pmc_dev *pdev) +{ +/* +* Some Lenovo Laptops (like different IdeaPad 3 Slims) need some +* me-time before sleeping or they get uncooperative after waking +* up and don't send events for keyboard and lid switch anymore. +* +* Unfortunately this doesn't entirely fix the problem: It can still +* happen when resuming with a timer (wakealarm), but at least the +* more common usecases (wakeup by opening lid or pressing a key) +* work fine with this workaround. +* +* See https://bugzilla.kernel.org/show_bug.cgi?id=221383 +*/ +if (!disable_workarounds &&amd_pmc_quirk_need_suspend_delay (pdev)) { +dev_info (pdev->dev,"Delaying suspend by 2.5s to avoid platform bug\n" ); +return true; + } +return false; +} +static void amd_pmc_s2idle_prepare (void ) {struct amd_pmc_dev *pdev = &pmc;
@@ -647,7 +668,8 @@ static void amd_pmc_s2idle_check(void)struct amd_pmc_dev *pdev = &pmc;int rc; -if (amd_pmc_intermediate_wakeup_need_delay (pdev)) +if (amd_pmc_intermediate_wakeup_need_delay (pdev) || +amd_pmc_want_suspend_delay (pdev))msleep (2500 );/* Dump the IdleMask before we add to the STB */
drivers/platform/x86/amd/pmc/pmc.h +1 -0
@@ -147,6 +147,7 @@ enum amd_pmc_def { };void amd_pmc_process_restore_quirks (struct amd_pmc_dev *dev); +bool amd_pmc_quirk_need_suspend_delay (struct amd_pmc_dev *dev);void amd_pmc_quirks_init (struct amd_pmc_dev *dev);void amd_mp2_stb_init (struct amd_pmc_dev *dev);void amd_mp2_stb_deinit (struct amd_pmc_dev *dev);
Greg Kroah-Hartman
maintainerPATCH 1300/1611 platform/x86/amd/pmc: Add delay_suspend module parameter
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Gibson <[email protected]>
commit 428b9fd2dce50b4dc5cd9ade10b92efcf57ce7aa upstream.
Enabling the new delay_suspend module parameter delays suspend for 2.5 seconds which is known to help for some AMD-based Lenovo Laptops that otherwise failed to send/receive events for key presses or the lid switch after s2idle. Apparently the EC needs to do some things in the background before suspend or it gets into a bad state.
There are many reports of AMD-based laptops (mostly but not exclusively IdeaPads) about similar issues on the web; this parameter gives affected users an easy way to try out if their issues have the same root cause and to work around them until their specific device is added to the quirks list.
The parameter description has a note encouraging users to report their device so it can be added to the quirks list, inspired by a similar request in parameter descriptions of the ideapad-laptop module.
The module parameter can be set to "1" to explicitly enable it, "0" to disable it even on devices that are assumed to be affected, or -1 (the default) to enable it if the device is assumed to be affected (according to fwbug_list[])
--- drivers/platform/x86/amd/pmc/pmc.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
drivers/platform/x86/amd/pmc/pmc.c +23 -2
@@ -16,6 +16,7 @@#include <linux/bits.h> #include <linux/debugfs.h> #include <linux/delay.h> +#include <linux/dmi.h> #include <linux/io.h> #include <linux/iopoll.h> #include <linux/limits.h>
@@ -89,6 +90,11 @@ static bool disable_workarounds;module_param (disable_workarounds, bool,0644 );MODULE_PARM_DESC (disable_workarounds,"Disable workarounds for platform bugs" ); +static int delay_suspend =-1 ; +module_param (delay_suspend, int,0644 ); +MODULE_PARM_DESC (delay_suspend, +"Delays s2idle by 2.5 seconds to work around buggy ECs, often causing keyboard issues after suspend. 0: don't delay, 1: do delay, -1 (default): let amd_pmc decide. If you need this please report this to: [email protected]" ); +static struct amd_pmc_dev pmc;static inline u32 amd_pmc_reg_read (struct amd_pmc_dev *dev,int reg_offset)
@@ -625,8 +631,23 @@ static bool amd_pmc_want_suspend_delay(s* * See https://bugzilla.kernel.org/show_bug.cgi?id=221383 */ -if (!disable_workarounds &&amd_pmc_quirk_need_suspend_delay (pdev)) { -dev_info (pdev->dev,"Delaying suspend by 2.5s to avoid platform bug\n" ); +if (amd_pmc_quirk_need_suspend_delay (pdev)) { +/* +* delay_suspend=1 force-enables this, otherwise it can be +* disabled with disable_workarounds or delay_suspend=0 +*/ +if (delay_suspend ==1 || (delay_suspend ==-1 && !disable_workarounds)) { +dev_info (pdev->dev,"Delaying suspend by 2.5s to avoid platform bug\n" ); +return true; + } +dev_info (pdev->dev,"Not delaying suspend because of module parameter, even though your device is assumed to need it!\n" ); + }else if (delay_suspend ==1 ) { +dev_info (pdev->dev,"Delaying suspend by 2.5s because delay_suspend=1. If this solves problems on your machine, please report this whole line to: [email protected] so it can be automatically detected as affected in the future. System Vendor: \"%s\" Product Name: \"%s\" Product Family: \"%s\" Board Vendor: \"%s\" Board Name: \"%s\"\n" , +dmi_get_system_info (DMI_SYS_VENDOR ), +dmi_get_system_info (DMI_PRODUCT_NAME ), +dmi_get_system_info (DMI_PRODUCT_FAMILY ), +dmi_get_system_info (DMI_BOARD_VENDOR ), +dmi_get_system_info (DMI_BOARD_NAME ));return true; }return false;
Greg Kroah-Hartman
maintainerPATCH 1301/1611 platform/x86/amd/pmc: Dont log during intermediate wakeups
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Gibson <[email protected]>
commit 037f0b03c663a247366673a807834389107995b7 upstream.
The ECs in the IdeaPads that need the delay_suspend quirk send lots of messages when charging, which not only causes intermediate wakeups when suspended, but also prevents the device from reaching the deepest suspend state.
Because of this amd_pmc_intermediate_wakeup_need_delay() returns false during intermediate wakeups and amd_pmc_want_suspend_delay() is called. So far it always logged its "Delaying suspend by 2.5s ..." messages then, which spams dmesg. This commit makes sure that those messages are only logged once per suspend.
--- drivers/platform/x86/amd/pmc/pmc.c | 39 +++++++++++++++++++++++++++++-------- drivers/platform/x86/amd/pmc/pmc.h | 1 2 files changed, 32 insertions(+), 8 deletions(-)
drivers/platform/x86/amd/pmc/pmc.c +31 -8
@@ -620,6 +620,20 @@ static bool amd_pmc_intermediate_wakeup_static bool amd_pmc_want_suspend_delay (struct amd_pmc_dev *pdev) {/* +* intermediate_wakeup implies that the machine didn't get to deepest sleep +* state before - otherwise this function isn't called in amd_pmc_s2idle_check() +* because amd_pmc_intermediate_wakeup_need_delay() returns true first. +* On some IdeaPads that happens when charging, because the EC seems +* to send lots of messages then that wake the machine. +* +* But even in that case, the sleep here is necessary (on those IdeaPads), +* otherwise they wake up completely (resume) after a few seconds. +* So this variable is only used to avoid spamming dmesg on each +* intermediate wakeup. +*/ +bool intermediate_wakeup = !pdev->is_first_check_after_suspend; + +/* * Some Lenovo Laptops (like different IdeaPad 3 Slims) need some * me-time before sleeping or they get uncooperative after waking * up and don't send events for keyboard and lid switch anymore.
@@ -637,17 +651,20 @@ static bool amd_pmc_want_suspend_delay(s* disabled with disable_workarounds or delay_suspend=0 */ if (delay_suspend ==1 || (delay_suspend ==-1 && !disable_workarounds)) { -dev_info (pdev->dev,"Delaying suspend by 2.5s to avoid platform bug\n" ); +if (!intermediate_wakeup) +dev_info (pdev->dev,"Delaying suspend by 2.5s to avoid platform bug\n" );return true; } -dev_info (pdev->dev,"Not delaying suspend because of module parameter, even though your device is assumed to need it!\n" ); +if (!intermediate_wakeup) +dev_info (pdev->dev,"Not delaying suspend because of module parameter, even though your device is assumed to need it!\n" ); }else if (delay_suspend ==1 ) { -dev_info (pdev->dev,"Delaying suspend by 2.5s because delay_suspend=1. If this solves problems on your machine, please report this whole line to: [email protected] so it can be automatically detected as affected in the future. System Vendor: \"%s\" Product Name: \"%s\" Product Family: \"%s\" Board Vendor: \"%s\" Board Name: \"%s\"\n" , -dmi_get_system_info (DMI_SYS_VENDOR ), -dmi_get_system_info (DMI_PRODUCT_NAME ), -dmi_get_system_info (DMI_PRODUCT_FAMILY ), -dmi_get_system_info (DMI_BOARD_VENDOR ), -dmi_get_system_info (DMI_BOARD_NAME )); +if (!intermediate_wakeup) +dev_info (pdev->dev,"Delaying suspend by 2.5s because delay_suspend=1. If this solves problems on your machine, please report this whole line to: [email protected] so it can be automatically detected as affected in the future. System Vendor: \"%s\" Product Name: \"%s\" Product Family: \"%s\" Board Vendor: \"%s\" Board Name: \"%s\"\n" , +dmi_get_system_info (DMI_SYS_VENDOR ), +dmi_get_system_info (DMI_PRODUCT_NAME ), +dmi_get_system_info (DMI_PRODUCT_FAMILY ), +dmi_get_system_info (DMI_BOARD_VENDOR ), +dmi_get_system_info (DMI_BOARD_NAME ));return true; }return false;
@@ -660,6 +677,9 @@ static void amd_pmc_s2idle_prepare(void)u8 msg;u32 arg =1 ; +/* Reset this variable because this is a fresh suspend */ + pdev->is_first_check_after_suspend = true; +/* Reset and Start SMU logging - to monitor the s0i3 stats */ amd_pmc_setup_smu_logging (pdev);
@@ -699,6 +719,9 @@ static void amd_pmc_s2idle_check(void) rc =amd_stb_write (pdev,AMD_PMC_STB_S2IDLE_CHECK );if (rc)dev_err (pdev->dev,"error writing to STB: %d\n" , rc); + +/* remember that first check after suspend is done (until next prepare) */ + pdev->is_first_check_after_suspend = false; }static int amd_pmc_dump_data (struct amd_pmc_dev *pdev)
drivers/platform/x86/amd/pmc/pmc.h +1 -0
@@ -114,6 +114,7 @@ struct amd_pmc_dev {struct dentry *dbgfs_dir;struct quirk_entry *quirks;bool disable_8042_wakeup; +bool is_first_check_after_suspend;struct amd_mp2_dev *mp2;struct stb_arg stb_arg; };
Greg Kroah-Hartman
maintainerPATCH 1302/1611 pkey: Move keytype check from pkey api to handler
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Holger Dengler <[email protected]>
commit 754e9e49b76fd5be339172aa98544182ed3ca75e upstream.
The PKEY_VERIFYPROTK ioctl takes data from user-space and verifies the contained protected key. While checking the integrity of the ioctl request structure is the responsibility of the generic pkey_api code, the verification of the contained protected key is the responsibility of the pkey handler.
The keytype verification (based on the calculated bitsize of the key) is part of the protected key verification and therefore the responsibility of the pkey handler (which already verifies it). Therefore the keytype verification is removed from the generic pkey_api code.
As the calculation of the key bitsize is currently wrong, the removal of the keytype check in pkey_api also removes this wrong calculation. For this reason, the commit is flagged with the Fixes:
tag.
--- drivers/s390/crypto/pkey_api.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/s390/crypto/pkey_api.c +1 -10
@@ -328,7 +328,6 @@ static int pkey_ioctl_verifyprotk(struct {struct pkey_verifyprotk kvp;struct protaeskeytoken *t; -u32 keytype;u8 *tmpbuf;int rc;
@@ -342,14 +341,6 @@ static int pkey_ioctl_verifyprotk(structreturn -EINVAL ; } - keytype =pkey_aes_bitsize_to_keytype (8 * kvp.protkey.len); -if (!keytype) { -PKEY_DBF_ERR ("%s unknown/unsupported protkey length %u\n" , - __func__, kvp.protkey.len); -memzero_explicit (&kvp,sizeof (kvp)); -return -EINVAL ; - } -/* build a 'protected key token' from the raw protected key */ tmpbuf =kzalloc (sizeof (*t),GFP_KERNEL );if (!tmpbuf) {
@@ -359,7 +350,7 @@ static int pkey_ioctl_verifyprotk(struct t = (struct protaeskeytoken *)tmpbuf; t->type =TOKTYPE_NON_CCA ; t->version =TOKVER_PROTECTED_KEY ; - t->keytype = keytype; + t->keytype = kvp.protkey.type; t->len = kvp.protkey.len;memcpy (t->protkey, kvp.protkey.protkey, kvp.protkey.len);
Greg Kroah-Hartman
maintainerPATCH 1303/1611 smb: client: use kvzalloc() for megabyte buffer in simple fallocate
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fredric Cover <[email protected]>
commit 806c00c23e3ce8eae397a40ced536ef88ae4e012 upstream.
Currently in smb3_simple_fallocate_range(), a 1 MB buffer is allocated using kzalloc(). Under heavy memory fragmentation, a contiguous 1 MB block of physical memory (an order-8 allocation) may not be available, causing the allocation to fail.
This failure was observed during xfstests generic/013 on a 4GB RAM test machine running fsstress:
fsstress: page allocation failure: order:8,
mode:0x40dc0(GFP_KERNEL|__GFP_ZERO|__GFP_COMP),
nodemask=(null),cpuset=/,mems_allowed=0
Call Trace: <TASK> dump_stack_lvl+0x5d/0x80 warn_alloc+0x163/0x190 __alloc_pages_slowpath.constprop.0+0x71b/0x12f0 __alloc_frozen_pages_noprof+0x2f6/0x340 alloc_pages_mpol+0xb6/0x170 ___kmalloc_large_node+0xb3/0xd0 __kmalloc_large_noprof+0x1e/0xc0 smb3_simple_falloc.isra.0+0x62b/0x960 cifs_fallocate+0xed/0x180 vfs_fallocate+0x165/0x3c0 __x64_sys_fallocate+0x48/0xa0 do_syscall_64+0xe1/0x640 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK>
Node 0 Normal: 3375*4kB ... 7*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB
Since this scratch buffer does not require physically contiguous memory, switch the allocation to kvzalloc(). This retains the performance benefits of kmalloc() under normal conditions, while gracefully falling back to virtually contiguous memory when physical allocation fails.
--- fs/smb/client/smb2ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/smb2ops.c +2 -2
@@ -3560,7 +3560,7 @@ static int smb3_simple_fallocate_range(uif (rc) goto out; - buf =kzalloc (1024 *1024 ,GFP_KERNEL ); + buf =kvzalloc (1024 *1024 ,GFP_KERNEL );if (buf ==NULL ) { rc = -ENOMEM ; goto out;
@@ -3617,7 +3617,7 @@ static int smb3_simple_fallocate_range(u out:kfree (out_data); -kfree (buf); +kvfree (buf);return rc; }
Greg Kroah-Hartman
maintainerPATCH 1304/1611 ksmbd: fix integer overflow in set_file_allocation_info()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
commit 1c0ae3df692ea2a4ce992f786346154e75a3f0d5 upstream.
set_file_allocation_info() converts the client-supplied FILE_ALLOCATION_INFORMATION::AllocationSize into a 512-byte block count with:
alloc_blks = (le64_to_cpu(file_alloc_info->AllocationSize) + 511) >> 9;
AllocationSize is a fully client-controlled __le64 field; the only validation performed by the caller (smb2_set_info_file(), case FILE_ALLOCATION_INFORMATION) is that the fixed buffer is at least sizeof(struct smb2_file_alloc_info) == 8 bytes. The value itself is never range-checked before this arithmetic.
When AllocationSize is close to U64_MAX (e.g. 0xffffffffffffffff), "AllocationSize + 511" wraps around mod 2^64 to a small number (0xffffffffffffffff + 511 = 510), so alloc_blks becomes 0. Since any existing regular file has stat.blocks > 0, the function then takes the "shrink" branch and calls:
ksmbd_vfs_truncate(work, fp, alloc_blks * 512); /* == 0 */
silently truncating the file to size 0, even though the client asked to grow the allocation to (what looks like) the maximum possible size. The trailing "if (size < alloc_blks * 512) i_size_write(inode, size);" restore is guarded by a comparison that is never true once alloc_blks == 0, so the truncation is not undone. This lets an authenticated SMB client that already holds an open handle with FILE_WRITE_DATA on a file silently truncate that same file to size 0 via a single crafted SET_INFO(FILE_ALLOCATION_INFORMATION) request advertising a near-U64_MAX AllocationSize, even though the request asks to grow the file's allocation rather than shrink it. This is a functional/data-loss bug, not a privilege-boundary
violation: the same client could already truncate the file via FILE_END_OF_FILE_INFORMATION or a plain write.
Fix it by validating AllocationSize against MAX_LFS_FILESIZE, the same upper bound the VFS itself uses to reject unrepresentable file sizes, before doing the "+511" rounding, and rejecting oversized values with -EINVAL. Bounding AllocationSize to MAX_LFS_FILESIZE - 511 guarantees the "+511" addition cannot wrap, and that the subsequent "alloc_blks * 512" values passed to vfs_fallocate() and ksmbd_vfs_truncate() stay within a representable loff_t as well.
No legitimate SMB client asks for an allocation size anywhere near 2^64 bytes, so this only rejects a value that was previously silently misinterpreted as zero.
Runtime-verified on a v6.19 KASAN test stand: sending SET_INFO (FILE_ALLOCATION_INFORMATION) with AllocationSize = 0xffffffffffffffff against ksmbd now returns -EINVAL and leaves the target file's size unchanged, where the unpatched kernel truncated it from 4096 to 0 bytes.
--- fs/smb/server/smb2pdu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +14 -1
@@ -6347,6 +6347,7 @@ static int set_file_allocation_info(stru*/ loff_t alloc_blks; +u64 alloc_size;struct inode *inode;struct kstat stat;int rc;
@@ -6362,7 +6363,19 @@ static int set_file_allocation_info(struif (rc)return rc; - alloc_blks = (le64_to_cpu (file_alloc_info->AllocationSize) +511 ) >>9 ; +/* +* AllocationSize is fully client-controlled (the caller only +* validates the fixed 8-byte buffer length). Reject values that +* would overflow the "round up to 512-byte blocks" conversion +* below instead of silently wrapping it to a tiny block count, +* which would truncate the file to a size the client never +* asked for. +*/ + alloc_size =le64_to_cpu (file_alloc_info->AllocationSize); +if (alloc_size >MAX_LFS_FILESIZE -511 ) +return -EINVAL ; + + alloc_blks = (alloc_size +511 ) >>9 ; inode =file_inode (fp->filp);if (alloc_blks > stat.blocks) {
Greg Kroah-Hartman
maintainerPATCH 1305/1611 hwmon: (ltc2992) add missing select REGMAP_I2C to Kconfig
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joshua Crofts <[email protected]>
commit a35a6f1b20100057c66b7be5a8f6864661c3945c upstream.
The Kconfig entry for the LTC2992 sensor doesn't contain a select REGMAP_I2C parameter, causing build failures if regmap isn't selected previously during the build process.
--- drivers/hwmon/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/hwmon/Kconfig +1 -0
@@ -1086,6 +1086,7 @@ config SENSORS_LTC2992 tristate "Linear Technology LTC2992" depends on I2C depends on GPIOLIB + select REGMAP_I2C help If you say yes here you get support for Linear Technology LTC2992 I2C System Monitor. The LTC2992 measures current, voltage, and
Greg Kroah-Hartman
maintainerPATCH 1306/1611 hwmon: (max6697) add missing select REGMAP_I2C to Kconfig
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joshua Crofts <[email protected]>
commit ed576f2f4eef8cbe2c110da503825a8dc4717030 upstream.
The Kconfig entry for the MAX6697 sensor doesn't contain a select REGMAP_I2C parameter, causing build failures if regmap isn't selected previously during the build process.
--- drivers/hwmon/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/hwmon/Kconfig +1 -0
@@ -1331,6 +1331,7 @@ config SENSORS_MAX6650 config SENSORS_MAX6697 tristate "Maxim MAX6697 and compatibles" depends on I2C + select REGMAP_I2C help If you say yes here you get support for MAX6581, MAX6602, MAX6622, MAX6636, MAX6689, MAX6693, MAX6694, MAX6697, MAX6698, and MAX6699
Greg Kroah-Hartman
maintainerPATCH 1307/1611 i2c: imx: fix locked bus on SMBus block-read of 0 (atomic)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
commit cb2fc37857693b55909fb77dc2c87cfbc1cdc476 upstream.
SMBus 3.1 6.5.7 allows a Block Read byte count of 0, but the atomic (polling) path rejects it as -EPROTO. Worse, it returns without a NACK+STOP: the next receive cycle has already started, so the target keeps holding SDA and the bus stays stuck until a power cycle for this i2c controller.
Reading I2DR to obtain the count likewise arms the next byte on the count > I2C_SMBUS_BLOCK_MAX path, which also returned -EPROTO directly and left the bus held.
Handle both: NACK the in-flight dummy byte (TXAK) and extend msgs->len so the existing last-byte handling emits STOP; the dummy byte is discarded. A count of 0 is a valid empty block read; a count above I2C_SMBUS_BLOCK_MAX is still reported as -EPROTO, but only after the bus has been released.
The interrupt-driven path has the same flaw from a later commit and is fixed separately, as it carries a different Fixes: tag and stable range.
--- drivers/i2c/busses/i2c-imx.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-imx.c +16 -3
@@ -1415,6 +1415,7 @@ static int i2c_imx_atomic_read(struct imint i, result;unsigned int temp;int block_data = msgs->flags &I2C_M_RECV_LEN ; +int block_err =0 ; result =i2c_imx_prepare_read (i2c_imx, msgs, false);if (result)
@@ -1436,8 +1437,20 @@ static int i2c_imx_atomic_read(struct im*/ if ((!i) && block_data) { len =imx_i2c_read_reg (i2c_imx,IMX_I2C_I2DR ); -if ((len ==0 ) || (len >I2C_SMBUS_BLOCK_MAX )) -return -EPROTO ; +if ((len ==0 ) || (len >I2C_SMBUS_BLOCK_MAX )) { +/* +* SMBus 3.1 6.5.7: support count byte of 0. +* I2C_SMBUS_BLOCK_MAX case should not hold the SDA either. +*/ +if (len >I2C_SMBUS_BLOCK_MAX ) + block_err = -EPROTO ; + temp =imx_i2c_read_reg (i2c_imx,IMX_I2C_I2CR ); + temp |=I2CR_TXAK ; +imx_i2c_write_reg (temp, i2c_imx,IMX_I2C_I2CR ); + msgs->buf[0 ] =0 ; + msgs->len =2 ; +continue ; + }dev_dbg (&i2c_imx->adapter.dev,"<%s> read length: 0x%X\n" , __func__, len);
@@ -1485,7 +1498,7 @@ static int i2c_imx_atomic_read(struct im"<%s> read byte: B%d=0x%X\n" , __func__, i, msgs->buf[i]); } -return 0 ; +return block_err; } static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs,
Greg Kroah-Hartman
maintainerPATCH 1308/1611 i2c: imx: fix locked bus on SMBus block-read of 0 (IRQ)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
commit 07fd9385f0d87dff4b34f355f68adf701080cb24 upstream.
SMBus 3.1 6.5.7 allows a Block Read byte count of 0, but the interrupt-driven block-read state machine rejects it as -EPROTO. Worse, it returns without a NACK+STOP: the next receive cycle has already started, so the target keeps holding SDA and the bus stays stuck until a power cycle of this i2c controller.
Accept count=0: NACK the in-flight dummy byte (TXAK) and set msg->len to 2 so i2c_imx_isr_read_continue() emits STOP via its normal last-byte path. The dummy byte is discarded; block-read callers only consume buf[0..count-1].
Reading I2DR has likewise already armed the next byte on the count > I2C_SMBUS_BLOCK_MAX error path, so NACK it (TXAK) before aborting with -EPROTO; otherwise the failing transfer's STOP cannot complete and the bus stays held.
The atomic path regressed earlier (v3.16) and is fixed separately; this patch covers only the v6.13 state-machine rework.
--- drivers/i2c/busses/i2c-imx.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/i2c/busses/i2c-imx.c +17 -0
@@ -1061,11 +1061,28 @@ static inline enum imx_i2c_state i2c_imxstatic inline void i2c_imx_isr_read_block_data_len (struct imx_i2c_struct *i2c_imx) {u8 len =imx_i2c_read_reg (i2c_imx,IMX_I2C_I2DR ); +unsigned int temp;if (len ==0 || len >I2C_SMBUS_BLOCK_MAX ) { +/* +* SMBus 3.1 6.5.7: support count byte of 0. +* I2C_SMBUS_BLOCK_MAX case should not hold the SDA either. +* So NACK it (TXAK) to not hold the bus. +*/ + temp =imx_i2c_read_reg (i2c_imx,IMX_I2C_I2CR ); + temp |=I2CR_TXAK ; +imx_i2c_write_reg (temp, i2c_imx,IMX_I2C_I2CR ); + +if (len ==0 ) { + i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] =0 ; + i2c_imx->msg->len =2 ; +return ; + } + i2c_imx->isr_result = -EPROTO ; i2c_imx->state =IMX_I2C_STATE_FAILED ;wake_up (&i2c_imx->queue); +return ; } i2c_imx->msg->len += len; i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = len;
Greg Kroah-Hartman
maintainerPATCH 1309/1611 i2c: mediatek: fix WRRD for SoCs without auto_restart option
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roman Vivchar <[email protected]>
commit deb35336b5bfed5db9231b5348bc1514db930797 upstream.
MediaTek mt65xx family SoCs have no auto restart, however, they still support the WRRD mode in the hardware. Because auto_restart is set to 0, the WRRD mode will be never enabled, leading to read errors.
Fix this by removing auto_restart check from the WRRD enable path.
--- drivers/i2c/busses/i2c-mt65xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-mt65xx.c +1 -1
@@ -1250,7 +1250,7 @@ static int mtk_i2c_transfer(struct i2c_a i2c->auto_restart = i2c->dev_comp->auto_restart;/* checking if we can skip restart and optimize using WRRD mode */ -if (i2c->auto_restart && num ==2 ) { +if (num ==2 ) {if (!(msgs[0 ].flags &I2C_M_RD ) && (msgs[1 ].flags &I2C_M_RD ) && msgs[0 ].addr == msgs[1 ].addr) { i2c->auto_restart =0 ;
Greg Kroah-Hartman
maintainerPATCH 1310/1611 i2c: mlxbf: Fix use-after-free in mlxbf_i2c_init_resource()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xuanqiang Luo <[email protected]>
commit 71356737a7a55c76fee847563e3d33f8e6dc6b6d upstream.
If devm_platform_get_and_ioremap_resource() returns an error, mlxbf_i2c_init_resource() frees tmp_res before reading tmp_res->io to get the error code. This results in a use-after-free.
Save the error code before freeing tmp_res.
--- drivers/i2c/busses/i2c-mlxbf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-mlxbf.c +3 -1
@@ -1058,8 +1058,10 @@ static int mlxbf_i2c_init_resource(struc tmp_res->io =devm_platform_get_and_ioremap_resource (pdev, type, &tmp_res->params);if (IS_ERR (tmp_res->io)) { +int ret =PTR_ERR (tmp_res->io); +devm_kfree (dev, tmp_res); -return PTR_ERR (tmp_res->io); +return ret; } tmp_res->type = type;
Greg Kroah-Hartman
maintainerPATCH 1311/1611 i2c: spacemit: fix spurious IRQ handling returning IRQ_HANDLED
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
commit 9db20d23aac7916ff49be409a4bfd48fe7cbbfb4 upstream.
When the interrupt status register reads zero, the handler should return IRQ_NONE instead of IRQ_HANDLED. What the return value actually feeds into is the spurious interrupt accounting in note_interrupt(): falsely claiming IRQ_HANDLED defeats the "irq XX:
nobody cared" detection, so a stuck interrupt source would never be caught.
--- drivers/i2c/busses/i2c-k1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-k1.c +1 -1
@@ -425,7 +425,7 @@ static irqreturn_t spacemit_i2c_irq_hand status =readl (i2c->base +SPACEMIT_ISR );if (!status) -return IRQ_HANDLED ; +return IRQ_NONE ; i2c->status = status;
Greg Kroah-Hartman
maintainerPATCH 1312/1611 ice: fix ice_init_link() error return preventing probe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Greenwalt <[email protected]>
commit eb509638686b0f8a98a0dd9c809f6a8db4d73a45 upstream.
ice_init_link() can return an error status from ice_update_link_info() or ice_init_phy_user_cfg(), causing probe to fail.
An incorrect NVM update procedure can result in link/PHY errors, and the recommended resolution is to update the NVM using the correct procedure. If the driver fails probe due to link errors, the user cannot update the NVM to recover. The link/PHY errors logged are
non-fatal: they are already annotated as 'not a fatal error if this fails'.
Since none of the errors inside ice_init_link() should prevent probe from completing, convert it to void and remove the error check in the caller. All failures are already logged; callers have no meaningful recovery path for link init errors.
--- drivers/net/ethernet/intel/ice/ice_main.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +5 -11
@@ -4871,16 +4871,14 @@ static void ice_init_wakeup(struct ice_pdevice_set_wakeup_enable (ice_pf_to_dev (pf), false); } -static int ice_init_link (struct ice_pf *pf) +static void ice_init_link (struct ice_pf *pf) {struct device *dev =ice_pf_to_dev (pf);int err; err =ice_init_link_events (pf->hw.port_info); -if (err) { +if (err)dev_err (dev,"ice_init_link_events failed: %d\n" , err); -return err; - }/* not a fatal error if this fails */ err =ice_init_nvm_phy_type (pf->hw.port_info);
@@ -4914,8 +4912,6 @@ static int ice_init_link(struct ice_pf * }else {set_bit (ICE_FLAG_NO_MEDIA , pf->flags); } - -return err; }static int ice_init_pf_sw (struct ice_pf *pf)
@@ -5058,13 +5054,11 @@ static int ice_init(struct ice_pf *pf)ice_init_wakeup (pf); - err =ice_init_link (pf); -if (err) - goto err_init_link; +ice_init_link (pf); err =ice_send_version (pf);if (err) - goto err_init_link; + goto err_deinit_pf_sw;ice_verify_cacheline_size (pf);
@@ -5083,7 +5077,7 @@ static int ice_init(struct ice_pf *pf)return 0 ; -err_init_link: +err_deinit_pf_sw:ice_deinit_pf_sw (pf); err_init_pf_sw:ice_dealloc_vsis (pf);
Greg Kroah-Hartman
maintainerPATCH 1313/1611 tcp: defer md5sig_info kfree past RCU grace period in tcp_connect
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit b74cd55038905d5e74c1de109ab78a30b2ea0e1f upstream.
The md5+ao reconciliation in tcp_connect() (net/ipv4/tcp_output.c) has two symmetric branches:
if (needs_md5) {
tcp_ao_destroy_sock(sk, false);
} else if (needs_ao) {
tcp_clear_md5_list(sk);
kfree(rcu_replace_pointer(tp->md5sig_info, NULL, ...));
}Both branches free a per-socket auth-info object while the socket is in TCP_SYN_SENT and is already on the inet ehash (inserted by inet_hash_connect() in tcp_v4_connect()). Both branches are reachable by softirq RX-path readers that load the corresponding info pointer via implicit RCU before bh_lock_sock_nested() is taken.
The needs_md5 branch is fixed in the prior patch by re-introducing the call_rcu() free in tcp_ao_destroy_sock(): the equivalent per-key loop runs inside tcp_ao_info_free_rcu(), the RCU callback, so by the time it frees each tcp_ao_key all softirq readers that captured the container have already completed rcu_read_unlock().
The needs_ao branch is not symmetric in the same way. The container free can be deferred via kfree_rcu(md5sig, rcu) -- struct tcp_md5sig_info already has the required rcu member (include/net/tcp.h:1999-2002), and the rest of the tree already does this in the tcp_md5sig_info_add() rollback paths (net/ipv4/tcp_ipv4.c:1410, 1436). But the per-key teardown is done by tcp_clear_md5_list() in process context BEFORE the container's RCU grace period: it walks &md5sig->head and frees each tcp_md5sig_key with bare hlist_del + kfree. A concurrent softirq reader in __tcp_md5_do_lookup() / __tcp_md5_do_lookup_exact() (tcp_ipv4.c:1253, 1298) walks the same list via hlist_for_each_entry_rcu() and races with that bare kfree on the keys themselves -- a per-key slab use-after-free of the same class as the TCP-AO bug, on the same race window.
Fix this in two halves:
1. Convert the bare kfree() in tcp_connect() to kfree_rcu() so the md5sig_info container joins the rest of the md5sig lifecycle. The local-variable lift is mechanical and required because kfree_rcu() is a macro that expects an lvalue.
2. Make tcp_clear_md5_list() RCU-safe by replacing hlist_del + kfree(key) with hlist_del_rcu + kfree_rcu(key, rcu). struct tcp_md5sig_key already carries the rcu member (include/net/tcp.h:1995) and tcp_md5_do_del() (net/ipv4/tcp_ipv4.c:1456) already uses kfree_rcu, so this restores the lifecycle invariant the rest of the file follows rather than introducing a one-off.
The other caller of tcp_clear_md5_list() is tcp_md5_destruct_sock() (net/ipv4/tcp.c:412), which runs from the sock destructor when the socket is already unhashed and unreachable; the extra grace period there is unnecessary but harmless. Making the helper unconditionally RCU-safe is the cleaner contract.
The needs_ao branch is not reachable by the userns reproducer used to demonstrate the AO-side splat (the repro installs both keys but ends up in the needs_md5 branch because the connect peer matches the MD5 key, not the AO key); however the symmetric race exists and a maintainer touching this code should not have to think about which branch escapes RCU and which one does not.
--- net/ipv4/tcp_ipv4.c | 4 ++-- net/ipv4/tcp_output.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
net/ipv4/tcp_ipv4.c +2 -2
@@ -1505,9 +1505,9 @@ void tcp_clear_md5_list(struct sock *sk) md5sig =rcu_dereference_protected (tp->md5sig_info,1 );hlist_for_each_entry_safe (key, n, &md5sig->head, node) { -hlist_del (&key->node); +hlist_del_rcu (&key->node);atomic_sub (sizeof (*key), &sk->sk_omem_alloc); -kfree (key); +kfree_rcu (key, rcu); } }
net/ipv4/tcp_output.c +6 -2
@@ -4263,9 +4263,13 @@ int tcp_connect(struct sock *sk)if (needs_md5) {tcp_ao_destroy_sock (sk, false); }else if (needs_ao) { +struct tcp_md5sig_info *md5sig; +tcp_clear_md5_list (sk); -kfree (rcu_replace_pointer (tp->md5sig_info,NULL , -lockdep_sock_is_held (sk))); + md5sig =rcu_replace_pointer (tp->md5sig_info,NULL , +lockdep_sock_is_held (sk)); +if (md5sig) +kfree_rcu (md5sig, rcu); } }#endif
Greg Kroah-Hartman
maintainerPATCH 1314/1611 tcp: Decrement tcp_md5_needed static branch
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Safonov <[email protected]>
commit 6f6e860e370c9e4e919b92118a25e9e1f82e9180 upstream.
In case of early freeing an unwanted TCP-MD5 key on TCP-AO connect(), md5sig_info is freed right away (and set to NULL). Later, at the moment of socket destruction, the static branch counter is not getting decremented.
Add a missing decrement for TCP-MD5 static branch.
--- net/ipv4/tcp_output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_output.c +2 -2
@@ -4268,8 +4268,8 @@ int tcp_connect(struct sock *sk)tcp_clear_md5_list (sk); md5sig =rcu_replace_pointer (tp->md5sig_info,NULL ,lockdep_sock_is_held (sk)); -if (md5sig) - kfree_rcu(md5sig, rcu); +kfree_rcu (md5sig, rcu); + static_branch_slow_dec_deferred(&tcp_md5_needed); } }#endif
Greg Kroah-Hartman
maintainerPATCH 1315/1611 ufs: core: tracing: Do not dereference pointers in TP_printk()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit 535fcf4b8a261fbb8cc4f91e4597343c135a90f2 upstream.
The trace events in drivers/ufs/core/ufs_trace.h were converted to take a pointer to the hba structure as an argument for the tracepoint and then in TP_printk() the printing of the dev_name from the ring buffer was converted to using the dev dereferenced pointer from the hba saved pointer.
This is not allowed as the TP_printk() is executed at the time the trace event is read from /sys/kernel/tracing/trace file. That can happen literally, seconds, minutes, hours, weeks, days, or even months later! There is no guarantee that the hba pointer will still exist by the time it is dereferenced when the "trace" file is read.
Instead, save the device name from the hba pointer at the time the tracepoint is called and place it into the ring buffer event. Then the TP_printk() can read the name directly from the ring buffer and remove the possibility that it will read a freed pointer and crash the kernel.
This was detected when testing the trace event code that looks for TP_printk() parameters doing illegal derferences[1]
[1] https://lore.kernel.org/all/[email protected]/
--- drivers/ufs/core/ufs_trace.h | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-)
drivers/ufs/core/ufs_trace.h +27 -9
@@ -90,16 +90,18 @@ TRACE_EVENT(ufshcd_clk_gating,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__field (int, state) ),TP_fast_assign ( + __assign_str(dev_name); __entry->hba = hba; __entry->state = state; ),TP_printk ("%s: gating state changed to %s" , -dev_name (__entry->hba->dev), +__get_str (dev_name),__print_symbolic (__entry->state,UFSCHD_CLK_GATING_STATES )) );
@@ -112,6 +114,7 @@ TRACE_EVENT(ufshcd_clk_scaling,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__string (state, state)__string (clk, clk) __field(u32, prev_state)
@@ -120,6 +123,7 @@ TRACE_EVENT(ufshcd_clk_scaling,TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name);__assign_str (state);__assign_str (clk); __entry->prev_state = prev_state;
@@ -127,7 +131,7 @@ TRACE_EVENT(ufshcd_clk_scaling, ),TP_printk ("%s: %s %s from %u to %u Hz" , -dev_name (__entry->hba->dev),__get_str (state),__get_str (clk), +__get_str (dev_name),__get_str (state),__get_str (clk), __entry->prev_state, __entry->curr_state) );
@@ -139,16 +143,18 @@ TRACE_EVENT(ufshcd_auto_bkops_state,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__string (state, state) ),TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name);__assign_str (state); ),TP_printk ("%s: auto bkops - %s" , -dev_name (__entry->hba->dev),__get_str (state)) +__get_str (dev_name),__get_str (state)) ); DECLARE_EVENT_CLASS(ufshcd_profiling_template,
@@ -159,6 +165,7 @@ DECLARE_EVENT_CLASS(ufshcd_profiling_temTP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__string (profile_info, profile_info)__field (s64, time_us) __field(int, err)
@@ -166,13 +173,14 @@ DECLARE_EVENT_CLASS(ufshcd_profiling_temTP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name);__assign_str (profile_info); __entry->time_us = time_us; __entry->err = err; ),TP_printk ("%s: %s: took %lld usecs, err %d" , -dev_name (__entry->hba->dev),__get_str (profile_info), +__get_str (dev_name),__get_str (profile_info), __entry->time_us, __entry->err) );
@@ -201,6 +209,7 @@ DECLARE_EVENT_CLASS(ufshcd_template, __field(s64, usecs) __field(int, err) __field(struct ufs_hba *, hba) + __string(dev_name, dev_name(hba->dev)) __field(int, dev_state) __field(int, link_state) ),
@@ -209,13 +218,14 @@ DECLARE_EVENT_CLASS(ufshcd_template, __entry->usecs = usecs; __entry->err = err; __entry->hba = hba; +__assign_str (dev_name); __entry->dev_state = dev_state; __entry->link_state = link_state; ), TP_printk( "%s: took %lld usecs, dev_state: %s, link_state: %s, err %d", - dev_name(__entry->hba->dev), + __get_str(dev_name), __entry->usecs, __print_symbolic(__entry->dev_state, UFS_PWR_MODES), __print_symbolic(__entry->link_state, UFS_LINK_STATES),
@@ -280,6 +290,7 @@ TRACE_EVENT(ufshcd_command, TP_STRUCT__entry( __field(struct scsi_device *, sdev) __field(struct ufs_hba *, hba) + __string(dev_name, dev_name(&sdev->sdev_dev)) __field(enum ufs_trace_str_t, str_t) __field(unsigned int, tag) __field(u32, doorbell)
@@ -292,6 +303,7 @@ TRACE_EVENT(ufshcd_command, ), TP_fast_assign( + __assign_str(dev_name); __entry->sdev = sdev; __entry->hba = hba; __entry->str_t = str_t;
@@ -308,7 +320,7 @@ TRACE_EVENT(ufshcd_command,TP_printk ("%s: %s: tag: %u, DB: 0x%x, size: %d, IS: %u, LBA: %llu, opcode: 0x%x (%s), group_id: 0x%x, hwq_id: %d" ,show_ufs_cmd_trace_str (__entry->str_t), -dev_name (&__entry->sdev->sdev_dev), __entry->tag, +__get_str (dev_name), __entry->tag, __entry->doorbell, __entry->transfer_len, __entry->intr, __entry->lba, (u32 )__entry->opcode,str_opcode (__entry->opcode), (u32)__entry->group_id, __entry->hwq_id
@@ -323,6 +335,7 @@ TRACE_EVENT(ufshcd_uic_command,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev)) __field(enum ufs_trace_str_t, str_t)__field (u32, cmd) __field(u32, arg1)
@@ -332,6 +345,7 @@ TRACE_EVENT(ufshcd_uic_command,TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name); __entry->str_t = str_t; __entry->cmd = cmd; __entry->arg1 = arg1;
@@ -341,7 +355,7 @@ TRACE_EVENT(ufshcd_uic_command,TP_printk ("%s: %s: cmd: 0x%x, arg1: 0x%x, arg2: 0x%x, arg3: 0x%x" , -show_ufs_cmd_trace_str (__entry->str_t),dev_name (__entry->hba->dev), +show_ufs_cmd_trace_str (__entry->str_t),__get_str (dev_name), __entry->cmd, __entry->arg1, __entry->arg2, __entry->arg3 ) );
@@ -354,6 +368,7 @@ TRACE_EVENT(ufshcd_upiu,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev)) __field(enum ufs_trace_str_t, str_t) __array(unsigned char, hdr, 12) __array(unsigned char, tsf, 16)
@@ -362,6 +377,7 @@ TRACE_EVENT(ufshcd_upiu,TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name); __entry->str_t = str_t;memcpy (__entry->hdr, hdr,sizeof (__entry->hdr));memcpy (__entry->tsf, tsf,sizeof (__entry->tsf));
@@ -370,7 +386,7 @@ TRACE_EVENT(ufshcd_upiu,TP_printk ("%s: %s: HDR:%s, %s:%s" , -show_ufs_cmd_trace_str (__entry->str_t),dev_name (__entry->hba->dev), +show_ufs_cmd_trace_str (__entry->str_t),__get_str (dev_name),__print_hex (__entry->hdr,sizeof (__entry->hdr)),show_ufs_cmd_trace_tsf (__entry->tsf_t), __print_hex(__entry->tsf, sizeof(__entry->tsf))
@@ -385,16 +401,18 @@ TRACE_EVENT(ufshcd_exception_event,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__field (u16, status) ),TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name); __entry->status = status; ),TP_printk ("%s: status 0x%x" , -dev_name (__entry->hba->dev), __entry->status +__get_str (dev_name), __entry->status ) );
Greg Kroah-Hartman
maintainerPATCH 1316/1611 xen/gntdev: fix error handling in ioctl
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 45ca1afe2fd14c04e37227e79d3f8455831d8408 upstream.
When gntdev_ioctl_map_grant_ref() fails to copy the operation result back to userspace after successfully adding the mapping to the list, the error path returns -EFAULT without releasing the reference acquired by gntdev_alloc_map(). The mapping remains in priv->maps with a refcount of 1, causing a memory leak and a dangling list entry.
Additionally, gntdev_add_map() may modify map->index to avoid overlap with existing mappings. Therefore, the index returned to userspace must be obtained after gntdev_add_map() completes.
Fix this by holding the mutex across gntdev_add_map(), retrieving the correct index, and copy_to_user(). If copy_to_user() fails, remove the mapping from the list and release the reference while still holding the lock.
Fix these issues by properly handling all error cases.
Message-ID: <[email protected]>
--- drivers/xen/gntdev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/xen/gntdev.c +6 -2
@@ -676,11 +676,15 @@ static long gntdev_ioctl_map_grant_ref(smutex_lock (&priv->lock);gntdev_add_map (priv, map); op.index = map->index <<PAGE_SHIFT ; -mutex_unlock (&priv->lock); -if (copy_to_user (u, &op,sizeof (op)) !=0 ) +if (copy_to_user (u, &op,sizeof (op)) !=0 ) { +list_del (&map->next); +mutex_unlock (&priv->lock); +gntdev_put_map (priv, map);return -EFAULT ; + } +mutex_unlock (&priv->lock);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1317/1611 xfrm: nat_keepalive: avoid double free on send error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qianyu Luo <[email protected]>
commit 226f4a490d1a938fc838d8f8c46a4eca864c0d78 upstream.
nat_keepalive_send() frees the keepalive skb whenever the IPv4 or IPv6 send helper reports an error.
That cleanup is only correct before the skb is handed to the output path. Once ip_build_and_send_pkt() or ip6_xmit() takes ownership, the networking stack may already have consumed the skb before returning an error, so freeing it again is unsafe.
Handle the pre-handoff failure cases inside nat_keepalive_send_ipv4() and nat_keepalive_send_ipv6(), where the caller still owns the skb, and keep nat_keepalive_send() responsible only for family dispatch and the unsupported-family cleanup path.
--- net/xfrm/xfrm_nat_keepalive.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
net/xfrm/xfrm_nat_keepalive.c +9 -6
@@ -55,8 +55,10 @@ static int nat_keepalive_send_ipv4(struc ka->encap_sport, sock_net_uid(net, NULL)); rt =ip_route_output_key (net, &fl4); -if (IS_ERR (rt)) +if (IS_ERR (rt)) { +kfree_skb (skb);return PTR_ERR (rt); + }skb_dst_set (skb, &rt->dst);
@@ -101,6 +103,7 @@ static int nat_keepalive_send_ipv6(struc dst = ipv6_stub->ipv6_dst_lookup_flow (net, sk, &fl6,NULL );if (IS_ERR (dst)) {local_unlock_nested_bh (&nat_keepalive_sk_ipv6.bh_lock); +kfree_skb (skb);return PTR_ERR (dst); }
@@ -118,7 +121,6 @@ static void nat_keepalive_send(struct na sizeof(struct ipv6hdr)) +sizeof (struct udphdr );const u8 nat_ka_payload =0xFF ; -int err = -EAFNOSUPPORT ;struct sk_buff *skb;struct udphdr *uh;
@@ -140,16 +142,17 @@ static void nat_keepalive_send(struct naswitch (ka->family) {case AF_INET : - err =nat_keepalive_send_ipv4 (skb, ka); +nat_keepalive_send_ipv4 (skb, ka);break ;#if IS_ENABLED (CONFIG_IPV6 )case AF_INET6 : - err =nat_keepalive_send_ipv6 (skb, ka, uh); +nat_keepalive_send_ipv6 (skb, ka, uh);break ;#endif - } -if (err) +default :kfree_skb (skb); +break ; + } }struct nat_keepalive_work_ctx {
Greg Kroah-Hartman
maintainerPATCH 1318/1611 xfrm: use compat translator only for u64 alignment mismatch
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 355fbcbdc2539cca7890b0d0914d4ce0f985ad74 upstream.
The XFRM compat layer (CONFIG_XFRM_USER_COMPAT) translates 32-bit xfrm netlink and setsockopt messages into the native 64-bit layout. It is only needed on architectures where the 32-bit and 64-bit ABIs disagree on u64 alignment, which the kernel encodes as COMPAT_FOR_U64_ALIGNMENT.
That symbol is defined only by arch/x86. XFRM_USER_COMPAT depends on it, so the translator can never be built on any other architecture, including arm64, which still provides a 32-bit compat ABI (CONFIG_COMPAT) for AArch32 EL0 userspace. On arm64 the AArch32 EABI already aligns u64 to 8 bytes, identical to the AArch64 ABI, so no translation is required and the native code path is correct for 32-bit tasks.
However, xfrm_user_rcv_msg() and xfrm_user_policy() gate on in_compat_syscall() alone and then call xfrm_get_translator(), which returns NULL when no translator is registered. On arm64 that is always the case, so every xfrm netlink message and the XFRM_POLICY setsockopt issued by a 32-bit task returns -EOPNOTSUPP. A 32-bit userspace process on arm64 (and on any other arch with CONFIG_COMPAT but without COMPAT_FOR_U64_ALIGNMENT) therefore cannot configure XFRM state or policy through the XFRM_USER netlink API, and cannot use the XFRM_POLICY setsockopt path, because both fail before reaching the native parser.
The translator series replaced the blanket compat rejection with a translator lookup. That made the path usable on x86 when the translator is available, but left architectures that cannot build the translator permanently rejected even when their compat layout already matches the native layout. Let those architectures use the native parser instead.
Gate the translator requirement on COMPAT_FOR_U64_ALIGNMENT instead of on in_compat_syscall() alone. Gating on the ABI property rather than on CONFIG_XFRM_USER_COMPAT is deliberate: on x86 with IA32_EMULATION=y but XFRM_USER_COMPAT=n, a 32-bit task must still be rejected rather than routed through the native parser, which would misread genuinely 4-byte-aligned x86-32 messages. COMPAT_FOR_U64_ALIGNMENT is the ABI property that makes the XFRM translator mandatory.
Only the receive/input direction needs the guard. The send, dump and notification paths already call the translator as "if (xtr) { ... }" with no error on NULL, so on arches without a translator they no-op and the kernel emits native 64-bit-layout messages, which is what an AArch32 task expects.
Tested on Juniper SRX hardware: with the fix, 32-bit IPsec userspace netlink and XFRM_POLICY setsockopt operations that previously failed with -EOPNOTSUPP now succeed; x86 behaviour is unchanged by inspection.
--- net/xfrm/xfrm_state.c | 2 +- net/xfrm/xfrm_user.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_state.c +1 -1
@@ -2983,7 +2983,7 @@ int xfrm_user_policy(struct sock *sk, inif (IS_ERR (data))return PTR_ERR (data); -if (in_compat_syscall ()) { +if (IS_ENABLED (CONFIG_COMPAT_FOR_U64_ALIGNMENT ) &&in_compat_syscall ()) {struct xfrm_translator *xtr =xfrm_get_translator ();if (!xtr) {
net/xfrm/xfrm_user.c +1 -1
@@ -3463,7 +3463,7 @@ static int xfrm_user_rcv_msg(struct sk_bif (!netlink_net_capable (skb,CAP_NET_ADMIN ))return -EPERM ; -if (in_compat_syscall ()) { +if (IS_ENABLED (CONFIG_COMPAT_FOR_U64_ALIGNMENT ) &&in_compat_syscall ()) {struct xfrm_translator *xtr =xfrm_get_translator ();if (!xtr)
Greg Kroah-Hartman
maintainerPATCH 1319/1611 xfrm: xfrm_interface: require CAP_NET_ADMIN in the device netns for changelink
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 095515d89b19b6cc19dfcdc846f97403ed1ebce3 upstream.
xfrmi_changelink() operates on at most two netns, dev_net(dev) and the interface link netns xi->net. They differ once the device is created in or moved to a netns other than the one the request runs in. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in xi->net can rewrite an interface that lives in xi->net.
Gate xfrmi_changelink() on rtnl_dev_link_net_capable() at its top, before any attribute is parsed.
--- net/xfrm/xfrm_interface_core.c | 3 +++ 1 file changed, 3 insertions(+)
net/xfrm/xfrm_interface_core.c +3 -0
@@ -869,6 +869,9 @@ static int xfrmi_changelink(struct net_dstruct net *net = xi->net;struct xfrm_if_parms p = {}; +if (!rtnl_dev_link_net_capable (dev, net)) +return -EPERM ; +xfrmi_netlink_parms (data, &p);if (!p.if_id) {NL_SET_ERR_MSG (extack,"if_id must be non zero" );
Greg Kroah-Hartman
maintainerPATCH 1320/1611 tpm: fix event_size output in tpm1_binary_bios_measurements_show
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit 1a58f6115bfb34eabcc7de8a3a9745b219179781 upstream.
Commit 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements") split the output to write the endian-converted event header first and then the variable-length event data.
However, the split was at sizeof(struct tcpa_event) - 1, even though event_data was a zero-length array, and later a flexible array member, both of which already excluded the event data.
Therefore, the current code writes the first three bytes of event_size from the endian-converted header and then the last byte from the raw header, which can emit a corrupted event_size on PPC64, where do_endian_conversion() maps to be32_to_cpu().
Split one byte later to write the full endian-converted header first, followed by the variable-length event->event_data.
--- drivers/char/tpm/eventlog/tpm1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/eventlog/tpm1.c +2 -2
@@ -236,12 +236,12 @@ static int tpm1_binary_bios_measurements temp_ptr = (char *) &temp_event; -for (i =0 ; i < (sizeof (struct tcpa_event ) -1 ) ; i++) +for (i =0 ; i <sizeof (struct tcpa_event ); i++)seq_putc (m, temp_ptr[i]); temp_ptr = (char *) v; -for (i = (sizeof (struct tcpa_event ) -1 ); +for (i =sizeof (struct tcpa_event ); i < (sizeof (struct tcpa_event ) + temp_event.event_size); i++)seq_putc (m, temp_ptr[i]);
Greg Kroah-Hartman
maintainerPATCH 1321/1611 tpm: Make the TPM character devices non-seekable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaewon Yang <[email protected]>
commit f20d61c22bcaf172d6790b6500e3838e532e71c8 upstream.
The TPM character devices expose a sequential command/response interface, but their open handlers leave FMODE_PREAD and FMODE_PWRITE enabled.
After a command leaves a response pending, pread(fd, buf, 16, 0x1400) passes 0x1400 as *off to tpm_common_read(). The transfer length is bounded by response_length, but the offset is used unchecked when forming data_buffer + *off. A sufficiently large offset therefore causes an out-of-bounds heap read through copy_to_user() and, if the copy succeeds, an out-of-bounds zero-write through the following memset().
Positional I/O does not provide coherent semantics for this interface. An arbitrary pread offset cannot represent how much of a response has been consumed sequentially. The write callback always stores a command at the start of data_buffer, while pwrite() does not update file->f_pos and can leave the sequential read cursor stale.
Call nonseekable_open() from both open handlers. This removes FMODE_PREAD and FMODE_PWRITE, causing positional reads and writes to fail with -ESPIPE before reaching the TPM callbacks, and explicitly marks the files non-seekable. Normal read() and write() continue to use the existing sequential f_pos cursor, leaving the response state machine unchanged.
Tested on Linux 6.12 with KASAN and a swtpm TPM2 device:
- sequential partial reads returned the complete response
- pread() and preadv() with offset 0x1400 returned -ESPIPE
- pwrite() and pwritev() with offset zero returned -ESPIPE
- the pending response remained intact after the rejected operations
- a subsequent normal command/response cycle completed normally
- no KASAN report was produced.
--- drivers/char/tpm/tpm-dev.c | 2 +- drivers/char/tpm/tpmrm-dev.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm-dev.c +1 -1
@@ -36,7 +36,7 @@ static int tpm_open(struct inode *inode,tpm_common_open (file, chip, priv,NULL ); -return 0 ; +return nonseekable_open (inode, file); out:clear_bit (0 , &chip->is_open);
drivers/char/tpm/tpmrm-dev.c +1 -1
@@ -29,7 +29,7 @@ static int tpmrm_open(struct inode *inodtpm_common_open (file, chip, &priv->priv, &priv->space); -return 0 ; +return nonseekable_open (inode, file); }static int tpmrm_release (struct inode *inode,struct file *file)
Greg Kroah-Hartman
maintainerPATCH 1322/1611 time: Fix off-by-one in compat settimeofday() usec validation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wang Yan <[email protected]>
commit 269f2b43fae692d1f3988c9f888a6301aa537b82 upstream.
The compat version of settimeofday() uses '>' instead of '>=' when validating tv_usec against USEC_PER_SEC, allowing the value 1000000 to pass the check. After the subsequent conversion to nanoseconds (tv_nsec *= NSEC_PER_USEC), this results in tv_nsec == NSEC_PER_SEC, which violates the timespec invariant that tv_nsec must be strictly less than NSEC_PER_SEC.
The native settimeofday() was already fixed in commit ce4abda5e126 ("time:
Fix off-by-one in settimeofday() usec validation"), but the compat counterpart was missed.
Fix it by using '>=' to reject tv_usec values outside the valid range [0, USEC_PER_SEC - 1].
--- kernel/time/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/time.c +1 -1
@@ -251,7 +251,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, str get_user(new_ts.tv_nsec, &tv->tv_usec))return -EFAULT ; -if (new_ts.tv_nsec >USEC_PER_SEC || new_ts.tv_nsec <0 ) +if (new_ts.tv_nsec >=USEC_PER_SEC || new_ts.tv_nsec <0 )return -EINVAL ; new_ts.tv_nsec *=NSEC_PER_USEC ;
Greg Kroah-Hartman
maintainerPATCH 1323/1611 spi: uniphier: Fix completion initialization order before devm_request_irq()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kunihiko Hayashi <[email protected]>
commit f3ad1c87d8201e54b66bd6072442f0b5d5a308ee upstream.
The driver calls devm_request_irq() before initializing the completion used by the interrupt handler. Because the interrupt may occur immediately after devm_request_irq(), the handler may execute before init_completion().
This may result in calling complete() on an uninitialized completion, causing undefined behavior. This has been observed with KASAN.
Fix this by initializing the completion before registering the IRQ.
--- drivers/spi/spi-uniphier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-uniphier.c +2 -2
@@ -659,6 +659,8 @@ static int uniphier_spi_probe(struct pla priv->host = host; priv->is_save_param = false; +init_completion (&priv->xfer_done); + priv->base =devm_platform_get_and_ioremap_resource (pdev,0 , &res);if (IS_ERR (priv->base)) { ret =PTR_ERR (priv->base);
@@ -686,8 +688,6 @@ static int uniphier_spi_probe(struct pla goto out_host_put; } -init_completion (&priv->xfer_done); - clk_rate =clk_get_rate (priv->clk); host->max_speed_hz =DIV_ROUND_UP (clk_rate,SSI_MIN_CLK_DIVIDER );
Greg Kroah-Hartman
maintainerPATCH 1324/1611 sctp: validate STALE_COOKIE cause length before reading staleness
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit 1cd23ca80784223fa2204e16203f754da4e821f8 upstream.
When an ERROR chunk with a STALE_COOKIE cause is received in the COOKIE_ECHOED state, sctp_sf_do_5_2_6_stale() reads the 4-byte Measure of Staleness that follows the cause header:
err = (struct sctp_errhdr *)(chunk->skb->data); stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err)));
err is the first cause in the chunk, not the STALE_COOKIE cause that caused the dispatch, and nothing guarantees the staleness field is present. sctp_walk_errors() only requires a cause to be as long as the 4-byte header, so for a STALE_COOKIE cause of length 4 the read runs past the cause, and for a minimal ERROR chunk past skb->tail. The value is echoed to the peer in the Cookie Preservative of the reply INIT, leaking uninitialized memory.
sctp_sf_cookie_echoed_err() already walks to the STALE_COOKIE cause, so check its length there and pass it to sctp_sf_do_5_2_6_stale(), which reads that cause instead of the first one. A STALE_COOKIE cause too short to hold the staleness field is discarded.
The read is reachable by any peer that can drive an association into COOKIE_ECHOED, including an unprivileged process using a raw SCTP socket in a user and network namespace.
--- net/sctp/sm_statefuns.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
net/sctp/sm_statefuns.c +14 -9
@@ -74,7 +74,8 @@ static enum sctp_disposition sctp_sf_do_const struct sctp_association *asoc, const union sctp_subtype type, void *arg, - struct sctp_cmd_seq *commands); + struct sctp_cmd_seq *commands, + struct sctp_errhdr *err); static enum sctp_disposition sctp_sf_shut_8_4_5( struct net *net, const struct sctp_endpoint *ep,
@@ -2524,9 +2525,15 @@ enum sctp_disposition sctp_sf_cookie_ech* errors. */ sctp_walk_errors(err, chunk->chunk_hdr) { -if (SCTP_ERROR_STALE_COOKIE == err->cause) -return sctp_sf_do_5_2_6_stale (net, ep, asoc, type, - arg, commands); +if (err->cause !=SCTP_ERROR_STALE_COOKIE ) +continue ; +/* The staleness is only meaningful if the cause is long +* enough to hold it; a shorter one is malformed. +*/ +if (ntohs (err->length) <sizeof (*err) +sizeof (__be32)) +break ; +return sctp_sf_do_5_2_6_stale (net, ep, asoc, type, + arg, commands, err); }/* It is possible to have malformed error causes, and that
@@ -2568,13 +2575,13 @@ static enum sctp_disposition sctp_sf_do_const struct sctp_association *asoc, const union sctp_subtype type, void *arg, - struct sctp_cmd_seq *commands) + struct sctp_cmd_seq *commands, + struct sctp_errhdr *err) { int attempts = asoc->init_err_counter + 1; -struct sctp_chunk *chunk = arg, *reply;struct sctp_cookie_preserve_param bht;struct sctp_bind_addr *bp; -struct sctp_errhdr *err; +struct sctp_chunk *reply;u32 stale;if (attempts > asoc->max_init_attempts) {
@@ -2585,8 +2592,6 @@ static enum sctp_disposition sctp_sf_do_return SCTP_DISPOSITION_DELETE_TCB ; } - err = (struct sctp_errhdr *)(chunk->skb->data); -/* When calculating the time extension, an implementation * SHOULD use the RTT information measured based on the * previous COOKIE ECHO / ERROR exchange, and should add no
Greg Kroah-Hartman
maintainerPATCH 1325/1611 NFS: Charge unstable writes by request size, not folio size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Coddington <[email protected]>
commit 27934d02cbeb8a957dd11c985a579e58d30c5270 upstream.
nfs_folio_mark_unstable() and nfs_folio_clear_commit() charge and uncharge NR_WRITEBACK/WB_WRITEBACK by folio_nr_pages(folio) once per *request* added to or removed from a commit list. This is correct only when a folio has a single associated request. When pg_test splits a folio into N sub-folio requests (e.g. pNFS flexfiles striping with a stripe unit smaller than the folio size, or plain wsize-limited splitting), each of the N requests independently charges the whole folio's page count, inflating the accounting by a factor of N per folio. With large folios and small stripe units this reaches multiple orders of magnitude: a 2 MiB folio split into 512 4 KiB requests can charge up to 512x its real size, pushing global dirty+writeback accounting past the system's dirty threshold and forcing every buffered writer on the host into the hard-throttle path, including unrelated in-kernel NFS server threads sharing the box.
Charge each request only for the pages it actually covers.
--- fs/nfs/internal.h | 12 +++++++----- fs/nfs/pnfs_nfs.c | 2 +- fs/nfs/write.c | 14 ++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-)
fs/nfs/internal.h +7 -5
@@ -854,17 +854,19 @@ void nfs_super_set_maxbytes(struct super }/* -* Record the page as unstable (an extra writeback period) and mark its -* inode as dirty. +* Record the request's range as unstable (an extra writeback period) and +* mark its inode as dirty. */ -static inline void nfs_folio_mark_unstable (struct folio *folio, +static inline void nfs_folio_mark_unstable (struct nfs_page *req,struct nfs_commit_info *cinfo) { +struct folio *folio =nfs_page_to_folio (req); +if (folio && !cinfo->dreq) {struct inode *inode = folio->mapping->host; -long nr =folio_nr_pages (folio); +long nr =DIV_ROUND_UP (req->wb_bytes,PAGE_SIZE ); -/* This page is really still in write-back - just that the +/* This range is really still in write-back - just that the * writeback is happening on the server now. */ node_stat_mod_folio (folio,NR_WRITEBACK , nr);
fs/nfs/pnfs_nfs.c +1 -1
@@ -1199,7 +1199,7 @@ pnfs_layout_mark_request_commit(struct nnfs_request_add_commit_list_locked (req, list, cinfo);mutex_unlock (&NFS_I (cinfo->inode)->commit_mutex); -nfs_folio_mark_unstable (nfs_page_to_folio (req), cinfo); +nfs_folio_mark_unstable (req, cinfo);return ; out_resched:mutex_unlock (&NFS_I (cinfo->inode)->commit_mutex);
fs/nfs/write.c +8 -6
@@ -807,7 +807,7 @@ nfs_request_add_commit_list(struct nfs_pmutex_lock (&NFS_I (cinfo->inode)->commit_mutex);nfs_request_add_commit_list_locked (req, &cinfo->mds->list, cinfo);mutex_unlock (&NFS_I (cinfo->inode)->commit_mutex); -nfs_folio_mark_unstable (nfs_page_to_folio (req), cinfo); +nfs_folio_mark_unstable (req, cinfo); }EXPORT_SYMBOL_GPL (nfs_request_add_commit_list);
@@ -866,10 +866,12 @@ nfs_mark_request_commit(struct nfs_pagenfs_request_add_commit_list (req, cinfo); } -static void nfs_folio_clear_commit (struct folio *folio) +static void nfs_folio_clear_commit (struct nfs_page *req) { +struct folio *folio =nfs_page_to_folio (req); +if (folio) { -long nr =folio_nr_pages (folio); +long nr =DIV_ROUND_UP (req->wb_bytes,PAGE_SIZE );node_stat_mod_folio (folio,NR_WRITEBACK , -nr); wb_stat_mod(&inode_to_bdi(folio->mapping->host)->wb,
@@ -890,7 +892,7 @@ static void nfs_clear_request_commit(strnfs_request_remove_commit_list (req, cinfo); }mutex_unlock (&NFS_I (inode)->commit_mutex); -nfs_folio_clear_commit (nfs_page_to_folio (req)); +nfs_folio_clear_commit (req); } }
@@ -1735,7 +1737,7 @@ void nfs_retry_commit(struct list_head * req =nfs_list_entry (page_list->next);nfs_list_remove_request (req);nfs_mark_request_commit (req, lseg, cinfo, ds_commit_idx); -nfs_folio_clear_commit (nfs_page_to_folio (req)); +nfs_folio_clear_commit (req);nfs_unlock_and_release_request (req); } }
@@ -1807,7 +1809,7 @@ static void nfs_commit_release_pages(str req =nfs_list_entry (data->pages.next);nfs_list_remove_request (req); folio =nfs_page_to_folio (req); -nfs_folio_clear_commit (folio); +nfs_folio_clear_commit (req); dprintk("NFS: commit (%s/%llu %d@%lld)", nfs_req_openctx(req)->dentry->d_sb->s_id,
Greg Kroah-Hartman
maintainerPATCH 1326/1611 nvme-apple: Prevent shared tags across queues on Apple A11
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nick Chan <[email protected]>
commit 6fe0687245e8406bf26143bd45eb16441bbe5280 upstream.
On Apple A11, tags of pending commands must be unique across the admin and IO queues, else the firmware crashes with
"duplicate tag error for tag N", with N being the tag.
Apply the existing workaround for M1 of reserving two tags for the admin queue to A11.
--- drivers/nvme/host/apple.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/nvme/host/apple.c +4 -8
@@ -225,7 +225,7 @@ static unsigned int apple_nvme_queue_dep {struct apple_nvme *anv =queue_to_apple_nvme (q); -if (q->is_adminq && anv->hw->has_lsq_nvmmu) +if (q->is_adminq)return APPLE_NVME_AQ_DEPTH ;return anv->hw->max_queue_depth;
@@ -303,7 +303,7 @@ static void apple_nvme_submit_cmd_t8015(memcpy ((void *)q->sqes + (q->sq_tail <<APPLE_NVME_IOSQES ), cmd,sizeof (*cmd)); -if (++q->sq_tail == anv->hw->max_queue_depth) +if (++q->sq_tail ==apple_nvme_queue_depth (q)) q->sq_tail =0 ;writel (q->sq_tail, q->sq_db);
@@ -1139,10 +1139,7 @@ static void apple_nvme_reset_work(struct }/* Setup the admin queue */ -if (anv->hw->has_lsq_nvmmu) - aqa =APPLE_NVME_AQ_DEPTH -1 ; -else - aqa = anv->hw->max_queue_depth -1 ; + aqa =APPLE_NVME_AQ_DEPTH -1 ; aqa |= aqa <<16 ;writel (aqa, anv->mmio_nvme +NVME_REG_AQA );writeq (anv->adminq.sq_dma_addr, anv->mmio_nvme +NVME_REG_ASQ );
@@ -1324,8 +1321,7 @@ static int apple_nvme_alloc_tagsets(stru* both queues. The admin queue gets the first APPLE_NVME_AQ_DEPTH which * must be marked as reserved in the IO queue. */ -if (anv->hw->has_lsq_nvmmu) - anv->tagset.reserved_tags =APPLE_NVME_AQ_DEPTH ; + anv->tagset.reserved_tags =APPLE_NVME_AQ_DEPTH ; anv->tagset.queue_depth = anv->hw->max_queue_depth -1 ; anv->tagset.timeout =NVME_IO_TIMEOUT ; anv->tagset.numa_node =NUMA_NO_NODE ;
Greg Kroah-Hartman
maintainerPATCH 1327/1611 nvmet-auth: reject short AUTH_RECEIVE buffers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 779575bc35c687697ba69e904f2cd22e60112534 upstream.
nvmet_execute_auth_receive() trusts the AUTH_RECEIVE allocation length after checking only that it is nonzero and matches the transfer length. In the SUCCESS1 and FAILURE1/default states, that lets a remote NVMe-oF initiator reach the fixed-size DH-HMAC-CHAP response builders with a kmalloc() buffer shorter than the response, so nvmet_auth_success1() and nvmet_auth_failure1() write past the allocation; both only WARN_ON the short length and then format the message anyway.
Impact: A remote NVMe-oF initiator with access to an auth-enabled target can trigger a 16-byte heap out-of-bounds write via a one-byte AUTH_RECEIVE allocation length.
Compute the minimum response length for the current DH-HMAC-CHAP step in nvmet_auth_receive_data_len() and report a zero data length when the host-supplied allocation length is shorter, so the existing zero-length check in nvmet_execute_auth_receive() rejects the command before any builder runs. The SUCCESS1 minimum is sizeof(struct nvmf_auth_dhchap_success1_data) plus the HMAC hash length, because the response hash is written into the rval[] flexible-array tail, so the minimum is state dependent rather than a flat sizeof. CHALLENGE keeps its existing variable-length guard in nvmet_auth_challenge().
This is reachable only when in-band DH-HMAC-CHAP authentication is configured on the target.
--- drivers/nvme/target/fabrics-cmd-auth.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/nvme/target/fabrics-cmd-auth.c +25 -1
@@ -494,7 +494,31 @@ static void nvmet_auth_failure1(struct nu32 nvmet_auth_receive_data_len (struct nvmet_req *req) { -return le32_to_cpu (req->cmd->auth_receive.al); +struct nvmet_ctrl *ctrl = req->sq->ctrl; +u32 al =le32_to_cpu (req->cmd->auth_receive.al); +u32 min_len; + +/* +* Reject too-short al before kmalloc(al), since the SUCCESS1 and +* FAILURE1/default builders write fixed response headers into it. +*/ +switch (req->sq->dhchap_step) { +case NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE : +return al; +case NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1 : + min_len =sizeof (struct nvmf_auth_dhchap_success1_data ); +if (req->sq->dhchap_c2) + min_len +=nvme_auth_hmac_hash_len (ctrl->shash_id); +break ; +default : + min_len =sizeof (struct nvmf_auth_dhchap_failure_data ); +break ; + } + +if (al < min_len) +return 0 ; + +return al; }void nvmet_execute_auth_receive (struct nvmet_req *req)
Greg Kroah-Hartman
maintainerPATCH 1328/1611 nvmet-rdma: handle inline data with a nonzero offset
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 48c0162f647bb47e6084ffbc71b8f213f5e2f4f8 upstream.
nvmet_rdma_use_inline_sg() maps the host-controlled inline data offset into the per-command inline scatterlist. The bounds check admits any offset with off + len <= inline_data_size, but the mapping still assumes the data begins in the first inline page:
sg->offset = off; sg->length = min_t(int, len, PAGE_SIZE - off);
When a port is configured with inline_data_size > PAGE_SIZE (settable up to max(SZ_16K, PAGE_SIZE)), an offset in (PAGE_SIZE, inline_data_size] makes "PAGE_SIZE - off" underflow, so sg->length is set to ~4 GiB and the block backend reads far past the first inline page. num_pages(len) also ignores the offset, so an in-bounds offset whose [off, off+len) span crosses a page boundary under-counts the scatterlist.
Map the offset properly: split it into a page index and an in-page offset, start the scatterlist at that page, and size the page count from page_off + len. Because the request scatterlist may now start at inline_sg[page_idx] rather than inline_sg[0], generalize the inline-SGL identity test in nvmet_rdma_release_rsp() to a range test; otherwise the persistent inline scatterlist is mistaken for an allocated one and nvmet_req_free_sgls() frees an inline page (and warns in free_large_kmalloc()).
--- drivers/nvme/target/rdma.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/nvme/target/rdma.c +10 -8
@@ -667,7 +667,8 @@ static void nvmet_rdma_release_rsp(strucif (rsp->n_rdma)nvmet_rdma_rw_ctx_destroy (rsp); -if (rsp->req.sg != rsp->cmd->inline_sg) +if (rsp->req.sg < rsp->cmd->inline_sg || + rsp->req.sg >= rsp->cmd->inline_sg + queue->dev->inline_page_count)nvmet_req_free_sgls (&rsp->req);if (unlikely (!list_empty_careful (&queue->rsp_wr_wait_list)))
@@ -822,24 +823,25 @@ static void nvmet_rdma_write_data_done(sstatic void nvmet_rdma_use_inline_sg (struct nvmet_rdma_rsp *rsp,u32 len,u64 off) { -int sg_count =num_pages (len); +u64 page_off = off %PAGE_SIZE ; +u64 page_idx = off /PAGE_SIZE ; +int sg_count =num_pages (page_off + len);struct scatterlist *sg;int i; - sg = rsp->cmd->inline_sg; + sg = &rsp->cmd->inline_sg[page_idx];for (i =0 ; i < sg_count; i++, sg++) {if (i < sg_count -1 )sg_unmark_end (sg);else sg_mark_end (sg); - sg->offset = off; - sg->length =min_t (int, len,PAGE_SIZE - off); + sg->offset = page_off; + sg->length =min_t (u64, len,PAGE_SIZE - page_off); len -= sg->length; -if (!i) - off =0 ; + page_off =0 ; } - rsp->req.sg = rsp->cmd->inline_sg; + rsp->req.sg = &rsp->cmd->inline_sg[page_idx]; rsp->req.sg_cnt = sg_count; }
Greg Kroah-Hartman
maintainerPATCH 1329/1611 nvmet: fix refcount leak in nvmet_sq_create()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 34b9a83c50660148bde01cde16451dbe78369749 upstream.
In nvmet_sq_create(), a reference on the ctrl is taken via kref_get_unless_zero() before calling nvmet_check_sqid(). If nvmet_check_sqid() fails, the function returns the error directly without releasing the reference, leading to a leak.
Fix this by jumping to the "ctrl_put" label, which already performs the necessary nvmet_ctrl_put(ctrl). This ensures the reference is properly released on this error path.
--- drivers/nvme/target/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/core.c +1 -1
@@ -935,7 +935,7 @@ u16 nvmet_sq_create(struct nvmet_ctrl *c status =nvmet_check_sqid (ctrl, sqid, true);if (status !=NVME_SC_SUCCESS ) -return status; + goto ctrl_put; ret =nvmet_sq_init (sq, cq);if (ret) {
Greg Kroah-Hartman
maintainerPATCH 1330/1611 netdev-genl: report NAPI thread PID in the callers pid namespace
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 1f24c0d01db214c9e661915e9972404c96ca73c0 upstream.
netdev_nl_napi_fill_one() reports the NAPI kthread PID in NETDEV_A_NAPI_PID using task_pid_nr(), which returns the PID in the initial pid namespace.
NETDEV_CMD_NAPI_GET does not have GENL_ADMIN_PERM and the netdev genl family is netnsok, so a caller in a child pid namespace can issue it. That caller then sees the kthread's global PID, even though the kthread is not visible in its pid namespace, where the value should be 0.
Translate the PID through the caller's pid namespace, the same way commit 3799c2570982 ("io_uring/fdinfo: translate SqThread PID through caller's pid_ns") did for the io_uring SQPOLL thread. The doit and dumpit paths both run synchronously in the caller's context, so task_active_pid_ns(current) is the caller's pid namespace.
--- net/core/netdev-genl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/netdev-genl.c +3 -1
@@ -2,6 +2,7 @@#include <linux/netdevice.h> #include <linux/notifier.h> +#include <linux/pid_namespace.h> #include <linux/rtnetlink.h> #include <net/busy_poll.h> #include <net/net_namespace.h>
@@ -189,7 +190,8 @@ netdev_nl_napi_fill_one(struct sk_buff * goto nla_put_failure;if (napi->thread) { - pid =task_pid_nr (napi->thread); + pid =task_pid_nr_ns (napi->thread, +task_active_pid_ns (current));if (nla_put_u32 (rsp,NETDEV_A_NAPI_PID , pid)) goto nla_put_failure; }
Greg Kroah-Hartman
maintainerPATCH 1331/1611 can: esd_usb: kill anchored URBs before freeing netdevs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit c43122fef328a70045fe7621c06de6b2b8e19264 upstream.
esd_usb_disconnect() frees each CAN netdev with free_candev() inside its per-netdev loop and only calls unlink_all_urbs(dev) afterwards. The per-netdev private data (struct esd_usb_net_priv) is embedded in the net_device allocation returned by alloc_candev(), so once free_candev() has run, dev->nets[i] points to freed memory. unlink_all_urbs() then dereferences the freed dev->nets[i] to kill the per-netdev TX anchor (usb_kill_anchored_urbs(&priv->tx_submitted)), clear active_tx_jobs, and reset priv->tx_contexts[].
Reorder the teardown so the anchored URBs are killed before the netdevs are freed, matching other CAN/USB drivers in the same directory such as ems_usb, usb_8dev and mcba_usb, which unregister, then unlink, then
free: unregister the netdevs first (which stops their TX queues), call unlink_all_urbs(dev) once, then free the netdevs.
This issue was found by an in-house static analysis tool.
--- drivers/net/can/usb/esd_usb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/can/usb/esd_usb.c +4 -1
@@ -1387,10 +1387,13 @@ static void esd_usb_disconnect(struct us netdev = dev->nets[i]->netdev;netdev_info (netdev,"unregister\n" );unregister_netdev (netdev); -free_candev (netdev); } }unlink_all_urbs (dev); +for (i =0 ; i < dev->net_count; i++) { +if (dev->nets[i]) +free_candev (dev->nets[i]->netdev); + }kfree (dev); } }
Greg Kroah-Hartman
maintainerPATCH 1332/1611 can: isotp: use unconditional synchronize_rcu() in isotp_release()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 9b1a02e0d980ac6b0e36a90378f847062f81d7e4 upstream.
isotp_notify() unregisters the (RCU) CAN filters via can_rx_unregister() and clears so->bound without waiting for a grace period. isotp_release() uses so->bound to decide whether it needs to call synchronize_rcu() before cancelling so->rxtimer, so when NETDEV_UNREGISTER runs first it skips that synchronize_rcu() and can cancel the timer while an in-flight isotp_rcv() is still executing and about to re-arm it via isotp_send_fc(), leading to a use-after-free timer callback on the freed socket.
sakisho-bot remarked a problem with rtnl_lock held in isotp_notify(), therefore make isotp_release() always call synchronize_rcu() before cancelling the timers, regardless of so->bound. This still closes the original race (isotp_notify() clearing so->bound without waiting for in-flight isotp_rcv() callers before isotp_release() cancels the RX timer) without adding any RCU wait to the netdevice notifier path.
--- net/can/isotp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/can/isotp.c +8 -1
@@ -1218,11 +1218,18 @@ static int isotp_release(struct socket *SINGLE_MASK (so->txid), isotp_rcv_echo, sk);dev_put (dev); -synchronize_rcu (); } } } +/* Always wait for a grace period before touching the timers below. +* A concurrent NETDEV_UNREGISTER may have already unregistered our +* filters and cleared so->bound in isotp_notify() without waiting +* for in-flight isotp_rcv() callers to finish, so this call must not +* be skipped just because so->bound is already 0 here. +*/ +synchronize_rcu (); +hrtimer_cancel (&so->txfrtimer);hrtimer_cancel (&so->txtimer);hrtimer_cancel (&so->rxtimer);
Greg Kroah-Hartman
maintainerPATCH 1333/1611 can: isotp: fix use-after-free race with concurrent NETDEV_UNREGISTER
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 20bab8b88baac140ca3701116e1d486c7f51e311 upstream.
isotp_release() looked up the bound network device via dev_get_by_index() using the stored ifindex. During device unregistration the device is unlisted from the ifindex hash before the NETDEV_UNREGISTER notifier chain runs, so a concurrent isotp_release() could find no device, skip can_rx_unregister() entirely, and still proceed to free the socket. Since isotp_release() had already removed itself from the isotp notifier list at that point, isotp_notify() would never get a chance to clean up either, leaving a stale CAN filter that keeps pointing at the freed socket.
Fix this the same way raw.c already does: hold a tracked reference to the bound net_device in the socket (so->dev/so->dev_tracker) from bind() onward instead of re-resolving it from the ifindex, and serialize bind()/release() with rtnl_lock() so that so->dev is always consistent with what the NETDEV_UNREGISTER notifier sees. so->dev stays valid regardless of ifindex-hash unlisting, and is only ever cleared by whichever of isotp_release()/isotp_notify() gets there first, so the filter is always removed exactly once.
isotp_bind() now rejects a (re)bind with -EAGAIN while so->[tx|rx].state isn't ISOTP_IDLE yet, so a timer left running by a prior NETDEV_UNREGISTER can't act on a newly bound so->ifindex. Both checks share the same lock_sock() section, so there is no window in which a concurrent isotp_notify() clearing so->bound could be missed.
--- net/can/isotp.c | 87 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 28 deletions(-)
net/can/isotp.c +59 -28
@@ -151,6 +151,8 @@ struct isotp_sock {struct sock sk;int bound;int ifindex; +struct net_device *dev; +netdevice_tracker dev_tracker;canid_t txid;canid_t rxid;ktime_t tx_gap;
@@ -965,6 +967,14 @@ static int isotp_sendmsg(struct socket * goto err_event_drop; } +/* so->bound is only checked once above - a wakeup may have +* unbound/rebound the socket meanwhile, so re-validate it +*/ +if (!so->bound) { + err = -EADDRNOTAVAIL ; + goto err_out_drop; + } +/* PDU size > default => try max_pdu_size */ if (size > so->tx.buflen && so->tx.buflen < max_pdu_size) {u8 *newbuf =kmalloc (max_pdu_size,GFP_KERNEL );
@@ -1200,28 +1210,30 @@ static int isotp_release(struct socket *list_del (&so->notifier);spin_unlock (&isotp_notifier_lock); +rtnl_lock ();lock_sock (sk); -/* remove current filters & unregister */ -if (so->bound) { -if (so->ifindex) { -struct net_device *dev; - - dev =dev_get_by_index (net, so->ifindex); -if (dev) { -if (isotp_register_rxid (so)) -can_rx_unregister (net, dev, so->rxid, -SINGLE_MASK (so->rxid), - isotp_rcv, sk); - -can_rx_unregister (net, dev, so->txid, -SINGLE_MASK (so->txid), - isotp_rcv_echo, sk); -dev_put (dev); - } - } +/* remove current filters & unregister +* tracked reference so->dev is taken at bind() time with rtnl_lock +*/ +if (so->bound && so->dev) { +if (isotp_register_rxid (so)) +can_rx_unregister (net, so->dev, so->rxid, +SINGLE_MASK (so->rxid), + isotp_rcv, sk); + +can_rx_unregister (net, so->dev, so->txid, +SINGLE_MASK (so->txid), + isotp_rcv_echo, sk); +netdev_put (so->dev, &so->dev_tracker); } + so->ifindex =0 ; + so->bound =0 ; + so->dev =NULL ; + +rtnl_unlock (); +/* Always wait for a grace period before touching the timers below. * A concurrent NETDEV_UNREGISTER may have already unregistered our * filters and cleared so->bound in isotp_notify() without waiting
@@ -1234,9 +1246,6 @@ static int isotp_release(struct socket *hrtimer_cancel (&so->txtimer);hrtimer_cancel (&so->rxtimer); - so->ifindex =0 ; - so->bound =0 ; -sock_orphan (sk); sock->sk =NULL ;
@@ -1291,6 +1300,7 @@ static int isotp_bind(struct socket *socif (!addr->can_ifindex)return -ENODEV ; +rtnl_lock ();lock_sock (sk);if (so->bound) {
@@ -1298,6 +1308,17 @@ static int isotp_bind(struct socket *soc goto out; } +/* A transmission or reception that outlived a previous binding +* (unbound by NETDEV_UNREGISTER) may still be draining; the FC/echo +* and RX watchdog timers bound how long this takes. Checked together +* with so->bound in the same lock_sock() section above, so there is +* no window in which a concurrent isotp_notify() could be missed. +*/ +if (so->tx.state !=ISOTP_IDLE || so->rx.state !=ISOTP_IDLE ) { + err = -EAGAIN ; + goto out; + } +/* ensure different CAN IDs when the rx_id is to be registered */ if (isotp_register_rxid (so) && rx_id == tx_id) { err = -EADDRNOTAVAIL ;
@@ -1310,14 +1331,12 @@ static int isotp_bind(struct socket *soc goto out; }if (dev->type !=ARPHRD_CAN ) { -dev_put (dev); err = -ENODEV ; - goto out; + goto out_put_dev; }if (READ_ONCE (dev->mtu) < so->ll.mtu) { -dev_put (dev); err = -EINVAL ; - goto out; + goto out_put_dev; }if (!(dev->flags &IFF_UP )) notify_enetdown =1 ;
@@ -1335,16 +1354,25 @@ static int isotp_bind(struct socket *soccan_rx_register (net, dev, tx_id,SINGLE_MASK (tx_id), isotp_rcv_echo, sk,"isotpe" , sk); -dev_put (dev); -/* switch to new settings */ so->ifindex = ifindex; so->rxid = rx_id; so->txid = tx_id; so->bound =1 ; +/* bind() ok -> hold a reference for so->dev so that isotp_release() +* can safely reach the device later, even if a concurrent +* NETDEV_UNREGISTER has already unlisted it by ifindex. +*/ + so->dev = dev; +netdev_hold (so->dev, &so->dev_tracker,GFP_KERNEL ); + +out_put_dev: +/* remove potential reference from dev_get_by_index() */ +dev_put (dev); out:release_sock (sk); +rtnl_unlock ();if (notify_enetdown) { sk->sk_err =ENETDOWN ;
@@ -1547,7 +1575,7 @@ static void isotp_notify(struct isotp_soif (!net_eq (dev_net (dev),sock_net (sk)))return ; -if (so->ifindex != dev->ifindex) +if (so->dev != dev)return ;switch (msg) {
@@ -1563,10 +1591,12 @@ static void isotp_notify(struct isotp_socan_rx_unregister (dev_net (dev), dev, so->txid,SINGLE_MASK (so->txid), isotp_rcv_echo, sk); +netdev_put (so->dev, &so->dev_tracker); } so->ifindex =0 ; so->bound =0 ; + so->dev =NULL ;release_sock (sk); sk->sk_err =ENODEV ;
@@ -1626,6 +1656,7 @@ static int isotp_init(struct sock *sk) so->ifindex =0 ; so->bound =0 ; + so->dev =NULL ; so->opt.flags =CAN_ISOTP_DEFAULT_FLAGS ; so->opt.ext_address =CAN_ISOTP_DEFAULT_EXT_ADDRESS ;
Greg Kroah-Hartman
maintainerPATCH 1334/1611 can: isotp: serialize TX state transitions under so->rx_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit cf070fe33bfbd1a4c21236078fadb35dd223a157 upstream.
The TX state machine (so->tx.state) is driven from three contexts:sendmsg() claiming and progressing a transfer, the RX path consuming Flow Control/echo frames, and two hrtimers timing out a stalled transfer. Mixing a lock-free cmpxchg() claim in sendmsg() with hrtimer_cancel() calls made under so->rx_lock elsewhere left windows where a frame or timer callback could act on a state that had already moved on, corrupting an unrelated transfer.
so->rx_lock now covers the full lifecycle of a TX claim: sendmsg() takes it to check so->tx.state is ISOTP_IDLE, switch it to ISOTP_SENDING, bump so->tx_gen and drain the previous transfer's timers - all as one critical section. isotp_rcv_fc()/isotp_rcv_cf() already run under this lock via isotp_rcv(), and isotp_rcv_echo() now takes it itself, so none of them can ever observe a transfer mid-claim. This also means a transfer can no longer be handed to sendmsg()'s cleanup paths (signal or send error) while another thread is concurrently claiming or finishing it, so those paths can cancel timers and reset the state unconditionally.
isotp_release() claims the socket the same way, so a racing sendmsg() sees a consistent ISOTP_SHUTDOWN and skips arming its timer or sending.
Only the hrtimer callbacks stay outside so->rx_lock, since they run under so->rx_lock's cancellation elsewhere and taking it themselves would deadlock. so->tx_gen lets them recognize whether the transfer they timed out is still the one currently active, so they don't report an error against a transfer that has since completed or been superseded.
--- net/can/isotp.c | 202 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 160 insertions(+), 42 deletions(-)
net/can/isotp.c +160 -42
@@ -157,7 +157,7 @@ struct isotp_sock {canid_t rxid;ktime_t tx_gap;ktime_t lastrxcf_tstamp; -struct hrtimer rxtimer, txtimer, txfrtimer; +struct hrtimer rxtimer, txtimer, txfrtimer, echotimer;struct can_isotp_options opt;struct can_isotp_fc_options rxfc, txfc;struct can_isotp_ll_options ll;
@@ -165,6 +165,7 @@ struct isotp_sock {u32 force_tx_stmin;u32 force_rx_stmin;u32 cfecho;/* consecutive frame echo tag */ +u32 tx_gen;/* generation, bumped per new tx transfer */ struct tpcon rx, tx;struct list_head notifier;wait_queue_head_t wait;
@@ -372,6 +373,15 @@ static int isotp_rcv_fc(struct isotp_sochrtimer_cancel (&so->txtimer); +/* isotp_tx_timeout() may have given up on this job while +* hrtimer_cancel() above waited for it to finish; so->rx_lock +* (held by our caller isotp_rcv()) rules out a concurrent claim, +* so a plain recheck is enough here. +*/ +if (so->tx.state !=ISOTP_WAIT_FC && + so->tx.state !=ISOTP_WAIT_FIRST_FC ) +return 1 ; +if ((cf->len < ae +FC_CONTENT_SZ ) || ((so->opt.flags &ISOTP_CHECK_PADDING ) &&check_pad (so, cf, ae +FC_CONTENT_SZ , so->opt.rxpad_content))) {
@@ -418,7 +428,7 @@ static int isotp_rcv_fc(struct isotp_soc so->tx.bs =0 ; so->tx.state =ISOTP_SENDING ;/* send CF frame and enable echo timeout handling */ -hrtimer_start (&so->txtimer,ktime_set (ISOTP_ECHO_TIMEOUT ,0 ), +hrtimer_start (&so->echotimer,ktime_set (ISOTP_ECHO_TIMEOUT ,0 ),HRTIMER_MODE_REL_SOFT );isotp_send_cframe (so);break ;
@@ -571,6 +581,14 @@ static int isotp_rcv_cf(struct sock *sk,hrtimer_cancel (&so->rxtimer); +/* isotp_rx_timer_handler() may have raced us for so->rx.state +* while hrtimer_cancel() above waited for it to finish, already +* reporting ETIMEDOUT and resetting the reception; don't process +* this CF into a reassembly that has already been given up on. +*/ +if (so->rx.state !=ISOTP_WAIT_DATA ) +return 1 ; +/* CFs are never longer than the FF */ if (cf->len > so->rx.ll_dl)return 1 ;
@@ -860,20 +878,36 @@ static void isotp_rcv_echo(struct sk_bufstruct canfd_frame *cf = (struct canfd_frame *)skb->data;/* only handle my own local echo CF/SF skb's (no FF!) */ -if (skb->sk != sk || so->cfecho != *(u32 *)cf->data) +if (skb->sk != sk)return ; +/* unlike isotp_rcv_fc()/isotp_rcv_cf(), not already under so->rx_lock +* (no isotp_rcv() caller here), so take it ourselves +*/ +spin_lock (&so->rx_lock); + +/* so->cfecho may since belong to a new transfer; recheck under lock */ +if (so->cfecho != *(u32 *)cf->data) + goto out_unlock; +/* cancel local echo timeout */ -hrtimer_cancel (&so->txtimer); +hrtimer_cancel (&so->echotimer);/* local echo skb with consecutive frame has been consumed */ so->cfecho =0 ; +/* claiming a transfer also takes so->rx_lock, so a plain recheck +* is enough: so->tx.state can't have flipped to ISOTP_SENDING for +* a new claim while we're still in here +*/ +if (so->tx.state !=ISOTP_SENDING ) + goto out_unlock; +if (so->tx.idx >= so->tx.len) {/* we are done */ so->tx.state =ISOTP_IDLE ;wake_up_interruptible (&so->wait); -return ; + goto out_unlock; }if (so->txfc.bs && so->tx.bs >= so->txfc.bs) {
@@ -881,53 +915,83 @@ static void isotp_rcv_echo(struct sk_buf so->tx.state =ISOTP_WAIT_FC ;hrtimer_start (&so->txtimer,ktime_set (ISOTP_FC_TIMEOUT ,0 ),HRTIMER_MODE_REL_SOFT ); -return ; + goto out_unlock; }/* no gap between data frames needed => use burst mode */ if (!so->tx_gap) {/* enable echo timeout handling */ -hrtimer_start (&so->txtimer,ktime_set (ISOTP_ECHO_TIMEOUT ,0 ), +hrtimer_start (&so->echotimer,ktime_set (ISOTP_ECHO_TIMEOUT ,0 ),HRTIMER_MODE_REL_SOFT );isotp_send_cframe (so); -return ; + goto out_unlock; }/* start timer to send next consecutive frame with correct delay */ hrtimer_start (&so->txfrtimer, so->tx_gap,HRTIMER_MODE_REL_SOFT ); + +out_unlock: +spin_unlock (&so->rx_lock); } -static enum hrtimer_restart isotp_tx_timer_handler (struct hrtimer *hrtimer) +/* shared by so->txtimer's and so->echotimer's callbacks. Both timers get +* cancelled under so->rx_lock elsewhere, so this must stay lock-free to +* avoid deadlocking with that; uses so->tx_gen instead to avoid tainting +* a new transfer with an error from the one that just timed out. +*/ +static enum hrtimer_restart isotp_tx_timeout (struct isotp_sock *so) { - struct isotp_sock *so = container_of(hrtimer, struct isotp_sock, - txtimer);struct sock *sk = &so->sk; +u32 gen =READ_ONCE (so->tx_gen); +u32 old_state =READ_ONCE (so->tx.state);/* don't handle timeouts in IDLE or SHUTDOWN state */ -if (so->tx.state ==ISOTP_IDLE || so->tx.state ==ISOTP_SHUTDOWN ) +if (old_state ==ISOTP_IDLE || old_state ==ISOTP_SHUTDOWN ) +return HRTIMER_NORESTART ; + +/* only claim the timeout if the state is still unchanged */ +if (cmpxchg (&so->tx.state, old_state,ISOTP_IDLE ) != old_state)return HRTIMER_NORESTART ;/* we did not get any flow control or echo frame in time */ -/* report 'communication error on send' */ - sk->sk_err =ECOMM ; -if (!sock_flag (sk,SOCK_DEAD )) -sk_error_report (sk); +if (READ_ONCE (so->tx_gen) == gen) { +/* report 'communication error on send' */ + sk->sk_err =ECOMM ; +if (!sock_flag (sk,SOCK_DEAD )) +sk_error_report (sk); + } -/* reset tx state */ - so->tx.state =ISOTP_IDLE ;wake_up_interruptible (&so->wait);return HRTIMER_NORESTART ; } +/* so->txtimer: fires when a Flow Control frame does not arrive in time */ +static enum hrtimer_restart isotp_tx_timer_handler (struct hrtimer *hrtimer) +{ + struct isotp_sock *so = container_of(hrtimer, struct isotp_sock, + txtimer); + +return isotp_tx_timeout (so); +} + +/* so->echotimer: fires when a sent CF/SF's local echo does not arrive */ +static enum hrtimer_restart isotp_echo_timer_handler (struct hrtimer *hrtimer) +{ + struct isotp_sock *so = container_of(hrtimer, struct isotp_sock, + echotimer); + +return isotp_tx_timeout (so); +} +static enum hrtimer_restart isotp_txfr_timer_handler (struct hrtimer *hrtimer) { struct isotp_sock *so = container_of(hrtimer, struct isotp_sock, txfrtimer);/* start echo timeout handling and cover below protocol error */ -hrtimer_start (&so->txtimer,ktime_set (ISOTP_ECHO_TIMEOUT ,0 ), +hrtimer_start (&so->echotimer,ktime_set (ISOTP_ECHO_TIMEOUT ,0 ),HRTIMER_MODE_REL_SOFT );/* cfecho should be consumed by isotp_rcv_echo() here */
@@ -947,13 +1011,24 @@ static int isotp_sendmsg(struct socket *int ae = (so->opt.flags &CAN_ISOTP_EXTEND_ADDR ) ?1 :0 ;int wait_tx_done = (so->opt.flags &CAN_ISOTP_WAIT_TX_DONE ) ?1 :0 ;s64 hrtimer_sec =ISOTP_ECHO_TIMEOUT ; +struct hrtimer *tx_hrt = &so->echotimer; +u32 new_state =ISOTP_SENDING ;int off;int err;if (!so->bound || so->tx.state ==ISOTP_SHUTDOWN )return -EADDRNOTAVAIL ; -while (cmpxchg (&so->tx.state,ISOTP_IDLE ,ISOTP_SENDING ) !=ISOTP_IDLE ) { +/* claim the socket under so->rx_lock: this serializes the claim +* with the RX path and with sendmsg()'s own error paths below, so +* none of them can ever see a transfer mid-claim +*/ +for (;;) { +spin_lock_bh (&so->rx_lock); +if (READ_ONCE (so->tx.state) ==ISOTP_IDLE ) +break ; +spin_unlock_bh (&so->rx_lock); +/* we do not support multiple buffers - for now */ if (msg->msg_flags &MSG_DONTWAIT )return -EAGAIN ;
@@ -962,11 +1037,23 @@ static int isotp_sendmsg(struct socket *return -EADDRNOTAVAIL ;/* wait for complete transmission of current pdu */ - err =wait_event_interruptible (so->wait, so->tx.state ==ISOTP_IDLE ); + err =wait_event_interruptible (so->wait, + so->tx.state ==ISOTP_IDLE );if (err) - goto err_event_drop; +return err; } +/* new transfer: bump so->tx_gen and drain the old one's timers, +* still under the so->rx_lock we just claimed the socket with +*/ +WRITE_ONCE (so->tx.state,ISOTP_SENDING ); +WRITE_ONCE (so->tx_gen,READ_ONCE (so->tx_gen) +1 ); +hrtimer_cancel (&so->txtimer); +hrtimer_cancel (&so->echotimer); +hrtimer_cancel (&so->txfrtimer); + so->cfecho =0 ; +spin_unlock_bh (&so->rx_lock); +/* so->bound is only checked once above - a wakeup may have * unbound/rebound the socket meanwhile, so re-validate it */
@@ -1077,18 +1164,33 @@ static int isotp_sendmsg(struct socket * so->cfecho = *(u32 *)cf->data; }else {/* standard flow control check */ - so->tx.state =ISOTP_WAIT_FIRST_FC ; + new_state =ISOTP_WAIT_FIRST_FC ;/* start timeout for FC */ hrtimer_sec =ISOTP_FC_TIMEOUT ; + tx_hrt = &so->txtimer;/* no CF echo tag for isotp_rcv_echo() (FF-mode) */ so->cfecho =0 ; } } -hrtimer_start (&so->txtimer,ktime_set (hrtimer_sec,0 ), +spin_lock_bh (&so->rx_lock); +if (so->tx.state ==ISOTP_SHUTDOWN ) { +/* isotp_release() has since taken over and already drained +* our timers - don't send into a socket that's going away +*/ +spin_unlock_bh (&so->rx_lock); +kfree_skb (skb); +dev_put (dev); +wake_up_interruptible (&so->wait); +return -EADDRNOTAVAIL ; + } +/* WAIT_FIRST_FC for standard FF, else stays ISOTP_SENDING */ + so->tx.state = new_state; +hrtimer_start (tx_hrt,ktime_set (hrtimer_sec,0 ),HRTIMER_MODE_REL_SOFT ); +spin_unlock_bh (&so->rx_lock);/* send the first or only CAN frame */ cf->flags = so->ll.tx_flags;
@@ -1101,13 +1203,10 @@ static int isotp_sendmsg(struct socket *pr_notice_once ("can-isotp: %s: can_send_ret %pe\n" , __func__,ERR_PTR (err)); +spin_lock_bh (&so->rx_lock);/* no transmission -> no timeout monitoring */ -hrtimer_cancel (&so->txtimer); - -/* reset consecutive frame echo tag */ - so->cfecho =0 ; - - goto err_out_drop; +hrtimer_cancel (tx_hrt); + goto err_out_drop_locked; }if (wait_tx_done) {
@@ -1123,14 +1222,21 @@ static int isotp_sendmsg(struct socket *return size; +err_out_drop: +/* claimed but nothing sent yet - no timer to cancel */ +spin_lock_bh (&so->rx_lock); + goto err_out_drop_locked; err_event_drop: -/* got signal: force tx state machine to be idle */ - so->tx.state =ISOTP_IDLE ; +/* interrupted waiting on our own transfer - drain its timers */ +spin_lock_bh (&so->rx_lock);hrtimer_cancel (&so->txfrtimer);hrtimer_cancel (&so->txtimer); -err_out_drop: -/* drop this PDU and unlock a potential wait queue */ +hrtimer_cancel (&so->echotimer); +err_out_drop_locked: +/* release the claim; so->rx_lock still held from above */ + so->cfecho =0 ; so->tx.state =ISOTP_IDLE ; +spin_unlock_bh (&so->rx_lock);wake_up_interruptible (&so->wait);return err;
@@ -1192,13 +1298,20 @@ static int isotp_release(struct socket * so =isotp_sk (sk); net =sock_net (sk); -/* wait for complete transmission of current pdu */ -while (wait_event_interruptible (so->wait, so->tx.state ==ISOTP_IDLE ) ==0 && -cmpxchg (&so->tx.state,ISOTP_IDLE ,ISOTP_SHUTDOWN ) !=ISOTP_IDLE ) +/* best-effort: wait for a running pdu to finish, but don't block on +* it forever - give up after the first signal +*/ +while (so->tx.state !=ISOTP_IDLE && +wait_event_interruptible (so->wait, so->tx.state ==ISOTP_IDLE ) ==0 ) ; -/* force state machines to be idle also when a signal occurred */ +/* claim the socket under so->rx_lock like sendmsg() does, so its +* claim can't race the forced ISOTP_SHUTDOWN below; force it +* unconditionally, even when a signal cut the wait above short +*/ +spin_lock_bh (&so->rx_lock); so->tx.state =ISOTP_SHUTDOWN ; +spin_unlock_bh (&so->rx_lock); so->rx.state =ISOTP_IDLE ;spin_lock (&isotp_notifier_lock);
@@ -1244,6 +1357,7 @@ static int isotp_release(struct socket *hrtimer_cancel (&so->txfrtimer);hrtimer_cancel (&so->txtimer); +hrtimer_cancel (&so->echotimer);hrtimer_cancel (&so->rxtimer);sock_orphan (sk);
@@ -1683,10 +1797,14 @@ static int isotp_init(struct sock *sk) so->rx.buflen =ARRAY_SIZE (so->rx.sbuf); so->tx.buflen =ARRAY_SIZE (so->tx.sbuf); -hrtimer_setup (&so->rxtimer, isotp_rx_timer_handler,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT ); -hrtimer_setup (&so->txtimer, isotp_tx_timer_handler,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT ); -hrtimer_setup (&so->txfrtimer, isotp_txfr_timer_handler,CLOCK_MONOTONIC , -HRTIMER_MODE_REL_SOFT ); +hrtimer_setup (&so->rxtimer, isotp_rx_timer_handler, +CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT ); +hrtimer_setup (&so->txtimer, isotp_tx_timer_handler, +CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT ); +hrtimer_setup (&so->echotimer, isotp_echo_timer_handler, +CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT ); +hrtimer_setup (&so->txfrtimer, isotp_txfr_timer_handler, +CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT );init_waitqueue_head (&so->wait);spin_lock_init (&so->rx_lock);
Greg Kroah-Hartman
maintainerPATCH 1335/1611 can: bcm: defer rx_op deallocation to workqueue to fix thrtimer UAF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
commit 68973f9db76144825e4f35dfdc80fb8279eb2d57 upstream.
Commit f1b4e32aca08 ("can: bcm: use call_rcu() instead of costly synchronize_rcu()") replaced synchronize_rcu() in bcm_delete_rx_op() with call_rcu() and introduced the RX_NO_AUTOTIMER flag.
However, this flag check was omitted for thrtimer in the packet rx fast-path. During BCM RX operation teardown, a concurrent RCU reader (bcm_rx_handler) can race and re-arm thrtimer via bcm_rx_update_and_send() after call_rcu() has been scheduled. Once the RCU grace period elapses, bcm_op is freed. The subsequently firing thrtimer then dereferences the deallocated op, causing a UAF.
Adding flag checks to the rx fast-path (bcm_rx_update_and_send) does not fully close the TOCTOU race and introduces latency for every CAN frame. Conversely, calling hrtimer_cancel() directly inside the RCU callback (softirq context) is fatal as hrtimer_cancel() can sleep, triggering a "scheduling while atomic" panic.
Resolve this by deferring the timer cancellation and memory free to a dedicated unbound workqueue (bcm_wq). The RCU callback now queues a work item to bcm_wq, which safely cancels both timers and deallocates memory in sleepable process context. A dedicated workqueue is used to prevent system-wide WQ saturation and is cleanly flushed/destroyed on module unload to avoid rmmod page faults.
Since the deferred work can now outlive the calling context by an unbounded amount, also take a reference on op->sk when it is assigned and drop it only once the deferred work has cancelled both timers, so a socket can no longer be freed out from under a still-armed timer whose callback (bcm_send_to_user()) dereferences op->sk.
--- net/can/bcm.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-)
net/can/bcm.c +34 -3
@@ -58,6 +58,7 @@#include <linux/can/skb.h> #include <linux/can/bcm.h> #include <linux/slab.h> +#include <linux/workqueue.h> #include <linux/spinlock.h> #include <net/sock.h> #include <net/net_namespace.h>
@@ -91,6 +92,8 @@ MODULE_ALIAS("can-proto-2");#define BCM_MIN_NAMELEN CAN_REQUIRED_SIZE(struct sockaddr_can, can_ifindex) +static struct workqueue_struct *bcm_wq; +/* * easy access to the first 64 bit of can(fd)_frame payload. cp->data is * 64 bit aligned so the offset has to be multiples of 8 which is ensured
@@ -104,6 +107,7 @@ static inline u64 get_u64(const struct cstruct bcm_op {struct list_head list;struct rcu_head rcu; +struct work_struct work;int ifindex;canid_t can_id;u32 flags;
@@ -788,9 +792,12 @@ static struct bcm_op *bcm_find_op(structreturn NULL ; } -static void bcm_free_op_rcu (struct rcu_head *rcu_head) +static void bcm_free_op_work (struct work_struct *work) { - struct bcm_op *op = container_of(rcu_head, struct bcm_op, rcu); + struct bcm_op *op = container_of(work, struct bcm_op, work); + +hrtimer_cancel (&op->timer); +hrtimer_cancel (&op->thrtimer);if ((op->frames) && (op->frames != &op->sframe))kfree (op->frames);
@@ -798,9 +805,23 @@ static void bcm_free_op_rcu(struct rcu_hif ((op->last_frames) && (op->last_frames != &op->last_sframe))kfree (op->last_frames); +/* the last possible access to op->timer/op->thrtimer has now +* happened above via hrtimer_cancel() - op->sk is no longer +* needed by any pending timer callback, so drop our reference +*/ +sock_put (op->sk); +kfree (op); } +static void bcm_free_op_rcu (struct rcu_head *rcu_head) +{ + struct bcm_op *op = container_of(rcu_head, struct bcm_op, rcu); + +INIT_WORK (&op->work, bcm_free_op_work); +queue_work (bcm_wq, &op->work); +} +static void bcm_remove_op (struct bcm_op *op) {hrtimer_cancel (&op->timer);
@@ -1055,6 +1076,7 @@ static int bcm_tx_setup(struct bcm_msg_h/* bcm_can_tx / bcm_tx_timeout_handler needs this */ op->sk = sk; +sock_hold (sk); op->ifindex = ifindex;/* initialize uninitialized (kzalloc) structure */
@@ -1216,6 +1238,7 @@ static int bcm_rx_setup(struct bcm_msg_h/* bcm_can_tx / bcm_tx_timeout_handler needs this */ op->sk = sk; +sock_hold (sk); op->ifindex = ifindex;/* ifindex for timeout events w/o previous frame reception */
@@ -1830,11 +1853,15 @@ static int __init bcm_module_init(void) {int err; + bcm_wq =alloc_workqueue ("can-bcm-wq" ,WQ_UNBOUND ,0 ); +if (!bcm_wq) +return -ENOMEM ; +pr_info ("can: broadcast manager protocol\n" ); err =register_pernet_subsys (&canbcm_pernet_ops);if (err) -return err; + goto register_pernet_failed; err =register_netdevice_notifier (&canbcm_notifier);if (err)
@@ -1852,6 +1879,8 @@ register_proto_failed:unregister_netdevice_notifier (&canbcm_notifier); register_notifier_failed:unregister_pernet_subsys (&canbcm_pernet_ops); +register_pernet_failed: +destroy_workqueue (bcm_wq);return err; }
@@ -1860,6 +1889,8 @@ static void __exit bcm_module_exit(void)can_proto_unregister (&bcm_can_proto);unregister_netdevice_notifier (&canbcm_notifier);unregister_pernet_subsys (&canbcm_pernet_ops); +rcu_barrier (); +destroy_workqueue (bcm_wq); }module_init (bcm_module_init);
Greg Kroah-Hartman
maintainerPATCH 1336/1611 can: bcm: fix lockless bound/ifindex race and silent RX_SETUP failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit d9b091d9d22fee81ec53fb55d2032951993ceadb upstream.
bcm_sendmsg() reads bo->ifindex and checks bo->bound before taking lock_sock(), while bcm_notify(), bcm_connect() and bcm_release() all mutate both fields under that same lock. Because the lockless reads and the locked writes are unordered with respect to each other, a racing bcm_notify() (device unregister) or bcm_connect() (concurrent bind on another thread sharing the socket) can make bcm_sendmsg() observe an inconsistent combination, e.g. a stale bound=1 together with the now-cleared ifindex=0, silently turning a socket bound to a specific CAN interface into one that also matches "any" interface.
Keep the lockless bo->bound check purely as a fast-path reject, and move the ifindex read (and a bo->bound re-check) into the locked section, where every writer already serializes. This removes the possibility of observing the two fields torn against each other, rather than trying to fix it with more READ_ONCE()/WRITE_ONCE() pairs on two independently updated fields. Annotate the now-purely-lockless bo->bound accesses consistently across all its write sites.
Also fix bcm_rx_setup() silently returning success when the target device disappears concurrently instead of reporting -ENODEV, so a broken RX op is no longer left registered as if it had succeeded.
--- net/can/bcm.c | 65 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 14 deletions(-)
net/can/bcm.c +51 -14
@@ -1318,6 +1318,11 @@ static int bcm_rx_setup(struct bcm_msg_h op->rx_reg_dev = dev;dev_put (dev); + }else { +/* the requested device is gone - do not +* silently succeed without registering +*/ + err = -ENODEV ; } }else
@@ -1387,12 +1392,13 @@ static int bcm_sendmsg(struct socket *so {struct sock *sk = sock->sk;struct bcm_sock *bo =bcm_sk (sk); -int ifindex = bo->ifindex;/* default ifindex for this bcm_op */ +int ifindex;struct bcm_msg_head msg_head;int cfsiz;int ret;/* read bytes or error codes as return value */ -if (!bo->bound) +/* Lockless fast-path check for bound socket */ +if (!READ_ONCE (bo->bound))return -ENOTCONN ;/* check for valid message length from userspace */
@@ -1408,17 +1414,38 @@ static int bcm_sendmsg(struct socket *soif ((size -MHSIZ ) % cfsiz)return -EINVAL ; +lock_sock (sk); + +/* Re-validate under the socket lock: a concurrent bcm_notify() +* may have unbound this socket (device removal) after the +* lockless fast-path check above. bo->ifindex is only ever +* mutated under lock_sock(), so reading it here - instead of +* before taking the lock - guarantees it can't be observed +* torn against bo->bound. +*/ +if (!bo->bound) { + ret = -ENOTCONN ; + goto out_release; + } + +/* default ifindex for this bcm_op */ + ifindex = bo->ifindex; +/* check for alternative ifindex for this bcm_op */ if (!ifindex && msg->msg_name) {/* no bound device as default => check msg_name */ DECLARE_SOCKADDR(struct sockaddr_can *, addr, msg->msg_name); -if (msg->msg_namelen <BCM_MIN_NAMELEN ) -return -EINVAL ; +if (msg->msg_namelen <BCM_MIN_NAMELEN ) { + ret = -EINVAL ; + goto out_release; + } -if (addr->can_family !=AF_CAN ) -return -EINVAL ; +if (addr->can_family !=AF_CAN ) { + ret = -EINVAL ; + goto out_release; + }/* ifindex from sendto() */ ifindex = addr->can_ifindex;
@@ -1427,20 +1454,21 @@ static int bcm_sendmsg(struct socket *sostruct net_device *dev; dev =dev_get_by_index (sock_net (sk), ifindex); -if (!dev) -return -ENODEV ; +if (!dev) { + ret = -ENODEV ; + goto out_release; + }if (dev->type !=ARPHRD_CAN ) {dev_put (dev); -return -ENODEV ; + ret = -ENODEV ; + goto out_release; }dev_put (dev); } } -lock_sock (sk); -switch (msg_head.opcode) {case TX_SETUP :
@@ -1490,6 +1518,7 @@ static int bcm_sendmsg(struct socket *sobreak ; } +out_release:release_sock (sk);return ret;
@@ -1526,7 +1555,12 @@ static void bcm_notify(struct bcm_sock * bo->bcm_proc_read = NULL; }#endif - bo->bound =0 ; +/* Paired with the lockless fast-path check in +* bcm_sendmsg(); bo->ifindex itself is only ever +* accessed under lock_sock() so it needs no +* annotation. +*/ +WRITE_ONCE (bo->bound,0 ); bo->ifindex =0 ; notify_enodev =1 ; }
@@ -1667,7 +1701,7 @@ static int bcm_release(struct socket *so/* remove device reference */ if (bo->bound) { - bo->bound =0 ; +WRITE_ONCE (bo->bound,0 ); bo->ifindex =0 ; }
@@ -1737,7 +1771,10 @@ static int bcm_connect(struct socket *so }#endif /* CONFIG_PROC_FS */ - bo->bound =1 ; +/* bo->ifindex above is fully assigned before this point; pairs +* with the lockless fast-path check in bcm_sendmsg() +*/ +WRITE_ONCE (bo->bound,1 ); fail:release_sock (sk);
Greg Kroah-Hartman
maintainerPATCH 1337/1611 can: bcm: add missing rcu list annotations and operations
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 7b2c3eabc4dafc062a25e10711154f2107526a78 upstream.
sashiko-bot remarked the missing use of list_add_rcu() in bcm_[rx|tx]_setup() to have a proper initialized bcm_op structure when bcm_proc_show() traverses the bcm_op's under rcu_read_lock().
To cover all initial settings of the bcm_op's the list_add_rcu() calls are moved to the end of the setup code.
While at it, also fix the mirroring removal side: bcm_release() called bcm_remove_op() - which frees the op via call_rcu() - on ops that were still linked in bo->tx_ops/bo->rx_ops, without list_del_rcu() first. Unlink each op with list_del_rcu() before handing it to bcm_remove_op(), matching the existing pattern in bcm_delete_tx_op()/bcm_delete_rx_op().
--- net/can/bcm.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
net/can/bcm.c +16 -9
@@ -260,7 +260,7 @@ static int bcm_proc_show(struct seq_file (reduction == 100) ? "near " : "", reduction); } -list_for_each_entry (op, &bo->tx_ops, list) { +list_for_each_entry_rcu (op, &bo->tx_ops, list) {seq_printf (m,"tx_op: %03X %s " , op->can_id,bcm_proc_getifname (net, ifname, op->ifindex));
@@ -946,6 +946,7 @@ static int bcm_tx_setup(struct bcm_msg_hstruct bcm_sock *bo =bcm_sk (sk);struct bcm_op *op;struct canfd_frame *cf; +bool add_op_to_list = false;unsigned int i;int err;
@@ -1087,8 +1088,7 @@ static int bcm_tx_setup(struct bcm_msg_hhrtimer_setup (&op->thrtimer, hrtimer_dummy_timeout,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT ); -/* add this bcm_op to the list of the tx_ops */ -list_add (&op->list, &bo->tx_ops); + add_op_to_list = true; }/* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
@@ -1110,6 +1110,10 @@ static int bcm_tx_setup(struct bcm_msg_h op->flags |=TX_ANNOUNCE ; } +/* add this bcm_op to the list of the tx_ops? */ +if (add_op_to_list) +list_add_rcu (&op->list, &bo->tx_ops); +if (op->flags &TX_ANNOUNCE )bcm_can_tx (op);
@@ -1250,9 +1254,6 @@ static int bcm_rx_setup(struct bcm_msg_hhrtimer_setup (&op->thrtimer, bcm_rx_thr_handler,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_SOFT ); -/* add this bcm_op to the list of the rx_ops */ -list_add (&op->list, &bo->rx_ops); -/* call can_rx_register() */ do_rx_register =1 ;
@@ -1331,10 +1332,12 @@ static int bcm_rx_setup(struct bcm_msg_h bcm_rx_handler, op, "bcm", sk);if (err) {/* this bcm rx op is broken -> remove it */ -list_del_rcu (&op->list);bcm_remove_op (op);return err; } + +/* add this bcm_op to the list of the rx_ops */ +list_add_rcu (&op->list, &bo->rx_ops); }return msg_head->nframes * op->cfsiz +MHSIZ ;
@@ -1664,8 +1667,10 @@ static int bcm_release(struct socket *soremove_proc_entry (bo->procname, net->can.bcmproc_dir);#endif /* CONFIG_PROC_FS */ -list_for_each_entry_safe (op, next, &bo->tx_ops, list) +list_for_each_entry_safe (op, next, &bo->tx_ops, list) { +list_del_rcu (&op->list);bcm_remove_op (op); + }list_for_each_entry_safe (op, next, &bo->rx_ops, list) {/*
@@ -1696,8 +1701,10 @@ static int bcm_release(struct socket *sosynchronize_rcu (); -list_for_each_entry_safe (op, next, &bo->rx_ops, list) +list_for_each_entry_safe (op, next, &bo->rx_ops, list) { +list_del_rcu (&op->list);bcm_remove_op (op); + }/* remove device reference */ if (bo->bound) {
Greg Kroah-Hartman
maintainerPATCH 1338/1611 bpf: Reset register bounds before narrowing retval range in check_mem_access()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 5e0b273e0a62cc04ec338c7b502797c66c2ed42a upstream.
When the BPF verifier processes a context load of an LSM hook return value, it calls __mark_reg_s32_range() to narrow the register to the hook's valid range. However, __mark_reg_s32_range() intersects the new range with the register's existing bounds using max_t()/min_t() rather than replacing them.
If the destination register carries stale bounds from a prior instruction (e.g. BPF_MOV64_IMM), the intersection can produce a range narrower than reality. The verifier then believes it knows the register's exact value, while at runtime the actual hook return value is loaded, creating a verifier/runtime mismatch that can be used to bypass BPF memory safety checks.
The else branch already calls mark_reg_unknown() to reset register state before any narrowing. Apply the same reset in the is_retval path so stale bounds are cleared before __mark_reg_s32_range() intersects.
--- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+)
kernel/bpf/verifier.c +1 -0
@@ -7672,6 +7672,7 @@ static int check_mem_access(struct bpf_v*/ if (info.reg_type ==SCALAR_VALUE ) {if (info.is_retval &&get_func_retval_range (env->prog, &range)) { +mark_reg_unknown (env, regs, value_regno); err =__mark_reg_s32_range (env, regs, value_regno, range.minval, range.maxval);if (err)
Greg Kroah-Hartman
maintainerPATCH 1339/1611 bpf,fork: wipe ->bpf_storage before bailouts that access it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
commit 9b51a6155d14389876916726430da30eabb1d4ed upstream.
Currently, copy_process() can bail out to free_task() before p->bpf_storage has been initialized, with this call graph (shown here for the !CONFIG_MEMCG case):
copy_process
dup_task_struct
arch_dup_task_struct
[copies the entire task_struct, including ->bpf_storage member]
[RLIMIT_NPROC check fails]
delayed_free_task
free_task
bpf_task_storage_free
rcu_dereference(task->bpf_storage)
bpf_local_storage_destroyIn this case, the nascent task's ->bpf_storage member that bpf_local_storage_destroy() operates on is a plain copy of the parent's ->bpf_storage pointer, not a real initialized pointer.
This leads to badness (kernel hangs, UAF).
This is reachable as long as the process calling fork() has been inserted into a task storage map.
--- kernel/fork.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/fork.c +5 -4
@@ -961,6 +961,11 @@ static struct task_struct *dup_task_stru tsk->mm_cid_active =0 ; tsk->migrate_from_cpu =-1 ;#endif + +#ifdef CONFIG_BPF_SYSCALL +RCU_INIT_POINTER (tsk->bpf_storage,NULL ); + tsk->bpf_ctx =NULL ; +#endif return tsk; free_stack:
@@ -2143,10 +2148,6 @@ __latent_entropy struct task_struct *cop p->sequential_io =0 ; p->sequential_io_avg =0 ;#endif -#ifdef CONFIG_BPF_SYSCALL -RCU_INIT_POINTER (p->bpf_storage,NULL ); - p->bpf_ctx =NULL ; -#endif unwind_task_init (p);
Greg Kroah-Hartman
maintainerPATCH 1340/1611 bpf: Add missing access_ok call to copy_user_syms
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Olsa <[email protected]>
commit d5dc200c3a3f217de072af269dd90adddf90e48d upstream.
As reported by sashiko we use __get_user without prior access_ok call on the user space pointer. Adding the missing call for the whole pointer array.
Plus removing the err check in the error path, because it's not needed and also we can return -ENOMEM directly from the first kvmalloc_array fail path.
Cc: [email protected]
[1] https://lore.kernel.org/bpf/[email protected]/
--- kernel/trace/bpf_trace.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
kernel/trace/bpf_trace.c +6 -5
@@ -2318,9 +2318,12 @@ static int copy_user_syms(struct user_syint err = -ENOMEM ;unsigned int i; +if (!access_ok (usyms, cnt *sizeof (*usyms))) +return -EFAULT ; + syms =kvmalloc_array (cnt,sizeof (*syms),GFP_KERNEL );if (!syms) - goto error; +return -ENOMEM ; buf =kvmalloc_array (cnt,KSYM_NAME_LEN ,GFP_KERNEL );if (!buf)
@@ -2345,10 +2348,8 @@ static int copy_user_syms(struct user_syreturn 0 ; error: -if (err) { -kvfree (syms); -kvfree (buf); - } +kvfree (syms); +kvfree (buf);return err; }
Greg Kroah-Hartman
maintainerPATCH 1341/1611 block: remove redundant GD_NEED_PART_SCAN in add_disk_final()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Connor Williamson <[email protected]>
commit 181bb9c9eae4f69fe510a62a42c2932d0314a800 upstream.
add_disk_final() sets GD_NEED_PART_SCAN before calling bdev_add(), then calls disk_scan_partitions() which sets the flag itself. The early set is redundant and introduces a race.
Between bdev_add() and disk_scan_partitions(), concurrent openers (multipathd, blkid, LVM) see the flag in blkdev_get_whole() and trigger bdev_disk_changed(). When disk_scan_partitions() then runs, it calls bdev_disk_changed() again, dropping the partitions the concurrent opener already created before re-adding them, which can result in transient partition disappearances.
The race is observable by inserting an msleep() between bdev_add() and disk_scan_partitions() while running concurrent open() calls during device bind. Without artificial delay, it manifests under scheduling pressure during boot on systems with aggressive device scanners (multipathd, systemd-udevd).
Therefore, do not set GD_NEED_PART_SCAN in add_disk_final(). Other GD_NEED_PART_SCAN consumers (blkdev_get_whole(), sd_need_revalidate()) should not be affected as the flag is set internally by disk_scan_partitions().
The retry-on-next-open intention from commit e5cfefa97bcc ("block: fix scan partition for exclusively open device again") should also not be affected as the early return paths in disk_scan_partitions() should be unreachable at device registration time (bd_holder is NULL and open_partitions is zero).
--- block/genhd.c | 4 ---- 1 file changed, 4 deletions(-)
block/genhd.c +0 -4
@@ -407,10 +407,6 @@ static void add_disk_final(struct gendisstruct device *ddev =disk_to_dev (disk);if (!(disk->flags &GENHD_FL_HIDDEN )) { -/* Make sure the first partition scan will be proceed */ -if (get_capacity (disk) &&disk_has_partscan (disk)) -set_bit (GD_NEED_PART_SCAN , &disk->state); -bdev_add (disk->part0, ddev->devt);if (get_capacity (disk))disk_scan_partitions (disk,BLK_OPEN_READ );
Greg Kroah-Hartman
maintainerPATCH 1342/1611 block: fix race in blk_time_get_ns() returning 0
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Waychison <[email protected]>
commit 691b052139c94ee6640ac39e0b764dd3867897c0 upstream.
blk_time_get_ns() populates the per-plug cached timestamp and then returns it by re-reading the field:
if (!plug->cur_ktime) {
plug->cur_ktime = ktime_get_ns();
current->flags |= PF_BLOCK_TS;
}
return plug->cur_ktime;This is problematic when the compiler emits the final "return plug->cur_ktime" as a reload from memory, after PF_BLOCK_TS has already been set.
Since the cached timestamp is now invalidated from finish_task_switch() (fad156c2af22 "block: invalidate cached plug timestamp after task switch"), a task preempted between setting PF_BLOCK_TS and that reload has plug->cur_ktime zeroed by blk_plug_invalidate_ts() when it is scheduled back in. The reload then returns 0.
A 0 handed back here is stored as a start timestamp -- e.g. blk_account_io_start() writes it to rq->start_time_ns -- and later subtracted from "now". blk_account_io_done() then adds (now - 0), i.e. roughly the system uptime, to the per-group nsecs[] counters. On an otherwise idle, healthy device this appears as sudden ~uptime-sized jumps in the diskstats time fields (write_ticks/discard_ticks/time_in_queue).
The solution is to be explicit in our reads and writes to this field that is preemption volatile. We also add a barrier() to ensure that any setting of PF_BLOCK_TS is ordered to happen after the cur_ktime update.
This issue was discovered using AI-assisted kprobes looking for paths that were leaking zeroed timestamps in a live system, based on the observation that we were sometimes seeing uptime-sized jumps in kernel exported counters. This was flagged by NodeDiskIOSaturation prometheus alerts that started firing on all hosts post 7.1.3 kernel upgrade, due to node-exporter now exporting a nonsensical node_disk_io_time_weighted_seconds_total.
--- block/blk.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
block/blk.h +10 -3
@@ -699,6 +699,7 @@ static inline int req_ref_read(struct restatic inline u64 blk_time_get_ns (void ) {struct blk_plug *plug = current->plug; +u64 now;if (!plug || !in_task ())return ktime_get_ns ();
@@ -707,12 +708,18 @@ static inline u64 blk_time_get_ns(void)* 0 could very well be a valid time, but rather than flag "this is * a valid timestamp" separately, just accept that we'll do an extra * ktime_get_ns() if we just happen to get 0 as the current time. +* +* cur_ktime can be zeroed by pre-emption the moment PF_BLOCK_TS is set. */ -if (!plug->cur_ktime) { - plug->cur_ktime =ktime_get_ns (); + now =READ_ONCE (plug->cur_ktime); +if (!now) { + now =ktime_get_ns (); +WRITE_ONCE (plug->cur_ktime, now); +/* Ensure PF_BLOCK_TS is set after cur_ktime. */ +barrier (); current->flags |=PF_BLOCK_TS ; } -return plug->cur_ktime; +return now; }static inline ktime_t blk_time_get (void )
Greg Kroah-Hartman
maintainerPATCH 1343/1611 block: fix IORING_URING_CMD_REISSUE flags check in blkdev_uring_cmd
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yitang Yang <[email protected]>
commit 4f919141be38ea2b1314e3a531b7b998eb64e8bc upstream.
blkdev_uring_cmd() checks IORING_URING_CMD_REISSUE to determine whether this is the first issue. However, this flag lives in cmd->flags instead of issue_flags.
Coincidentally, IO_URING_F_NONBLOCK shares bit 31 with IORING_URING_CMD_REISSUE. As a result, the SQE read was never performed, bic->len remained zero, and every BLOCK_URING_CMD_DISCARD failed with -EINVAL.
Fix it by checking cmd->flags as intended.
--- block/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/ioctl.c +1 -1
@@ -857,7 +857,7 @@ int blkdev_uring_cmd(struct io_uring_cmdu32 cmd_op = cmd->cmd_op;/* Read what we need from the SQE on the first issue */ -if (!(issue_flags &IORING_URING_CMD_REISSUE )) { +if (!(cmd->flags &IORING_URING_CMD_REISSUE )) {const struct io_uring_sqe *sqe = cmd->sqe; if (unlikely(sqe->ioprio || sqe->__pad1 || sqe->len ||
Greg Kroah-Hartman
maintainerPATCH 1344/1611 net: sparx5: unregister blocking notifier on init failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 483be61b4a9a6df3b7cb277e8f189e082dee4cb8 upstream.
sparx5_register_notifier_blocks() registers the switchdev blocking notifier before allocating the ordered workqueue. If the workqueue allocation fails, the error path unregisters the switchdev and netdevice notifiers, but leaves the blocking notifier registered.
Add a separate error label for the workqueue allocation failure path and unregister the switchdev blocking notifier there.
--- drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +3 -1
@@ -765,11 +765,13 @@ int sparx5_register_notifier_blocks(stru sparx5_owq =alloc_ordered_workqueue ("sparx5_order" ,0 );if (!sparx5_owq) { err = -ENOMEM ; - goto err_switchdev_blocking_nb; + goto err_alloc_workqueue; }return 0 ; +err_alloc_workqueue: +unregister_switchdev_blocking_notifier (&s5->switchdev_blocking_nb); err_switchdev_blocking_nb:unregister_switchdev_notifier (&s5->switchdev_nb); err_switchdev_nb:
Greg Kroah-Hartman
maintainerPATCH 1345/1611 dm thin metadata: fix superblock refcount leak on snapshot shadow failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Genjian Zhang <[email protected]>
commit 4b22d0801fadfcae2e106e6ba32e49439c7c7ebf upstream.
__reserve_metadata_snap() increments THIN_SUPERBLOCK_LOCATION in the metadata space map before shadowing it. When dm_tm_shadow_block() fails, a reference is leaked in the metadata space map.
Fix by adding the missing dm_sm_dec_block().
--- drivers/md/dm-thin-metadata.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm-thin-metadata.c +3 -1
@@ -1353,8 +1353,10 @@ static int __reserve_metadata_snap(strucdm_sm_inc_block (pmd->metadata_sm,THIN_SUPERBLOCK_LOCATION ); r =dm_tm_shadow_block (pmd->tm,THIN_SUPERBLOCK_LOCATION , &sb_validator, ©, &inc); -if (r) +if (r) { +dm_sm_dec_block (pmd->metadata_sm,THIN_SUPERBLOCK_LOCATION );return r; + }BUG_ON (!inc);
Greg Kroah-Hartman
maintainerPATCH 1346/1611 dm thin metadata: fix metadata snapshot consistency on commit failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming-Hung Tsai <[email protected]>
commit 5bcd4d3058ebaf46ad2e163829d87dd4870c7a45 upstream.
__reserve_metadata_snap() and __release_metadata_snap() modify the superblock's held_root directly in the block_manager's buffer. If the subsequent metadata commit fails, the held_root gets flushed to disk through the abort_transaction path, resulting in inconsistent metadata.
Reproducer 1: __reserve_metadata_snap()
1. Create a 2 MiB metadata device and make the region after the 14th block inaccessible, to trigger metadata commit failure in the subsequent reserve_metadata_snap operation. The 14th block will be the shadow destination for the index block.
dmsetup create tmeta --table "0 112 linear /dev/sdc 0 112 3984 error"
2. Create a 16 MiB thin-pool
dmsetup create tdata --table "0 32768 zero"
dd if=/dev/zero of=/dev/mapper/tmeta bs=4k count=1 dmsetup create tpool --table "0 32768 thin-pool /dev/mapper/tmeta \/dev/mapper/tdata 128 0 1 skip_block_zeroing"
3. Take a metadata snapshot to trigger metadata commit failure and transaction abort. However, the held_root is written to disk, breaking metadata consistency.
dmsetup message tpool 0 "reserve_metadata_snap"
thin_check v1.2.2 result:
Bad reference count for metadata block 6. Expected 2, but space map contains 1. Bad reference count for metadata block 7. Expected 2, but space map contains 1. Bad reference count for metadata block 13. Expected 1, but space map contains 0.
Reproducer 2: __release_metadata_snap()
1. Create a 2 MiB metadata device and make the region after the 16th block inaccessible, to trigger metadata commit failure in the subsequent release_metadata_snap operation. The 16th block will be the shadow destination for the index block.
dmsetup create tmeta --table "0 128 linear /dev/sdc 0 128 3968 error"
2. Create a 16 MiB thin-pool
dmsetup create tdata --table "0 32768 zero"
dd if=/dev/zero of=/dev/mapper/tmeta bs=4k count=1 dmsetup create tpool --table "0 32768 thin-pool /dev/mapper/tmeta \/dev/mapper/tdata 128 0 1 skip_block_zeroing"
3. Reserve then release the metadata snapshot, to trigger metadata commit failure and transaction abort. The held_root gets removed from the on-disk superblock, causing inconsistent metadata.
dmsetup message tpool 0 "reserve_metadata_snap"
dmsetup message tpool 0 "release_metadata_snap"
thin_check v1.2.2 result:
Bad reference count for metadata block 6. Expected 1, but space map contains 2. Bad reference count for metadata block 7. Expected 1, but space map contains 2. 1 metadata blocks have leaked.
Fix by deferring the held_root update to commit time.
Additionally, move the existing-snapshot check in __reserve_metadata_snap before the shadow operation to avoid unnecessary work. In __release_metadata_snap, clear pmd->held_root before btree deletion so partial failure leaks blocks rather than leaving a stale reference, and unlock the snapshot block before decrementing its refcount.
--- drivers/md/dm-thin-metadata.c | 63 ++++++++++++------------------------------ 1 file changed, 18 insertions(+), 45 deletions(-)
drivers/md/dm-thin-metadata.c +18 -45
@@ -186,6 +186,7 @@ struct dm_pool_metadata {uint32_t time;dm_block_t root;dm_block_t details_root; +dm_block_t held_root;struct list_head thin_devices;uint64_t trans_id;unsigned long flags;
@@ -748,6 +749,7 @@ static int __open_metadata(struct dm_poo*/ pmd->root =le64_to_cpu (disk_super->data_mapping_root); pmd->details_root =le64_to_cpu (disk_super->device_details_root); + pmd->held_root =le64_to_cpu (disk_super->held_root);__setup_btree_details (pmd);dm_bm_unlock (sblock);
@@ -838,6 +840,7 @@ static int __begin_transaction(struct dm pmd->time =le32_to_cpu (disk_super->time); pmd->root =le64_to_cpu (disk_super->data_mapping_root); pmd->details_root =le64_to_cpu (disk_super->device_details_root); + pmd->held_root =le64_to_cpu (disk_super->held_root); pmd->trans_id =le64_to_cpu (disk_super->trans_id); pmd->flags =le32_to_cpu (disk_super->flags); pmd->data_block_size =le32_to_cpu (disk_super->data_block_size);
@@ -928,6 +931,7 @@ static int __commit_transaction(struct d disk_super->time =cpu_to_le32 (pmd->time); disk_super->data_mapping_root =cpu_to_le64 (pmd->root); disk_super->device_details_root =cpu_to_le64 (pmd->details_root); + disk_super->held_root =cpu_to_le64 (pmd->held_root); disk_super->trans_id =cpu_to_le64 (pmd->trans_id); disk_super->flags =cpu_to_le32 (pmd->flags);
@@ -1333,9 +1337,14 @@ static int __reserve_metadata_snap(struc {int r, inc;struct thin_disk_superblock *disk_super; -struct dm_block *copy, *sblock; +struct dm_block *copy;dm_block_t held_root; +if (pmd->held_root) { +DMWARN ("Pool metadata snapshot already exists: release this before taking another." ); +return -EBUSY ; + } +/* * We commit to ensure the btree roots which we increment in a * moment are up to date.
@@ -1363,14 +1372,6 @@ static int __reserve_metadata_snap(struc held_root =dm_block_location (copy); disk_super =dm_block_data (copy); -if (le64_to_cpu (disk_super->held_root)) { -DMWARN ("Pool metadata snapshot already exists: release this before taking another." ); - -dm_tm_dec (pmd->tm, held_root); -dm_tm_unlock (pmd->tm, copy); -return -EBUSY ; - } -/* * Wipe the spacemap since we're not publishing this. */
@@ -1386,18 +1387,8 @@ static int __reserve_metadata_snap(strucdm_tm_inc (pmd->tm,le64_to_cpu (disk_super->device_details_root));dm_tm_unlock (pmd->tm, copy); -/* -* Write the held root into the superblock. -*/ - r =superblock_lock (pmd, &sblock); -if (r) { -dm_tm_dec (pmd->tm, held_root); -return r; - } + pmd->held_root = held_root; - disk_super =dm_block_data (sblock); - disk_super->held_root =cpu_to_le64 (held_root); -dm_bm_unlock (sblock);return 0 ; }
@@ -1417,18 +1408,10 @@ static int __release_metadata_snap(struc {int r;struct thin_disk_superblock *disk_super; -struct dm_block *sblock, *copy; +struct dm_block *copy;dm_block_t held_root; - r =superblock_lock (pmd, &sblock); -if (r) -return r; - - disk_super =dm_block_data (sblock); - held_root =le64_to_cpu (disk_super->held_root); - disk_super->held_root =cpu_to_le64 (0 ); - -dm_bm_unlock (sblock); + held_root = pmd->held_root;if (!held_root) {DMWARN ("No pool metadata snapshot found: nothing to release." );
@@ -1439,13 +1422,15 @@ static int __release_metadata_snap(strucif (r)return r; + pmd->held_root =0 ; + disk_super =dm_block_data (copy);dm_btree_del (&pmd->info,le64_to_cpu (disk_super->data_mapping_root));dm_btree_del (&pmd->details_info,le64_to_cpu (disk_super->device_details_root)); -dm_sm_dec_block (pmd->metadata_sm, held_root); -dm_tm_unlock (pmd->tm, copy); +dm_sm_dec_block (pmd->metadata_sm, held_root); +return 0 ; }
@@ -1464,19 +1449,7 @@ int dm_pool_release_metadata_snap(structstatic int __get_metadata_snap (struct dm_pool_metadata *pmd,dm_block_t *result) { -int r; -struct thin_disk_superblock *disk_super; -struct dm_block *sblock; - - r =dm_bm_read_lock (pmd->bm,THIN_SUPERBLOCK_LOCATION , - &sb_validator, &sblock); -if (r) -return r; - - disk_super =dm_block_data (sblock); - *result =le64_to_cpu (disk_super->held_root); - -dm_bm_unlock (sblock); + *result = pmd->held_root;return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1347/1611 dm era: fix out-of-bounds memory access for non-zero start sector
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Moelius <[email protected]>
commit a868196f03c2b19418ae3d2b69e195d668a271e5 upstream.
dm-era tracks writes in target-relative blocks, but era_map() calculates the writeset block before applying the target offset. Tables with a non-zero start sector can therefore pass an absolute mapped-device block to metadata_current_marked().
If the absolute block is beyond the current writeset size, writeset_marked() tests past the end of the in-core bitset. KASAN reports this as a vmalloc-out-of-bounds access.
Apply the target offset before calculating the era block so writeset lookups use the target-relative block number.
--- drivers/md/dm-era-target.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm-era-target.c +3 -1
@@ -1231,6 +1231,7 @@ static dm_block_t get_block(struct era *static void remap_to_origin (struct era *era,struct bio *bio) {bio_set_dev (bio, era->origin_dev->bdev); + bio->bi_iter.bi_sector =dm_target_offset (era->ti, bio->bi_iter.bi_sector); }/*
@@ -1562,7 +1563,7 @@ static void era_dtr(struct dm_target *tistatic int era_map (struct dm_target *ti,struct bio *bio) {struct era *era = ti->private; -dm_block_t block =get_block (era, bio); +dm_block_t block;/* * All bios get remapped to the origin device. We do this now, but
@@ -1570,6 +1571,7 @@ static int era_map(struct dm_target *ti,* block is marked in this era. */ remap_to_origin (era, bio); + block =get_block (era, bio);/* * REQ_PREFLUSH bios carry no data, so we're not interested in them.
Greg Kroah-Hartman
maintainerPATCH 1348/1611 dm-bufio: fix wrong count calculation in dm_bufio_issue_discard
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 422f1d4f141eaa3a6e4199ceec86cc6b9bf26570 upstream.
block_to_sector converts a block number to a sector number and adds c->start to the result. It is inappropriate to use this function for converting the number of blocks to a number to sectors because c->start would be incorrectly added to the result.
Luckily, the only target that uses dm_bufio_issue_discard is dm-ebs, which sets c->start to 0, so this bug is latent.
--- drivers/md/dm-bufio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm-bufio.c +3 -1
@@ -2215,7 +2215,9 @@ int dm_bufio_issue_discard(struct dm_bufstruct dm_io_region io_reg = { .bdev = c->bdev, .sector =block_to_sector (c, block), - .count =block_to_sector (c, count), + .count =likely (c->sectors_per_block_bits >=0 ) ? + count << c->sectors_per_block_bits : + count * (c->block_size >>SECTOR_SHIFT ), };if (WARN_ON_ONCE (dm_bufio_in_request ()))
Greg Kroah-Hartman
maintainerPATCH 1349/1611 dm-ioctl: fix a possible overflow in list_version_get_info
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 76c6f845dc0c614304a6e6ee619b552f97cf24b3 upstream.
sizeof(tt->version) is 12 bytes, but the code writes 16 bytes into the output buffer - info->vers->version[0], info->vers->version[1], info->vers->version[2] and info->vers->next. This can cause buffer overflow.
Fix this buffer overflow by replacing "sizeof(tt->version)" with "sizeof(struct dm_target_versions)".
--- drivers/md/dm-ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-ioctl.c +1 -1
@@ -683,7 +683,7 @@ static void list_version_get_info(structstruct vers_iter *info = param;/* Check space - it might have changed since the first iteration */ -if ((char *)info->vers +sizeof (tt->version) +strlen (tt->name) +1 > info->end) { +if ((char *)info->vers +sizeof (struct dm_target_versions ) +strlen (tt->name) +1 > info->end) { info->flags =DM_BUFFER_FULL_FLAG ;return ; }
Greg Kroah-Hartman
maintainerPATCH 1350/1611 dm-log: fix a bitset_size overflow on 32bit machines
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Marzinski <[email protected]>
commit 9743132a41f4d9d0e54c5f2adcb821b04796bab1 upstream.
Commit c20e36b7631d ("dm log: fix out-of-bounds write due to region_count overflow") made sure that region_count could fit in an unsigned int. But the bitmap memory isn't allocated based on region_count. It uses bitset_size (a size_t variable). The first step of calculating bitset_size is to set it to region_count, rounded up to a multiple of BITS_PER_LONG. If region_size is less than BITS_PER_LONG smaller than UINT_MAX, it will get rounded up to 2^32. On a 32bit architecture, this will make bitset_size wrap around to 0 and fail, despite region_count being valid.
Since bitset_size gets divided by 8, it can hold any valid region_count. It just needs a special case to handle the rollover. If it is 0, the value rolled over, and bitset size should be set to the number of bytes needed to hold 2^32 bits.
--- drivers/md/dm-log.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/md/dm-log.c +3 -0
@@ -425,6 +425,9 @@ static int create_log_context(struct dm_*/ bitset_size =dm_round_up (region_count,BITS_PER_LONG ); bitset_size >>=BYTE_SHIFT ; +/* Handle dm_round_up rollover on 32-bit systems */ +if (!bitset_size) + bitset_size =1UL << (BITS_PER_LONG -BYTE_SHIFT ); lc->bitset_uint32_count = bitset_size /sizeof (*lc->clean_bits);
Greg Kroah-Hartman
maintainerPATCH 1351/1611 dm-pcache: reject option groups without values
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Moelius <[email protected]>
commit d9c631e3fbd44246a2be781d26cfacbb9b8ec127 upstream.
The pcache target parses optional arguments as name/value pairs. A table that advertises one optional argument and supplies only a recognized option name, for example "cache_mode", reaches parse_cache_opts() with argc == 1. The parser consumes the name, decrements argc to zero, then calls dm_shift_arg() again for the value. dm_shift_arg() returns NULL when no arguments remain, and the following strcmp() dereferences that NULL pointer.
Check that each recognized option has a value before consuming it. This keeps valid "cache_mode writeback" and "data_crc true/false" tables unchanged while making malformed tables fail during target construction with a precise missing-value error.
--- drivers/md/dm-pcache/dm_pcache.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/md/dm-pcache/dm_pcache.c +8 -0
@@ -168,6 +168,10 @@ static int parse_cache_opts(struct dm_pcache *pcache, struct dm_arg_set *as, argc--;if (!strcmp (arg,"cache_mode" )) { +if (!argc) { + *error ="Missing value for cache_mode" ; +return -EINVAL ; + } arg =dm_shift_arg (as);if (!strcmp (arg,"writeback" )) { opts->cache_mode =PCACHE_CACHE_MODE_WRITEBACK ;
@@ -177,6 +181,10 @@ static int parse_cache_opts(struct dm_pcache *pcache, struct dm_arg_set *as, } argc--; }else if (!strcmp (arg,"data_crc" )) { +if (!argc) { + *error ="Missing value for data_crc" ; +return -EINVAL ; + } arg =dm_shift_arg (as);if (!strcmp (arg,"true" )) { opts->data_crc = true;
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 1352/1611 dm-stats: fix dm_jiffies_to_msec64
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 386df1a57b631c456d14f857cb0c0c2e11c16bef upstream.
There were wrong calculations in dm_jiffies_to_msec64 that produced incorrect output when HZ was different from 1000. This commit fixes them.
--- drivers/md/dm-stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-stats.c +2 -2
@@ -842,10 +842,10 @@ static unsigned long long dm_jiffies_to_ result =jiffies_to_msecs (j &0x3fffff );if (j >=1 <<22 ) { mult =jiffies_to_msecs (1 <<22 ); - result += (unsigned long long )mult * (unsigned long long )jiffies_to_msecs ((j >>22 ) &0x3fffff ); + result += (unsigned long long )mult * ((j >>22 ) &0x3fffff ); }if (j >=1ULL <<44 ) - result += (unsigned long long )mult * (unsigned long long )mult * (unsigned long long )jiffies_to_msecs (j >>44 ); + result += (unsigned long long )mult * (unsigned long long )(1 <<22 ) * (j >>44 );return result; }
Greg Kroah-Hartman
maintainerPATCH 1353/1611 dm-stats: fix merge accounting
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 1917eb2db750ecbdf710f79a8042eaa545a063c7 upstream.
There were wrong parentheses when setting stats_aux->merged, so that merging was never properly accounted. This commit fixes it.
--- drivers/md/dm-stats.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-stats.c +2 -4
@@ -692,10 +692,8 @@ void dm_stats_account_io(struct dm_stats*/ last =raw_cpu_ptr (stats->last); stats_aux->merged = - (bi_sector == (READ_ONCE (last->last_sector) && - ((bi_rw ==WRITE ) == - (READ_ONCE (last->last_rw) ==WRITE )) - )); + bi_sector ==READ_ONCE (last->last_sector) && + (bi_rw ==WRITE ) == (READ_ONCE (last->last_rw) ==WRITE );WRITE_ONCE (last->last_sector, end_sector);WRITE_ONCE (last->last_rw, bi_rw); }else
Greg Kroah-Hartman
maintainerPATCH 1354/1611 dm_early_create: fix freeing used table on dm_resume failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 366665416f20527ff7cad548a32d1ddf23195740 upstream.
If dm_resume fails, the kernel attempts to free table with dm_table_destroy, but the table was already instantiated with dm_swap_table. This commit skips the call to dm_table_destroy in this case.
--- drivers/md/dm-ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-ioctl.c +1 -1
@@ -2341,7 +2341,7 @@ int __init dm_early_create(struct dm_ioc/* resume device */ r =dm_resume (md);if (r) - goto err_destroy_table; + goto err_hash_remove;DMINFO ("%s (%s) is ready" , md->disk->disk_name, dmi->name);dm_put (md);
Greg Kroah-Hartman
maintainerPATCH 1355/1611 dm-integrity: fix leaking uninitialized kernel memory
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 7bb03b2b01b814a9fc14afbfc2cbb2cca5b34750 upstream.
If hash size is less than device's tuple size, dm-integrity is supposed to zero the remaining space. There was a bug in the code that zeroing didn't work. This commit fixes it.
--- drivers/md/dm-integrity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-integrity.c +1 -1
@@ -2605,7 +2605,7 @@ skip_spinlock:struct bio_vec bv =bio_iter_iovec (bio, dio->bio_details.bi_iter);const char *mem =integrity_kmap (ic, bv.bv_page);if (ic->tag_size < ic->tuple_size) -memset (dio->integrity_payload + pos + ic->tag_size,0 , ic->tuple_size - ic->tuple_size); +memset (dio->integrity_payload + pos + ic->tag_size,0 , ic->tuple_size - ic->tag_size);integrity_sector_checksum (ic, &dio->ahash_req, dio->bio_details.bi_iter.bi_sector, mem, bv.bv_offset, dio->integrity_payload + pos);integrity_kunmap (ic, mem); pos += ic->tuple_size;
Greg Kroah-Hartman
maintainerPATCH 1356/1611 dm-integrity: fix a bug if the bio is out of limits
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 5a266764fadaff8b5c1fe37a186ebf9b09cb953e upstream.
If dm_integrity_check_limits fails, the code would exit with DM_MAPIO_KILL. However, the range would be already locked at this point, and it wouldn't be unlocked, resulting in a deadlock. Let's move the limit check up, so that when it exits, no resources are leaked.
--- drivers/md/dm-integrity.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/md/dm-integrity.c +3 -4
@@ -2522,6 +2522,9 @@ static int dm_integrity_map_inline(strucif (unlikely ((bio->bi_opf &REQ_PREFLUSH ) !=0 ))return DM_MAPIO_REMAPPED ; +if (unlikely (!dm_integrity_check_limits (ic, bio->bi_iter.bi_sector, bio))) +return DM_MAPIO_KILL ; + retry:if (!dio->integrity_payload) {unsigned digest_size, extra_size;
@@ -2586,10 +2589,6 @@ skip_spinlock: dio->bio_details.bi_iter = bio->bi_iter; -if (unlikely (!dm_integrity_check_limits (ic, bio->bi_iter.bi_sector, bio))) { -return DM_MAPIO_KILL ; - } - bio->bi_iter.bi_sector += ic->start +SB_SECTORS ; bip =bio_integrity_alloc (bio,GFP_NOIO ,1 );
Greg Kroah-Hartman
maintainerPATCH 1357/1611 dm-integrity: dont increment hash_offset twice
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit edf025f083854f80032b73a1aad69a3c90db236f upstream.
hash_offset is already incremented in the loop "for (i = 0; i < to_copy; i++, ts--)". Do not increment it again.
--- drivers/md/dm-integrity.c | 3 --- 1 file changed, 3 deletions(-)
drivers/md/dm-integrity.c +0 -3
@@ -1479,9 +1479,6 @@ thorough_test: *metadata_offset =0 ; } -if (unlikely (!is_power_of_2 (ic->tag_size))) - hash_offset = (hash_offset + to_copy) % ic->tag_size; - total_size -= to_copy; }while (unlikely (total_size));
Greg Kroah-Hartman
maintainerPATCH 1358/1611 dm-verity: avoid double increment of &use_bh_wq_enabled
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 72e9ec2fe32b00994f41719cf77423fca67d48b2 upstream.
verity_parse_opt_args is called twice, first with the only_modifier_opts, first with only_modifier_opts == true and then with only_modifier_opts == false. Thus, the static branch &use_bh_wq_enabled was incremented twice and the destructor verity_dtr would only decrement it once.
Fix tihs bug by only incrementing it on the first call, on the second call, when v->use_bh_wq is true, do nothing.
--- drivers/md/dm-verity-target.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-verity-target.c +2 -0
@@ -1194,6 +1194,8 @@ static int verity_parse_opt_args(structcontinue ; }else if (!strcasecmp (arg_name,DM_VERITY_OPT_TASKLET_VERIFY )) { +if (v->use_bh_wq) +continue ; v->use_bh_wq = true;static_branch_inc (&use_bh_wq_enabled);continue ;
Greg Kroah-Hartman
maintainerPATCH 1359/1611 dm-verity: fix a possible NULL pointer dereference
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit e72b793ae440f6900fb17a4b8518c707b5cd3e17 upstream.
Fix a possible NULL pointer dereference dm_verity_loadpin_is_bdev_trusted if the device has no table.
--- drivers/md/dm-verity-loadpin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-verity-loadpin.c +1 -1
@@ -70,7 +70,7 @@ bool dm_verity_loadpin_is_bdev_trusted(s table =dm_get_live_table (md, &srcu_idx); -if (table->num_targets !=1 ) +if (!table || table->num_targets !=1 ) goto out; ti =dm_table_get_target (table,0 );
Greg Kroah-Hartman
maintainerPATCH 1360/1611 dm-verity: increase sprintf buffer size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 88dd117c92a142253fb7a17e791773902b3babc6 upstream.
The prefix "DM_VERITY_ERR_BLOCK_NR" is 22 chars. Add '=', one digit for type, ',', up to 20 digits for a u64 block number, and a NUL terminator:
that's 46 bytes. The buffer is 42 bytes. For block numbers >= 16 decimal digits (devices larger than ~16 EB with 4K blocks), snprintf silently truncates the uevent environment variable.
--- drivers/md/dm-verity-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-verity-target.c +1 -1
@@ -25,7 +25,7 @@#define DM_MSG_PREFIX "verity" -#define DM_VERITY_ENV_LENGTH 42 +#define DM_VERITY_ENV_LENGTH 46#define DM_VERITY_ENV_VAR_NAME "DM_VERITY_ERR_BLOCK_NR"#define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144
Greg Kroah-Hartman
maintainerPATCH 1361/1611 dm-verity: make error counter atomic
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 8ec4d9c5a5cf4b61fc087f871465b1f79b393325 upstream.
The error counter "v->corrupted_errs" was not atomic, thus it could be subject to race conditions. The call to dm_audit_log_target("max-corrupted-errors") may be skipped due to the races.
--- drivers/md/dm-verity-target.c | 12 +++++++----- drivers/md/dm-verity.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/md/dm-verity-target.c +7 -5
@@ -165,14 +165,16 @@ static int verity_handle_err(struct dm_vchar *envp[] = { verity_env,NULL };const char *type_str ="" ;struct mapped_device *md =dm_table_get_md (v->ti->table); +int ce;/* Corruption should be visible in device status in all modes */ v->hash_failed = true; -if (v->corrupted_errs >=DM_VERITY_MAX_CORRUPTED_ERRS ) - goto out; - - v->corrupted_errs++; + ce =atomic_read (&v->corrupted_errs); +do { +if (ce >=DM_VERITY_MAX_CORRUPTED_ERRS ) + goto out; + }while (!atomic_try_cmpxchg (&v->corrupted_errs, &ce, ce +1 ));switch (type) {case DM_VERITY_BLOCK_TYPE_DATA :
@@ -188,7 +190,7 @@ static int verity_handle_err(struct dm_vDMERR_LIMIT ("%s: %s block %llu is corrupted" , v->data_dev->name, type_str, block); -if (v->corrupted_errs ==DM_VERITY_MAX_CORRUPTED_ERRS ) { +if (ce +1 ==DM_VERITY_MAX_CORRUPTED_ERRS ) {DMERR ("%s: reached maximum errors" , v->data_dev->name);dm_audit_log_target (DM_MSG_PREFIX ,"max-corrupted-errors" , v->ti,0 ); }
drivers/md/dm-verity.h +1 -1
@@ -62,7 +62,7 @@ struct dm_verity {unsigned int digest_size;/* digest size for the current hash algorithm */ enum verity_mode mode;/* mode for handling verification errors */ enum verity_mode error_mode;/* mode for handling I/O errors */ -unsigned int corrupted_errs;/* Number of errors for corrupted blocks */ +atomic_t corrupted_errs;/* Number of errors for corrupted blocks */ struct workqueue_struct *verify_wq;
Greg Kroah-Hartman
maintainerPATCH 1362/1611 dma-fence: Make dma_fence_dedup_array() robust against 0-count input
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baineng Shou <[email protected]>
commit 77a9298741f8f9e8b963c977f5582ab21c6d3427 upstream.
dma_fence_dedup_array() returns 1 when called with num_fences == 0:
the for-loop body never executes, j stays at 0, and the final return ++j yields 1. This contradicts both the kernel-doc ("Return:
Number of unique fences remaining in the array") and the natural expectation that 0 input gives 0 output.
The caller __dma_fence_unwrap_merge() bails out via the if (count == 0 || count == 1) fast path and so is save.
But amdgpu_userq_wait_*() could reach the dedup call with a zero local count and dereference an uninitialized fence slot in the array.
Make the contract match the documentation by returning 0 early. This also skips an unnecessary sort() call on an empty array.
--- drivers/dma-buf/dma-fence-unwrap.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/dma-buf/dma-fence-unwrap.c +3 -0
@@ -97,6 +97,9 @@ int dma_fence_dedup_array(struct dma_fen {int i, j; +if (!num_fences) +return 0 ; +sort (fences, num_fences,sizeof (*fences), fence_cmp,NULL );/*
Greg Kroah-Hartman
maintainerPATCH 1363/1611 accel/amdxdna: Fix use-after-free in amdxdna_gem_dmabuf_mmap()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 63bbf9ac5dde2ba85e7b39d0a0b7d540e6252ba4 upstream.
When vm_insert_pages() fails, the error path calls vma->vm_ops->close(vma) which internally calls drm_gem_vm_close() → drm_gem_object_put(), releasing the GEM object reference acquired at the start of the function. However, the close_vma label then falls through to put_obj, which calls drm_gem_object_put() a second time on the same object.
If the first put releases the last reference, the object is freed and the second put accesses freed memory, causing a use-after-free.
Fix by returning directly from close_vma instead of falling through to put_obj, since the close handler already performs all necessary cleanup including the object put.
--- drivers/accel/amdxdna/amdxdna_gem.c | 1 + 1 file changed, 1 insertion(+)
drivers/accel/amdxdna/amdxdna_gem.c +1 -0
@@ -374,6 +374,7 @@ static int amdxdna_gem_dmabuf_mmap(struc close_vma: vma->vm_ops->close (vma); +return ret; put_obj:drm_gem_object_put (gobj);return ret;
Greg Kroah-Hartman
maintainerPATCH 1364/1611 accel/ivpu: Reject firmware log with size smaller than header
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jhonraushan <[email protected]>
commit ddb44baed257560f192b145ed36cf8c0a412de47 upstream.
fw_log_from_bo() validates the tracing buffer header_size and that the log fits within the BO, but never checks that log->size is at least log->header_size. fw_log_print_buffer() then computes:
u32 data_size = log->size - log->header_size;
which underflows to a near-U32_MAX value when firmware reports a log whose size is smaller than its header. That huge data_size defeats the log_start/log_end bounds clamps added by commit dd1311bcf0e6 ("accel/ivpu:
Add bounds checks for firmware log indices"), so fw_log_print_lines() reads far past the small real data region of the BO. A size of 0 also makes fw_log_from_bo() advance the offset by 0, causing the callers to loop forever on the same header.
Reject logs whose size is smaller than the header (which also rejects size == 0).
--- drivers/accel/ivpu/ivpu_fw_log.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/accel/ivpu/ivpu_fw_log.c +4 -0
@@ -43,6 +43,10 @@ static int fw_log_from_bo(struct ivpu_deivpu_dbg (vdev,FW_BOOT ,"Invalid header size 0x%x\n" , log->header_size);return -EINVAL ; } +if (log->size < log->header_size) { +ivpu_dbg (vdev,FW_BOOT ,"Invalid log size 0x%x\n" , log->size); +return -EINVAL ; + }if ((char *)log + log->size > (char *)ivpu_bo_vaddr (bo) +ivpu_bo_size (bo)) {ivpu_dbg (vdev,FW_BOOT ,"Invalid log size 0x%x\n" , log->size);return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 1365/1611 scsi: hpsa: Fix DMA mapping leak on IOACCEL2 reset path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit e166bafc483e927150cb9b5f286c9191ea0df84e upstream.
If phys_disk->in_reset is set, the function returns directly without undoing the resources acquired for the command. Add the missing error cleanup by unmapping the IOACCEL2 SG chain block when needed, unmapping the SCSI command, and dropping the outstanding IOACCEL command count before returning.
--- drivers/scsi/hpsa.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/scsi/hpsa.c +4 -0
@@ -5020,6 +5020,10 @@ static int hpsa_scsi_ioaccel2_queue_commif (phys_disk->in_reset) { cmd->result =DID_RESET <<16 ; +atomic_dec (&phys_disk->ioaccel_cmds_out); +scsi_dma_unmap (cmd); +if (use_sg > h->ioaccel_maxsg) +hpsa_unmap_ioaccel2_sg_chain_block (h, cp);return -1 ; }
Greg Kroah-Hartman
maintainerPATCH 1366/1611 scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 1bd28625e25be549ee7c47532e7c3ef91c682410 upstream.
The memory allocated for mboxq using mempool_alloc() is not freed in some of the early exit error paths. Fix that by moving the mempool_free() call to an earlier point after last use.
--- drivers/scsi/lpfc/lpfc_init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/lpfc/lpfc_init.c +1 -2
@@ -8194,6 +8194,7 @@ lpfc_sli4_driver_resource_setup(struct lmempool_free (mboxq, phba->mbox_mem_pool); goto out_free_bsmbx; } +mempool_free (mboxq, phba->mbox_mem_pool);/* * 1 for cmd, 1 for rsp, NVME adds an extra one
@@ -8316,8 +8317,6 @@ lpfc_sli4_driver_resource_setup(struct l goto out_free_sg_dma_buf; } -mempool_free (mboxq, phba->mbox_mem_pool); -/* Verify OAS is supported */ lpfc_sli4_oas_verify (phba);
Greg Kroah-Hartman
maintainerPATCH 1367/1611 scsi: sg: Report request-table problems when any status is set
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 1d3a742afeb761eaead774691bde1ced699e9a5d upstream.
SG_GET_REQUEST_TABLE reports per-request diagnostic state through sg_req_info::problem. The field is meant to indicate whether there is an error to report for a completed request.
sg_fill_request_table() currently combines masked_status, host_status and driver_status with bitwise AND. This only reports a problem when all three status fields are non-zero at the same time. A normal target check condition, for example, has masked_status set while host_status and driver_status may both be zero, so the request is incorrectly reported as clean.
Use the same condition as sg_new_read(), which sets SG_INFO_CHECK when any of the three status fields is non-zero.
--- drivers/scsi/sg.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/sg.c +3 -4
@@ -862,10 +862,9 @@ sg_fill_request_table(Sg_fd *sfp, sg_reqif (val >=SG_MAX_QUEUE )break ; rinfo[val].req_state = srp->done +1 ; - rinfo[val].problem = - srp->header.masked_status & - srp->header.host_status & - srp->header.driver_status; + rinfo[val].problem = srp->header.masked_status || + srp->header.host_status || + srp->header.driver_status;if (srp->done) rinfo[val].duration = srp->header.duration;
Greg Kroah-Hartman
maintainerPATCH 1368/1611 scsi: xen: scsiback: Free the command tag on the TMR submit-failure path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 66aefc277ebb796ec285d550305535dc3fc0179f upstream.
scsiback_device_action() obtains a command tag in scsiback_get_pend_req() and submits a task-management request with target_submit_tmr(). When target_submit_tmr() fails it returns < 0 and scsiback jumps to the err: label, which sends a response but frees nothing, leaking the tag.
Impact: a pvSCSI guest can leak the command tags of a LUN's session, stopping the LUN, by issuing VSCSIIF_ACT_SCSI_ABORT or RESET requests whenever target_submit_tmr() fails.
transport_generic_free_cmd() cannot be used here. By the time target_submit_tmr() returns an error it has already run __target_init_cmd() (so se_cmd->cmd_kref is one, not zero), and on its target_get_sess_cmd() error path it has freed se_cmd->se_tmr_req via core_tmr_release_req() while leaving SCF_SCSI_TMR_CDB set and the pointer dangling. Letting the command release run target_free_cmd_mem() would then double-free se_tmr_req.
Use the same helper, which returns just the tag, on this path too.
--- drivers/xen/xen-scsiback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/xen-scsiback.c +1 -1
@@ -640,7 +640,7 @@ static void scsiback_device_action(strucreturn ; err: -scsiback_do_resp_with_sense (NULL , err,0 , pending_req); +scsiback_resp_and_free (pending_req, err); }/*
Greg Kroah-Hartman
maintainerPATCH 1369/1611 scsi: xen: scsiback: Free unsubmitted command instead of double-putting it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit ca978f8a93d4d36841839bf2847d29b88c2591d6 upstream.
scsiback_get_pend_req() obtains a command tag and returns a vscsibk_pend whose embedded se_cmd has only been memset to 0, so its cmd_kref is 0; the se_cmd is initialised (kref_init() via target_init_cmd()) only later, in scsiback_cmd_exec(), on the successful VSCSIIF_ACT_SCSI_CDB path. The two error paths in scsiback_do_cmd_fn() taken before the command is submitted -- a failed scsiback_gnttab_data_map() and an unknown ring_req.act -- call transport_generic_free_cmd(&pending_req->se_cmd, 0), which kref_put()s a refcount of 0. That underflows it ("refcount_t: underflow; use-after-free") and, as the release function is not run, leaks the command tag.
Impact: a pvSCSI guest can leak every command tag of a LUN's session, stopping the LUN, by submitting requests with a bad grant reference or an unknown request type; under panic_on_warn the refcount underflow panics the host.
Add a helper that just returns the tag with target_free_tag() and sends the error response. It frees the tag while the v2p reference still pins the session, and snapshots the response fields beforehand because freeing the tag can let another ring reuse the pending_req slot.
--- drivers/xen/xen-scsiback.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/xen/xen-scsiback.c +22 -6
@@ -612,6 +612,25 @@ static void scsiback_disconnect(struct vxenbus_unmap_ring_vfree (info->dev, info->ring.sring); } +/* +* Send the error response for a request that did not reach the target core +* and return its tag. Free the tag before the response drops the v2p +* reference that keeps the session alive, and snapshot what the response +* needs since returning the tag can let the slot be reused. +*/ +static void scsiback_resp_and_free (struct vscsibk_pend *pending_req, +int32_t result) +{ +struct vscsibk_info *info = pending_req->info; +struct v2p_entry *v2p = pending_req->v2p; +struct se_session *se_sess = v2p->tpg->tpg_nexus->tvn_se_sess; +u16 rqid = pending_req->rqid; + +target_free_tag (se_sess, &pending_req->se_cmd); +scsiback_send_response (info,NULL , result,0 , rqid); +kref_put (&v2p->kref, scsiback_free_translation_entry); +} +static void scsiback_device_action (struct vscsibk_pend *pending_req,enum tcm_tmreq_table act,int tag) {
@@ -793,9 +812,8 @@ static int scsiback_do_cmd_fn(struct vsccase VSCSIIF_ACT_SCSI_CDB :if (scsiback_gnttab_data_map (&ring_req, pending_req)) {scsiback_fast_flush_area (pending_req); -scsiback_do_resp_with_sense (NULL , -DID_ERROR <<16 ,0 , pending_req); -transport_generic_free_cmd (&pending_req->se_cmd,0 ); +scsiback_resp_and_free (pending_req, +DID_ERROR <<16 ); }else {scsiback_cmd_exec (pending_req); }
@@ -809,9 +827,7 @@ static int scsiback_do_cmd_fn(struct vscbreak ;default :pr_err_ratelimited ("invalid request\n" ); -scsiback_do_resp_with_sense (NULL ,DID_ERROR <<16 ,0 , - pending_req); -transport_generic_free_cmd (&pending_req->se_cmd,0 ); +scsiback_resp_and_free (pending_req,DID_ERROR <<16 );break ; }
Greg Kroah-Hartman
maintainerPATCH 1370/1611 scsi: target: Bound PR-OUT TransportID parsing to the received buffer
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit d04a179085c262c9ed577d0a4cbc6482ff1fd9a3 upstream.
core_scsi3_decode_spec_i_port() and core_scsi3_emulate_register_and_move() hand the raw PERSISTENT RESERVE OUT parameter buffer to target_parse_pr_out_transport_id() without telling it how many bytes are valid. For an iSCSI TransportID (FORMAT CODE 01b), iscsi_parse_pr_out_transport_id() locates the ",i,0x" ISID separator with an unbounded strstr() (and on the error path prints the name with a further unbounded "%s"). An initiator can submit a TransportID whose iSCSI name contains neither a ",i,0x" substring nor a NUL terminator, filling the parameter list to its end, so the scan runs off the end of the buffer.
When the parameter list spans more than one page the buffer is a multi-page vmap (transport_kmap_data_sg()), so the over-read walks into the trailing vmalloc guard page and oopses (KASAN: vmalloc-out-of-bounds in strstr). It is reachable by any fabric that delivers a PR OUT to a device exported through an iSCSI TPG, including a guest via vhost-scsi.
Pass the number of received bytes down to the parser and validate the iSCSI TransportID's own self-described length (ADDITIONAL LENGTH + 4) once, up
front: reject it if it is below the spc4r17 minimum or larger than the received buffer, then bound the separator search, the ISID walk and the name copy by that length. This is the length check the callers already perform after the parse (core_scsi3_decode_spec_i_port() compares tid_len against tpdl, core_scsi3_emulate_register_and_move() validates it against data_length), moved ahead of the scan. Also drop the unbounded "%s" of the unterminated name.
Add per-format explicit name-length checks before copying into i_str, rather than silently truncating with min_t: for FORMAT CODE 00b reject if the descriptor body (tid_len - 4 bytes) cannot fit in i_str[TRANSPORT_IQN_LEN]; for FORMAT CODE 01b reject if the name portion (from &buf[4] up to the separator) cannot fit. Both checks make the bounds intent explicit at each format branch.
While here, also reject a FORMAT CODE 01b TransportID whose ",i,0x" separator sits at the very end of the descriptor: that leaves an empty ISID and points the returned port nexus pointer at buf + tid_len, one past the descriptor, which the registration code (__core_scsi3_locate_pr_reg(), __core_scsi3_alloc_registration()) then dereferences as the ISID string -- the same over-read of the parameter buffer for a malformed descriptor.
--- drivers/target/target_core_fabric_lib.c | 89 ++++++++++++++++++++++++-------- drivers/target/target_core_internal.h | 3 - drivers/target/target_core_pr.c | 4 - 3 files changed, 73 insertions(+), 23 deletions(-)
drivers/target/target_core_fabric_lib.c +69 -20
@@ -289,13 +289,24 @@ static void sbp_parse_pr_out_transport_istatic bool iscsi_parse_pr_out_transport_id (struct se_portal_group *se_tpg,char *buf, +u32 buf_len,u32 *out_tid_len,char **port_nexus_ptr,char *i_str) {char *p; +u32 tid_len;int i; -u8 format_code = (buf[0 ] &0xc0 ); +u8 format_code; + +/* +* The 4-byte iSCSI TransportID header (FORMAT CODE + 2-byte ADDITIONAL +* LENGTH) must be present before any of it can be parsed. +*/ +if (buf_len <4 ) +return false; + + format_code = buf[0 ] &0xc0 ;/* * Check for FORMAT CODE 00b or 01b from spc4r17, section 7.5.4.6: *
@@ -315,15 +326,17 @@ static bool iscsi_parse_pr_out_transportreturn false; }/* -* If the caller wants the TransportID Length, we set that value for the -* entire iSCSI Tarnsport ID now. +* Reconstruct the self-described TransportID length from the ADDITIONAL +* LENGTH field plus the 4-byte header. Reject it if it is below the +* spc4r17 section 7.5.4.6 minimum (ADDITIONAL LENGTH shall be at least +* 20) or if it runs past the bytes actually received, so that every +* access below stays inside the TransportID. */ -if (out_tid_len) { -/* The shift works thanks to integer promotion rules */ - *out_tid_len =get_unaligned_be16 (&buf[2 ]); -/* Add four bytes for iSCSI Transport ID header */ - *out_tid_len +=4 ; - } + tid_len =get_unaligned_be16 (&buf[2 ]) +4 ; +if (tid_len <24 || tid_len > buf_len) +return false; +if (out_tid_len) + *out_tid_len = tid_len;/* * Check for ',i,0x' separator between iSCSI Name and iSCSI Initiator
@@ -331,16 +344,32 @@ static bool iscsi_parse_pr_out_transport* format. */ if (format_code ==0x40 ) { - p =strstr (&buf[4 ],",i,0x" ); + p =strnstr (&buf[4 ],",i,0x" , tid_len -4 );if (!p) { -pr_err ("Unable to locate \",i,0x\" separator" -" for Initiator port identifier: %s\n" , - &buf[4 ]); +pr_err ("Unable to locate \",i,0x\" separator in iSCSI TransportID\n" ); +return false; + } +/* +* The iSCSI name runs from &buf[4] up to the separator; reject it +* if it cannot fit in i_str[TRANSPORT_IQN_LEN]. +*/ +if (p - &buf[4 ] >=TRANSPORT_IQN_LEN ) { +pr_err ("iSCSI Initiator port name too long in TransportID\n" );return false; } *p ='\0' ;/* Terminate iSCSI Name */ p +=5 ;/* Skip over ",i,0x" separator */ +/* +* The ISID must follow the separator. A ",i,0x" sitting at the +* very end of the TransportID leaves no ISID and would point the +* port nexus at buf + tid_len, i.e. past the descriptor, which +* the registration code then reads as the ISID string. +*/ +if (p >= buf + tid_len) { +pr_err ("Missing ISID in iSCSI Initiator port TransportID\n" ); +return false; + } *port_nexus_ptr = p;/* * Go ahead and do the lower case conversion of the received
@@ -348,7 +377,7 @@ static bool iscsi_parse_pr_out_transport* for comparison against the running iSCSI session's ISID from * iscsi_target.c:lio_sess_get_initiator_sid() */ -for (i =0 ; i <12 ; i++) { +for (i =0 ; i <12 && p < buf + tid_len; i++) {/* * The first ISCSI INITIATOR SESSION ID field byte * containing an ASCII null character terminates the
@@ -366,10 +395,22 @@ static bool iscsi_parse_pr_out_transport *p =tolower (*p); p++; } - }else +strscpy (i_str, &buf[4 ],TRANSPORT_IQN_LEN ); + }else { *port_nexus_ptr =NULL ; - -strscpy (i_str, &buf[4 ],TRANSPORT_IQN_LEN ); +/* +* FORMAT CODE 00b: the name occupies buf[4..tid_len-1]. The +* declared length tid_len - 4 must fit in i_str[TRANSPORT_IQN_LEN]. +* (For 01b the same tid_len bound would be over-restrictive: the +* descriptor also carries the separator and ISID, so a legal +* <=223-byte name gives tid_len up to 244.) +*/ +if (tid_len -4 >=TRANSPORT_IQN_LEN ) { +pr_err ("iSCSI Initiator port name too long in TransportID\n" ); +return false; + } +strscpy (i_str, &buf[4 ], tid_len -4 ); + }return true; }
@@ -419,8 +460,16 @@ int target_get_pr_transport_id(struct se }bool target_parse_pr_out_transport_id (struct se_portal_group *tpg, -char *buf,u32 *out_tid_len,char **port_nexus_ptr,char *i_str) +char *buf,u32 buf_len,u32 *out_tid_len, +char **port_nexus_ptr,char *i_str) { +/* +* The fixed-length SAS/SRP/FCP/SBP TransportIDs are 24 bytes; the iSCSI +* format is variable and bounds itself against buf_len below. +*/ +if (tpg->proto_id !=SCSI_PROTOCOL_ISCSI && buf_len <24 ) +return false; +switch (tpg->proto_id) {case SCSI_PROTOCOL_SAS :/*
@@ -439,8 +488,8 @@ bool target_parse_pr_out_transport_id(stsbp_parse_pr_out_transport_id (buf, i_str);break ;case SCSI_PROTOCOL_ISCSI : -return iscsi_parse_pr_out_transport_id (tpg, buf, out_tid_len, - port_nexus_ptr, i_str); +return iscsi_parse_pr_out_transport_id (tpg, buf, buf_len, + out_tid_len, port_nexus_ptr, i_str);default :pr_err ("Unknown proto_id: 0x%02x\n" , tpg->proto_id);return false;
drivers/target/target_core_internal.h +2 -1
@@ -104,7 +104,8 @@ int target_get_pr_transport_id(struct se struct t10_pr_registration *pr_reg, int *format_code, unsigned char *buf);bool target_parse_pr_out_transport_id (struct se_portal_group *tpg, -char *buf,u32 *out_tid_len,char **port_nexus_ptr,char *i_str); +char *buf,u32 buf_len,u32 *out_tid_len, +char **port_nexus_ptr,char *i_str);/* target_core_hba.c */ struct se_hba *core_alloc_hba (const char *,u32 ,u32 );
drivers/target/target_core_pr.c +2 -2
@@ -1573,7 +1573,7 @@ core_scsi3_decode_spec_i_port( iport_ptr =NULL ; tid_found =target_parse_pr_out_transport_id (tmp_tpg, - ptr, &tid_len, &iport_ptr, i_str); + ptr, tpdl, &tid_len, &iport_ptr, i_str);if (!tid_found)continue ;/*
@@ -3281,7 +3281,7 @@ core_scsi3_emulate_pro_register_and_move goto out; } tid_found =target_parse_pr_out_transport_id (dest_se_tpg, - &buf[24 ], &tmp_tid_len, &iport_ptr, initiator_str); + &buf[24 ], tid_len, &tmp_tid_len, &iport_ptr, initiator_str);if (!tid_found) {pr_err ("SPC-3 PR REGISTER_AND_MOVE: Unable to locate" " initiator_str from Transport ID\n" );
Greg Kroah-Hartman
maintainerPATCH 1371/1611 scsi: target: core: Fix iSCSI ISID use-after-free in REGISTER AND MOVE
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit fda6a1f3c3d7047b5ce5654487649c2daa738bfc upstream.
core_scsi3_emulate_pro_register_and_move() maps the PERSISTENT RESERVE OUT parameter list with transport_kmap_data_sg() and parses the destination TransportID with target_parse_pr_out_transport_id(). For an iSCSI TransportID (FORMAT CODE 01b), iscsi_parse_pr_out_transport_id() returns the ISID in iport_ptr as a raw pointer into that mapped buffer.
The function then unmaps the buffer with transport_kunmap_data_sg() before dereferencing iport_ptr in strcmp(), __core_scsi3_locate_pr_reg() and core_scsi3_alloc_registration(). When the parameter list spans more than one page (PARAMETER LIST LENGTH > 4096), transport_kmap_data_sg() uses vmap() and transport_kunmap_data_sg() does vunmap(), so the kernel virtual address backing iport_ptr is torn down and every subsequent dereference is a use-after-free read of the unmapped region.
Keep the parameter list mapped until iport_ptr is no longer needed: drop the early transport_kunmap_data_sg() and unmap once on the success path, right before returning. The error paths already unmap through the existing "if (buf) transport_kunmap_data_sg(cmd)" at the out: label, which now runs on every post-map error exit because buf is no longer cleared early. Only reads of the mapping happen while spinlocks are held; the map and unmap calls remain outside any lock. The sibling caller core_scsi3_decode_spec_i_port() already uses the buffer before unmapping it and is left unchanged.
--- drivers/target/target_core_pr.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/target/target_core_pr.c +5 -3
@@ -3289,9 +3289,6 @@ core_scsi3_emulate_pro_register_and_move goto out; } -transport_kunmap_data_sg (cmd); - buf =NULL ; - pr_debug("SPC-3 PR [%s] Extracted initiator %s identifier: %s" " %s\n", dest_tf_ops->fabric_name, (iport_ptr != NULL) ? "port" : "device", initiator_str, (iport_ptr != NULL) ?
@@ -3528,6 +3525,11 @@ after_iport_check:core_scsi3_update_and_write_aptpl (cmd->se_dev, aptpl);core_scsi3_put_pr_reg (dest_pr_reg); +/* +* iport_ptr aliases the PR-OUT parameter list mapped above, so the +* buffer is unmapped only here on success (and at out: on error). +*/ +transport_kunmap_data_sg (cmd);return 0 ; out:if (buf)
Greg Kroah-Hartman
maintainerPATCH 1372/1611 scsi: elx: efct: Fix refcount leak in efct_hw_io_abort()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: WenTao Liang <[email protected]>
commit 2c007acf7b31c39c08ce4959451ad00b19be4c1f upstream.
When efct_hw_reqtag_alloc() fails in efct_hw_io_abort(), the error path returns -ENOSPC without releasing the reference obtained via kref_get_unless_zero() earlier in the function. All other error paths correctly drop the reference. This causes a permanent reference leak on the io_to_abort object.
Additionally, the abort_in_progress flag is left set to true on this path, which means future abort attempts for the same I/O will immediately return -EINPROGRESS even though the abort was never submitted, effectively blocking recovery.
Fix this by adding the missing kref_put() call and reset abort_in_progress to false, matching the cleanup done in the efct_hw_wq_write() failure path below.
--- drivers/scsi/elx/efct/efct_hw.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/elx/efct/efct_hw.c +2 -0
@@ -1998,6 +1998,8 @@ efct_hw_io_abort(struct efct_hw *hw, str wqcb =efct_hw_reqtag_alloc (hw, efct_hw_wq_process_abort, io_to_abort);if (!wqcb) {efc_log_err (hw->os,"can't allocate request tag\n" ); + io_to_abort->abort_in_progress = false; +kref_put (&io_to_abort->ref, io_to_abort->release);return -ENOSPC ; }
Greg Kroah-Hartman
maintainerPATCH 1373/1611 scsi: elx: efct: Fix I/O leak on unsupported additional CDB
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 9cb2d5291dbfe7bed565ead3337047dee9ed1064 upstream.
efct_dispatch_fcp_cmd() allocates an efct_io before dispatching an unsolicited FCP command. If the command has an unsupported additional CDB, the function returns -EIO before handing the IO to the SCSI layer.
Free the allocated IO before returning from this error path.
--- drivers/scsi/elx/efct/efct_unsol.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/elx/efct/efct_unsol.c +1 -0
@@ -385,6 +385,7 @@ efct_dispatch_fcp_cmd(struct efct_node *if (cmnd->fc_flags &FCP_CFL_LEN_MASK ) {efc_log_err (efct,"Additional CDB not supported\n" ); +efct_scsi_io_free (io);return -EIO ; }/*
Greg Kroah-Hartman
maintainerPATCH 1374/1611 Input: ims-pcu - fix use-after-free and double-free in disconnect
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 462a999917755a3bf77448dfd64307963cf0a9f0 upstream.
ims_pcu_disconnect() only intended to perform cleanup when the primary (control) interface is unbound. However, it currently relies on the interface class to distinguish between control and data interfaces. A malicious device could present a data interface with the same class as the control interface, leading to premature cleanup and potential use-after-free or double-free.
Switch to verifying that the interface being disconnected is indeed the control interface.
--- drivers/input/misc/ims-pcu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/misc/ims-pcu.c +1 -2
@@ -2051,7 +2051,6 @@ err_free_mem:static void ims_pcu_disconnect (struct usb_interface *intf) {struct ims_pcu *pcu =usb_get_intfdata (intf); -struct usb_host_interface *alt = intf->cur_altsetting;usb_set_intfdata (intf,NULL );
@@ -2059,7 +2058,7 @@ static void ims_pcu_disconnect(struct us* See if we are dealing with control or data interface. The cleanup * happens when we unbind primary (control) interface. */ -if (alt->desc.bInterfaceClass !=USB_CLASS_COMM ) +if (intf != pcu->ctrl_intf)return ;ims_pcu_stop_io (pcu);
Greg Kroah-Hartman
maintainerPATCH 1375/1611 Input: ims-pcu - only expose sysfs attributes on control interface
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 001428ea4d2c371107cb984108e266adf99f1f1e upstream.
When the driver was converted to use the driver core to instantiate device attributes (via .dev_groups in the usb_driver structure), the attributes started appearing on all interfaces bound to the driver. Since the ims-pcu driver manually claims the secondary data interface during probe, the driver core automatically creates the sysfs attributes for that interface as well.
However, the driver only supports these attributes on the primary control interface. Data interfaces lack the necessary descriptors and internal state to handle these requests, and accessing them can lead to unexpected behavior or crashes.
Fix this by updating the is_visible() callbacks for both the main and OFN attribute groups to verify that the interface being accessed is indeed the control interface.
--- drivers/input/misc/ims-pcu.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/misc/ims-pcu.c +7 -0
@@ -14,6 +14,7 @@#include <linux/leds.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/sysfs.h> #include <linux/types.h> #include <linux/usb/input.h> #include <linux/usb/cdc.h>
@@ -1229,6 +1230,9 @@ static umode_t ims_pcu_is_attr_visible(sstruct ims_pcu *pcu =usb_get_intfdata (intf);umode_t mode = attr->mode; +if (intf != pcu->ctrl_intf) +return 0 ; +if (pcu->bootloader_mode) { if (attr != &dev_attr_update_firmware_status.attr && attr != &dev_attr_update_firmware.attr &&
@@ -1468,6 +1472,9 @@ static umode_t ims_pcu_ofn_is_attr_visibstruct ims_pcu *pcu =usb_get_intfdata (intf);umode_t mode = attr->mode; +if (intf != pcu->ctrl_intf) +return SYSFS_GROUP_INVISIBLE ; +/* * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor. */
Greg Kroah-Hartman
maintainerPATCH 1376/1611 Input: ims-pcu - release data interface on disconnect
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 441c510a649c8ddce38aa0311334ed8bb546b36c upstream.
During probe the driver claims the data interface, but it never releases it. Release it in disconnect to avoid leaving it permanently claimed.
--- drivers/input/misc/ims-pcu.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/misc/ims-pcu.c +1 -0
@@ -2076,6 +2076,7 @@ static void ims_pcu_disconnect(struct usims_pcu_destroy_application_mode (pcu);ims_pcu_buffers_free (pcu); +usb_driver_release_interface (&ims_pcu_driver, pcu->data_intf);kfree (pcu); }
Greg Kroah-Hartman
maintainerPATCH 1377/1611 Input: ims-pcu - validate control endpoint type
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit baf56975806534268e24acf9a8abb1c447ce11e9 upstream.
The driver currently assumes that the first endpoint of the control interface is an interrupt IN endpoint without verifying it. A malicious device could provide a different endpoint type, which would then be passed to usb_fill_int_urb(), potentially leading to kernel warnings or undefined behavior.
Verify that the control endpoint is an interrupt IN endpoint.
--- drivers/input/misc/ims-pcu.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/input/misc/ims-pcu.c +6 -0
@@ -1689,6 +1689,12 @@ static int ims_pcu_parse_cdc_data(structreturn -ENODEV ; pcu->ep_ctrl = &alt->endpoint[0 ].desc; +if (!usb_endpoint_is_int_in (pcu->ep_ctrl)) { +dev_err (pcu->dev, +"Control endpoint is not INTERRUPT IN\n" ); +return -EINVAL ; + } + pcu->max_ctrl_size =usb_endpoint_maxp (pcu->ep_ctrl); pcu->data_intf = usb_ifnum_to_if(pcu->udev,
Greg Kroah-Hartman
maintainerPATCH 1378/1611 Input: ims-pcu - add response length checks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 48c9d92fd4ee3a8f5d2cb46c802a0eff8e67c79c upstream.
The driver processes response data from device buffers without verifying that the device actually sent enough data. This can lead to out-of-bounds reads or processing stale data.
Add checks for the expected response length before accessing the buffers.
--- drivers/input/misc/ims-pcu.c | 87 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 6 deletions(-)
drivers/input/misc/ims-pcu.c +81 -6
@@ -407,7 +407,16 @@ static void ims_pcu_destroy_gamepad(strustatic void ims_pcu_report_events (struct ims_pcu *pcu) { -u32 data =get_unaligned_be32 (&pcu->read_buf[3 ]); +u32 data; + +/* 6-axis setting (1 byte) + button data + checksum */ +if (pcu->read_pos <IMS_PCU_DATA_OFFSET +1 +sizeof (data) +1 ) { +dev_warn (pcu->dev,"Short buttons report: %d bytes\n" , + pcu->read_pos); +return ; + } + + data =get_unaligned_be32 (&pcu->read_buf[IMS_PCU_DATA_OFFSET +1 ]);ims_pcu_buttons_report (pcu, data & ~IMS_PCU_GAMEPAD_MASK );if (pcu->gamepad)
@@ -667,11 +676,19 @@ static int __ims_pcu_execute_bl_command(return error; } -if (expected_response && pcu->cmd_buf[2 ] != expected_response) { -dev_err (pcu->dev, -"Unexpected response from bootloader: 0x%02x, wanted 0x%02x\n" , - pcu->cmd_buf[2 ], expected_response); -return -EINVAL ; +if (expected_response) { +if (pcu->cmd_buf_len <3 ) { +dev_err (pcu->dev,"Short response from bootloader: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + +if (pcu->cmd_buf[2 ] != expected_response) { +dev_err (pcu->dev, +"Unexpected response from bootloader: 0x%02x, wanted 0x%02x\n" , + pcu->cmd_buf[2 ], expected_response); +return -EINVAL ; + } }return 0 ;
@@ -699,6 +716,12 @@ static int ims_pcu_get_info(struct ims_preturn error; } +if (pcu->cmd_buf_len <IMS_PCU_DATA_OFFSET +IMS_PCU_SET_INFO_SIZE +1 ) { +dev_err (pcu->dev,"Short GET_INFO response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } +memcpy (pcu->part_number, &pcu->cmd_buf[IMS_PCU_INFO_PART_OFFSET ],sizeof (pcu->part_number));
@@ -796,6 +819,12 @@ static int ims_pcu_verify_block(struct ireturn error; } +if (pcu->cmd_buf_len <IMS_PCU_BL_DATA_OFFSET +sizeof (*fragment) + len +1 ) { +dev_err (pcu->dev,"Short READ_APP response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + fragment = (void *)&pcu->cmd_buf[IMS_PCU_BL_DATA_OFFSET ];if (get_unaligned_le32 (&fragment->addr) != addr || fragment->len != len) {
@@ -990,6 +1019,10 @@ ims_pcu_backlight_get_brightness(struct error);/* Assume the LED is OFF */ brightness =LED_OFF ; + }else if (pcu->cmd_buf_len <IMS_PCU_DATA_OFFSET +2 +1 ) { +dev_err (pcu->dev,"Short GET_BRIGHTNESS response: %d bytes\n" , + pcu->cmd_buf_len); + brightness =LED_OFF ; }else { brightness =get_unaligned_le16 (&pcu->cmd_buf[IMS_PCU_DATA_OFFSET ]);
@@ -1266,6 +1299,12 @@ static int ims_pcu_read_ofn_config(strucif (error)return error; +if (pcu->cmd_buf_len <OFN_REG_RESULT_OFFSET +2 +1 ) { +dev_err (pcu->dev,"Short OFN_GET_CONFIG response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + result = (s16 )get_unaligned_le16 (pcu->cmd_buf +OFN_REG_RESULT_OFFSET );if (result <0 )return -EIO ;
@@ -1286,6 +1325,12 @@ static int ims_pcu_write_ofn_config(struif (error)return error; +if (pcu->cmd_buf_len <OFN_REG_RESULT_OFFSET +2 +1 ) { +dev_err (pcu->dev,"Short OFN_SET_CONFIG response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + result = (s16 )get_unaligned_le16 (pcu->cmd_buf +OFN_REG_RESULT_OFFSET );if (result <0 )return -EIO ;
@@ -1824,6 +1869,12 @@ static int ims_pcu_get_device_info(strucreturn error; } +if (pcu->cmd_buf_len <IMS_PCU_DATA_OFFSET +6 +1 ) { +dev_err (pcu->dev,"Short GET_FW_VERSION response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + snprintf(pcu->fw_version, sizeof(pcu->fw_version), "%02d%02d%02d%02d.%c%c", pcu->cmd_buf[2], pcu->cmd_buf[3], pcu->cmd_buf[4], pcu->cmd_buf[5],
@@ -1836,6 +1887,12 @@ static int ims_pcu_get_device_info(strucreturn error; } +if (pcu->cmd_buf_len <IMS_PCU_DATA_OFFSET +6 +1 ) { +dev_err (pcu->dev,"Short GET_BL_VERSION response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + snprintf(pcu->bl_version, sizeof(pcu->bl_version), "%02d%02d%02d%02d.%c%c", pcu->cmd_buf[2], pcu->cmd_buf[3], pcu->cmd_buf[4], pcu->cmd_buf[5],
@@ -1848,6 +1905,12 @@ static int ims_pcu_get_device_info(strucreturn error; } +if (pcu->cmd_buf_len <IMS_PCU_DATA_OFFSET +1 +1 ) { +dev_err (pcu->dev,"Short RESET_REASON response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } +snprintf (pcu->reset_reason,sizeof (pcu->reset_reason),"%02x" , pcu->cmd_buf[IMS_PCU_DATA_OFFSET ]);
@@ -1874,6 +1937,12 @@ static int ims_pcu_identify_type(structreturn error; } +if (pcu->cmd_buf_len <IMS_PCU_DATA_OFFSET +1 +1 ) { +dev_err (pcu->dev,"Short GET_DEVICE_ID response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + *device_id = pcu->cmd_buf[IMS_PCU_DATA_OFFSET ];dev_dbg (pcu->dev,"Detected device ID: %d\n" , *device_id);
@@ -1965,6 +2034,12 @@ static int ims_pcu_init_bootloader_mode(return error; } +if (pcu->cmd_buf_len <IMS_PCU_DATA_OFFSET +15 +4 +1 ) { +dev_err (pcu->dev,"Short QUERY_DEVICE response: %d bytes\n" , + pcu->cmd_buf_len); +return -EIO ; + } + pcu->fw_start_addr =get_unaligned_le32 (&pcu->cmd_buf[IMS_PCU_DATA_OFFSET +11 ]); pcu->fw_end_addr =
Greg Kroah-Hartman
maintainerPATCH 1379/1611 Input: ims-pcu - fix DMA mapping violation in line setup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 8adf4289d945e8990e4336436a97da71d21d2cae upstream.
In ims_pcu_line_setup(), the driver uses pcu->cmd_buf as a transfer buffer for usb_control_msg(). However, pcu->cmd_buf is embedded in the struct ims_pcu allocation, which violates DMA mapping rules regarding cacheline alignment.
Use a heap-allocated buffer for the line coding data instead.
--- drivers/input/misc/ims-pcu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/input/misc/ims-pcu.c +7 -2
@@ -1821,11 +1821,16 @@ static void ims_pcu_stop_io(struct ims_pstatic int ims_pcu_line_setup (struct ims_pcu *pcu) {struct usb_host_interface *interface = pcu->ctrl_intf->cur_altsetting; -struct usb_cdc_line_coding *line = (void *)pcu->cmd_buf; + struct usb_cdc_line_coding *line __free(kfree) = +kmalloc (sizeof (*line),GFP_KERNEL );int error; -memset (line,0 ,sizeof (*line)); +if (!line) +return -ENOMEM ; + line->dwDTERate =cpu_to_le32 (57600 ); + line->bCharFormat =USB_CDC_1_STOP_BITS ; + line->bParityType =USB_CDC_NO_PARITY ; line->bDataBits =8 ; error = usb_control_msg(pcu->udev, usb_sndctrlpipe(pcu->udev, 0),
Greg Kroah-Hartman
maintainerPATCH 1380/1611 Input: ims-pcu - fix firmware leak in async update
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit d48795b5cd6828d36b707e8d62fc9e5c90e004ab upstream.
The firmware object was not being released if validation failed. Use __free(firmware) to ensure the firmware is always released.
--- drivers/input/misc/ims-pcu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/misc/ims-pcu.c +2 -3
@@ -944,9 +944,10 @@ out:return retval; } -static void ims_pcu_process_async_firmware (const struct firmware *fw, +static void ims_pcu_process_async_firmware (const struct firmware *_fw,void *context) { + const struct firmware *fw __free(firmware) = _fw;struct ims_pcu *pcu = context;int error;
@@ -966,8 +967,6 @@ static void ims_pcu_process_async_firmwa scoped_guard(mutex, &pcu->cmd_mutex)ims_pcu_handle_firmware_update (pcu, fw); -release_firmware (fw); - out:complete (&pcu->async_firmware_done); }
Greg Kroah-Hartman
maintainerPATCH 1381/1611 Input: ims-pcu - fix out-of-bounds read in ims_pcu_irq() debug logging
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 403b0a6970b1084bb27907c0f8225801fdd0fe1d upstream.
The debug logging in ims_pcu_irq() unconditionally prints data from pcu->urb_in_buf. However, if the interrupt fired for pcu->urb_ctrl, the actual data resides in pcu->urb_ctrl_buf. If urb->actual_length for the control URB exceeds pcu->max_in_size, this leads to an out-of-bounds read.
Fix this by printing from the correct buffer associated with the URB.
--- drivers/input/misc/ims-pcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/ims-pcu.c +1 -1
@@ -1559,7 +1559,7 @@ static void ims_pcu_irq(struct urb *urb) }dev_dbg (pcu->dev,"%s: received %d: %*ph\n" , __func__, - urb->actual_length, urb->actual_length, pcu->urb_in_buf); + urb->actual_length, urb->actual_length, urb->transfer_buffer);if (urb == pcu->urb_in)ims_pcu_process_data (pcu, urb);
Greg Kroah-Hartman
maintainerPATCH 1382/1611 Input: ims-pcu - fix potential infinite loop in CDC union descriptor parsing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit d4579af29e67ca8722db0a1194227f8015c8981d upstream.
The driver parses CDC union descriptors in ims_pcu_get_cdc_union_desc() by iterating through the extra descriptor data. However, it does not verify that the bLength of each descriptor is at least 2. A malicious device could provide a descriptor with bLength = 0, leading to an infinite loop in the driver.
Add a check to ensure bLength is at least 2 before proceeding with parsing.
--- drivers/input/misc/ims-pcu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/misc/ims-pcu.c +3 -2
@@ -1687,8 +1687,9 @@ ims_pcu_get_cdc_union_desc(struct usb_inwhile (buflen >=sizeof (*union_desc)) { union_desc = (struct usb_cdc_union_desc *)buf; -if (union_desc->bLength > buflen) { -dev_err (&intf->dev,"Too large descriptor\n" ); +if (union_desc->bLength <2 || union_desc->bLength > buflen) { +dev_err (&intf->dev,"Invalid descriptor length: %d\n" , + union_desc->bLength);return NULL ; }
Greg Kroah-Hartman
maintainerPATCH 1383/1611 Input: ims-pcu - fix race condition in reset_device sysfs callback
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 411b8c4b274737c3bf08e1e025801161603cfffc upstream.
The ims_pcu_reset_device() sysfs callback calls ims_pcu_execute_command() without acquiring pcu->cmd_mutex. This can lead to data races and corruption of the shared command buffer if triggered concurrently with other commands.
Acquire pcu->cmd_mutex before calling ims_pcu_execute_command().
--- drivers/input/misc/ims-pcu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/misc/ims-pcu.c +2 -0
@@ -1166,6 +1166,8 @@ static ssize_t ims_pcu_reset_device(strudev_info (pcu->dev,"Attempting to reset device\n" ); +guard (mutex)(&pcu->cmd_mutex); + error =ims_pcu_execute_command (pcu,PCU_RESET , &reset_byte,1 );if (error) { dev_info(pcu->dev,
Greg Kroah-Hartman
maintainerPATCH 1384/1611 Input: ims-pcu - fix type confusion in CDC union descriptor parsing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit ca459e237bc49567649c56bc72e4c602fb92fd67 upstream.
The driver currently trusts the bMasterInterface0 from the CDC union descriptor without verifying that it matches the interface being probed. This could lead to the driver overwriting the private data of another interface.
Validate that the control interface found in the descriptor is indeed the one we are probing.
--- drivers/input/misc/ims-pcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/ims-pcu.c +1 -1
@@ -1727,7 +1727,7 @@ static int ims_pcu_parse_cdc_data(struct pcu->ctrl_intf =usb_ifnum_to_if (pcu->udev, union_desc->bMasterInterface0); -if (!pcu->ctrl_intf) +if (pcu->ctrl_intf != intf)return -EINVAL ; alt = pcu->ctrl_intf->cur_altsetting;
Greg Kroah-Hartman
maintainerPATCH 1385/1611 net/mlx5e: macsec: fix use-after-free of metadata_dst on RX SC delete
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit de74d8fd10291763d97b218f09adcc7513c975e4 upstream.
When an offloaded MACsec RX SC is deleted, macsec_del_rxsc_ctx() freed the per-SC metadata_dst with metadata_dst_free(), which kfree()s the object unconditionally and ignores the dst reference count. The RX datapath in mlx5e_macsec_offload_handle_rx_skb() looks up the SC under rcu_read_lock() via xa_load(), takes a reference with dst_hold() and attaches the dst to the skb with skb_dst_set(). A reader that already obtained the rx_sc pointer can race with the delete path and operate on freed memory.
Fix the owner side by dropping the reference with dst_release() instead of freeing unconditionally, and convert the RX datapath to dst_hold_safe() so a reader racing the SC delete cannot attach a dst whose last reference was just dropped; only attach it when a reference was actually taken.
mlx5e_macsec_add_rxsc() also published sc_xarray_element via xa_alloc() before rx_sc->md_dst was allocated and initialised, so a datapath reader that looked the SC up by fs_id could observe rx_sc with md_dst still NULL or, on weakly-ordered architectures, a non-NULL md_dst pointer whose contents were not yet visible. NULL-check the xa_load() result and md_dst on the datapath, and reorder add_rxsc() so the xa_alloc() publish happens only after md_dst is fully initialised; the xarray RCU publish then pairs with the rcu_read_lock()/xa_load() in the datapath.
Note: macsec_del_rxsc_ctx() also kfree()s rx_sc->sc_xarray_element without an RCU grace period while the same datapath reads it under rcu_read_lock(); that is a separate pre-existing issue left to a follow-up patch.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 47 ++++++++------ 1 file changed, 28 insertions(+), 19 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c +28 -19
@@ -713,34 +713,43 @@ static int mlx5e_macsec_add_rxsc(struct } sc_xarray_element->rx_sc = rx_sc; - err =xa_alloc (&macsec->sc_xarray, &sc_xarray_element->fs_id, sc_xarray_element, -XA_LIMIT (1 ,MLX5_MACEC_RX_FS_ID_MAX ),GFP_KERNEL ); -if (err) { -if (err == -EBUSY ) -netdev_err (ctx->netdev, -"MACsec offload: unable to create entry for RX SC (%d Rx SCs already allocated)\n" , -MLX5_MACEC_RX_FS_ID_MAX ); - goto destroy_sc_xarray_elemenet; - } rx_sc->md_dst =metadata_dst_alloc (0 ,METADATA_MACSEC ,GFP_KERNEL );if (!rx_sc->md_dst) { err = -ENOMEM ; - goto erase_xa_alloc; + goto destroy_sc_xarray_elemenet; } rx_sc->sci = ctx_rx_sc->sci; rx_sc->active = ctx_rx_sc->active; -list_add_rcu (&rx_sc->rx_sc_list_element, rx_sc_list); - rx_sc->sc_xarray_element = sc_xarray_element; rx_sc->md_dst->u.macsec_info.sci = rx_sc->sci; + +/* +* Publish the fully-initialised SC last: xa_alloc() makes +* sc_xarray_element->rx_sc (and rx_sc->md_dst) reachable from the RX +* datapath via xa_load(). Doing it only after md_dst is allocated and +* initialised pairs with the rcu_read_lock()/xa_load() in +* mlx5e_macsec_offload_handle_rx_skb(), so a reader can never observe +* a non-NULL md_dst with uninitialised contents. +*/ + err =xa_alloc (&macsec->sc_xarray, &sc_xarray_element->fs_id, sc_xarray_element, +XA_LIMIT (1 ,MLX5_MACEC_RX_FS_ID_MAX ),GFP_KERNEL ); +if (err) { +if (err == -EBUSY ) +netdev_err (ctx->netdev, +"MACsec offload: unable to create entry for RX SC (%d Rx SCs already allocated)\n" , +MLX5_MACEC_RX_FS_ID_MAX ); + goto destroy_md_dst; + } + +list_add_rcu (&rx_sc->rx_sc_list_element, rx_sc_list);mutex_unlock (&macsec->lock);return 0 ; -erase_xa_alloc: -xa_erase (&macsec->sc_xarray, sc_xarray_element->fs_id); +destroy_md_dst: +dst_release (&rx_sc->md_dst->dst); destroy_sc_xarray_elemenet:kfree (sc_xarray_element); destroy_rx_sc:
@@ -828,7 +837,7 @@ static void macsec_del_rxsc_ctx(struct m*/ list_del_rcu (&rx_sc->rx_sc_list_element);xa_erase (&macsec->sc_xarray, rx_sc->sc_xarray_element->fs_id); -metadata_dst_free (rx_sc->md_dst); +dst_release (&rx_sc->md_dst->dst);kfree (rx_sc->sc_xarray_element);kfree_rcu_mightsleep (rx_sc); }
@@ -1698,10 +1707,10 @@ void mlx5e_macsec_offload_handle_rx_skb(rcu_read_lock (); sc_xarray_element =xa_load (&macsec->sc_xarray, fs_id); - rx_sc = sc_xarray_element->rx_sc; -if (rx_sc) { -dst_hold (&rx_sc->md_dst->dst); -skb_dst_set (skb, &rx_sc->md_dst->dst); + rx_sc = sc_xarray_element ? sc_xarray_element->rx_sc :NULL ; +if (rx_sc && rx_sc->md_dst) { +if (dst_hold_safe (&rx_sc->md_dst->dst)) +skb_dst_set (skb, &rx_sc->md_dst->dst); }rcu_read_unlock ();
Greg Kroah-Hartman
maintainerPATCH 1386/1611 tracing/user_events: Fix use-after-free in user_event_mm_dup()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 50fd6dd755c6e48a38af2fa4621167eea56829c2 upstream.
user_event_mm_dup() walks the parent mm's enabler list locklessly under rcu_read_lock() during fork() (from copy_process()); it does not take event_mutex:
rcu_read_lock(); list_for_each_entry_rcu(enabler, &old_mm->enablers, mm_enablers_link) enabler->event = user_event_get(orig->event);
user_event_enabler_destroy() removes an enabler from that list with list_del_rcu() and then, without waiting for a grace period, drops the enabler's user_event reference with user_event_put() and frees the enabler with kfree(). A reader that loaded the enabler before the list_del_rcu() can still be walking it, which leads to two use-after-frees:
- kfree(enabler) frees the enabler while that reader dereferences enabler->event.
- user_event_put() may drop the last reference to the user_event, which is then freed (via delayed_destroy_user_event() on a work queue), while the same reader does user_event_get(orig->event) on it.
Both are reachable by an unprivileged task that can open user_events_data:
one multithreaded process that registers an enabler and then concurrently unregisters it and calls fork() triggers the race. KASAN reports a slab-use-after-free in user_event_mm_dup() during clone(), with a "refcount_t: addition on 0" warning when the user_event is freed.
The enabler use-after-free was found first; the user_event one was reported by XIAO WU, and the earlier enabler-only fix did not address it.
Defer both the user_event_put() and the kfree(enabler) to a work item queued with queue_rcu_work(), so they run only after an RCU grace period, once all readers walking the enabler list have finished. The put must run in process context because user_event_put() takes event_mutex on the last reference, so a work queue is used rather than call_rcu(). The now-unlocked put lets the locked argument of user_event_enabler_destroy() be removed; all callers are updated.
--- kernel/trace/trace_events_user.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-)
kernel/trace/trace_events_user.c +32 -7
@@ -109,6 +109,9 @@ struct user_event_enabler {/* Track enable bit, flags, etc. Aligned for bitops. */ unsigned long values; + +/* Defer the event put and enabler free past an RCU grace period. */ +struct rcu_work put_rwork; };/* Bits 0-5 are for the bit to update upon enable/disable (0-63 allowed) */
@@ -396,17 +399,39 @@ error:return NULL ; }; -static void user_event_enabler_destroy (struct user_event_enabler *enabler, -bool locked) +static void delayed_user_event_enabler_put (struct work_struct *work) { -list_del_rcu (&enabler->mm_enablers_link); +struct user_event_enabler *enabler =container_of (to_rcu_work (work), + struct user_event_enabler, put_rwork);/* No longer tracking the event via the enabler */ -user_event_put (enabler->event, locked); +user_event_put (enabler->event, false); +/* Run from queue_rcu_work(), the RCU grace period has elapsed */ kfree (enabler); } +static void user_event_enabler_destroy (struct user_event_enabler *enabler) +{ +list_del_rcu (&enabler->mm_enablers_link); + +/* +* The enabler is removed from an RCU-traversed list +* (user_event_mm_dup() walks mm->enablers under rcu_read_lock() only), +* and readers there dereference enabler->event and take a new ref on +* it. Both the put of that event reference and the free of the enabler +* therefore have to wait for a grace period so no reader can be looking +* at the enabler or racing the last put of its event. +* +* The put itself must not run in RCU context: when it drops the last +* reference user_event_put() takes event_mutex, which cannot be taken +* from a softirq/RCU callback. Defer both to a work item scheduled +* after a grace period via queue_rcu_work(). +*/ +INIT_RCU_WORK (&enabler->put_rwork, delayed_user_event_enabler_put); +queue_rcu_work (system_percpu_wq, &enabler->put_rwork); +} +static int user_event_mm_fault_in (struct user_event_mm *mm,unsigned long uaddr,int attempt) {
@@ -464,7 +489,7 @@ static void user_event_enabler_fault_fix/* User asked for enabler to be removed during fault */ if (test_bit (ENABLE_VAL_FREEING_BIT ,ENABLE_BITOPS (enabler))) { -user_event_enabler_destroy (enabler, true); +user_event_enabler_destroy (enabler); goto out; }
@@ -764,7 +789,7 @@ static void user_event_mm_destroy(structstruct user_event_enabler *enabler, *next;list_for_each_entry_safe (enabler, next, &mm->enablers, mm_enablers_link) -user_event_enabler_destroy (enabler, false); +user_event_enabler_destroy (enabler);mmdrop (mm->mm);kfree (mm);
@@ -2655,7 +2680,7 @@ static long user_events_ioctl_unreg(unsi flags |= enabler->values &ENABLE_VAL_COMPAT_MASK ;if (!test_bit (ENABLE_VAL_FAULTING_BIT ,ENABLE_BITOPS (enabler))) -user_event_enabler_destroy (enabler, true); +user_event_enabler_destroy (enabler);/* Removed at least one */ ret =0 ;
Greg Kroah-Hartman
maintainerPATCH 1387/1611 wifi: libertas_tf: fix use-after-free in lbtf_free_adapter()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit aa6dcd5c8dd9ba1d7d0f60093bcda41c0d6d438d upstream.
lbtf_free_adapter() calls timer_delete(&priv->command_timer), which does not wait for a running command_timer_fn() callback. lbtf_free_adapter() runs on the teardown path right before ieee80211_free_hw() frees priv, both in lbtf_remove_card() and in the probe error path. command_timer is armed by mod_timer() in lbtf_cmd() whenever a firmware command is sent. command_timer_fn() dereferences priv. If a command times out as the device is removed, command_timer_fn() runs concurrently with teardown and dereferences priv after it has been freed.
This is the same use-after-free that commit 03cc8f90d053 ("wifi: libertas:
fix use-after-free in lbs_free_adapter()") fixed in the sibling libertas driver. The libertas_tf variant has the identical pattern and was left unchanged. Use timer_delete_sync() so any in-flight callback completes before priv is 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
@@ -174,7 +174,7 @@ static void lbtf_free_adapter(struct lbt {lbtf_deb_enter (LBTF_DEB_MAIN );lbtf_free_cmd_buffer (priv); -timer_delete (&priv->command_timer); +timer_delete_sync (&priv->command_timer);lbtf_deb_leave (LBTF_DEB_MAIN ); }
Greg Kroah-Hartman
maintainerPATCH 1388/1611 locking/rt: Fix the incorrect RCU protection in rt_spin_unlock()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
commit 89038cc87d80c77e7aa6f42a64b2573b74af339f upstream.
rt_spin_unlock() releases the RCU protection before unlocking the lock. That opens the door for the following UAF scenario:
T1 T2
spin_lock(&p->lock); rcu_read_lock();
invalidate(p); p = rcu_dereference(ptr);
rcu_assign_pointer(ptr, NULL); if (!p) return;
spin_unlock(&p->lock); spin_lock(&p->lock)
lock(&lock->lock); rcu_read_lock(); kfree_rcu(p); rcu_read_unlock(); .... spin_unlock(&p->lock) rcu_read_unlock(); // Ends grace period rcu_do_batch() kfree(p); UAF -> rt_mutex_cmpxchg_release(&lock->lock...)
Regular spinlocks keep preemption disabled accross the unlock operation, which provides full RCU protection, but the RT substitution fails to resemble that. Same applies for the rwlock substitution.
Move the rcu_read_unlock() invocation past the unlock operations to match the non-RT semantics. This makes it asymmetric vs. rt_xxx_lock(), but that's harmless as the caller needs to hold RCU read lock across the lock operation. The migrate_enable() call stays before the unlock operation because there is no per CPU operation in the unlock path which would require migration to be kept disabled.
--- kernel/locking/spinlock_rt.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
kernel/locking/spinlock_rt.c +24 -3
@@ -79,10 +79,27 @@ void __sched rt_spin_unlock(spinlock_t * {spin_release (&lock->dep_map, _RET_IP_);migrate_enable (); -rcu_read_unlock ();if (unlikely (!rt_mutex_cmpxchg_release (&lock->lock, current,NULL )))rt_mutex_slowunlock (&lock->lock); + +/* +* This must be last to prevent the following UAF: +* +* T1 T2 +* spin_lock(&p->lock); rcu_read_lock(); +* invalidate(p); p = rcu_dereference(ptr); +* rcu_assign_pointer(ptr, NULL); if (!p) return; +* spin_unlock(&p->lock); spin_lock(&p->lock); +* kfree_rcu(p); rcu_read_unlock(); +* .... +* spin_unlock(&p->lock) +* rcu_read_unlock(); // Ends grace period +* rcu_do_batch() +* kfree(p); +* UAF -> rt_mutex_cmpxchg_release(&p->lock.lock...) +*/ +rcu_read_unlock (); }EXPORT_SYMBOL (rt_spin_unlock);
@@ -262,17 +279,21 @@ void __sched rt_read_unlock(rwlock_t *rw {rwlock_release (&rwlock->dep_map, _RET_IP_);migrate_enable (); -rcu_read_unlock ();rwbase_read_unlock (&rwlock->rwbase,TASK_RTLOCK_WAIT ); + +/* This must be last. See comment in rt_spin_unlock() */ +rcu_read_unlock (); }EXPORT_SYMBOL (rt_read_unlock); void __sched rt_write_unlock(rwlock_t *rwlock) __releases(RCU) {rwlock_release (&rwlock->dep_map, _RET_IP_); -rcu_read_unlock ();migrate_enable ();rwbase_write_unlock (&rwlock->rwbase); + +/* This must be last. See comment in rt_spin_unlock() */ +rcu_read_unlock (); }EXPORT_SYMBOL (rt_write_unlock);
Greg Kroah-Hartman
maintainerPATCH 1389/1611 posix-cpu-timers: Use u64 multiplication in update_rlimit_cpu()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
commit 26aff38fefb1d6cd87e22525f41cc8f1aa61b24f upstream.
update_rlimit_cpu() converts the RLIMIT_CPU value to nanoseconds with
u64 nsecs = rlim_new * NSEC_PER_SEC;
On 32-bit kernels both rlim_new (unsigned long) and NSEC_PER_SEC (1000000000L) are 32-bit, so the multiplication is performed in unsigned long and truncated for rlim_new > 4 seconds before being widened to u64.
The same file already casts to u64 for the matching computation in check_process_timers():
u64 softns = (u64)soft * NSEC_PER_SEC;
As a result, the truncated value is installed into the CPUCLOCK_PROF expiry cache (nextevt), causing the process CPU timer to be programmed to fire prematurely for any RLIMIT_CPU soft limit >= 5 seconds. The actual SIGXCPU/SIGKILL decision in check_process_timers() already casts to u64 and is therefore correct, so limit enforcement is not broken; only the expiry-cache programming is wrong. Apply the same cast here so both paths convert rlim_cur identically.
64-bit kernels are unaffected.
--- kernel/time/posix-cpu-timers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/posix-cpu-timers.c +1 -1
@@ -41,7 +41,7 @@ void posix_cputimers_group_init(struct p*/ int update_rlimit_cpu (struct task_struct *task,unsigned long rlim_new) { -u64 nsecs = rlim_new *NSEC_PER_SEC ; +u64 nsecs = (u64 )rlim_new *NSEC_PER_SEC ;unsigned long irq_fl;if (!lock_task_sighand (task, &irq_fl))
Greg Kroah-Hartman
maintainerPATCH 1390/1611 selftests/ftrace: Drop invalid top-level local in test_ownership
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cao Ruichuang <[email protected]>
commit 808c447df2fe234eb7d9e08ecf53159d291c104c upstream.
test_ownership.tc is sourced by ftracetest under /bin/sh.
The script currently declares mount_point with local at file scope, which makes /bin/sh abort with "local: not in a function" before the test can reach the eventfs ownership checks.
Replace the top-level local declaration with a normal shell variable so kernels that support the gid= tracefs mount option can run the test at all.
--- tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc +1 -1
@@ -6,7 +6,7 @@ original_group=`stat -c "%g" .` original_owner=`stat -c "%u" .` -local mount_point=$(get_mount_point) +mount_point=$(get_mount_point) mount_options=$(get_mnt_options "$mount_point")
Greg Kroah-Hartman
maintainerPATCH 1391/1611 cpu: hotplug: Preserve per instance callback errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
commit 673db10729fb121ea1b16fe57791a0cb9eac1eb5 upstream.
cpuhp_invoke_callback() unwinds earlier callbacks for the same hotplug state when one instance fails. The rollback path currently reuses ret, so a successful rollback can hide the original error and make the failed transition look successful.
Keep the rollback result separate from the original error.
--- kernel/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/cpu.c +4 -4
@@ -175,7 +175,7 @@ static int cpuhp_invoke_callback(unsignestruct cpuhp_step *step =cpuhp_get_step (state);int (*cbm)(unsigned int cpu,struct hlist_node *node);int (*cb)(unsigned int cpu); -int ret, cnt; +int ret, cnt, rollback_ret;if (st->fail == state) { st->fail =CPUHP_INVALID ;
@@ -239,12 +239,12 @@ err:break ;trace_cpuhp_multi_enter (cpu, st->target, state, cbm, node); - ret =cbm (cpu, node); -trace_cpuhp_exit (cpu, st->state, state, ret); + rollback_ret =cbm (cpu, node); +trace_cpuhp_exit (cpu, st->state, state, rollback_ret);/* * Rollback must not fail, */ -WARN_ON_ONCE (ret); +WARN_ON_ONCE (rollback_ret); }return ret; }
Greg Kroah-Hartman
maintainerPATCH 1392/1611 cpu: hotplug: Bound hotplug states sysfs output
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
commit 86f436567f2516a0083b210bedc933544826a2c3 upstream.
states_show() adds CPU hotplug state names into a single sysfs buffer using sprintf(). With enough registered states, this can write past the end of the PAGE_SIZE buffer.
Use sysfs_emit_at() so output is bounded.
--- kernel/cpu.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
kernel/cpu.c +4 -8
@@ -2865,21 +2865,17 @@ static const struct attribute_group cpuh .name = "hotplug", }; -static ssize_t states_show (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t states_show (struct device *dev,struct device_attribute *attr,char *buf) { -ssize_t cur, res =0 ; +ssize_t res =0 ;int i;mutex_lock (&cpuhp_state_mutex);for (i =CPUHP_OFFLINE ; i <=CPUHP_ONLINE ; i++) {struct cpuhp_step *sp =cpuhp_get_step (i); -if (sp->name) { - cur =sprintf (buf,"%3d: %s\n" , i, sp->name); - buf += cur; - res += cur; - } +if (sp->name) + res +=sysfs_emit_at (buf, res,"%3d: %s\n" , i, sp->name); }mutex_unlock (&cpuhp_state_mutex);return res;
Greg Kroah-Hartman
maintainerPATCH 1393/1611 gpio: mt7621: more robust management of IRQ domain teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergio Paracuellos <[email protected]>
commit 839738536adabae1a7e98ed3fc332ce9cc991d27 upstream.
The driver uses devm_gpiochip_add_data() to register the GPIO chips which means the devres subsystem will unregister them only after the function 'mt7621_gpio_remove()' returns. During the window between domain destruction and devres unregistering the GPIO chips, the chips are still fully active. If a consumer or userspace invokes gpiod_to_irq() during this window, 'mt7621_gpio_to_irq()' can dereference the already-freed irq domain pointer. Thus, manage the IRQ domain teardown using 'devm_add_action_or_reset()' to guarantee it is destroyed strictly after the GPIO chips are removed.
--- drivers/gpio/gpio-mt7621.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpio/gpio-mt7621.c +7 -8
@@ -270,9 +270,9 @@ static const struct irq_chip mt7621_irq_ };static void -mt7621_gpio_remove (struct platform_device *pdev) +mt7621_gpio_remove (void *data) { -struct mtk *priv =platform_get_drvdata (pdev); +struct mtk *priv = data;int offset, virq;if (priv->gpio_irq >0 )
@@ -473,14 +473,14 @@ mediatek_gpio_probe(struct platform_deviif (mtk->gpio_irq >0 ) { ret =mt7621_gpio_irq_setup (pdev, mtk);if (ret) - goto fail; +return ret; } -return 0 ; + ret =devm_add_action_or_reset (dev, mt7621_gpio_remove, mtk); +if (ret) +return ret; -fail: -mt7621_gpio_remove (pdev); -return ret; +return 0 ; }static const struct of_device_id mediatek_gpio_match[] = {
@@ -491,7 +491,6 @@ MODULE_DEVICE_TABLE(of, mediatek_gpio_mastatic struct platform_driver mediatek_gpio_driver = { .probe = mediatek_gpio_probe, - .remove = mt7621_gpio_remove, .driver = { .name ="mt7621_gpio" , .of_match_table = mediatek_gpio_match,
Greg Kroah-Hartman
maintainerPATCH 1394/1611 gpio: tegra: do not call pinctrl for GPIO direction
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit d3e91a95b2b0fc6336dbf3ec90d831a1654d2720 upstream.
tegra_gpio_direction_input() and tegra_gpio_direction_output() already program the GPIO controller direction registers directly. The additional pinctrl_gpio_direction_input/output() calls do not add a Tegra pinctrl operation, because the Tegra pinmux ops provide GPIO request/free handling but no gpio_set_direction hook.
The extra call still enters the pinctrl core and takes pctldev->mutex. Shared GPIO users can call the direction path while holding their per-line spinlock, so this otherwise redundant pinctrl direction call can sleep in an atomic context.
This was found by our static analysis tool and then confirmed by manual review of tegra_gpio_probe(), the Tegra GPIO direction callbacks and the Tegra pinctrl ops. The reviewed path has a default non-sleeping struct gpio_chip while the direction callback still enters the pinctrl mutex path.
A directed runtime validation kept the same non-sleeping chip registration and drove:
gpio_shared_proxy_direction_output()
gpiod_direction_output_raw_commit()
tegra_gpio_direction_output()
pinctrl_gpio_direction_output()
Lockdep reported a sleep-in-atomic warning with the shared GPIO spinlock held and pinctrl_get_device_gpio_range() plus tegra_gpio_direction_output() on the stack.
Do not mark the whole chip as can_sleep to paper over this: can_sleep describes whether get()/set() may sleep, and Tegra value access is MMIO. Remove the redundant pinctrl direction calls and keep pinctrl involvement in the existing request/free path.
--- drivers/gpio/gpio-tegra.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
drivers/gpio/gpio-tegra.c +2 -16
@@ -172,18 +172,11 @@ static int tegra_gpio_direction_input(st unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip); -int ret;tegra_gpio_mask_write (tgi,GPIO_MSK_OE (tgi, offset), offset,0 );tegra_gpio_enable (tgi, offset); - ret =pinctrl_gpio_direction_input (chip, offset); -if (ret <0 ) -dev_err (tgi->dev, -"Failed to set pinctrl input direction of GPIO %d: %d" , - chip->base + offset, ret); - -return ret; +return 0 ; } static int tegra_gpio_direction_output(struct gpio_chip *chip,
@@ -191,19 +184,12 @@ static int tegra_gpio_direction_output(s int value) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip); -int ret;tegra_gpio_set (chip, offset, value);tegra_gpio_mask_write (tgi,GPIO_MSK_OE (tgi, offset), offset,1 );tegra_gpio_enable (tgi, offset); - ret =pinctrl_gpio_direction_output (chip, offset); -if (ret <0 ) -dev_err (tgi->dev, -"Failed to set pinctrl output direction of GPIO %d: %d" , - chip->base + offset, ret); - -return ret; +return 0 ; } static int tegra_gpio_get_direction(struct gpio_chip *chip,
Greg Kroah-Hartman
maintainerPATCH 1395/1611 gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergio Paracuellos <[email protected]>
commit 0e024f58291dfcb28d98c512002e1a80fad69798 upstream.
Function 'mediatek_gpio_bank_probe()' registers three GPIO chips using 'devm_gpiochip_add_data()'. At this point, the chips become live and visible to consumers. However, the IRQ domain isn't allocated and set up until 'mt7621_gpio_irq_setup()' is called after the GPIO chips setup finishes. If a consumer requests a GPIO IRQ concurrently 'mt7621_gpio_to_irq()' can be called and pass a NULL irq domain pointer irq_create_mapping(), that can corrupt the mappings or cause a crash. Fix this possible problem seting up irq domain before GPIO chips setup is performed.
--- drivers/gpio/gpio-mt7621.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpio/gpio-mt7621.c +6 -6
@@ -464,12 +464,6 @@ mediatek_gpio_probe(struct platform_devi mtk->num_gpios =MTK_BANK_WIDTH *MTK_BANK_CNT ;platform_set_drvdata (pdev, mtk); -for (i =0 ; i <MTK_BANK_CNT ; i++) { - ret =mediatek_gpio_bank_probe (dev, i); -if (ret) -return ret; - } -if (mtk->gpio_irq >0 ) { ret =mt7621_gpio_irq_setup (pdev, mtk);if (ret)
@@ -480,6 +474,12 @@ mediatek_gpio_probe(struct platform_deviif (ret)return ret; +for (i =0 ; i <MTK_BANK_CNT ; i++) { + ret =mediatek_gpio_bank_probe (dev, i); +if (ret) +return ret; + } +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1396/1611 gpio-f7188x: Add support for NCT6126D version B
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Louvel <[email protected]>
commit 9a6c0b6ea12746d50cf53d59a7e05fd83f974bda upstream.
The Nuvoton NCT6126D Super-I/O is available in two hardware revisions. According to the manufacturer datasheet revision 2.4, version A reports chip ID 0xD283, while version B reports chip ID 0xD284.
The driver currently only recognizes only the version A ID. Version B only contains hardware fixes unrelated to the GPIO functionality, so it can be supported by simply adding its chip ID without any other driver changes.
--- drivers/gpio/gpio-f7188x.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpio/gpio-f7188x.c +4 -2
@@ -48,7 +48,8 @@/* * Nuvoton devices. */ -#define SIO_NCT6126D_ID 0xD283/* NCT6126D chipset ID */ +#define SIO_NCT6126D_VER_A_ID 0xD283/* NCT6126D version A chipset ID */ +#define SIO_NCT6126D_VER_B_ID 0xD284/* NCT6126D version B chipset ID */ #define SIO_LD_GPIO_NUVOTON 0x07/* GPIO logical device */
@@ -564,7 +565,8 @@ static int __init f7188x_find(int addr,case SIO_F81865_ID : sio->type = f81865;break ; -case SIO_NCT6126D_ID : +case SIO_NCT6126D_VER_A_ID : +case SIO_NCT6126D_VER_B_ID : sio->device =SIO_LD_GPIO_NUVOTON ; sio->type = nct6126d;break ;
Greg Kroah-Hartman
maintainerPATCH 1397/1611 gpio: mt7621: avoid corruption of shared interrupt trigger state
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergio Paracuellos <[email protected]>
commit 1781172526d1092323af443fa03f00e6de560401 upstream.
The bank-shared fields like 'rising' and 'falling' are modified using non-atomic read-modify-write operations. Since every gpio chip instance represents an entire bank of 32 pins, if 'mediatek_gpio_irq_type()' is called concurrently for different IRQs on the same bank a possible overwrite of each other's configuration is possible. Thus, protect this state with 'gpio_generic_lock_irqsave' lock in the same way it is handled in irp_chip 'mediatek_gpio_irq_mask()' and 'mediatek_gpio_irq_unmask()' callbacks.
--- drivers/gpio/gpio-mt7621.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-mt7621.c +2 -0
@@ -187,6 +187,8 @@ mediatek_gpio_irq_type(struct irq_data *struct mtk_gc *rg =gpiochip_get_data (gc);u32 mask =BIT (mt7621_gpio_hwirq_to_offset (d->hwirq, rg)); +guard (gpio_generic_lock_irqsave)(&rg->chip); +if (type ==IRQ_TYPE_PROBE ) {if ((rg->rising | rg->falling | rg->hlevel | rg->llevel) & mask)
Greg Kroah-Hartman
maintainerPATCH 1398/1611 gpios: palmas: add .get_direction() op
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andreas Kemnade <[email protected]>
commit db4a79713ed8e252d5e4edf6eaaa80948b6855a2 upstream.
Accessing debug/gpio is quite noisy without a get_direction() implementation. To calm that down add an implementation.
--- drivers/gpio/gpio-palmas.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/gpio/gpio-palmas.c +19 -0
@@ -116,6 +116,24 @@ static int palmas_gpio_input(struct gpioreturn ret; } +static int palmas_gpio_get_direction (struct gpio_chip *gc,unsigned int offset) +{ +struct palmas_gpio *pg =gpiochip_get_data (gc); +struct palmas *palmas = pg->palmas; +unsigned int val; +unsigned int reg; +int ret; +int gpio16 = (offset/8 ); + + offset %=8 ; + reg = (gpio16) ?PALMAS_GPIO_DATA_DIR2 :PALMAS_GPIO_DATA_DIR ; + ret =palmas_read (palmas,PALMAS_GPIO_BASE , reg, &val); +if (ret) +return ret; + +return (val &BIT (offset)) ?GPIO_LINE_DIRECTION_OUT :GPIO_LINE_DIRECTION_IN ; +} +static int palmas_gpio_to_irq (struct gpio_chip *gc,unsigned offset) {struct palmas_gpio *pg =gpiochip_get_data (gc);
@@ -165,6 +183,7 @@ static int palmas_gpio_probe(struct plat palmas_gpio->gpio_chip.can_sleep = true; palmas_gpio->gpio_chip.direction_input = palmas_gpio_input; palmas_gpio->gpio_chip.direction_output = palmas_gpio_output; + palmas_gpio->gpio_chip.get_direction = palmas_gpio_get_direction; palmas_gpio->gpio_chip.to_irq = palmas_gpio_to_irq; palmas_gpio->gpio_chip.set = palmas_gpio_set; palmas_gpio->gpio_chip.get = palmas_gpio_get;
Greg Kroah-Hartman
maintainerPATCH 1399/1611 net: sit: require CAP_NET_ADMIN in the device netns for changelink
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 27ccb68e7cccead5d8c611665a45d23032d468b3 upstream.
ipip6_changelink() operates on at most two netns, dev_net(dev) and the tunnel link netns t->net. They differ once the device is created in or moved to a netns other than the one the request runs in. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in t->net can rewrite a tunnel that lives in t->net.
Gate ipip6_changelink() on rtnl_dev_link_net_capable() at its top, before any attribute is parsed. sit was the one tunnel type not covered by the recent series that added this check to the other changelink() handlers.
--- net/ipv6/sit.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/sit.c +3 -0
@@ -1610,6 +1610,9 @@ static int ipip6_changelink(struct net_d__u32 fwmark = t->fwmark;int err; +if (!rtnl_dev_link_net_capable (dev, net)) +return -EPERM ; +if (dev == sitn->fb_tunnel_dev)return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 1400/1611 net: ethernet: ti: icssg: guard PA stat lookups
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Philippe Schenker <[email protected]>
commit 27b9daba50609335db6ca81e4cccf50ded21ec76 upstream.
icssg_ndo_get_stats64() unconditionally calls emac_get_stat_by_name() with FW PA stat names regardless of whether the PA stats block is present on the hardware. emac_get_stat_by_name() already guards the PA stats lookup with if (emac->prueth->pa_stats); when that pointer is NULL the lookup falls through to netdev_err() and returns -EINVAL. Because ndo_get_stats64 is polled regularly by the networking stack this produces thousands of log entries of the form:
icssg-prueth icssg1-eth end0: Invalid stats FW_RX_ERROR
A secondary consequence is that the int(-EINVAL) return value is implicitly widened to a near-ULLONG_MAX unsigned value when accumulated into the __u64 fields of rtnl_link_stats64, silently corrupting the rx_errors, rx_dropped and tx_dropped counters reported by ip -s link.
Every other PA-aware code path in the driver is already guarded with the same if (emac->prueth->pa_stats) check. Apply the same guard here.
--- drivers/net/ethernet/ti/icssg/icssg_common.c | 49 +++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-)
drivers/net/ethernet/ti/icssg/icssg_common.c +28 -21
@@ -1315,28 +1315,35 @@ void icssg_ndo_get_stats64(struct net_de stats->rx_over_errors =emac_get_stat_by_name (emac,"rx_over_errors" ); stats->multicast =emac_get_stat_by_name (emac,"rx_multicast_frames" ); - stats->rx_errors = ndev->stats.rx_errors + -emac_get_stat_by_name (emac,"FW_RX_ERROR" ) + -emac_get_stat_by_name (emac,"FW_RX_EOF_SHORT_FRMERR" ) + -emac_get_stat_by_name (emac,"FW_RX_B0_DROP_EARLY_EOF" ) + -emac_get_stat_by_name (emac,"FW_RX_EXP_FRAG_Q_DROP" ) + -emac_get_stat_by_name (emac,"FW_RX_FIFO_OVERRUN" ); - stats->rx_dropped = ndev->stats.rx_dropped + -emac_get_stat_by_name (emac,"FW_DROPPED_PKT" ) + -emac_get_stat_by_name (emac,"FW_INF_PORT_DISABLED" ) + -emac_get_stat_by_name (emac,"FW_INF_SAV" ) + -emac_get_stat_by_name (emac,"FW_INF_SA_DL" ) + -emac_get_stat_by_name (emac,"FW_INF_PORT_BLOCKED" ) + -emac_get_stat_by_name (emac,"FW_INF_DROP_TAGGED" ) + -emac_get_stat_by_name (emac,"FW_INF_DROP_PRIOTAGGED" ) + -emac_get_stat_by_name (emac,"FW_INF_DROP_NOTAG" ) + -emac_get_stat_by_name (emac,"FW_INF_DROP_NOTMEMBER" ); + stats->rx_errors = ndev->stats.rx_errors; + stats->rx_dropped = ndev->stats.rx_dropped; stats->tx_errors = ndev->stats.tx_errors; - stats->tx_dropped = ndev->stats.tx_dropped + -emac_get_stat_by_name (emac,"FW_RTU_PKT_DROP" ) + -emac_get_stat_by_name (emac,"FW_TX_DROPPED_PACKET" ) + -emac_get_stat_by_name (emac,"FW_TX_TS_DROPPED_PACKET" ) + -emac_get_stat_by_name (emac,"FW_TX_JUMBO_FRM_CUTOFF" ); + stats->tx_dropped = ndev->stats.tx_dropped; + +if (!emac->prueth->pa_stats) +return ; + + stats->rx_errors += +emac_get_stat_by_name (emac,"FW_RX_ERROR" ) + +emac_get_stat_by_name (emac,"FW_RX_EOF_SHORT_FRMERR" ) + +emac_get_stat_by_name (emac,"FW_RX_B0_DROP_EARLY_EOF" ) + +emac_get_stat_by_name (emac,"FW_RX_EXP_FRAG_Q_DROP" ) + +emac_get_stat_by_name (emac,"FW_RX_FIFO_OVERRUN" ); + stats->rx_dropped += +emac_get_stat_by_name (emac,"FW_DROPPED_PKT" ) + +emac_get_stat_by_name (emac,"FW_INF_PORT_DISABLED" ) + +emac_get_stat_by_name (emac,"FW_INF_SAV" ) + +emac_get_stat_by_name (emac,"FW_INF_SA_DL" ) + +emac_get_stat_by_name (emac,"FW_INF_PORT_BLOCKED" ) + +emac_get_stat_by_name (emac,"FW_INF_DROP_TAGGED" ) + +emac_get_stat_by_name (emac,"FW_INF_DROP_PRIOTAGGED" ) + +emac_get_stat_by_name (emac,"FW_INF_DROP_NOTAG" ) + +emac_get_stat_by_name (emac,"FW_INF_DROP_NOTMEMBER" ); + stats->tx_dropped += +emac_get_stat_by_name (emac,"FW_RTU_PKT_DROP" ) + +emac_get_stat_by_name (emac,"FW_TX_DROPPED_PACKET" ) + +emac_get_stat_by_name (emac,"FW_TX_TS_DROPPED_PACKET" ) + +emac_get_stat_by_name (emac,"FW_TX_JUMBO_FRM_CUTOFF" ); }EXPORT_SYMBOL_GPL (icssg_ndo_get_stats64);
Greg Kroah-Hartman
maintainerPATCH 1401/1611 net: wwan: t7xx: destroy DMA pool on CLDMA late init failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 2bd6f26d4ce1e87de4d736b1e8896daf3acf1c0e upstream.
t7xx_cldma_late_init() creates md_ctrl->gpd_dmapool before initializing the TX and RX rings. If any ring initialization fails, the error path frees the already initialized rings but leaves the DMA pool allocated.
Destroy md_ctrl->gpd_dmapool on the late-init failure path to avoid leaking the DMA pool.
--- drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +3 -0
@@ -1066,6 +1066,9 @@ err_free_tx_ring:while (i--)t7xx_cldma_ring_free (md_ctrl, &md_ctrl->tx_ring[i],DMA_TO_DEVICE ); +dma_pool_destroy (md_ctrl->gpd_dmapool); + md_ctrl->gpd_dmapool =NULL ; +return ret; }
Greg Kroah-Hartman
maintainerPATCH 1402/1611 net: ixp4xx_hss: fix duplicate HDLC netdev allocation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit db818b0e8af7bac16860116a19c341a63d6677b4 upstream.
ixp4xx_hss_probe() allocates two HDLC netdevs. The first one is stored in ndev, initialized, and registered with register_hdlc_device(). The second one is stored in port->netdev and later used by the remove path for unregister_hdlc_device() and free_netdev().
This means that the registered netdev is not the same object that is unregistered and freed on remove. It also leaks the first allocation if the second alloc_hdlcdev() call fails, and the first allocation is not checked before ndev is used.
Older code allocated the HDLC netdev only once and stored the same object in both the local variable and port->netdev. The buggy conversion split this into two alloc_hdlcdev() calls. A later rename changed the local variable name to ndev, but the underlying mismatch remained.
Fix this by allocating the HDLC netdev only once and assigning the same object to port->netdev.
--- drivers/net/wan/ixp4xx_hss.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wan/ixp4xx_hss.c +2 -2
@@ -1487,11 +1487,11 @@ static int ixp4xx_hss_probe(struct platf "unable to get CLK internal GPIO\n"); ndev =alloc_hdlcdev (port); - port->netdev =alloc_hdlcdev (port); -if (!port->netdev) { +if (!ndev) { err = -ENOMEM ; goto err_plat; } + port->netdev = ndev;SET_NETDEV_DEV (ndev, &pdev->dev); hdlc =dev_to_hdlc (ndev);
Greg Kroah-Hartman
maintainerPATCH 1403/1611 net/sched: act_ct: preserve tc_skb_cb across defragmentation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit 9092e15defbe6c7bc241c306093ca9d358a578e7 upstream.
tcf_ct_handle_fragments() calls nf_ct_handle_fragments() without saving and restoring skb->cb. The defrag helper clears IPCB/IP6CB, which aliases the tc_skb_cb/qdisc_skb_cb control buffer. Fragmented traffic through act_ct therefore loses qdisc metadata such as pkt_segs and can trigger WARN_ON_ONCE() in qdisc_pkt_segs() when panic_on_warn is enabled.
Save and restore the full tc_skb_cb around nf_ct_handle_fragments(), matching the pattern used by ovs_ct_handle_fragments().
--- net/sched/act_ct.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/sched/act_ct.c +4 -3
@@ -842,11 +842,11 @@ static int tcf_ct_handle_fragments(struc u8 family, u16 zone, bool *defrag) { enum ip_conntrack_info ctinfo; +struct tc_skb_cb cb;struct nf_conn *ct;int err =0 ;bool frag;u8 proto; -u16 mru;/* Previously seen (loopback)? Ignore. */ ct =nf_ct_get (skb, &ctinfo);
@@ -860,12 +860,13 @@ static int tcf_ct_handle_fragments(strucif (err || !frag)return err; - err =nf_ct_handle_fragments (net, skb, zone, family, &proto, &mru); + cb = *tc_skb_cb (skb); + err =nf_ct_handle_fragments (net, skb, zone, family, &proto, &cb.mru);if (err)return err; *defrag = true; -tc_skb_cb (skb)->mru = mru; + *tc_skb_cb (skb) = cb;return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1404/1611 selftests: net: fix file owner for broadcast_ether_dst test
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ross Porter <[email protected]>
commit b8613e9792002add3bf77122868cc06ce142e953 upstream.
Ensure the output file is always owned by root (even if tcpdump was compiled with --with-user), by passing the -Z root argument when invoking it.
--- tools/testing/selftests/net/broadcast_ether_dst.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/broadcast_ether_dst.sh +1 -1
@@ -44,7 +44,7 @@ test_broadcast_ether_dst() { # tcpdump will exit after receiving a single packet # timeout will kill tcpdump if it is still running after 2s timeout 2s ip netns exec "${CLIENT_NS}" \ - tcpdump -i link0 -c 1 -w "${CAPFILE}" icmp &> "${OUTPUT}" & + tcpdump -i link0 -c 1 -w "${CAPFILE}" -Z root icmp &> "${OUTPUT}" & pid=$! slowwait 1 grep -qs "listening" "${OUTPUT}"