6.6.163-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 1627/3318 hwmon: (tmp102) Fix jiffies wraparound in conversion-ready check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Verdonck <[email protected]>
[ Upstream commit 56c1d32323e773b8b927316f8beeae9238576335 ]
tmp102 records a one-shot deadline in ->ready_time at probe (and resume) and, on every temperature read, refuses the read with -EAGAIN while time_before(jiffies, ready_time) is true, in order to skip the first ~35 ms conversion.
->ready_time is an unsigned long compared with time_before(), whose signed difference is only meaningful while the two values are within LONG_MAX jiffies of each other. Because ->ready_time is set once and never refreshed, jiffies keeps advancing away from it, and after 2^31 jiffies the difference flips sign. On a 32-bit HZ=100 kernel that happens ~248.5 days after boot: time_before() then permanently reports "not ready" and the driver returns -EAGAIN on every read, without ever touching the sensor, until the next reboot.
Store the deadline as a 64-bit jiffies value and compare it with get_jiffies_64()/time_before64(), which does not wrap in any practical uptime.
--- drivers/hwmon/tmp102.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/tmp102.c +4 -4
@@ -54,7 +54,7 @@struct tmp102 {struct regmap *regmap;u16 config_orig; -unsigned long ready_time; +u64 ready_time; };/* convert left adjusted 13-bit TMP102 register value to milliCelsius */
@@ -79,7 +79,7 @@ static int tmp102_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input:/* Is it too early to return a conversion ? */ -if (time_before (jiffies, tmp102->ready_time)) { +if (time_before64 (get_jiffies_64 (), tmp102->ready_time)) {dev_dbg (dev,"%s: Conversion not ready yet..\n" , __func__);return -EAGAIN ; }
@@ -245,7 +245,7 @@ static int tmp102_probe(struct i2c_client *client)* Mark that we are not ready with data until the first * conversion is complete */ - tmp102->ready_time = jiffies +msecs_to_jiffies (CONVERSION_TIME_MS ); + tmp102->ready_time =get_jiffies_64 () +msecs_to_jiffies (CONVERSION_TIME_MS ); hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, tmp102,
@@ -278,7 +278,7 @@ static int tmp102_resume(struct device *dev) err =regmap_update_bits (tmp102->regmap,TMP102_CONF_REG ,TMP102_CONF_SD ,0 ); - tmp102->ready_time = jiffies +msecs_to_jiffies (CONVERSION_TIME_MS ); + tmp102->ready_time =get_jiffies_64 () +msecs_to_jiffies (CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1628/3318 gfs2: reject invalid inode sizes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiaming Zhang <[email protected]>
[ Upstream commit 33ed0a0567e0abe66ea65e89dad2e35082890fbe ]
A corrupted GFS2 image can store a dinode size that is larger than what VFS i_size can represent. gfs2_dinode_in() reads the on-disk di_size as a u64 and writes it directly into inode->i_size. If the value is larger than S64_MAX, the incore i_size becomes negative. That negative value can bypass the existing stuffed inode size check:
inode->i_size > gfs2_max_stuffed_size(ip)
Later, gfs2_quotad may try to sync the quota file and unstuff the quota inode. gfs2_unstuffer_folio() reads the negative i_size into an unsigned length and passes it to memcpy(), turning it into a huge copy size and triggering a out-of-bound issue.
Reject dinodes whose size exceeds sb->s_maxbytes before storing the value in inode->i_size. Also make the stuffed inode check use the raw on-disk size while it is still unsigned.
--- fs/gfs2/glops.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/gfs2/glops.c +8 -2
@@ -412,6 +412,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)umode_t mode =be32_to_cpu (str->di_mode);struct inode *inode = &ip->i_inode;bool is_new = inode->i_state &I_NEW ; +u64 size;if (unlikely (ip->i_no_addr !=be64_to_cpu (str->di_num.no_addr))) {gfs2_consist_inode (ip);
@@ -437,7 +438,12 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)i_uid_write (inode,be32_to_cpu (str->di_uid));i_gid_write (inode,be32_to_cpu (str->di_gid));set_nlink (inode,be32_to_cpu (str->di_nlink)); -i_size_write (inode,be64_to_cpu (str->di_size)); + size =be64_to_cpu (str->di_size); +if (unlikely (size > inode->i_sb->s_maxbytes)) { +gfs2_consist_inode (ip); +return -EIO ; + } +i_size_write (inode, size);gfs2_set_inode_blocks (inode,be64_to_cpu (str->di_blocks)); atime.tv_sec =be64_to_cpu (str->di_atime); atime.tv_nsec =be32_to_cpu (str->di_atime_nsec);
@@ -475,7 +481,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) ip->i_depth = (u8 )depth; ip->i_entries =be32_to_cpu (str->di_entries); -if (gfs2_is_stuffed (ip) && inode->i_size >gfs2_max_stuffed_size (ip)) { +if (gfs2_is_stuffed (ip) && size >gfs2_max_stuffed_size (ip)) {gfs2_consist_inode (ip);return -EIO ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1629/3318 m68k: Fix task info flags handling for 68000
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Palmer <[email protected]>
[ Upstream commit 2c6805145e1605cef39459f78979f7edee251b41 ]
The logic for deciding what to do after a syscall should be checking if any of the lower byte bits are set and then checking if the reschedule bit is set.
Currently we are loading the top word, checking if any bits are set (which never seems to be true) and thus jumping over loading the whole long and checking if the reschedule bit is set.
We get the thread info in two places so split that logic out in a macro and then fix the code so that it loads the byte of the flags we need to check, checks if anything is set and then checks if the reschedule bit in particular is set.
Stable-dep-of: 48859f8018d9 ("m68k: Fix seccomp filtering on ColdFire and 68000")
--- arch/m68k/68000/entry.S | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
arch/m68k/68000/entry.S +13 -8
@@ -21,6 +21,13 @@ .text +/* get thread_info pointer into a2 */ + .macro getthreadinfo + movel %sp,%d1 + andl #-THREAD_SIZE,%d1 + movel %d1,%a2 + .endm + .globl system_call .globl resume .globl ret_from_exception
@@ -73,9 +80,8 @@ ENTRY(system_call) movel %sp@(PT_OFF_ORIG_D0),%d0 - movel %sp,%d1 /* get thread_info pointer */ - andl #-THREAD_SIZE,%d1 - movel %d1,%a2 + /* Doing a trace ? */ + getthreadinfo btst #(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) jne do_trace cmpl #NR_syscalls,%d0
@@ -99,16 +105,15 @@ Luser_return: /* heavy interrupt load*/ andw #ALLOWINT,%sr - movel %sp,%d1 /* get thread_info pointer */ - andl #-THREAD_SIZE,%d1 - movel %d1,%a2 + getthreadinfo 1: - move %a2@(TINFO_FLAGS),%d1 /* thread_info->flags */ + /* check if any of the flags are set */ + moveb %a2@(TINFO_FLAGS + 3),%d1 /* thread_info->flags (low 8 bits) */ jne Lwork_to_do RESTORE_ALL Lwork_to_do: - movel %a2@(TINFO_FLAGS),%d1 /* thread_info->flags */ + /* check if reschedule needs to be called */ btst #TIF_NEED_RESCHED,%d1 jne reschedule
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1630/3318 m68k: Fix seccomp filtering on ColdFire and 68000
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christopher Lusk <[email protected]>
[ Upstream commit 48859f8018d93bd93ef35f7430fdf5b97f2f9715 ]
m68k selects HAVE_ARCH_SECCOMP_FILTER for all configurations, but the ColdFire and 68000 syscall entry paths only branch to syscall_trace_enter() for TIF_SYSCALL_TRACE. TIF_SECCOMP alone falls through to syscall dispatch, leaving installed filters ineffective.
Test the combined TIF_SYSCALL_TRACE and TIF_SECCOMP mask in both paths and route either flag through the existing slow path. Leave the classic MMU syscall entry implementation unchanged.
Validated the combined test under QEMU mcf5208evb (ColdFire): filters denying getpid, openat, unlinkat, and reboot each returned -EPERM. A classic-MMU control (q800) denied the filtered getpid syscall both before and after this change. The 68000 path shares the same source-level omission and receives the identical masked test but was not separately emulated. Compile-tested W=1 with CONFIG_SECCOMP_FILTER=y on both m5208evb_defconfig and a custom no-MMU UCSIMM configuration; the latter built arch/m68k/68000/entry.o and vmlinux.
--- arch/m68k/68000/entry.S | 3 ++- arch/m68k/coldfire/entry.S | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/m68k/68000/entry.S +2 -1
@@ -82,7 +82,8 @@ ENTRY(system_call) /* Doing a trace ? */ getthreadinfo - btst #(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) + moveb %a2@(TINFO_FLAGS+2),%d1 + andl #((_TIF_SYSCALL_TRACE + _TIF_SECCOMP) >> 8),%d1 jne do_trace cmpl #NR_syscalls,%d0 jcc badsys
arch/m68k/coldfire/entry.S +2 -1
@@ -75,7 +75,8 @@ ENTRY(system_call) movel %d2,%a0 movel %a0@,%a1 /* save top of frame */ movel %sp,%a1@(TASK_THREAD+THREAD_ESP0) - btst #(TIF_SYSCALL_TRACE%8),%a0@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) + moveb %a0@(TINFO_FLAGS+2),%d2 + andl #((_TIF_SYSCALL_TRACE + _TIF_SECCOMP) >> 8),%d2 bnes 1f movel %d3,%a0
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1631/3318 powerpc/pseries/iommu: Add TCEs for 16GB pages when RAM is pre-mapped
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gaurav Batra <[email protected]>
[ Upstream commit 0b8b0c17a8998709ecb2852d56442ea981102941 ]
In powerPC, if Dynamic DMA Window is big enough, RAM is pre-mapped. To determine the size of RAM, a PAPR+ property "ibm,lrdr-capacity" is used. This OF property dictates what is the max size of RAM an LPAR can have, including DR added memory.
In PowerPC, 16GB pages can be allocated at machine level and then assigned to LPARs. These 16GB pages are added to LPAR memory at the time of boot. The address range for these 16GB pages is above MAX RAM an LPAR can have (ibm,lrdr-capacity). In the current implementation, these 16GB pages are being excluded from pre-mapped TCEs. A driver can have DMA buffers allocated from 16GB pages. This results in platform to raise an EEH when DMA is attempted on buffers in 16GB memory range.
commit 6aa989ab2bd0 ("powerpc/pseries/iommu: memory notifier incorrectly adds TCEs for pmemory")
Prior to the above patch, memblock_end_of_DRAM() was being used to determine the MAX memory of an LPAR. This included 16GB pages as well. The issue with using memblock_end_of_DRAM() is that when pmemory is converted to RAM via daxctl command, the DDW engine will incorrectly try to add TCEs for pmemory as well.
Below is the address distribution of RAM, 16GB pages and pmemory for an LPAR with max memory of 256GB, memory allocated 64GB, 2 16GB pages and assigned pmemory of 8GB.
RANGE SIZE STATE REMOVABLE BLOCK
0x0000000000000000-0x0000000fffffffff 64G online yes 0-255 0x0000004000000000-0x00000047ffffffff 32G online yes 1024-1151
cat /sys/bus/nd/devices/region0/resource0x40100000000
cat /sys/bus/nd/devices/region0/size
8589934592
The approach to fix this problem is to revert back the code changes introduced by the above patch and to stash away the MAX memory of an LPAR, including 16GB pages, at the LPAR boot time. This value is then used whenever TCEs are needed to be pre-mapped - enable_DDW() or, iommu_mem_notifier()
--- arch/powerpc/platforms/pseries/iommu.c | 62 ++++++++++++++++++-------- 1 file changed, 43 insertions(+), 19 deletions(-)
arch/powerpc/platforms/pseries/iommu.c +43 -19
@@ -120,6 +120,8 @@ static struct iommu_table *iommu_pseries_alloc_table(int node)return tbl; } +static phys_addr_t pseries_ddw_max_ram__ro_after_init ; +#ifdef CONFIG_IOMMU_API static struct iommu_table_group_ops spapr_tce_table_group_ops;#endif
@@ -1239,15 +1241,19 @@ struct failed_ddw_pdn {static LIST_HEAD (failed_ddw_pdn_list); -static phys_addr_t ddw_memory_hotplug_max (void ) +static phys_addr_t __init ddw_memory_hotplug_max (void ) { -resource_size_t max_addr; +resource_size_t max_addr =memory_hotplug_max (); +struct device_node *memory; -#if defined(CONFIG_NUMA ) && defined(CONFIG_MEMORY_HOTPLUG ) - max_addr =hot_add_drconf_memory_max (); -#else - max_addr =memblock_end_of_DRAM (); -#endif +for_each_node_by_type (memory,"memory" ) { +struct resource res; + +if (of_address_to_resource (memory,0 , &res)) +continue ; + + max_addr =max_t (resource_size_t, max_addr, res.end +1 ); + }return max_addr; }
@@ -1354,7 +1360,7 @@ static struct property *ddw_property_create(const char *propname, u32 liobn, u64static bool enable_ddw (struct pci_dev *dev,struct device_node *pdn) {int len =0 , ret; -int max_ram_len =order_base_2 (ddw_memory_hotplug_max ()); +int max_ram_len =order_base_2 (pseries_ddw_max_ram);struct ddw_query_response query;struct ddw_create_response create;int page_shift;
@@ -1525,7 +1531,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) window->direct = true;/* DDW maps the whole partition, so enable direct DMA mapping */ - ret =walk_system_ram_range (0 ,ddw_memory_hotplug_max () >>PAGE_SHIFT , + ret =walk_system_ram_range (0 , pseries_ddw_max_ram >>PAGE_SHIFT , win64->value, tce_setrange_multi_pSeriesLP_walk);if (ret) { dev_info(&dev->dev, "failed to map DMA window for %pOF: %d\n",
@@ -1620,7 +1626,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn)* memory and need to set the DMA limit. */ if (pmem_present && direct_mapping && len == max_ram_len) - dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + (1ULL << len); + dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + pseries_ddw_max_ram;return direct_mapping; }
@@ -1804,23 +1810,35 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action, {struct dma_win *window;struct memory_notify *arg = data; +unsigned long limit = arg->nr_pages; +unsigned long max_ram_pages = pseries_ddw_max_ram >>PAGE_SHIFT ;int ret =0 ;/* This notifier can get called when onlining persistent memory as well. * TCEs are not pre-mapped for persistent memory. Persistent memory will -* always be above ddw_memory_hotplug_max() +* always be above pseries_ddw_max_ram */ +if (arg->start_pfn >= max_ram_pages) +return NOTIFY_OK ; + +/* RAM is being DLPAR'ed. The range should never exceed max ram. +* Just in case, clamp the range and throw a warning. +*/ +if (arg->start_pfn + limit > max_ram_pages) { + limit = max_ram_pages - arg->start_pfn; +WARN_ONCE (1 ,"Limiting Page Range %lx - %lx to Max Mem Pages: %lx\n" , + arg->start_pfn, arg->start_pfn + arg->nr_pages, + max_ram_pages); + }switch (action) {case MEM_GOING_ONLINE :spin_lock (&dma_win_list_lock);list_for_each_entry (window, &dma_win_list, list) { -if (window->direct && (arg->start_pfn <<PAGE_SHIFT ) < -ddw_memory_hotplug_max ()) { +if (window->direct) { ret |=tce_setrange_multi_pSeriesLP (arg->start_pfn, - arg->nr_pages, window->prop); + limit, window->prop); } -/* XXX log error */ }spin_unlock (&dma_win_list_lock);break ;
@@ -1828,12 +1846,10 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,case MEM_OFFLINE :spin_lock (&dma_win_list_lock);list_for_each_entry (window, &dma_win_list, list) { -if (window->direct && (arg->start_pfn <<PAGE_SHIFT ) < -ddw_memory_hotplug_max ()) { +if (window->direct) { ret |=tce_clearrange_multi_pSeriesLP (arg->start_pfn, - arg->nr_pages, window->prop); + limit, window->prop); } -/* XXX log error */ }spin_unlock (&dma_win_list_lock);break ;
@@ -1917,6 +1933,14 @@ void __init iommu_init_early_pSeries(void)register_memory_notifier (&iommu_mem_nb);set_pci_dma_ops (&dma_iommu_ops); + +/* During init determine the max memory an LPAR can have and set it. This +* will be used for pre-mapping RAM in DDW. memblock_end_of_DRAM() can +* change during the running of LPAR - daxctl can add pmemory as +* "system-ram". This memory range should not be pre-mapped in DDW since +* the address of pmemory can be much higher than the DDW size. +*/ + pseries_ddw_max_ram =ddw_memory_hotplug_max (); }static int __init disable_multitce (char *str)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1632/3318 media: ene_ir: Ensure teardown is done in the correct order
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit ae6cfbad7ca346b78f4cdac38438bbfaed8c18a0 ]
The timer can be re-armed from the irq, so ensure that the timers are deleted after the irq and that we only free the rc device once we are sure that the irq has been silenced.
--- drivers/media/rc/ene_ir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/ene_ir.c +2 -2
@@ -1106,15 +1106,15 @@ static void ene_remove(struct pnp_dev *pnp_dev)unsigned long flags;rc_unregister_device (dev->rdev); -del_timer_sync (&dev->tx_sim_timer);spin_lock_irqsave (&dev->hw_lock, flags);ene_rx_disable (dev);ene_rx_restore_hw_buffer (dev);spin_unlock_irqrestore (&dev->hw_lock, flags); -rc_free_device (dev->rdev);free_irq (dev->irq, dev); +timer_delete_sync (&dev->tx_sim_timer);release_region (dev->hw_io,ENE_IO_SIZE ); +rc_free_device (dev->rdev);kfree (dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1633/3318 f2fs: fix to check continuousness in f2fs_sync_meta_pages() correctly
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit 1383cff4ccf3c8833c6255edffa29eb67c6419bb ]
In f2fs_sync_meta_pages(), whenever i becomes zero inside while loop, below check may be skipped, it failed to check the continuousness:
if (nr_to_write != LONG_MAX && i != 0 &&
folio->index != prev +
folio_nr_pages(fbatch.folios[i-1])) {--- fs/f2fs/checkpoint.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/f2fs/checkpoint.c +4 -5
@@ -406,7 +406,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, long nr_to_write, enum iostat_type io_type) { struct address_space *mapping = META_MAPPING(sbi); -pgoff_t index =0 , prev =ULONG_MAX ; +pgoff_t index =0 , next =ULONG_MAX ;struct folio_batch fbatch;long nwritten =0 ;int nr_folios;
@@ -427,9 +427,8 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,for (i =0 ; i < nr_folios; i++) {struct folio *folio = fbatch.folios[i]; -if (nr_to_write !=LONG_MAX && i !=0 && - folio->index != prev + -folio_nr_pages (fbatch.folios[i-1 ])) { +if (nr_to_write !=LONG_MAX && next !=ULONG_MAX && + folio->index != next) {folio_batch_release (&fbatch); goto stop; }
@@ -458,7 +457,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,break ; } nwritten +=folio_nr_pages (folio); - prev = folio->index; + next = folio->index +folio_nr_pages (folio);if (unlikely (nwritten >= nr_to_write))break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1634/3318 iio: light: ltr501: Power down chip if request irq fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 8a9bcd587d7d768e6c8e9fff88bb89645e412731 ]
In case devm_request_threaded_irq() failed, we were leaving the chip powered instead of powering it down again. Power down the chip switching ALS and PS modes to standby.
--- drivers/iio/light/ltr501.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/ltr501.c +1 -1
@@ -1557,7 +1557,7 @@ static int ltr501_probe(struct i2c_client *client)if (ret) {dev_err (&client->dev,"request irq (%d) failed\n" , client->irq); -return ret; + goto powerdown_on_error; } }else { indio_dev->info = data->chip_info->info_no_irq;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1635/3318 media: redrat3: Error path leaves device in transmitting state
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 8024d5e84531d828535365718278f1cf0ce67db0 ]
In the allocation failure error path, the transmitting boolean is not cleared. If this error path is followed the transmitter cannot be used again until the device is replugged or the module reloaded.
Fix the error path by moving the assignment statement.
Remove the check for the transmitting state in transmit, since rc-core ensures there is never a reentrant call to the driver transmit function; the transmit function is always called with dev->lock held.
The transmitting boolean is only used for interpretting firmware errors.
--- drivers/media/rc/redrat3.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/media/rc/redrat3.c +3 -8
@@ -773,17 +773,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,u8 curlencheck =0 ;unsigned i, sendbuf_len; -if (rr3->transmitting) { -dev_warn (dev,"%s: transmitter already in use\n" , __func__); -return -EAGAIN ; - } -if (count >RR3_MAX_SIG_SIZE -RR3_TX_TRAILER_LEN )return -EINVAL ; -/* rr3 will disable rc detector on transmit */ - rr3->transmitting = true; - sample_lens =kcalloc (RR3_DRIVER_MAXLENS ,sizeof (*sample_lens),GFP_KERNEL );
@@ -796,6 +788,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, goto out; } +/* rr3 will disable rc detector on transmit */ + rr3->transmitting = true; +for (i =0 ; i < count; i++) { cur_sample_len =redrat3_us_to_len (txbuf[i]);if (cur_sample_len >0xffff ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1636/3318 drm/panel: Add new helpers for refcounted panel allocatons
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anusha Srivatsa <[email protected]>
[ Upstream commit ed9c594d495deb676825489032cee0a03ce29bf9 ]
Introduce reference counted allocations for panels to avoid use-after-free. The patch adds the macro devm_drm_bridge_alloc() to allocate a new refcounted panel. Followed the documentation for drmm_encoder_alloc() and devm_drm_dev_alloc and other similar implementations for this purpose.
Stable-dep-of: 4eeeac9d7c36 ("drm/panel: ebbg-ft8719: Set prepare_prev_first")
--- drivers/gpu/drm/drm_panel.c | 25 +++++++++++++++++++++++++ include/drm/drm_panel.h | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+)
drivers/gpu/drm/drm_panel.c +25 -0
@@ -336,6 +336,31 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np) }EXPORT_SYMBOL (of_drm_find_panel); +void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, +const struct drm_panel_funcs *funcs, +int connector_type) +{ +void *container; +struct drm_panel *panel; + +if (!funcs) { +dev_warn (dev,"Missing funcs pointer\n" ); +return ERR_PTR (-EINVAL ); + } + + container =devm_kzalloc (dev, size,GFP_KERNEL ); +if (!container) +return ERR_PTR (-ENOMEM ); + + panel = container + offset; + panel->funcs = funcs; + +drm_panel_init (panel, dev, funcs, connector_type); + +return container; +} +EXPORT_SYMBOL (__devm_drm_panel_alloc); +/** * of_drm_get_panel_orientation - look up the orientation of the panel through * the "rotation" binding from a device tree node
include/drm/drm_panel.h +22 -0
@@ -269,6 +269,28 @@ struct drm_panel {bool enabled; }; +void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, +const struct drm_panel_funcs *funcs, +int connector_type); + +/** +* devm_drm_panel_alloc - Allocate and initialize a refcounted panel. +* +* @dev: struct device of the panel device +* @type: the type of the struct which contains struct &drm_panel +* @member: the name of the &drm_panel within @type +* @funcs: callbacks for this panel +* @connector_type: the connector type (DRM_MODE_CONNECTOR_*) corresponding to +* the panel interface +* +* Returns: +* Pointer to container structure embedding the panel, ERR_PTR on failure. +*/ +#define devm_drm_panel_alloc (dev, type, member, funcs, connector_type) \ + ((type *)__devm_drm_panel_alloc(dev, sizeof(type), \ + offsetof(type, member), funcs, \ + connector_type)) +void drm_panel_init (struct drm_panel *panel,struct device *dev,const struct drm_panel_funcs *funcs,int connector_type);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1637/3318 panel/ebbg-ft8719: Use refcounted allocation in place of devm_kzalloc()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anusha Srivatsa <[email protected]>
[ Upstream commit b30a15a4e7e54b676d6c395e71daf5f286997731 ]
Move to using the new API devm_drm_panel_alloc() to allocate the panel.
Stable-dep-of: 4eeeac9d7c36 ("drm/panel: ebbg-ft8719: Set prepare_prev_first")
--- drivers/gpu/drm/panel/panel-ebbg-ft8719.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/panel/panel-ebbg-ft8719.c +5 -6
@@ -198,9 +198,11 @@ static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi)struct ebbg_ft8719 *ctx;int i, ret; - ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); -if (!ctx) -return -ENOMEM ; + ctx = devm_drm_panel_alloc(dev, struct ebbg_ft8719, panel, + &ebbg_ft8719_panel_funcs, +DRM_MODE_CONNECTOR_DSI ); +if (IS_ERR (ctx)) +return PTR_ERR (ctx);for (i =0 ; i <ARRAY_SIZE (ctx->supplies); i++) ctx->supplies[i].supply = regulator_names[i];
@@ -231,9 +233,6 @@ static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi) dsi->mode_flags =MIPI_DSI_MODE_VIDEO |MIPI_DSI_MODE_VIDEO_BURST |MIPI_DSI_CLOCK_NON_CONTINUOUS ; -drm_panel_init (&ctx->panel, dev, &ebbg_ft8719_panel_funcs, -DRM_MODE_CONNECTOR_DSI ); - ret =drm_panel_of_backlight (&ctx->panel);if (ret)return dev_err_probe (dev, ret,"Failed to get backlight\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1638/3318 drm/panel: ebbg-ft8719: Set prepare_prev_first
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Casey Connolly <[email protected]>
[ Upstream commit 4eeeac9d7c3600a6cae75b2a7bc9c5b67530923c ]
This corrects the host initialisation sequence so that we can send DSI/DCS commands in prepare().
--- drivers/gpu/drm/panel/panel-ebbg-ft8719.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/panel/panel-ebbg-ft8719.c +2 -0
@@ -233,6 +233,8 @@ static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi) dsi->mode_flags =MIPI_DSI_MODE_VIDEO |MIPI_DSI_MODE_VIDEO_BURST |MIPI_DSI_CLOCK_NON_CONTINUOUS ; + ctx->panel.prepare_prev_first = true; + ret =drm_panel_of_backlight (&ctx->panel);if (ret)return dev_err_probe (dev, ret,"Failed to get backlight\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1639/3318 platform/x86: int3472: Fix uninitialised variable warning
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
[ Upstream commit 70e6384fe0f4cf9768944f81924f6c1478b0ce43 ]
Fix a compiler warning about an uninitialised err_msg variable by printing the error where it is handled:
drivers/platform/x86/intel/int3472/discrete.c:440:24: warning: ‘err_msg’ may be used uninitialized [-Wmaybe-uninitialized]
440 | return dev_err_probe(int3472->dev, ret, err_msg);
--- drivers/platform/x86/intel/int3472/discrete.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +8 -8
@@ -156,7 +156,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,struct acpi_resource_gpio *agpio;u8 active_value, pin, type;union acpi_object *obj; -const char *err_msg;const char *func;u32 polarity;int ret;
@@ -202,25 +201,29 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_POWERDOWN : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, func, polarity);if (ret) - err_msg ="Failed to map GPIO pin to sensor\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to map GPIO pin to sensor\n" );break ;case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, agpio, polarity);if (ret) - err_msg ="Failed to register clock\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to register clock\n" );break ;case INT3472_GPIO_TYPE_PRIVACY_LED : ret =skl_int3472_register_pled (int3472, agpio, polarity);if (ret) - err_msg ="Failed to register LED\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE : ret =skl_int3472_register_regulator (int3472, agpio);if (ret) - err_msg ="Failed to map regulator to sensor\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to map regulator to sensor\n" );break ;default :
@@ -234,9 +237,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, int3472->ngpios++;ACPI_FREE (obj); -if (ret <0 ) -return dev_err_probe (int3472->dev, ret, err_msg); -return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1640/3318 media: i2c: ov5647: fix power cleanup on remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 6e81cfc38548109021ab761b94ecdd01f8753154 ]
ov5647_remove() disables runtime PM without powering off the sensor if it is still runtime active. pm_runtime_disable() does not invoke the runtime suspend callback, so the sensor can remain powered on.
If the device is not already runtime suspended, call ov5647_power_off() and mark the runtime PM state as suspended.
This issue was found by manual code inspection.
--- drivers/media/i2c/ov5647.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ov5647.c +4 -0
@@ -1490,6 +1490,10 @@ static void ov5647_remove(struct i2c_client *client)v4l2_ctrl_handler_free (&sensor->ctrls);v4l2_device_unregister_subdev (sd);pm_runtime_disable (&client->dev); +if (!pm_runtime_status_suspended (&client->dev)) { +ov5647_power_off (&client->dev); +pm_runtime_set_suspended (&client->dev); + }mutex_destroy (&sensor->lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1641/3318 staging: media: av7110: fix sp8870 initialization failure state
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Punnay Sharma <[email protected]>
[ Upstream commit 30684fa98394bc0eb4362282908612aab7d4dad9 ]
The SP8870 DVB frontend driver prematurely flags the device as initialized at the very beginning of the sp8870_init() routine, prior to requesting the firmware (dvb-fe-sp8870.fw) and executing the I2C upload sequence.
If request_firmware() times out or sp8870_firmware_upload() encounters an I2C bus error, the function aborts and returns -EIO. However, because state->initialised is already set to 1, all subsequent invocations of fe->ops.init() by the DVB core will immediately return 0 (success) without attempting to load the firmware again. This leaves the demodulator microcontroller halted and the frontend permanently dead until the module is forcibly reloaded.
Relocate the state->initialised = 1 assignment to the end of sp8870_init(), ensuring the flag is only set after the firmware is successfully uploaded and the system controller is actually restarted.
--- drivers/staging/media/av7110/sp8870.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/media/av7110/sp8870.c +2 -1
@@ -297,7 +297,6 @@ static int sp8870_init (struct dvb_frontend* fe)sp8870_wake_up (state);if (state->initialised)return 0 ; - state->initialised =1 ;dprintk ("%s\n" , __func__);
@@ -336,6 +335,8 @@ static int sp8870_init (struct dvb_frontend* fe)sp8870_writereg (state,0x0D00 ,0x010 );sp8870_writereg (state,0x0D01 ,0x000 ); + state->initialised =1 ; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1642/3318 hte: tegra194-test: shut down timer before GPIO release
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 30167fadbf87fa901a2fee49c30a5c5a506a43e8 ]
tegra_hte_test_remove() releases GPIO descriptors before stopping hte.timer. gpio_timer_cb() accesses hte.gpio_out and rearms the timer, so a callback concurrent with remove can use a released descriptor and rearm after teardown.
Shut down the timer before releasing the GPIO descriptors. timer_shutdown_sync() waits for a running callback and prevents it from being rearmed.
--- drivers/hte/hte-tegra194-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hte/hte-tegra194-test.c +1 -1
@@ -218,10 +218,10 @@ static int tegra_hte_test_remove(struct platform_device *pdev) { (void )pdev; +timer_shutdown_sync (&hte.timer);free_irq (hte.gpio_in_irq, &hte);gpiod_put (hte.gpio_in);gpiod_put (hte.gpio_out); -del_timer_sync (&hte.timer);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1643/3318 drm/panel: Fix build error on !CONFIG_OF
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lucas De Marchi <[email protected]>
[ Upstream commit 8f47efd68db3bd87941df1ea3a5b77c62db5632e ]
Move helpers outside of CONFIG_OF, so basic allocation also works without it.
--- drivers/gpu/drm/drm_panel.c | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_panel.c +25 -25
@@ -298,6 +298,31 @@ int drm_panel_get_modes(struct drm_panel *panel, }EXPORT_SYMBOL (drm_panel_get_modes); +void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, +const struct drm_panel_funcs *funcs, +int connector_type) +{ +void *container; +struct drm_panel *panel; + +if (!funcs) { +dev_warn (dev,"Missing funcs pointer\n" ); +return ERR_PTR (-EINVAL ); + } + + container =devm_kzalloc (dev, size,GFP_KERNEL ); +if (!container) +return ERR_PTR (-ENOMEM ); + + panel = container + offset; + panel->funcs = funcs; + +drm_panel_init (panel, dev, funcs, connector_type); + +return container; +} +EXPORT_SYMBOL (__devm_drm_panel_alloc); +#ifdef CONFIG_OF /** * of_drm_find_panel - look up a panel using a device tree node
@@ -336,31 +361,6 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np) }EXPORT_SYMBOL (of_drm_find_panel); -void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, -const struct drm_panel_funcs *funcs, -int connector_type) -{ -void *container; -struct drm_panel *panel; - -if (!funcs) { -dev_warn (dev,"Missing funcs pointer\n" ); -return ERR_PTR (-EINVAL ); - } - - container =devm_kzalloc (dev, size,GFP_KERNEL ); -if (!container) -return ERR_PTR (-ENOMEM ); - - panel = container + offset; - panel->funcs = funcs; - -drm_panel_init (panel, dev, funcs, connector_type); - -return container; -} -EXPORT_SYMBOL (__devm_drm_panel_alloc); -/** * of_drm_get_panel_orientation - look up the orientation of the panel through * the "rotation" binding from a device tree node
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1644/3318 ext4: Move CONFIG_UNICODE defguards into the code flow
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gabriel Krisman Bertazi <[email protected]>
[ Upstream commit d98c822232f8642960a69caedeb7909471127939 ]
Instead of a bunch of ifdefs, make the unicode built checks part of the code flow where possible, as requested by Torvalds.
Stable-dep-of: 19e16597f9ba ("ext4: fix ABBA deadlock in ext4_rmdir()")
--- fs/ext4/crypto.c | 10 ++-------- fs/ext4/ext4.h | 33 +++++++++++++++++++++------------ fs/ext4/namei.c | 14 +++++--------- fs/ext4/super.c | 4 +--- 4 files changed, 29 insertions(+), 32 deletions(-)
fs/ext4/crypto.c +2 -8
@@ -31,11 +31,10 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,ext4_fname_from_fscrypt_name (fname, &name); -#if IS_ENABLED (CONFIG_UNICODE ) err =ext4_fname_setup_ci_filename (dir, iname, fname);if (err)ext4_fname_free_filename (fname); -#endif +return err; }
@@ -51,11 +50,9 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry,ext4_fname_from_fscrypt_name (fname, &name); -#if IS_ENABLED (CONFIG_UNICODE ) err =ext4_fname_setup_ci_filename (dir, &dentry->d_name, fname);if (err)ext4_fname_free_filename (fname); -#endif return err; }
@@ -70,10 +67,7 @@ void ext4_fname_free_filename(struct ext4_filename *fname) fname->usr_fname =NULL ; fname->disk_name.name =NULL ; -#if IS_ENABLED (CONFIG_UNICODE ) -kfree (fname->cf_name.name); - fname->cf_name.name =NULL ; -#endif +ext4_fname_free_ci_filename (fname); }static bool uuid_is_zero (__u8 u[16 ])
fs/ext4/ext4.h +21 -12
@@ -2747,8 +2747,25 @@ ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);#if IS_ENABLED (CONFIG_UNICODE )extern int ext4_fname_setup_ci_filename (struct inode *dir, -const struct qstr *iname, -struct ext4_filename *fname); +const struct qstr *iname, +struct ext4_filename *fname); + +static inline void ext4_fname_free_ci_filename (struct ext4_filename *fname) +{ +kfree (fname->cf_name.name); + fname->cf_name.name =NULL ; +} +#else +static inline int ext4_fname_setup_ci_filename (struct inode *dir, +const struct qstr *iname, +struct ext4_filename *fname) +{ +return 0 ; +} + +static inline void ext4_fname_free_ci_filename (struct ext4_filename *fname) +{ +}#endif /* ext4 encryption related stuff goes here crypto.c */
@@ -2771,16 +2788,11 @@ static inline int ext4_fname_setup_filename(struct inode *dir,int lookup, struct ext4_filename *fname) { - int err = 0; fname->usr_fname = iname; fname->disk_name.name = (unsigned char *) iname->name; fname->disk_name.len = iname->len; -#if IS_ENABLED (CONFIG_UNICODE ) - err =ext4_fname_setup_ci_filename (dir, iname, fname); -#endif - -return err; +return ext4_fname_setup_ci_filename (dir, iname, fname); } static inline int ext4_fname_prepare_lookup(struct inode *dir,
@@ -2792,10 +2804,7 @@ static inline int ext4_fname_prepare_lookup(struct inode *dir,static inline void ext4_fname_free_filename (struct ext4_filename *fname) { -#if IS_ENABLED (CONFIG_UNICODE ) -kfree (fname->cf_name.name); - fname->cf_name.name =NULL ; -#endif +ext4_fname_free_ci_filename (fname); } static inline int ext4_ioctl_get_encryption_pwsalt(struct file *filp,
fs/ext4/namei.c +5 -9
@@ -1875,8 +1875,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi } } -#if IS_ENABLED (CONFIG_UNICODE ) -if (!inode &&IS_CASEFOLDED (dir)) { +if (IS_ENABLED (CONFIG_UNICODE ) && !inode &&IS_CASEFOLDED (dir)) {/* Eventually we want to call d_add_ci(dentry, NULL) * for negative dentries in the encoding case as * well. For now, prevent the negative dentry
@@ -1884,7 +1883,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi*/ return NULL ; } -#endif +return d_splice_alias (inode, dentry); }
@@ -3260,16 +3259,14 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)ext4_fc_track_unlink (handle, dentry); retval =ext4_mark_inode_dirty (handle, dir); -#if IS_ENABLED (CONFIG_UNICODE )/* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at ext4_lookup(), when it is better * supported by the VFS for the CI case. */ -if (IS_CASEFOLDED (dir)) +if (IS_ENABLED (CONFIG_UNICODE ) &&IS_CASEFOLDED (dir))d_invalidate (dentry); -#endif end_rmdir:brelse (bh);
@@ -3371,16 +3368,15 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) goto out_trace; retval =__ext4_unlink (dir, &dentry->d_name,d_inode (dentry), dentry); -#if IS_ENABLED (CONFIG_UNICODE ) +/* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at ext4_lookup(), when it is better * supported by the VFS for the CI case. */ -if (IS_CASEFOLDED (dir)) +if (IS_ENABLED (CONFIG_UNICODE ) &&IS_CASEFOLDED (dir))d_invalidate (dentry); -#endif out_trace:trace_ext4_unlink_exit (dentry, retval);
fs/ext4/super.c +1 -3
@@ -3630,14 +3630,12 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly)return 0 ; } -#if !IS_ENABLED (CONFIG_UNICODE ) -if (ext4_has_feature_casefold (sb)) { +if (!IS_ENABLED (CONFIG_UNICODE ) &&ext4_has_feature_casefold (sb)) {ext4_msg (sb,KERN_ERR ,"Filesystem with casefold feature cannot be " "mounted without CONFIG_UNICODE" );return 0 ; } -#endif if (readonly)return 1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1645/3318 ext4: fix ABBA deadlock in ext4_rmdir()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergey Senozhatsky <[email protected]>
[ Upstream commit 19e16597f9baf1b5719a3a6c710486446f6808fd ]
We observe the following ABBA deadlock (casefolding enabled):
INFO: task jbd2/dm-13-8:447 blocked for more than 720 seconds. task:jbd2/dm-13-8 state:D stack:0 pid:447 tgid:447 ppid:2 Call Trace: <TASK> __schedule+0xc2c/0xe60 schedule+0x40/0xe0 jbd2_journal_wait_updates+0x8f/0xf0 jbd2_journal_commit_transaction+0x321/0x1850 kjournald2+0xa9/0x230 kthread+0x226/0x2a0 ret_from_fork+0x101/0x1e0 ret_from_fork_asm+0x1a/0x30 INFO: task Thread-10:4161 blocked for more than 720 seconds. task:Thread-10 state:D stack:0 pid:4161 tgid:3848 ppid:540 Call Trace: <TASK> __schedule+0xc2c/0xe60 schedule+0x40/0xe0 wait_transaction_locked+0x8c/0xd0 start_this_handle+0x252/0x870 jbd2__journal_start+0x120/0x280 __ext4_journal_start_sb+0x11a/0x250 ext4_evict_inode+0x208/0x760 iput+0x222/0x5c0 dput+0x293/0x690 ____fput+0x145/0x2b0 task_work_run+0x7a/0xb0 exit_to_user_mode_loop+0xc0/0xd0 do_syscall_64+0x14b/0xf10 entry_SYSCALL_64_after_hwframe+0x76/0x7e
NMI backtrace for cpu 0
CPU: 0 UID: 1010216 PID: 4160 Comm: Thread-7 RIP: 0010:d_walk+0x0/0x290 [..] Call Trace: <TASK> shrink_dcache_parent+0xb2/0x100 d_invalidate+0x50/0x110 ext4_rmdir+0x3a2/0x3d0 vfs_rmdir+0x9d/0x1d0 do_rmdir+0xf0/0x330 __x64_sys_unlinkat+0x34/0x50 do_syscall_64+0x61/0xf10
The problem is that ext4_rmdir() calls d_invalidate() before stopping the jbd2 transaction handle. Because d_invalidate() traverses child dentries it can encounter dying or in-use dentries. If a concurrent thread executing __dentry_kill() on a child dentry invokes ext4_evict_inode(), it requests a new transaction handle via ext4_journal_start(), which waits for all running handles to close. However, the thread executing ext4_rmdir() still holds its active transaction handle while looping in shrink_dcache_parent() waiting for the dying child dentry to complete eviction.
Stop transaction handle in ext4_rmdir() before calling d_invalidate().
--- fs/ext4/namei.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
fs/ext4/namei.c +6 -5
@@ -3259,19 +3259,20 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)ext4_fc_track_unlink (handle, dentry); retval =ext4_mark_inode_dirty (handle, dir); +end_rmdir: +brelse (bh); +if (handle) +ext4_journal_stop (handle); +/* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at ext4_lookup(), when it is better * supported by the VFS for the CI case. */ -if (IS_ENABLED (CONFIG_UNICODE ) &&IS_CASEFOLDED (dir)) +if (!retval &&IS_ENABLED (CONFIG_UNICODE ) &&IS_CASEFOLDED (dir))d_invalidate (dentry); -end_rmdir: -brelse (bh); -if (handle) -ext4_journal_stop (handle);return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1646/3318 misc: fastrpc: Rename phys to dma_addr for clarity
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumari Pallavi <[email protected]>
[ Upstream commit 428b2f2b60c37f69e0723a225135da1f352d2602 ]
The fields buf->phys and map->phys currently store DMA addresses returned by dma_map_*() APIs, not physical addresses. This naming is misleading and may lead to incorrect assumptions about the address type and its translation.
Rename these fields from phys to dma_addr to improve code clarity and align with kernel conventions for dma_addr_t usage.
Stable-dep-of: 09fa66ec1b48 ("misc: fastrpc: fix double-free in fastrpc_map_attach() error path")
--- drivers/misc/fastrpc.c | 77 ++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 36 deletions(-)
drivers/misc/fastrpc.c +41 -36
@@ -108,7 +108,7 @@static const char *domains[FASTRPC_DEV_MAX ] = {"adsp" ,"mdsp" ,"sdsp" ,"cdsp" };struct fastrpc_phy_page { -u64 addr;/* physical address */ +dma_addr_t addr;/* dma address */ u64 size;/* size of contiguous region */ };
@@ -173,7 +173,7 @@ struct fastrpc_msg {u64 ctx;/* invoke caller context */ u32 handle;/* handle to invoke */ u32 sc;/* scalars structure describing the data */ -u64 addr;/* physical address */ +dma_addr_t addr;/* dma address */ u64 size;/* size of contiguous region */ };
@@ -196,7 +196,7 @@ struct fastrpc_buf {struct dma_buf *dmabuf;struct device *dev;void *virt; -u64 phys; +dma_addr_t dma_addr;u64 size;/* Lock for dma buf attachments */ struct mutex lock;
@@ -219,7 +219,7 @@ struct fastrpc_map {struct dma_buf *buf;struct sg_table *table;struct dma_buf_attachment *attach; -u64 phys; +dma_addr_t dma_addr;u64 size;void *va;u64 len;
@@ -324,11 +324,12 @@ static void fastrpc_free_map(struct kref *ref) perm.vmid =QCOM_SCM_VMID_HLOS ; perm.perm =QCOM_SCM_PERM_RWX ; - err =qcom_scm_assign_mem (map->phys, map->len, + err =qcom_scm_assign_mem (map->dma_addr, map->len, &src_perms, &perm,1 );if (err) { -dev_err (map->fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d\n" , - map->phys, map->len, err); +dev_err (map->fl->sctx->dev, +"Failed to assign memory dma_addr %pad size 0x%llx err %d\n" , + &map->dma_addr, map->len, err);return ; } }
@@ -399,7 +400,7 @@ static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,static void fastrpc_buf_free (struct fastrpc_buf *buf) {dma_free_coherent (buf->dev, buf->size, buf->virt, -FASTRPC_PHYS (buf->phys)); +FASTRPC_PHYS (buf->dma_addr));kfree (buf); }
@@ -418,12 +419,12 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, buf->fl = fl; buf->virt =NULL ; - buf->phys =0 ; + buf->dma_addr =0 ; buf->size = size; buf->dev = dev; buf->raddr =0 ; - buf->virt =dma_alloc_coherent (dev, buf->size, (dma_addr_t *)&buf->phys, + buf->virt =dma_alloc_coherent (dev, buf->size, &buf->dma_addr,GFP_KERNEL );if (!buf->virt) {mutex_destroy (&buf->lock);
@@ -449,7 +450,7 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, buf = *obuf;if (fl->sctx && fl->sctx->sid) - buf->phys += ((u64 )fl->sctx->sid <<32 ); + buf->dma_addr += ((u64 )fl->sctx->sid <<32 );return 0 ; }
@@ -742,7 +743,7 @@ static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,return -ENOMEM ; ret =dma_get_sgtable (buffer->dev, &a->sgt, buffer->virt, -FASTRPC_PHYS (buffer->phys), buffer->size); +FASTRPC_PHYS (buffer->dma_addr), buffer->size);if (ret <0 ) {dev_err (buffer->dev,"failed to get scatterlist from DMA API\n" );kfree (a);
@@ -791,7 +792,7 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,dma_resv_assert_held (dmabuf->resv);return dma_mmap_coherent (buf->dev, vma, buf->virt, -FASTRPC_PHYS (buf->phys), size); +FASTRPC_PHYS (buf->dma_addr), size); }static const struct dma_buf_ops fastrpc_dma_buf_ops = {
@@ -843,10 +844,10 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, map->table = table;if (attr &FASTRPC_ATTR_SECUREMAP ) { - map->phys =sg_phys (map->table->sgl); + map->dma_addr =sg_phys (map->table->sgl); }else { - map->phys =sg_dma_address (map->table->sgl); - map->phys += ((u64 )fl->sctx->sid <<32 ); + map->dma_addr =sg_dma_address (map->table->sgl); + map->dma_addr += ((u64 )fl->sctx->sid <<32 ); }for_each_sg (map->table->sgl, sgl, map->table->nents, sgl_index)
@@ -873,10 +874,11 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, dst_perms[1 ].vmid = fl->cctx->vmperms[0 ].vmid; dst_perms[1 ].perm =QCOM_SCM_PERM_RWX ; map->attr = attr; - err =qcom_scm_assign_mem (map->phys, (u64 )map->len, &src_perms, dst_perms,2 ); + err =qcom_scm_assign_mem (map->dma_addr, (u64 )map->len, &src_perms, dst_perms,2 );if (err) { -dev_err (sess->dev,"Failed to assign memory with phys 0x%llx size 0x%llx err %d\n" , - map->phys, map->len, err); +dev_err (sess->dev, +"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , + &map->dma_addr, map->len, err); goto map_err; } }
@@ -1055,7 +1057,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)struct vm_area_struct *vma =NULL ; rpra[i].buf.pv = (u64 ) ctx->args[i].ptr; - pages[i].addr = ctx->maps[i]->phys; + pages[i].addr = ctx->maps[i]->dma_addr;mmap_read_lock (current->mm); vma =vma_lookup (current->mm, ctx->args[i].ptr);
@@ -1082,7 +1084,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) goto bail; rpra[i].buf.pv = args - ctx->olaps[oix].offset; - pages[i].addr = ctx->buf->phys - + pages[i].addr = ctx->buf->dma_addr - ctx->olaps[oix].offset + (pkt_size - rlen); pages[i].addr = pages[i].addr &PAGE_MASK ;
@@ -1114,7 +1116,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) list[i].num = ctx->args[i].length ?1 :0 ; list[i].pgidx = i;if (ctx->maps[i]) { - pages[i].addr = ctx->maps[i]->phys; + pages[i].addr = ctx->maps[i]->dma_addr; pages[i].size = ctx->maps[i]->size; } rpra[i].dma.fd = ctx->args[i].fd;
@@ -1196,7 +1198,7 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, msg->ctx = ctx->ctxid | fl->pd; msg->handle = handle; msg->sc = ctx->sc; - msg->addr = ctx->buf ? ctx->buf->phys :0 ; + msg->addr = ctx->buf ? ctx->buf->dma_addr :0 ; msg->size =roundup (ctx->msg_sz,PAGE_SIZE );fastrpc_context_get (ctx);
@@ -1359,13 +1361,15 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,if (fl->cctx->vmcount) {u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - err =qcom_scm_assign_mem (fl->cctx->remote_heap->phys, + err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, (u64 )fl->cctx->remote_heap->size, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount);if (err) { -dev_err (fl->sctx->dev,"Failed to assign memory with phys 0x%llx size 0x%llx err %d\n" , - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); +dev_err (fl->sctx->dev, +"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , + &fl->cctx->remote_heap->dma_addr, + fl->cctx->remote_heap->size, err); goto err_map; } scm_done = true;
@@ -1385,7 +1389,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, args[1 ].length = inbuf.namelen; args[1 ].fd =-1 ; - pages[0 ].addr = fl->cctx->remote_heap->phys; + pages[0 ].addr = fl->cctx->remote_heap->dma_addr; pages[0 ].size = fl->cctx->remote_heap->size; args[2 ].ptr = (u64 )(uintptr_t ) pages;
@@ -1414,12 +1418,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, dst_perms.vmid =QCOM_SCM_VMID_HLOS ; dst_perms.perm =QCOM_SCM_PERM_RWX ; - err =qcom_scm_assign_mem (fl->cctx->remote_heap->phys, + err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, (u64 )fl->cctx->remote_heap->size, &src_perms, &dst_perms,1 );if (err) -dev_err (fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d\n" , - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); +dev_err (fl->sctx->dev,"Failed to assign memory dma_addr %pad size 0x%llx err %d\n" , + &fl->cctx->remote_heap->dma_addr, fl->cctx->remote_heap->size, err); } err_map:fastrpc_buf_free (fl->cctx->remote_heap);
@@ -1509,7 +1513,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, args[2 ].length = inbuf.filelen; args[2 ].fd = init.filefd; - pages[0 ].addr = imem->phys; + pages[0 ].addr = imem->dma_addr; pages[0 ].size = imem->size; args[3 ].ptr = (u64 )(uintptr_t ) pages;
@@ -1963,7 +1967,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) args[0 ].ptr = (u64) (uintptr_t) &req_msg; args[0 ].length =sizeof (req_msg); - pages.addr = buf->phys; + pages.addr = buf->dma_addr; pages.size = buf->size; args[1 ].ptr = (u64) (uintptr_t) &pages;
@@ -1991,11 +1995,12 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)if (req.flags ==ADSP_MMAP_REMOTE_HEAP_ADDR && fl->cctx->vmcount) {u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - err =qcom_scm_assign_mem (buf->phys, (u64 )buf->size, + err =qcom_scm_assign_mem (buf->dma_addr, (u64 )buf->size, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount);if (err) { -dev_err (fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d" , - buf->phys, buf->size, err); +dev_err (fl->sctx->dev, +"Failed to assign memory dma_addr %pad size 0x%llx err %d" , + &buf->dma_addr, buf->size, err); goto err_assign; } }
@@ -2109,7 +2114,7 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp) args[0 ].ptr = (u64) (uintptr_t) &req_msg; args[0 ].length =sizeof (req_msg); - pages.addr = map->phys; + pages.addr = map->dma_addr; pages.size = map->len; args[1 ].ptr = (u64) (uintptr_t) &pages;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1647/3318 misc: fastrpc: fix double-free in fastrpc_map_attach() error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifei Gao <[email protected]>
[ Upstream commit 09fa66ec1b4896ab841da085ca58b6433f28f07f ]
map->table is assigned right after dma_buf_map_attachment_unlocked() succeeds. The two failure checks that follow, the len > map->size test and, where subsystem VMIDs are configured, a failed qcom_scm_assign_mem(), jump to map_err with map->table already set.
map_err manually calls dma_buf_detach() and dma_buf_put() and then falls through to fastrpc_map_put(). Since that change the error path tail is fastrpc_map_put() -> fastrpc_free_map(), and fastrpc_free_map() already unmaps, detaches and puts the dma-buf whenever map->table is set. The two operations therefore run twice: the second dma_buf_put() drops an extra reference on map->buf, and dma_buf_unmap_attachment_unlocked() dereferences the map->attach already freed by the manual dma_buf_detach(). kref_init() sets the refcount to 1 with no intervening get, so the final fastrpc_map_put() frees the map synchronously and the redundant cleanup is deterministic.
The len > map->size branch is reachable by an unprivileged process via FASTRPC_IOCTL_MEM_MAP with an fd whose dma-buf is smaller than the requested length, before any DSP invocation.
Route both map->table-is-set failure branches to get_err instead of map_err, so fastrpc_free_map() is the single owner of the unmap/detach/put sequence. map_err is retained for the dma_buf_map_attachment_unlocked() failure, which is reached with map->table still NULL and an attachment that fastrpc_free_map() will not clean up, so its dma_buf_detach()/dma_buf_put() must still run manually.
--- drivers/misc/fastrpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/fastrpc.c +2 -2
@@ -856,7 +856,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd,dev_dbg (sess->dev,"Bad size passed len 0x%llx map size 0x%llx\n" , len, map->size); err = -EINVAL ; - goto map_err; + goto get_err; } map->va =sg_virt (map->table->sgl); map->len = len;
@@ -879,7 +879,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd,dev_err (sess->dev,"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , &map->dma_addr, map->len, err); - goto map_err; + goto get_err; } }spin_lock (&fl->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1648/3318 crypto: ecc - Handle exceptional points in Shamir multiplication
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 6fd70bc8bc01a578c7728b7bd1cb5689c62cc5b7 ]
Shamir multiplication mishandles equal points, opposite points and the point at infinity. This rejects valid ECDSA signatures and can accept invalid digest/signature tuples when the public key is G or -G. The kernel incorrectly rejects 16 valid signatures from Wycheproof.
Handle doubling, cancellation and the point at infinity in precomputation and accumulation. Add regression tests for P-256 ECDSA and 256/512-bit EC-RDSA. The valid vectors are Wycheproof P1363 secp256r1/SHA-256 cases 60 and 210 converted to X9.62, two constructed ECDSA signatures for Q = +/-G with k = 2, and six constructed EC-RDSA signatures for Q = G, -G and -2G. Also add two invalid P-256 digest/signature tuples for Q = +/-G that must return -EKEYREJECTED.
--- crypto/ecc.c | 33 ++++- crypto/testmgr.c | 10 +- crypto/testmgr.h | 339 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 375 insertions(+), 7 deletions(-)
crypto/ecc.c +31 -2
@@ -1380,9 +1380,22 @@ static void ecc_point_add(const struct ecc_point *result,vli_set (result->x, q->x, ndigits);vli_set (result->y, q->y, ndigits);vli_mod_sub (z, result->x, p->x, curve->p, ndigits); +if (vli_is_zero (z, ndigits)) { +if (vli_cmp (p->y, q->y, ndigits)) { +/* P + (-P) is the point at infinity. */ +vli_clear (result->x, ndigits); +vli_clear (result->y, ndigits); +return ; + } +/* The co-Z addition formula does not handle P == Q. */ + z[0 ] =1 ; +ecc_point_double_jacobian (result->x, result->y, z, curve); + goto out; + }vli_set (px, p->x, ndigits);vli_set (py, p->y, ndigits);xycz_add (px, py, result->x, result->y, curve); +out:vli_mod_inv (z, z, curve->p, ndigits);apply_z (result->x, result->y, z, curve); }
@@ -1422,22 +1435,38 @@ void ecc_point_mult_shamir(const struct ecc_point *result,vli_set (rx, point->x, ndigits);vli_set (ry, point->y, ndigits);vli_clear (z +1 , ndigits -1 ); - z[0 ] =1 ; + z[0 ] = !ecc_point_is_zero (point);for (--i; i >=0 ; i--) {ecc_point_double_jacobian (rx, ry, z, curve); idx = !!vli_test_bit (u1, i); idx |= (!!vli_test_bit (u2, i)) <<1 ; point = points[idx]; -if (point) { +if (point && !ecc_point_is_zero (point)) {u64 tx[ECC_MAX_DIGITS ];u64 ty[ECC_MAX_DIGITS ];u64 tz[ECC_MAX_DIGITS ]; +if (vli_is_zero (z, ndigits)) { +/* Adding to infinity starts a new accumulator. */ +vli_set (rx, point->x, ndigits); +vli_set (ry, point->y, ndigits); + z[0 ] =1 ; +continue ; + }vli_set (tx, point->x, ndigits);vli_set (ty, point->y, ndigits);apply_z (tx, ty, z, curve);vli_mod_sub (tz, rx, tx, curve->p, ndigits); +if (vli_is_zero (tz, ndigits)) { +if (!vli_cmp (ry, ty, ndigits)) +ecc_point_double_jacobian (rx, ry, z, + curve); +else +/* Adding opposite points yields infinity. */ +vli_clear (z, ndigits); +continue ; + }xycz_add (tx, ty, rx, ry, curve);vli_mod_mult_fast (z, z, tz, curve); }
crypto/testmgr.c +6 -4
@@ -4186,8 +4186,10 @@ static int test_akcipher_one(struct crypto_akcipher *tfm, crypto_akcipher_verify(req) :/* Run asymmetric encrypt */ crypto_akcipher_encrypt(req), &wait); -if (err) { -pr_err ("alg: akcipher: %s test failed. err %d\n" , op, err); +if (err != vecs->verify_error) { +pr_err ("alg: akcipher: %s test failed: expected %d, got %d\n" , + op, vecs->verify_error, err); + err = err ?: -EINVAL ; goto free_all; }if (!vecs->siggen_sigver_test && c) {
@@ -4209,9 +4211,9 @@ static int test_akcipher_one(struct crypto_akcipher *tfm,/* * Don't invoke (decrypt or sign) test which require a private key -* for vectors with only a public key. +* for vectors with only a public key or an invalid signature. */ -if (vecs->public_key_vec) { +if (vecs->public_key_vec || vecs->verify_error) { err =0 ; goto free_all; }
crypto/testmgr.h +338 -1
363 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1649/3318 usb: typec: ucsi: ccg: Validate altmode index in GET_CURRENT_CAM response
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seungjin Bae <[email protected]>
[ Upstream commit 02ee864e8d2142c5648998944c3306ea6a763c26 ]
When the PPM reports more than one DisplayPort alternate mode for a connector, ucsi_ccg_update_altmodes() merges them into a single entry in uc->updated[] and sets uc->has_multiple_dp. In that case, ucsi_ccg_update_get_current_cam_cmd() rewrites the response of the GET_CURRENT_CAM command. The response is a single byte holding the index of the currently active alternate mode, and it is provided by the PPM firmware.
The function uses this byte directly as an index into uc->orig[], and then uses the linked_idx read from that entry as the translated index into uc->updated[]. Both arrays have UCSI_MAX_ALTMODES entries, but neither index is checked against that size.
If a malicious or buggy PPM reports a value of UCSI_MAX_ALTMODES or larger, e.g. 0xFF, uc->orig[cam].linked_idx reads over the end of uc->orig[]. The byte read from there is then used as the index for writing cam into uc->updated[new_cam].active_idx, so the out-of-bounds read is followed by an out-of-bounds write. This happens without any userspace action, since the UCSI core issues GET_CURRENT_CAM on its own when handling connector changes.
Fix this by rejecting responses whose index is out of range, printing an error and returning -EPROTO, so that the caller cannot accept this. Also check linked_idx before using it as an index, so that the write into uc->updated[] is always within bounds.
The response is now only processed when the command completed without an error. ucsi_sync_control_common() only reads the response when the CCI reports command completion, so otherwise the buffer is not filled and must not be mistaken for an invalid index.
This bug was found with a Python script that traces where firmware input is used.
--- drivers/usb/typec/ucsi/ucsi_ccg.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +16 -2
@@ -356,14 +356,28 @@ static int ucsi_ccg_init(struct ucsi_ccg *uc)return -ETIMEDOUT ; } -static void ucsi_ccg_update_get_current_cam_cmd (struct ucsi_ccg *uc,u8 *data) +static int ucsi_ccg_update_get_current_cam_cmd (struct ucsi_ccg *uc,u8 *data) {u8 cam, new_cam; cam = data[0 ]; +if (cam >=UCSI_MAX_ALTMODES ) { +dev_err (uc->dev,"PPM returned invalid alternate mode index %u\n" , + cam); +return -EPROTO ; + } + new_cam = uc->orig[cam].linked_idx; +if (new_cam >=UCSI_MAX_ALTMODES ) { +dev_err (uc->dev,"invalid linked alternate mode index %u for %u\n" , + new_cam, cam); +return -EPROTO ; + } + uc->updated[new_cam].active_idx = cam; data[0 ] = new_cam; + +return 0 ; } static bool ucsi_ccg_update_altmodes(struct ucsi *ucsi,
@@ -547,7 +561,7 @@ static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset,switch (UCSI_COMMAND (uc->last_cmd_sent)) {case UCSI_GET_CURRENT_CAM :if (uc->has_multiple_dp) -ucsi_ccg_update_get_current_cam_cmd (uc, (u8 *)val); + ret =ucsi_ccg_update_get_current_cam_cmd (uc, (u8 *)val);break ;case UCSI_GET_ALTERNATE_MODES : if (UCSI_ALTMODE_RECIPIENT(uc->last_cmd_sent) ==
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1650/3318 sctp: hold shkey across socket migration
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lee <[email protected]>
[ Upstream commit ad1320865b1826ffa2e81e37c49535751e81335c ]
sctp_sock_migrate() transfers queued DATA skbs from the old socket to the new one. skb_orphan() invokes sctp_wfree() during that transfer and drops the skb-owned shared-key reference.
If userspace has removed that key from the association, this can be the final reference. The following sctp_set_owner_w() then dereferences the freed chunk->shkey while trying to take the new owner reference.
Take a temporary shared-key reference before orphaning the skb and release it after the new owner has taken its reference. This preserves the selected authentication key throughout the ownership transfer.
Bug found and triaged by OpenAI Security Research and validated by Trail of Bits.
Stable-dep-of: 52ffeaa358d1 ("sctp: re-point retained control chunks on association migration")
--- net/sctp/socket.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/sctp/socket.c +11 -1
@@ -148,9 +148,19 @@ static inline void sctp_set_owner_w(struct sctp_chunk *chunk)static void sctp_clear_owner_w (struct sctp_chunk *chunk) { +/* Keep the shkey alive until the new owner takes its reference. */ +if (chunk->shkey) +sctp_auth_shkey_hold (chunk->shkey);skb_orphan (chunk->skb); } +static void sctp_set_owner_w_migrate (struct sctp_chunk *chunk) +{ +sctp_set_owner_w (chunk); +if (chunk->shkey) +sctp_auth_shkey_release (chunk->shkey); +} +#define traverse_and_process () \ do { \ msg = chunk->msg; \
@@ -9700,7 +9710,7 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,lock_sock_nested (newsk,SINGLE_DEPTH_NESTING );sctp_for_each_tx_datachunk (assoc, true, sctp_clear_owner_w);sctp_assoc_migrate (assoc, newsk); -sctp_for_each_tx_datachunk (assoc, false, sctp_set_owner_w); +sctp_for_each_tx_datachunk (assoc, false, sctp_set_owner_w_migrate);/* If the association on the newsk is already closed before accept() * is called, set RCV_SHUTDOWN flag.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1651/3318 sctp: re-point retained control chunks on association migration
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jun Yang <[email protected]>
[ Upstream commit 52ffeaa358d1f3d91aa87a26ad90d77769cff74b ]
sctp_sock_migrate() transfers DATA chunk ownership but leaves retained control chunks pointing at the old socket. A later retransmission can therefore access the socket after it has been freed.
Extend the migration walk to cover retained control chunks and use sctp_control_set_owner_w() to assign their new owner. Reuse the DATA ownership check so each chunk is processed once per pass, even when it is reachable through multiple lists or retained pointers.
Preserve a control chunk's existing authentication key across migration so its final release can still generate SCTP_AUTH_FREE_KEY when needed.
--- include/net/sctp/sm.h | 1 + net/sctp/sm_make_chunk.c | 5 ++-- net/sctp/socket.c | 53 ++++++++++++++++++++++++++++++---------- 3 files changed, 44 insertions(+), 15 deletions(-)
include/net/sctp/sm.h +1 -0
@@ -253,6 +253,7 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc, struct sctp_fwdtsn_skip *skiplist);struct sctp_chunk *sctp_make_auth (const struct sctp_association *asoc,__u16 key_id); +void sctp_control_set_owner_w (struct sctp_chunk *chunk);struct sctp_chunk *sctp_make_strreset_req (const struct sctp_association *asoc,__u16 stream_num,__be16 *stream_list,bool out,bool in);
net/sctp/sm_make_chunk.c +3 -2
@@ -95,7 +95,7 @@ static void sctp_control_release_owner(struct sk_buff *skb) } } -static void sctp_control_set_owner_w (struct sctp_chunk *chunk) +void sctp_control_set_owner_w (struct sctp_chunk *chunk) {struct sctp_association *asoc = chunk->asoc;struct sk_buff *skb = chunk->skb;
@@ -108,7 +108,8 @@ static void sctp_control_set_owner_w(struct sctp_chunk *chunk)* For now don't do anything for now. */ if (chunk->auth) { - chunk->shkey = asoc->shkey; +if (!chunk->shkey) + chunk->shkey = asoc->shkey;sctp_auth_shkey_hold (chunk->shkey); } skb->sk = asoc ? asoc->base.sk :NULL ;
net/sctp/socket.c +40 -13
81 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1652/3318 nvme: make the DH-HMAC-CHAP secret attributes readable by root only
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Belanger <[email protected]>
[ Upstream commit bbca7c312ab25efd0024eb87545c51a76ab2ea39 ]
The dhchap_secret and dhchap_ctrl_secret sysfs attributes have mode 0644. Their show functions return the secret, so any local user can read the DH-HMAC-CHAP secrets of a connected controller.
Define them with DEVICE_ATTR_ADMIN_RW(), which sets mode 0600. The macro takes the show and store functions from the attribute name, so rename them. Writing the attributes was already limited to root and is not changed.
--- drivers/nvme/host/sysfs.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/nvme/host/sysfs.c +6 -8
@@ -410,7 +410,7 @@ static ssize_t dctype_show(struct device *dev,static DEVICE_ATTR_RO (dctype);#ifdef CONFIG_NVME_AUTH -static ssize_t nvme_ctrl_dhchap_secret_show (struct device *dev, +static ssize_t dhchap_secret_show (struct device *dev,struct device_attribute *attr,char *buf) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -421,7 +421,7 @@ static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,return sysfs_emit (buf,"%s\n" , opts->dhchap_secret); } -static ssize_t nvme_ctrl_dhchap_secret_store (struct device *dev, +static ssize_t dhchap_secret_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -465,10 +465,9 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,return count; } -static DEVICE_ATTR(dhchap_secret, S_IRUGO | S_IWUSR, - nvme_ctrl_dhchap_secret_show, nvme_ctrl_dhchap_secret_store); +static DEVICE_ATTR_ADMIN_RW (dhchap_secret); -static ssize_t nvme_ctrl_dhchap_ctrl_secret_show (struct device *dev, +static ssize_t dhchap_ctrl_secret_show (struct device *dev,struct device_attribute *attr,char *buf) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -479,7 +478,7 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_show(struct device *dev,return sysfs_emit (buf,"%s\n" , opts->dhchap_ctrl_secret); } -static ssize_t nvme_ctrl_dhchap_ctrl_secret_store (struct device *dev, +static ssize_t dhchap_ctrl_secret_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -523,8 +522,7 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,return count; } -static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR, - nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store); +static DEVICE_ATTR_ADMIN_RW (dhchap_ctrl_secret);#endif static struct attribute *nvme_dev_attrs[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1653/3318 bnxt_en: dont leave an XDP program installed when the open fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vaibhav Nagare <[email protected]>
[ Upstream commit 78731b46967e3e7102b5cd5062bef185f3404b5c ]
bnxt_xdp_set() stores the new program and drops the reference on the old one before reopening the NIC. If bnxt_open_nic() then fails, ndo_bpf() returns an error with the new program still in bp->xdp_prog. The caller treats the error as "nothing was installed" and drops its own reference, so bp->xdp_prog is left pointing at a freed program and the next XDP update dereferences it:
BUG: unable to handle page fault for address: ff78ecc80ddd1038 RIP: 0010:__bpf_prog_put+0x5/0x80 Call Trace: bnxt_xdp_set+0xad/0x1b0 [bnxt_en] dev_xdp_propagate+0x36/0xa0 bond_xdp_set+0xeb/0x2d0 [bonding] dev_xdp_install+0x1b1/0x350 bpf_xdp_link_update+0xc5/0x1b0 link_update+0x104/0x1e0 __sys_bpf+0x662/0xcf0
Seen on a 6.12 based kernel after bnxt_alloc_mem() failed an order-4 allocation on a fragmented host:
bnxt_en 0000:a0:00.1 ens4f1np1: nic open fail (rc: fffffff4)
bond1: (slave ens4f1np1): Error -12 calling ndo_bpf
Bonding is not required to hit this; a plain XDP attach on a bnxt interface takes the same path.
Restore the previous program when an attach or a replace fails, and recompute the page-mode and XDP TX ring configuration from it. The configuration matters because bnxt_init_one_rx_ring() only assigns rxr->xdp_prog in page mode, and __bnxt_set_rx_skb_mode() derives dev->max_mtu from the installed program. Release the old program only once the change has been committed.
A detach is not undone. dev_xdp_detach_link() clears the core's record of the program even when the driver returns an error, so putting the program back would leave the driver running a program the core has already dropped. If the reopen fails during a detach, bnxt_xdp_set() therefore returns 0 with the device closed; bnxt_open_nic() has already logged the failure.
Found in a crash dump; the change was not tested on hardware.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +20 -5
@@ -388,6 +388,7 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)struct net_device *dev = bp->dev;int tx_xdp =0 , rc, tc;struct bpf_prog *old; +int old_tx_xdp;if (prog && !prog->aux->xdp_has_frags && bp->dev->mtu >BNXT_MAX_PAGE_MODE_MTU ) {
@@ -414,11 +415,12 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)if (netif_running (dev))bnxt_close_nic (bp, true, false); + old_tx_xdp = bp->tx_nr_rings_xdp; old =xchg (&bp->xdp_prog, prog); -if (old) -bpf_prog_put (old); -if (prog) { +apply_cfg: + tc =netdev_get_num_tc (dev) ? :1 ; +if (bp->xdp_prog) {bnxt_set_rx_skb_mode (bp, true);xdp_features_set_redirect_target (dev, true); }else {
@@ -431,8 +433,21 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)bnxt_set_tpa_flags (bp);bnxt_set_ring_params (bp); -if (netif_running (dev)) -return bnxt_open_nic (bp, true, false); +if (rc) +return rc; + +if (netif_running (dev)) { + rc =bnxt_open_nic (bp, true, false); +/* a detach cannot be undone, only an attach */ +if (rc && prog) { +WRITE_ONCE (bp->xdp_prog, old); + tx_xdp = old_tx_xdp; + goto apply_cfg; + } + } + +if (old) +bpf_prog_put (old);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1654/3318 mm/madvise: atomically clear the young bit on THP MADV_COLD
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pedro Falcato <[email protected]>
[ Upstream commit 246c8cc33438a71c28f9b86baa492d9a0a130316 ]
As-is, madvise_cold_or_pageout_pte_range() discards the hardware young bit by invalidating the PMD, doing pmd_mkold() and subsequently writing to the pmd again. However, it does so in a racy manner, looking at a possibly-stale snapshot. It's entirely possible that a write elsewhere set the hardware D bit, which this logic now loses.
Fix it by using pmdp_test_and_clear_young(). This is an atomic modification of the PMD entry, and thus safe against any possible racing writes. As a (nice) side-effect, this elides one non-required TLB flush in pmdp_invalidate().
This bug can interact with the swapping system in complicated ways, leading to data loss. For instance, if a folio is marked lazyfree, but was later read from, and then MADV_COLD'd while racing a write to that same THP, dropping the dirty bit may lead to data loss as reclaim/MADV_PAGEOUT drops the "clean" anon folio:
T0 T1
================================================================MADV_FREE(thp) |
folio marked lazyfree |
read(thp) |
PMD marked young by hardware |
| MADV_COLD(thp)
write(thp) | if (pmd_young(pmd)) {
PMD marked dirty by hardware | set(pmdp, pmd_mkold(pmd));
MADV_PAGEOUT/reclaim |
dirty bit may or may not be |
set |
reclaim/pageout may drop |
the folio |
--- mm/madvise.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
mm/madvise.c +1 -4
@@ -404,10 +404,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, }if (pmd_young (orig_pmd)) { -pmdp_invalidate (vma, addr, pmd); - orig_pmd =pmd_mkold (orig_pmd); - -set_pmd_at (mm, addr, pmd, orig_pmd); +pmdp_test_and_clear_young (vma, addr, pmd);tlb_remove_pmd_tlb_entry (tlb, pmd, addr); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1655/3318 ALSA: compress_offload: Use automatic cleanup of kfree()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 9b02221422a55e834469fdc91dc4d5147f5a1fb9 ]
There are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
A caveat is that some allocations are memdup_user() and they return an error pointer instead of NULL. Those need special cares and the value has to be cleared with no_free_ptr() at the allocation error path.
Other than that, the conversions are straightforward.
No functional changes, only code refactoring.
Stable-dep-of: 82da1acad6fd ("ALSA: compress: reject buffer geometry change on gapless next_track")
--- sound/core/compress_offload.c | 36 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 23 deletions(-)
sound/core/compress_offload.c +13 -23
@@ -458,7 +458,7 @@ static int snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) { int retval; -struct snd_compr_codec_caps *caps; + struct snd_compr_codec_caps *caps __free(kfree) = NULL;if (!stream->ops->get_codec_caps)return -ENXIO ;
@@ -469,12 +469,9 @@ snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) retval = stream->ops->get_codec_caps (stream, caps);if (retval) - goto out; +return retval;if (copy_to_user ((void __user *)arg, caps,sizeof (*caps))) - retval = -EFAULT ; - -out: -kfree (caps); +return -EFAULT ; return retval; }#endif /* !COMPR_CODEC_CAPS_OVERFLOW */
@@ -579,7 +576,7 @@ static int snd_compress_check_input(struct snd_compr_params *params)static int snd_compr_set_params (struct snd_compr_stream *stream,unsigned long arg) { -struct snd_compr_params *params; + struct snd_compr_params *params __free(kfree) = NULL;int retval;if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN || stream->next_track) {
@@ -589,24 +586,22 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)*/ params =memdup_user ((void __user *)arg,sizeof (*params));if (IS_ERR (params)) -return PTR_ERR (params); +return PTR_ERR (no_free_ptr (params)); retval =snd_compress_check_input (params);if (retval) - goto out; +return retval; retval =snd_compr_allocate_buffer (stream, params); -if (retval) { - retval = -ENOMEM ; - goto out; - } +if (retval) +return -ENOMEM ; retval = stream->ops->set_params (stream, params);if (retval) - goto out; +return retval;if (stream->next_track) - goto out; +return retval; stream->metadata_set = false; stream->next_track = false;
@@ -615,15 +610,13 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) }else {return -EPERM ; } -out: -kfree (params);return retval; }static int snd_compr_get_params (struct snd_compr_stream *stream,unsigned long arg) { -struct snd_codec *params; + struct snd_codec *params __free(kfree) = NULL;int retval;if (!stream->ops->get_params)
@@ -634,12 +627,9 @@ snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg)return -ENOMEM ; retval = stream->ops->get_params (stream, params);if (retval) - goto out; +return retval;if (copy_to_user ((char __user *)arg, params,sizeof (*params))) - retval = -EFAULT ; - -out: -kfree (params); +return -EFAULT ;return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1656/3318 ALSA: compress: reject buffer geometry change on gapless next_track
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 82da1acad6fd60b6072dd5f3383e6a55efdd2ac7 ]
snd_compr_set_params() is invoked from the gapless next_track re-entry path, which calls snd_compr_allocate_buffer() again and lets buffer_size change while total_bytes_available and total_bytes_transferred still hold values computed for the previous buffer. snd_compr_calc_avail() then derives an avail/count value from those stale counters against the new buffer_size, and snd_compr_write_data() copy_from_user()s that many bytes into the new, potentially smaller buffer, overflowing it with user-controlled length and content.
The buffer is set up once, with the initial SET_PARAMS, and neither the core nor the DSP expects it to change for a gapless track transition. Do not call snd_compr_allocate_buffer() on the next_track path and reject a request that changes the buffer geometry, so that the codec parameters that the driver receives match the buffer in use.
--- sound/core/compress_offload.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
sound/core/compress_offload.c +13 -3
@@ -592,9 +592,19 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)if (retval)return retval; - retval =snd_compr_allocate_buffer (stream, params); -if (retval) -return -ENOMEM ; +if (stream->next_track) { +/* +* total_bytes_available/transferred still refer to the +* current buffer; its geometry must not change. +*/ +if (params->buffer.fragment_size != stream->runtime->fragment_size || + params->buffer.fragments != stream->runtime->fragments) +return -EINVAL ; + }else { + retval =snd_compr_allocate_buffer (stream, params); +if (retval) +return retval; + } retval = stream->ops->set_params (stream, params);if (retval)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1657/3318 fs/ntfs3: validate the EA value length in ntfs_read_ea()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuejie Shi <[email protected]>
[ Upstream commit 351817226fbf0031c4c63d1f5d7f15c3172312eb ]
ntfs_read_ea() checks the $EA list for consistency, but it only recomputes the packed size of an entry when the entry's own size field is zero:
for (off = 0; off < size; off += ea_size) {
const struct EA_FULL *ef = Add2Ptr(ea_p, off);
u32 bytes = size - off;
...
if (ef->size) {
ea_size = le32_to_cpu(ef->size);
if (ea_size > bytes)
goto out1;
continue; /* <- elength never checked */
}
...
ea_size = ALIGN(struct_size(ef, name,
1 + ef->name_len +
le16_to_cpu(ef->elength)),
4);
if (ea_size > bytes)
goto out1;
}ef->size is non-zero for every entry except the last one, and it is what ntfs3 itself writes (ntfs_set_ea() stores exactly that aligned packed size), so in practice elength is not validated at all. find_ea() then uses unpacked_ea_size(), which also prefers ea->size when it is set, so it agrees and hands the entry back.
ntfs_get_ea() copies elength bytes with no further bound of its own:
len = le16_to_cpu(ea->elength);
...
if (len > size) { /* size is the *caller's* buffer */
err = -ERANGE;
...
}
memcpy(buffer, ea->name + ea->name_len + 1, len);so a caller that supplies a large enough buffer receives up to 64 KiB of whatever follows the small $EA allocation -- straight to userspace via getxattr(2).
Compute the packed size unconditionally and require it to fit in the entry. Hoist the "bytes < offsetof(struct EA_FULL, name)" test above the ef->size branch as well: name_len and elength were being read there without it, which is itself a small over-read of the kmalloc'd buffer when fewer than 8 bytes are left. The old "bytes < sizeof(ef->size)" test is subsumed by it.
# mkntfs image; create /mnt/ntfs/poc with user.ntfs6 set, then rewrite
# that EA_FULL's elength from 0xf to 0xff00 on the raw device
mount -t ntfs3 -o ro /dev/vda /mnt/ntfs
getxattr("/mnt/ntfs/poc", "user.ntfs6", buf, 128 * 1024);BUG: KASAN: slab-out-of-bounds in ntfs_get_ea+0x294/0x3e0 Read of size 65280 at addr ffff0000cca53acf by task xattr_probe/142 __asan_memcpy+0x3c/0xa0 ntfs_get_ea+0x294/0x3e0 ntfs_getxattr+0x284/0x318 __vfs_getxattr+0x104/0x160 vfs_getxattr+0x1b4/0x1e0 do_getxattr+0xcc/0x230 path_getxattrat+0x184/0x270 __arm64_sys_getxattr+0x64/0x80 Allocated by task 142: __kmalloc_noprof+0x294/0x668 ntfs_read_ea+0x1e4/0x420 ntfs_get_ea+0x2c8/0x3e0 The buggy address belongs to the object at ffff0000cca53a80 which belongs to the cache kmalloc-96 of size 96
The object being over-read is the one ntfs_read_ea() just allocated, and it is 96 bytes.
Entries written by ntfs3 and by Windows set size to the aligned packed size, so the new test does not reject anything a working filesystem produces.
--- fs/ntfs3/xattr.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
fs/ntfs3/xattr.c +14 -11
@@ -146,29 +146,32 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,for (off =0 ; off < size; off += ea_size) {const struct EA_FULL *ef =Add2Ptr (ea_p, off);u32 bytes = size - off; -size_t need; - -/* Check if we can use field ea->size. */ -if (bytes <sizeof (ef->size)) - goto out1; +u32 packed_size;/* Check if we can use fields ef->name_len and ef->elength. */ if (bytes < offsetof(struct EA_FULL , name)) goto out1; -/* Size needed to hold this record's name and value. */ - need =struct_size (ef, name, -1 + ef->name_len +le16_to_cpu (ef->elength)); +/* +* The name and the value have to fit in the entry whether or +* not ef->size is set, because ntfs_get_ea() copies elength +* bytes out of this buffer and checks them only against the +* caller supplied buffer size. +*/ + packed_size = +ALIGN (struct_size (ef, name, +1 + ef->name_len + +le16_to_cpu (ef->elength)), +4 );if (ef->size) { ea_size =le32_to_cpu (ef->size); -/* ef->size must fit the list and cover the record. */ -if (ea_size > bytes || ea_size < need) +if (ea_size > bytes || packed_size > ea_size) goto out1;continue ; } - ea_size =ALIGN (need,4 ); + ea_size = packed_size;if (ea_size > bytes) goto out1; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1658/3318 usb: xhci: Fix bounce buffer overflow
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Pecio <[email protected]>
[ Upstream commit 68c5cb7574c567e83ba95258cb146db95e069a87 ]
High-speed devices with out of spec 1024 byte bulk endpoints exist and are allowed by USB core, but xhci-hcd always sets packet size to 512. The exact nature of these devices isn't documented, commit fb5ee84ea72c ("USB: Accept bulk endpoints with 1024-byte maxpacket") only states that they "don't work with xHCI host controllers", whatever it means.
But somebody (or a malicious device) can try, and then the driver will allocate a 512 byte bounce buffer for this endpoint and may write up to 1024 bytes into it if particular scatter-gather URBs are used, because xhci_align_td() obtains packet size from the descriptor. Fix this.
As a side effect, TRBs will be aligned to the packet size chosen by the driver on all endpoints of all speeds. Alignment serves the xHC, not device, so this is fine. Only out of spec devices are affected anyway.
--- drivers/usb/host/xhci-ring.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/usb/host/xhci-ring.c +3 -6
@@ -3644,15 +3644,13 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred,static int xhci_align_td (struct xhci_hcd *xhci,struct urb *urb,u32 enqd_len, -u32 *trb_buff_len,struct xhci_segment *seg) +u32 *trb_buff_len,struct xhci_segment *seg,u32 max_pkt) {struct device *dev =xhci_to_hcd (xhci)->self.sysdev;unsigned int unalign; -unsigned int max_pkt;u32 new_buff_len;size_t len; - max_pkt =usb_endpoint_maxp (&urb->ep->desc); unalign = (enqd_len + *trb_buff_len) % max_pkt;/* we got lucky, last normal TRB data on segment is packet aligned */
@@ -3797,9 +3795,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,if (enqd_len + trb_buff_len < full_len) { field |=TRB_CHAIN ;if (trb_is_link (ring->enqueue +1 )) { -if (xhci_align_td (xhci, urb, enqd_len, - &trb_buff_len, - ring->enq_seg)) { +if (xhci_align_td (xhci, urb, enqd_len, &trb_buff_len, + ring->enq_seg, ring->bounce_buf_len)) { send_addr = ring->enq_seg->bounce_dma;/* TD bounced at least, and last on this seg */ td->bounce_seg = ring->enq_seg;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1659/3318 KVM: arm64: Validate the host vCPUs VM before reading it under pKVM
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit cf533b4d3630b229d78ad55567c5db2f365052a2 ]
On an MTE-capable host under pKVM, enter_exception64() reads the VM's MTE flag through vcpu->kvm, which for a host vCPU is a host-writable pointer nothing validates. The host can point it at any address in the hyp linear map and read back bit 1 of that word through PSR_TCO in the vCPU's CPSR, or panic the hypervisor with an unmapped one.
Get the VM through a get/put pair around the read: a loaded vCPU's is the hyp VM, an unloaded host vCPU's is read once and pinned, and a pointer the host never shared leaves TCO clear.
--- arch/arm64/kvm/hyp/exception.c | 5 ++- arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 28 ++++++++++++++ arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 2 + arch/arm64/kvm/hyp/nvhe/pkvm.c | 43 ++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/exception.c +4 -1
@@ -92,6 +92,7 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, enum exception_type type) {unsigned long sctlr, vbar, old, new, mode; +struct kvm *kvm;u64 exc_offset; mode = *vcpu_cpsr (vcpu) & (PSR_MODE_MASK |PSR_MODE32_BIT );
@@ -131,8 +132,10 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, new |= (old &PSR_C_BIT ); new |= (old &PSR_V_BIT ); -if (kvm_has_mte (kern_hyp_va (vcpu->kvm))) + kvm =vcpu_get_kvm (vcpu); +if (kvm &&kvm_has_mte (kvm)) new |=PSR_TCO_BIT ; +vcpu_put_kvm (vcpu, kvm); new |= (old &PSR_DIT_BIT );
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h +28 -0
@@ -13,6 +13,34 @@#include <asm/kvm_emulate.h> #include <asm/kvm_host.h> +#ifdef __KVM_NVHE_HYPERVISOR__ +#include <nvhe/pkvm.h> + +/* Under pKVM a host vCPU's ->kvm is host-writable. */ +static inline struct kvm *vcpu_get_kvm (struct kvm_vcpu *vcpu) +{ +if (is_protected_kvm_enabled ()) +return pkvm_vcpu_get_kvm (vcpu); + +return kern_hyp_va (vcpu->kvm); +} + +static inline void vcpu_put_kvm (struct kvm_vcpu *vcpu,struct kvm *kvm) +{ +if (is_protected_kvm_enabled ()) +pkvm_vcpu_put_kvm (vcpu, kvm); +} +#else +static inline struct kvm *vcpu_get_kvm (struct kvm_vcpu *vcpu) +{ +return vcpu->kvm; +} + +static inline void vcpu_put_kvm (struct kvm_vcpu *vcpu,struct kvm *kvm) +{ +} +#endif +static inline void kvm_skip_instr (struct kvm_vcpu *vcpu) {if (vcpu_mode_is_32bit (vcpu)) {
arch/arm64/kvm/hyp/include/nvhe/pkvm.h +2 -0
@@ -64,5 +64,7 @@ int __pkvm_teardown_vm(pkvm_handle_t handle);struct pkvm_hyp_vcpu *pkvm_load_hyp_vcpu (pkvm_handle_t handle,unsigned int vcpu_idx);void pkvm_put_hyp_vcpu (struct pkvm_hyp_vcpu *hyp_vcpu); +struct kvm *pkvm_vcpu_get_kvm (struct kvm_vcpu *vcpu); +void pkvm_vcpu_put_kvm (struct kvm_vcpu *vcpu,struct kvm *kvm);#endif /* __ARM64_KVM_NVHE_PKVM_H__ */
arch/arm64/kvm/hyp/nvhe/pkvm.c +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1660/3318 ALSA: usb-audio: Bound packet copies by the PCM buffer size
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit 06be918062adc1a5a76dc346803b136b20bdb5ae ]
retire_capture_urb() and prepare_playback_urb() assume that one USB packet never carries more data than the whole ALSA ring buffer. Nothing enforces that: the packet size comes from the device (wMaxPacketSize, and curpacksize == maxpacksize when the class-specific endpoint descriptor sets MaxPacketsOnly), while the PCM hardware constraints only require 64-byte periods, two periods and a period time of one data interval. An 8 kHz mono U8 stream on a 128-byte buffer is legal, and a full-speed device can send 1023-byte packets into it.
On the first oversized packet hwptr_done is wrapped once and stays beyond buffer_bytes (895 for 1023 bytes into 128). On the next packet the wrap arithmetic in the copy path computes
bytes1 = subs->buffer_bytes - oldptr
with oldptr > buffer_bytes, so bytes1 wraps to about 4 GB and memcpy() runs off the end of the URB buffer and of the vmalloc'd DMA buffer:
BUG: KASAN: slab-out-of-bounds in retire_capture_urb+0x251/0x870 Read of size 4294966529 at addr ffff88800c1e2800 by task vhci_rx/82
and for playback, where copy_to_urb() has the same shape:
BUG: KASAN: vmalloc-out-of-bounds in copy_to_urb.isra.0+0x188/0x430 Read of size 4294966529 at addr ffffc9000004537f by task vhci_rx/79 prepare_playback_urb+0x98a/0x1fc0
Truncate an oversized capture packet to the buffer size, and stop filling a playback URB once it holds a whole buffer. With bytes <= buffer_bytes the single wrap of hwptr_done and the two-part memcpy() in both copy paths stay inside the buffer. A device whose packets do not fit the buffer at all was never going to play correctly anyway.
Reproduced on 7.3-rc7 with a USB/IP device (dummy_hcd cannot carry isochronous data) advertising a UAC1 endpoint with MaxPacketsOnly and wMaxPacketSize 1023, and a PCM client using period_size 64, periods 2.
--- sound/usb/pcm.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
sound/usb/pcm.c +19 -1
@@ -1292,6 +1292,18 @@ static void retire_capture_urb(struct snd_usb_substream *subs, bytes -= adj; subs->stream_offset_adj -= adj; } +/* +* A packet can be as large as the endpoint's maxpacksize, which +* the device chooses, while the ring buffer can be as small as +* two 64-byte periods. The hwptr_done wrap below handles one +* wrap only, so never take more than one buffer from a packet. +*/ +if (unlikely (bytes > subs->buffer_bytes)) { +dev_warn_ratelimited (&subs->dev->dev, +"%u-byte packet exceeds %u-byte buffer, truncating\n" , + bytes, subs->buffer_bytes); + bytes = subs->buffer_bytes; + } frames = bytes / stride;if (!subs->txfr_quirk) bytes = frames * stride;
@@ -1505,8 +1517,14 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,for (i =0 ; i < ctx->packets; i++) { counts =snd_usb_endpoint_next_packet_size (ep, ctx, i, avail); +/* +* Bound by the ring buffer as well as by the URB: +* copy_to_urb() wraps hwptr_done once, so one URB must +* never carry more than the whole buffer. +*/ if (counts <0 || - (frames + counts) * stride > ctx->buffer_size) + (frames + counts) * stride > ctx->buffer_size || + (frames + counts) * stride > subs->buffer_bytes)break ;/* set up descriptor */ urb->iso_frame_desc[i].offset = frames * stride;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1661/3318 mm/hugetlb: unmap the page where the other VMA maps it
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit ae99c503eb362b42cd5d24d80bc6cba669acc4c2 ]
If the owner of a MAP_PRIVATE hugetlb mapping fails to allocate a page for CoW, unmap_ref_private() unmaps the old page from all other private VMAs that have no reservation of their own. It finds them by the offset in the file, but then zaps each of them at the address of the faulting VMA. Nothing says that another VMA maps the offset at that address: a child can have moved its copy of the VMA with mremap(), and a second mapping of the file is wherever mmap() has put it.
So __unmap_hugepage_range() walks the page tables of the other mm at an address outside of iter_vma, where i_mmap_rwsem of this file protects nothing and where anything can be mapped, and the page stays mapped where it really is.
All of the following was seen on v7.3-rc6+ (g6c377d19d4a5) in KVM guests, as a user without any privilege. It takes a pool of 2 MiB pages with no free page that is not reserved, so that the allocation fails: the user can take or reserve what is free itself.
- The child moves its VMA away. The page is never unmapped, the mapcount stays 2, and the owner goes round retry_avoidcopy in hugetlb_wp() until the child is gone or a page becomes free. SIGKILL to the owner does not end it. 5 of 5 runs.
- The owner's mm has a second private mapping of the offset, made with MAP_NORESERVE. The owner zaps its own entry and reads zeroes where its data was. 5 of 5 runs.
- The child moves its VMA away and maps a 1 GiB hugetlb page at the old address, so this one takes a pool with a 1 GiB page as well. huge_pte_offset() for the 2 MiB size steps through the PUD leaf, so the "PMD table" is the 1 GiB page itself and its "page table lock" is folio->private of that page, which holds 2. Kernels with lock debugging oops in __unmap_hugepage_range(), 7 of 7 runs. Others spin on that word for ever with preemption disabled, 5 of 5 runs:
watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [u_det3:130]
RIP: 0010:queued_spin_lock_slowpath+0x8a/0x290
RAX: 0000000000000002 RBX: ffffea0001000028
Call Trace:
__unmap_hugepage_range+0x154/0x6d0
unmap_hugepage_range+0xc1/0x140
hugetlb_wp+0x55c/0x700
hugetlb_fault+0x5f3/0x8f0RCU stalls follow, and killing all tasks of the user changes nothing. Four such owners, whose children share a single 1 GiB page, took down the whole guest with its four CPUs, 2 of 2 runs: one reported soft lockups on all four, the other gave no sign of life any more.
i_mmap_rwsem stays write locked. With a MAP_PRIVATE mapping of a hugetlbfs file that belongs to another user, and that the attacker can only read, the next mmap() of that file by its owner sleeps uninterruptibly in __mmap_region(), 4 of 4 runs.
Compute the address from the offset for each VMA. The tree walk returns only VMAs that cover pgoff, and vm_start, vm_end and vm_pgoff of a hugetlb VMA are aligned to the huge page size, as pgoff is, so the whole range lies inside iter_vma. Its page tables can not go away there, since the VMA is unlinked from the file under i_mmap_rwsem first.
With the right address the page is unmapped from all VMAs but the owner's, so the retry in hugetlb_wp() finds a mapcount of 1 and reuses the page.
A child that has moved its copy of the VMA now loses the page, and gets SIGBUS when it faults on a missing page of that VMA. That is what the comment above the function has always promised to those who do not own the reservation, and what already happens to a child that has left the VMA in place.
The address has been wrong from the start, and the second case needs only mmap() and fork(). mremap() of hugetlb VMAs, which the other cases use, came with commit 550a7d60bd5e ("mm, hugepages: add mremap() support for hugepage backed vma") in v5.16.
Original fix generated by an LLM and sent in private by Josef.
--- mm/hugetlb.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/hugetlb.c +13 -3
@@ -5524,6 +5524,8 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,struct address_space *mapping;pgoff_t pgoff; +VM_WARN_ON_ONCE (!folio_test_anon (page_folio (page))); +/* * vm_pgoff is in PAGE_SIZE units, hence the different calculation * from page cache lookup which is in HPAGE_SIZE units.
@@ -5559,9 +5561,17 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,* could insert a zeroed page instead of the data existing * from the time of fork. This would look like data corruption */ -if (!is_vma_resv_set (iter_vma,HPAGE_RESV_OWNER )) -unmap_hugepage_range (iter_vma, address, - address +huge_page_size (h), page,0 ); +if (is_vma_resv_set (iter_vma,HPAGE_RESV_OWNER )) +continue ; + +/* +* The address in other VMAs can differ. Even though our old +* folio is anon, we always operate on the underlying hugetlb +* file. +*/ + address =vma_pgoff_address (pgoff,1 , iter_vma); +unmap_hugepage_range (iter_vma, address, + address +huge_page_size (h), page,0 ); }i_mmap_unlock_write (mapping); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1662/3318 ipmr: Call ipmr_fib_lookup() under RCU.
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 019c892e46544af0ae94ec833f79aa903c837666 ]
Yi Lai reported RCU splat in reg_vif_xmit() below. [0]
When CONFIG_IP_MROUTE_MULTIPLE_TABLES=n, ipmr_fib_lookup() uses rcu_dereference() without explicit rcu_read_lock().
Although rcu_read_lock_bh() is already held by the caller __dev_queue_xmit(), lockdep requires explicit rcu_read_lock() for rcu_dereference().
Let's move up rcu_read_lock() in reg_vif_xmit() to cover ipmr_fib_lookup().
[0]:
WARNING: suspicious RCU usage 7.1.0-rc2-next-20260504-9d0d467c3572 #1 Not tainted
-----------------------------net/ipv4/ipmr.c:329 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
2 locks held by syz.2.17/1779:
#0: ffffffff87896440 (rcu_read_lock_bh){....}-{1:3}, at: local_bh_disable include/linux/bottom_half.h:20 [inline] #0: ffffffff87896440 (rcu_read_lock_bh){....}-{1:3}, at: rcu_read_lock_bh include/linux/rcupdate.h:891 [inline] #0: ffffffff87896440 (rcu_read_lock_bh){....}-{1:3}, at: __dev_queue_xmit+0x239/0x4140 net/core/dev.c:4792 #1: ffff88801a199d18 (_xmit_PIMREG#2){+...}-{3:3}, at: spin_lock include/linux/spinlock.h:342 [inline] #1: ffff88801a199d18 (_xmit_PIMREG#2){+...}-{3:3}, at: __netif_tx_lock include/linux/netdevice.h:4795 [inline] #1: ffff88801a199d18 (_xmit_PIMREG#2){+...}-{3:3}, at: __dev_queue_xmit+0x1d5d/0x4140 net/core/dev.c:4865
stack backtrace: CPU: 1 UID: 0 PID: 1779 Comm: syz.2.17 Not tainted 7.1.0-rc2-next-20260504-9d0d467c3572 #1 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x121/0x150 lib/dump_stack.c:120 dump_stack+0x19/0x20 lib/dump_stack.c:129 lockdep_rcu_suspicious+0x15b/0x1f0 kernel/locking/lockdep.c:6878 ipmr_fib_lookup net/ipv4/ipmr.c:329 [inline] reg_vif_xmit+0x2ee/0x3c0 net/ipv4/ipmr.c:540 __netdev_start_xmit include/linux/netdevice.h:5382 [inline] netdev_start_xmit include/linux/netdevice.h:5391 [inline] xmit_one net/core/dev.c:3889 [inline] dev_hard_start_xmit+0x170/0x700 net/core/dev.c:3905 __dev_queue_xmit+0x1df1/0x4140 net/core/dev.c:4871 dev_queue_xmit include/linux/netdevice.h:3423 [inline] packet_xmit+0x252/0x370 net/packet/af_packet.c:276 packet_snd net/packet/af_packet.c:3082 [inline] packet_sendmsg+0x39ad/0x5650 net/packet/af_packet.c:3114 sock_sendmsg_nosec net/socket.c:797 [inline] __sock_sendmsg net/socket.c:812 [inline] ____sys_sendmsg+0xa21/0xba0 net/socket.c:2716 ___sys_sendmsg+0x121/0x1c0 net/socket.c:2770 __sys_sendmsg+0x177/0x220 net/socket.c:2802 __do_sys_sendmsg net/socket.c:2807 [inline] __se_sys_sendmsg net/socket.c:2805 [inline] __x64_sys_sendmsg+0x80/0xc0 net/socket.c:2805 x64_sys_call+0x1d9c/0x21c0 arch/x86/include/generated/asm/syscalls_64.h:47 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xc1/0x1020 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f37e563ee5d Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 93 af 1b 00 f7 d8 64 89 01 48 RSP: 002b:00007ffe5caa7fa8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00000000005c5fa0 RCX: 00007f37e563ee5d RDX: 0000000000000000 RSI: 00002000000012c0 RDI: 0000000000000004 RBP: 00000000005c5fa0 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 00000000005c5fac R15: 00000000005c5fa0 </TASK>
Stable-dep-of: aa1799e93f5e ("ipmr, ip6mr: validate packets injected into the register vif on xmit")
--- net/ipv4/ipmr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/ipmr.c +2 -1
@@ -512,15 +512,16 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) };int err; +rcu_read_lock (); err =ipmr_fib_lookup (net, &fl4, &mrt);if (err <0 ) { +rcu_read_unlock ();kfree_skb (skb);return err; }DEV_STATS_ADD (dev, tx_bytes, skb->len);DEV_STATS_INC (dev, tx_packets); -rcu_read_lock ();/* Pairs with WRITE_ONCE() in vif_add() and vif_delete() */ ipmr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1663/3318 ipmr, ip6mr: validate packets injected into the register vif on xmit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit aa1799e93f5ebb973252aec649d84d12d9c7fd1c ]
reg_vif_xmit() passes the packet to ipmr_cache_report() which copies its IP header into the IGMPMSG_WHOLEPKT report that is queued to the mroute socket. Nothing guarantees that the packet contains a full IP header, so when a short packet is injected on the register device (e.g., using AF_PACKET), the copy reads past the end of the packet and a recvmsg() on the mroute socket leaks the uninitialized bytes to user space [1].
IPv6 has the same problem [2]. Its reg_vif_xmit() does call pskb_inet_may_pull(), but the helper keys off skb->protocol and does not pull anything when the protocol is neither IPv4 nor IPv6.
Fix by dropping packets whose protocol does not match the address family of the register device or that do not contain a full network header.
[1]
BUG: KMSAN: kernel-infoleak in _copy_to_iter raw_recvmsg
Uninit was stored to memory at:
ipmr_cache_report
reg_vif_xmit
packet_sendmsg
Uninit was created at:
__alloc_skb
sock_alloc_send_pskb
packet_sendmsg
Bytes 1-3 of 21 are uninitialized
[2]
BUG: KMSAN: kernel-infoleak in _copy_to_iter rawv6_recvmsg
Uninit was stored to memory at:
ip6mr_cache_report
reg_vif_xmit
packet_sendmsg
Uninit was created at:
__alloc_skb
sock_alloc_send_pskb
packet_sendmsg
Bytes 8-23 of 41 are uninitialized
--- net/ipv4/ipmr.c | 6 ++++++ net/ipv6/ip6mr.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
net/ipv4/ipmr.c +6 -0
@@ -512,6 +512,12 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) };int err; +if (skb->protocol !=htons (ETH_P_IP ) || !pskb_inet_may_pull (skb)) { +DEV_STATS_INC (dev, tx_errors); +kfree_skb (skb); +return NETDEV_TX_OK ; + } +rcu_read_lock (); err =ipmr_fib_lookup (net, &fl4, &mrt);if (err <0 ) {
net/ipv6/ip6mr.c +1 -1
@@ -616,7 +616,7 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, .flowi6_mark = skb->mark, }; -if (!pskb_inet_may_pull (skb)) +if (skb->protocol !=htons (ETH_P_IPV6 ) || !pskb_inet_may_pull (skb)) goto tx_err;if (ip6mr_fib_lookup (net, &fl6, &mrt) <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1664/3318 ceph: fix longname buffer overflow in ceph_fname_to_usr()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
[ Upstream commit 71975d6e0db17646102488cf54480fda9de0f7a7 ]
Snapshot longname reconstruction formats "_<name>_<inode>" via snprintf() and memcpy()s the result into oname->name. Checking the length against NAME_MAX only protects the LOOKUPNAME/export callers, whose buffer is allocated with fscrypt_fname_alloc_buffer(NAME_MAX). The readdir path points oname->name straight at the altname in the MDS reply, whose capacity is altname_len; the reconstructed name can exceed that while still fitting under NAME_MAX, overflowing the in-place destination.
Save the actual oname->len before the decryption overwrites it, and fail with -ENAMETOOLONG when the reconstructed name would not fit.
--- fs/ceph/crypto.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ceph/crypto.c +8 -0
@@ -388,6 +388,7 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,struct fscrypt_str iname;char *name = fname->name;int name_len = fname->name_len; +int dst_len;int ret;if (WARN_ON_ONCE (tname &&is_vmalloc_addr (tname->name)))
@@ -463,6 +464,9 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname, iname.len = fname->ctext_len; } +/* oname->len is overwritten by the decryption below */ + dst_len = oname->len; + _oname.name =unlikely (is_vmalloc_addr (oname->name)) ? tname->name : oname->name; _oname.len = oname->len;
@@ -480,6 +484,10 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname, name_len =snprintf (tmp_buf,sizeof (tmp_buf),"_%.*s_%ld" , oname->len, oname->name, dir->i_ino); +if (name_len > dst_len) { + ret = -ENAMETOOLONG ; + goto out; + }memcpy (oname->name, tmp_buf, name_len); oname->len = name_len; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1665/3318 mm/page_vma_mapped: continue past nonmatching huge PMDs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 1a2993227e8a27fc4cdea305bbdae82d290bc885 ]
A PTE-mapped large folio can straddle PMD boundaries after an unaligned mremap(). If the first part is discarded and replaced with an unrelated huge PMD, page_vma_mapped_walk() stops instead of looking for the rest of the folio in subsequent PMDs.
This also affects migration entries. A walk that stops at an unrelated huge PMD can leave migration PTEs behind when migration or an anonymous folio split restores the mappings. Those entries do not hold mapping references and can outlive the source folio.
This issue can lead to memory corruption and I have a reproducer for it.
Skip the current PMD rather than ending the walk on a flag or PFN mismatch. Do the same if the PMD became nonpresent before the locked recheck. Release the PMD lock, clear the per-PMD state and advance with step_forward(), so the existing range limit controls termination. This covers present, migration and device-private huge PMDs while preserving the matching-PMD and split-to-PTE paths.
--- mm/page_vma_mapped.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
mm/page_vma_mapped.c +16 -6
@@ -254,18 +254,18 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)if (!thp_migration_supported () || !(pvmw->flags &PVMW_MIGRATION )) -return not_found (pvmw); + goto next_pmd; entry =pmd_to_swp_entry (pmde);if (!is_migration_entry (entry) || !check_pmd (swp_offset_pfn (entry), pvmw)) -return not_found (pvmw); + goto next_pmd;return true; }if (likely (pmd_trans_huge (pmde) ||pmd_devmap (pmde))) {if (pvmw->flags &PVMW_MIGRATION ) -return not_found (pvmw); + goto next_pmd;if (!check_pmd (pmd_pfn (pmde), pvmw)) -return not_found (pvmw); + goto next_pmd;return true; }/* THP pmd was split under us: handle on pte level */
@@ -284,8 +284,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)spin_unlock (ptl); } -step_forward (pvmw,PMD_SIZE ); -continue ; + goto next_pmd; }if (!map_pte (pvmw, &ptl)) {if (!pvmw->pte)
@@ -318,6 +317,17 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)spin_lock (pvmw->ptl); } goto this_pte; +next_pmd: +/* +* A large folio can be PTE-mapped across PMDs, so a +* nonmatching PMD does not end the walk. +*/ +if (pvmw->ptl) { +spin_unlock (pvmw->ptl); + pvmw->ptl =NULL ; + } + pvmw->pmd =NULL ; +step_forward (pvmw,PMD_SIZE ); }while (pvmw->address < end);return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1666/3318 mm/shmem: honour F_SEAL_EXEC when an ACL is set
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 0237c47ca17005ea41b510c6116f0257dbf84eab ]
The owner of a memfd sealed with F_SEAL_EXEC can still change its execute bits by setting a POSIX access ACL. With CONFIG_TMPFS_POSIX_ACL, this lets an unprivileged owner make a non-executable memfd executable, bypassing vm.memfd_noexec=2.
simple_set_acl() updates i_mode directly, bypassing the seal check in shmem_setattr(). Add shmem_set_acl() to check the resulting mode. Share the F_SEAL_EXEC check with shmem_setattr() using memfd_check_seals_mode() in include/linux/memfd.h.
Fix generated by an LLM and sent by Chris Mason in private.
--- include/linux/memfd.h | 9 +++++++++ mm/shmem.c | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-)
include/linux/memfd.h +9 -0
@@ -2,8 +2,17 @@#ifndef __LINUX_MEMFD_H#define __LINUX_MEMFD_H +#include <linux/fcntl.h> #include <linux/file.h> +static inline int memfd_check_seals_mode (unsigned int seals,umode_t old_mode, +umode_t new_mode) +{ +if ((seals &F_SEAL_EXEC ) && ((old_mode ^ new_mode) &0111 )) +return -EPERM ; +return 0 ; +} +#ifdef CONFIG_MEMFD_CREATE extern long memfd_fcntl (struct file *file,unsigned int cmd,unsigned int arg);unsigned int *memfd_file_seals_ptr (struct file *file);
mm/shmem.c +30 -5
@@ -75,6 +75,7 @@ static struct vfsmount *shm_mnt;#include <linux/magic.h> #include <linux/syscalls.h> #include <linux/fcntl.h> +#include <linux/memfd.h> #include <uapi/linux/memfd.h> #include <linux/rmap.h> #include <linux/uuid.h>
@@ -1202,10 +1203,11 @@ static int shmem_setattr(struct mnt_idmap *idmap,if (error)return error; -if ((info->seals &F_SEAL_EXEC ) && (attr->ia_valid &ATTR_MODE )) { -if ((inode->i_mode ^ attr->ia_mode) &0111 ) { -return -EPERM ; - } +if (attr->ia_valid &ATTR_MODE ) { + error =memfd_check_seals_mode (info->seals, inode->i_mode, + attr->ia_mode); +if (error) +return error; }if (S_ISREG (inode->i_mode) && (attr->ia_valid &ATTR_SIZE )) {
@@ -4524,12 +4526,35 @@ static const struct file_operations shmem_file_operations = {#endif }; +#ifdef CONFIG_TMPFS_POSIX_ACL +static int shmem_set_acl (struct mnt_idmap *idmap,struct dentry *dentry, +struct posix_acl *acl,int type) +{ +struct inode *inode =d_inode (dentry); +umode_t mode = inode->i_mode; +int error; + +if (type ==ACL_TYPE_ACCESS ) { + error =posix_acl_equiv_mode (acl, &mode); +if (error <0 ) +return error; + error =memfd_check_seals_mode (SHMEM_I (inode)->seals, + inode->i_mode, mode); +if (error) +return error; + } +return simple_set_acl (idmap, dentry, acl, type); +} +#else +#define shmem_set_acl simple_set_acl +#endif +static const struct inode_operations shmem_inode_operations = { .getattr = shmem_getattr, .setattr = shmem_setattr, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, - .set_acl = simple_set_acl, + .set_acl = shmem_set_acl, .fileattr_get = shmem_fileattr_get, .fileattr_set = shmem_fileattr_set, #endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1667/3318 spi: cadence-xspi: reject SDMA transfers larger than the requested length
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit ea9854a169e9c1437df8829bea21c2f2e80b137c ]
The XSPI controller reports the size of the slave-DMA transaction through SDMA_SIZE_REG. Both SDMA handlers take this register at face value and copy the reported number of bytes between the SDMA FIFO and the transfer buffers, without checking it against the length of the transfer that was actually requested.
While cdns_xspi_adjust_mem_op_size() clamps the size of the operations issued by the SPI core, the device can still report a bigger SDMA size than what was programmed, which makes the handlers read from or write to memory beyond the end of the transfer buffers.
Track the number of bytes requested for the current data phase in a new sdma_xfer_len field, set by cdns_xspi_send_stig_command() and by the Marvell b0 transfer path, and reject any SDMA size that exceeds it.
--- drivers/spi/spi-cadence-xspi.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/spi/spi-cadence-xspi.c +17 -2
@@ -220,6 +220,7 @@ struct cdns_xspi_dev {int irq;int cur_cs;unsigned int sdmasize; +unsigned int sdma_xfer_len;struct completion cmd_complete;struct completion auto_cmd_complete;
@@ -326,7 +327,7 @@ static int cdns_xspi_controller_init(struct cdns_xspi_dev *cdns_xspi)return 0 ; } -static void cdns_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) +static int cdns_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) {u32 sdma_size, sdma_trd_info;u8 sdma_dir;
@@ -335,6 +336,13 @@ static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) sdma_trd_info =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_TRD_INFO_REG ); sdma_dir =FIELD_GET (CDNS_XSPI_SDMA_DIR , sdma_trd_info); +if (sdma_size > cdns_xspi->sdma_xfer_len) { +dev_err (cdns_xspi->dev, +"SDMA size %u exceeds the requested length %u\n" , + sdma_size, cdns_xspi->sdma_xfer_len); +return -EINVAL ; + } +switch (sdma_dir) {case CDNS_XSPI_SDMA_DIR_READ : ioread8_rep(cdns_xspi->sdmabase,
@@ -346,6 +354,8 @@ static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) cdns_xspi->out_buffer, sdma_size);break ; } + +return 0 ; } static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi,
@@ -391,6 +401,7 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cdns_xspi->in_buffer = op->data.buf.in; cdns_xspi->out_buffer = op->data.buf.out; + cdns_xspi->sdma_xfer_len = op->data.nbytes;cdns_xspi_trigger_command (cdns_xspi, cmd_regs);
@@ -399,7 +410,11 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi,cdns_xspi_set_interrupts (cdns_xspi, false);return -EIO ; } -cdns_xspi_sdma_handle (cdns_xspi); + ret =cdns_xspi_sdma_handle (cdns_xspi); +if (ret) { +cdns_xspi_set_interrupts (cdns_xspi, false); +return ret; + } }wait_for_completion (&cdns_xspi->cmd_complete);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1668/3318 nvme-auth: add flag for bi-directional auth
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark O'Donovan <[email protected]>
[ Upstream commit fc1e03eacac8e5ff8664ce2ebadabba8604f09f4 ]
Introduces an explicit variable for bi-directional auth. The currently used variable chap->s2 is incorrectly zeroed for uni-directional auth. That will be fixed in the next patch so this needs to change to avoid sending unexpected success2 messages
Stable-dep-of: f9e43d924bc7 ("nvme-auth: fail when the controller does not authenticate itself")
--- drivers/nvme/host/auth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvme/host/auth.c +4 -1
@@ -29,6 +29,7 @@ struct nvme_dhchap_queue_context {int error;u32 s1;u32 s2; +bool bi_directional;u16 transaction;u8 status;u8 dhgroup_id;
@@ -313,6 +314,7 @@ static int nvme_auth_set_dhchap_reply_data(struct nvme_ctrl *ctrl, data->dhvlen =cpu_to_le16 (chap->host_key_len);memcpy (data->rval, chap->response, chap->hash_len);if (ctrl->ctrl_key) { + chap->bi_directional = true;get_random_bytes (chap->c2, chap->hash_len); data->cvalid =1 ; chap->s2 =nvme_auth_get_seqnum ();
@@ -664,6 +666,7 @@ static void nvme_auth_reset_dhchap(struct nvme_dhchap_queue_context *chap) chap->error =0 ; chap->s1 =0 ; chap->s2 =0 ; + chap->bi_directional = false; chap->transaction =0 ;memset (chap->c1,0 ,sizeof (chap->c1));memset (chap->c2,0 ,sizeof (chap->c2));
@@ -826,7 +829,7 @@ static void nvme_queue_auth_work(struct work_struct *work) goto fail2; } -if (chap->s2) { +if (chap->bi_directional) {/* DH-HMAC-CHAP Step 5: send success2 */ dev_dbg (ctrl->device,"%s: qid %d send success2\n" , __func__, chap->qid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1669/3318 nvme-auth: fail when the controller does not authenticate itself
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit f9e43d924bc74feeb56197de82b2845de2a4b85a ]
nvme_auth_process_dhchap_success1() returns success as soon as the controller clears the rvalid flag in its DH-HMAC-CHAP success1 message, without looking at whether the host had asked the controller to authenticate. A host configured with a controller secret sends a challenge in its reply, computes the expected controller response, and sets chap->bi_directional; if the controller then answers with rvalid = 0 the response is never compared, the host still sends success2, and the queue is marked as authenticated.
A malicious or man-in-the-middle controller therefore only has to clear one flag to turn the configured bidirectional authentication into a one-way one, without holding any secret of its own. The target side already treats the mirror image of this as fatal: when the host supplied a challenge but no controller key is configured, nvmet_auth_success1() fails the authentication rather than answering with rvalid = 0.
Refuse the connection if the controller returns no response although bidirectional authentication was requested. chap->bi_directional is the right condition rather than ctrl->ctrl_key, because secure concatenation sends a challenge only to derive the PSK and deliberately clears bi_directional; a one-way setup without a controller secret keeps returning success as before.
--- drivers/nvme/host/auth.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/nvme/host/auth.c +14 -1
@@ -367,8 +367,21 @@ static int nvme_auth_process_dhchap_success1(struct nvme_ctrl *ctrl,nvme_auth_hmac_name (chap->hash_id), nvme_auth_dhgroup_name(chap->dhgroup_id)); -if (!data->rvalid) +if (!data->rvalid) { +/* +* The controller did not return a response. If we asked it to +* authenticate itself the session must not be used, otherwise +* mutual authentication would silently degrade to one-way. +*/ +if (chap->bi_directional) { +dev_warn (ctrl->device, +"qid %d: controller did not authenticate\n" , + chap->qid); + chap->status =NVME_AUTH_DHCHAP_FAILURE_FAILED ; +return -ECONNREFUSED ; + }return 0 ; + }/* Validate controller response */ if (crypto_memneq (chap->response, data->rval, data->hl)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1670/3318 mm/madvise: fix data loss from MADV_FREE on a KSM page
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 22d043c1da48d6c7274f9dd900714b6d58b7b9c6 ]
MADV_FREE can clear the dirty flag of a singly mapped KSM folio. The folio remains in the stable tree and can gain new mappings without being dirtied again. Once marked lazyfree, reclaim can discard data that those mappings still need.
KSM always marks a folio dirty when converting it to a KSM folio in try_to_merge_one_page(). Marking a folio lazyfree clears PG_swapbacked but leaves PG_dirty unchanged. Preserving PG_dirty makes reclaim restore PG_swapbacked instead of discarding the folio. This also protects folios that were already lazyfree when KSM converted them.
Skip KSM folios before clearing their dirty flag, checking under the folio lock to serialize with KSM conversion.
--- mm/madvise.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/madvise.c +9 -0
@@ -707,6 +707,15 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,if (folio_test_swapcache (folio) ||folio_test_dirty (folio)) {if (!folio_trylock (folio))continue ; +/* +* KSM folios can gain new mappings at any time, so we must +* not clear their dirty flag. +*/ +if (folio_test_ksm (folio)) { +folio_unlock (folio); +continue ; + } +/* * If folio is shared with others, we mustn't clear * the folio's dirty flag.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1671/3318 ipmr: prevent info-leak in pmr_cache_report()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 4f34002e2e37639133693c13a2a9977fab86880d ]
Yiming Qian reported:
<quote>
ipmr_cache_report() allocates a report skb with alloc_skb(128, GFP_ATOMIC) and appends a struct igmphdr using skb_put(). In the non-IGMPMSG_WHOLEPKT` path it initializes only:
- igmp->type
- igmp->code
but does not initialize:
- igmp->csum
- igmp->group
Later, igmpmsg_netlink_event() copies the bytes after sizeof(struct igmpmsg) into the IPMRA_CREPORT_PKT netlink attribute and emits RTM_NEWCACHEREPORT on RTNLGRP_IPV4_MROUTE_R.
As a result, 6 bytes of stale heap data from the skb head are disclosed to userspace.
</quote>
Let's use skb_put_zero() instead of skb_put() to fix this bug.
Stable-dep-of: 94a6736bb5ab ("ipmr: only copy pktinfo to cache reports")
--- net/ipv4/ipmr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/ipmr.c +4 -3
@@ -1094,11 +1094,12 @@ static int ipmr_cache_report(const struct mr_table *mrt, msg->im_vif_hi = vifi >>8 ;ipv4_pktinfo_prepare (mroute_sk, pkt, false);memcpy (skb->cb, pkt->cb,sizeof (skb->cb)); -/* Add our header */ - igmp =skb_put (skb,sizeof (struct igmphdr )); +/* Add our header. +* Note that code, csum and group fields are cleared. +*/ + igmp =skb_put_zero (skb,sizeof (struct igmphdr )); igmp->type = assert; msg->im_msgtype = assert; - igmp->code =0 ;ip_hdr (skb)->tot_len =htons (skb->len);/* Fix the length */ skb->transport_header = skb->network_header; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1672/3318 ipmr: only copy pktinfo to cache reports
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 94a6736bb5abe6b2ef38490d0cab19c1c6a7c71f ]
ipmr_cache_report() prepares IP_PKTINFO on the original skb. The ipv4_pktinfo_prepare() helper updates skb->cb and clears the pktinfo fields when packet info is disabled. Since the skb can continue through the data path, preserve and restore its original control block around the helper.
The original implementation copies the entire control block to the report skb. For synthetic RTM_GETROUTE packets, NETLINK_CB data is interpreted as IPCB by the raw IPv4 receive path. With IP_RECVOPTS or IP_RETOPTS enabled, corrupted option offsets cause out-of-bounds reads or a stack buffer overflow. WHOLEPKT and WRVIFWHOLE reports also inherit stale IP option offsets when their header is prepended.
Clear the report skb control block. Only prepare and copy pktinfo when the input skb has an IPv4 header. Synthetic route-query skbs use NETLINK_CB, not IPCB, so leave their report control block zeroed. Restore pkt->cb after preparing pktinfo for regular IPv4 packets.
--- net/ipv4/ipmr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/ipv4/ipmr.c +10 -2
@@ -1037,6 +1037,7 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt,static int ipmr_cache_report (const struct mr_table *mrt,struct sk_buff *pkt,vifi_t vifi,int assert) { +unsigned char pkt_cb[sizeof (pkt->cb)];const int ihl =ip_hdrlen (pkt);struct sock *mroute_sk;struct igmphdr *igmp;
@@ -1092,8 +1093,6 @@ static int ipmr_cache_report(const struct mr_table *mrt, msg = (struct igmpmsg *)skb_network_header (skb); msg->im_vif = vifi; msg->im_vif_hi = vifi >>8 ; -ipv4_pktinfo_prepare (mroute_sk, pkt, false); -memcpy (skb->cb, pkt->cb,sizeof (skb->cb));/* Add our header. * Note that code, csum and group fields are cleared. */
@@ -1104,6 +1103,15 @@ static int ipmr_cache_report(const struct mr_table *mrt, skb->transport_header = skb->network_header; } +memset (skb->cb,0 ,sizeof (skb->cb)); +/* Route queries from ipmr_get_route() carry NETLINK_CB, not IPCB. */ +if (ip_hdr (pkt)->version) { +memcpy (pkt_cb, pkt->cb,sizeof (pkt_cb)); +ipv4_pktinfo_prepare (mroute_sk, pkt, false); + *PKTINFO_SKB_CB (skb) = *PKTINFO_SKB_CB (pkt); +memcpy (pkt->cb, pkt_cb,sizeof (pkt_cb)); + } +igmpmsg_netlink_event (mrt, skb);/* Deliver to mrouted */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1673/3318 coresight/etm4: fix missing disable active config
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
commit 895b12b7d7b8c651f73f57a1ea040d35aa7048cb upstream.
When etm4 device is disabled via sysfs, it should disable its active count.
--- drivers/hwtracing/coresight/coresight-etm4x-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hwtracing/coresight/coresight-etm4x-core.c +3 -0
@@ -1078,6 +1078,9 @@ static void etm4_disable_sysfs(struct coresight_device *csdev)smp_call_function_single (drvdata->cpu, etm4_disable_hw, drvdata,1 );spin_unlock (&drvdata->spinlock); + +cscfg_csdev_disable_active_config (csdev); +cpus_read_unlock ();/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1674/3318 apparmor: check accept index + 1 is in bounds
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanglei Zhu <[email protected]>
[ Upstream commit afe5d5a747393cb3d00795db31d7fce5108a766a ]
aa_lookup_fperms() returns perms[index + 1] when the current fsuid does not match cond->uid, so such an entry consumes two slots in the perms table. But verify_dfa_accept_index() only checks that index is within the perms table, so a policy whose last accept entry is reached with a non-matching fsuid reads perms[index + 1] one entry past the end of the table.
The perms table is allocated by unpack_perms_table() with a u16 size read from the policy blob, so a crafted policy can place an accept entry at index size - 1 to reach the out-of-bounds read.
Check that index + 1 is also in bounds.
--- security/apparmor/policy_unpack.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
security/apparmor/policy_unpack.c +15 -4
@@ -1194,13 +1194,22 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)* verify_dfa_accept_index - verify accept indexes are in range of perms table * @dfa: the dfa to check accept indexes are in range * table_size: the permission table size the indexes should be within +* @pair: the accept indexes reference two slots, index and index + 1 */ -static bool verify_dfa_accept_index (struct aa_dfa *dfa,int table_size) +static bool verify_dfa_accept_index (struct aa_dfa *dfa,int table_size, +bool pair) {int i;for (i =0 ; i < dfa->tables[YYTD_ID_ACCEPT ]->td_lolen; i++) {if (ACCEPT_TABLE (dfa)[i] >= table_size)return false; +/* +* Accept indexes for owner-conditional permissions come +* in pairs, so the non-owner entry at index + 1 must also +* be in bounds. +*/ +if (pair &&ACCEPT_TABLE (dfa)[i] +1 >= table_size) +return false; }return true; }
@@ -1264,15 +1273,17 @@ static int verify_profile(struct aa_profile *profile)if (!rules)return 0 ; -if (rules->file->dfa && !verify_dfa_accept_index (rules->file->dfa, - rules->file->size)) { +if (rules->file->dfa && + !verify_dfa_accept_index (rules->file->dfa, rules->file->size, + rules->file != rules->policy)) {audit_iface (profile,NULL ,NULL ,"Unpack: file Invalid named transition" ,NULL , -EPROTO );return -EPROTO ; }if (rules->policy->dfa && - !verify_dfa_accept_index (rules->policy->dfa, rules->policy->size)) { + !verify_dfa_accept_index (rules->policy->dfa, rules->policy->size, + false)) {audit_iface (profile,NULL ,NULL ,"Unpack: policy Invalid named transition" ,NULL , -EPROTO );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1675/3318 wifi: rtw88: usb: route bmc frames via the high queue only for DTIM delivery
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit c710c7c2e0380d7c0eeb33b686262edcaef7cb07 ]
In AP mode every broadcast and multicast data frame is routed to TX_DESC_QSEL_HIGH, the after-DTIM queue, whether or not anybody is asleep. The firmware drains that queue at beacon pace, a dozen or so frames per second measured on RTL8822BU, while one associated client's mDNS/SSDP chatter alone exceeds that. The excess accumulates inside the chip until the shared TX page pool is exhausted (measured: 14 of 1803 pages left). From that point every host-sourced frame queues behind the backlog: authentication responses reach the air seconds after the client has given up, so no station can associate anymore, and the beacon reserved-page download fails the BCN_VALID poll ("error beacon valid") because it needs pages from the same pool. The AP keeps beaconing, so the failure looks like a silent RX stall and only a reboot recovers.
mac80211 already decides when after-DTIM delivery is needed: it sets IEEE80211_TX_CTL_SEND_AFTER_DTIM on bmc frames only while at least one station is actually dozing. Honor that instead of routing
unconditionally: flagged frames keep going through the high queue with the MORE_DATA and HGQMD handling introduced by commit 076f786a0ae1 ("wifi: rtw88: Fix AP mode incorrect DTIM behavior"), everything else leaves at line rate through the AC queues. This partially reverts the usb.c hunk of that commit, whose unconditional routing is what lets the backlog build up.
On a bench AP (USB2, 20 MHz, WPA2, hostapd, a Windows client driven through disconnect/reconnect cycles): reconnects fail 0/5 on RTL8822BU and 0/3 on RTL8821CU before this change, and pass 10/10 and 5/5 with it, with the page pool staying healthy and no beacon errors logged.
--- drivers/net/wireless/realtek/rtw88/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/usb.c +3 -1
@@ -499,6 +499,7 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)static u8 rtw_usb_tx_queue_mapping_to_qsel (struct sk_buff *skb) {struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);__le16 fc = hdr->frame_control;u8 qsel;
@@ -506,7 +507,8 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) qsel =TX_DESC_QSEL_MGMT ; else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) - qsel =TX_DESC_QSEL_HIGH ; + qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) ? +TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority; else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1676/3318 wifi: rtw88: usb: bound what the driver feeds the after-DTIM queue
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit 04cc8c59a3d79ef7ec2341f1c7aef1d40a0ce7df ]
Frames routed to the high queue are transmitted right after DTIM beacons only, inside the ATIM window, while they wait in the shared TX page pool. The driver puts no limit on how many it hands over, so as long as one station dozes, any sustained broadcast or multicast traffic outruns the drain and empties the pool: measured on an RTL8822BU AP with a single client in power save and ~40 frames/s of mDNS chatter, the free page count at 0x240 goes from 1803 to 16 in about 100 seconds and stays there for as long as the traffic lasts. From that point every other transmit queues behind the backlog, authentication responses arrive too late for anyone to join, and the reserved page download fails ("error beacon valid"). The AP keeps beaconing and only a reboot recovers.
Feed the high queue through a small budget that refills below the measured drain rate (about 3 frames per DTIM, ~15/s at dtim_period 2 on the default 2 TU ATIM window); whatever exceeds the budget leaves on its access category queue right away. The high queue backlog is now bounded by the burst size under any load, so the page pool cannot run dry, at the price that a dozing station may miss part of a broadcast storm.
--- drivers/net/wireless/realtek/rtw88/usb.c | 41 ++++++++++++++++++++++-- drivers/net/wireless/realtek/rtw88/usb.h | 5 +++ 2 files changed, 43 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtw88/usb.c +38 -3
@@ -496,7 +496,37 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)return rtw_usb_write_data (rtwdev, &pkt_info, buf); } -static u8 rtw_usb_tx_queue_mapping_to_qsel (struct sk_buff *skb) +#define RTW_USB_HIQ_REFILL_INTERVAL (HZ / 10)/* one unit of budget per 100 ms */ +#define RTW_USB_HIQ_BUDGET_MAX 16 + +static bool rtw_usb_hiq_take_budget (struct rtw_usb *rtwusb) +{ +unsigned long flags, elapsed, add; +bool ok; + +spin_lock_irqsave (&rtwusb->hiq_lock, flags); + + elapsed = jiffies - rtwusb->hiq_refill; + add = elapsed /RTW_USB_HIQ_REFILL_INTERVAL ; +if (add) { + rtwusb->hiq_budget = min_t(unsigned long, rtwusb->hiq_budget + add, +RTW_USB_HIQ_BUDGET_MAX ); + +/* keep the unfinished part of the interval for the next unit */ + rtwusb->hiq_refill = jiffies - elapsed %RTW_USB_HIQ_REFILL_INTERVAL ; + } + + ok = rtwusb->hiq_budget >0 ; +if (ok) + rtwusb->hiq_budget--; + +spin_unlock_irqrestore (&rtwusb->hiq_lock, flags); + +return ok; +} + +static u8 rtw_usb_tx_queue_mapping_to_qsel (struct rtw_usb *rtwusb, +struct sk_buff *skb) {struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);
@@ -507,7 +537,8 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) qsel =TX_DESC_QSEL_MGMT ; else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) - qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) ? + qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) && +rtw_usb_hiq_take_budget (rtwusb) ?TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority;
@@ -527,7 +558,7 @@ static int rtw_usb_tx_write(struct rtw_dev *rtwdev,u8 *pkt_desc;int ep; - pkt_info->qsel =rtw_usb_tx_queue_mapping_to_qsel (skb); + pkt_info->qsel =rtw_usb_tx_queue_mapping_to_qsel (rtwusb, skb); pkt_desc =skb_push (skb, chip->tx_pkt_desc_sz);memset (pkt_desc,0 , chip->tx_pkt_desc_sz); ep =qsel_to_ep (rtwusb, pkt_info->qsel);
@@ -795,6 +826,10 @@ static int rtw_usb_init_tx(struct rtw_dev *rtwdev)struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);int i; +spin_lock_init (&rtwusb->hiq_lock); + rtwusb->hiq_budget =RTW_USB_HIQ_BUDGET_MAX ; + rtwusb->hiq_refill = jiffies; + rtwusb->txwq =create_singlethread_workqueue ("rtw88_usb: tx wq" );if (!rtwusb->txwq) {rtw_err (rtwdev,"failed to create TX work queue\n" );
drivers/net/wireless/realtek/rtw88/usb.h +5 -0
@@ -74,6 +74,11 @@ struct rtw_usb {u8 out_ep[RTW_USB_EP_MAX ];int qsel_to_ep[TX_DESC_QSEL_MAX ]; +/* protects hiq_budget and hiq_refill */ +spinlock_t hiq_lock; +u32 hiq_budget; +unsigned long hiq_refill; +struct workqueue_struct *txwq, *rxwq;struct sk_buff_head tx_queue[RTW_USB_EP_MAX ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1677/3318 wifi: rtw88: usb: only let the frames a dozing station needs use the after-DTIM queue
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit 185971f1b4eb4ea9059d76cf1a18f992eef998c1 ]
With the budget in place the high queue can no longer take the chip down, but ordinary chatter still competes with the frames a sleeping station actually needs. mac80211 marks every broadcast and multicast frame with IEEE80211_TX_CTL_SEND_AFTER_DTIM while a station dozes, mDNS and SSDP included, so under normal traffic the budget is spent on frames nobody waits for.
Do what the vendor driver does with its default "allow special" high queue filter: admit only ARP, EAPOL and DHCP to the after-DTIM path, the frames a station coming out of power save has to see; everything else goes out on its access category queue at line rate. The frames are classified the way rtw89_core_tx_btc_spec_pkt_notify() does it, from skb->protocol and the network and transport header offsets that mac80211 keeps from the netdev path; EAPOL is the control port flag. Frames the AP relays between its own stations arrive as ETH_P_802_3 and are not inspected, they leave on the access category queue.
With the filter in place the page pool stays at 1803 through the same 180 second storm, a DHCP flood still takes the after-DTIM path (and is then held by the budget), and join/ping cycling without power save is unchanged (10/10).
--- drivers/net/wireless/realtek/rtw88/usb.c | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/usb.c +25 -2
@@ -2,9 +2,11 @@/* Copyright(c) 2018-2019 Realtek Corporation */ +#include <linux/ip.h> #include <linux/module.h> -#include <linux/usb.h> #include <linux/mutex.h> +#include <linux/udp.h> +#include <linux/usb.h> #include "main.h" #include "debug.h" #include "reg.h"
@@ -496,6 +498,27 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)return rtw_usb_write_data (rtwdev, &pkt_info, buf); } +static bool rtw_usb_bmc_needs_dtim (struct sk_buff *skb) +{ +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb); +struct udphdr *udphdr; + +if (info->control.flags &IEEE80211_TX_CTRL_PORT_CTRL_PROTO ) +return true; + +if (skb->protocol ==htons (ETH_P_ARP )) +return true; + +if (skb->protocol ==htons (ETH_P_IP ) && +ip_hdr (skb)->protocol ==IPPROTO_UDP ) { + udphdr =udp_hdr (skb); + +return udphdr->dest ==htons (67 ) || udphdr->dest ==htons (68 ); + } + +return false; +} +#define RTW_USB_HIQ_REFILL_INTERVAL (HZ / 10)/* one unit of budget per 100 ms */ #define RTW_USB_HIQ_BUDGET_MAX 16
@@ -538,7 +561,7 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct rtw_usb *rtwusb,else if (is_broadcast_ether_addr (hdr->addr1) ||is_multicast_ether_addr (hdr->addr1)) qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) && -rtw_usb_hiq_take_budget (rtwusb) ? +rtw_usb_bmc_needs_dtim (skb) &&rtw_usb_hiq_take_budget (rtwusb) ?TX_DESC_QSEL_HIGH : skb->priority;else if (skb_get_queue_mapping (skb) <=IEEE80211_AC_BK ) qsel = skb->priority;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1678/3318 wifi: rtw88: widen the ATIM window while an AP interface is up
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit cf8b516f67652f550e040951b88a2040b375afcf ]
The frames held for dozing stations go out right after the DTIM beacon and only for the duration of the ATIM window. The chips come up with a 2 TU window (the two that program it set 0x2 at init), which drains about three frames per DTIM; the vendor driver sets 0xa or 0xc in AP mode instead. With the 2 TU window the measured page pool exhaustion takes ~100 s of ordinary multicast chatter; at 0x4 the same storm already drains, so 0xa leaves comfortable headroom.
Program 0xa when an AP interface starts and put the default back when it stops, since most chips never initialize the register themselves. The bound and the filter of the previous patches still apply: the window adds drain capacity, the budget protects the pool when that is not enough, the filter keeps chatter off the beacon-paced path.
--- drivers/net/wireless/realtek/rtw88/mac80211.c | 2 ++ drivers/net/wireless/realtek/rtw88/reg.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/net/wireless/realtek/rtw88/mac80211.c +2 -0
@@ -455,6 +455,7 @@ static int rtw_ops_start_ap(struct ieee80211_hw *hw,mutex_lock (&rtwdev->mutex);rtw_write32_set (rtwdev,REG_TCR ,BIT_TCR_UPDATE_HGQMD ); +rtw_write16 (rtwdev,REG_ATIMWND ,ATIMWND_AP ); rtwdev->ap_active = true;rtw_store_op_chan (rtwdev, true); chip->ops->phy_calibration (rtwdev);
@@ -471,6 +472,7 @@ static void rtw_ops_stop_ap(struct ieee80211_hw *hw,mutex_lock (&rtwdev->mutex);rtw_write32_clr (rtwdev,REG_TCR ,BIT_TCR_UPDATE_HGQMD ); +rtw_write16 (rtwdev,REG_ATIMWND ,ATIMWND_DEFAULT ); rtwdev->ap_active = false;if (!rtw_core_check_sta_active (rtwdev))rtw_clear_op_chan (rtwdev);
drivers/net/wireless/realtek/rtw88/reg.h +2 -0
@@ -397,6 +397,8 @@#define REG_DRVERLYINT 0x0558#define REG_BCNDMATIM 0x0559#define REG_ATIMWND 0x055A +#define ATIMWND_DEFAULT 0x2 +#define ATIMWND_AP 0xa#define REG_USTIME_TSF 0x055C#define REG_BCN_MAX_ERR 0x055D#define REG_RXTSF_OFFSET_CCK 0x055E
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1679/3318 drm/nouveau/pci: use config-space MSI rearm on MCP79/MCP7A (NVAC)
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Czernohous <[email protected]>
commit 354d47fb3f35461b7f942831c1b2a7105e92b57f upstream.
NVAC (MCP79/MCP7A) uses g94_pci_func, whose .msi_rearm is nv40_pci_msi_rearm(): a re-arm write through the MMIO mirror of PCI config space. On this IGP that path is unreliable; when a re-arm is missed the interrupt line stays dead, command submission times out and the GPU appears hung until reboot. On an Apple Mac mini (early 2009, MCP79, boot0 0x0ac080b1) this showed as sporadic fifo timeouts and GPU hangs under load unless MSI was disabled via config=NvMSI=0.
Give NVAC its own pci func that re-arms through real PCI config space (nv46_pci_msi_rearm) instead. This follows existing precedent: nv46.c documents the MMIO-mirror re-arm as broken on several related parts, and commit 5112abc6a433 ("drm/nouveau/pci/g92: Fix rearm") fixed g92 the same way while moving the remaining chipsets, NVAC included, into the newly added shared g94 table, where NVAC stayed on the MMIO path. This change completes that fix for NVAC. The sibling IGP NVAA (MCP77/MCP78) has MSI disabled entirely as "reported broken" in nvkm_pci_new_(); NVAC works correctly once the re-arm goes through config space, so disabling MSI is not necessary.
Only NVAC is switched: that is the hardware this has been validated on. The other users of g94_pci_func (G94/G96/G98/GT2xx and the MCP77/MCP89 IGPs) keep their current behavior; MCP77 and MCP89 plausibly want the same treatment but were not tested.
Tested on the Mac mini as a daily driver for two months with MSI enabled and zero fifo timeouts. Independently confirmed stable on an iMac9,1 (MCP79) running 6.12.90 with the v1 form of this change (the same one-line functional switch, applied to that kernel's g94 implementation).
[ Backport note: linux-6.6.y predates commit 2f89bb3264af
("drm/nouveau/pci: add PRI address of config space mirror to nvkm_pci_func"), so struct nvkm_pci_func has no .cfg member here. mcp79_pci_func uses the nv40 .rd32/.wr08/.wr32 accessors instead, exactly as g94_pci_func does in this tree, and still differs from g94_pci_func only in .msi_rearm. ]
--- .../gpu/drm/nouveau/include/nvkm/subdev/pci.h | 1 + .../gpu/drm/nouveau/nvkm/engine/device/base.c | 2 +- .../gpu/drm/nouveau/nvkm/subdev/pci/Kbuild | 1 + .../gpu/drm/nouveau/nvkm/subdev/pci/mcp79.c | 36 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/pci/mcp79.c
drivers/gpu/drm/nouveau/include/nvkm/subdev/pci.h +1 -0
@@ -46,6 +46,7 @@ int nv4c_pci_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nint g84_pci_new (struct nvkm_device *,enum nvkm_subdev_type ,int inst,struct nvkm_pci **);int g92_pci_new (struct nvkm_device *,enum nvkm_subdev_type ,int inst,struct nvkm_pci **);int g94_pci_new (struct nvkm_device *,enum nvkm_subdev_type ,int inst,struct nvkm_pci **); +int mcp79_pci_new (struct nvkm_device *,enum nvkm_subdev_type ,int inst,struct nvkm_pci **);int gf100_pci_new (struct nvkm_device *,enum nvkm_subdev_type ,int inst,struct nvkm_pci **);int gf106_pci_new (struct nvkm_device *,enum nvkm_subdev_type ,int inst,struct nvkm_pci **);int gk104_pci_new (struct nvkm_device *,enum nvkm_subdev_type ,int inst,struct nvkm_pci **);
drivers/gpu/drm/nouveau/nvkm/engine/device/base.c +1 -1
@@ -1285,7 +1285,7 @@ nvac_chipset = { .mc = { 0x00000001, g98_mc_new }, .mmu = { 0x00000001, mcp77_mmu_new }, .mxm = { 0x00000001, nv50_mxm_new }, - .pci = { 0x00000001, g94_pci_new }, + .pci = { 0x00000001, mcp79_pci_new }, .therm = { 0x00000001, g84_therm_new }, .timer = { 0x00000001, nv41_timer_new }, .volt = { 0x00000001, nv40_volt_new },
drivers/gpu/drm/nouveau/nvkm/subdev/pci/Kbuild +1 -0
@@ -9,6 +9,7 @@ nvkm-y += nvkm/subdev/pci/nv4c.o nvkm-y += nvkm/subdev/pci/g84.o nvkm-y += nvkm/subdev/pci/g92.o nvkm-y += nvkm/subdev/pci/g94.o +nvkm-y += nvkm/subdev/pci/mcp79.o nvkm-y += nvkm/subdev/pci/gf100.o nvkm-y += nvkm/subdev/pci/gf106.o nvkm-y += nvkm/subdev/pci/gk104.o
drivers/gpu/drm/nouveau/nvkm/subdev/pci/mcp79.c new file +36 -0
@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2026 Marek Czernohous +* +* MCP79/MCP7A (NVAC): like g94, but MSI re-arm goes through real PCI +* config space. The MMIO-mirror re-arm is unreliable on this IGP and a +* missed re-arm kills the interrupt line (see the nv46 comment; g92 +* already re-arms through config space for the same reason). +*/ +#include "priv.h" + +static const struct nvkm_pci_func +mcp79_pci_func = { + .init = g84_pci_init, + .rd32 = nv40_pci_rd32, + .wr08 = nv40_pci_wr08, + .wr32 = nv40_pci_wr32, + .msi_rearm = nv46_pci_msi_rearm, + + .pcie.init = g84_pcie_init, + .pcie.set_link = g84_pcie_set_link, + + .pcie.max_speed = g84_pcie_max_speed, + .pcie.cur_speed = g84_pcie_cur_speed, + + .pcie.set_version = g84_pcie_set_version, + .pcie.version = g84_pcie_version, + .pcie.version_supported = g92_pcie_version_supported, +}; + +int +mcp79_pci_new (struct nvkm_device *device,enum nvkm_subdev_type type,int inst, +struct nvkm_pci **ppci) +{ +return nvkm_pci_new_ (&mcp79_pci_func, device, type, inst, ppci); +}
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1680/3318 drm/nouveau: disable the fence uevent work instead of just cancelling it
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Czernohous <[email protected]>
commit 827eb9328eaed831d7cc426ac2705038a40835b6 upstream.
nouveau_fence_context_del() drains the uevent work while the event that feeds it is still armed:
cancel_work_sync(&fctx->uevent_work); nouveau_fence_context_kill(fctx, 0); nvif_event_dtor(&fctx->event);
nouveau_fence_wait_uevent_handler() queues the work unconditionally:
schedule_work(&fctx->uevent_work); return NVIF_EVENT_KEEP;
so a non-stall interrupt arriving after cancel_work_sync() has returned re-arms the work that was just drained. The window closes in two steps, neither of which is the drain. The kill blocks the event when the last fence holding a notify_ref is signalled, which reaches atomic_xchg(&ntfy->allowed, 0) (nvkm/core/event.c:104), and nvkm_event_ntfy() skips a ntfy that is not allowed (:183). That stops further handlers from starting, but not one that is already inside nvkm_event_ntfy(): the event is created with wait = false (nouveau_fence.c:201), so nvkm_event_ntfy_block_() leaves it on the list and never takes event->list_lock. Only nvif_event_dtor() waits that one
out: nvkm_event_ntfy_del() (:141) goes through nvkm_event_ntfy_remove(), which takes write_lock_irq() on that same list_lock (:84).
Either way the re-arm happens after the drain, and the caller drops its reference immediately afterwards, for example nv84_fence_context_del():
nouveau_fence_context_del(&fctx->base); chan->fence = NULL; nouveau_fence_context_free(&fctx->base);
That is a kref_put() on fctx->fence_ref, so the context outlives the teardown only while emitted fences still hold a reference of their own. That is no safety net: whenever none do, the count reaches zero right there and nouveau_fence_context_put() kfree()s fctx while the work is still queued. &fctx->uevent_work is embedded in that allocation, so the workqueue already dereferences freed memory when it picks the item up, and nouveau_fence_uevent_work() can then take fctx->lock on it. With CONFIG_DEBUG_OBJECTS_WORK and CONFIG_DEBUG_OBJECTS_FREE, kfree() of a still-queued work item is reported as the free of an active object.
On live memory the re-armed work has nothing left to do:nouveau_fence_context_kill() empties fctx->pending and sets fctx->killed under fctx->lock, nouveau_fence_emit() then returns -ENODEV rather than queueing anything new, and nouveau_fence_update() only reaches nvif_event_block() if it signalled something off that list. The defect is the access to freed memory, not what the work would have found.
Only chips from G84 on can reach this at all: nouveau_fence_context_new() returns before nvif_event_ctor() when priv->uevent is clear, and nv84_fence_create() is the only place that sets it. nv84_fence_context_del() is the context_del for all of those, because nvc0_fence_create() and gv100_fence_create() build on nv84_fence_create() and override only context_new.
Use disable_work_sync() instead. It drains the work exactly like cancel_work_sync() does, and additionally increments the work item's disable count, after which "any attempt to queue @work will fail and return %false" (kernel/workqueue.c, disable_work()). The handler's schedule_work() then has nothing to re-arm, and the teardown order stays as it is.
Draining a second time after nvif_event_dtor() would close the window as well, and without the newer API: once nvkm_event_ntfy_remove() has returned, no handler can start or still be running, so nothing re-arms the work past that point. disable_work_sync() is preferred here because it needs one synchronisation point instead of two, it keeps the work from being queued at all rather than cleaning up after it, and it is what drm has settled on for this (drm/xe, drm/panthor, drm_pagemap). Blocking the event rather than the work is not an option: fctx->event is created with wait = false, so a handler already inside nvkm_event_ntfy() can still queue the work.
Note for backports: disable_work_sync() arrived in v6.10 with commit 86898fa6b8cd ("workqueue: Implement disable/enable for (delayed) work items"), while the fix being corrected here reached 6.6.18 and 6.7.6. linux-6.6.y therefore carries this bug without the API, and this patch would apply there and then fail to build. A 6.6.y backport wants the second drain described above instead, as its own patch.
[ Backport note: linux-6.6.y carries the uevent work (commit
39126abc5e20 reached 6.6.18) but not disable_work_sync(), which arrived in v6.10 with commit 86898fa6b8cd ("workqueue: Implement disable/enable for (delayed) work items"). As described above, drain the work a second time after nvif_event_dtor() instead: once nvkm_event_ntfy_remove() has returned, no handler can start or still be running, so nothing can re-queue the work past that point. The first drain is left in place. ]
--- drivers/gpu/drm/nouveau/nouveau_fence.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/nouveau/nouveau_fence.c +6 -0
@@ -106,6 +106,12 @@ nouveau_fence_context_del(struct nouveau_fence_chan *fctx)cancel_work_sync (&fctx->uevent_work);nouveau_fence_context_kill (fctx,0 );nvif_event_dtor (&fctx->event); +/* +* The event handler can re-queue uevent_work after the drain above. +* nvif_event_dtor() has waited out any running handler and no new +* one can start, so drain once more before the context goes away. +*/ +cancel_work_sync (&fctx->uevent_work); fctx->dead =1 ;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1681/3318 mm/page-writeback: avoid 32-bit overflow in dirty threshold shares
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 9597c2056e05bd79df9d343a9b42e84a54de1c52 ]
The ratios used by __wb_calc_thresh() are scaled to parts per million, but the threshold and ratio operands are unsigned long. On 32-bit kernels, their multiplication can wrap before the result is assigned to u64.
For example, with a threshold of 25600 pages and the default maximum ratio of 1000000, wb_max_thresh becomes 4125 pages instead of 25600. The shared threshold and minimum share calculations can overflow in the same way, producing incorrect per-writeback dirty limits.
Use a u64 threshold for the three ratio multiplications and div_u64() to retain the existing division order and rounding.
In 6.6, __wb_calc_thresh() gets the threshold from dtc->thresh and has no freerun adjustment here. Widen the local threshold and compute the maximum share once for the existing clamp.
--- mm/page-writeback.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
mm/page-writeback.c +8 -5
@@ -883,8 +883,9 @@ static void mdtc_calc_avail(struct dirty_throttle_control *mdtc,static unsigned long __wb_calc_thresh (struct dirty_throttle_control *dtc) {struct wb_domain *dom =dtc_dom (dtc); -unsigned long thresh = dtc->thresh; +u64 thresh = dtc->thresh;u64 wb_thresh; +u64 wb_max_thresh;unsigned long numerator, denominator;unsigned long wb_min_ratio, wb_max_ratio;
@@ -894,15 +895,17 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc)fprop_fraction_percpu (&dom->completions, dtc->wb_completions, &numerator, &denominator); - wb_thresh = (thresh * (100 *BDI_RATIO_SCALE - bdi_min_ratio)) / (100 *BDI_RATIO_SCALE ); + wb_thresh =div_u64 (thresh * (100 *BDI_RATIO_SCALE - bdi_min_ratio), +100 *BDI_RATIO_SCALE ); wb_thresh *= numerator; wb_thresh =div64_ul (wb_thresh, denominator);wb_min_max_ratio (dtc->wb, &wb_min_ratio, &wb_max_ratio); - wb_thresh += (thresh * wb_min_ratio) / (100 *BDI_RATIO_SCALE ); -if (wb_thresh > (thresh * wb_max_ratio) / (100 *BDI_RATIO_SCALE )) - wb_thresh = thresh * wb_max_ratio / (100 *BDI_RATIO_SCALE ); + wb_thresh +=div_u64 (thresh * wb_min_ratio,100 *BDI_RATIO_SCALE ); + wb_max_thresh =div_u64 (thresh * wb_max_ratio,100 *BDI_RATIO_SCALE ); +if (wb_thresh > wb_max_thresh) + wb_thresh = wb_max_thresh;return wb_thresh; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1682/3318 udf: validate the device specification EA before using it
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunpeng Tian <[email protected]>
[ Upstream commit 9a2390959685ac35a58c80c8016120849a2babf6 ]
udf_get_extendedattr() bounds an extended attribute only against struct genericFormat, which is 12 bytes. A type-12 device specification is struct deviceSpec, which is 24 bytes plus a flexible impUse array. Thus a corrupted filesystem can contain extended attribute that is accepted by udf_get_extendedattr() but udf_write_inode() or udf_read_inode() may access beyond the end of provided buffer.
Provide a udf_device_spec_valid() check to validate correctness of extended attribute that is a deviceSpec. While here, check the result of udf_add_extendedattr() before dereferencing it as it can return NULL in case of error.
[JK: Removed duplicated validity checks]
--- fs/udf/inode.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-)
fs/udf/inode.c +37 -5
@@ -1344,6 +1344,26 @@ int udf_setsize(struct inode *inode, loff_t newsize)return err; } +/* +* Verify validity of struct deviceSpec on disk. udf_get_extendedattr() has +* already verified the generic header and made sure attribute fits in the +* inode so we just have to make sure attribute space is large enough for +* deviceSpec struct and required impUse information. +*/ +static bool udf_device_spec_valid (struct deviceSpec *dsea) +{ +u32 attr_length, imp_use_length; + + attr_length =le32_to_cpu (dsea->attrLength); + imp_use_length =le32_to_cpu (dsea->impUseLength); +if (attr_length <sizeof (struct deviceSpec ) || + imp_use_length <sizeof (struct regid ) || + imp_use_length > attr_length -sizeof (struct deviceSpec )) +return false; + +return true; +} +/* * Maximum length of linked list formed by ICB hierarchy. The chosen number is * arbitrary - just that we hopefully don't limit any real use of rewritten
@@ -1658,13 +1678,12 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)if (S_ISCHR (inode->i_mode) ||S_ISBLK (inode->i_mode)) {struct deviceSpec *dsea = (struct deviceSpec *)udf_get_extendedattr (inode,12 ,1 ); -if (dsea) { -init_special_inode (inode, inode->i_mode, + +if (!dsea || !udf_device_spec_valid (dsea)) + goto out; +init_special_inode (inode, inode->i_mode,MKDEV (le32_to_cpu (dsea->majorDeviceIdent),le32_to_cpu (dsea->minorDeviceIdent))); -/* Developer ID ??? */ - }else - goto out; } ret =0 ; out:
@@ -1812,6 +1831,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)udf_add_extendedattr (inode,sizeof (struct deviceSpec ) +sizeof (struct regid ),12 ,0x3 ); +if (!dsea) { + err = -ENOSPC ; + goto out_unlock; + } dsea->attrType =cpu_to_le32 (12 ); dsea->attrSubtype =1 ; dsea->attrLength = cpu_to_le32(
@@ -1819,6 +1842,10 @@ static int udf_update_inode(struct inode *inode, int do_sync) sizeof(struct regid)); dsea->impUseLength =cpu_to_le32 (sizeof (struct regid )); } +if (!udf_device_spec_valid (dsea)) { + err = -EFSCORRUPTED ; + goto out_unlock; + } eid = (struct regid *)dsea->impUse;memset (eid,0 ,sizeof (*eid));strcpy (eid->ident,UDF_ID_DEVELOPER );
@@ -1958,6 +1985,11 @@ static int udf_update_inode(struct inode *inode, int do_sync)brelse (bh);return err; + +out_unlock: +unlock_buffer (bh); +brelse (bh); +return err; } struct inode *__udf_iget(struct super_block *sb, struct kernel_lb_addr *ino,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1683/3318 hwmon: (tmp108) Fix jiffies wraparound in conversion-ready check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Verdonck <[email protected]>
[ Upstream commit 6b8b1d1d7bc7e579b53fc7c3293b787d68de702a ]
tmp108 records a one-shot deadline in ->ready_time at probe (and resume) and, on every temperature read, refuses the read with -EAGAIN while time_before(jiffies, ready_time) is true, in order to skip the initial conversion.
->ready_time is an unsigned long compared with time_before(), whose signed difference is only meaningful while the two values are within LONG_MAX jiffies of each other. Because ->ready_time is set once and never refreshed, jiffies keeps advancing away from it, and after 2^31 jiffies the difference flips sign. On a 32-bit HZ=100 kernel that happens ~248.5 days after boot: time_before() then permanently reports "not ready" and the driver returns -EAGAIN on every read, without ever touching the sensor, until the next reboot. The continuous-mode path, which sets ->ready_time to jiffies with no added conversion delay, wraps the same way.
Store the deadline as a 64-bit jiffies value and compare it with get_jiffies_64()/time_before64(), which does not wrap in any practical uptime.
--- drivers/hwmon/tmp108.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/tmp108.c +4 -4
@@ -73,7 +73,7 @@struct tmp108 {struct regmap *regmap;u16 orig_config; -unsigned long ready_time; +u64 ready_time; };/* convert 12-bit TMP108 register value to milliCelsius */
@@ -124,7 +124,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input:/* Is it too early to return a conversion ? */ -if (time_before (jiffies, tmp108->ready_time)) { +if (time_before64 (get_jiffies_64 (), tmp108->ready_time)) {dev_dbg (dev,"%s: Conversion not ready yet..\n" , __func__);return -EAGAIN ;
@@ -371,7 +371,7 @@ static int tmp108_probe(struct i2c_client *client)return err; } - tmp108->ready_time = jiffies; + tmp108->ready_time =get_jiffies_64 ();if ((tmp108->orig_config &TMP108_CONF_MODE_MASK ) ==TMP108_MODE_SHUTDOWN ) tmp108->ready_time +=
@@ -405,7 +405,7 @@ static int tmp108_resume(struct device *dev) err =regmap_update_bits (tmp108->regmap,TMP108_REG_CONF ,TMP108_CONF_MODE_MASK ,TMP108_MODE_CONTINUOUS ); - tmp108->ready_time = jiffies + + tmp108->ready_time =get_jiffies_64 () +msecs_to_jiffies (TMP108_CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1684/3318 dmaengine: qcom: bam_dma: Defer IRQ trigger type to device tree
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vishnu Santhosh <[email protected]>
[ Upstream commit 3cee6f79553202d7d3954555560ac38d719344b8 ]
The driver hardcodes IRQF_TRIGGER_HIGH when registering the BAM interrupt, which overrides the trigger type specified in the device tree. On Qualcomm Shikra SoC, the A2 BAM signals an edge interrupt to the apps processor; registering it as level-high causes the interrupt to not fire, resulting in missed DMA completions.
Use IRQF_TRIGGER_NONE instead, which causes the kernel to use the trigger type already configured by platform_get_irq() when it parsed the device tree interrupts property. This makes the driver platform-agnostic.
Stable-dep-of: 82eed160cfa7 ("dmaengine: qcom: bam_dma: free interrupt before the clock in error path")
--- drivers/dma/qcom/bam_dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/qcom/bam_dma.c +1 -1
@@ -1323,7 +1323,7 @@ static int bam_dma_probe(struct platform_device *pdev)bam_channel_init (bdev, &bdev->channels[i], i); ret =devm_request_irq (bdev->dev, bdev->irq, bam_dma_irq, -IRQF_TRIGGER_HIGH ,"bam_dma" , bdev); +IRQF_TRIGGER_NONE ,"bam_dma" , bdev);if (ret) goto err_bam_channel_exit;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1685/3318 dmaengine: qcom: bam_dma: free interrupt before the clock in error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 82eed160cfa7a296ae4eb5acb8dd8f493323eea7 ]
The BAM interrupt is requested with a devres helper and so on error it's freed after probe() returns. We disable the clock before freeing or masking it so it may still fire and we may end up reading BAM registers with clock disabled.
Stop using devres for interrupts as we free it in remove() manually anyway. Add an appropriate label and free the interrupt before disabling the clock in error path and in remove().
--- drivers/dma/qcom/bam_dma.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/dma/qcom/bam_dma.c +7 -5
@@ -1322,8 +1322,8 @@ static int bam_dma_probe(struct platform_device *pdev)for (i =0 ; i < bdev->num_channels; i++)bam_channel_init (bdev, &bdev->channels[i], i); - ret =devm_request_irq (bdev->dev, bdev->irq, bam_dma_irq, -IRQF_TRIGGER_NONE ,"bam_dma" , bdev); + ret =request_irq (bdev->irq, bam_dma_irq,IRQF_TRIGGER_NONE , +"bam_dma" , bdev);if (ret) goto err_bam_channel_exit;
@@ -1332,7 +1332,7 @@ static int bam_dma_probe(struct platform_device *pdev) ret =dma_set_max_seg_size (bdev->common.dev,BAM_FIFO_SIZE );if (ret) {dev_err (bdev->dev,"cannot set maximum segment size\n" ); - goto err_bam_channel_exit; + goto err_free_irq; }platform_set_drvdata (pdev, bdev);
@@ -1360,7 +1360,7 @@ static int bam_dma_probe(struct platform_device *pdev) ret =dma_async_device_register (&bdev->common);if (ret) {dev_err (bdev->dev,"failed to register dma async device\n" ); - goto err_bam_channel_exit; + goto err_free_irq; } ret = of_dma_controller_register(pdev->dev.of_node, bam_dma_xlate,
@@ -1379,6 +1379,8 @@ static int bam_dma_probe(struct platform_device *pdev) err_unregister_dma:dma_async_device_unregister (&bdev->common); +err_free_irq: +free_irq (bdev->irq, bdev); err_bam_channel_exit:for (i =0 ; i < bdev->num_channels; i++)tasklet_kill (&bdev->channels[i].vc.task);
@@ -1404,7 +1406,7 @@ static int bam_dma_remove(struct platform_device *pdev)/* mask all interrupts for this execution environment */ writel_relaxed (0 ,bam_addr (bdev,0 ,BAM_IRQ_SRCS_MSK_EE )); -devm_free_irq (bdev->dev, bdev->irq, bdev); +free_irq (bdev->irq, bdev);for (i =0 ; i < bdev->num_channels; i++) {bam_dma_terminate_all (&bdev->channels[i].vc.chan);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1686/3318 nilfs2: correct return value kernel-doc descriptions for the rest
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryusuke Konishi <[email protected]>
[ Upstream commit 343d4a33f26d048fde4b02cfc3681f766b3f1b12 ]
Similar to the previous changes to fix return value descriptions, this fixes the format of the return value descriptions of functions for the rest.
Stable-dep-of: 7131aaa74bcc ("nilfs2: ignore non-fatal signals during synchronous log write wait")
--- fs/nilfs2/gcinode.c | 24 +++++++++------------- fs/nilfs2/inode.c | 12 +++-------- fs/nilfs2/recovery.c | 32 +++++++++++------------------ fs/nilfs2/segbuf.c | 12 ++--------- fs/nilfs2/segment.c | 48 ++++++++++++++++--------------------------- fs/nilfs2/the_nilfs.c | 12 +++++------ 6 files changed, 50 insertions(+), 90 deletions(-)
fs/nilfs2/gcinode.c +10 -14
@@ -46,14 +46,11 @@* specified by @pbn to the GC pagecache with the key @blkoff. * This function sets @vbn (@pbn if @vbn is zero) in b_blocknr of the buffer. * -* Return Value: On success, 0 is returned. On Error, one of the following -* negative error code is returned. -* -* %-EIO - I/O error. -* -* %-ENOMEM - Insufficient amount of memory available. -* -* %-ENOENT - The block specified with @pbn does not exist. +* Return: 0 on success, or one of the following negative error codes on +* failure: +* * %-EIO - I/O error (including metadata corruption). +* * %-ENOENT - The block specified with @pbn does not exist. +* * %-ENOMEM - Insufficient memory available. */ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff, sector_t pbn, __u64 vbn,
@@ -114,12 +111,11 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,* specified by @vbn to the GC pagecache. @pbn can be supplied by the * caller to avoid translation of the disk block address. * -* Return Value: On success, 0 is returned. On Error, one of the following -* negative error code is returned. -* -* %-EIO - I/O error. -* -* %-ENOMEM - Insufficient amount of memory available. +* Return: 0 on success, or one of the following negative error codes on +* failure: +* * %-EIO - I/O error (including metadata corruption). +* * %-ENOENT - Invalid virtual block address. +* * %-ENOMEM - Insufficient memory available. */ int nilfs_gccache_submit_read_node (struct inode *inode,sector_t pbn,__u64 vbn,struct buffer_head **out_bh)
fs/nilfs2/inode.c +3 -9
@@ -676,10 +676,7 @@ struct inode *nilfs_iget_for_gc(struct super_block *sb, unsigned long ino,* or does nothing if the inode already has it. This function allocates * an additional inode to maintain page cache of B-tree nodes one-on-one. * -* Return Value: On success, 0 is returned. On errors, one of the following -* negative error code is returned. -* -* %-ENOMEM - Insufficient memory available. +* Return: 0 on success, or %-ENOMEM if memory is insufficient. */ int nilfs_attach_btree_node_cache (struct inode *inode) {
@@ -740,11 +737,8 @@ void nilfs_detach_btree_node_cache(struct inode *inode)* in one inode and the one for b-tree node pages is set up in the * other inode, which is attached to the former inode. * -* Return Value: On success, a pointer to the inode for data pages is -* returned. On errors, one of the following negative error code is returned -* in a pointer type. -* -* %-ENOMEM - Insufficient memory available. +* Return: a pointer to the inode for data pages on success, or %-ENOMEM +* if memory is insufficient. */ struct inode *nilfs_iget_for_shadow (struct inode *inode) {
fs/nilfs2/recovery.c +12 -20
@@ -741,18 +741,13 @@ static void nilfs_abort_roll_forward(struct the_nilfs *nilfs)* @sb: super block instance * @ri: pointer to a nilfs_recovery_info struct to store search results. * -* Return Value: On success, 0 is returned. On error, one of the following -* negative error code is returned. -* -* %-EINVAL - Inconsistent filesystem state. -* -* %-EIO - I/O error -* -* %-ENOSPC - No space left on device (only in a panic state). -* -* %-ERESTARTSYS - Interrupted. -* -* %-ENOMEM - Insufficient memory available. +* Return: 0 on success, or one of the following negative error codes on +* failure: +* * %-EINVAL - Inconsistent filesystem state. +* * %-EIO - I/O error. +* * %-ENOMEM - Insufficient memory available. +* * %-ENOSPC - No space left on device (only in a panic state). +* * %-ERESTARTSYS - Interrupted. */ int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
@@ -817,14 +812,11 @@ int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,* segment pointed by the superblock. It sets up struct the_nilfs through * this search. It fills nilfs_recovery_info (ri) required for recovery. * -* Return Value: On success, 0 is returned. On error, one of the following -* negative error code is returned. -* -* %-EINVAL - No valid segment found -* -* %-EIO - I/O error -* -* %-ENOMEM - Insufficient memory available. +* Return: 0 on success, or one of the following negative error codes on +* failure: +* * %-EINVAL - No valid segment found. +* * %-EIO - I/O error. +* * %-ENOMEM - Insufficient memory available. */ int nilfs_search_super_root (struct the_nilfs *nilfs,struct nilfs_recovery_info *ri)
fs/nilfs2/segbuf.c +2 -10
@@ -403,12 +403,7 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf,* @segbuf: buffer storing a log to be written * @nilfs: nilfs object * -* Return Value: On Success, 0 is returned. On Error, one of the following -* negative error code is returned. -* -* %-EIO - I/O error -* -* %-ENOMEM - Insufficient memory available. +* Return: Always 0. */ static int nilfs_segbuf_write (struct nilfs_segment_buffer *segbuf,struct the_nilfs *nilfs)
@@ -449,10 +444,7 @@ static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,* nilfs_segbuf_wait - wait for completion of requested BIOs * @segbuf: segment buffer * -* Return Value: On Success, 0 is returned. On Error, one of the following -* negative error code is returned. -* -* %-EIO - I/O error +* Return: 0 on success, or %-EIO if I/O error is detected. */ static int nilfs_segbuf_wait (struct nilfs_segment_buffer *segbuf) {
fs/nilfs2/segment.c +18 -30
66 lines not on this page · raw message
fs/nilfs2/the_nilfs.c +5 -7
@@ -50,8 +50,8 @@ void nilfs_set_last_segment(struct the_nilfs *nilfs,* alloc_nilfs - allocate a nilfs object * @sb: super block instance * -* Return Value: On success, pointer to the_nilfs is returned. -* On error, NULL is returned. +* Return: a pointer to the allocated nilfs object on success, or NULL on +* failure. */ struct the_nilfs *alloc_nilfs (struct super_block *sb) {
@@ -202,8 +202,7 @@ static int nilfs_store_log_cursor(struct the_nilfs *nilfs,* exponent information written in @sbp and stores it in @blocksize, * or aborts with an error message if it's too large. * -* Return Value: On success, 0 is returned. If the block size is too -* large, -EINVAL is returned. +* Return: 0 on success, or %-EINVAL if the block size is too large. */ static int nilfs_get_blocksize (struct super_block *sb,struct nilfs_super_block *sbp,int *blocksize)
@@ -546,7 +545,7 @@ static int nilfs_valid_sb(struct nilfs_super_block *sbp)* area, or if the parameters themselves are not normal, it is * determined to be invalid. * -* Return Value: true if invalid, false if valid. +* Return: true if invalid, false if valid. */ static bool nilfs_sb2_bad_offset (struct nilfs_super_block *sbp,u64 offset) {
@@ -677,8 +676,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,* reading the super block, getting disk layout information, initializing * shared fields in the_nilfs). * -* Return Value: On success, 0 is returned. On error, a negative error -* code is returned. +* Return: 0 on success, or a negative error code on failure. */ int init_nilfs (struct the_nilfs *nilfs,struct super_block *sb,char *data) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1687/3318 nilfs2: ignore non-fatal signals during synchronous log write wait
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryusuke Konishi <[email protected]>
[ Upstream commit 7131aaa74bcc7c9da1f1d1c8724da75c775557a0 ]
Based on a syzbot report, Wang Jianjian pointed out that following a successful directory operation in nilfs_rename(), a synchronous write requested within nilfs_transaction_commit(), triggered by a sync flag set by nilfs_commit_chunk(), could be interrupted by a user signal. This interruption leaves in-memory metadata updates intact while returning an error, causing inconsistency with the VFS dentry cache and ultimately triggering a kernel warning.
According to "signal(7)", local disks are not classified as "slow devices" (such as terminals, FIFOs, or pipes) and their I/O operations on disk devices are not interrupted by signals. In kernel space, waiting for such disk I/O should therefore not be aborted by ordinary (non-fatal) signals.
Suppress this issue by modifying nilfs_segctor_sync(), which waits for the log writer thread to complete synchronous writes, to catch only fatal signals via fatal_signal_pending() and return -EINTR rather than -ERESTARTSYS. To complement this change and prevent the wait loop from busy-looping when schedule() returns immediately due to a pending non-fatal signal, switch the wait state from TASK_INTERRUPTIBLE to TASK_KILLABLE.
This serves as an effective interim stabilization measure without structural changes until a comprehensive fix for metadata consistency is implemented.
--- fs/nilfs2/ioctl.c | 2 +- fs/nilfs2/recovery.c | 2 +- fs/nilfs2/segment.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)
fs/nilfs2/ioctl.c +1 -1
@@ -960,10 +960,10 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,* Return: 0 on success, or one of the following negative error codes on * failure: * * %-EFAULT - Failure during execution of requested operation. +* * %-EINTR - Interrupted. * * %-EIO - I/O error. * * %-ENOMEM - Insufficient memory available. * * %-ENOSPC - No space left on device (only in a panic state). -* * %-ERESTARTSYS - Interrupted. * * %-EROFS - Read only filesystem. */ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
fs/nilfs2/recovery.c +1 -1
@@ -743,11 +743,11 @@ static void nilfs_abort_roll_forward(struct the_nilfs *nilfs)* * Return: 0 on success, or one of the following negative error codes on * failure: +* * %-EINTR - Interrupted. * * %-EINVAL - Inconsistent filesystem state. * * %-EIO - I/O error. * * %-ENOMEM - Insufficient memory available. * * %-ENOSPC - No space left on device (only in a panic state). -* * %-ERESTARTSYS - Interrupted. */ int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
fs/nilfs2/segment.c +5 -5
@@ -2243,7 +2243,7 @@ static int nilfs_segctor_sync(struct nilfs_sc_info *sci)wake_up (&sci->sc_wait_daemon);for (;;) { -set_current_state (TASK_INTERRUPTIBLE ); +set_current_state (TASK_KILLABLE );/* * Synchronize only while the log writer thread is alive.
@@ -2257,11 +2257,11 @@ static int nilfs_segctor_sync(struct nilfs_sc_info *sci) err = wait_req.err;break ; } -if (!signal_pending (current)) { +if (!fatal_signal_pending (current)) {schedule ();continue ; } - err = -ERESTARTSYS ; + err = -EINTR ;break ; }finish_wait (&sci->sc_wait_request, &wait_req.wq);
@@ -2295,10 +2295,10 @@ static void nilfs_segctor_wakeup(struct nilfs_sc_info *sci, int err, bool force)* * Return: 0 on success, or one of the following negative error codes on * failure: +* * %-EINTR - Interrupted. * * %-EIO - I/O error (including metadata corruption). * * %-ENOMEM - Insufficient memory available. * * %-ENOSPC - No space left on device (only in a panic state). -* * %-ERESTARTSYS - Interrupted. * * %-EROFS - Read only filesystem. */ int nilfs_construct_segment (struct super_block *sb)
@@ -2325,10 +2325,10 @@ int nilfs_construct_segment(struct super_block *sb)* * Return: 0 on success, or one of the following negative error codes on * failure: +* * %-EINTR - Interrupted. * * %-EIO - I/O error (including metadata corruption). * * %-ENOMEM - Insufficient memory available. * * %-ENOSPC - No space left on device (only in a panic state). -* * %-ERESTARTSYS - Interrupted. * * %-EROFS - Read only filesystem. */ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1688/3318 ASoC: stm: stm32_i2s: Drop redundant error messages
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit a6cdfb6230944082e7be64f9166eed64656b1162 ]
Both devm_request_irq() and snd_dmaengine_pcm_register() already log failures internally. Drop the redundant error messages and return the original errors directly.
Stable-dep-of: 1b207c85551f ("ASoC: stm: stm32_i2s: request IRQ after regmap initialization")
--- sound/soc/stm/stm32_i2s.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/stm/stm32_i2s.c +2 -4
@@ -1079,10 +1079,8 @@ static int stm32_i2s_parse_dt(struct platform_device *pdev, ret =devm_request_irq (&pdev->dev, irq, stm32_i2s_isr,0 ,dev_name (&pdev->dev), i2s); -if (ret) { -dev_err (&pdev->dev,"irq request returned %d\n" , ret); +if (ret)return ret; - }/* Reset */ rst =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL );
@@ -1136,7 +1134,7 @@ static int stm32_i2s_probe(struct platform_device *pdev) ret =snd_dmaengine_pcm_register (&pdev->dev, &stm32_i2s_pcm_config,0 );if (ret) -return dev_err_probe (&pdev->dev, ret,"PCM DMA register error\n" ); +return ret; ret =snd_soc_register_component (&pdev->dev, &stm32_i2s_component, i2s->dai_drv,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1689/3318 ASoC: stm: stm32_i2s: request IRQ after regmap initialization
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 1b207c85551fd74854d632116849295b2305245f ]
The ISR accesses the managed regmap, but probe requests the IRQ before creating it. An early interrupt can reach an uninitialized regmap. Reverse-order cleanup can free the regmap while the IRQ remains active.
Request the IRQ after regmap initialization so probe unwind and removal free and synchronize it before releasing the regmap.
The teardown ordering issue was found by static analysis.
--- sound/soc/stm/stm32_i2s.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
sound/soc/stm/stm32_i2s.c +11 -12
@@ -1027,7 +1027,7 @@ static int stm32_i2s_parse_dt(struct platform_device *pdev,const struct of_device_id *of_id;struct reset_control *rst;struct resource *res; -int irq, ret; +int ret;if (!np)return -ENODEV ;
@@ -1072,16 +1072,6 @@ static int stm32_i2s_parse_dt(struct platform_device *pdev,return ret; } -/* Get irqs */ - irq =platform_get_irq (pdev,0 ); -if (irq <0 ) -return irq; - - ret =devm_request_irq (&pdev->dev, irq, stm32_i2s_isr,0 , -dev_name (&pdev->dev), i2s); -if (ret) -return ret; -/* Reset */ rst =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL );if (IS_ERR (rst))
@@ -1106,7 +1096,7 @@ static int stm32_i2s_probe(struct platform_device *pdev) {struct stm32_i2s_data *i2s;u32 val; -int ret; +int irq, ret; i2s =devm_kzalloc (&pdev->dev,sizeof (*i2s),GFP_KERNEL );if (!i2s)
@@ -1132,6 +1122,15 @@ static int stm32_i2s_probe(struct platform_device *pdev)return dev_err_probe (&pdev->dev,PTR_ERR (i2s->regmap),"Regmap init error\n" ); + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + ret =devm_request_irq (&pdev->dev, irq, stm32_i2s_isr,0 , +dev_name (&pdev->dev), i2s); +if (ret) +return ret; + ret =snd_dmaengine_pcm_register (&pdev->dev, &stm32_i2s_pcm_config,0 );if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1690/3318 drm/msm/dsi: Fix VM leak in dsi_tx_buf_alloc_6g()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit ab91ba61871a896ca2ecc6e048d80a152136da44 ]
dsi_tx_buf_alloc_6g() takes a reference to the kms VM with drm_gpuvm_get() and stores it in msm_host->vm. If msm_gem_kernel_new() fails, the function returns early without dropping that reference. Since msm_host->tx_gem_obj is cleared on the error path, msm_dsi_tx_buf_free() will never see a non-NULL tx_gem_obj and thus never calls drm_gpuvm_put(), leaking the VM reference.
Drop the VM reference and clear msm_host->vm on the error path.
Patchwork: https://patchwork.freedesktop.org/patch/754332/
--- drivers/gpu/drm/msm/dsi/dsi_host.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_host.c +2 -0
@@ -1184,6 +1184,8 @@ int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size)if (IS_ERR (data)) { msm_host->tx_gem_obj =NULL ; +msm_gem_address_space_put (msm_host->aspace); + msm_host->aspace =NULL ;return PTR_ERR (data); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1691/3318 KVM: arm64: Fix MMFR0 TGRAN advertisement for pVMs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Donnefort <[email protected]>
[ Upstream commit 6c29285e78b5e4811145ebda382ac0ba732ce56a ]
Protected VM ID register emulation leaves unlisted fields at 0. This creates two issues for TGRAN:
* TGRAN16: 0 means non-implemented. It prevents 16KB protected VMs from booting even when the hardware supports it.
* TGRAN4|TGRAN64: 0 means implemented. This may falsely advertise the feature even when the hardware does not support it.
Advertise all the TGRAN fields in pvmid_aa64mmfr0 so that the hardware support is properly propagated.
--- arch/arm64/kvm/hyp/include/nvhe/fixed_config.h | 3 ++- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/include/nvhe/fixed_config.h +2 -1
@@ -90,7 +90,8 @@*/ #define PVM_ID_AA64MMFR0_RESTRICT_UNSIGNED (\ FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_PARANGE), ID_AA64MMFR0_EL1_PARANGE_40) | \ - FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_ASIDBITS), ID_AA64MMFR0_EL1_ASIDBITS_16) \ + FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_ASIDBITS), ID_AA64MMFR0_EL1_ASIDBITS_16) | \ + SYS_FIELD_PREP_ENUM(ID_AA64MMFR0_EL1, TGRAN16, IMP) \ )/*
arch/arm64/kvm/hyp/nvhe/sys_regs.c +9 -0
@@ -191,6 +191,15 @@ static u64 get_pvm_id_aa64mmfr0(const struct kvm_vcpu *vcpu) set_mask =get_restricted_features_unsigned (id_aa64mmfr0_el1_sys_val,PVM_ID_AA64MMFR0_RESTRICT_UNSIGNED ); + set_mask |=SYS_FIELD_PREP (ID_AA64MMFR0_EL1 ,TGRAN4 , +min_t (int,cpuid_feature_extract_signed_field (id_aa64mmfr0_el1_sys_val, +ID_AA64MMFR0_EL1_TGRAN4_SHIFT ), +ID_AA64MMFR0_EL1_TGRAN4_IMP )); + set_mask |=SYS_FIELD_PREP (ID_AA64MMFR0_EL1 ,TGRAN64 , +min_t (int,cpuid_feature_extract_signed_field (id_aa64mmfr0_el1_sys_val, +ID_AA64MMFR0_EL1_TGRAN64_SHIFT ), +ID_AA64MMFR0_EL1_TGRAN64_IMP )); +return (id_aa64mmfr0_el1_sys_val &PVM_ID_AA64MMFR0_ALLOW ) | set_mask; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1692/3318 ata: sata_inic162x: remove dangerous broken driver
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ethan Nelson-Moore <[email protected]>
[ Upstream commit 96fdeb7e3fd8d937f8351ed90824c9d904e590a1 ]
The sata_inic162x driver was labeled as "very experimental" in commit bb9696192826 ("libata: make it clear that sata_inic162x is experimental") due to data corruption issues, but not marked as broken. Since then, no changes have been made to it that could fix these issues. Since the driver was not marked as broken, and the message about potential data corruption is only visible in the code and dmesg, it is possible that someone could enable the driver without realizing its potential for data corruption. Remove the driver to protect users' data.
--- drivers/ata/Kconfig | 7 - drivers/ata/Makefile | 1 - drivers/ata/sata_inic162x.c | 902 ------------------------------------ 3 files changed, 910 deletions(-) delete mode 100644 drivers/ata/sata_inic162x.c
drivers/ata/Kconfig +0 -7
@@ -331,13 +331,6 @@ config SATA_AHCI_SEATTLE If unsure, say N -config SATA_INIC162X - tristate "Initio 162x SATA support (Very Experimental)" - depends on PCI - select SATA_HOST - help - This option enables support for Initio 162x Serial ATA. - config SATA_ACARD_AHCI tristate "ACard AHCI variant (ATP 8620)" depends on PCI
drivers/ata/Makefile +0 -1
@@ -9,7 +9,6 @@ obj-$(CONFIG_SATA_AHCI_SEATTLE) += ahci_seattle.o libahci.o libahci_platform.o obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o libahci_platform.o obj-$(CONFIG_SATA_FSL) += sata_fsl.o obj-$(CONFIG_SATA_GEMINI) += sata_gemini.o -obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o obj-$(CONFIG_SATA_SIL24) += sata_sil24.o obj-$(CONFIG_SATA_DWC) += sata_dwc_460ex.o obj-$(CONFIG_SATA_HIGHBANK) += sata_highbank.o libahci.o
drivers/ata/sata_inic162x.c deleted +0 -902
902 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1693/3318 init/version.c: Replace strlcpy with strscpy
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Azeem Shaikh <[email protected]>
[ Upstream commit 8ebab155ea18a6d6c47b17287a0ab4633334f6eb ]
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
Direct replacement is safe here since return value of -errno is used to check for truncation instead of sizeof(dest).
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
Stable-dep-of: b6bec5b63a5b ("init: fix early boot crash with bare hostname parameter")
--- init/version.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
init/version.c +3 -3
@@ -21,10 +21,10 @@ static int __init early_hostname(char *arg) {size_t bufsize =sizeof (init_uts_ns.name.nodename);size_t maxlen = bufsize -1 ; -size_t arglen; +ssize_t arglen; - arglen =strlcpy (init_uts_ns.name.nodename, arg, bufsize); -if (arglen > maxlen) { + arglen =strscpy (init_uts_ns.name.nodename, arg, bufsize); +if (arglen <0 ) {pr_warn ("hostname parameter exceeds %zd characters and will be truncated" , maxlen); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1694/3318 init: fix early boot crash with bare hostname parameter
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit b6bec5b63a5b812145e53aaad1e63661c7214f93 ]
When a bare hostname parameter is specified on the kernel command line without the '=' separator, early parameter parsing passes NULL to early_hostname(), which dereferences it in strscpy() and can crash the system during early boot.
Reject NULL values in early_hostname() and return -EINVAL instead.
--- init/version.c | 3 +++ 1 file changed, 3 insertions(+)
init/version.c +3 -0
@@ -23,6 +23,9 @@ static int __init early_hostname(char *arg)size_t maxlen = bufsize -1 ;ssize_t arglen; +if (!arg) +return -EINVAL ; + arglen =strscpy (init_uts_ns.name.nodename, arg, bufsize);if (arglen <0 ) { pr_warn("hostname parameter exceeds %zd characters and will be truncated",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1695/3318 ALSA: line6: Use guard() for spin locks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit bdcdb4e7aa410122baa3496b93e7850dc20a90fa ]
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Stable-dep-of: 443ed4edc267 ("ALSA: line6: Handle period elapsed calls outside the locks")
--- sound/usb/line6/capture.c | 6 +----- sound/usb/line6/driver.c | 31 +++++++++++++++---------------- sound/usb/line6/midi.c | 10 ++-------- sound/usb/line6/pcm.c | 27 ++++++++++++--------------- 4 files changed, 30 insertions(+), 44 deletions(-)
sound/usb/line6/capture.c +1 -5
@@ -157,8 +157,6 @@ void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length)static void audio_in_callback (struct urb *urb) {int i, index, length =0 , shutdown =0 ; -unsigned long flags; -struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context; line6pcm->in.last_frame = urb->start_frame;
@@ -168,7 +166,7 @@ static void audio_in_callback(struct urb *urb)if (urb == line6pcm->in.urbs[index])break ; -spin_lock_irqsave (&line6pcm->in.lock, flags); +guard (spinlock_irqsave)(&line6pcm->in.lock);for (i =0 ; i <LINE6_ISO_PACKETS ; ++i) {char *fbuf;
@@ -223,8 +221,6 @@ static void audio_in_callback(struct urb *urb) test_bit(LINE6_STREAM_PCM, &line6pcm->in.running))line6_capture_check_period (line6pcm, length); } - -spin_unlock_irqrestore (&line6pcm->in.lock, flags); }/* open capture callback */
sound/usb/line6/driver.c +15 -16
@@ -286,31 +286,30 @@ static void line6_data_received(struct urb *urb) {struct usb_line6 *line6 = (struct usb_line6 *)urb->context;struct midi_buffer *mb = &line6->line6midi->midibuf_in; -unsigned long flags;int done;if (urb->status == -ESHUTDOWN )return ;if (line6->properties->capabilities &LINE6_CAP_CONTROL_MIDI ) { -spin_lock_irqsave (&line6->line6midi->lock, flags); - done = -line6_midibuf_write (mb, urb->transfer_buffer, urb->actual_length); - -if (done < urb->actual_length) { -line6_midibuf_ignore (mb, done); -dev_dbg (line6->ifcdev,"%d %d buffer overflow - message skipped\n" , - done, urb->actual_length); + scoped_guard(spinlock_irqsave, &line6->line6midi->lock) { + done = +line6_midibuf_write (mb, urb->transfer_buffer, urb->actual_length); + +if (done < urb->actual_length) { +line6_midibuf_ignore (mb, done); +dev_dbg (line6->ifcdev,"%d %d buffer overflow - message skipped\n" , + done, urb->actual_length); + } } -spin_unlock_irqrestore (&line6->line6midi->lock, flags);for (;;) { -spin_lock_irqsave (&line6->line6midi->lock, flags); - done = -line6_midibuf_read (mb, line6->buffer_message, -LINE6_MIDI_MESSAGE_MAXLEN , -LINE6_MIDIBUF_READ_RX ); -spin_unlock_irqrestore (&line6->line6midi->lock, flags); + scoped_guard(spinlock_irqsave, &line6->line6midi->lock) { + done = +line6_midibuf_read (mb, line6->buffer_message, +LINE6_MIDI_MESSAGE_MAXLEN , +LINE6_MIDIBUF_READ_RX ); + }if (done <=0 )break ;
sound/usb/line6/midi.c +2 -8
@@ -72,7 +72,6 @@ static void line6_midi_transmit(struct snd_rawmidi_substream *substream)*/ static void midi_sent (struct urb *urb) { -unsigned long flags;int status;int num;struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
@@ -84,7 +83,7 @@ static void midi_sent(struct urb *urb)if (status == -ESHUTDOWN )return ; -spin_lock_irqsave (&line6->line6midi->lock, flags); +guard (spinlock_irqsave)(&line6->line6midi->lock); num = --line6->line6midi->num_active_send_urbs;if (num ==0 ) {
@@ -94,8 +93,6 @@ static void midi_sent(struct urb *urb)if (num ==0 )wake_up (&line6->line6midi->send_wait); - -spin_unlock_irqrestore (&line6->line6midi->lock, flags); }/*
@@ -158,17 +155,14 @@ static int line6_midi_output_close(struct snd_rawmidi_substream *substream)static void line6_midi_output_trigger (struct snd_rawmidi_substream *substream,int up) { -unsigned long flags;struct usb_line6 *line6 =line6_rawmidi_substream_midi (substream)->line6; line6->line6midi->substream_transmit = substream; -spin_lock_irqsave (&line6->line6midi->lock, flags); +guard (spinlock_irqsave)(&line6->line6midi->lock);if (line6->line6midi->num_active_send_urbs ==0 )line6_midi_transmit (substream); - -spin_unlock_irqrestore (&line6->line6midi->lock, flags); }static void line6_midi_output_drain (struct snd_rawmidi_substream *substream)
sound/usb/line6/pcm.c +12 -15
@@ -190,11 +190,10 @@ static void line6_buffer_release(struct snd_line6_pcm *line6pcm,static int line6_stream_start (struct snd_line6_pcm *line6pcm,int direction,int type) { -unsigned long flags;struct line6_pcm_stream *pstr =get_stream (line6pcm, direction);int ret =0 ; -spin_lock_irqsave (&pstr->lock, flags); +guard (spinlock_irqsave)(&pstr->lock);if (!test_and_set_bit (type, &pstr->running) && !(pstr->active_urbs || pstr->unlink_urbs)) { pstr->count =0 ;
@@ -207,7 +206,6 @@ static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,if (ret <0 )clear_bit (type, &pstr->running); -spin_unlock_irqrestore (&pstr->lock, flags);return ret; }
@@ -215,21 +213,20 @@ static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,static void line6_stream_stop (struct snd_line6_pcm *line6pcm,int direction,int type) { -unsigned long flags;struct line6_pcm_stream *pstr =get_stream (line6pcm, direction); -spin_lock_irqsave (&pstr->lock, flags); -clear_bit (type, &pstr->running); -if (!pstr->running) { -spin_unlock_irqrestore (&pstr->lock, flags); -line6_unlink_audio_urbs (line6pcm, pstr); -spin_lock_irqsave (&pstr->lock, flags); -if (direction ==SNDRV_PCM_STREAM_CAPTURE ) { - line6pcm->prev_fbuf =NULL ; - line6pcm->prev_fsize =0 ; - } + scoped_guard(spinlock_irqsave, &pstr->lock) { +clear_bit (type, &pstr->running); +if (pstr->running) +return ; + } + +line6_unlink_audio_urbs (line6pcm, pstr); +if (direction ==SNDRV_PCM_STREAM_CAPTURE ) { +guard (spinlock_irqsave)(&pstr->lock); + line6pcm->prev_fbuf =NULL ; + line6pcm->prev_fsize =0 ; } -spin_unlock_irqrestore (&pstr->lock, flags); }/* common PCM trigger callback */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1696/3318 ALSA: line6: Handle period elapsed calls outside the locks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 443ed4edc2678cc51c5a01e7dffc4c890be40051 ]
LINE6 driver may call snd_pcm_period_elapsed() for both playback and capture substreams at processing the playback substream, and this may lead to a ABBA deadlock.
Move the actual calls of snd_pcm_period_elapsed() outside the locks for avoiding it. The capture period notification at submitting the initial playback URBs (only with the impulse mode) is simply skipped, as it's done in the lock context; it'll be caught up at the next period.
--- sound/usb/line6/capture.c | 25 ++++++++++++++++--------- sound/usb/line6/capture.h | 2 +- sound/usb/line6/playback.c | 31 +++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 20 deletions(-)
sound/usb/line6/capture.c +16 -9
@@ -137,24 +137,21 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize) line6pcm->in.pos_done -= runtime->buffer_size; } -void line6_capture_check_period (struct snd_line6_pcm *line6pcm,int length) +/* update the capture position and check whether we need period_elapsed call */ +bool line6_capture_check_period (struct snd_line6_pcm *line6pcm,int length) { -struct snd_pcm_substream *substream = -get_substream (line6pcm,SNDRV_PCM_STREAM_CAPTURE ); - line6pcm->in.bytes += length;if (line6pcm->in.bytes >= line6pcm->in.period) { line6pcm->in.bytes %= line6pcm->in.period; -spin_unlock (&line6pcm->in.lock); -snd_pcm_period_elapsed (substream); -spin_lock (&line6pcm->in.lock); +return true; } +return false; }/* * Callback for completed capture URB. */ -static void audio_in_callback (struct urb *urb) +static bool handle_audio_in (struct urb *urb) {int i, index, length =0 , shutdown =0 ;struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context;
@@ -219,8 +216,18 @@ static void audio_in_callback(struct urb *urb)if (!test_bit (LINE6_STREAM_IMPULSE , &line6pcm->in.running) &&test_bit (LINE6_STREAM_PCM , &line6pcm->in.running)) -line6_capture_check_period (line6pcm, length); +return line6_capture_check_period (line6pcm, length); } + +return false; +} + +static void audio_in_callback (struct urb *urb) +{ +struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context; + +if (handle_audio_in (urb)) +snd_pcm_period_elapsed (get_substream (line6pcm,SNDRV_PCM_STREAM_CAPTURE )); }/* open capture callback */
sound/usb/line6/capture.h +1 -1
@@ -17,7 +17,7 @@ extern const struct snd_pcm_ops snd_line6_capture_ops;extern void line6_capture_copy (struct snd_line6_pcm *line6pcm,char *fbuf,int fsize); -extern void line6_capture_check_period (struct snd_line6_pcm *line6pcm, +extern bool line6_capture_check_period (struct snd_line6_pcm *line6pcm,int length);extern int line6_create_audio_in_urbs (struct snd_line6_pcm *line6pcm);extern int line6_submit_audio_in_all_urbs (struct snd_line6_pcm *line6pcm);
sound/usb/line6/playback.c +21 -10
@@ -136,6 +136,8 @@ static void add_monitor_signal(struct urb *urb_out, unsigned char *signal,/* Find a free URB, prepare audio data, and submit URB. must be called in line6pcm->out.lock context +Returns 1 if snd_pcm_period_elapsed() needs to be called for the +capture stream after releasing the lock, 0 if not, or a negative error */ static int submit_audio_out_urb (struct snd_line6_pcm *line6pcm) {
@@ -151,6 +153,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) line6pcm->properties->rates.rats[0 ].den * (line6pcm->line6->intervals_per_second /LINE6_ISO_INTERVAL );struct urb *urb_out; +bool capture_period_elapsed = false; index =find_first_zero_bit (&line6pcm->out.active_urbs, line6pcm->line6->iso_buffers);
@@ -260,8 +263,9 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) urb_out->transfer_buffer, urb_out-> transfer_buffer_length); -line6_capture_check_period (line6pcm, - urb_out->transfer_buffer_length); + capture_period_elapsed = +line6_capture_check_period (line6pcm, + urb_out->transfer_buffer_length); } }else { if (!(line6pcm->line6->properties->capabilities & LINE6_CAP_HWMON)
@@ -283,24 +287,26 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)dev_err (line6pcm->line6->ifcdev,"URB out #%d submission failed (%d)\n" , index, ret); -return 0 ; +return capture_period_elapsed; }/* Submit all currently available playback URBs. must be called in line6pcm->out.lock context +The capture period notification is skipped here since we can't call +snd_pcm_period_elapsed() in the lock; it'll be caught up at the next one. */ int line6_submit_audio_out_all_urbs (struct snd_line6_pcm *line6pcm) { -int ret =0 , i; +int ret, i;for (i =0 ; i < line6pcm->line6->iso_buffers; ++i) { ret =submit_audio_out_urb (line6pcm);if (ret <0 ) -break ; +return ret; } -return ret; +return 0 ; }/*
@@ -316,6 +322,8 @@ static void audio_out_callback(struct urb *urb)const int bytes_per_frame = line6pcm->properties->bytes_per_channel * line6pcm->properties->playback_hw.channels_max; +bool capture_period_elapsed = false; +bool playback_period_elapsed = false;#if USE_CLEAR_BUFFER_WORKAROUND memset (urb->transfer_buffer,0 , urb->transfer_buffer_length);
@@ -358,19 +366,22 @@ static void audio_out_callback(struct urb *urb) shutdown =1 ;if (!shutdown) { -submit_audio_out_urb (line6pcm); + capture_period_elapsed =submit_audio_out_urb (line6pcm) >0 ;if (test_bit (LINE6_STREAM_PCM , &line6pcm->out.running)) { line6pcm->out.bytes += length;if (line6pcm->out.bytes >= line6pcm->out.period) { line6pcm->out.bytes %= line6pcm->out.period; -spin_unlock (&line6pcm->out.lock); -snd_pcm_period_elapsed (substream); -spin_lock (&line6pcm->out.lock); + playback_period_elapsed = true; } } }spin_unlock_irqrestore (&line6pcm->out.lock, flags); + +if (capture_period_elapsed) +snd_pcm_period_elapsed (get_substream (line6pcm,SNDRV_PCM_STREAM_CAPTURE )); +if (playback_period_elapsed) +snd_pcm_period_elapsed (substream); }/* open playback callback */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1697/3318 mm/mglru: fix ineffective memory protection for non-kswapd reclaim
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridong Chen <[email protected]>
[ Upstream commit 15da1e4978dd4ea8f5faa6e15ee967ba4ad9a30a ]
For MGLRU, memory.min/low is not honored during global proactive reclaim (writing to the root memory.reclaim) and global direct reclaim, because these paths shrink memcgs using stale protection (emin/elow). It can be reproduced as follows:
# echo 7 > /sys/kernel/mm/lru_gen/enabled # cd /sys/fs/cgroup # mkdir -p a/b # echo 100M > a/memory.min # echo +memory > a/cgroup.subtree_control # echo 100M > a/b/memory.min # echo $$ > a/b/cgroup.procs # dd if=/dev/zero of=/tmp/testfile bs=1M count=200 # cat a/b/memory.current 222650368 # echo 500M > memory.reclaim -bash: echo: write error: Resource temporarily unavailable # cat a/b/memory.current 6070272
memory.min is 100M, yet reclaim drops a/b down to 6M, breaking the protection. The traditional LRU path is not affected because shrink_node() calls mem_cgroup_calculate_protection() for each memcg it visits during a top-down tree walk.
Commit 30d77b7eef01 ("mm/mglru: fix ineffective protection calculation") moved the protection computation into lru_gen_age_node(), which only runs for kswapd. Non-kswapd global reclaim reaches shrink_one() through lru_gen_shrink_node() -> shrink_many() without any protection computation, so emin/elow are whatever a previous kswapd run left behind - or zero if kswapd never ran on this node. Relying on a prior kswapd pass is not correct either: a memcg's emin/elow are derived from its ancestors' memory.min/low settings and from children_min_usage, both of which change over time, so emin/elow go stale even after kswapd has run and must be recomputed at the point of reclaim.
Introduce mem_cgroup_calculate_protection_path() which computes emin/elow along the root-to-target path only, by iterating through the cgroup ancestors array top-down. This avoids the full tree traversal that would be needed with mem_cgroup_calculate_protection(), limiting the cost to O(depth) per memcg - typically 3-5 levels.
Call it from shrink_one() for the non-kswapd path so that each memcg about to be shrunk has correct protection values.
--- include/linux/memcontrol.h | 10 ++++++++++ mm/memcontrol.c | 41 ++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 8 +++++++- 3 files changed, 58 insertions(+), 1 deletion(-)
include/linux/memcontrol.h +10 -0
@@ -1871,6 +1871,16 @@ static inline void count_objcg_event(struct obj_cgroup *objcg,#endif /* CONFIG_MEMCG_KMEM */ +#if defined(CONFIG_MEMCG ) && defined(CONFIG_LRU_GEN ) +void mem_cgroup_calculate_protection_path (struct mem_cgroup *root, +struct mem_cgroup *memcg); +#else +static inline void mem_cgroup_calculate_protection_path (struct mem_cgroup *root, +struct mem_cgroup *memcg) +{ +} +#endif +#if defined(CONFIG_MEMCG_KMEM ) && defined(CONFIG_ZSWAP )bool obj_cgroup_may_zswap (struct obj_cgroup *objcg);void obj_cgroup_charge_zswap (struct obj_cgroup *objcg,size_t size);
mm/memcontrol.c +41 -0
47 lines not on this page · raw message
mm/vmscan.c +7 -1
@@ -5459,7 +5459,13 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc)struct mem_cgroup *memcg =lruvec_memcg (lruvec);struct pglist_data *pgdat =lruvec_pgdat (lruvec); -/* lru_gen_age_node() called mem_cgroup_calculate_protection() */ +/* +* For kswapd, mem_cgroup_calculate_protection() has already +* been called during the top-down cgroup traversal. +*/ +if (!current_is_kswapd ()) +mem_cgroup_calculate_protection_path (NULL , memcg); +if (mem_cgroup_below_min (NULL , memcg))return MEMCG_LRU_YOUNG ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1698/3318 f2fs: return -EIO for a lost inode block after cp_error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daeho Jeong <[email protected]>
[ Upstream commit 53b12b63304b34a3850a901c4de3cc6ad08e0aee ]
After cp_error, dirty node caches are dropped without being written. If such an inode was never written, its NAT entry is still NEW_ADDR, and reading its inode block returns -ENOENT.
f2fs_get_dnode_of_data() passes that -ENOENT up, and callers take it as a hole. Since the inode block is missing, the next offset can only advance one block, so fiemap walks block by block up to maxbytes, about 2^30 blocks, while holding the inode lock. It took hours in a power-off recovery test after shutdown and blocked unlink and umount on the file.
Return -EIO instead of -ENOENT when the inode block itself is missing after cp_error or shutdown. A missing direct or indirect node is still reported as -ENOENT.
--- fs/f2fs/node.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
fs/f2fs/node.c +14 -2
@@ -785,8 +785,20 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)if (!npage[0 ]) { npage[0 ] =f2fs_get_node_page (sbi, nids[0 ]); -if (IS_ERR (npage[0 ])) -return PTR_ERR (npage[0 ]); +if (IS_ERR (npage[0 ])) { + err =PTR_ERR (npage[0 ]); +/* +* cp_error drops dirty node caches, so the inode block +* of an inode that was never written reads as NEW_ADDR +* and returns -ENOENT. It is not a hole; the inode is +* gone. Callers treat -ENOENT as a hole and keep +* looking block by block (e.g. fiemap up to maxbytes). +*/ +if (err == -ENOENT && (f2fs_cp_error (sbi) || +is_sbi_flag_set (sbi,SBI_IS_SHUTDOWN ))) + err = -EIO ; +return err; + } }/* if inline_data is set, should not report any block indices */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1699/3318 drm/amd/pm:restate all customized OD features on every table upload for smu 13.0.0/smu 14.0.2
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kenneth Feng <[email protected]>
[ Upstream commit 44d0d3031e47973ed65fd327669d5e2eaaf6c565 ]
PMFW interprets OverDriveTable.FeatureCtrlMask as the complete set of overdrive features that are currently overridden, not as a delta describing the operation at hand. On import it resets every feature whose bit is clear back to its default value - for the VF curve that means zeroing VoltageOffsetPerZoneBoundary[] outright.
The driver assumed the opposite. smu_v14_0_2_od_edit_dpm_table() clears the mask after a successful commit, so a subsequent above-default power1_cap write goes through smu_v14_0_2_set_ppt_limit() and uploads a table carrying only PP_OD_FEATURE_PPT_BIT. PMFW then drops the user's voltage offset and reverts to the stock V/F curve, while the driver's cached user table still reports the offset through pp_od_clk_voltage.
--- drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 2 ++ .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 22 ++++++------------- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++------------ 3 files changed, 16 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +2 -0
@@ -353,6 +353,8 @@ struct smu_table_context {void *boot_overdrive_table;void *user_overdrive_table; +uint32_t user_od_feature_mask; +uint32_t gpu_metrics_table_size;void *gpu_metrics_table; };
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +7 -15
@@ -1378,7 +1378,6 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,struct amdgpu_device *adev = smu->adev;uint32_t offset_of_voltageoffset;int32_t minimum, maximum; -uint32_t feature_ctrlmask;int i, ret =0 ;switch (type) {
@@ -1530,21 +1529,16 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,break ;case PP_OD_RESTORE_DEFAULT_TABLE : - feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;memcpy (od_table, table_context->boot_overdrive_table,sizeof (OverDriveTableExternal_t)); - od_table->OverDriveTable.FeatureCtrlMask = feature_ctrlmask; + od_table->OverDriveTable.FeatureCtrlMask =0 ; + table_context->user_od_feature_mask =0 ; fallthrough;case PP_OD_COMMIT_DPM_TABLE : -/* -* The member below instructs PMFW the settings focused in -* this single operation. -* `uint32_t FeatureCtrlMask;` -* It does not contain actual informations about user's custom -* settings. Thus we do not cache it. -*/ + table_context->user_od_feature_mask = + od_table->OverDriveTable.FeatureCtrlMask; offset_of_voltageoffset = offsetof(OverDriveTable_t , VoltageOffsetPerZoneBoundary); if (memcmp((u8 *)od_table + offset_of_voltageoffset, table_context->user_overdrive_table + offset_of_voltageoffset,
@@ -1557,7 +1551,6 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,return ret; } - od_table->OverDriveTable.FeatureCtrlMask =0 ;memcpy (table_context->user_overdrive_table + offset_of_voltageoffset, (u8 *)od_table + offset_of_voltageoffset,sizeof (OverDriveTableExternal_t) - offset_of_voltageoffset);
@@ -1813,6 +1806,7 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu) boot_od_table, sizeof(OverDriveTableExternal_t)); smu->user_dpm_profile.user_od = false; + smu->smu_table.user_od_feature_mask =0 ; }else if (smu->user_dpm_profile.user_od) { memcpy(&user_od_table_bak, user_od_table,
@@ -1842,10 +1836,8 @@ static int smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)OverDriveTableExternal_t *od_table = table_context->overdrive_table;OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;int res; - - user_od_table->OverDriveTable.FeatureCtrlMask =1U <<PP_OD_FEATURE_GFXCLK_BIT | -1U <<PP_OD_FEATURE_UCLK_BIT | -1U <<PP_OD_FEATURE_GFX_VF_CURVE_BIT ; + user_od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; res =smu_v13_0_0_upload_overdrive_table (smu, user_od_table); user_od_table->OverDriveTable.FeatureCtrlMask =0 ;if (res ==0 )
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +7 -14
@@ -1359,7 +1359,6 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,struct amdgpu_device *adev = smu->adev;uint32_t offset_of_voltageoffset;int32_t minimum, maximum; -uint32_t feature_ctrlmask;int i, ret =0 ;switch (type) {
@@ -1511,21 +1510,16 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,break ;case PP_OD_RESTORE_DEFAULT_TABLE : - feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;memcpy (od_table, table_context->boot_overdrive_table,sizeof (OverDriveTableExternal_t)); - od_table->OverDriveTable.FeatureCtrlMask = feature_ctrlmask; + od_table->OverDriveTable.FeatureCtrlMask =0 ; + table_context->user_od_feature_mask =0 ; fallthrough;case PP_OD_COMMIT_DPM_TABLE : -/* -* The member below instructs PMFW the settings focused in -* this single operation. -* `uint32_t FeatureCtrlMask;` -* It does not contain actual informations about user's custom -* settings. Thus we do not cache it. -*/ + table_context->user_od_feature_mask = + od_table->OverDriveTable.FeatureCtrlMask; offset_of_voltageoffset = offsetof(OverDriveTable_t , VoltageOffsetPerZoneBoundary); if (memcmp((u8 *)od_table + offset_of_voltageoffset, table_context->user_overdrive_table + offset_of_voltageoffset,
@@ -1538,7 +1532,6 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,return ret; } - od_table->OverDriveTable.FeatureCtrlMask =0 ;memcpy (table_context->user_overdrive_table + offset_of_voltageoffset, (u8 *)od_table + offset_of_voltageoffset,sizeof (OverDriveTableExternal_t) - offset_of_voltageoffset);
@@ -1791,6 +1784,7 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu) boot_od_table, sizeof(OverDriveTableExternal_t)); smu->user_dpm_profile.user_od = false; + smu->smu_table.user_od_feature_mask =0 ; }else if (smu->user_dpm_profile.user_od) { memcpy(&user_od_table_bak, user_od_table,
@@ -1821,9 +1815,8 @@ static int smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;int res; - user_od_table->OverDriveTable.FeatureCtrlMask =1U <<PP_OD_FEATURE_GFXCLK_BIT | -1U <<PP_OD_FEATURE_UCLK_BIT | -1U <<PP_OD_FEATURE_GFX_VF_CURVE_BIT ; + user_od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; res =smu_v13_0_7_upload_overdrive_table (smu, user_od_table); user_od_table->OverDriveTable.FeatureCtrlMask =0 ;if (res ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1700/3318 mfd: twl-core: Use i2c_check_functionality as boolean value
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 7ee4fa2674e51a0d100b9240cd8a50355141362f ]
i2c_check_functionality() returns a boolean status rather than an error code - directly use it as a boolean value.
Stable-dep-of: 3c5c55d979dd ("mfd: twl-core: Unregister the auxiliary platform device on unbind")
--- drivers/mfd/twl-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/twl-core.c +1 -1
@@ -725,7 +725,7 @@ twl_probe(struct i2c_client *client)return status; } -if (i2c_check_functionality (client->adapter,I2C_FUNC_I2C ) ==0 ) { +if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {dev_dbg (&client->dev,"can't talk I2C?\n" ); status = -EIO ; goto free;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1701/3318 mfd: twl-core: Unregister the auxiliary platform device on unbind
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 3c5c55d979ddcb0765ce531bc7ba173c87c8712a ]
twl_probe() registers a standalone platform device named "twl", but keeps its pointer only in a local variable. Probe errors unregister the device, while successful probe leaves no way for twl_remove() to release it. The platform device therefore remains registered after the I2C driver unbinds.
Register a managed action on the I2C device immediately after adding the platform device. This unregisters it on probe failure and driver unbind, and also handles failure to register the action itself. Remove the manual error-path unregister to avoid releasing the device twice.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/mfd/twl-core.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/mfd/twl-core.c +14 -7
@@ -690,6 +690,11 @@ static struct of_dev_auxdata twl_auxdata_lookup[] = { { /* sentinel */ }, }; +static void twl_unregister_device (void *data) +{ +platform_device_unregister (data); +} +/* NOTE: This driver only handles a single twl4030/tps659x0 chip */ static int twl_probe (struct i2c_client *client)
@@ -725,17 +730,22 @@ twl_probe(struct i2c_client *client)return status; } + status =devm_add_action_or_reset (&client->dev, twl_unregister_device, + pdev); +if (status) +return status; +if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {dev_dbg (&client->dev,"can't talk I2C?\n" ); status = -EIO ; - goto free; + goto out; } twl_priv =devm_kzalloc (&client->dev,sizeof (struct twl_private ),GFP_KERNEL );if (!twl_priv) { status = -ENOMEM ; - goto free; + goto out; }if ((id->driver_data) &TWL6030_CLASS ) {
@@ -755,7 +765,7 @@ twl_probe(struct i2c_client *client) GFP_KERNEL);if (!twl_priv->twl_modules) { status = -ENOMEM ; - goto free; + goto out; }for (i =0 ; i < num_slaves; i++) {
@@ -842,10 +852,7 @@ twl_probe(struct i2c_client *client) fail:if (status <0 )twl_remove (client); -free: -if (status <0 ) -platform_device_unregister (pdev); - +out:return status; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1702/3318 ALSA: hda/hdmi: clamp sad_count in ELD proc write handler
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit b3e7ddd694f8429217ba509b55b910a0e4361dfb ]
snd_hdmi_write_eld_info() parses a "sad_count N" line from the root-writable ELD proc interface and assigns N directly to e->sad_count with no upper bound, unlike the per-index "sadN_*" lines a few lines below which are already bounded to ELD_MAX_SAD.
snd_hdmi_eld_update_pcm_info() later iterates
"for (i = 0; i < e->sad_count; i++)" over the fixed e->sad[ELD_MAX_SAD] array, so an oversized sad_count read from the proc file causes it to walk past the array.
Reject sad_count values above ELD_MAX_SAD, matching the existing per-index guard.
--- sound/pci/hda/hda_eld.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/pci/hda/hda_eld.c +4 -2
@@ -525,9 +525,11 @@ void snd_hdmi_write_eld_info(struct hdmi_eld *eld, e->aud_synch_delay = val; else if (!strcmp(name, "speakers")) e->spk_alloc = val; - else if (!strcmp(name, "sad_count")) + else if (!strcmp(name, "sad_count")) { +if (val >ELD_MAX_SAD ) +continue ; e->sad_count = val; - else if (!strncmp(name, "sad", 3)) { + } else if (!strncmp(name, "sad", 3)) { sname = name +4 ; n = name[3 ] -'0' ;if (name[4 ] >='0' && name[4 ] <='9' ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1703/3318 mailbox: altera: shut down RX polling timer on channel teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 0cf10e65639cba32d05994f85e6a8f08dd0ffe08 ]
The RX polling callback unconditionally rearms the timer after it processes mailbox data. altera_mbox_shutdown() uses timer_delete_sync(), which waits for a running callback but does not prevent that callback from rearming the timer after the deletion.
Use timer_shutdown_sync() for the final polling teardown so the timer cannot be queued again while the mailbox channel is being released. The timer is reinitialized with timer_setup() on a later channel startup, so polling mode remains reusable.
--- drivers/mailbox/mailbox-altera.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mailbox/mailbox-altera.c +1 -1
@@ -270,7 +270,7 @@ static void altera_mbox_shutdown(struct mbox_chan *chan)writel_relaxed (~0 , mbox->mbox_base +MAILBOX_INTMASK_REG );free_irq (mbox->irq, chan); }else if (!mbox->is_sender) { -del_timer_sync (&mbox->rxpoll_timer); +timer_shutdown_sync (&mbox->rxpoll_timer); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1704/3318 platform/x86: asus-wmi: Serialize WMI method evaluations with a mutex
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Scardovi <[email protected]>
[ Upstream commit b9428edaf4109e86a97254228d831767d0acc1f8 ]
Concurrent evaluations of ASUS WMI management methods (from ACPI notify, HID, userspace daemons, and debugfs) enter the BIOS ACPI/SMM interface simultaneously, triggering re-entrant SMIs or EC mailbox buffer corruption.
Fix this at the root by introducing a centralized evaluation helper (asus_wmi_evaluate_method_locked()) protected by a global mutex (asus_wmi_eval_lock) using guard(mutex). Route all evaluations of ASUS_WMI_MGMT_GUID (method3, method5, method_buf, and show_call) through this helper.
A static mutex is required because asus_wmi_evaluate_method() is an exported symbol used by external modules (such as hid-asus and asus-armoury) that lack access to struct asus_wmi drvdata, and the underlying ASUS ACPI/EC management method is a single physical platform resource.
The mutex is non-recursive: nested ACPI/WMI notify handlers must not call back into evaluate on the same task (defer via workqueue, as asus_rfkill_notify already does).
The sysfs-versus-notify race predates the later export of asus_wmi_evaluate_method(), so Fixes points at the original shared evaluate helper rather than that export.
--- drivers/platform/x86/asus-wmi.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
drivers/platform/x86/asus-wmi.c +21 -9
@@ -15,6 +15,7 @@#include <linux/acpi.h> #include <linux/backlight.h> +#include <linux/cleanup.h> #include <linux/debugfs.h> #include <linux/delay.h> #include <linux/dmi.h>
@@ -27,6 +28,7 @@#include <linux/kernel.h> #include <linux/leds.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/pci.h> #include <linux/pci_hotplug.h> #include <linux/platform_data/x86/asus-wmi.h>
@@ -316,6 +318,20 @@ struct asus_wmi {/* WMI ************************************************************************/ +/* +* Concurrent evaluations of ASUS WMI methods can re-enter firmware +* SMI/EC mailbox handling and corrupt the mailbox. +*/ +static DEFINE_MUTEX (asus_wmi_eval_lock); + +static acpi_status asus_wmi_evaluate_method_locked (u32 method_id, +struct acpi_buffer *input, +struct acpi_buffer *output) +{ +guard (mutex)(&asus_wmi_eval_lock); +return wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, input, output); +} +static int asus_wmi_evaluate_method3 (u32 method_id,u32 arg0,u32 arg1,u32 arg2,u32 *retval) {
@@ -330,8 +346,7 @@ static int asus_wmi_evaluate_method3(u32 method_id,union acpi_object *obj;u32 tmp =0 ; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (method_id, &input, &output);if (ACPI_FAILURE (status))return -EIO ;
@@ -373,8 +388,7 @@ static int asus_wmi_evaluate_method5(u32 method_id,union acpi_object *obj;u32 tmp =0 ; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (method_id, &input, &output);if (ACPI_FAILURE (status))return -EIO ;
@@ -412,8 +426,7 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,union acpi_object *obj;int err =0 ; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (method_id, &input, &output);if (ACPI_FAILURE (status))return -EIO ;
@@ -4260,9 +4273,8 @@ static int show_call(struct seq_file *m, void *data)union acpi_object *obj;acpi_status status; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID , -0 , asus->debug.method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (asus->debug.method_id, + &input, &output);if (ACPI_FAILURE (status))return -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1705/3318 mm: disallow ioremaping ordinary RAM in generic_access_phys()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 4590752e20aa393cc0d4fe538c0747d14a98c97a ]
generic_access_phys() can end up getting called on CoW PFNMAP mappings, resulting in it trying to ioremap anonymous folios, which especially the x86 code doesn't enjoy, and which is in general just odd/wrong.
E.g., with a CoW mapping of a PCI BAR:
ioremap on RAM at 0x0000000045623000 - 0x0000000045623fff
WARNING: arch/x86/mm/ioremap.c:216 at __ioremap_caller.isra.0+0x4c2/0x5f0 Call Trace: generic_access_phys+0x130/0x4d0 mm/memory.c:7178 kernfs_vma_access+0x1ce/0x280 fs/kernfs/file.c:437 __access_remote_vm+0x58f/0x890 mm/memory.c:7256 mem_rw+0x2a1/0x670 fs/proc/base.c:912
But more generically, we should disallow access to anything that looks like ordinary RAM in the system: including allocating memory (e.g., alloc_pages) and mapping them in a VM_PFNMAP.
For pages with an online memmap, allow only pages marked as reserved (PageReserved). This also includes memblock allocations, however, distinguishing them from other MMIO is tricky, and nobody should really be mapping them in a PFNMAP (except someone abusing /dev/mem, which we do not care about).
So only allow access if there is no online memmap, or if the pages are marked reserved. Reject other pages with -EINVAL.
Note that, just like other pfn_to_online_page() users, we won't care about concurrent memory offlining; mapping memory that can concurrently get offlined is highly dubious.
--- mm/memory.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
mm/memory.c +14 -0
@@ -5757,6 +5757,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,resource_size_t phys_addr;unsigned long prot =0 ;void __iomem *maddr; +struct page *page;pte_t *ptep, pte;spinlock_t *ptl;int offset =offset_in_page (addr);
@@ -5769,6 +5770,19 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,if (follow_pte (vma->vm_mm, addr, &ptep, &ptl))return -EINVAL ; pte =ptep_get (ptep); + +/* +* Reject anything that looks like ordinary RAM, including anonymous +* folios in CoW mappings or allocated kernel memory. Note that we +* cannot distinguish memblock allocations from non-RAM reliably, so +* we cannot easily reject them here. +*/ + page =pfn_to_online_page (pte_pfn (pte)); +if (page && !PageReserved (page)) { +pte_unmap_unlock (ptep, ptl); +return -EINVAL ; + } +pte_unmap_unlock (ptep, ptl); prot =pgprot_val (pte_pgprot (pte));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1706/3318 KVM: arm64: Move IN_GUEST_MODE ahead of state being loaded
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 22b6557ad05bf05c73246f62c19af3e04017270e ]
IN_GUEST_MODE is advertised too late, when state has already been moved onto CPU registers and cannot be observed by another CPU anymore.
Move the IN_GUEST_MODE publication ahead of the state being loaded, and immediately check for pending request. This ensures that there is no window of opportunity for another CPU to observe OUTSIDE_GUEST_MODE and yet for state to be loaded.
This also simplifies the "state rollback", which solely amounts to synchronising the timer when no irqchip is present.
--- arch/arm64/kvm/arm.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
arch/arm64/kvm/arm.c +10 -7
@@ -959,30 +959,33 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)local_irq_disable (); -kvm_vgic_flush_hwstate (vcpu); - -kvm_pmu_update_vcpu_events (vcpu); -/* * Ensure we set mode to IN_GUEST_MODE after we disable * interrupts and before the final VCPU requests check. * See the comment in kvm_vcpu_exiting_guest_mode() and * Documentation/virt/kvm/vcpu-requests.rst +* +* Requests to self must be posted before this point, or +* won't be taken into account until the next exit. No state +* loading other than what happens at vcpu_load() time can +* be done before we have checked for pending requests. */ smp_store_mb (vcpu->mode,IN_GUEST_MODE );if (ret <=0 ||kvm_vcpu_exit_request (vcpu, &ret)) { -isb ();/* Ensure work in x_flush_hwstate is committed */ -kvm_pmu_sync_hwstate (vcpu);if (unlikely (!irqchip_in_kernel (vcpu->kvm)))kvm_timer_sync_user (vcpu); -kvm_vgic_sync_hwstate (vcpu);smp_store_release (&vcpu->mode,OUTSIDE_GUEST_MODE );local_irq_enable ();preempt_enable ();continue ; } +/* From here onwards, we are commited to entering the guest */ +kvm_vgic_flush_hwstate (vcpu); + +kvm_pmu_update_vcpu_events (vcpu); +kvm_arm_setup_debug (vcpu);kvm_arch_vcpu_ctxflush_fp (vcpu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1707/3318 media: rockchip: rga: use clk_bulk api
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Püschel <[email protected]>
[ Upstream commit a2a4f69fd2e333bacd17d1788eb5211cb6f373cc ]
Use the clk_bulk API to avoid code duplication for each of the three clocks.
Stable-dep-of: a875c43dd95e ("media: rockchip: rga: quiesce IRQ before releasing m2m state")
--- drivers/media/platform/rockchip/rga/rga.c | 65 +++-------------------- drivers/media/platform/rockchip/rga/rga.h | 6 +-- 2 files changed, 11 insertions(+), 60 deletions(-)
drivers/media/platform/rockchip/rga/rga.c +8 -57
@@ -690,48 +690,10 @@ static const struct video_device rga_videodev = { .device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING, }; -static int rga_enable_clocks (struct rockchip_rga *rga) -{ -int ret; - - ret =clk_prepare_enable (rga->sclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga sclk: %d\n" , ret); -return ret; - } - - ret =clk_prepare_enable (rga->aclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga aclk: %d\n" , ret); - goto err_disable_sclk; - } - - ret =clk_prepare_enable (rga->hclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga hclk: %d\n" , ret); - goto err_disable_aclk; - } - -return 0 ; - -err_disable_aclk: -clk_disable_unprepare (rga->aclk); -err_disable_sclk: -clk_disable_unprepare (rga->sclk); - -return ret; -} - -static void rga_disable_clocks (struct rockchip_rga *rga) -{ -clk_disable_unprepare (rga->sclk); -clk_disable_unprepare (rga->hclk); -clk_disable_unprepare (rga->aclk); -} -static int rga_parse_dt (struct rockchip_rga *rga) {struct reset_control *core_rst, *axi_rst, *ahb_rst; +int ret; core_rst =devm_reset_control_get (rga->dev,"core" );if (IS_ERR (core_rst)) {
@@ -763,23 +725,12 @@ static int rga_parse_dt(struct rockchip_rga *rga)udelay (1 );reset_control_deassert (ahb_rst); - rga->sclk =devm_clk_get (rga->dev,"sclk" ); -if (IS_ERR (rga->sclk)) { -dev_err (rga->dev,"failed to get sclk clock\n" ); -return PTR_ERR (rga->sclk); - } - - rga->aclk =devm_clk_get (rga->dev,"aclk" ); -if (IS_ERR (rga->aclk)) { -dev_err (rga->dev,"failed to get aclk clock\n" ); -return PTR_ERR (rga->aclk); - } - - rga->hclk =devm_clk_get (rga->dev,"hclk" ); -if (IS_ERR (rga->hclk)) { -dev_err (rga->dev,"failed to get hclk clock\n" ); -return PTR_ERR (rga->hclk); + ret =devm_clk_bulk_get_all (rga->dev, &rga->clks); +if (ret <0 ) { +dev_err (rga->dev,"failed to get clocks\n" ); +return ret; } + rga->num_clks = ret;return 0 ; }
@@ -941,7 +892,7 @@ static int __maybe_unused rga_runtime_suspend(struct device *dev) {struct rockchip_rga *rga =dev_get_drvdata (dev); -rga_disable_clocks (rga); +clk_bulk_disable_unprepare (rga->num_clks, rga->clks);return 0 ; }
@@ -950,7 +901,7 @@ static int __maybe_unused rga_runtime_resume(struct device *dev) {struct rockchip_rga *rga =dev_get_drvdata (dev); -return rga_enable_clocks (rga); +return clk_bulk_prepare_enable (rga->num_clks, rga->clks); }static const struct dev_pm_ops rga_pm = {
drivers/media/platform/rockchip/rga/rga.h +3 -3
@@ -6,6 +6,7 @@#ifndef __RGA_H__#define __RGA_H__ +#include <linux/clk.h> #include <linux/platform_device.h> #include <media/videobuf2-v4l2.h> #include <media/v4l2-ctrls.h>
@@ -68,9 +69,8 @@ struct rockchip_rga {struct device *dev;struct regmap *grf;void __iomem *regs; -struct clk *sclk; -struct clk *aclk; -struct clk *hclk; +struct clk_bulk_data *clks; +int num_clks;struct rockchip_rga_version version;/* vfd lock */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1708/3318 media: rockchip: rga: quiesce IRQ before releasing m2m state
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit a875c43dd95ee4f9c4e3e5ae1cb8362cc6d7817d ]
rga_remove() releases the m2m state before the IRQ is freed. The IRQ is devm-managed and is only released once rga_remove() returns, so rga_isr() can still run while the m2m device state is being torn down.
Store the IRQ number in struct rockchip_rga, unregister the video device first, and free the IRQ before releasing the m2m state so the handler cannot run against the freed state.
--- drivers/media/platform/rockchip/rga/rga.c | 4 +++- drivers/media/platform/rockchip/rga/rga.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/rockchip/rga/rga.c +3 -1
@@ -770,6 +770,7 @@ static int rga_probe(struct platform_device *pdev) ret = irq; goto err_put_clk; } + rga->irq = irq; ret =devm_request_irq (rga->dev, irq, rga_isr,0 ,dev_name (rga->dev), rga);
@@ -881,8 +882,9 @@ static void rga_remove(struct platform_device *pdev)v4l2_info (&rga->v4l2_dev,"Removing\n" ); -v4l2_m2m_release (rga->m2m_dev);video_unregister_device (rga->vfd); +devm_free_irq (rga->dev, rga->irq, rga); +v4l2_m2m_release (rga->m2m_dev);v4l2_device_unregister (&rga->v4l2_dev);pm_runtime_disable (rga->dev);
drivers/media/platform/rockchip/rga/rga.h +1 -0
@@ -69,6 +69,7 @@ struct rockchip_rga {struct device *dev;struct regmap *grf;void __iomem *regs; +int irq;struct clk_bulk_data *clks;int num_clks;struct rockchip_rga_version version;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1709/3318 fbdev: core: Initialize modelist in framebuffer_alloc()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrey Misiurov <[email protected]>
[ Upstream commit 0c9cb9321cb3863b52bdea4b8ae5a27705762c9e ]
framebuffer_alloc() returns zeroed memory, so info->modelist starts out with NULL next and prev pointers. The list head is initialized only later, by fb_videomode_to_modelist() or by do_register_framebuffer().
The "fix potential memory leak" commits listed below added fb_destroy_modelist(&info->modelist) to the probe error paths of s3fb, tdfxfb, tridentfb, i740fb and carminefb. These paths can run before the list head is initialized:
- s3fb, tdfxfb, tridentfb and i740fb call fb_videomode_to_modelist() only after a successful EDID read, and tridentfb can also hit the error path on an ioremap() or kmalloc() failure before that;
- carminefb jumps to the error path when fb_find_mode() fails, before its fb_videomode_to_modelist() call.
fb_destroy_modelist() then dereferences the NULL head. Reproduced on Debian 12 (6.1.180) by binding s3fb to a VGA device without EDID and forcing fb_alloc_cmap() to fail:
s3fb 0000:00:03.0: cannot allocate colormap
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:fb_destroy_modelist+0x10/0x80 Call Trace: s3_pci_probe.cold+0x12b/0x2bf [s3fb] local_pci_probe+0x41/0x80 pci_device_probe+0xc3/0x240 really_probe+0xde/0x380 __driver_probe_device+0x84/0x150 driver_probe_device+0x1f/0x90 __driver_attach+0xce/0x1c0 bus_for_each_dev+0x87/0xd0 bus_add_driver+0x1ae/0x200 driver_register+0x89/0xe0 do_one_initcall+0x59/0x220 do_init_module+0x4a/0x1f0
Initialize the list head in framebuffer_alloc(), so info->modelist is always a valid, possibly empty, list and fb_destroy_modelist() is safe on every error path. Keep the lazy initialization in do_register_framebuffer(), as drivers that embed struct fb_info rather than calling framebuffer_alloc() still depend on it.
--- drivers/video/fbdev/core/fb_info.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/core/fb_info.c +1 -0
@@ -42,6 +42,7 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev) info->device = dev; info->fbcon_rotate_hint =-1 ; +INIT_LIST_HEAD (&info->modelist);#if IS_ENABLED (CONFIG_FB_BACKLIGHT )mutex_init (&info->bl_curve_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1710/3318 s390/pci: Add error cleanup in zpci_directed_irq_init()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tobias Schumacher <[email protected]>
[ Upstream commit 769f66f595c11185c66913ea5d96420504bfebc3 ]
If per-CPU airq_iv allocation fails in the loop, previously allocated vectors and arrays leak. Add proper error path to release all resources on failure.
The error path frees zpci_sbv, but SIC_IRQ_MODE_DIRECT has already programmed its address into the hardware. Set the directed interrupt mode only after all allocations have succeeded, so a failed init leaves no freed memory registered with the hardware.
--- arch/s390/pci/pci_irq.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
arch/s390/pci/pci_irq.c +19 -7
@@ -450,15 +450,10 @@ static int __init zpci_directed_irq_init(void)if (!zpci_sbv)return -ENOMEM ; - iib.diib.isc =PCI_ISC ; - iib.diib.nr_cpus =num_possible_cpus (); - iib.diib.disb_addr =virt_to_phys (zpci_sbv->vector); -zpci_set_irq_ctrl (SIC_IRQ_MODE_DIRECT ,0 , &iib); - zpci_ibv =kcalloc (num_possible_cpus (),sizeof (*zpci_ibv),GFP_KERNEL );if (!zpci_ibv) -return -ENOMEM ; + goto out_free_sbv;for_each_possible_cpu (cpu) {/*
@@ -470,13 +465,30 @@ static int __init zpci_directed_irq_init(void)AIRQ_IV_CACHELINE | (!cpu ? AIRQ_IV_ALLOC : 0), NULL);if (!zpci_ibv[cpu]) -return -ENOMEM ; + goto out_free_dibv; } + + iib.diib.isc =PCI_ISC ; + iib.diib.nr_cpus =num_possible_cpus (); + iib.diib.disb_addr =virt_to_phys (zpci_sbv->vector); +zpci_set_irq_ctrl (SIC_IRQ_MODE_DIRECT ,0 , &iib);on_each_cpu (cpu_enable_directed_irq,NULL ,1 ); zpci_irq_chip.irq_set_affinity = zpci_set_irq_affinity;return 0 ; + +out_free_dibv: +for_each_possible_cpu (cpu) { +if (zpci_ibv[cpu]) +airq_iv_release (zpci_ibv[cpu]); + } +kfree (zpci_ibv); + zpci_ibv =NULL ; +out_free_sbv: +airq_iv_release (zpci_sbv); + zpci_sbv =NULL ; +return -ENOMEM ; }static int __init zpci_floating_irq_init (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1711/3318 ALSA: mpu401: shut down timer before freeing MPU
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 9332af5220d42341bb1446a62c545c0518e990ef ]
When an MPU401 interface has no usable IRQ, the driver polls raw-MIDI input and output with a timer. During raw-MIDI teardown, the timer callback can already be running when snd_mpu401_uart_remove_timer() clears the last mode bit and calls timer_delete(). That API neither waits for a running callback nor prevents it from rearming the timer, and free_irq() does not synchronize timer callbacks. snd_mpu401_uart_free() can therefore release mpu while the timer callback still uses it.
Initialize the timer once when the MPU object is created and only rearm it while a timer mode is active. Shut it down synchronously after freeing the IRQ so an in-flight callback completes before mpu and its resources are released.
--- sound/drivers/mpu401/mpu401_uart.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
sound/drivers/mpu401/mpu401_uart.c +5 -3
@@ -161,14 +161,15 @@ static void snd_mpu401_uart_timer(struct timer_list *t)spin_lock_irqsave (&mpu->timer_lock, flags);/*mpu->mode |= MPU401_MODE_TIMER;*/ -mod_timer (&mpu->timer,1 + jiffies); +if (mpu->timer_invoked) +mod_timer (&mpu->timer,1 + jiffies);spin_unlock_irqrestore (&mpu->timer_lock, flags);if (mpu->rmidi)_snd_mpu401_uart_interrupt (mpu); }/* -* initialize the timer callback if not programmed yet +* arm the timer if it is not already active */ static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu,int input) {
@@ -176,7 +177,6 @@ static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input)spin_lock_irqsave (&mpu->timer_lock, flags);if (mpu->timer_invoked ==0 ) { -timer_setup (&mpu->timer, snd_mpu401_uart_timer,0 );mod_timer (&mpu->timer,1 + jiffies); } mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER :
@@ -490,6 +490,7 @@ static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi)struct snd_mpu401 *mpu = rmidi->private_data;if (mpu->irq >=0 )free_irq (mpu->irq, (void *) mpu); +timer_shutdown_sync (&mpu->timer);release_and_free_resource (mpu->res);kfree (mpu); }
@@ -544,6 +545,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,spin_lock_init (&mpu->input_lock);spin_lock_init (&mpu->output_lock);spin_lock_init (&mpu->timer_lock); +timer_setup (&mpu->timer, snd_mpu401_uart_timer,0 ); mpu->hardware = hardware; mpu->irq =-1 ;if (! (info_flags &MPU401_INFO_INTEGRATED )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1712/3318 f2fs: convert f2fs_mpage_readpages() to use folio
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit db92e6c729d87e6f5b0f467f01a96dbf1e452106 ]
Convert f2fs_mpage_readpages() to use folio and related functionality.
Stable-dep-of: b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
--- fs/f2fs/data.c | 80 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 40 deletions(-)
fs/f2fs/data.c +40 -40
@@ -2375,7 +2375,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,* Major change was from block_size == page_size in f2fs by default. */ static int f2fs_mpage_readpages (struct inode *inode, -struct readahead_control *rac,struct page *page) +struct readahead_control *rac,struct folio *folio) {struct bio *bio =NULL ;sector_t last_block_in_bio =0 ;
@@ -2395,6 +2395,7 @@ static int f2fs_mpage_readpages(struct inode *inode,#endif unsigned nr_pages = rac ?readahead_count (rac) :1 ;unsigned max_nr_pages = nr_pages; +pgoff_t index;int ret =0 ; map.m_pblk =0 ;
@@ -2408,64 +2409,63 @@ static int f2fs_mpage_readpages(struct inode *inode,for (; nr_pages; nr_pages--) {if (rac) { - page =readahead_page (rac); -prefetchw (&page->flags); + folio =readahead_folio (rac); +prefetchw (&folio->flags); } -#ifdef CONFIG_F2FS_FS_COMPRESSION - if (f2fs_compressed_file(inode)) { - /* there are remained compressed pages, submit them */ - if (!f2fs_cluster_can_merge_page(&cc, page->index)) { - ret = f2fs_read_multi_pages(&cc, &bio, - max_nr_pages, - &last_block_in_bio, - rac != NULL, false); - f2fs_destroy_compress_ctx(&cc, false); - if (ret) - goto set_error_page; - } - if (cc.cluster_idx == NULL_CLUSTER) { - if (nc_cluster_idx == - page->index >> cc.log_cluster_size) { - goto read_single_page; - } - - ret = f2fs_is_compressed_cluster(inode, page->index); - if (ret < 0) - goto set_error_page; - else if (!ret) { - nc_cluster_idx = - page->index >> cc.log_cluster_size; - goto read_single_page; - } + index =folio_index (folio); - nc_cluster_idx = NULL_CLUSTER; - } - ret = f2fs_init_compress_ctx(&cc); +#ifdef CONFIG_F2FS_FS_COMPRESSION + if (!f2fs_compressed_file(inode)) + goto read_single_page; + + /* there are remained compressed pages, submit them */ + if (!f2fs_cluster_can_merge_page(&cc, index)) { + ret = f2fs_read_multi_pages(&cc, &bio, + max_nr_pages, + &last_block_in_bio, + rac != NULL, false); + f2fs_destroy_compress_ctx(&cc, false); if (ret) goto set_error_page; + } + if (cc.cluster_idx == NULL_CLUSTER) { + if (nc_cluster_idx == index >> cc.log_cluster_size) + goto read_single_page; - f2fs_compress_ctx_add_page(&cc, page); + ret = f2fs_is_compressed_cluster(inode, index); + if (ret < 0) + goto set_error_page; + else if (!ret) { + nc_cluster_idx = + index >> cc.log_cluster_size; + goto read_single_page; + } - goto next_page; + nc_cluster_idx = NULL_CLUSTER; } + ret = f2fs_init_compress_ctx(&cc); + if (ret) + goto set_error_page; + + f2fs_compress_ctx_add_page(&cc, &folio->page); + + goto next_page; read_single_page: #endif - ret = f2fs_read_single_page(inode, page, max_nr_pages, &map, + ret = f2fs_read_single_page(inode, &folio->page, max_nr_pages, &map, &bio, &last_block_in_bio, rac); if (ret) { #ifdef CONFIG_F2FS_FS_COMPRESSION set_error_page: #endif - zero_user_segment(page, 0, PAGE_SIZE); - unlock_page(page); + folio_zero_segment(folio, 0, folio_size(folio)); + folio_unlock(folio); } #ifdef CONFIG_F2FS_FS_COMPRESSION next_page: #endif - if (rac) - put_page(page); #ifdef CONFIG_F2FS_FS_COMPRESSION if (f2fs_compressed_file(inode)) {
@@ -2502,7 +2502,7 @@ static int f2fs_read_data_folio(struct file *file, struct folio *folio)if (f2fs_has_inline_data (inode)) ret =f2fs_read_inline_data (inode, page);if (ret == -EAGAIN ) - ret =f2fs_mpage_readpages (inode,NULL , page); + ret =f2fs_mpage_readpages (inode,NULL , folio);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1713/3318 f2fs: convert f2fs_read_single_page() to use folio
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit ed54eed355675f79d9322c07d92f38037fc6b514 ]
Convert f2fs_read_single_page() to use folio and related functionality.
Stable-dep-of: b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
--- fs/f2fs/data.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
fs/f2fs/data.c +14 -13
@@ -2089,7 +2089,7 @@ static inline loff_t f2fs_readpage_limit(struct inode *inode)return i_size_read (inode); } -static int f2fs_read_single_page(struct inode *inode, struct page *page, +static int f2fs_read_single_page(struct inode *inode, struct folio *folio, unsigned nr_pages, struct f2fs_map_blocks *map, struct bio **bio_ret,
@@ -2102,9 +2102,10 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,sector_t last_block;sector_t last_block_in_file;sector_t block_nr; +pgoff_t index =folio_index (folio);int ret =0 ; - block_in_file = (sector_t )page_index (page); + block_in_file = (sector_t )index; last_block = block_in_file + nr_pages; last_block_in_file =bytes_to_blks (inode,f2fs_readpage_limit (inode) + blocksize -1 );
@@ -2135,7 +2136,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, got_it:if ((map->m_flags &F2FS_MAP_MAPPED )) { block_nr = map->m_pblk + block_in_file - map->m_lblk; -SetPageMappedToDisk (page); +folio_set_mappedtodisk (folio);if (!f2fs_is_valid_blkaddr (F2FS_I_SB (inode), block_nr,DATA_GENERIC_ENHANCE_READ )) {
@@ -2146,15 +2147,15 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, } }else { zero_out: -zero_user_segment (page,0 ,PAGE_SIZE ); -if (f2fs_need_verity (inode, page->index) && - !fsverity_verify_page (page)) { +folio_zero_segment (folio,0 ,folio_size (folio)); +if (f2fs_need_verity (inode, index) && + !fsverity_verify_folio (folio)) { ret = -EIO ; goto out; } -if (!PageUptodate (page)) -SetPageUptodate (page); -unlock_page (page); +if (!folio_test_uptodate (folio)) +folio_mark_uptodate (folio); +folio_unlock (folio); goto out; }
@@ -2164,14 +2165,14 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,*/ if (bio && (!page_is_mergeable (F2FS_I_SB (inode), bio, *last_block_in_bio, block_nr) || - !f2fs_crypt_mergeable_bio (bio, inode, page->index,NULL ))) { + !f2fs_crypt_mergeable_bio (bio, inode, index,NULL ))) { submit_and_realloc:f2fs_submit_read_bio (F2FS_I_SB (inode), bio,DATA ); bio =NULL ; }if (bio ==NULL ) { bio =f2fs_grab_read_bio (inode, block_nr, nr_pages, - is_readahead ?REQ_RAHEAD :0 , page->index, + is_readahead ?REQ_RAHEAD :0 , index, false);if (IS_ERR (bio)) { ret =PTR_ERR (bio);
@@ -2186,7 +2187,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,*/ f2fs_wait_on_block_writeback (inode, block_nr); -if (bio_add_page (bio, page, blocksize,0 ) < blocksize) +if (!bio_add_folio (bio, folio, blocksize,0 )) goto submit_and_realloc;inc_page_count (F2FS_I_SB (inode),F2FS_RD_DATA );
@@ -2454,7 +2455,7 @@ static int f2fs_mpage_readpages(struct inode *inode, read_single_page:#endif - ret =f2fs_read_single_page (inode, &folio->page, max_nr_pages, &map, + ret =f2fs_read_single_page (inode, folio, max_nr_pages, &map, &bio, &last_block_in_bio, rac);if (ret) {#ifdef CONFIG_F2FS_FS_COMPRESSION
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1714/3318 f2fs: remove mappedtodisk flag usage in mmap write path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nanzhe Zhao <[email protected]>
[ Upstream commit b3c9843589257631bac18f30655e82d88970688a ]
PG_mappedtodisk was inherited from the nobh/buffer-head era. However, f2fs has no buffer heads and the flag is no longer meaningful. The only user of the flag is the "no holes" shortcut in f2fs_vm_page_mkwrite(), which makes mmap write faults skip marking the folio dirty. Moreover, it causes the following race condition with filesystem freezing:
CPU0 (write fault) CPU1 (freeze_super)
---- ----
f2fs_vm_page_mkwrite()
sb_start_pagefault()
/* shortcut: no dirty */
sb_end_pagefault()
sb_wait_write(SB_FREEZE_PAGEFAULT)
/* no waiter, passes */
sync_filesystem()
/* folio not dirty, skipped */ finish_fault()
/* PTE writable */
fault_dirty_shared_page()
folio_mark_dirty()
/* dirty folio on a frozen fs */
It will also skip APP_MAPPED_IO iostat/REQ_TIME updates and post-EOF folio zeroing.
Remove this shortcut in f2fs_vm_page_mkwrite() and stop setting it in f2fs_read_single_page().
--- fs/f2fs/data.c | 1 - fs/f2fs/file.c | 6 ------ 2 files changed, 7 deletions(-)
fs/f2fs/data.c +0 -1
@@ -2136,7 +2136,6 @@ static int f2fs_read_single_page(struct inode *inode, struct folio *folio, got_it:if ((map->m_flags &F2FS_MAP_MAPPED )) { block_nr = map->m_pblk + block_in_file - map->m_lblk; -folio_set_mappedtodisk (folio);if (!f2fs_is_valid_blkaddr (F2FS_I_SB (inode), block_nr,DATA_GENERIC_ENHANCE_READ )) {
fs/f2fs/file.c +0 -6
@@ -215,12 +215,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)/* wait for GCed page writeback via META_MAPPING */ f2fs_wait_on_block_writeback (inode, dn.data_blkaddr); -/* -* check to see if the page is mapped already (no holes) -*/ -if (folio_test_mappedtodisk (folio)) - goto out_sem; -/* page is wholly or partially inside EOF */ if (((loff_t)(folio->index +1 ) <<PAGE_SHIFT ) > isize) {loff_t offset;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1715/3318 mm: memcontrol: raise MEMCG_MAX for charges that fail without reclaiming
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Damato <[email protected]>
[ Upstream commit 374f65b1481992eb6b9c6bffd53f3afa5c2e94cf ]
Charges that exceed memory.max and return through the nomem label can raise no event and simply return -ENOMEM.
A non-blocking charge can hit the limit, get rejected, but is not visible in memory.events.
This was noticed in a production setting where bpf_mem_alloc() attempted to refill its per-cpu freelists, which triggered a non-blocking charge while at the limit.
Commit d6e103a757fa ("mm: memcontrol: do not miss MEMCG_MAX events for enforced allocations") added raised_max_event to cover charges that are force charged without ever reaching reclaim, but charges that are rejected outright were left out. Getting an allocation failure without the corresponding MEMCG_MAX event is unexpected and makes debugging and monitoring harder.
Raise the event on the way out for rejected charges as well, by routing the -ENOMEM return through the same exit path that already covers forced charges. The existing behavior of raising a MEMCG_MAX event on every charge/reclaim/retry iteration is left unchanged.
Tested with a module that performs accounted GFP_NOWAIT page allocations from a task in a cgroup at its memory.max, and measures the resulting memory.events:max delta. Without this patch the rejected charges raise no event at all; with it the delta matches the number of rejected charges exactly. A GFP_KERNEL|__GFP_NORETRY control, which reaches reclaim, raises the same two events per failed charge before and after, confirming the existing charge/reclaim/retry accounting is unchanged.
--- mm/memcontrol.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
mm/memcontrol.c +16 -12
@@ -2682,10 +2682,11 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask,bool drained = false;bool raised_max_event = false;unsigned long pflags; +int ret =0 ; retry:if (consume_stock (memcg, nr_pages)) -return 0 ; +return ret;if (!do_memsw_account () ||page_counter_try_charge (&memcg->memsw, batch, &counter)) {
@@ -2797,16 +2798,11 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask,* put the burden of reclaim on regular allocation requests * and let these go through as privileged allocations. */ -if (!(gfp_mask & (__GFP_NOFAIL | __GFP_HIGH))) -return -ENOMEM ; +if (!(gfp_mask & (__GFP_NOFAIL | __GFP_HIGH))) { + ret = -ENOMEM ; + goto out; + } force: -/* -* If the allocation has to be enforced, don't forget to raise -* a MEMCG_MAX event. -*/ -if (!raised_max_event) -memcg_memory_event (mem_over_limit,MEMCG_MAX ); -/* * The allocation either can't fail or will lead to more memory * being freed very soon. Allow memory usage go over the limit
@@ -2816,7 +2812,15 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask,if (do_memsw_account ())page_counter_charge (&memcg->memsw, nr_pages); -return 0 ; +out: +/* +* Don't forget to raise a MEMCG_MAX event for forced or rejected +* requests. +*/ +if (!raised_max_event) +memcg_memory_event (mem_over_limit,MEMCG_MAX ); + +return ret; done_restock:if (batch > nr_pages)
@@ -2869,7 +2873,7 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, gfpflags_allow_blocking(gfp_mask)) {mem_cgroup_handle_over_high (gfp_mask); } -return 0 ; +return ret; } static inline int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1716/3318 f2fs: atomic: fix to forbid dio in atomic_file
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit b2c160f4f3cfe9334b3e6bb52cb89a3a20ef0385 ]
atomic write can only be used via buffered IO, let's fail direct IO on atomic_file and return -EOPNOTSUPP.
Stable-dep-of: 06dfe4a7eb69 ("f2fs: disallow mmap write and data-modifying fallocate on atomic files")
--- fs/f2fs/file.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
fs/f2fs/file.c +24 -12
@@ -2275,6 +2275,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) goto out;f2fs_down_write (&fi->i_gc_rwsem[WRITE ]); +f2fs_down_write (&fi->i_gc_rwsem[READ ]);/* * Should wait end_io to count F2FS_WB_CP_DATA correctly by
@@ -2284,10 +2285,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)f2fs_warn (sbi,"Unexpected flush for atomic writes: ino=%lu, npages=%u" , inode->i_ino,get_dirty_pages (inode)); ret =filemap_write_and_wait_range (inode->i_mapping,0 ,LLONG_MAX ); -if (ret) { -f2fs_up_write (&fi->i_gc_rwsem[WRITE ]); - goto out; - } +if (ret) + goto out_unlock;/* Check if the inode already has a COW inode */ if (fi->cow_inode ==NULL ) {
@@ -2296,10 +2295,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)struct inode *dir =d_inode (dentry->d_parent); ret =f2fs_get_tmpfile (idmap, dir, &fi->cow_inode); -if (ret) { -f2fs_up_write (&fi->i_gc_rwsem[WRITE ]); - goto out; - } +if (ret) + goto out_unlock;set_inode_flag (fi->cow_inode,FI_COW_FILE );clear_inode_flag (fi->cow_inode,FI_INLINE_DATA );
@@ -2313,10 +2310,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)invalidate_mapping_pages (fi->cow_inode->i_mapping,0 ,-1 ); ret =f2fs_do_truncate_blocks (fi->cow_inode,0 , true); -if (ret) { -f2fs_up_write (&fi->i_gc_rwsem[WRITE ]); - goto out; - } +if (ret) + goto out_unlock; }f2fs_write_inode (inode,NULL );
@@ -2335,7 +2330,11 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) }f2fs_i_size_write (fi->cow_inode, isize); +out_unlock: +f2fs_up_write (&fi->i_gc_rwsem[READ ]);f2fs_up_write (&fi->i_gc_rwsem[WRITE ]); +if (ret) + goto out;f2fs_update_time (sbi,REQ_TIME ); fi->atomic_write_task = current;
@@ -4729,6 +4728,13 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)f2fs_down_read (&fi->i_gc_rwsem[READ ]); } +/* dio is not compatible w/ atomic file */ +if (f2fs_is_atomic_file (inode)) { +f2fs_up_read (&fi->i_gc_rwsem[READ ]); + ret = -EOPNOTSUPP ; + goto out; + } +/* * We have to use __iomap_dio_rw() and iomap_dio_complete() instead of * the higher-level function iomap_dio_rw() in order to ensure that the
@@ -5134,6 +5140,12 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)/* Determine whether we will do a direct write or a buffered write. */ dio =f2fs_should_use_dio (inode, iocb, from); +/* dio is not compatible w/ atomic write */ +if (dio &&f2fs_is_atomic_file (inode)) { + ret = -EOPNOTSUPP ; + goto out_unlock; + } +/* Possibly preallocate the blocks for the write. */ target_size = iocb->ki_pos +iov_iter_count (from); preallocated =f2fs_preallocate_blocks (iocb, from, dio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1717/3318 f2fs: disallow mmap write and data-modifying fallocate on atomic files
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daeho Jeong <[email protected]>
[ Upstream commit 06dfe4a7eb696d868b196c2a49873142f19bd862 ]
Stores through a shared writable mapping and fallocate with FALLOC_FL_PUNCH_HOLE, FALLOC_FL_ZERO_RANGE, FALLOC_FL_COLLAPSE_RANGE or FALLOC_FL_INSERT_RANGE do not go through ->write_begin, so they bypass the COW inode and modify the original inode directly. Reject them while the file is in atomic write mode, as fallocate already does for pinned and compressed files. A write fault gets SIGBUS and fallocate gets -EOPNOTSUPP.
fallocate without these flags only preallocates blocks and stays allowed.
f2fs_vm_page_mkwrite() cannot take inode_lock, so check the flag under invalidate_lock, and hold invalidate_lock in f2fs_ioc_start_atomic_write() from the flush until the flag is set. Otherwise a fault could check the flag, then start_atomic_write could flush and set the flag, and the fault would dirty the folio afterwards.
--- fs/f2fs/file.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
fs/f2fs/file.c +18 -2
@@ -178,6 +178,17 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)file_update_time (vmf->vma->vm_file);filemap_invalidate_lock_shared (inode->i_mapping); +/* +* mmap stores bypass the COW inode and would break atomicity. Check +* under invalidate_lock: f2fs_ioc_start_atomic_write() holds it while +* flushing dirty folios and setting FI_ATOMIC_FILE, so either it sees +* our dirty folio and writes it back, or we see the flag. +*/ +if (unlikely (f2fs_is_atomic_file (inode))) { + err = -EOPNOTSUPP ; + goto out_sem; + } +folio_lock (folio);/* * A concurrent buffered write can extend isize, so we store isize in a
@@ -1990,9 +2001,11 @@ static long f2fs_fallocate(struct file *file, int mode,/* * Pinned file should not support partial truncation since the block -* can be used by applications. +* can be used by applications. Atomic files should not either, since +* these modify the original inode directly and break atomicity. */ -if ((f2fs_compressed_file (inode) ||f2fs_is_pinned_file (inode)) && +if ((f2fs_compressed_file (inode) ||f2fs_is_pinned_file (inode) || +f2fs_is_atomic_file (inode)) && (mode & (FALLOC_FL_PUNCH_HOLE |FALLOC_FL_COLLAPSE_RANGE |FALLOC_FL_ZERO_RANGE |FALLOC_FL_INSERT_RANGE ))) { ret = -EOPNOTSUPP ;
@@ -2276,6 +2289,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)f2fs_down_write (&fi->i_gc_rwsem[WRITE ]);f2fs_down_write (&fi->i_gc_rwsem[READ ]); +/* serialize with f2fs_vm_page_mkwrite(), see the comment there */ +filemap_invalidate_lock (inode->i_mapping);/* * Should wait end_io to count F2FS_WB_CP_DATA correctly by
@@ -2331,6 +2346,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)f2fs_i_size_write (fi->cow_inode, isize); out_unlock: +filemap_invalidate_unlock (inode->i_mapping);f2fs_up_write (&fi->i_gc_rwsem[READ ]);f2fs_up_write (&fi->i_gc_rwsem[WRITE ]);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1718/3318 serial: sc16is7xx: declare SPR/TLR/XOFF2 register as volatile
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hugo Villeneuve <[email protected]>
[ Upstream commit 983f91e5f13149ade6dbd9568053ecd0ab5e9265 ]
SPR shares the same address space as TLR and XOFF2. If SPR or TLR were to be used eventually, this could lead to incorrect read value from the cache.
Prevent this potential bug by declaring SPR/TLR/XOFF2 as volatile.
Stable-dep-of: 1c41d09dcd07 ("serial: sc16is7xx: declare MCR and IER as volatile registers")
--- drivers/tty/serial/sc16is7xx.c | 1 + 1 file changed, 1 insertion(+)
drivers/tty/serial/sc16is7xx.c +1 -0
@@ -536,6 +536,7 @@ static bool sc16is7xx_regmap_volatile(struct device *dev, unsigned int reg)case SC16IS7XX_IIR_REG :case SC16IS7XX_LSR_REG :case SC16IS7XX_MSR_REG : +case SC16IS7XX_SPR_REG :/* Shared address space with TLR & XOFF2 */ case SC16IS7XX_TXLVL_REG :case SC16IS7XX_RXLVL_REG :case SC16IS7XX_IOSTATE_REG :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1719/3318 serial: sc16is7xx: add comments for lock requirements
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hugo Villeneuve <[email protected]>
[ Upstream commit 42405cb77fd35b5acc0e5a11d74eef68c2afa484 ]
Indicate why lock needs to be asserted when accessing
MSR register, as this is not immediately obvious when looking at this register in the device datasheet.
Stable-dep-of: 1c41d09dcd07 ("serial: sc16is7xx: declare MCR and IER as volatile registers")
--- drivers/tty/serial/sc16is7xx.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/tty/serial/sc16is7xx.c +5 -4
@@ -532,10 +532,10 @@ static const struct sc16is7xx_devtype sc16is762_devtype = {static bool sc16is7xx_regmap_volatile (struct device *dev,unsigned int reg) {switch (reg) { -case SC16IS7XX_RHR_REG : -case SC16IS7XX_IIR_REG : -case SC16IS7XX_LSR_REG : -case SC16IS7XX_MSR_REG : +case SC16IS7XX_RHR_REG :/* Shared address space with THR & DLL */ +case SC16IS7XX_IIR_REG :/* Shared address space with FCR & EFR */ +case SC16IS7XX_LSR_REG :/* Shared address space with XON2 */ +case SC16IS7XX_MSR_REG :/* Shared address space with TCR & XOFF1 */ case SC16IS7XX_SPR_REG :/* Shared address space with TLR & XOFF2 */ case SC16IS7XX_TXLVL_REG :case SC16IS7XX_RXLVL_REG :
@@ -780,6 +780,7 @@ static void sc16is7xx_update_mlines(struct sc16is7xx_one *one)unsigned long flags;unsigned int status, changed; +/* Lock required as MSR address is shared with TCR and XOFF1. */ lockdep_assert_held_once (&one->lock); status =sc16is7xx_get_hwmctrl (port);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1720/3318 serial: sc16is7xx: declare MCR and IER as volatile registers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hugo Villeneuve <[email protected]>
[ Upstream commit 1c41d09dcd07ee9648e20aa8238e404c2e6a12fb ]
MCR register has the same address as XON1 register. IER register has the same address as DLH register.
Which register is accessed depends on bits configuration in some other registers.
To prevent potential access errors, declare MCR and IER as volatile registers.
--- drivers/tty/serial/sc16is7xx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/serial/sc16is7xx.c +2 -0
@@ -533,7 +533,9 @@ static bool sc16is7xx_regmap_volatile(struct device *dev, unsigned int reg) {switch (reg) {case SC16IS7XX_RHR_REG :/* Shared address space with THR & DLL */ +case SC16IS7XX_IER_REG :/* Shared address space with DLH */ case SC16IS7XX_IIR_REG :/* Shared address space with FCR & EFR */ +case SC16IS7XX_MCR_REG :/* Shared address space with XON1 */ case SC16IS7XX_LSR_REG :/* Shared address space with XON2 */ case SC16IS7XX_MSR_REG :/* Shared address space with TCR & XOFF1 */ case SC16IS7XX_SPR_REG :/* Shared address space with TLR & XOFF2 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1721/3318 virtiofs: add FUSE protocol validation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuto Ohnuki <[email protected]>
[ Upstream commit 68b69fa0edb241a946cd4c850110990f30705164 ]
Add virtio_fs_verify_response() to validate that the server properly follows the FUSE protocol by checking:
- Response length is at least sizeof(struct fuse_out_header).
- oh.len matches the actual response length.
- oh.unique matches the request's unique identifier.
On validation failure, set error to -EIO and normalize oh.len to prevent underflow in copy_args_from_argbuf().
Addresses the TODO comment in virtio_fs_request_complete().
Stable-dep-of: 5364d081125a ("virtiofs: validate fixed-output response length")
--- fs/fuse/virtio_fs.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
fs/fuse/virtio_fs.c +25 -4
@@ -564,6 +564,27 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req) req->argbuf =NULL ; } +/* Verify that the server properly follows the FUSE protocol */ +static bool virtio_fs_verify_response (struct fuse_req *req,unsigned int len) +{ +struct fuse_out_header *oh = &req->out.h; + +if (len <sizeof (*oh)) { +pr_warn ("virtio-fs: response too short (%u)\n" , len); +return false; + } +if (oh->len != len) { +pr_warn ("virtio-fs: oh.len mismatch (%u != %u)\n" , oh->len, len); +return false; + } +if (oh->unique != req->in.h.unique) { +pr_warn ("virtio-fs: oh.unique mismatch (%llu != %llu)\n" , + oh->unique, req->in.h.unique); +return false; + } +return true; +} +/* Work function for request completion */ static void virtio_fs_request_complete (struct fuse_req *req,struct virtio_fs_vq *fsvq)
@@ -574,10 +595,6 @@ static void virtio_fs_request_complete(struct fuse_req *req,unsigned int len, i, thislen;struct page *page; -/* -* TODO verify that server properly follows FUSE protocol -* (oh.uniq, oh.len) -*/ args = req->args;copy_args_from_argbuf (args, req);
@@ -633,6 +650,10 @@ static void virtio_fs_requests_done_work(struct work_struct *work)virtqueue_disable_cb (vq);while ((req =virtqueue_get_buf (vq, &len)) !=NULL ) { +if (!virtio_fs_verify_response (req, len)) { + req->out.h.error = -EIO ; + req->out.h.len =sizeof (struct fuse_out_header ); + }spin_lock (&fpq->lock);list_move_tail (&req->list, &reqs);spin_unlock (&fpq->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1722/3318 virtiofs: validate fixed-output response length
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sung Byeongchan <[email protected]>
[ Upstream commit 5364d081125a34e90851fbb46ecc93f79339ce78 ]
A short successful virtiofs response can leave the fixed-output portion of the request argument buffer unwritten. The completion path nevertheless copies the full declared output to the request destination, allowing stale allocator contents to reach callers such as fuse_statfs().
Require successful fixed-output responses to contain their complete declared output. Continue to permit a shorter final argument only for out_argvar requests. Reject positive and internal restart error values and require valid error replies to be header-only. The error already stored in the FUSE output header is returned by fuse_request_end(), so do not copy output arguments from an error reply.
This was found by source review with AI assistance. A header-only successful FUSE_STATFS reply returned stale fields in nine of nine calls across three boots. The fixed kernel rejected the short response and preserved complete replies, valid negative-error replies, and variable-output replies.
--- fs/fuse/virtio_fs.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
fs/fuse/virtio_fs.c +30 -0
@@ -535,6 +535,10 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req)unsigned int num_out;unsigned int i; +/* fuse_request_end() returns this error; there are no args to copy. */ +if (req->out.h.error) + goto out; + remaining = req->out.h.len -sizeof (req->out.h); num_in = args->in_numargs - args->in_pages; num_out = args->out_numargs - args->out_pages;
@@ -560,6 +564,7 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req)if (args->out_argvar) args->out_args[args->out_numargs -1 ].size = remaining; +out:kfree (req->argbuf); req->argbuf =NULL ; }
@@ -567,7 +572,9 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req)/* Verify that the server properly follows the FUSE protocol */ static bool virtio_fs_verify_response (struct fuse_req *req,unsigned int len) { +struct fuse_args *args = req->args;struct fuse_out_header *oh = &req->out.h; +unsigned int expected;if (len <sizeof (*oh)) {pr_warn ("virtio-fs: response too short (%u)\n" , len);
@@ -582,6 +589,29 @@ static bool virtio_fs_verify_response(struct fuse_req *req, unsigned int len) oh->unique, req->in.h.unique);return false; } +if (oh->error <= -ERESTARTSYS || oh->error >0 ) { +pr_warn ("virtio-fs: invalid error value (%d)\n" , oh->error); +return false; + } + +if (oh->error) { +if (len !=sizeof (*oh)) { +pr_warn ("virtio-fs: error response too long (%u)\n" , len); +return false; + } +return true; + } + + expected =sizeof (*oh) + +fuse_len_args (args->out_numargs, args->out_args); +if (len > expected || + (len < expected && + (!args->out_argvar || + expected - len > args->out_args[args->out_numargs -1 ].size))) { +pr_warn ("virtio-fs: invalid response length (%u, expected %u)\n" , + len, expected); +return false; + }return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1723/3318 mm/page_table_check: skip zero pages
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 33afd07412a1efe5b750a3fd5eb0272ebdd12761 ]
page_table_check_set() accounts pages by whether they are PageAnon(). The shared zero page is a special page, not an ordinary file-backed page. Read faults on private anonymous mappings can install many read-only PTEs that point at the zero page, but page_table_check currently accounts them in file_map_count.
That lets an unprivileged process populate enough zero-page mappings to overflow file_map_count and trip the BUG_ON() in page_table_check_set().
Skip zero pages in page_table_check accounting. They do not need the anonymous/file mapping conflict checks that page_table_check performs for ordinary pages, and this keeps the existing counter size and page_ext layout unchanged.
--- mm/page_table_check.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_table_check.c +4 -2
@@ -67,7 +67,8 @@ static void page_table_check_clear(unsigned long pfn, unsigned long pgcnt)unsigned long i;bool anon; -if (!pfn_valid (pfn)) +if (!pfn_valid (pfn) ||is_zero_pfn (pfn) || +is_huge_zero_page (compound_head (pfn_to_page (pfn))))return ; page =pfn_to_page (pfn);
@@ -107,7 +108,8 @@ static void page_table_check_set(unsigned long pfn, unsigned long pgcnt,unsigned long i;bool anon; -if (!pfn_valid (pfn)) +if (!pfn_valid (pfn) ||is_zero_pfn (pfn) || +is_huge_zero_page (compound_head (pfn_to_page (pfn))))return ; page =pfn_to_page (pfn);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1724/3318 mm/memory: constrain generic_access_phys() to page boundary
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
[ Upstream commit ae0298a5fbeff32951c0d31398ccec97ec6aa0ea ]
This patch addresses an issue in generic_access_phys() where accessing memory across page boundaries in PFNMAP VMAs assumes physical pages are contiguous, which can lead to accessing unintended physical memory or exceeding VMA boundaries.
generic_access_phys() improperly validates the memory access range: it only validates the start address using follow_pfnmap_start() and passes PAGE_ALIGN(len + offset) to ioremap_prot().
This poses two problems:
1. In PFNMAP VMAs, consecutive virtual pages are not guaranteed to be physically contiguous, and individual PTEs may have different access permissions or writability.
2. The mapping may cross VMA boundaries if len extends beyond vma->vm_end.
Constrain the access in generic_access_phys() to at most the current page boundary (PAGE_SIZE - offset) and map only a single PAGE_SIZE via ioremap_prot(). Since the caller __access_remote_vm() already loops over the requested length and handles partial transfers, it will naturally iterate over the remaining pages.
Also add a missing (resource_size_t) cast during PFN re-validation to avoid truncation on 32-bit PAE systems.
--- mm/memory.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
mm/memory.c +7 -1
@@ -5766,6 +5766,12 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,if (!(vma->vm_flags & (VM_IO |VM_PFNMAP )))return -EINVAL ; +/* +* Limit access to one page at a time, as that's what follow_pte() +* guarantees; expect the caller to retry to read larger ranges. +*/ + len =min_t (int, len,PAGE_SIZE - offset); + retry:if (follow_pte (vma->vm_mm, addr, &ptep, &ptl))return -EINVAL ;
@@ -5791,7 +5797,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,if ((write &FOLL_WRITE ) && !pte_write (pte))return -EINVAL ; - maddr =ioremap_prot (phys_addr,PAGE_ALIGN (len + offset), prot); + maddr =ioremap_prot (phys_addr,PAGE_SIZE , prot);if (!maddr)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1725/3318 mptcp: fix MP_CAPABLE token migration when cloning reqsk
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruide Cao <[email protected]>
[ Upstream commit 2093bc7fa50056fef8620d2b82bcb2e9a0a5575d ]
TCP request migration clones pending request sockets with inet_reqsk_clone(). For MPTCP MP_CAPABLE requests this byte-copies the token_node hlist state into the clone even though the token table still names the original request, and the following warning can be seen:
WARNING: net/mptcp/token.c:364 at mptcp_token_destroy_request+0x2b0/0x330, CPU#2: swapper/2/0 CPU: 2 UID: 0 PID: 0 Comm: swapper/2 Not tainted 7.2.0-rc5-00353-gc27e36054537 #10 PREEMPT(full) RIP: 0010:mptcp_token_destroy_request (net/mptcp/token.c:364 (discriminator 1)) Call Trace: <IRQ> subflow_v4_req_destructor (net/mptcp/subflow.c:694) __reqsk_free (net/ipv4/inet_connection_sock.c:906) reqsk_timer_handler (include/net/request_sock.h:137 net/ipv4/inet_connection_sock.c:1147) call_timer_fn (kernel/time/timer.c:1748)
Move token request ownership from the original request to the clone under the token bucket lock. Make mptcp_token_accept() and mptcp_token_destroy_request() re-check token_node under the same lock and treat an already moved or removed request as a normal race instead of warning. This also keeps token bucket chain_len accounting balanced.
If a passive MP_CAPABLE socket cannot claim the token, destroy the provisional MPTCP socket and let the subflow fall back rather than installing a socket with mismatched token ownership. Mark that path as a passive handshake fallback so MPCapableFallbackACK records the downgrade.
If the speculative clone later loses the inet_ehash_insert() ownership arbitration, the original request may find that its token was already moved and fall back to plain TCP. The clone destructor then releases the token reservation and keeps chain_len balanced. This trades an exceptionally rare fallback for eliminating the warning and persistent accounting drift.
--- net/mptcp/protocol.c | 32 ++++++++++++++++---- net/mptcp/protocol.h | 4 ++- net/mptcp/subflow.c | 6 +++- net/mptcp/token.c | 68 +++++++++++++++++++++++++++++++++++++----- net/mptcp/token_test.c | 4 +-- 5 files changed, 98 insertions(+), 16 deletions(-)
net/mptcp/protocol.c +27 -5
@@ -3419,6 +3419,24 @@ static void mptcp_copy_ip_options(struct sock *newsk, const struct sock *sk)rcu_read_unlock (); } +static void mptcp_sk_clone_destroy (struct sock *nsk) +{ +struct mptcp_sock *msk =mptcp_sk (nsk); + +mptcp_release_sched (msk); +mptcp_set_state (nsk,TCP_CLOSE ); +/* inet_csk_prepare_forced_close() clears TCP sock_ops state via +* tcp_sk(), but nsk is an MPTCP master socket; keep the inet-level +* destroy preparation here. +*/ +bh_unlock_sock (nsk); +sock_put (nsk); +sock_set_flag (nsk,SOCK_DEAD ); +this_cpu_inc (*nsk->sk_prot->orphan_count); +inet_sk (nsk)->inet_num =0 ; +inet_csk_destroy_sock (nsk); +} + struct sock *mptcp_sk_clone_init(const struct sock *sk, const struct mptcp_options_received *mp_opt, struct sock *ssk,
@@ -3478,11 +3496,6 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,list_add (&subflow->node, &msk->conn_list);sock_hold (ssk); -/* new mpc subflow takes ownership of the newly -* created mptcp socket -*/ -mptcp_token_accept (subflow_req, msk); -/* set msk addresses early to ensure mptcp_pm_get_local_id() * uses the correct data */
@@ -3491,6 +3504,14 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,mptcp_rcv_space_init (msk, ssk); msk->rcvq_space.time =mptcp_stamp (); +if (!mptcp_token_accept (subflow_req, msk)) { +list_del_init (&subflow->node); +WRITE_ONCE (msk->first,NULL ); +sock_put (ssk); +mptcp_sk_clone_destroy (nsk); +return NULL ; + } +if (mp_opt->suboptions &OPTION_MPTCP_MPC_ACK )__mptcp_subflow_fully_established (msk, subflow, mp_opt);bh_unlock_sock (nsk);
@@ -3989,6 +4010,7 @@ static struct proto mptcp_prot = { .get_port = mptcp_get_port, .forward_alloc_get = mptcp_forward_alloc_get, .sockets_allocated = &mptcp_sockets_allocated, + .orphan_count = &tcp_orphan_count, .memory_allocated = &tcp_memory_allocated, .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc,
net/mptcp/protocol.h +3 -1
@@ -890,9 +890,11 @@ static inline void mptcp_token_init_request(struct request_sock *req) }int mptcp_token_new_request (struct request_sock *req); +void mptcp_token_move_request (struct request_sock *req, +struct request_sock *new_req);void mptcp_token_destroy_request (struct request_sock *req);int mptcp_token_new_connect (struct sock *ssk); -void mptcp_token_accept (struct mptcp_subflow_request_sock *r, +bool mptcp_token_accept (struct mptcp_subflow_request_sock *r,struct mptcp_sock *msk);bool mptcp_token_exists (u32 token);struct mptcp_sock *mptcp_token_get_sock (struct net *net,u32 token);
net/mptcp/subflow.c +5 -1
@@ -82,6 +82,8 @@ void mptcp_subflow_reqsk_clone(struct request_sock *req, } new_subflow_req->msk = msk; + +mptcp_token_move_request (req, new_req); } static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
@@ -911,8 +913,10 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,if (ctx->mp_capable) { ctx->conn =mptcp_sk_clone_init (listener->conn, &mp_opt, child, req); -if (!ctx->conn) +if (!ctx->conn) { + fallback = true; goto fallback; + } ctx->subflow_id =1 ; owner =mptcp_sk (ctx->conn);
net/mptcp/token.c +61 -7
107 lines not on this page · raw message
net/mptcp/token_test.c +2 -2
@@ -94,7 +94,7 @@ static void mptcp_token_test_accept(struct kunit *test)KUNIT_ASSERT_EQ (test,0 ,mptcp_token_new_request ((struct request_sock *)req)); msk->token = req->token; -mptcp_token_accept (req, msk); +KUNIT_EXPECT_TRUE (test,mptcp_token_accept (req, msk));KUNIT_EXPECT_PTR_EQ (test, msk,mptcp_token_get_sock (&init_net, msk->token));/* this is now a no-op */
@@ -117,7 +117,7 @@ static void mptcp_token_test_destroyed(struct kunit *test)KUNIT_ASSERT_EQ (test,0 ,mptcp_token_new_request ((struct request_sock *)req)); msk->token = req->token; -mptcp_token_accept (req, msk); +KUNIT_EXPECT_TRUE (test,mptcp_token_accept (req, msk));/* simulate race on removal */ refcount_set (&sk->sk_refcnt,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1726/3318 irqchip/atmel-aic[5]: Disable interrupts in the irq_pm_shutdown() callbacks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 0ca21fe111457c843624a835641bb490e704bb2f ]
irq_gc_shutdown() calls the irq_pm_shutdown() callbacks from syscore_shutdown() with interrupts enabled. aic_pm_shutdown() and aic5_pm_shutdown() take the generic chip lock with raw_spin_lock(), and irq_gc_eoi() takes the same lock from the interrupt handler. An interrupt from the chip while the lock is held spins in irq_gc_eoi() and hangs the reboot.
Lockdep reports this on every reboot of a SAM9X75 Curiosity board:
WARNING: inconsistent lock state
inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage. busybox/101 [HC0[0]:SC0[0]:HE1:SE1] takes:
c1c2b434 (&gc->lock){?.-.}-{2:2}, at: aic5_pm_shutdown+0x34/0xd8 {IN-HARDIRQ-W} state was registered at:
...
irq_gc_eoi+0x28/0x60
handle_fasteoi_irq+0x120/0x214 ...
aic5_pm_shutdown from irq_gc_shutdown+0x4c/0x58 irq_gc_shutdown from syscore_shutdown+0x5c/0x9c syscore_shutdown from kernel_restart+0x34/0x78 kernel_restart from sys_reboot+0x180/0x25c
Use the irqsave guard, as
commit 33517881ede7 ("irqchip/brcmstb-l2: Use _irqsave locking variants in non-interrupt code") did for brcmstb-l2.
--- drivers/irqchip/irq-atmel-aic.c | 5 +++-- drivers/irqchip/irq-atmel-aic5.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/irqchip/irq-atmel-aic.c +3 -2
@@ -126,11 +126,12 @@ static void aic_resume(struct irq_data *d)static void aic_pm_shutdown (struct irq_data *d) {struct irq_chip_generic *gc =irq_data_get_irq_chip_data (d); +unsigned long flags; -irq_gc_lock (gc); +irq_gc_lock_irqsave (gc, flags);irq_reg_writel (gc,0xffffffff ,AT91_AIC_IDCR );irq_reg_writel (gc,0xffffffff ,AT91_AIC_ICCR ); -irq_gc_unlock (gc); +irq_gc_unlock_irqrestore (gc, flags); }#else #define aic_suspend NULL
drivers/irqchip/irq-atmel-aic5.c +3 -2
@@ -224,15 +224,16 @@ static void aic5_pm_shutdown(struct irq_data *d)struct irq_domain_chip_generic *dgc = domain->gc;struct irq_chip_generic *bgc =irq_get_domain_generic_chip (domain,0 );struct irq_chip_generic *gc =irq_data_get_irq_chip_data (d); +unsigned long flags;int i; -irq_gc_lock (bgc); +irq_gc_lock_irqsave (bgc, flags);for (i =0 ; i < dgc->irqs_per_chip; i++) {irq_reg_writel (bgc, i + gc->irq_base,AT91_AIC5_SSR );irq_reg_writel (bgc,1 ,AT91_AIC5_IDCR );irq_reg_writel (bgc,1 ,AT91_AIC5_ICCR ); } - irq_gc_unlock(bgc); + irq_gc_unlock_irqrestore(bgc, flags); }#else #define aic5_suspend NULL
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1727/3318 irqchip/imx-intmux: Convert to platform_driver::remove_new() callback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 984e5c7b8d7bac9efd3818e06dcf1f7aab7701b2 ]
The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks.
To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove().
Trivially convert this driver from always returning zero in the remove callback to the void returning variant.
Stable-dep-of: b167c1a30e9e ("irqchip/imx-intmux: Fix runtime PM teardown on remove")
--- drivers/irqchip/irq-imx-intmux.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/irqchip/irq-imx-intmux.c +6 -8
@@ -282,7 +282,7 @@ static int imx_intmux_probe(struct platform_device *pdev)return ret; } -static int imx_intmux_remove (struct platform_device *pdev) +static void imx_intmux_remove (struct platform_device *pdev) {struct intmux_data *data =platform_get_drvdata (pdev);int i;
@@ -298,8 +298,6 @@ static int imx_intmux_remove(struct platform_device *pdev) }pm_runtime_disable (&pdev->dev); - -return 0 ; }#ifdef CONFIG_PM
@@ -354,11 +352,11 @@ static const struct of_device_id imx_intmux_id[] = {static struct platform_driver imx_intmux_driver = { .driver = { - .name ="imx-intmux" , - .of_match_table = imx_intmux_id, - .pm = &imx_intmux_pm_ops, + .name ="imx-intmux" , + .of_match_table = imx_intmux_id, + .pm = &imx_intmux_pm_ops, }, - .probe = imx_intmux_probe, - .remove = imx_intmux_remove, + .probe = imx_intmux_probe, + .remove_new = imx_intmux_remove, };builtin_platform_driver (imx_intmux_driver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1728/3318 irqchip/imx-intmux: Fix runtime PM teardown on remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit b167c1a30e9e020e4c5e102c7a555943742c024b ]
imx_intmux_probe() enables the IPG clock and then drops its runtime PM reference with pm_runtime_put(). With CONFIG_PM enabled, the runtime suspend callback disables the IPG clock. With CONFIG_PM disabled, the clock remains enabled after probe.
imx_intmux_remove() accesses the CHANIER registers without first making sure that the device is runtime active. The device may therefore be runtime suspended with the IPG clock disabled when these registers are accessed. In addition, the remove path only calls pm_runtime_disable() and does not balance the clock enable when CONFIG_PM is disabled.
Resume the device and acquire a runtime PM reference before accessing the registers. If resume fails, skip the register accesses but still tear down the chained handlers and IRQ domains. Disable runtime PM afterwards, drop the acquired reference without triggering another runtime suspend, and explicitly disable the IPG clock.
This keeps the clock enabled while the hardware registers are accessed and balances the clk_prepare_enable() performed during probe for both CONFIG_PM configurations.
This issue was found by manual code inspection.
--- drivers/irqchip/irq-imx-intmux.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/irqchip/irq-imx-intmux.c +12 -3
@@ -285,12 +285,16 @@ static int imx_intmux_probe(struct platform_device *pdev)static void imx_intmux_remove (struct platform_device *pdev) {struct intmux_data *data =platform_get_drvdata (pdev); -int i; +int i, ret; + + ret =pm_runtime_resume_and_get (&pdev->dev); +if (ret <0 ) +dev_warn (&pdev->dev,"failed to resume device: %d\n" , ret);for (i =0 ; i < data->channum; i++) {/* disable all interrupt sources of this channel */ -writel_relaxed (0 , data->regs +CHANIER (i)); - +if (ret >=0 ) +writel_relaxed (0 , data->regs +CHANIER (i));irq_set_chained_handler_and_data (data->irqchip_data[i].irq,NULL ,NULL );
@@ -298,6 +302,11 @@ static void imx_intmux_remove(struct platform_device *pdev) }pm_runtime_disable (&pdev->dev); +if (ret >=0 ) { +pm_runtime_put_noidle (&pdev->dev); +clk_disable_unprepare (data->ipg_clk); +pm_runtime_set_suspended (&pdev->dev); + } }#ifdef CONFIG_PM
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1729/3318 serial: sc16is7xx: fix data corruption due to unexpected xon/xoff
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Fuzzey <[email protected]>
[ Upstream commit 8bb50e95c0abd44607bc60a43032c1dbf7470d5a ]
The hardware supports automatically sending XON/OFF based on the FIFO status and that is already implemented by the driver. However that capability was not announced with the UPF_SOFT_FLOW bit.
When the port is opened with the default of XON enabled the driver configures that in the hardware.
If userspace does not want XON/OFF (which is normally the case) it will use TCSETS to disactivate it. However the serial core optimises this to only notify the driver if someting imporant has changed, and for XON/XOFF thit is only if the driver declares UPF_SOFT_FLOW.
So we end up with unwanted XON/XOFF in the data stream.
The problem only occurs if nothing else needed to be set by termios, ie if the user space requested values are the same as the default values, except for XON/XOFF.
Since the default speed is 9600 this means that the problem only occurs when requesting 9600, otherwise the call to the driver will be made to change the speed, and that will also clear the XON/XOFF.
As 9600 is quite rare these days that probably explains why this hasn't already been seen.
It also only occurs on the first port open after boot since the subsequent opens will use the "logical state" set by TCSETS but not communicated to the driver the first time.
--- drivers/tty/serial/sc16is7xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/sc16is7xx.c +1 -1
@@ -1588,7 +1588,7 @@ static int sc16is7xx_probe(struct device *dev, s->p[i].port.irq = irq; s->p[i].port.type =PORT_SC16IS7XX ; s->p[i].port.fifosize =SC16IS7XX_FIFO_SIZE ; - s->p[i].port.flags =UPF_FIXED_TYPE |UPF_LOW_LATENCY ; + s->p[i].port.flags =UPF_FIXED_TYPE |UPF_LOW_LATENCY |UPF_SOFT_FLOW ; s->p[i].port.iobase = i;/* * Use all ones as membase to make sure uart_configure_port() in
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1730/3318 PCI: rockchip: Drive at 2.5 GT/s, error other speeds
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geraldo Nascimento <[email protected]>
[ Upstream commit 84d08ff902f1ec01177fef1a21a38934927f5aee ]
Configure the core to be driven at 2.5 GT/s Link Speed and ignore any other speed with a warning. Also drop the 5.0 GT/s Link Speed defines from Rockchip PCIe header.
The reason is that Shawn Lin from Rockchip has reiterated that there may be danger of "catastrophic failure" in using their PCIe with 5.0 GT/s speeds.
While Rockchip has done so informally without issuing a proper errata, and the particulars are thus unknown, this may cause data loss or worse.
This change is corroborated by RK3399 official datasheet [1], which states maximum link speed for this platform is 2.5 GT/s.
[1] https://opensource.rock-chips.com/images/d/d7/Rockchip_RK3399_Datasheet_V2.1-20200323.pdf
--- drivers/pci/controller/pcie-rockchip.c | 14 ++++++-------- drivers/pci/controller/pcie-rockchip.h | 3 --- 2 files changed, 6 insertions(+), 11 deletions(-)
drivers/pci/controller/pcie-rockchip.c +6 -8
@@ -66,8 +66,10 @@ int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip) } rockchip->link_gen =of_pci_get_max_link_speed (node); -if (rockchip->link_gen <0 || rockchip->link_gen >2 ) - rockchip->link_gen =2 ; +if (rockchip->link_gen <0 || rockchip->link_gen >=2 ) { + rockchip->link_gen =1 ; +dev_warn (dev,"invalid max-link-speed, limited to 2.5 GT/s\n" ); + } rockchip->core_rst =devm_reset_control_get_exclusive (dev,"core" );if (IS_ERR (rockchip->core_rst)) {
@@ -237,12 +239,8 @@ int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) goto err_exit_phy; } -if (rockchip->link_gen ==2 ) -rockchip_pcie_write (rockchip,PCIE_CLIENT_GEN_SEL_2 , -PCIE_CLIENT_CONFIG ); -else -rockchip_pcie_write (rockchip,PCIE_CLIENT_GEN_SEL_1 , -PCIE_CLIENT_CONFIG ); +rockchip_pcie_write (rockchip,PCIE_CLIENT_GEN_SEL_1 , +PCIE_CLIENT_CONFIG ); regs =PCIE_CLIENT_LINK_TRAIN_ENABLE |PCIE_CLIENT_ARI_ENABLE |PCIE_CLIENT_CONF_LANE_NUM (rockchip->lanes);
drivers/pci/controller/pcie-rockchip.h +0 -3
@@ -37,7 +37,6 @@#define PCIE_CLIENT_MODE_RC HIWORD_UPDATE_BIT(0x0040)#define PCIE_CLIENT_MODE_EP HIWORD_UPDATE(0x0040, 0)#define PCIE_CLIENT_GEN_SEL_1 HIWORD_UPDATE(0x0080, 0) -#define PCIE_CLIENT_GEN_SEL_2 HIWORD_UPDATE_BIT(0x0080)#define PCIE_CLIENT_LEGACY_INT_CTRL (PCIE_CLIENT_BASE + 0x0c)#define PCIE_CLIENT_INT_IN_ASSERT HIWORD_UPDATE_BIT(0x0002)#define PCIE_CLIENT_INT_IN_DEASSERT HIWORD_UPDATE(0x0002, 0)
@@ -184,8 +183,6 @@ (((x) & PCIE_CLIENT_DEBUG_LTSSM_MASK) == PCIE_CLIENT_DEBUG_LTSSM_L2)#define PCIE_LINK_UP (x) \ (((x) & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_UP) -#define PCIE_LINK_IS_GEN2 (x) \ - (((x) & PCIE_CORE_PL_CONF_SPEED_MASK) == PCIE_CORE_PL_CONF_SPEED_5G)#define RC_REGION_0_ADDR_TRANS_H 0x00000000#define RC_REGION_0_ADDR_TRANS_L 0x00000000
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1731/3318 dm-bufio: fix non-working memory limit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit 1190dbeaeaa026a4879e675b8556a150c36a7ced ]
The function evict_old is supposed to loop and evict buffers while the allocated size is above the threshold. However if it hits one bufio client that is empty, it stops and doesn't attempt to scan other clients.
This commit fixes it, so that it skips empty clients and retries up to dm_bufio_client_count times.
--- drivers/md/dm-bufio.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-)
drivers/md/dm-bufio.c +37 -4
@@ -2499,6 +2499,13 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsigninit_waitqueue_head (&c->free_buffer_wait); c->async_write_error =0 ; +/* +* A client with no buffers yet is not holding the oldest buffer in +* the system; leaving this zeroed would claim exactly that and keep +* the client pinned at the front of dm_bufio_all_clients. +*/ + c->oldest_buffer = jiffies; + c->dm_io =dm_io_client_create ();if (IS_ERR (c->dm_io)) { r =PTR_ERR (c->dm_io);
@@ -2828,9 +2835,23 @@ static unsigned long __evict_a_few(unsigned long nr_buffers) count =__evict_many (c, ¶ms,LIST_CLEAN , nr_buffers);dm_bufio_unlock (c); -if (count) +if (count) { c->oldest_buffer = params.last_accessed; -__insert_client (c); +__insert_client (c); + }else { +/* +* We evicted nothing, so 'oldest_buffer' tells us nothing new +* and the client keeps its old, possibly very stale, value. +* Requeue it at the back rather than by that value, otherwise +* __insert_client() would put it straight back at the front +* and every subsequent call would pop this same client again, +* never reaching any of the others. +* +* This leaves the list slightly out of order, which is fine - +* it is only ever an approximation. +*/ +list_add_tail (&c->client_list, &dm_bufio_all_clients); + }return count; }
@@ -2855,11 +2876,23 @@ static void evict_old(void) {unsigned long threshold = dm_bufio_cache_size - dm_bufio_cache_size /DM_BUFIO_LOW_WATERMARK_RATIO ; +int unproductive =0 ;mutex_lock (&dm_bufio_clients_lock);while (dm_bufio_current_allocated > threshold) { -if (!__evict_a_few (64 )) -break ; +if (__evict_a_few (64 )) { + unproductive =0 ; + }else { +/* +* This client had nothing to give. Try the others +* before giving up: one idle client, or one whose +* buffers are all held, must not stop us evicting +* from everybody else. Stop once a whole sweep of +* the client list has freed nothing. +*/ +if (++unproductive >= dm_bufio_client_count) +break ; + }cond_resched (); }mutex_unlock (&dm_bufio_clients_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1732/3318 ASoC: qcom: q6apm-dai: wrap the position of a full ring to 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladyslav Tymoshchuk <[email protected]>
[ Upstream commit 0ea3e0b196f9dcc17b40ac881a6efef06459975b ]
q6apm_dai_pointer() turns the number of period buffers the DSP has returned in the current lap, 1..periods, into a position and reports one frame less than that. Commit a93dad6f4e6a ("ASoC: q6apm-dai: make use of q6apm_get_hw_pointer") added the "- 1" so that the end of the ring is not reported as a position equal to the buffer size.
One frame short has a cost once the application stops feeding the stream. The DSP returns the last queued buffer and the position stops at appl_ptr - 1, so avail stays at buffer_size - 1, below the default stop_threshold. The DSP sends nothing more as its queue is empty, so no period interrupt comes either: ALSA never detects the underrun and the stream stays RUNNING. A poll-driven application that missed its last wakeup waits forever, and drain only ends on its timeout, with -EIO. On capture, the last frame of each period is held back until the next one.
Before that commit the position wrapped to 0 at the end of the ring. Do that again. A full lap is the start of the ring, and snd_pcm_update_hw_ptr0() accounts for the wrap: the position cannot move by more than one lap between two updates, as each returned buffer calls snd_pcm_period_elapsed() and the DSP holds at most periods buffers.
Seen on a OnePlus Pad 3 (SM8750) with PipeWire in interrupt-driven
scheduling: after a stall the PCM sat at hw_ptr 78239, appl_ptr 78240 (avail 3839 of 3840) for two hours.
--- sound/soc/qcom/qdsp6/q6apm-dai.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
sound/soc/qcom/qdsp6/q6apm-dai.c +8 -4
@@ -440,11 +440,15 @@ static snd_pcm_uframes_t q6apm_dai_pointer(struct snd_soc_component *component,struct q6apm_dai_rtd *prtd = runtime->private_data;snd_pcm_uframes_t ptr; - ptr =q6apm_get_hw_pointer (prtd->graph, substream->stream) * runtime->period_size; -if (ptr) -return ptr -1 ; +/* +* The hw pointer counts the period buffers the DSP has returned in +* this lap, 1..periods. A full lap is the start of the ring again: +* report 0 rather than one frame less, so that the position of a +* drained buffer reaches appl_ptr and ALSA sees the underrun. +*/ + ptr =q6apm_get_hw_pointer (prtd->graph, substream->stream) % runtime->periods; -return 0 ; +return ptr * runtime->period_size; } static int q6apm_dai_hw_params(struct snd_soc_component *component,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1733/3318 drm/amdkfd: fix doorbell allocation race creating duplicate allocations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Martin <[email protected]>
[ Upstream commit bebad45050945a3d668d6701fb77ae2571c5d44b ]
The check-and-allocate sequence on pdd->qpd.proc_doorbells is lockless at every call site of kfd_alloc_process_doorbells():kfd_get_process_doorbells() (mmap of /dev/kfd), kfd_ioctl_create_queue() and the CRIU restore path each test the pointer under different locking (or none), so two racing threads can both observe NULL and each allocate a doorbell BO and bitmap, orphaning one allocation and handing the two mappings different backing pages.
Move the serialization into kfd_alloc_process_doorbells() itself, using a new per-process-device mutex so all three call sites are covered regardless of their own locking. The device-global kfd->doorbell_mutex is not suitable here: it is acquired under dqm->lock on the kernel-doorbell path (start_cpsch() -> pm_init() -> kq_initialize() -> kfd_get_kernel_doorbell()), so holding it across the sleeping allocations above would create a lock-ordering inversion with dqm->lock via TTM eviction, and it would also serialize doorbell setup of unrelated processes behind a device-wide lock for per-process state.
This issue was discovered by Tencent CodeBuddy Security.
v3 (Felix Kuehling):
- Removed unlocked check in kfd_get_process_doorbell flagged as problematic by Sashiko Bot. Fall back to the locked check inside kfd_alloc_process_doorbells
- Added missing mutex_destroy
v4 (Felix Kuehling):
- Removed unlocked checks around other kfd_alloc_process_doorbells calls
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 18 +++++++----------- drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c | 23 +++++++++++++++++------ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 ++ 4 files changed, 29 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -11
@@ -339,12 +339,10 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, goto err_bind_process; } -if (!pdd->qpd.proc_doorbells) { - err =kfd_alloc_process_doorbells (dev->kfd, pdd); -if (err) { -pr_debug ("failed to allocate process doorbells\n" ); - goto err_bind_process; - } + err =kfd_alloc_process_doorbells (dev->kfd, pdd); +if (err) { +pr_debug ("failed to allocate process doorbells\n" ); + goto err_bind_process; }/* Starting with GFX11, wptr BOs must be mapped to GART for MES to determine work
@@ -2294,11 +2292,9 @@ static int criu_restore_devices(struct kfd_process *p, goto exit; } -if (!pdd->qpd.proc_doorbells) { - ret =kfd_alloc_process_doorbells (dev->kfd, pdd); -if (ret) - goto exit; - } + ret =kfd_alloc_process_doorbells (dev->kfd, pdd); +if (ret) + goto exit; }/*
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +17 -6
@@ -239,11 +239,9 @@ phys_addr_t kfd_get_process_doorbells(struct kfd_process_device *pdd)struct amdgpu_device *adev = pdd->dev->adev;uint32_t first_db_index; -if (!pdd->qpd.proc_doorbells) { -if (kfd_alloc_process_doorbells (pdd->dev->kfd, pdd)) -/* phys_addr_t 0 is error */ -return 0 ; - } +if (kfd_alloc_process_doorbells (pdd->dev->kfd, pdd)) +/* phys_addr_t 0 is error */ +return 0 ; first_db_index = amdgpu_doorbell_index_on_bar(adev, pdd->qpd.proc_doorbells,
@@ -257,12 +255,21 @@ int kfd_alloc_process_doorbells(struct kfd_dev *kfd, struct kfd_process_device *int r;struct qcm_process_device *qpd = &pdd->qpd; +mutex_lock (&pdd->doorbell_mutex); + +/* Another thread may have won the check-and-allocate race */ +if (qpd->proc_doorbells) { +mutex_unlock (&pdd->doorbell_mutex); +return 0 ; + } +/* Allocate bitmap for dynamic doorbell allocation */ qpd->doorbell_bitmap =bitmap_zalloc (KFD_MAX_NUM_OF_QUEUES_PER_PROCESS ,GFP_KERNEL );if (!qpd->doorbell_bitmap) {DRM_ERROR ("Failed to allocate process doorbell bitmap\n" ); -return -ENOMEM ; + r = -ENOMEM ; + goto unlock; } r =init_doorbell_bitmap (&pdd->qpd, kfd);
@@ -284,11 +291,15 @@ int kfd_alloc_process_doorbells(struct kfd_dev *kfd, struct kfd_process_device *DRM_ERROR ("Failed to allocate process doorbells\n" ); goto err; } + +mutex_unlock (&pdd->doorbell_mutex);return 0 ; err:bitmap_free (qpd->doorbell_bitmap); qpd->doorbell_bitmap =NULL ; +unlock: +mutex_unlock (&pdd->doorbell_mutex);return r; }
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -0
@@ -752,6 +752,9 @@ struct kfd_process_device {/* per-process-per device QCM data structure */ struct qcm_process_device qpd; +/* Serializes process doorbell allocation for this device */ +struct mutex doorbell_mutex; +/*Apertures*/ uint64_t lds_base;uint64_t lds_limit;
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2 -0
@@ -1061,6 +1061,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) pdd->runtime_inuse = false; } +mutex_destroy (&pdd->doorbell_mutex);kfree (pdd); p->pdds[i] =NULL ; }
@@ -1600,6 +1601,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, pdd->dev = dev;INIT_LIST_HEAD (&pdd->qpd.queues_list);INIT_LIST_HEAD (&pdd->qpd.priv_queue_list); +mutex_init (&pdd->doorbell_mutex); pdd->qpd.dqm = dev->dqm; pdd->qpd.pqm = &p->pqm; pdd->qpd.evicted =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1734/3318 nilfs2: force clear dirty state when restoring from the shadow map
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiaming Zhang <[email protected]>
[ Upstream commit cb6702e63e0a16afd83875294e5ce53becdd1b1f ]
When garbage collection fails, nilfs2 rolls the DAT metadata file's page cache back to a shadow copy taken before GC started. nilfs_clear_dirty_pages() drops the dirty state of the folios in the DAT cache, then nilfs_copy_back_pages() overwrites them with the saved contents and warns if one is still dirty:
/* overwrite existing folio in the destination cache */ WARN_ON(folio_test_dirty(dfolio));
nilfs_clear_dirty_pages() used to clear the dirty state unconditionally, which is safe here because the rollback runs with the log writer stopped, so nothing else can dirty the cache while it runs. The same helper is also used when writeback finds dirty folios after the filesystem has degraded to read-only, where it does run concurrently with the log writer, so commit ca76bb226bf4 ("nilfs2: do not force clear folio if buffer is referenced") made nilfs_clear_folio_dirty() skip a folio if any of its buffer heads is busy. The rollback caller shares that helper, so its clearing step can now return with a folio still dirty.
A DAT folio can hold a busy buffer head without anyone modifying the
folio: nilfs_mdt_read_block() submits read-ahead for the blocks following the one it was asked for and waits only for the first, so the read-ahead buffers are still locked when it returns. With a block size smaller than the page size, a locked read-ahead buffer can share a folio with a block that GC dirtied and keep the whole folio dirty past the clearing step.
Add a force flag to nilfs_clear_dirty_pages() and nilfs_clear_folio_dirty() that skips the busy buffer check, and set it in the two calls from nilfs_mdt_restore_from_shadow_map(). The read-only fallback callers keep passing false, so that commit still protects them and the WARN_ON() is left alone.
--- fs/nilfs2/inode.c | 4 ++-- fs/nilfs2/mdt.c | 6 +++--- fs/nilfs2/page.c | 51 ++++++++++++++++++++++++++++------------------- fs/nilfs2/page.h | 5 +++-- 4 files changed, 38 insertions(+), 28 deletions(-)
fs/nilfs2/inode.c +2 -2
@@ -162,7 +162,7 @@ static int nilfs_writepages(struct address_space *mapping,int err =0 ;if (sb_rdonly (inode->i_sb)) { -nilfs_clear_dirty_pages (mapping, false); +nilfs_clear_dirty_pages (mapping, false, false);return -EROFS ; }
@@ -185,7 +185,7 @@ static int nilfs_writepage(struct page *page, struct writeback_control *wbc)* have dirty pages that try to be flushed in background. * So, here we simply discard this dirty page. */ -nilfs_clear_dirty_page (page, false); +nilfs_clear_dirty_page (page, false, false);unlock_page (page);return -EROFS ; }
fs/nilfs2/mdt.c +3 -3
@@ -411,7 +411,7 @@ nilfs_mdt_write_page(struct page *page, struct writeback_control *wbc)* have dirty pages that try to be flushed in background. * So, here we simply discard this dirty page. */ -nilfs_clear_dirty_page (page, false); +nilfs_clear_dirty_page (page, false, false);unlock_page (page);return -EROFS ; }
@@ -634,10 +634,10 @@ void nilfs_mdt_restore_from_shadow_map(struct inode *inode)if (mi->mi_palloc_cache)nilfs_palloc_clear_cache (inode); -nilfs_clear_dirty_pages (inode->i_mapping, true); +nilfs_clear_dirty_pages (inode->i_mapping, true, true);nilfs_copy_back_pages (inode->i_mapping, shadow->inode->i_mapping); -nilfs_clear_dirty_pages (ii->i_assoc_inode->i_mapping, true); +nilfs_clear_dirty_pages (ii->i_assoc_inode->i_mapping, true, true);nilfs_copy_back_pages (ii->i_assoc_inode->i_mapping,NILFS_I (shadow->inode)->i_assoc_inode->i_mapping);
fs/nilfs2/page.c +30 -21
82 lines not on this page · raw message
fs/nilfs2/page.h +3 -2
@@ -41,8 +41,9 @@ void nilfs_folio_bug(struct folio *);int nilfs_copy_dirty_pages (struct address_space *,struct address_space *);void nilfs_copy_back_pages (struct address_space *,struct address_space *); -void nilfs_clear_dirty_page (struct page *,bool ); -void nilfs_clear_dirty_pages (struct address_space *,bool ); +void nilfs_clear_dirty_page (struct page *page,bool silent,bool force); +void nilfs_clear_dirty_pages (struct address_space *mapping,bool silent, +bool force);unsigned int nilfs_page_count_clean_buffers (struct page *,unsigned int ,unsigned int ); unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1735/3318 IB/hfi1: Shutdown self-rearming timers before freeing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 9d3259e41ccd5016cd2c6d013232b89df6d73011 ]
The HFI1 receive error and synthetic counter timers rearm themselves from their callbacks. Their cleanup paths use timer_delete_sync(), which only waits for a running callback and does not prevent a concurrent or subsequent rearm.
Use timer_shutdown_sync() when releasing these timers. This prevents a callback from enqueueing either timer after cleanup begins, before the containing hfi1_devdata is freed.
Preserve the existing work cancellation and workqueue destruction ordering for synthetic counters.
--- drivers/infiniband/hw/hfi1/chip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/hfi1/chip.c +2 -2
@@ -5576,7 +5576,7 @@ static int init_rcverr(struct hfi1_devdata *dd)static void free_rcverr (struct hfi1_devdata *dd) {if (dd->rcverr_timer.function) -del_timer_sync (&dd->rcverr_timer); +timer_shutdown_sync (&dd->rcverr_timer); }static void handle_rxe_err (struct hfi1_devdata *dd,u32 unused,u64 reg)
@@ -12308,7 +12308,7 @@ static void free_cntrs(struct hfi1_devdata *dd)int i;if (dd->synth_stats_timer.function) -del_timer_sync (&dd->synth_stats_timer); +timer_shutdown_sync (&dd->synth_stats_timer);cancel_work_sync (&dd->update_cntr_work); ppd = (struct hfi1_pportdata *)(dd +1 );for (i =0 ; i < dd->num_pports; i++, ppd++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1736/3318 wifi: brcmfmac: cfg80211: Report port_authorized for 4-way HS offload
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Janne Grunau <[email protected]>
[ Upstream commit 6fff9de5c5b425817588eeed42bd56d665751c13 ]
Since commit 416386060 ("Mark authorization completed on driver indication during 4-way HS offload") [0] wpa_supplicant expects NL80211_CMD_PORT_AUTHORIZED to complete the authentication when the driver supports 4-way handshake offload.
This was apparently never tested with the upstream brcmfmac driver as it does not report this. This broke authentication on Apple silicon devices (BRCM4378, BRMC4387, BRMC4388) and other devices when wpa_supplicant 2.11 was released [1]. This was initially dealt with by reverting the commit in Fedora [2] and other Linux distributions.
Instead of carrying the revert over to wpa_supplicant 2.12 add the expected NL80211_CMD_PORT_AUTHORIZED when the connection is established.
The "Fixes:" tag is not fully accurate as this has only became an issue after userspace changes years after the change. Since the change is expected to be required in all active stable branches for wpa_supplicant 2.11 / 2.12 compatibility it is helpful even though BRCMF_PROFILE_FWSUP_SAE did not exists then.
--- .../net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +7 -0
@@ -6424,6 +6424,7 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;struct brcmf_cfg80211_connect_info *conn_info =cfg_to_conn (cfg);struct cfg80211_connect_resp_params conn_params; +bool authorized;brcmf_dbg (TRACE ,"Enter\n" );
@@ -6448,7 +6449,13 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, conn_params.req_ie_len = conn_info->req_ie_len; conn_params.resp_ie = conn_info->resp_ie; conn_params.resp_ie_len = conn_info->resp_ie_len; + authorized = completed && + (profile->use_fwsup ==BRCMF_PROFILE_FWSUP_SAE || + profile->use_fwsup ==BRCMF_PROFILE_FWSUP_PSK );cfg80211_connect_done (ndev, &conn_params,GFP_KERNEL ); +if (authorized) +cfg80211_port_authorized (ndev, profile->bssid,NULL ,0 , +GFP_KERNEL );brcmf_dbg (CONN ,"Report connect result - connection %s\n" , completed ?"succeeded" :"failed" ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1737/3318 mptcp: fix subflow bitfield misuse
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit 7538fa33bb2f66b8b809ff39d58308be48e197a0 ]
The subflow status bitfield is protected by the subflow socket lock, with one notable exception: the close_event_done bit is actually under the msk socket lock protection.
As reported by Clashiko [1], flipping the latter bit may corrupt other entries in the same bitfield.
Move the close_event_done outside the bitfield, in a 32bit hole.
--- net/mptcp/protocol.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/mptcp/protocol.h +4 -2
@@ -510,12 +510,14 @@ struct mptcp_subflow_context { stale : 1, /* unable to snd/rcv data, do not use for xmit */ valid_csum_seen : 1, /* at least one csum validated */ is_mptfo : 1, /* subflow is doing TFO */ - close_event_done : 1, /* has done the post-closed part */ resetting : 1, /* subflow is resetting */ - __unused : 7; + __unused : 8;bool data_avail;bool scheduled;bool pm_listener;/* a listener managed by the kernel PM? */ +bool close_event_done;/* has done the post-closed part, +* protected by msk socket lock +*/ u32 remote_nonce;u64 thmac;u32 local_nonce;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1738/3318 serial: 8250_exar: Clear interrupts before registering handler
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 5bc430afeba5d5101765c1f1a4437a90218b00b9 ]
While now there is no issue if IRQ is fired before we clearing the interrupts as the handler does the same, but strictly speaking it might be problematic if IRQ handler wants to do something more.
Move clearing interrupt code to be called before registering the IRQ handler.
Stable-dep-of: 33d337816e00 ("serial: 8250_exar: store the GPIO platform device in struct exar8250")
--- drivers/tty/serial/8250/8250_exar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_exar.c +3 -3
@@ -722,14 +722,14 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) uart.port.irq =pci_irq_vector (pcidev,0 ); uart.port.dev = &pcidev->dev; +/* Clear interrupts */ +exar_misc_clear (priv); + rc =devm_request_irq (&pcidev->dev, uart.port.irq, exar_misc_handler,IRQF_SHARED ,"exar_uart" , priv);if (rc)return rc; -/* Clear interrupts */ -exar_misc_clear (priv); -for (i =0 ; i < nr_ports && i < maxnr; i++) { rc = board->setup (priv, pcidev, &uart, i);if (rc) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1739/3318 serial: exar: add optional board_init function
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Parker Newman <[email protected]>
[ Upstream commit 393b520a99b21d9ec6d4bb32e7c05bbb4f6dc777 ]
Add an optional "board_init()" function pointer to struct exar8250_board which is called once during probe prior to setting up the ports. It will be used in subsequent patches of this series.
Stable-dep-of: 33d337816e00 ("serial: 8250_exar: store the GPIO platform device in struct exar8250")
--- drivers/tty/serial/8250/8250_exar.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_exar.c +12 -1
@@ -177,12 +177,14 @@ struct exar8250_platform {* struct exar8250_board - board information * @num_ports: number of serial ports * @reg_shift: describes UART register mapping in PCI memory -* @setup: quirk run at ->probe() stage +* @board_init: quirk run once at ->probe() stage before setting up ports +* @setup: quirk run at ->probe() stage for each port * @exit: quirk run at ->remove() stage */ struct exar8250_board {unsigned int num_ports;unsigned int reg_shift; +int (*board_init)(struct exar8250 *priv,struct pci_dev *pcidev);int (*setup)(struct exar8250 *,struct pci_dev *,struct uart_8250_port *,int );void (*exit)(struct pci_dev *pcidev);
@@ -730,6 +732,15 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)if (rc)return rc; +if (board->board_init) { + rc = board->board_init (priv, pcidev); +if (rc) { +dev_err_probe (&pcidev->dev, rc, +"failed to init serial board\n" ); +return rc; + } + } +for (i =0 ; i < nr_ports && i < maxnr; i++) { rc = board->setup (priv, pcidev, &uart, i);if (rc) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1740/3318 serial: exar: fix checkpach warnings
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Parker Newman <[email protected]>
[ Upstream commit c6795fbffc4547b40933ec368200bd4926a41b44 ]
-Fix several "missing identifier name" warnings from checkpatch in struct exar8250_platform and struct exar8250_board. Example:
WARNING: function definition argument <arg> should also have an identifier name
- Fix space before tab warning from checkpatch:
WARNING: please, no space before tabs
+ * 0^I^I2 ^IMode bit 0$
Stable-dep-of: 33d337816e00 ("serial: 8250_exar: store the GPIO platform device in struct exar8250")
--- drivers/tty/serial/8250/8250_exar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/tty/serial/8250/8250_exar.c +5 -5
@@ -133,7 +133,7 @@* * MPIO Port Function * ---- ---- -------- -* 0 2 Mode bit 0 +* 0 2 Mode bit 0 * 1 2 Mode bit 1 * 2 2 Terminate bus * 3 - <reserved>
@@ -169,8 +169,8 @@ struct exar8250_platform {int (*rs485_config)(struct uart_port *port,struct ktermios *termios,struct serial_rs485 *rs485);const struct serial_rs485 *rs485_supported; -int (*register_gpio)(struct pci_dev *,struct uart_8250_port *); -void (*unregister_gpio)(struct uart_8250_port *); +int (*register_gpio)(struct pci_dev *pcidev,struct uart_8250_port *port); +void (*unregister_gpio)(struct uart_8250_port *port); };/**
@@ -185,8 +185,8 @@ struct exar8250_board {unsigned int num_ports;unsigned int reg_shift;int (*board_init)(struct exar8250 *priv,struct pci_dev *pcidev); -int (*setup)(struct exar8250 *,struct pci_dev *, -struct uart_8250_port *,int ); +int (*setup)(struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port,int idx);void (*exit)(struct pci_dev *pcidev); };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1741/3318 serial: 8250_exar: store the GPIO platform device in struct exar8250
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 33d337816e00994daaf670243186d9e537ee090d ]
The GPIO platform device is registered via platform->register_gpio() when port 0 is being set up. It is stored to port->port.private_data of the on-stack uart template (and from there it is copied into every registered port). pci_xr17v35x_exit() then fetches it back by serial8250_get_port(priv->line[0]).
But port 0 does not have to exist at that point. If serial8250_register_8250_port() fails for port 0, priv->line[0] holds a negative error code. The probe still succeeds (it only breaks the loop), so on unbind, priv->line[0] (a negative value) is passed to serial8250_get_port(). The GPIO device is never unregistered and a bogus port is accessed.
The same problem would also occur after the planned conversion of serial8250_register_8250_port() to return a uart port instead of a line. As Sashiko pointed out in that case:
If board->setup() fails for the first port (i=0) in exar_pci_probe(), priv->uport[0] remains NULL. If serial8250_register_8250_port() fails, it returns an ERR_PTR. In either case, the loop breaks and probe returns success. When the device is later unbound, pci_xr17v35x_exit() unconditionally passes priv->uport[0] to platform->unregister_gpio(), which will dereference it without checking for validity.
The GPIO device belongs to the PCI device, not to any particular port. So store it in a new struct exar8250::gpio member. Pass priv to both ->register_gpio() and ->unregister_gpio(), so that pci_xr17v35x_exit() does not need to look up any port at all.
--- drivers/tty/serial/8250/8250_exar.c | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/tty/serial/8250/8250_exar.c +18 -18
@@ -169,8 +169,9 @@ struct exar8250_platform {int (*rs485_config)(struct uart_port *port,struct ktermios *termios,struct serial_rs485 *rs485);const struct serial_rs485 *rs485_supported; -int (*register_gpio)(struct pci_dev *pcidev,struct uart_8250_port *port); -void (*unregister_gpio)(struct uart_8250_port *port); +int (*register_gpio)(struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port); +void (*unregister_gpio)(struct exar8250 *priv); };/**
@@ -194,6 +195,7 @@ struct exar8250 {unsigned int nr;struct exar8250_board *board;void __iomem *virt; +struct platform_device *gpio;int line[]; };
@@ -452,22 +454,21 @@ static const struct software_node exar_gpio_node = { .properties = exar_gpio_properties, }; -static int xr17v35x_register_gpio (struct pci_dev *pcidev,struct uart_8250_port *port) +static int xr17v35x_register_gpio (struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port) {if (pcidev->vendor ==PCI_VENDOR_ID_EXAR ) - port->port.private_data = -__xr17v35x_register_gpio (pcidev, &exar_gpio_node); + priv->gpio =__xr17v35x_register_gpio (pcidev, &exar_gpio_node);return 0 ; } -static void xr17v35x_unregister_gpio (struct uart_8250_port *port) +static void xr17v35x_unregister_gpio (struct exar8250 *priv) { -if (!port->port.private_data) -return ; - -__xr17v35x_unregister_gpio (port->port.private_data); - port->port.private_data =NULL ; +if (priv->gpio) { +__xr17v35x_unregister_gpio (priv->gpio); + priv->gpio =NULL ; + } } static int generic_rs485_config(struct uart_port *port, struct ktermios *termios,
@@ -550,8 +551,9 @@ static const struct software_node iot2040_gpio_node = { .properties = iot2040_gpio_properties, }; -static int iot2040_register_gpio (struct pci_dev *pcidev, -struct uart_8250_port *port) +static int iot2040_register_gpio (struct exar8250 *priv, +struct pci_dev *pcidev, +struct uart_8250_port *port) {u8 __iomem *p = port->port.membase;
@@ -560,8 +562,7 @@ static int iot2040_register_gpio(struct pci_dev *pcidev,writeb (IOT2040_UARTS_ENABLE , p +UART_EXAR_MPIOLVL_15_8 );writeb (IOT2040_UARTS_GPIO_HI_MODE , p +UART_EXAR_MPIOSEL_15_8 ); - port->port.private_data = -__xr17v35x_register_gpio (pcidev, &iot2040_gpio_node); + priv->gpio =__xr17v35x_register_gpio (pcidev, &iot2040_gpio_node);return 0 ; }
@@ -635,7 +636,7 @@ pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev,/* Setup Multipurpose Input/Output pins. */ setup_gpio (pcidev, p); - ret = platform->register_gpio (pcidev, port); + ret = platform->register_gpio (priv, pcidev, port); }return ret;
@@ -645,9 +646,8 @@ static void pci_xr17v35x_exit(struct pci_dev *pcidev) {const struct exar8250_platform *platform =exar_get_platform ();struct exar8250 *priv =pci_get_drvdata (pcidev); -struct uart_8250_port *port =serial8250_get_port (priv->line[0 ]); - platform->unregister_gpio (port); + platform->unregister_gpio (priv); }static inline void exar_misc_clear (struct exar8250 *priv)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1742/3318 f2fs: bound the SIT/NAT bitmaps by the checkpoint pack
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kaixuan Li <[email protected]>
[ Upstream commit 080833a32fd5dc10b3acf2fa9af9b3213e6cb617 ]
sit_ver_bitmap_bytesize and nat_ver_bitmap_bytesize are used as memcpy lengths into and out of sbi->ckpt, which is sized from cp_payload alone, and nothing compares either length against that allocation.
sanity_check_ckpt() has checked these two fields since c77ec61ca0a4, which added them after a crafted image overran build_sit_info(). That check ties each length to a segment count; it never compares either against the allocation, which is the half this adds.
Mounting over-reads in build_sit_info() and build_node_manager(), and the first checkpoint writes the same lengths back through the same pointers, so the over-read's contents reach the on-disk checkpoint. An unmount is enough; the filesystem does not have to be used.
Bound both ends the way __bitmap_ptr() lays them out. The three branches differ, so a single sum of the two lengths would still admit a small overflow when cp_payload is non-zero.
--- fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/f2fs/super.c +24 -0
@@ -3649,6 +3649,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)block_t avail_node_count, valid_node_count;unsigned int nat_blocks, nat_bits_bytes, nat_bits_blocks;unsigned int sit_blk_cnt; +unsigned long long ckpt_size, sit_end, nat_end;int i, j; total =le32_to_cpu (raw_super->segment_count);
@@ -3780,6 +3781,29 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)return 1 ; } +/* +* Nothing above ties the bitmap lengths to sbi->ckpt, which is +* (1 + cp_payload) blocks. Bound both ends the way __bitmap_ptr() +* lays them out. +*/ + ckpt_size = (unsigned long long )(cp_payload +1 ) *F2FS_BLKSIZE ; +if (__is_set_ckpt_flags (ckpt,CP_LARGE_NAT_BITMAP_FLAG )) { + nat_end =CP_MIN_CHKSUM_OFFSET +sizeof (__le32) + nat_bitmap_size; + sit_end = nat_end + sit_bitmap_size; + }else if (cp_payload >0 ) { + nat_end =CP_MIN_CHKSUM_OFFSET + nat_bitmap_size; + sit_end =F2FS_BLKSIZE + sit_bitmap_size; + }else { + sit_end =CP_MIN_CHKSUM_OFFSET + sit_bitmap_size; + nat_end = sit_end + nat_bitmap_size; + } + +if (sit_end > ckpt_size || nat_end > ckpt_size) { +f2fs_err (sbi,"Bitmaps do not fit the checkpoint pack: sit ends at %llu, nat at %llu, pack is %llu bytes" , + sit_end, nat_end, ckpt_size); +return 1 ; + } +if (__is_set_ckpt_flags (ckpt,CP_LARGE_NAT_BITMAP_FLAG ) &&le32_to_cpu (ckpt->checksum_offset) !=CP_MIN_CHKSUM_OFFSET ) { f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, "
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1743/3318 block: introduce bio_in_atomic()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit 8ed0831b5263e1aa48d99063795a1f20e4e69b50 ]
Move the atomic context detection logic from erofs's z_erofs_in_atomic() into the block layer as bio_in_atomic(). This helper returns true when the current context is unsafe for sleeping bio completion handlers (e.g., hard/soft IRQ, preempt-disabled).
The logic was originally added to erofs in commit c99fab6e80b7 ("erofs:
fix atomic context detection when !CONFIG_DEBUG_LOCK_ALLOC"). A subsequent patch will use it in the block layer's bio completion infrastructure, so move it to include/linux/bio.h where both subsystems can share it.
Convert erofs to call the new bio_in_atomic() directly.
Stable-dep-of: a605d5d71a6d ("f2fs: fix to use bio_in_atomic() in f2fs_read_end_io()")
--- fs/erofs/zdata.c | 11 +---------- include/linux/bio.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-)
fs/erofs/zdata.c +1 -10
@@ -1404,15 +1404,6 @@ static void z_erofs_decompressqueue_kthread_work(struct kthread_work *work) }#endif -/* Use (kthread_)work in atomic contexts to minimize scheduling overhead */ -static inline bool z_erofs_in_atomic (void ) -{ -if (IS_ENABLED (CONFIG_PREEMPTION ) &&rcu_preempt_depth ()) -return true; -if (!IS_ENABLED (CONFIG_PREEMPT_COUNT )) -return true; -return !preemptible (); -}static void z_erofs_decompress_kickoff (struct z_erofs_decompressqueue *io,int bios)
@@ -1429,7 +1420,7 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,if (atomic_add_return (bios, &io->pending_bios))return ; -if (z_erofs_in_atomic ()) { +if (bio_in_atomic ()) {/* See `sync_decompress` in sysfs-fs-erofs for more details */ if (sbi->opt.sync_decompress ==EROFS_SYNC_DECOMPRESS_AUTO ) sbi->opt.sync_decompress =EROFS_SYNC_DECOMPRESS_FORCE_ON ;
include/linux/bio.h +15 -0
@@ -438,6 +438,21 @@ static inline struct bio *bio_alloc(struct block_device *bdev,void submit_bio (struct bio *bio); +/** +* bio_in_atomic - check if the current context is unsafe for bio completion +* +* Return: %true in atomic contexts (e.g. hard/soft IRQ, preempt-disabled); +* %false when a bio can be safely completed in the current context. +*/ +static inline bool bio_in_atomic (void ) +{ +if (IS_ENABLED (CONFIG_PREEMPTION ) &&rcu_preempt_depth ()) +return true; +if (!IS_ENABLED (CONFIG_PREEMPT_COUNT )) +return true; +return !preemptible (); +} +extern void bio_endio (struct bio *);static inline void bio_io_error (struct bio *bio)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1744/3318 f2fs: fix to use bio_in_atomic() in f2fs_read_end_io()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit a605d5d71a6d280c43c7ede9778dda63fb5c3f22 ]
f2fs_read_end_io() uses "in_task() && !irqs_disabled()" to decide whether it is safe to sleep, the result is passed down as @in_task to:
- f2fs_put_dic() -> f2fs_free_dic() -> f2fs_release_decomp_mem() -> vm_unmap_ram(), which may sleep.
- f2fs_end_read_compressed_page() -> f2fs_cache_compressed_page() -> f2fs_grab_cache() -> f2fs_lock_cache(), which may sleep in wait_on_bit_lock().
However, the check still treats below task contexts as sleepable:
- with spinlock held via spin_lock(), i.e. preempt count != 0 while irqs are enabled.
- with BH disabled via local_bh_disable().
- inside an RCU read lock on kernels with CONFIG_PREEMPTION.
- with any spinlock held on kernels without CONFIG_PREEMPT_COUNT.
So the "sleeping function called from invalid context" issue fixed by commit 08a7efc5b02a ("f2fs: vm_unmap_ram() may be called from an invalid context") can still be triggered.
The block layer provides bio_in_atomic() for exactly this purpose, it checks rcu_preempt_depth() and preemptible(), and conservatively returns true if CONFIG_PREEMPT_COUNT is disabled, let's use it instead. The difference is as below:
old: intask = in_task() && !irqs_disabled()
new: intask = !bio_in_atomic()
Context | old intask | new intask
-------------------------------------+----------------+----------------
Hard IRQ / softirq | false | false IRQs disabled | false | false spin_lock() held, IRQs enabled | true (wrong) | false BH disabled by local_bh_disable() | true (wrong) | false RCU read lock (CONFIG_PREEMPTION) | true (wrong) | false Spinlock held, w/o PREEMPT_COUNT | true (wrong) | false
Note that on kernels without CONFIG_PREEMPT_COUNT, bio_in_atomic() always returns true, so dic freeing will always be offloaded to sbi->wq, and compressed pages will not be cached in f2fs_read_end_io(); this is the price of correctness, since there is no way to tell whether the current context can sleep.
--- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c +1 -1
@@ -288,7 +288,7 @@ static void f2fs_read_end_io(struct bio *bio) {struct f2fs_sb_info *sbi =F2FS_P_SB (bio_first_page_all (bio));struct bio_post_read_ctx *ctx; -bool intask =in_task () && !irqs_disabled (); +bool intask = !bio_in_atomic ();iostat_update_and_unbind_ctx (bio); ctx = bio->bi_private;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1745/3318 scsi: ufs: core: Add a helper for clearing hba->outstanding_reqs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Jhu <[email protected]>
[ Upstream commit 22d14117ec1845a81acb3a5c4be325f7e8332f70 ]
ufshcd_poll() and ufshcd_abort() each have their own copy of the code that clears bits in hba->outstanding_reqs under hba->outstanding_lock.
Move that code into ufshcd_clear_outstanding_reqs() and its locked variant __ufshcd_clear_outstanding_reqs(), and use them in both functions. No functional change.
--- drivers/ufs/core/ufshcd.c | 48 +++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-)
drivers/ufs/core/ufshcd.c +36 -12
@@ -5601,6 +5601,37 @@ static void ufshcd_clear_polled(struct ufs_hba *hba, } } +/* +* Return a bitmask of the transfer requests cleared from +* @hba->outstanding_reqs. +*/ +static unsigned long __ufshcd_clear_outstanding_reqs (struct ufs_hba *hba, +unsigned long mask, +bool from_irq) + __must_hold(&hba->outstanding_lock) +{ +unsigned long completed_reqs = mask & hba->outstanding_reqs; + +if (from_irq) { +/* Do not complete polled requests from interrupt context. */ +ufshcd_clear_polled (hba, &completed_reqs); + } + hba->outstanding_reqs &= ~completed_reqs; + +return completed_reqs; +} + +/* +* Return a bitmask of the transfer requests cleared from +* @hba->outstanding_reqs. +*/ +static unsigned long ufshcd_clear_outstanding_reqs (struct ufs_hba *hba, +unsigned long mask) +{ +guard (spinlock_irqsave)(&hba->outstanding_lock); +return __ufshcd_clear_outstanding_reqs (hba, mask, false); +} +/* * Return: > 0 if one or more commands have been completed or 0 if no * requests have been completed.
@@ -5611,6 +5642,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)unsigned long completed_reqs, flags;u32 tr_doorbell;struct ufs_hw_queue *hwq; +bool from_irq;if (is_mcq_enabled (hba)) { hwq = &hba->uhq[queue_num];
@@ -5620,12 +5652,9 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)spin_lock_irqsave (&hba->outstanding_lock, flags); tr_doorbell =ufshcd_readl (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL ); - completed_reqs = ~tr_doorbell & hba->outstanding_reqs; -if (queue_num ==UFSHCD_POLL_FROM_INTERRUPT_CONTEXT ) { -/* Do not complete polled requests from interrupt context. */ -ufshcd_clear_polled (hba, &completed_reqs); - } - hba->outstanding_reqs &= ~completed_reqs; + from_irq = queue_num ==UFSHCD_POLL_FROM_INTERRUPT_CONTEXT ; + completed_reqs =__ufshcd_clear_outstanding_reqs (hba, ~tr_doorbell, + from_irq);spin_unlock_irqrestore (&hba->outstanding_lock, flags);if (completed_reqs)
@@ -7694,7 +7723,6 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)struct ufshcd_lrb *lrbp = &hba->lrb[tag];unsigned long flags;int err =FAILED ; -bool outstanding;u32 reg;WARN_ONCE (tag <0 ,"Invalid tag %d\n" , tag);
@@ -7786,11 +7814,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)* Clear the corresponding bit from outstanding_reqs since the command * has been aborted successfully. */ -spin_lock_irqsave (&hba->outstanding_lock, flags); - outstanding =__test_and_clear_bit (tag, &hba->outstanding_reqs); -spin_unlock_irqrestore (&hba->outstanding_lock, flags); - -if (outstanding) +if (ufshcd_clear_outstanding_reqs (hba,BIT (tag)))ufshcd_release_scsi_cmd (hba, lrbp); err =SUCCESS ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1746/3318 wifi: mt76: move the channel survey when the channel changes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 68342a7bd7e5e273e2969e3c0f4c62ee3d006ce8 ]
mt7921 and mt7925 report every survey counter against one channel and never mark the one in use. With firmware channel management, both use channel contexts and never call __mt76_set_channel(), so phy->chan_state, phy->chandef and phy->main_chandef keep the first channel of the band.
Update them when a context is assigned or changed, after booking the time spent on the old channel. This also makes the legacy rate lookup in mt76_connac2_mac_fill_txs() and mt7925_mac_add_txs_skb() use the band of the current channel.
With two channel contexts (multi-channel or MLO), the survey follows the context that was assigned or changed last, since the driver reads the band 0 counters only.
Tested on MT7922 over PCIe, MT7921AU and MT7925 over USB.
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 14 ++++++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ drivers/net/wireless/mediatek/mt76/mt7921/main.c | 1 + drivers/net/wireless/mediatek/mt76/mt792x_core.c | 1 + 4 files changed, 18 insertions(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +14 -0
@@ -945,6 +945,20 @@ void mt76_update_survey(struct mt76_phy *phy) }EXPORT_SYMBOL_GPL (mt76_update_survey); +void mt76_phy_chandef_set (struct mt76_phy *phy, +struct cfg80211_chan_def *chandef) +{ +if (!chandef->chan) +return ; + +mt76_update_survey (phy); + + phy->chandef = *chandef; + phy->main_chan = chandef->chan; + phy->chan_state =mt76_channel_state (phy, chandef->chan); +} +EXPORT_SYMBOL_GPL (mt76_phy_chandef_set); +void mt76_set_channel (struct mt76_phy *phy) {struct mt76_dev *dev = phy->dev;
drivers/net/wireless/mediatek/mt76/mt76.h +2 -0
@@ -1297,6 +1297,8 @@ void mt76_release_buffered_frames(struct ieee80211_hw *hw,bool mt76_has_tx_pending (struct mt76_phy *phy);void mt76_set_channel (struct mt76_phy *phy);void mt76_update_survey (struct mt76_phy *phy); +void mt76_phy_chandef_set (struct mt76_phy *phy, +struct cfg80211_chan_def *chandef);void mt76_update_survey_active_time (struct mt76_phy *phy,ktime_t time);int mt76_get_survey (struct ieee80211_hw *hw,int idx,struct survey_info *survey);
drivers/net/wireless/mediatek/mt76/mt7921/main.c +1 -0
@@ -1292,6 +1292,7 @@ static void mt7921_ctx_iter(void *priv, u8 *mac,mt7921_mcu_config_sniffer (mvif, ctx); else mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx); +mt76_phy_chandef_set (mvif->phy->mt76, &ctx->def); } static void
drivers/net/wireless/mediatek/mt76/mt792x_core.c +1 -0
@@ -244,6 +244,7 @@ int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,mutex_lock (&dev->mt76.mutex); mvif->mt76.ctx = ctx; +mt76_phy_chandef_set (&dev->mphy, &ctx->def);mutex_unlock (&dev->mt76.mutex);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1747/3318 fuse: dont launder folios of a bad inode
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
[ Upstream commit 01d0f3d294af126f517d92c11e100525537f8be4 ]
fuse_flush() and fuse_writepages() reject writing back dirty data for any inode that has been marked bad, but fuse_launder_folio() doesn't.
This can cause the following warning in fuse_write_file_get() to trigger, as reported by syzbot:
WARNING: fs/fuse/file.c:2043 at fuse_write_file_get fs/fuse/file.c:2043 [inline]
WARNING: fs/fuse/file.c:2043 at fuse_iomap_writeback_range+0x7c8/0x18f0 fs/fuse/file.c:2227
Call Trace:
iomap_writeback_folio+0x1526/0x2490 fs/iomap/buffered-io.c:2022
fuse_launder_folio+0x17b/0x240 fs/fuse/file.c:2331
folio_unmap_invalidate+0x4cd/0x830 mm/truncate.c:634
invalidate_inode_pages2_range+0x629/0xb30 mm/truncate.c:726
fuse_open+0x5a6/0x770 fs/fuse/file.c:297This can be hit on a writeback cache mount:
1) a writeable file is open and a buffered write dirties some pages
2) another thread opens the same file read-only. fuse_open() passes the bad inode check and sends OPEN to the server.
3) a SETATTR reply with the wrong file type marks the inode bad
4) the writeable file is closed. Flush and release skip writeback because the inode is bad. The pages stay dirty but the file gets removed from write_files.
5) server replies to the OPEN. The reply has no FOPEN_KEEP_CACHE, so fuse_open() calls invalidate_inode_pages2().
6) the invalidation finds the dirty pages and calls fuse_launder_folio(), which finds no wriable file and hits the WARN_ON in fuse_write_file_get().
Instead of trying to write back dirty data for the bad inode, fuse_launder_folio() should return -EIO.
--- fs/fuse/file.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/fuse/file.c +4 -0
@@ -2476,6 +2476,10 @@ static int fuse_write_end(struct file *file, struct address_space *mapping,static int fuse_launder_folio (struct folio *folio) {int err =0 ; + +if (fuse_is_bad (folio->mapping->host)) +return -EIO ; +if (folio_clear_dirty_for_io (folio)) {struct inode *inode = folio->mapping->host;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1748/3318 block: amiflop: synchronize flush timer before track flush
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 9690943353cec1690a715e000ba6a74e5139f530 ]
The amiflop track buffer is shared with the timer callback. timer_delete() does not wait for an in-flight callback, and that callback can rearm itself when it cannot acquire the floppy controller. A synchronous track flush can therefore race with the callback.
Stop the timer before synchronous track writes and use timer_delete_sync() to wait for any callback already running. Keep callback rearming disabled until the write is complete. Apply this to the FDFMTTRK path as well.
FDFLUSH, FDFMTTRK and close-time flushes run outside the blk-mq request callback. Freeze their queues so an in-flight request cannot change the shared track buffer while it is encoded and written. Restart the timer if a track remains dirty after a failed flush.
--- drivers/block/amiflop.c | 69 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 8 deletions(-)
drivers/block/amiflop.c +61 -8
@@ -264,6 +264,8 @@ static struct fd_data_type data_types[] = {static struct amiga_floppy_struct unit[FD_MAX_UNITS ];static struct timer_list flush_track_timer[FD_MAX_UNITS ]; +static DEFINE_SPINLOCK (flush_track_timer_lock); +static bool flush_track_timer_stopped[FD_MAX_UNITS ];static struct timer_list post_write_timer;static unsigned long post_write_timer_drive;static struct timer_list motor_on_timer;
@@ -1369,11 +1371,22 @@ static void flush_track_callback(struct timer_list *timer)sizeof (flush_track_timer[0 ]); nr&=3 ; +spin_lock (&flush_track_timer_lock); +if (flush_track_timer_stopped[nr]) { +spin_unlock (&flush_track_timer_lock); +return ; + } +spin_unlock (&flush_track_timer_lock); + writefromint =1 ;if (!try_fdc (nr)) {/* we might block in an interrupt, so try again later */ - flush_track_timer[nr].expires = jiffies +1 ; -add_timer (flush_track_timer + nr); +spin_lock (&flush_track_timer_lock); +if (!flush_track_timer_stopped[nr]) { + flush_track_timer[nr].expires = jiffies +1 ; +add_timer (flush_track_timer + nr); + } +spin_unlock (&flush_track_timer_lock);return ; }get_fdc (nr);
@@ -1420,6 +1433,35 @@ static int non_int_flush_track (unsigned long nr)return 1 ; } +static void flush_track_timer_stop (unsigned int drive) +{ +unsigned long flags; + +spin_lock_irqsave (&flush_track_timer_lock, flags); + flush_track_timer_stopped[drive] = true; +spin_unlock_irqrestore (&flush_track_timer_lock, flags); + +timer_delete_sync (flush_track_timer + drive); +} + +static void flush_track_timer_start (unsigned int drive) +{ +unsigned long flags; + +spin_lock_irqsave (&flush_track_timer_lock, flags); + flush_track_timer_stopped[drive] = false; +if (unit[drive].dirty) +mod_timer (flush_track_timer + drive, jiffies +1 ); +spin_unlock_irqrestore (&flush_track_timer_lock, flags); +} + +static void flush_track_timer_sync (unsigned int drive) +{ +flush_track_timer_stop (drive); +non_int_flush_track (drive); +flush_track_timer_start (drive); +} +static int get_track (int drive,int track) {int error, errcnt;
@@ -1434,8 +1476,7 @@ static int get_track(int drive, int track) }if (unit[drive].dirty ==1 ) { -del_timer (flush_track_timer + drive); -non_int_flush_track (drive); +flush_track_timer_sync (drive); } errcnt =0 ;while (errcnt <MAX_ERRORS ) {
@@ -1561,6 +1602,12 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,case FDFMTTRK :if (param < p->type->tracks * p->type->heads) { +flush_track_timer_stop (drive); +if (unit[drive].dirty ==1 && + !non_int_flush_track (drive)) { +flush_track_timer_start (drive); +return -EIO ; + }get_fdc (drive);if (fd_seek (drive,param) !=0 ){ memset(p->trackbuf, FD_FILL_BYTE,
@@ -1569,6 +1616,7 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode, }floppy_off (drive);rel_fdc (); +flush_track_timer_start (drive); }else return -EINVAL ;
@@ -1590,8 +1638,7 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,case FDDEFPRM :return -EINVAL ;case FDFLUSH :/* unconditionally, even if not needed */ -del_timer (flush_track_timer + drive); -non_int_flush_track (drive); +flush_track_timer_sync (drive);break ;#ifdef RAW_IOCTL case IOCTL_RAW_TRACK :
@@ -1610,9 +1657,14 @@ static int fd_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd, unsigned long param) { int ret; +bool freeze_queue = cmd ==FDFMTTRK || cmd ==FDFLUSH ;mutex_lock (&amiflop_mutex); +if (freeze_queue) +blk_mq_freeze_queue (bdev->bd_disk->queue); ret =fd_locked_ioctl (bdev, mode, cmd, param); +if (freeze_queue) +blk_mq_unfreeze_queue (bdev->bd_disk->queue);mutex_unlock (&amiflop_mutex);return ret;
@@ -1712,9 +1764,9 @@ static void floppy_release(struct gendisk *disk)int drive = p - unit;mutex_lock (&amiflop_mutex); +blk_mq_freeze_queue (disk->queue);if (unit[drive].dirty ==1 ) { -del_timer (flush_track_timer + drive); -non_int_flush_track (drive); +flush_track_timer_sync (drive); }if (!fd_ref[drive]--) {
@@ -1724,6 +1776,7 @@ static void floppy_release(struct gendisk *disk)#ifdef MODULE floppy_off (drive);#endif +blk_mq_unfreeze_queue (disk->queue);mutex_unlock (&amiflop_mutex); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1749/3318 leds: ktd2692: Pass context to regulator cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit c73e9f04445f361d5f19ca2edfde742ce18348ef ]
regulator_disable_action() retrieves the driver context from device driver data. However, ktd2692_parse_dt() registers the action before ktd2692_probe() stores the context with platform_set_drvdata().
If devm_add_action_or_reset() cannot allocate the action, it invokes the callback immediately. A later probe failure also invokes it during managed-resource unwinding. Both paths dereference a NULL context.
Pass the already allocated context directly to the action and retain the device pointer in it for error reporting. The context is allocated before the action is registered, so reverse-order devres unwinding keeps it alive through the callback.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/leds/flash/leds-ktd2692.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/leds/flash/leds-ktd2692.c +6 -4
@@ -72,6 +72,8 @@ struct ktd2692_led_config_data { };struct ktd2692_context { +struct device *dev; +/* Related LED Flash class device */ struct led_classdev_flash fled_cdev;
@@ -258,13 +260,12 @@ static void ktd2692_setup(struct ktd2692_context *led)static void regulator_disable_action (void *_data) { -struct device *dev = _data; -struct ktd2692_context *led =dev_get_drvdata (dev); +struct ktd2692_context *led = _data;int ret; ret =regulator_disable (led->regulator);if (ret) -dev_err (dev,"Failed to disable supply: %d\n" , ret); +dev_err (led->dev,"Failed to disable supply: %d\n" , ret); } static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
@@ -296,7 +297,7 @@ static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,dev_err (dev,"Failed to enable supply: %d\n" , ret); }else { ret =devm_add_action_or_reset (dev, - regulator_disable_action, dev); + regulator_disable_action, led);if (ret)return ret; }
@@ -354,6 +355,7 @@ static int ktd2692_probe(struct platform_device *pdev)if (!led)return -ENOMEM ; + led->dev = &pdev->dev; fled_cdev = &led->fled_cdev; led_cdev = &fled_cdev->led_cdev;
Signature · 1 line
2.53.0