6.6.163-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 1072/3318 mm/madvise: use folio_trylock() in the cold/pageout PMD split
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit 5a6c9cf117fca3c38a98fb2a2d5549795c8b0b73 ]
MADV_COLD or MADV_PAGEOUT over part of a PMD splits the THP in madvise_cold_or_pageout_pte_range(). Two threads doing that to the same THP create spurious failures.
CPU0 CPU1
---- ----
folio_get()
spin_unlock(ptl)
folio_lock()
folio_get() spin_unlock(ptl) folio_lock() <- blocks, keeps its ref
split_folio()
folio_expected_ref_count(folio) != folio_ref_count(folio) - 1
-EAGAINCPU1 cannot drop its reference until it gets the lock CPU0 holds, so CPU0's split always fails. folio_trylock() makes CPU1 leave without ever taking a reference. The PTE branch of this same function already does this, as do madvise_free_pte_range() and madvise_free_huge_pmd().
Reproducer: 400 rounds of eight threads calling MADV_COLD on half of each of eight THPs, re-formed with MADV_COLLAPSE between rounds. From /proc/vmstat:
thp_split_page thp_split_page_failed
before 3186 860
after 3200 0
The short before count is rounds where every thread failed and the advice was dropped for that THP entirely.
On failure the walker returns 0 and nothing retries. The PMD path becomes best effort when the folio lock is held elsewhere - same as the PTE path.
--- mm/madvise.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/madvise.c +2 -1
@@ -391,9 +391,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,if (next - addr !=HPAGE_PMD_SIZE ) {int err; +if (!folio_trylock (folio)) + goto huge_unlock;folio_get (folio);spin_unlock (ptl); -folio_lock (folio); err =split_folio (folio);folio_unlock (folio);folio_put (folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1073/3318 mm/page_alloc: do not boost watermarks in kdump capture kernels
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuanhe Shu <[email protected]>
[ Upstream commit 331f94007d79b3c02d3098eea469a92aea3efc2c ]
A watermark boost is not confined to one watermark: wmark_pages() adds it to min, low and high alike, so every watermark check sees it, including should_reclaim_retry() and the last ditch ALLOC_WMARK_HIGH attempt in __alloc_pages_may_oom(). Once the boost exceeds the memory still free the allocator gives up and invokes the OOM killer, and a capture kernel that is still booting has nothing to kill: the boot panics and the vmcore is lost.
Seen on an arm64 machine with 64K pages, CONFIG_PAGE_BLOCK_MAX_ORDER=10 (pageblock = 64M) and crashkernel=512M, running a distribution kernel based on 7.0.14. A high order UNMOVABLE allocation fell back to a MOVABLE pageblock while the capture kernel was still in do_initcalls():
Node 0 DMA free:68096kB boost:65536kB min:68160kB low:68800kB high:69440kB managed:479168kB Out of memory and no killable processes...
Kernel panic - not syncing: System is deadlocked on memory
The zone was not short of memory. Subtracting the boost gives min:2624kB low:3264kB high:3904kB, so the 68096kB still free sat 17 times above the high watermark and the allocator would not even have entered its slow path. The boost supplied 65536kB of the 68160kB min and by itself put the zone 64kB under water. It is that large because boost_watermark() clamps it with max(pageblock_nr_pages, max_boost); watermark_boost_factor alone would have allowed 5824kB.
Commit 14f69140ff9c ("mm: limit boost_watermark on small zones") already tried to protect capture kernels, but it infers them from the zone size and skips the boost only below four pageblocks. arm64 64K pageblocks were 512M then, so the guard reached zones up to 2G; CONFIG_PAGE_BLOCK_MAX_ORDER can cap them at 64M, which shrinks the guard to zones under 256M and lets this 468M zone through.
kdump is a property of the kernel, not of the zone, so test for it directly. A capture kernel exits within seconds and never uses the fragmentation avoidance the boost buys. Normal kernels are unaffected:
the size based check still covers their genuinely tiny zones.
Passing sysctl.vm.watermark_boost_factor=0 to the capture kernel does not cover this window: sysctl.* parameters are written through procfs by do_sysctl_args(), which runs after do_initcalls() where the panic above happened, and watermark_boost_factor has no early_param of its own.
--- mm/page_alloc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
mm/page_alloc.c +10 -2
@@ -37,6 +37,7 @@#include <linux/vmstat.h> #include <linux/fault-inject.h> #include <linux/compaction.h> +#include <linux/crash_dump.h> #include <trace/events/kmem.h> #include <trace/events/oom.h> #include <linux/prefetch.h>
@@ -1771,10 +1772,17 @@ static inline bool boost_watermark(struct zone *zone)if (!watermark_boost_factor)return false; + +/* +* A kdump capture kernel exits before a boost can pay off, while +* the raised watermark can exceed the memory left for the dump. +*/ +if (is_kdump_kernel ()) +return false; +/* * Don't bother in zones that are unlikely to produce results. -* On small machines, including kdump capture kernels running -* in a small area, boosting the watermark can cause an out of +* On small machines, boosting the watermark can cause an out of * memory situation immediately. */ if ((pageblock_nr_pages *4 ) >zone_managed_pages (zone))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1074/3318 mm/hugetlb_cgroup: move per-node usage on cross node migration
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongfu Li <[email protected]>
[ Upstream commit fe0ba1909c59660f078560f5130e7af7c6004f12 ]
Patch series "mm/hugetlb_cgroup: move the per-node usage along with the folio", v2.
The per-node usage reported by hugetlb.<size>.numa_stat is accounted against folio_nid() in __hugetlb_cgroup_commit_charge() and __hugetlb_cgroup_uncharge_folio(), so it is only correct while a folio stays charged on the same node and in the same hugetlb_cgroup.
Two paths move a folio which stays charged, and neither moves the usage with it. hugetlb_cgroup_migrate() only moves the hugetlb_cgroup pointers of a folio migrated to another node, and hugetlb_cgroup_move_parent() only moves the page_counter charges and the hugetlb_cgroup pointer of the folios of a dying cgroup. In both cases the node (or cgroup) which was charged keeps a usage which never goes away, while the node (or cgroup) which ends up uncharging the folio underflows as soon as the folio is freed.
Patch 1/2 moves the usage along with the folio on cross node migration, patch 2/2 does the same for the folios a dying cgroup reparents.
This patch (of 2):
hugetlb.<size>.numa_stat uses folio_nid() to account usage in __hugetlb_cgroup_commit_charge() and __hugetlb_cgroup_uncharge_folio(). hugetlb_cgroup_migrate() only moves hugetlb_cgroup pointers, leaving per-node usage behind on the source node during cross-node migration.
When the migrated folio gets uncharged, we subtract usage from the destination node counter. This creates stale usage on the source node and unsigned long counter underflow on the destination node. The hugetlb.<size>.numa_stat interface exposes these incorrect per-node usage values to userspace.
Add a hugetlb_cgroup_move_usage() helper which moves the usage from the old node to the new node, and call it from hugetlb_cgroup_migrate().
--- mm/hugetlb_cgroup.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
mm/hugetlb_cgroup.c +31 -0
@@ -177,6 +177,34 @@ static void hugetlb_cgroup_css_free(struct cgroup_subsys_state *css)hugetlb_cgroup_free (hugetlb_cgroup_from_css (css)); } +static void hugetlb_cgroup_move_usage (struct hugetlb_cgroup *from, +struct hugetlb_cgroup *to, +struct folio *from_folio, +struct folio *to_folio) +{ +int idx =hstate_index (folio_hstate (from_folio)); +unsigned long nr_pages =folio_nr_pages (from_folio); +int from_nid =folio_nid (from_folio); +int to_nid =folio_nid (to_folio); +unsigned long usage; + +lockdep_assert_held (&hugetlb_lock); + +if (!from || !to) +return ; + +if (from == to && from_nid == to_nid) +return ; + + usage = from->nodeinfo[from_nid]->usage[idx]; +if (WARN_ON_ONCE (usage < nr_pages)) +return ; +WRITE_ONCE (from->nodeinfo[from_nid]->usage[idx], usage - nr_pages); + + usage = to->nodeinfo[to_nid]->usage[idx]; +WRITE_ONCE (to->nodeinfo[to_nid]->usage[idx], usage + nr_pages); +} +/* * Should be called with hugetlb_lock held. * Since we are holding hugetlb_lock, pages cannot get moved from
@@ -902,6 +930,9 @@ void hugetlb_cgroup_migrate(struct folio *old_folio, struct folio *new_folio)/* move the h_cg details to new cgroup */ set_hugetlb_cgroup (new_folio, h_cg);set_hugetlb_cgroup_rsvd (new_folio, h_cg_rsvd); + +hugetlb_cgroup_move_usage (h_cg, h_cg, old_folio, new_folio); +list_move (&new_folio->lru, &h->hugepage_activelist);spin_unlock_irq (&hugetlb_lock);return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1075/3318 mm/hugetlb_cgroup: move per-node usage on cgroup reparenting
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongfu Li <[email protected]>
[ Upstream commit 23fac055c21176f66ed453394b533bdfc00f7fba ]
hugetlb_cgroup_css_offline() hands the folios of a dying cgroup over to its parent with hugetlb_cgroup_move_parent(), which moves the page_counter charges and the hugetlb_cgroup pointer of the folio but not its per-node usage. The parent's hugetlb.<size>.numa_stat is short by that usage while they are charged, and underflows once they are freed, exposing incorrect per-node usage values to userspace.
Move the per-node usage to the parent as well. The folios keep their node here, so only the cgroup which holds the usage changes.
--- mm/hugetlb_cgroup.c | 2 ++ 1 file changed, 2 insertions(+)
mm/hugetlb_cgroup.c +2 -0
@@ -240,6 +240,8 @@ static void hugetlb_cgroup_move_parent(int idx, struct hugetlb_cgroup *h_cg,/* Take the pages off the local counter */ page_counter_cancel (counter, nr_pages); +hugetlb_cgroup_move_usage (h_cg, parent, folio, folio); +set_hugetlb_cgroup (folio, parent); out:return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1076/3318 mm/shmem: report RCU-tasks quiescent states while undoing a range
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit ebd1a08c192109c83a87ddf42793ed6283180faf ]
This shows up in the Meta fleet on ftruncate() of large tmpfs files:
INFO: rcu_tasks detected stalls on tasks:
00000000752fd185: .. nvcsw: 59455/59455 holdout: 1 idle_cpu: -1/0
task:rocksdb:bottom state:R running task
__folio_split
find_get_entry
find_get_entries
truncate_inode_partial_folio
shmem_undo_range
shmem_setattr
notify_change
do_ftruncate
__x64_sys_ftruncate
do_syscall_64shmem_undo_range() walks the whole of the requested range in folio_batch sized steps, twice, and its two cond_resched() calls are the only reschedule points in that walk.
cond_resched() is not an RCU-tasks quiescent state. Use cond_resched_tasks_rcu_qs() at both points so the walk reports an RCU-tasks quiescent state as it proceeds.
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
@@ -1024,7 +1024,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, }folio_batch_remove_exceptionals (&fbatch);folio_batch_release (&fbatch); -cond_resched (); +cond_resched_tasks_rcu_qs (); }/*
@@ -1065,7 +1065,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, index = start;while (index < end) { -cond_resched (); +cond_resched_tasks_rcu_qs ();if (!find_get_entries (mapping, &index, end -1 , &fbatch, indices)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1077/3318 mm/damon/core: charge only the part of a region the filter left
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 4ff3b4a54a32142497fb44b79d0920aa6ba3393d ]
Patch series "mm/damon/core: fix the size charged for a filter-trimmed region", v2.
An address range DAMOS filter that partially overlaps a monitoring region splits it, so the scheme action reaches only one side of the boundary. damos_apply_scheme() reads the region size before that split and never re-reads it, so the quota charge and schemes/<S>/stats/sz_tried account for the whole original region.
Patch 1 re-reads the size after the core filters have run. Patch 2 adds KUnit coverage for what the function charges and reports, for the trimmed cases and for the cases that must not change.
This patch (of 2):
An address range DAMOS filter that partially overlaps a monitoring region splits the region at the filter boundary, so the scheme action is applied to only one side of it. damos_apply_scheme() reads the region size once on entry, before damos_core_filter_out() performs that split.
The quota charge and the statistics update therefore account for the region as it was before the trim. schemes/<S>/stats/sz_tried counts memory the filter excluded, which Documentation/mm/damon/design.rst says is not counted as tried, and with quotas/bytes set the excluded part is charged against the budget, throttling the scheme to a fraction of what was configured.
User impact is that DAMOS could unexpectedly slowly run, due to over-charged quota. DAMOS stat could also be confusing. No critical events such as crashes or leask happen.
Re-read the region size after the core filters have run.
--- mm/damon/core.c | 1 + 1 file changed, 1 insertion(+)
mm/damon/core.c +1 -0
@@ -1008,6 +1008,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, }if (damos_filter_out (c, t, r, s))return ; + sz =damon_sz_region (r);ktime_get_coarse_ts64 (&begin);if (c->callback.before_damos_apply) err = c->callback.before_damos_apply (c, t, r, s);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1078/3318 platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit 540b8ae192afb5566c1b13b6884aee87107a26b9 ]
hp_calculate_security_buffer() special-cases an empty authentication string and returns a fixed 4 bytes (sizeof(u16) * 2). But hp_populate_security_buffer() does not special-case that same input:
for any authentication string that does not start with BEAM_PREFIX, including the empty string, it always builds "UTF_PREFIX + authentication" and converts the result to UTF-16, writing a 2-byte length header plus 2 bytes per character of "<utf-16/>" (9 characters), 20 bytes total, regardless of how long "authentication" itself is.
The caller, hp_set_attribute(), sizes its kmalloc() buffer using hp_calculate_security_buffer()'s return value, so for an empty authentication token it allocates 4 bytes for the security area but hp_populate_security_buffer() then writes 20 bytes into it, causing a 16-byte heap buffer overflow.
The authentication token used here is the current admin/setup password, which is an empty string by default until one is configured. Any write to a writable BIOS attribute while no admin password has been set reaches this path.
Fix by removing the special-case early return for an empty string in hp_calculate_security_buffer(). The generic calculation that follows already accounts for the UTF_PREFIX correctly, which naturally yields the same 20 bytes that hp_populate_security_buffer() writes for an empty string, avoiding duplicate logic for special cases.
--- drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 3 --- 1 file changed, 3 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +0 -3
@@ -47,9 +47,6 @@ size_t hp_calculate_security_buffer(const char *authentication)return sizeof (u16) *2 ; authlen =strlen (authentication); -if (!authlen) -return sizeof (u16) *2 ; - size =sizeof (u16) + authlen *sizeof (u16);if (!strstarts (authentication,BEAM_PREFIX )) size +=strlen (UTF_PREFIX ) *sizeof (u16);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1079/3318 platform/x86: hp-wmi: fix heap OOB read and memory corruption in hp_wmi_perform_query()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit 6dea092b261f04d632411c2be52d13190f5f67b1 ]
hp_wmi_perform_query() evaluates an ACPI WMI method and expects a struct bios_return header in the returned buffer. However, it only checks that the ACPI object type is ACPI_TYPE_BUFFER without verifying that obj->buffer.length is at least sizeof(*bios_return) (8 bytes).
If the firmware or ACPI method returns a buffer shorter than 8 bytes:
1. bios_return->return_code at offset 4 reads out of bounds from the allocated ACPI buffer slab.
2. If return_code evaluates to 0 and outsize is non-zero, (int)(obj->buffer.length - sizeof(*bios_return)) evaluates to a negative integer (e.g. -8 for a 0-length buffer). actual_outsize is set to this negative value and passed to memcpy(buffer, ..., actual_outsize), where the signed negative value is cast to size_t (e.g. 0xfffffffffffffff8), attempting to copy ~18 Exabytes and triggering an immediate kernel crash. Additionally, memset(buffer + actual_outsize, ...) performs an out-of-bounds write before buffer.
Fix this by ensuring obj->buffer.length is at least sizeof(*bios_return) before accessing the return code, and compute actual_outsize safely using min_t(u32, ...), which is sound specifically because the guard above already rules out obj->buffer.length being smaller than sizeof(*bios_return) by the time that subtraction runs.
--- drivers/platform/x86/hp/hp-wmi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/hp/hp-wmi.c +4 -3
@@ -355,8 +355,9 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command, goto out_free; } -if (obj->type !=ACPI_TYPE_BUFFER ) { -pr_warn ("query 0x%x returned an invalid object 0x%x\n" , query, ret); +if (obj->type !=ACPI_TYPE_BUFFER || + obj->buffer.length <sizeof (*bios_return)) { +pr_warn ("query 0x%x returned wrong type or too small buffer\n" , query); ret = -EINVAL ; goto out_free; }
@@ -375,7 +376,7 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command,if (!outsize) goto out_free; - actual_outsize =min (outsize, (int )(obj->buffer.length -sizeof (*bios_return))); + actual_outsize =min_t (u32, outsize, obj->buffer.length -sizeof (*bios_return));memcpy (buffer, obj->buffer.pointer +sizeof (*bios_return), actual_outsize);memset (buffer + actual_outsize,0 , outsize - actual_outsize);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1080/3318 platform/x86: simatic-ipc: fix platform device leak on registration failure
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 9523698252fd583d6987582b9c34ec6500d10986 ]
register_platform_devices() registers the battery, LED, and watchdog platform devices in sequence. If LED registration fails, the battery device remains registered. If watchdog registration fails, the LED and battery devices remain registered.
These failure paths leave successful platform_device_register_data() calls without the matching platform_device_unregister() calls.
Add an unwind ladder to unregister previously registered platform devices in reverse order before returning the registration error.
The issue was identified by a static analysis tool I developed and confirmed by manual review.
--- drivers/platform/x86/siemens/simatic-ipc.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/platform/x86/siemens/simatic-ipc.c +17 -4
@@ -92,6 +92,7 @@ static int register_platform_devices(u32 station_id)u8 wdtmode =SIMATIC_IPC_DEVICE_NONE ;u8 battmode =SIMATIC_IPC_DEVICE_NONE ;char *pdevname; +int ret;int i;for (i =0 ; i <ARRAY_SIZE (device_modes); i++) {
@@ -139,8 +140,10 @@ static int register_platform_devices(u32 station_id) pdevname,PLATFORM_DEVID_NONE , &platform_data, sizeof(struct simatic_ipc_platform)); -if (IS_ERR (ipc_led_platform_device)) -return PTR_ERR (ipc_led_platform_device); +if (IS_ERR (ipc_led_platform_device)) { + ret =PTR_ERR (ipc_led_platform_device); + goto err_unregister_batt; + }pr_debug ("device=%s created\n" , ipc_led_platform_device->name);
@@ -153,8 +156,10 @@ static int register_platform_devices(u32 station_id)KBUILD_MODNAME "_wdt" ,PLATFORM_DEVID_NONE , &platform_data, sizeof(struct simatic_ipc_platform)); -if (IS_ERR (ipc_wdt_platform_device)) -return PTR_ERR (ipc_wdt_platform_device); +if (IS_ERR (ipc_wdt_platform_device)) { + ret =PTR_ERR (ipc_wdt_platform_device); + goto err_unregister_led; + }pr_debug ("device=%s created\n" , ipc_wdt_platform_device->name);
@@ -169,6 +174,14 @@ static int register_platform_devices(u32 station_id) }return 0 ; + +err_unregister_led: +if (ledmode !=SIMATIC_IPC_DEVICE_NONE ) +platform_device_unregister (ipc_led_platform_device); +err_unregister_batt: +if (battmode !=SIMATIC_IPC_DEVICE_NONE ) +platform_device_unregister (ipc_batt_platform_device); +return ret; }static void request_additional_modules (u32 station_id)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1081/3318 platform/x86/intel-uncore-freq: Continue restoring limits on resume
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixiong Wei <[email protected]>
[ Upstream commit 38998529f45c02edcf96b0a3ddd3c83de6d11bbe ]
The PM notifier iterates over every uncore frequency instance to restore user-configured MSR_UNCORE_RATIO_LIMIT values after resume. Entries that have never been configured legitimately have stored_uncore_data set to zero.
The refactoring that split common and enumeration code changed the iteration from active control CPUs to all allocated instances. It also changed the skip for an invalid or unconfigured entry from continue to return, causing that entry to terminate the entire restore operation.
On a multi-package or multi-die system, configuring only a later instance therefore leaves its limit unrestored after suspend, hibernation, or restore if an earlier entry is invalid or unconfigured.
Use continue to skip only the current entry and restore all remaining configured instances.
--- drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c +1 -1
@@ -185,7 +185,7 @@ static int uncore_pm_notify(struct notifier_block *nb, unsigned long mode,struct uncore_data *data = &uncore_instances[i];if (!data || !data->valid || !data->stored_uncore_data) -return 0 ; +continue ;wrmsrl_on_cpu (data->control_cpu,MSR_UNCORE_RATIO_LIMIT , data->stored_uncore_data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1082/3318 fbdev: ssd1307fb: check for fb_deferred_io_init() error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 81ae1f9a6c850efab3e5dec6b7c9aa5c587f92b7 ]
fb_deferred_io_init() allocates deferred I/O state, populating info->fbdefio_state, or leaving it NULL if an error occurs.
Currently ssd1307fb_probe() ignores its return value.
Therefore if an error arises in fb_deferred_io_init() (for instance, due to an allocation failure) info->fbdefio_state is left NULL.
When the file is subsequently opened, fb_open() will dereference a NULL pointer (calling fb_deferred_io_open()).
Fix this by checking for the error.
--- drivers/video/fbdev/ssd1307fb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/video/fbdev/ssd1307fb.c +5 -1
@@ -771,7 +771,11 @@ static int ssd1307fb_probe(struct i2c_client *client) info->fix.smem_start =__pa (vmem); info->fix.smem_len = vmem_size; -fb_deferred_io_init (info); + ret =fb_deferred_io_init (info); +if (ret) { +dev_err (dev,"failed to init fb deferred io: %d\n" , ret); + goto fb_defio_error; + }i2c_set_clientdata (client, info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1083/3318 fbdev: xen-fbfront: check for fb_deferred_io_init() error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 5b234b0dd29d79207c059c7b40851dd1e934fa3a ]
fb_deferred_io_init() allocates deferred I/O state, populating info->fbdefio_state, or leaving it NULL if an error occurs.
Currently xenfb_probe() ignores its return value.
Therefore if an error arises in fb_deferred_io_init() (for instance, due to an allocation failure) info->fbdefio_state is left NULL.
When the file is subsequently opened, fb_open() will dereference a NULL pointer (calling fb_deferred_io_open()).
Fix this by checking for the error.
--- drivers/video/fbdev/xen-fbfront.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/xen-fbfront.c +6 -1
@@ -442,7 +442,11 @@ static int xenfb_probe(struct xenbus_device *dev, } fb_info->fbdefio = &xenfb_defio; -fb_deferred_io_init (fb_info); + ret =fb_deferred_io_init (fb_info); +if (ret <0 ) { +xenbus_dev_fatal (dev, ret,"fb_deferred_io_init" ); + goto error_cmap; + }xenfb_init_shared_page (info, fb_info);
@@ -464,6 +468,7 @@ static int xenfb_probe(struct xenbus_device *dev, error_fb:fb_deferred_io_cleanup (fb_info); +error_cmap:fb_dealloc_cmap (&fb_info->cmap);framebuffer_release (fb_info); error_nomem:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1084/3318 fbdev: udlfb: check for fb_deferred_io_init() error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit eae055f33e41e1d3e1a7e905bdcb1e9f196ed31d ]
fb_deferred_io_init() allocates deferred I/O state, populating info->fbdefio_state, or leaving it NULL if an error occurs.
Currently dlfb_ops_open() ignores its return value.
Therefore if an error arises in fb_deferred_io_init() (for instance, due to an allocation failure) info->fbdefio_state is left NULL.
fb_open() will then dereference a NULL pointer (calling fb_deferred_io_open()) as soon as dlfb_ops_open() returns.
Additionally, if the allocation of info->fbdefio itself fails, dlfb_ops_open() sets info->fbdefio to NULL and invokes fb_deferred_io_init() regardless, hitting BUG_ON(!fbdefio).
Fix this by only invoking fb_deferred_io_init() if the allocation succeeded, and checking for the error.
The driver already supports operating without deferred I/O, so in either case fall back to that by setting info->fbdefio to NULL.
The ignored return value was introduced in commit 56c134f7f1b5 ("fbdev:
Track deferred-I/O pages in pageref struct").
However, the BUG_ON() issue originates from the earlier commit 5bea1fbf9423 ("staging: udlfb: fix incorrect fb_defio implementation for multiple framebuffers"), so target that for the fix.
--- drivers/video/fbdev/udlfb.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/video/fbdev/udlfb.c +6 -3
@@ -1007,10 +1007,13 @@ static int dlfb_ops_open(struct fb_info *info, int user) fbdefio->delay =DL_DEFIO_WRITE_DELAY ; fbdefio->sort_pagereflist = true; fbdefio->deferred_io = dlfb_dpy_deferred_io; - } - info->fbdefio = fbdefio; -fb_deferred_io_init (info); + info->fbdefio = fbdefio; +if (fb_deferred_io_init (info)) { +kfree (fbdefio); + info->fbdefio =NULL ; + } + } } dev_dbg(info->dev, "open, user=%d fb_info=%p count=%d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1085/3318 fbdev: smscufx: check for fb_deferred_io_init() error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 8ea6c6e77ccf887f3e68c64f4c261071a345da1e ]
fb_deferred_io_init() allocates deferred I/O state, populating info->fbdefio_state, or leaving it NULL if an error occurs.
Currently ufx_ops_open() ignores its return value.
Therefore if an error arises in fb_deferred_io_init() (for instance, due to an allocation failure) info->fbdefio_state is left NULL.
fb_open() will then dereference a NULL pointer (calling fb_deferred_io_open()) as soon as ufx_ops_open() returns.
Additionally, if the allocation of info->fbdefio itself fails, ufx_ops_open() sets info->fbdefio to NULL and invokes fb_deferred_io_init() regardless, hitting BUG_ON(!fbdefio).
Fix this by only invoking fb_deferred_io_init() if the allocation succeeded, and checking for the error.
The driver already supports operating without deferred I/O, so in either case fall back to that by setting info->fbdefio to NULL.
The ignored return value was introduced in commit 56c134f7f1b5 ("fbdev:
Track deferred-I/O pages in pageref struct").
However, the BUG_ON() issue originates from the earlier commit 3c8a63e22a08 ("Add support for SMSC UFX6000/7000 USB display adapters"), so target that for the fix.
--- drivers/video/fbdev/smscufx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/video/fbdev/smscufx.c +6 -3
@@ -1097,10 +1097,13 @@ static int ufx_ops_open(struct fb_info *info, int user)if (fbdefio) { fbdefio->delay =UFX_DEFIO_WRITE_DELAY ; fbdefio->deferred_io = ufx_dpy_deferred_io; - } - info->fbdefio = fbdefio; -fb_deferred_io_init (info); + info->fbdefio = fbdefio; +if (fb_deferred_io_init (info)) { +kfree (fbdefio); + info->fbdefio =NULL ; + } + } } pr_debug("open /dev/fb%d user=%d fb_info=%p count=%d",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1086/3318 fbdev: sh_mobile_lcdc: check for fb_deferred_io_init() error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 5192201aaac2a923ff98306e3ccda58718ee395f ]
fb_deferred_io_init() allocates deferred I/O state, populating info->fbdefio_state, or leaving it NULL if an error occurs.
Currently sh_mobile_lcdc_start() ignores its return value.
Therefore if an error arises in fb_deferred_io_init() (for instance, due to an allocation failure) info->fbdefio_state is left NULL.
When the file is subsequently opened, fb_open() will dereference a NULL pointer (calling fb_deferred_io_open()).
Fix this by checking for the error.
Also clear info->fbdefio in that case, so that sh_mobile_lcdc_stop() does not attempt to clean up deferred I/O state that was never initialised.
--- drivers/video/fbdev/sh_mobile_lcdcfb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/video/fbdev/sh_mobile_lcdcfb.c +5 -1
@@ -1042,7 +1042,11 @@ static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv) ch->defio.deferred_io = sh_mobile_lcdc_deferred_io; ch->defio.delay =msecs_to_jiffies (tmp); ch->info->fbdefio = &ch->defio; -fb_deferred_io_init (ch->info); + ret =fb_deferred_io_init (ch->info); +if (ret) { + ch->info->fbdefio =NULL ; +return ret; + } }sh_mobile_lcdc_display_on (ch);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1087/3318 dm-bufio: fix a race leading to an unsigned integer underflow
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 005d2ec5723cd4ac740de678274623f1fadd6a6e ]
The function __scan tests "count - freed <= retain_target" and then sets "atomic_long_set(&c->need_shrink, 0);" It exits with the condition "if (!atomic_long_read(&c->need_shrink)) break;" It may be possible that between these two statements, another thread sets &c->need_shrink to a non-zero value. In this case, the function __scan continues and it may possibly the "freed" variable is larger than the "count" variable. The expression "count - freed" underflows and the function __scan will continue to free all the buffers, even those that are below retain_target.
Fix this bug by immediatelly exiting if we set "atomic_long_set(&c->need_shrink, 0)"; and don't attempt to re-read c->need_shrink afterwards.
--- drivers/md/dm-bufio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm-bufio.c +3 -1
@@ -2378,8 +2378,10 @@ static void __scan(struct dm_bufio_client *c)for (l =0 ; l <LIST_SIZE ; l++) {while (true) { -if (count - freed <= retain_target) +if (count - freed <= retain_target) {atomic_long_set (&c->need_shrink,0 ); +break ; + }if (!atomic_long_read (&c->need_shrink))break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1088/3318 speakup: Fix NULL pointer dereference on VT switch + selection
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Thibault <[email protected]>
[ Upstream commit e1301ab8a8411fccc7effe0711fc09939a94953c ]
When selecting/pasting very quickly after VT switch, the tty is not set yet, leading to a NULL dereference. We can just abort the operation.
--- drivers/accessibility/speakup/selection.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/accessibility/speakup/selection.c +6 -0
@@ -61,6 +61,9 @@ static struct speakup_selection_work speakup_sel_work = {int speakup_set_selection (struct tty_struct *tty) { +if (!tty) +return -ENODEV ; +/* we get kref here first in order to avoid a subtle race when * cancelling selection work. getting kref first establishes the * invariant that if speakup_sel_work.tty is not NULL when
@@ -120,6 +123,9 @@ static struct speakup_selection_work speakup_paste_work = {int speakup_paste_selection (struct tty_struct *tty) { +if (!tty) +return -ENODEV ; +tty_kref_get (tty);if (cmpxchg (&speakup_paste_work.tty,NULL , tty)) {tty_kref_put (tty);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1089/3318 clk: qcom: ipq5018: add 24MHz rate for USB UTMI clock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kathiravan Thirumoorthy <[email protected]>
[ Upstream commit 75e893169fc5c9ec28d5f9dffde40ce29b59a5de ]
The USB UTMI reference clock must operate at 24 MHz, as recommended by the hardware team, for reliable USB operation.
Validation showed that USB 3.2 hub enumeration with USB 2.0 devices fails when the UTMI reference clock is not configured to the required 24 MHz rate. Configuring the UTMI reference clock to 24 MHz to resolve the enumeration failure and ensure successful device detection.
--- drivers/clk/qcom/gcc-ipq5018.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/qcom/gcc-ipq5018.c +1 -0
@@ -1269,6 +1269,7 @@ static struct clk_rcg2 usb0_master_clk_src = { };static const struct freq_tbl ftbl_usb0_mock_utmi_clk_src[] = { +F (24000000 ,P_XO ,1 ,0 ,0 ),F (60000000 ,P_GPLL4 ,10 ,1 ,2 ), { } };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1090/3318 clk: qcom: ipq5332: add 24MHz rate for USB UTMI clock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kathiravan Thirumoorthy <[email protected]>
[ Upstream commit 19b62f31e15ef70dc927aab91b1576ea6c37f992 ]
The USB UTMI reference clock must operate at 24 MHz, as recommended by the hardware team, for reliable USB operation.
Validation showed that USB 3.2 hub enumeration with USB 2.0 devices fails when the UTMI reference clock is not configured to the required 24 MHz rate. Configuring the UTMI reference clock to 24 MHz to resolve the enumeration failure and ensure successful device detection.
--- drivers/clk/qcom/gcc-ipq5332.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/qcom/gcc-ipq5332.c +1 -0
@@ -1048,6 +1048,7 @@ static struct clk_rcg2 gcc_usb0_master_clk_src = { };static const struct freq_tbl ftbl_gcc_usb0_mock_utmi_clk_src[] = { +F (24000000 ,P_XO ,1 ,0 ,0 ),F (60000000 ,P_GPLL4_OUT_AUX ,10 ,1 ,2 ), { } };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1091/3318 iomap: dont lose a fiemap iteration error when emitting the last extent
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit 0d0104adc2c8316433b660cdf6d182a09881864f ]
iomap_fiemap() emits extents one behind: iomap_fiemap_iter() flushes the previous extent and remembers the current one, and the remembered extent is written with FIEMAP_EXTENT_LAST after the iteration loop.
That final flush overwrites ret, so when ->iomap_begin() fails partway through the iteration the error is replaced by the result of iomap_to_fiemap() (zero on success) and iomap_fiemap() returns success with a truncated extent list whose last entry is wrongly marked as the last extent in the file. The pre-iomap_iter code returned the error from inside the loop, before flushing the pending extent.
Check for the iteration error before flushing the pending extent, so that real errors are propagated and only a successful iteration emits the final FIEMAP_EXTENT_LAST extent. -ENOENT (no mapping) is still not an error, and the pending extent is still emitted in that case.
--- fs/iomap/fiemap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/iomap/fiemap.c +4 -4
@@ -80,15 +80,15 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi,while ((ret =iomap_iter (&iter, ops)) >0 ) iter.processed =iomap_fiemap_iter (&iter, fi, &prev); +/* inode with no (attribute) mapping will give ENOENT */ +if (ret <0 && ret != -ENOENT ) +return ret; +if (prev.type !=IOMAP_HOLE ) { ret =iomap_to_fiemap (fi, &prev,FIEMAP_EXTENT_LAST );if (ret <0 )return ret; } - -/* inode with no (attribute) mapping will give ENOENT */ -if (ret <0 && ret != -ENOENT ) -return ret;return 0 ; }EXPORT_SYMBOL_GPL (iomap_fiemap);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1092/3318 nvme-rdma: dont complete a request after a bogus remote invalidation
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 909307cea08aff4e486cdb7491de5c76a2c31341 ]
When a remote invalidation names an rkey that is not the one we handed out for this request, nvme_rdma_process_nvme_rsp() logs and schedules error recovery, then falls through to nvme_rdma_end_request(). The request is completed with req->mr never invalidated, and nvme_rdma_unmap_data() hands it back with ib_mr_pool_put(), which only puts it on a list. The rkey stays valid and still maps the pages the completed read filled, so a controller that sent the bogus invalidation can write into those pages after pread() has returned.
Return instead, the way the local invalidation path below already does, and leave the request for error recovery to cancel.
--- drivers/nvme/host/rdma.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/rdma.c +1 -0
@@ -1699,6 +1699,7 @@ static void nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue,"Bogus remote invalidation for rkey %#x\n" , req->mr ? req->mr->rkey : 0);nvme_rdma_error_recovery (queue->ctrl); +return ; } }else if (req->mr) {int ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1093/3318 nvmet: free the bvec on file namespace range errors
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 9d820d55b3cb4859c7cf42a74dc78f6154f97398 ]
nvmet_file_execute_rw() allocates the bvec before nvmet_file_execute_io() checks whether the request fits in the backing file. If the request extends beyond the file, nvmet_file_execute_io() calls nvmet_req_complete() to return an error. This skips nvmet_file_io_done(), so the allocated memory is never freed. Repeated requests can exhaust memory.
Use nvmet_file_io_done() to free the bvec before returning the range error to the client.
--- drivers/nvme/target/io-cmd-file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/io-cmd-file.c +2 -2
@@ -133,8 +133,8 @@ static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags) pos =le64_to_cpu (req->cmd->rw.slba) << req->ns->blksize_shift;if (unlikely (pos + req->transfer_len > req->ns->size)) { -nvmet_req_complete (req,errno_to_nvme_status (req, -ENOSPC )); -return true; + ret = -ENOSPC ; + goto complete; }memset (&req->f.iocb,0 ,sizeof (struct kiocb ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1094/3318 nvmet: zns: dont leak stale memory in zone management receive
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit 31b8a6af19b73e6167c4b655cd5e86681bac1c41 ]
A Zone Management Receive report returns the full buffer the host asked for, but nvmet_bdev_zone_zmgmt_recv_work() writes only the 8-byte Number of Zones field and one 64-byte descriptor for each matching zone that fits. The 56 reserved header bytes and every descriptor slot past the last match keep whatever the buffer held before. A 4096-byte report covering a single zone leaves 4024 bytes unwritten.
The tcp, rdma and fc transports allocate that buffer with sgl_alloc() and pci-epf with kmalloc(), none with __GFP_ZERO, and on success each sends the whole buffer to the host (nvmet_setup_c2h_data_pdu() for tcp), so the host receives old kernel memory from the target.
nvmet_bdev_execute_zone_mgmt_recv() also never checks the transport data length against NUMD, so on transports where the host sets that length, the buffer sent back can be much larger than the report NUMD describes. pci-epf derives its data length from NUMD, so the length check below does not apply there, but the zeroing still covers the report.
Reject a data length that does not match NUMD with nvmet_check_transfer_len(), as nvmet_bdev_execute_zone_append() does, and zero the report with nvmet_zero_sgl() before filling it. Zeroing NUMD bytes is only enough because of the length check, so the two go together.
Allocating with __GFP_ZERO in the transports would also close the leak, but it adds a memset to every read command to fix one handler, so the transports are left alone.
Tested over the loop, tcp, rdma and fc transports with a zoned null_blk namespace: before this patch, zone reports carried stale bytes and a data length larger than NUMD was accepted; with it, reports are fully initialized and such a length fails with Data SGL Length Invalid.
--- drivers/nvme/target/zns.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/nvme/target/zns.c +10 -0
@@ -290,6 +290,11 @@ static void nvmet_bdev_zone_zmgmt_recv_work(struct work_struct *w)if (status) goto out; +/* Only the zone count and matching descriptors are written below. */ + status =nvmet_zero_sgl (req,0 , out_bufsize); +if (status) + goto out; +if (!req_slba_nr_zones) { status =NVME_SC_SUCCESS ; goto out;
@@ -318,6 +323,11 @@ static void nvmet_bdev_zone_zmgmt_recv_work(struct work_struct *w)void nvmet_bdev_execute_zone_mgmt_recv (struct nvmet_req *req) { +u32 out_bufsize = (le32_to_cpu (req->cmd->zmr.numd) +1 ) <<2 ; + +if (!nvmet_check_transfer_len (req, out_bufsize)) +return ; +INIT_WORK (&req->z.zmgmt_work, nvmet_bdev_zone_zmgmt_recv_work);queue_work (zbd_wq, &req->z.zmgmt_work); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1095/3318 PCI: rockchip-host: Do not attempt 5.0 GT/s retraining
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 2a1e6c382fb7567679c07bd6a7060fefc7a5edc9 ]
Drop the 5.0 GT/s Link Speed retraining from Rockchip PCIe Root Complex Mode Operation, so-called host driver.
The reason is that Shawn Lin from Rockchip has reiterated that there may be danger of "catastrophic failure" in using their PCIe with 5.0GT/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-host.c | 20 -------------------- 1 file changed, 20 deletions(-)
drivers/pci/controller/pcie-rockchip-host.c +0 -20
@@ -334,26 +334,6 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) goto err_power_off_phy; } -if (rockchip->link_gen ==2 ) { -/* -* Enable retrain for gen2. This should be configured only after -* gen1 finished. -*/ - status =rockchip_pcie_read (rockchip,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL2 ); - status &= ~PCI_EXP_LNKCTL2_TLS ; - status |=PCI_EXP_LNKCTL2_TLS_5_0GT ; -rockchip_pcie_write (rockchip, status,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL2 ); - status =rockchip_pcie_read (rockchip,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL ); - status |=PCI_EXP_LNKCTL_RL ; -rockchip_pcie_write (rockchip, status,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL ); - - err =readl_poll_timeout (rockchip->apb_base +PCIE_CORE_CTRL , - status,PCIE_LINK_IS_GEN2 (status),20 , -500 *USEC_PER_MSEC ); -if (err) -dev_dbg (dev,"PCIe link training gen2 timeout, fall back to gen1!\n" ); - } -/* Check the final link width from negotiated lane counter from MGMT */ status =rockchip_pcie_read (rockchip,PCIE_CORE_CTRL ); status = 0x1 << ((status & PCIE_CORE_PL_CONF_LANE_MASK) >>
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1096/3318 sh: intc: Sort the prio and sense lists after filling them
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 94a219eda3b5fb1d1753a5ecf28b171c8f308a27 ]
register_intc_controller() sorts d->prio and d->sense right after allocating them, with hw->nr_prio_regs and hw->nr_sense_regs as the element count. The lists hold hw->nr_vectors entries and are only filled later, by intc_register_irq().
On SH7785, sh7785-irq0123 and sh7785-irq4567 have four vectors but the SoC's eleven priority registers, so sort() swaps 88 bytes in a 32 byte kmalloc object at boot. slub_debug=FZPU reports "Right Redzone overwritten" in kmalloc-32, and v6.5 and v6.6 panic in __kmem_cache_alloc_node() while registering sh7785-irq0123.
Found with a custom QEMU model of the SH7785LCR. On it, v6.4 sh7785lcr_defconfig boots with SLAB, the defconfig default before v6.5, and hangs before the console is up when built with SLUB.
Sort the lists once all vectors are registered, with the number of entries that were added.
--- drivers/sh/intc/core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/sh/intc/core.c +5 -6
@@ -277,9 +277,6 @@ int __init register_intc_controller(struct intc_desc *desc) k +=save_reg (d, k, hw->prio_regs[i].set_reg, smp); k +=save_reg (d, k, hw->prio_regs[i].clr_reg, smp); } - -sort (d->prio, hw->nr_prio_regs,sizeof (*d->prio), - intc_handle_int_cmp,NULL ); }if (hw->sense_regs) {
@@ -290,9 +287,6 @@ int __init register_intc_controller(struct intc_desc *desc)for (i =0 ; i < hw->nr_sense_regs; i++) k +=save_reg (d, k, hw->sense_regs[i].reg,0 ); - -sort (d->sense, hw->nr_sense_regs,sizeof (*d->sense), - intc_handle_int_cmp,NULL ); }if (hw->subgroups)
@@ -360,6 +354,11 @@ int __init register_intc_controller(struct intc_desc *desc) } } +sort (d->prio, d->nr_prio,sizeof (*d->prio), + intc_handle_int_cmp,NULL ); +sort (d->sense, d->nr_sense,sizeof (*d->sense), + intc_handle_int_cmp,NULL ); +intc_subgroup_init (desc, d);/* enable bits matching force_enable after registering irqs */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1097/3318 f2fs: read i_size once in f2fs_vm_page_mkwrite
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 c04f209773ecb31e592cababce0d6658ee0b8d58 ]
f2fs_vm_page_mkwrite() reads i_size twice: once to check whether the folio is partially beyond EOF, and once to calculate the offset for folio_zero_segment(). But a concurrent buffered write can extend isize and cause the following race condition to corrupt data:
buffered write writes [0,3500)
CPU0 (write fault) CPU1 (buffered write)
---- ----
f2fs_vm_page_mkwrite()
folio_lock(folio)
if (((loff_t)(folio->index + 1) << PAGE_SHIFT) >
i_size_read(inode))
/* i_size_read() = 3500 */
write(fd, buf, 200, 4096)
/* writes into page1, does not
wait for folio lock */
i_size_write(inode, 4296) offset = i_size_read(inode) & ~PAGE_MASK
/* i_size_read() = 4296, offset = 200 */ folio_zero_segment(folio, offset, folio_size(folio)) /* valid data [200, 3500) is zeroed */
Fix this by reading i_size once and using the same value for both the EOF check and the zeroing offset.
--- fs/f2fs/file.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
fs/f2fs/file.c +10 -4
@@ -124,6 +124,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct dnode_of_data dn;bool need_alloc = !f2fs_is_pinned_file (inode); +loff_t isize;int err =0 ;vm_fault_t ret;
@@ -178,8 +179,14 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)filemap_invalidate_lock_shared (inode->i_mapping);folio_lock (folio); +/* +* A concurrent buffered write can extend isize, so we store isize in a +* local variable to let the zeroing offset match the EOF check below. +*/ + isize =i_size_read (inode); +if (unlikely (folio->mapping != inode->i_mapping || -folio_pos (folio) >i_size_read (inode) || +folio_pos (folio) > isize || !folio_test_uptodate (folio))) {folio_unlock (folio); err = -EFAULT ;
@@ -215,11 +222,10 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) goto out_sem;/* page is wholly or partially inside EOF */ -if (((loff_t)(folio->index +1 ) <<PAGE_SHIFT ) > -i_size_read (inode)) { +if (((loff_t)(folio->index +1 ) <<PAGE_SHIFT ) > isize) {loff_t offset; - offset =i_size_read (inode) & ~PAGE_MASK ; + offset = isize & ~PAGE_MASK ;folio_zero_segment (folio, offset,folio_size (folio)); }folio_mark_dirty (folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1098/3318 f2fs: check every cur_*_segno[] entry on readonly images
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 9c4ee79190c8c23a9fb5c07d3bc87eaac514b2bb ]
sanity_check_ckpt() bounds-checks cur_node_segno[] and cur_data_segno[] against main_segs, but on an image with the RO feature the goto that skips the duplicate-segno cross-checks also leaves the enclosing loop, so only index 0 of each array is ever checked.
An unchecked index reaches __set_sit_entry_type() through build_curseg() -> reset_curseg(), which writes se->type through &sit_i->sentries[segno]. With segment_count_main 120 and cur_data_segno[1] set to 200, KASAN reports three out-of-bounds writes during mount and the mount then succeeds.
Use continue so every index is bounds-checked, and skip the node-vs-data cross-check explicitly, which is the other thing the old goto skipped.
--- fs/f2fs/super.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/super.c +6 -3
@@ -3707,7 +3707,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)return 1 ;if (f2fs_sb_has_readonly (sbi)) - goto check_data; +continue ;for (j = i +1 ; j <NR_CURSEG_NODE_TYPE ; j++) { if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
@@ -3719,14 +3719,14 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) } } } -check_data: +for (i =0 ; i <NR_CURSEG_DATA_TYPE ; i++) {if (le32_to_cpu (ckpt->cur_data_segno[i]) >= main_segs ||le16_to_cpu (ckpt->cur_data_blkoff[i]) >= blocks_per_seg)return 1 ;if (f2fs_sb_has_readonly (sbi)) - goto skip_cross; +continue ;for (j = i +1 ; j <NR_CURSEG_DATA_TYPE ; j++) { if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
@@ -3738,6 +3738,9 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) } } } +if (f2fs_sb_has_readonly (sbi)) + goto skip_cross; +for (i =0 ; i <NR_CURSEG_NODE_TYPE ; i++) {for (j =0 ; j <NR_CURSEG_DATA_TYPE ; j++) { if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1099/3318 pinctrl: stm32: Fix fwnode reference leak in stm32_gpiolib_register_bank()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Ke <[email protected]>
[ Upstream commit 54c66b5e47a9b10cbf4a1efe9b01301b7ffee205 ]
stm32_gpiolib_register_bank() walks the "gpio-ranges" property with fwnode_property_get_reference_args(). As documented in drivers/base/property.c:
* The caller is responsible for calling fwnode_handle_put() on the
* returned @args->fwnode pointer.
The returned reference is never put. The function calls the helper twice, once directly and then repeatedly in a while loop, and each call overwrites args, so only the last reference is even reachable and all the earlier ones are leaked for good.
Put the reference as soon as args.args[] has been consumed, both for the initial call and for every iteration of the loop.
Found by code review.
--- drivers/pinctrl/stm32/pinctrl-stm32.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +5 -1
@@ -1332,8 +1332,12 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode/* get the last defined gpio line (offset + nb of pins) */ npins = args.args[0 ] + args.args[2 ]; -while (!fwnode_property_get_reference_args (fwnode,"gpio-ranges" ,NULL ,3 , ++i, &args)) +fwnode_handle_put (args.fwnode); + +while (!fwnode_property_get_reference_args (fwnode,"gpio-ranges" ,NULL ,3 , ++i, &args)) { npins =max (npins, (int )(args.args[0 ] + args.args[2 ])); +fwnode_handle_put (args.fwnode); + } }else { bank_nr = pctl->nbanks; bank->gpio_chip.base = bank_nr *STM32_GPIO_PINS_PER_BANK ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1100/3318 lib/decompress_bunzip2: fix off-by-one in run-length bounds check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Turner <[email protected]>
[ Upstream commit 69919be2b93ef3922f646729ff42b4bd9a30846b ]
The run-length path rejects a block when dbufCount+t equals dbufSize, but the loop that follows writes exactly t bytes starting at dbufCount, so a block that fills the buffer exactly is legal. bzip2 allows it too: its decompressor bounds a block at 100000 * blockSize100k and checks that limit per byte appended. Use > instead of >=.
bzip2's encoder stops filling a block 19 bytes early, so nothing it produces ever reaches the limit and the bug stays hidden. Compressors that use the full block size do reach it: an lbzip2 -9 image whose block ends on a run fails to decode, and a self-extracting kernel built that way does not boot.
This code came from busybox, which fixed the same line in 2013 in commit 932e233a491b ("bunzip2: fix off-by-one check").
I ran into this because my system uses lbzip2 as /bin/bzip2 -- a common thing on Gentoo I believe. As far as I can tell, anyone using lbzip2 as their system bzip2 would run into this and it's only because it's very uncommon these days to compress a kernel with bzip2 that no one has noticed. I only noticed because I was adding support for various compression formats on alpha.
--- lib/decompress_bunzip2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/decompress_bunzip2.c +1 -1
@@ -439,7 +439,7 @@ static int INIT get_next_block(struct bunzip_data *bd)array.) */ if (runPos) { runPos =0 ; -if (dbufCount+t >= dbufSize) +if (dbufCount+t > dbufSize)return RETVAL_DATA_ERROR ; uc = symToByte[mtfSymbol[0 ]];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1101/3318 lib: decompress_bunzip2: fix integer overflow in run-length decoding
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
[ Upstream commit b822ad8d702df0be9fe3f24f71caeb0522d72319 ]
The RUNA/RUNB decoder in get_next_block() accumulates a run length into the signed int t with no bound. runPos doubles per symbol, so t grows as at least 2^n-1 and reaches INT_MAX after 31 RUNA symbols. The guard that follows, dbufCount+t >= dbufSize, is itself a signed addition, and as the kernel builds with -fno-strict-overflow it wraps negative once dbufCount is nonzero, so the guard is skipped. while (t--) dbuf[dbufCount++] = uc then writes INT_MAX entries into a buffer holding at most 900000. One literal symbol ahead of the run is enough to make dbufCount nonzero.
Bound t to the block size as it is accumulated. t only grows within a run, so the value tested never exceeds the final run length; any stream that decodes today satisfies dbufCount+t < dbufSize at the flush, hence t < dbufSize throughout, and no such stream is rejected. Because t grows as at least 2^n-1 the bound trips by the 20th symbol, leaving runPos at most 2^19, so the following runPos <<= 1 cannot overflow either.
--- lib/decompress_bunzip2.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/decompress_bunzip2.c +4 -0
@@ -428,6 +428,10 @@ static int INIT get_next_block(struct bunzip_data *bd) t += (runPos << nextSym);/* +runPos if RUNA; +2*runPos if RUNB */ +/* Bound the run so t and runPos cannot overflow. */ +if (t >= dbufSize) +return RETVAL_DATA_ERROR ; + runPos <<=1 ;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1102/3318 ALSA: cs46xx: fix unit mismatch in DSP code area bounds check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis Arefev <[email protected]>
[ Upstream commit fd65108f5001ffb416dc9bd37ec1893f55cff24a ]
ins->code.offset and code->size are measured in 32-bit words, while DSP_CODE_BYTE_SIZE is the size of the DSP code area in bytes. The check ins->code.offset + code->size > DSP_CODE_BYTE_SIZE in cs46xx_dsp_load_module() therefore allowed up to four times more code than the code area can hold.
The shadow buffer ins->code.data is allocated with kmalloc(DSP_CODE_BYTE_SIZE), i.e. it holds DSP_CODE_BYTE_SIZE/4 words. A firmware file with a code segment larger than DSP_CODE_BYTE_SIZE/4 words (28 KiB) passed the check and caused an out-of-bounds write in shadow_and_reallocate_code() and an out-of-bounds read in snd_cs46xx_download().
Compare the sum in words against DSP_CODE_BYTE_SIZE/4 and cast it to u64 so that the sum cannot wrap for large code->size values.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- sound/pci/cs46xx/dsp_spos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/cs46xx/dsp_spos.c +1 -1
@@ -396,7 +396,7 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * mdev_dbg (chip->card->dev,"dsp_spos: module got no code segment\n" ); }else { -if (ins->code.offset + code->size >DSP_CODE_BYTE_SIZE ) { +if ((u64 )ins->code.offset + code->size >DSP_CODE_BYTE_SIZE /4 ) {dev_err (chip->card->dev,"dsp_spos: no space available in DSP\n" );return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1103/3318 platform/x86: hp-bioscfg: fix OOB reads in hp_get_string_from_buffer()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit 176b38b84ae5e075850b3ebb25f906d66f95a46d ]
The escape prescan loop uses 'size' as both its bound and its accumulator, so each escape character found extends the loop and reads past the end of src[].
Use the original u16 count as the loop bound. Also include the 2-byte length prefix in the bounds check, pass the u16 count instead of the byte count to utf16s_to_utf8s(), and advance the buffer by the bytes actually consumed instead of the escape-inflated count.
Tested on HP EliteBook 840 G2 (Fedora 44, Linux 7.2.7).
--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +15 -11
@@ -54,8 +54,8 @@ int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer)int hp_get_string_from_buffer (u8 **buffer,u32 *buffer_size,char *dst,u32 dst_size) {u16 *src = (u16 *)*buffer; +u16 orig_size;u16 src_size; -u16 size;int i;int conv_dst_size;
@@ -63,17 +63,21 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_if (*buffer_size <sizeof (u16))return -EINVAL ; - src_size = *(src++); -/* size value in u16 chars */ - size = src_size /sizeof (u16); + src_size = *src; -/* Ensure there is enough space remaining to read and convert -* the string +/* +* Ensure there is enough space remaining for the length prefix +* just read plus the string data it describes. */ -if (*buffer_size < src_size) +if (*buffer_size <sizeof (u16) + src_size)return -EINVAL ; -for (i =0 ; i < size; i++) + src++; +/* size value in u16 chars */ + orig_size = src_size /sizeof (u16); + size = orig_size; + +for (i =0 ; i < orig_size; i++) if (src[i] == '\\' || src[i] == '\r' || src[i] == '\n' ||
@@ -91,7 +95,7 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_/* * convert from UTF-16 unicode to ASCII */ -utf16s_to_utf8s (src, src_size,UTF16_HOST_ENDIAN , dst, conv_dst_size); +utf16s_to_utf8s (src, orig_size,UTF16_HOST_ENDIAN , dst, conv_dst_size); dst[conv_dst_size] =0 ;for (i =0 ; i < conv_dst_size; i++) {
@@ -117,8 +121,8 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ src++; } - *buffer = (u8 *)src; - *buffer_size -= size *sizeof (u16); + *buffer +=sizeof (u16) + src_size; + *buffer_size -=sizeof (u16) + src_size;return size; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1104/3318 platform/x86: hp-bioscfg: fix non-ASCII truncation in hp_get_string_from_buffer()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit 6b8d2374b32c35efa2a431b3cd2fe346f8917dcc ]
utf16s_to_utf8s() writes into dst, but the loop that follows overwrites dst from the raw UTF-16 code units with truncating casts, so any character above U+007F is mangled. For example, U+00E9 is stored as 0xe9 instead of 0xc3 0xa9.
Convert into a scratch buffer first, then escape '\\', '\r', '\n' and '\t' into dst with string_escape_mem(). Quotes are not escaped, so the existing strreplace() still handles them.
Tested on HP EliteBook 840 G2 (Fedora 44, Linux 7.2.7).
--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 62 +++++--------------- 1 file changed, 14 insertions(+), 48 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +14 -48
@@ -11,7 +11,7 @@#include <linux/module.h> #include <linux/kernel.h> #include <linux/printk.h> -#include <linux/string.h> +#include <linux/string_helpers.h> #include <linux/wmi.h> #include "bioscfg.h" #include "../../firmware_attributes_class.h"
@@ -53,12 +53,12 @@ int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer)int hp_get_string_from_buffer (u8 **buffer,u32 *buffer_size,char *dst,u32 dst_size) { +char utf8_buf[MAX_BUFF_SIZE ];u16 *src = (u16 *)*buffer; +int escaped_len;u16 orig_size;u16 src_size; -u16 size; -int i; -int conv_dst_size; +int utf8_len;if (*buffer_size <sizeof (u16))return -EINVAL ;
@@ -75,56 +75,22 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ src++;/* size value in u16 chars */ orig_size = src_size /sizeof (u16); - size = orig_size; - -for (i =0 ; i < orig_size; i++) -if (src[i] =='\\' || - src[i] =='\r' || - src[i] =='\n' || - src[i] =='\t' ) - size++; -/* -* Conversion is limited to destination string max number of -* bytes. -*/ - conv_dst_size = size; -if (size >= dst_size) - conv_dst_size = dst_size -1 ; + utf8_len =utf16s_to_utf8s (src, orig_size,UTF16_HOST_ENDIAN , + utf8_buf,sizeof (utf8_buf)); -/* -* convert from UTF-16 unicode to ASCII -*/ -utf16s_to_utf8s (src, orig_size,UTF16_HOST_ENDIAN , dst, conv_dst_size); - dst[conv_dst_size] =0 ; - -for (i =0 ; i < conv_dst_size; i++) { -if (*src =='\\' || - *src =='\r' || - *src =='\n' || - *src =='\t' ) { - dst[i++] ='\\' ; -if (i == conv_dst_size) -break ; - } - -if (*src =='\r' ) - dst[i] ='r' ; -else if (*src =='\n' ) - dst[i] ='n' ; -else if (*src =='\t' ) - dst[i] ='t' ; -else if (*src =='"' ) - dst[i] ='\'' ; -else - dst[i] = *src; - src++; - } + escaped_len =string_escape_mem (utf8_buf, utf8_len, dst, dst_size -1 , +ESCAPE_SPACE |ESCAPE_SPECIAL , +"\\\r\n\t" ); +if (escaped_len > dst_size -1 ) + escaped_len = dst_size -1 ; + dst[escaped_len] ='\0' ; +strreplace (dst,'"' ,'\'' ); *buffer +=sizeof (u16) + src_size; *buffer_size -=sizeof (u16) + src_size; -return size; +return escaped_len; } int hp_get_common_data_from_buffer(u8 **buffer_ptr, u32 *buffer_size,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1105/3318 platform/x86: hp-bioscfg: return -E2BIG from validate_password_input()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit a4f19c589b21e18567d3c0ac7b9294f81e29b1de ]
validate_password_input() returns the positive INVALID_BIOS_AUTH on rejection. store_password_instance() skips the store on nonzero ret, but its final "return ret < 0 ? ret : count" treats the positive value as success, so userspace sees count instead of an error.
Return -E2BIG for an invalid password length.
Tested on HP EliteBook 840 G2 (Fedora 44, Linux 7.2.7): writing 999 bytes to current_password returned 999 before this change.
--- drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c +4 -3
@@ -71,12 +71,13 @@ static int validate_password_input(int instance_id, const char *buf) length--;if (length >MAX_PASSWD_SIZE ) -return INVALID_BIOS_AUTH ; +return -E2BIG ;if (password_data->min_password_length > length || password_data->max_password_length < length) -return INVALID_BIOS_AUTH ; -return SUCCESS ; +return -E2BIG ; + +return 0 ; }ATTRIBUTE_N_PROPERTY_SHOW (is_enabled, password);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1106/3318 platform/x86: hp-bioscfg: allow clearing current_password
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit acada379d5c4dd3a86d48fc69802e769eff29f7e ]
The ABI documents echo "" > current_password as the way to end a session, but validate_password_input() rejects an empty string when min_password_length is nonzero, so the password stays cached.
Skip the length check for an empty current_password so the write clears it.
Compile tested only.
--- .../platform/x86/hp/hp-bioscfg/passwdobj-attributes.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c +7 -2
@@ -61,7 +61,8 @@ int hp_get_password_instance_for_type(const char *name)return -EINVAL ; } -static int validate_password_input (int instance_id,const char *buf) +static int validate_password_input (int instance_id,const char *buf, +bool is_current) {int length;struct password_data *password_data = &bioscfg_drv.password_data[instance_id];
@@ -70,6 +71,10 @@ static int validate_password_input(int instance_id, const char *buf)if (length >0 && buf[length -1 ] =='\n' ) length--; +/* An empty current_password clears the session password */ +if (is_current && !length) +return 0 ; +if (length >MAX_PASSWD_SIZE )return -E2BIG ;
@@ -98,7 +103,7 @@ static int store_password_instance(struct kobject *kobj, const char *buf, id =get_password_instance_id (kobj);if (id >=0 ) - ret =validate_password_input (id, buf_cp); + ret =validate_password_input (id, buf_cp, is_current); }if (!ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1107/3318 platform/x86: hp-bioscfg: NUL-terminate the SPM auth token
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit f2769668959f6411ac69e83080a240f8a8785e05 ]
auth_token_store() copies the token with kmemdup(), which does not NUL terminate it, but hp_calculate_security_buffer() and hp_populate_security_buffer() use it as a C string and read past the allocation.
A lone newline (echo > auth_token) is worse: kmemdup() of 0 bytes returns ZERO_SIZE_PTR, which passes the NULL checks, so a later attribute write passes it to strlen().
A userspace replica of the two helpers under ASan reports a heap buffer overflow in hp_calculate_security_buffer() for the unterminated token and a fault at address 0x10 for the lone newline, and is clean with this change.
The token is a string, so copy it with kstrndup(), which always NUL terminates and allocates at least one byte.
--- drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +1 -1
@@ -307,7 +307,7 @@ static ssize_t auth_token_store(struct kobject *kobj, length--;/* allocate space and copy current auth token */ - bioscfg_drv.spm_data.auth_token =kmemdup (buf, length,GFP_KERNEL ); + bioscfg_drv.spm_data.auth_token =kstrndup (buf, length,GFP_KERNEL );if (!bioscfg_drv.spm_data.auth_token) { ret = -ENOMEM ; goto exit_token;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1108/3318 serial: 8250_lpss: do not touch uninitialized line in ehl_serial_exit()
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 3e3ae95a3d84a6028f37a07ab7ad78bb14689f2e ]
lpss8250_probe() calls lpss->board->exit() on its error path. For the EHL board, that is ehl_serial_exit() and it does:
serial8250_get_port(lpss->data.line)->dma = NULL;
But when lpss8250_dma_setup() or serial8250_register_8250_port() fails, lpss->data.line was never assigned. As lpss is kzalloc()ed, line is 0 and ehl_serial_exit() clears the dma pointer of an unrelated port -- serial8250_ports[0], i.e. ttyS0, which is often the console.
Initialize lpss->data.line to -1 in probe and skip the clearing in ehl_serial_exit() if no port was registered.
--- drivers/tty/serial/8250/8250_lpss.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_lpss.c +4 -3
@@ -183,9 +183,8 @@ static int ehl_serial_setup(struct lpss8250 *lpss, struct uart_port *port)static void ehl_serial_exit (struct lpss8250 *lpss) { -struct uart_8250_port *up =serial8250_get_port (lpss->data.line); - - up->dma =NULL ; +if (lpss->data.line >=0 ) +serial8250_get_port (lpss->data.line)->dma =NULL ; }#ifdef CONFIG_SERIAL_8250_DMA
@@ -332,6 +331,8 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)return ret; lpss->board = (struct lpss8250_board *)id->driver_data; +/* for tests in lpss->board->exit() */ + lpss->data.line =-1 ;memset (&uart,0 ,sizeof (struct uart_8250_port ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1109/3318 serial: pmac_zilog: push received data to the port that received it
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tim Douglas <[email protected]>
[ Upstream commit f3dc727da3af64abc12b625bbf1eb68d55d882cc ]
pmz_interrupt() drains both channels but, since commit 2e124b4a390c ("TTY: switch tty_flip_buffer_push"), pushes the flip buffer of the port whose handler is running rather than the port that was drained. With both ports open, data received on the other port can be left in its flip buffer until something else pushes it, so its reader may not see it.
--- drivers/tty/serial/pmac_zilog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/pmac_zilog.c +2 -2
@@ -444,7 +444,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id) skip_a:spin_unlock (&uap_a->port.lock);if (push) -tty_flip_buffer_push (&uap->port.state->port); +tty_flip_buffer_push (&uap_a->port.state->port);if (!uap_b) goto out;
@@ -469,7 +469,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id) skip_b:spin_unlock (&uap_b->port.lock);if (push) -tty_flip_buffer_push (&uap->port.state->port); +tty_flip_buffer_push (&uap_b->port.state->port); out:return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1110/3318 ARM: 9488/1: smp: set current pointer in assembly before jumping into C
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 f6e551e7d515579b952422c93415470fb672d848 ]
With CONFIG_KCOV_INSTRUMENT_ALL=y, secondary CPUs fail to come online on ARMv6K/ARMv7 SMP:
CPU1: failed to boot: -38
The compiler inserts a call to __sanitizer_cov_trace_pc() at the entry of secondary_start_kernel(), before set_current(task). The KCOV hook dereferences current while TPIDRURO is still uninitialized, causing a data abort before cpu_init() has installed the exception stacks. The secondary CPU consequently never completes startup.
Initialize current in the secondary assembly handoff, as __mmap_switched already does for the boot CPU.
With current set in assembly, the set_current() call in secondary_start_kernel() is redundant. Drop it together with the function and the task argument. The hotplug resuscitate path in arch_cpu_idle_dead() needs no hand-off either, as smp_ops.cpu_die() can only return if the CPU kept its register state, TPIDRURO included.
--- arch/arm/include/asm/smp.h | 2 +- arch/arm/kernel/head-nommu.S | 1 + arch/arm/kernel/head.S | 1 + arch/arm/kernel/smp.c | 15 ++------------- 4 files changed, 5 insertions(+), 14 deletions(-)
arch/arm/include/asm/smp.h +1 -1
@@ -43,7 +43,7 @@ extern void set_smp_ipi_range(int ipi_base, int nr_ipi);* Called from platform specific assembly code, this is the * secondary CPU entry point. */ -asmlinkage void secondary_start_kernel(struct task_struct *task); +asmlinkage void secondary_start_kernel(void);/*
arch/arm/kernel/head-nommu.S +1 -0
@@ -116,6 +116,7 @@ ENTRY(secondary_startup) ldr r7, __secondary_data @ reload r7 ldr sp, [r7, #12] @ set up the stack pointer ldr r0, [r7, #16] @ set up task pointer + set_current r0, r1 mov fp, #0 b secondary_start_kernel ENDPROC(secondary_startup)
arch/arm/kernel/head.S +1 -0
@@ -442,6 +442,7 @@ ENTRY(__secondary_switched) adr_l r7, secondary_data + 12 @ get secondary_data.stack ldr sp, [r7] ldr r0, [r7, #4] @ get secondary_data.task + set_current r0, r1 mov fp, #0 b secondary_start_kernel ENDPROC(__secondary_switched)
arch/arm/kernel/smp.c +2 -13
@@ -371,12 +371,9 @@ void __noreturn arch_cpu_idle_dead(void)*/ __asm__("mov sp, %0\n" " mov fp, #0\n" -" mov r0, %1\n" " b secondary_start_kernel" : - :"r" (task_stack_page (current) +THREAD_SIZE -8 ), -"r" (current) - :"r0" ); + :"r" (task_stack_page (current) +THREAD_SIZE -8 ));unreachable (); }
@@ -397,23 +394,15 @@ static void smp_store_cpu_info(unsigned int cpuid)check_cpu_icache_size (cpuid); } -static void set_current (struct task_struct *cur) -{ -/* Set TPIDRURO */ - asm("mcr p15, 0, %0, c13, c0, 3" ::"r" (cur) :"memory" ); -} -/* * This is the secondary CPU boot entry. We're using this CPUs * idle thread stack, but a set of temporary page tables. */ -asmlinkage void secondary_start_kernel(struct task_struct *task) +asmlinkage void secondary_start_kernel(void) {struct mm_struct *mm = &init_mm;unsigned int cpu; -set_current (task); -secondary_biglittle_init ();/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1111/3318 ARM: 9491/1: alignment: restore uaccess state on emulation fault
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 80dafbcb705cead6d25cb821cf29c47da8860c8c ]
The alignment handlers enable access to user memory while emulating unaligned instructions. If a checked access faults, its exception table fixup jumps to the handler's fault label and bypasses uaccess_restore(). This leaves DOMAIN_USER as DOMAIN_CLIENT with SW domain PAN, or leaves TTBR0 page table walks enabled with TTBR0 PAN, while the fault is handled.
An ARM926 QEMU test using LDMIA across an unmapped page boundary reports DOMAIN_USER=1 at TYPE_FAULT before this change and DOMAIN_USER=0 after it. SW domain PAN is the default on ARMv5, ARMv6, and non-LPAE ARMv7 builds.
Keep the saved uaccess state at function scope and track whether it was saved. Restore it at the fault label only when needed. Paths that did not enable user access continue to skip the restore.
--- arch/arm/mm/alignment.c | 51 ++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-)
arch/arm/mm/alignment.c +37 -14
@@ -341,6 +341,8 @@ static int do_alignment_ldrhstrh(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd =RD_BITS (instr); +unsigned int ua_flags; +bool ua_saved = false; ai_half +=1 ;
@@ -364,10 +366,11 @@ do_alignment_ldrhstrh(unsigned long addr, u32 instr, struct pt_regs *regs) user:if (LDST_L_BIT (instr)) {unsigned long val; -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;get16t_unaligned_check (val, addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags);/* signed half-word? */ if (instr &0x40 )
@@ -375,14 +378,17 @@ do_alignment_ldrhstrh(unsigned long addr, u32 instr, struct pt_regs *regs) regs->uregs[rd] = val; }else { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;put16t_unaligned_check (regs->uregs[rd], addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }return TYPE_LDST ; fault: +if (ua_saved) +uaccess_restore (ua_flags);return TYPE_FAULT ; }
@@ -391,6 +397,8 @@ do_alignment_ldrdstrd(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd =RD_BITS (instr);unsigned int rd2; +unsigned int ua_flags; +bool ua_saved = false;int load;if ((instr &0xfe000000 ) ==0xe8000000 ) {
@@ -425,26 +433,30 @@ do_alignment_ldrdstrd(unsigned long addr, u32 instr, struct pt_regs *regs) user:if (load) {unsigned long val, val2; -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;get32t_unaligned_check (val, addr);get32t_unaligned_check (val2, addr +4 ); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); regs->uregs[rd] = val; regs->uregs[rd2] = val2; }else { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;put32t_unaligned_check (regs->uregs[rd], addr);put32t_unaligned_check (regs->uregs[rd2], addr +4 ); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }return TYPE_LDST ; bad:return TYPE_ERROR ; fault: +if (ua_saved) +uaccess_restore (ua_flags);return TYPE_FAULT ; }
@@ -452,6 +464,8 @@ static int do_alignment_ldrstr(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd =RD_BITS (instr); +unsigned int ua_flags; +bool ua_saved = false; ai_word +=1 ;
@@ -469,18 +483,22 @@ do_alignment_ldrstr(unsigned long addr, u32 instr, struct pt_regs *regs) trans:if (LDST_L_BIT (instr)) {unsigned int val; -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;get32t_unaligned_check (val, addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); regs->uregs[rd] = val; }else { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;put32t_unaligned_check (regs->uregs[rd], addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }return TYPE_LDST ; fault: +if (ua_saved) +uaccess_restore (ua_flags);return TYPE_FAULT ; }
@@ -502,6 +520,8 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd, rn, correction, nr_regs, regbits;unsigned long eaddr, newaddr; +unsigned int ua_flags; +bool ua_saved = false;if (LDM_S_BIT (instr)) goto bad;
@@ -547,7 +567,8 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs)#endif if (user_mode (regs)) { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;for (regbits =REGMASK_BITS (instr), rd =0 ; regbits; regbits >>=1 , rd +=1 )if (regbits &1 ) {
@@ -559,7 +580,7 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs)put32t_unaligned_check (regs->uregs[rd], eaddr); eaddr +=4 ; } -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }else {for (regbits =REGMASK_BITS (instr), rd =0 ; regbits; regbits >>=1 , rd +=1 )
@@ -581,6 +602,8 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs)return TYPE_DONE ; fault: +if (ua_saved) +uaccess_restore (ua_flags); regs->ARM_pc -= correction;return TYPE_FAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1112/3318 Bluetooth: btusb: Add device ID for Realtek RTL8761BUE (StarTech AV53C1)
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolaj Klitlund Børty <[email protected]>
[ Upstream commit 1430308fc9d47a801a305700cd444b1a0051d14a ]
Add the USB ID 0x14b0:0x047a for the StarTech AV53C1-USB-BLUETOOTH adapter, a Realtek RTL8761BUE based Bluetooth 5.3 dongle.
Without this entry btusb treats the device as a generic Bluetooth adapter and never loads the Realtek firmware, leaving the controller on its ROM firmware. In that state it advertises and scans actively, but never reports advertisements during passive scanning. LE connections initiated by the kernel wait for a passive-scan report before issuing LE Create Connection, so connecting and pairing from BlueZ time out without any error from the controller.
The same product is also sold with the ID 0x2c0a:0x8761, which is already supported.
lsusb -v output for the device:
Bus 001 Device 010: ID 14b0:047a StarTech.com Ltd. Bluetooth Radio Device Descriptor:
bcdUSB 1.10
bDeviceClass 224 Wireless
bDeviceSubClass 1 Radio Frequency
bDeviceProtocol 1 Bluetooth
idVendor 0x14b0 StarTech.com Ltd.
idProduct 0x047a
bcdDevice 2.00
iManufacturer 1 Realtek iProduct 2 Bluetooth Radio iSerial 3 00E04C239987 bNumInterfaces 2
Interface Descriptor:
bInterfaceClass 224 Wireless
bInterfaceSubClass 1 Radio Frequency
bInterfaceProtocol 1 Bluetooth
--- drivers/bluetooth/btusb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bluetooth/btusb.c +2 -0
@@ -771,6 +771,8 @@ static const struct usb_device_id quirks_table[] = { BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x37ad, 0x0600), .driver_info = BTUSB_REALTEK | BTUSB_WIDEBAND_SPEECH }, + { USB_DEVICE(0x14b0, 0x047a), .driver_info = BTUSB_REALTEK | + BTUSB_WIDEBAND_SPEECH }, /* Additional Realtek 8821AE Bluetooth devices */ { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1113/3318 Bluetooth: 6lowpan: Pin module for 6lowpan_control debugfs file
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bui Viet Dung <[email protected]>
[ Upstream commit 8368f0c2cde48c09ed70644059f24172b0c59f52 ]
An open debugfs file retains lowpan_control_fops in the debugfs proxy state. However, lowpan_control_fops has no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth_6lowpan module.
With CONFIG_BT_6LOWPAN=m, a userspace process can keep the debugfs file descriptor for 6lowpan_control open across module unload (delete_module / rmmod bluetooth_6lowpan). When the process subsequently closes the file descriptor, full_proxy_release() accesses the already freed and unmapped lowpan_control_fops table, causing a kernel page fault or oops.
The issue was discovered via manual code audit ofnet/bluetooth/6lowpan.c.
Set .owner = THIS_MODULE on lowpan_control_fops so that debugfs pins the module until all open file descriptors have finished.
--- net/bluetooth/6lowpan.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/6lowpan.c +1 -0
@@ -1200,6 +1200,7 @@ static int lowpan_control_open(struct inode *inode, struct file *file) }static const struct file_operations lowpan_control_fops = { + .owner =THIS_MODULE , .open = lowpan_control_open, .read = seq_read, .write = lowpan_control_write,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1114/3318 Bluetooth: hci_debugfs: Pin module for debugfs file operations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bui Viet Dung <[email protected]>
[ Upstream commit 2a3e2287877b1ee40ffb80b7d769b633866533f3 ]
An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, the file_operations defined in hci_debugfs.c (use_debug_keys_fops, sc_only_mode_fops, ssp_debug_mode_fops, force_bredr_smp_fops, force_static_address_fops, force_no_mitm_fops, dut_mode_fops, vendor_diag_fops, and the DEFINE_QUIRK_ATTRIBUTE macro) have no .owner set to THIS_MODULE.
As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth module. When a userspace process opens any of these debugfs files, a subsequent controller removal and module unload (rmmod bluetooth) can succeed while the file descriptor remains open.
When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release():
BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: <TASK> __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
The issue was discovered via manual code audit of net/bluetooth/hci_debugfs.c and verified on a Linux 7.3-rc6 test VM with CONFIG_BT=m.
Set .owner = THIS_MODULE on all debugfs file_operations tables in hci_debugfs.c so that debugfs keeps the module loaded until close has finished.
--- net/bluetooth/hci_debugfs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/bluetooth/hci_debugfs.c +9 -0
@@ -69,6 +69,7 @@ static ssize_t __name ## _write(struct file *file, \ } \ \ static const struct file_operations __name ## _fops = { \ + .owner =THIS_MODULE , \ .open = simple_open, \ .read = __name ## _read, \ .write = __name ## _write, \
@@ -287,6 +288,7 @@ static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf, }static const struct file_operations use_debug_keys_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = use_debug_keys_read, .llseek = default_llseek,
@@ -305,6 +307,7 @@ static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf, }static const struct file_operations sc_only_mode_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = sc_only_mode_read, .llseek = default_llseek,
@@ -441,6 +444,7 @@ static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf, }static const struct file_operations ssp_debug_mode_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = ssp_debug_mode_read, .llseek = default_llseek,
@@ -533,6 +537,7 @@ static ssize_t force_bredr_smp_write(struct file *file, }static const struct file_operations force_bredr_smp_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = force_bredr_smp_read, .write = force_bredr_smp_write,
@@ -782,6 +787,7 @@ static ssize_t force_static_address_write(struct file *file, }static const struct file_operations force_static_address_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = force_static_address_read, .write = force_static_address_write,
@@ -1185,6 +1191,7 @@ static ssize_t force_no_mitm_write(struct file *file, }static const struct file_operations force_no_mitm_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = force_no_mitm_read, .write = force_no_mitm_write,
@@ -1323,6 +1330,7 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf, }static const struct file_operations dut_mode_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = dut_mode_read, .write = dut_mode_write,
@@ -1379,6 +1387,7 @@ static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf, }static const struct file_operations vendor_diag_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = vendor_diag_read, .write = vendor_diag_write,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1115/3318 Bluetooth: L2CAP: Reject mode changes on connected channels
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
[ Upstream commit c1398cf11b31a94c27ed810ba69515e0df5ce379 ]
A peer can send a configuration response with an RFC option for another mode to a connected channel, for example to switch it from Streaming to ERTM mode. l2cap_parse_conf_rsp() then changes chan->mode, but l2cap_ertm_init() is not called again, so the ERTM sequence lists are never allocated. The next out-of-sequence I-frame makes l2cap_seq_list_clear() write through the NULL srej_list.list.
Refuse the channel when a response tries to change the mode of a connected channel.
--- net/bluetooth/l2cap_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +5 -1
@@ -3754,7 +3754,11 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, } } -if (chan->mode ==L2CAP_MODE_BASIC && chan->mode != rfc.mode) +/* A connected channel cannot change its mode, as the new mode would +* not be initialized. +*/ +if (chan->mode != rfc.mode && + (chan->mode ==L2CAP_MODE_BASIC || chan->state ==BT_CONNECTED ))return -ECONNREFUSED ; chan->mode = rfc.mode;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1116/3318 Bluetooth: L2CAP: Reject invalid TxWindow in configuration requests
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
[ Upstream commit c5ebb0245fe927cf5fa33510a9cb2799c4a2dd01 ]
A peer can send an ERTM RFC option with a TxWindow of zero, which is out of spec. It is stored in remote_tx_win unchanged and later passed to l2cap_seq_list_init(), where roundup_pow_of_two(0) is undefined. On some architectures this results in a ZERO_SIZE_PTR list and a remote kernel oops.
A TxWindow above 63 is out of spec as well. With 6-bit sequence numbers we would then send more unacknowledged frames than the sequence space can tell apart.
Reply with L2CAP_CONF_UNACCEPT and propose the default TxWindow instead of accepting the value, so remote_tx_win always stays within 1 to 63. Keep the parameters of an earlier request then, and do not treat the request as done because an earlier one was.
Also refuse a zero size in l2cap_seq_list_init(), so any other path that reaches it with a zero TxWindow fails the channel instead of the kernel.
--- net/bluetooth/l2cap_core.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
net/bluetooth/l2cap_core.c +27 -8
@@ -323,6 +323,10 @@ static int l2cap_seq_list_init(struct l2cap_seq_list *seq_list, u16 size) {size_t alloc_size, i; +/* roundup_pow_of_two(0) is undefined */ +if (!size) +return -EINVAL ; +/* Allocated size is a power of 2 to map sequence numbers * (which may be up to 14 bits) in to a smaller array that is * sized for the negotiated ERTM transmit windows.
@@ -3601,18 +3605,33 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t databreak ;case L2CAP_MODE_ERTM : -if (!test_bit (CONF_EWS_RECV , &chan->conf_state)) - chan->remote_tx_win = rfc.txwin_size; -else - rfc.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; - - chan->remote_max_tx = rfc.max_transmit; - size =min_t (u16,le16_to_cpu (rfc.max_pdu_size), chan->conn->mtu -L2CAP_EXT_HDR_SIZE -L2CAP_SDULEN_SIZE -L2CAP_FCS_SIZE ); rfc.max_pdu_size =cpu_to_le16 (size); - chan->remote_mps = size; + +/* The TxWindow must be within 1 to 63, otherwise +* propose the default one and keep the parameters of +* an earlier request. This overrides a PENDING result +* from the EFS check above, so the request is no +* longer pending, nor done if an earlier one was. +*/ +if (!rfc.txwin_size || + rfc.txwin_size >L2CAP_DEFAULT_TX_WINDOW ) { + result =L2CAP_CONF_UNACCEPT ; +clear_bit (CONF_LOC_CONF_PEND , &chan->conf_state); +clear_bit (CONF_OUTPUT_DONE , &chan->conf_state); + rfc.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; + remote_efs =0 ; + }else { +if (!test_bit (CONF_EWS_RECV , &chan->conf_state)) + chan->remote_tx_win = rfc.txwin_size; +else + rfc.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; + + chan->remote_max_tx = rfc.max_transmit; + chan->remote_mps = size; + }__l2cap_set_ertm_timeouts (chan, &rfc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1117/3318 Bluetooth: L2CAP: Use default TxWindow for zero socket option
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
[ Upstream commit 226fa3b676cbf2236f803bccd347462433ffc2c8 ]
L2CAP_OPTIONS accepts a txwin_size of zero and
stores it in tx_win. The zero is then sent to the
peer in our configuration request, and if the
channel ends up in ERTM mode it is passed tol2cap_seq_list_init().
Use the default TxWindow instead, as the mode can
still be changed to ERTM during configuration.
--- net/bluetooth/l2cap_sock.c | 4 ++++ 1 file changed, 4 insertions(+)
net/bluetooth/l2cap_sock.c +4 -0
@@ -803,6 +803,10 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,break ; } +/* A zero TxWindow is invalid, use the default instead */ +if (!opts.txwin_size) + opts.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; +if (!l2cap_valid_mtu (chan, opts.imtu)) { err = -EINVAL ;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1118/3318 cpufreq: schedutil: Serialize sugov_start() against rate limit updates
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
[ Upstream commit ce390caf5541c493c9061e7a2d98a463e66b736a ]
The current value of sg_policy->tunables->rate_limit_us is used in sugov_start() without locking to update sg_policy->freq_update_delay_ns, so if rate_limit_us_store() runs in parallel with it, the rate limit update may go unnoticed and the new freq_update_delay_ns value may be stale until the rate limit is updated again.
To avoid that, acquire the update_lock mutex of the rate limit sysfs attribute, that is held by rate_limit_us_store() during rate limit updates, around the freq_update_delay_ns in sugov_start().
--- kernel/sched/cpufreq_schedutil.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/sched/cpufreq_schedutil.c +13 -1
@@ -70,6 +70,18 @@ static void sugov_update_rate_limit_us(struct sugov_policy *sg_policy) (s64 )sg_policy->tunables->rate_limit_us *NSEC_PER_USEC ; } +static void sugov_update_rate_limit_us_sync (struct sugov_policy *sg_policy) +{ +/* +* Serialize with rate_limit_us_store() to prevent this path from using +* a stale rate limit tunable value to set the limit for the given +* policy. +*/ +guard (mutex)(&sg_policy->tunables->attr_set.update_lock); + +sugov_update_rate_limit_us (sg_policy); +} +static bool sugov_should_update_freq (struct sugov_policy *sg_policy,u64 time) {s64 delta_ns;
@@ -834,7 +846,7 @@ static int sugov_start(struct cpufreq_policy *policy)void (*uu)(struct update_util_data *data,u64 time,unsigned int flags);unsigned int cpu; -sugov_update_rate_limit_us (sg_policy); +sugov_update_rate_limit_us_sync (sg_policy); sg_policy->last_freq_update_time =0 ; sg_policy->next_freq =0 ; sg_policy->work_in_progress = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1119/3318 crypto: qat - initialise state_lock on every path in adf_devmgr_add_dev()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahsan Atta <[email protected]>
[ Upstream commit 4ad7c1bd5f3dcd3fd6efbb068d6ee2a68dddfece ]
state_lock is initialised at the end of adf_devmgr_add_dev(), but the VF on host path whose id mapping already exists returns earlier via 'goto unlock'. That mapping outlives the VF, so this path is taken every time a VF is recreated on a BDF that already hosted one, e.g.:
echo 0 > sriov_numvfs
echo 32 > sriov_numvfs
accel_dev is freshly allocated on each probe, so state_lock is left zeroed and adf_dev_up() takes an uninitialised mutex. With CONFIG_DEBUG_MUTEXES this is reported on a dh895xcc with 32 host-bound VFs:
DEBUG_LOCKS_WARN_ON(lock->magic != lock)
WARNING: kernel/locking/mutex.c:159 at mutex_lock+0x171/0x1c0 Call Trace: adf_dev_up+0x27/0xe0 [intel_qat] adf_probe+0x700/0xa80 [qat_dh895xccvf] local_pci_probe+0xd5/0x190
The same happens on teardown when adf_dev_down() locks it again.
Initialise the lock next to the other per-device state, before the tables are updated, so it is done on every path.
--- drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c +1 -1
@@ -137,6 +137,7 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,mutex_lock (&table_lock);atomic_set (&accel_dev->ref_count,0 ); +mutex_init (&accel_dev->state_lock);/* PF on host or VF on guest - optimized to remove redundant is_vf */ if (!accel_dev->is_vf || !pf) {
@@ -210,7 +211,6 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev, map->attached = true;list_add_tail (&map->list, &vfs_table); } -mutex_init (&accel_dev->state_lock); unlock:mutex_unlock (&table_lock);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1120/3318 irqchip/gic-v3-its: Dont clamp nvecs to zero when id_bits is 32
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 5a9d62555e7164ec79a5fe70153d79cf1fdfd614 ]
GITS_TYPER_IDBITS is five bits, so id_bits reaches 32 and min_t(unsigned int, ...) truncates BIT(32) to 0. nvecs becomes 0, its_lpi_alloc() rejects that, and its_msi_prepare() returns -ENOMEM. On 32-bit ARM the shift is undefined instead.
The clamp is correct for every value below the maximum, so only that one value is affected.
--- drivers/irqchip/irq-gic-v3-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -3416,7 +3416,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,* Also honor the ITS's own EID limit. */ id_bits =FIELD_GET (GITS_TYPER_IDBITS , its->typer) +1 ; - nvecs = min_t(unsigned int, nvecs, BIT(id_bits)); + nvecs =min_t (u64, nvecs,BIT_ULL (id_bits)); nr_ites =max (2 , nvecs); sz = nr_ites * (FIELD_GET (GITS_TYPER_ITT_ENTRY_SIZE , its->typer) +1 ); sz =max (sz,ITS_ITT_ALIGN ) +ITS_ITT_ALIGN -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1121/3318 irqchip/mchp-eic: Fix clock reference leak in mchp_eic_probe()
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 af9c707eb065a7d48eb92dc15acdb4346acf5db0 ]
of_clk_get_by_name() returns the clock with an elevated reference count that mchp_eic_probe() keeps for the lifetime of the driver, but none of the probe error paths drops it, so the reference is leaked whenever probe fails after the clock has been obtained.
Put the reference in the error cleanup. The clk_prepare_enable() failure path must jump there directly as it cannot call clk_disable_unprepare() on a clock that was never enabled.
--- drivers/irqchip/irq-mchp-eic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-mchp-eic.c +3 -1
@@ -228,7 +228,7 @@ static int mchp_eic_init(struct device_node *node, struct device_node *parent) ret =clk_prepare_enable (eic->clk);if (ret) - goto unmap; + goto clk_put;for (i =0 ; i <MCHP_EIC_NIRQ ; i++) {struct of_phandle_args irq;
@@ -264,6 +264,8 @@ static int mchp_eic_init(struct device_node *node, struct device_node *parent) clk_unprepare:clk_disable_unprepare (eic->clk); +clk_put: +clk_put (eic->clk); unmap:iounmap (eic->base); free:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1122/3318 ALSA: ump: Correct return size of fill_rpn()
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 85e8c5f933ee3dbc9d061e121237797e9fa05315 ]
The RPN/NRPN conversion in fill_rpn() is supposed to return the number of bytes of the resultant UMP packet, but it returns boolean values. This would result in the incorrect ump_bytes in the converter, which will confuse stream processing. Correct to the right value 8 as a MIDI 2.0 UMP packet.
--- sound/core/ump_convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/ump_convert.c +1 -1
@@ -323,7 +323,7 @@ static int fill_rpn(struct ump_cvt_to_ump_bank *cc, cc->cc_data_lsb);reset_rpn (cc); -return 1 ; +return 8 ; }/* convert to a MIDI 1.0 Channel Voice message */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1123/3318 gfs2: fix the escaped block copy in gfs2_before_commit()
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 1a4aeb6d6a08af1a2e2c52c84170561625819377 ]
Commit d68d0c6c3fc7 ("gfs2: Use memcpy_{from,to}_page where appropriate") made the escaped buffer copy read from the mempool page it had just allocated instead of from the buffer, so the block written to the log is whatever the pool page last held. If the journal is replayed after a crash, the block is restored from that and the file's data is corrupted. Only escaped buffers are affected: jdata blocks whose first four bytes match GFS2_MAGIC. Copy from the buffer's folio instead.
--- fs/gfs2/lops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/lops.c +3 -1
@@ -700,7 +700,9 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit, page =mempool_alloc (gfs2_page_pool,GFP_NOIO ); p =page_address (page); -memcpy_from_page (p, page,bh_offset (bd2->bd_bh), bd2->bd_bh->b_size); +memcpy_from_folio (p, bd2->bd_bh->b_folio, +bh_offset (bd2->bd_bh), + bd2->bd_bh->b_size); *(__be32 *)p =0 ;clear_buffer_escaped (bd2->bd_bh);unlock_buffer (bd2->bd_bh);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1124/3318 spi: jcore: fix divide-by-zero when speed_hz is zero
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 7db773075501248893c22b11bedc6745d6d0be45 ]
jcore_spi_baudrate() computes hw->clock_freq / 2 / speed without validating speed. The SPI core fills transfer.speed_hz from spi->max_speed_hz when it is zero, and jcore_spi_probe() never sets host->max_speed_hz, so the clamp in __spi_setup() is skipped. A spi_device created via the sysfs new_device interface (or a DT node without spi-max-frequency) therefore has max_speed_hz == 0, and any SPI_IOC_MESSAGE transfer reaches jcore_spi_baudrate() with speed == 0, causing a division by zero and a kernel panic.
Clamp speed to a minimum of 1 Hz before the division so the divisor is never zero. The computed divider then truncates to the register field width and the transfer simply runs at the slowest supported rate.
Verified by inspection of the __spi_setup() clamp and __spi_validate()'s speed_hz handling; the division-by-zero path requires the J-Core controller, which was not available.
--- drivers/spi/spi-jcore.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/spi/spi-jcore.c +2 -0
@@ -84,6 +84,8 @@ static void jcore_spi_baudrate(struct jcore_spi *hw, int speed) {if (speed == hw->speed_hz)return ; +if (speed <=0 ) + speed =1 ; hw->speed_hz = speed;if (speed >= hw->clock_freq /2 ) hw->speed_reg =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1125/3318 efi/libstub: Dont replace an existing LINUX_EFI_MEMRESERVE table
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit aaf3ed0f46298e18ec8bc477cf0a37478e41f2ea ]
The LINUX_EFI_MEMRESERVE table is the root of a linked list of memory reservations that need to persist across kexec, such as the GICv3 LPI pending and property tables, which cannot be moved once the redistributors have been enabled. Each kernel adds its own reservations to the list that it finds via the EFI configuration table, and honours the ones made by its predecessors.
The EFI stub installs a new, empty table unconditionally, replacing any existing one. This is fine on a cold boot, but not if the stub is being executed by a loader that passes on the configuration tables of an earlier kernel, e.g., a kexec loader that runs the incoming kernel's EFI stub, as the reservations made by earlier kernels would be lost.
So leave an existing table in place, and only install a new one if none exists yet.
--- drivers/firmware/efi/libstub/efi-stub.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/firmware/efi/libstub/efi-stub.c +8 -0
@@ -81,6 +81,14 @@ static void install_memreserve_table(void)efi_guid_t memreserve_table_guid =LINUX_EFI_MEMRESERVE_TABLE_GUID ;efi_status_t status; +/* +* If an earlier boot stage installed a memreserve table already, e.g., +* a kexec loader passing on the persistent reservations made by the +* previous kernel, use it as is: installing a new one would replace it. +*/ +if (get_efi_config_table (memreserve_table_guid)) +return ; + status =efi_bs_call (allocate_pool,EFI_LOADER_DATA ,sizeof (*rsv), (void **)&rsv);if (status !=EFI_SUCCESS ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1126/3318 KVM: arm64: Move OUTSIDE_GUEST_MODE publication past context being saved
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 1d4ce2901f1e25b06d447c0b02d105d6dd3550d8 ]
OUTSIDE_GUEST_MODE indicates to the rest of KVM that the vcpu has exited. So far, this is set as soon as we return from the notional hypervisor (which with VHE is just a function call away).
However, code that uses OUTSIDE_GUEST_MODE as a synchronisation point relies on the vcpu state to have been written back to the in-memory structures. Clearly, this is not what is happening.
Move the publication of OUTSIDE_GUEST_MODE to the point where the state is actually written, and give this write release semantics to ensure the correct ordering.
--- arch/arm64/kvm/arm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/arm64/kvm/arm.c +8 -2
@@ -969,12 +969,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)smp_store_mb (vcpu->mode,IN_GUEST_MODE );if (ret <=0 ||kvm_vcpu_exit_request (vcpu, &ret)) { - vcpu->mode =OUTSIDE_GUEST_MODE ;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 ;
@@ -991,7 +991,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) ret =kvm_arm_vcpu_enter_exit (vcpu); - vcpu->mode =OUTSIDE_GUEST_MODE ; vcpu->stat.exits++;/* * Back from guest
@@ -1023,6 +1022,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)kvm_arch_vcpu_ctxsync_fp (vcpu); +/* +* The state that was pushed into the CPU on entering +* the guest has been synchronised back, let's +* advertise we're outside of the guest. +*/ +smp_store_release (&vcpu->mode,OUTSIDE_GUEST_MODE ); +/* * We must ensure that any pending interrupts are taken before * we exit guest timing so that timer ticks are accounted as
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1127/3318 KVM: arm64: Turn vcpu->arch.pause into a counter
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 e64309198eda29415a95113def92aa40196cd422 ]
We have situations where we can call kvm_arm_halt_guest() without holding config_lock, which means that halt and resume can overlap in funny ways when called from separate contexts, and result in situations where a vcpu is resumed while other parts of KVM assume it is halted. Consequences are left to the imagination of the reader.
Fix this sorry situation by turning kvm_vcpu_arch::pause into an atomic counter, which makes the races described above harmless.
--- arch/arm64/include/asm/kvm_host.h | 7 +++---- arch/arm64/kvm/arm.c | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-)
arch/arm64/include/asm/kvm_host.h +3 -4
@@ -513,11 +513,10 @@ struct kvm_vcpu_arch {/* * Don't run the guest (internal implementation need). * -* Contrary to the flags above, this is set/cleared outside of -* a vcpu context, and thus cannot be mixed with the flags -* themselves (or the flag accesses need to be made atomic). +* Contrary to the flags above, this is updated outside of +* a vcpu context, and thus cannot be mixed with the flags. */ -bool pause; +atomic_t pause;/* * We maintain more than a single set of debug registers to support
arch/arm64/kvm/arm.c +12 -9
@@ -386,6 +386,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)kvm_arm_pvtime_vcpu_init (&vcpu->arch); vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; +atomic_set (&vcpu->arch.pause,0 ); err =kvm_vgic_vcpu_init (vcpu);if (err)
@@ -547,6 +548,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,return ret; } +static bool vcpu_can_run (struct kvm_vcpu *vcpu) +{ +return !kvm_arm_vcpu_stopped (vcpu) && !atomic_read (&vcpu->arch.pause); +} +/** * kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled * @v: The VCPU pointer
@@ -562,8 +568,7 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) (kvm_timer_should_notify_user (v) || kvm_pmu_should_notify_user(v))); -return ((irq_lines ||kvm_vgic_vcpu_pending_irq (v)) - && !kvm_arm_vcpu_stopped (v) && !v->arch.pause); +return ((irq_lines ||kvm_vgic_vcpu_pending_irq (v)) &&vcpu_can_run (v)); }bool kvm_arch_vcpu_in_kernel (struct kvm_vcpu *vcpu)
@@ -658,7 +663,7 @@ void kvm_arm_halt_guest(struct kvm *kvm)struct kvm_vcpu *vcpu;kvm_for_each_vcpu (i, vcpu, kvm) - vcpu->arch.pause = true; +atomic_inc (&vcpu->arch.pause);kvm_make_all_cpus_request (kvm,KVM_REQ_SLEEP ); }
@@ -668,8 +673,8 @@ void kvm_arm_resume_guest(struct kvm *kvm)struct kvm_vcpu *vcpu;kvm_for_each_vcpu (i, vcpu, kvm) { - vcpu->arch.pause = false; -__kvm_vcpu_wake_up (vcpu); +if (atomic_dec_and_test (&vcpu->arch.pause)) +__kvm_vcpu_wake_up (vcpu); } }
@@ -677,11 +682,9 @@ static void kvm_vcpu_sleep(struct kvm_vcpu *vcpu) {struct rcuwait *wait =kvm_arch_vcpu_get_wait (vcpu); -rcuwait_wait_event (wait, - (!kvm_arm_vcpu_stopped (vcpu)) && (!vcpu->arch.pause), -TASK_INTERRUPTIBLE ); +rcuwait_wait_event (wait,vcpu_can_run (vcpu),TASK_INTERRUPTIBLE ); -if (kvm_arm_vcpu_stopped (vcpu) || vcpu->arch.pause) { +if (!vcpu_can_run (vcpu)) {/* Awaken to handle a signal, request we sleep again later. */ kvm_make_request (KVM_REQ_SLEEP , vcpu); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1128/3318 spi: npcm-fiu: limit UMA data_size to the 16-byte staging buffer
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 f0be928a41384ea93c876364f360779f70359249 ]
npcm_fiu_uma_read() and npcm_fiu_uma_write() use a 16-byte on-stack staging buffer (u32 data_reg[4]) and move data_size bytes to or from it. data_size comes straight from op->data.nbytes, which is supplied by the SPI MEM operation and is not bounded by the driver:npcm_fiu_exec_op() only validates op->addr.nbytes, and no adjust_op_size callback truncates the transfer to the controller FIFO size.
A SPI MEM operation with addr.nbytes == 0 and data.nbytes > 16 therefore overflows data_reg[] on the kernel stack (write path) or reads past it (read path), corrupting the stack.
Reject data_size larger than the staging buffer in both UMA helpers by returning -EOPNOTSUPP, so spi_mem falls back to the generic SPI message path. The chunked path in npcm_fiu_manualwrite() always passes at most CHUNK_SIZE bytes, so it is unaffected.
--- drivers/spi/spi-npcm-fiu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/spi-npcm-fiu.c +8 -0
@@ -342,6 +342,10 @@ static int npcm_fiu_uma_read(struct spi_mem *mem,u32 val;u32 i; +/* data_reg holds at most 16 bytes */ +if (data_size >sizeof (data_reg)) +return -EOPNOTSUPP ; + regmap_update_bits(fiu->regmap, NPCM_FIU_UMA_CTS, NPCM_FIU_UMA_CTS_DEV_NUM, (spi_get_chipselect(mem->spi, 0) <<
@@ -397,6 +401,10 @@ static int npcm_fiu_uma_write(struct spi_mem *mem,u32 val;u32 i; +/* data_reg holds at most 16 bytes */ +if (data_size >sizeof (data_reg)) +return -EOPNOTSUPP ; + regmap_update_bits(fiu->regmap, NPCM_FIU_UMA_CTS, NPCM_FIU_UMA_CTS_DEV_NUM, (spi_get_chipselect(mem->spi, 0) <<
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1129/3318 mfd: tps65217: Fix NULL pointer dereference on IRQ init failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radiy Zhambakiev <[email protected]>
[ Upstream commit 0473a5b0663663b75573bf284beb77459e07c461 ]
tps65217_probe() ignores the return value of tps65217_irq_init(), so when the irq domain creation fails the probe still completes and the driver ends up bound with a NULL tps->irq_domain. Unloading the module then makes tps65217_remove() call irq_domain_remove() on the NULL pointer and oops the kernel. On top of that, irq_find_mapping() may fall back to the default irq domain and dispose of mappings that belong to other interrupt controllers.
Check the return value and abort the probe on failure so the error is reported and no inconsistent state is left for removal.
--- drivers/mfd/tps65217.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/tps65217.c +3 -1
@@ -333,7 +333,9 @@ static int tps65217_probe(struct i2c_client *client) }if (client->irq) { -tps65217_irq_init (tps, client->irq); + ret =tps65217_irq_init (tps, client->irq); +if (ret) +return ret; }else {int i;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1130/3318 mfd: tps65217: Check return value when masking interrupt sources
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radiy Zhambakiev <[email protected]>
[ Upstream commit 66ed12c1e5a986bee1dc63f9bd9c7f068138a69a ]
tps65217_irq_init() ignores the error returned by tps65217_set_bits() when masking all interrupt sources. A failed register write leaves the driver's software mask out of sync with the hardware and may result in spurious interrupts.
Check the return value and propagate the error to the caller.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/mfd/tps65217.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mfd/tps65217.c +6 -2
@@ -155,8 +155,12 @@ static int tps65217_irq_init(struct tps65217 *tps, int irq)/* Mask all interrupt sources */ tps->irq_mask =TPS65217_INT_MASK ; -tps65217_set_bits (tps,TPS65217_REG_INT ,TPS65217_INT_MASK , -TPS65217_INT_MASK ,TPS65217_PROTECT_NONE ); + ret =tps65217_set_bits (tps,TPS65217_REG_INT ,TPS65217_INT_MASK , +TPS65217_INT_MASK ,TPS65217_PROTECT_NONE ); +if (ret) { +dev_err (tps->dev,"Failed to mask interrupt sources: %d\n" , ret); +return ret; + } tps->irq_domain =irq_domain_add_linear (tps->dev->of_node,TPS65217_NUM_IRQ , &tps65217_irq_domain_ops, tps);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1131/3318 mfd: tps65217: Use devres for IRQ domain and wake teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radiy Zhambakiev <[email protected]>
[ Upstream commit cffd44d2d89524e2dda6adc7b0dd59363be1c8e6 ]
Removing the parent device used to tear the IRQ domain down in tps65217_remove() before the MFD children are unbound: the i2c core only releases the parent's devres after the remove callback returns, whereas devm_mfd_add_devices() registered its own devres action which unbinds the children. Children that requested interrupts from the domain (e.g. tps65217-charger) therefore call free_irq() on virtual IRQs whose descriptors have already been disposed. With CONFIG_SPARSE_IRQ free_irq() then returns early without stopping the threaded handler, leaking the irqaction, the IRQ kthread and a module reference.
Register the domain teardown as a devres action right after the domain is created instead. Devres actions are released in reverse order of registration, so the MFD children release their IRQs first, then the parent interrupt is freed and its thread stopped, and only then is the domain torn down. The same ordering covers probe failure, which no longer needs manual cleanup, and the remove callback can be dropped entirely.
Balance the enable_irq_wake() in tps65217_irq_init() by registering disable_irq_wake() as a devres action as well. Only do so when enabling actually succeeded, since the parent chip may not support setting wake-up.
--- drivers/mfd/tps65217.c | 57 +++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-)
drivers/mfd/tps65217.c +39 -18
@@ -146,6 +146,31 @@ static const struct irq_domain_ops tps65217_irq_domain_ops = { .map = tps65217_irq_map, }; +static void tps65217_irq_cleanup (void *data) +{ +struct tps65217 *tps = data; +unsigned int virq; + +if (!tps->irq_domain) +return ; + +for (int i =0 ; i <TPS65217_NUM_IRQ ; i++) { + virq =irq_find_mapping (tps->irq_domain, i); +if (virq) +irq_dispose_mapping (virq); + } + +irq_domain_remove (tps->irq_domain); + tps->irq_domain =NULL ; +} + +static void tps65217_irq_wake_disable (void *data) +{ +unsigned long irq = (unsigned long )data; + +disable_irq_wake (irq); +} +static int tps65217_irq_init (struct tps65217 *tps,int irq) {int ret;
@@ -169,6 +194,10 @@ static int tps65217_irq_init(struct tps65217 *tps, int irq)return -ENOMEM ; } + ret =devm_add_action_or_reset (tps->dev, tps65217_irq_cleanup, tps); +if (ret) +return ret; + ret =devm_request_threaded_irq (tps->dev, irq,NULL , tps65217_irq_thread,IRQF_ONESHOT ,"tps65217-irq" , tps);
@@ -178,7 +207,16 @@ static int tps65217_irq_init(struct tps65217 *tps, int irq)return ret; } -enable_irq_wake (irq); + ret =enable_irq_wake (irq); +if (ret) { +dev_warn (tps->dev,"failed to enable IRQ wake: %d\n" , ret); +return 0 ; + } + + ret =devm_add_action_or_reset (tps->dev, tps65217_irq_wake_disable, + (void *)(unsigned long )irq); +if (ret) +return ret;return 0 ; }
@@ -379,22 +417,6 @@ static int tps65217_probe(struct i2c_client *client)return 0 ; } -static void tps65217_remove (struct i2c_client *client) -{ -struct tps65217 *tps =i2c_get_clientdata (client); -unsigned int virq; -int i; - -for (i =0 ; i <TPS65217_NUM_IRQ ; i++) { - virq =irq_find_mapping (tps->irq_domain, i); -if (virq) -irq_dispose_mapping (virq); - } - -irq_domain_remove (tps->irq_domain); - tps->irq_domain =NULL ; -} -static const struct i2c_device_id tps65217_id_table[] = { {"tps65217" ,TPS65217 }, {/* sentinel */ }
@@ -408,7 +430,6 @@ static struct i2c_driver tps65217_driver = { }, .id_table = tps65217_id_table, .probe = tps65217_probe, - .remove = tps65217_remove, };static int __init tps65217_init (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1132/3318 ASoC: qcom: q6apm: reset the hw pointer with the fragment queue
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 0337b8129cf676b8eb767b2a1f312955760a5460 ]
On every prepare in queue mode, q6apm_dai_prepare() frees and allocates the fragments again, and q6apm_alloc_fragments() resets dsp_buf, so the first buffer queued after it is the first one of the ring. The hw pointer that q6apm_dai_pointer() reports is left as it was.
q6apm-dai used to keep its own position and cleared it in prepare. Since commit a93dad6f4e6a ("ASoC: q6apm-dai: make use of q6apm_get_hw_pointer") the position comes from the hw pointer, so a stream that is prepared again, e.g. to recover from an xrun, reports the position of the previous run until the DSP returns its first buffer, while ALSA has reset its own pointer to 0.
Reset the hw pointer together with dsp_buf.
--- sound/soc/qcom/qdsp6/q6apm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/qcom/qdsp6/q6apm.c +1 -0
@@ -223,6 +223,7 @@ int q6apm_map_memory_regions(struct q6apm_graph *graph, unsigned int dir, phys_amutex_lock (&graph->lock); data->dsp_buf =0 ; +atomic_set (&data->hw_ptr,0 );if (data->buf) {mutex_unlock (&graph->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1133/3318 spi: amd: fix len==0 underflow and FIFO overflow
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 e2f4edfc061e493fddde16c4bbe1c4f230f41e4a ]
amd_spi_fifo_xfer() unconditionally decrements xfer->len when a tx_buf is present. The SPI core does not reject zero-length transfers, so a transfer submitted through the SPI_IOC_MESSAGE ioctl with len == 0 and a tx_buf makes the u32 len wrap to 0xFFFFFFFF, and the following per-byte loop writes far past the FIFO window.
The driver also never checks the cumulative FIFO offset against AMD_SPI_FIFO_SIZE. The core splits each transfer down to the controller's max transfer size but does not bound the total message length, so a message of several transfers whose total exceeds the FIFO overflows it with out-of-bounds MMIO writes (tx) and reads (rx).
Skip zero-length transfers and reject any transfer that would run past the end of the FIFO window.
Tested with a user-space replica of the fifo_xfer length arithmetic (ASAN build): a zero-length transfer with tx_buf makes len-- wrap to 0xffffffff, and skipping zero-length transfers avoids the wrap. No AMD SPI hardware was available, so the FIFO bound check was verified by inspection against AMD_SPI_FIFO_SIZE.
--- drivers/spi/spi-amd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/spi/spi-amd.c +17 -0
@@ -284,11 +284,22 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,list_for_each_entry (xfer, &message->transfers, transfer_list) { +/* Skip zero-length transfers to avoid len underflow below */ +if (!xfer->len) +continue ; +if (xfer->speed_hz)amd_set_spi_freq (amd_spi, xfer->speed_hz);else amd_set_spi_freq (amd_spi, spi->max_speed_hz); +/* Reject transfers that would overflow the FIFO window */ +if (fifo_pos + xfer->len > +AMD_SPI_FIFO_BASE +AMD_SPI_FIFO_SIZE ) { + message->status = -EMSGSIZE ; + goto fin_msg; + } +if (xfer->tx_buf) { buf = (u8 *)xfer->tx_buf;if (!tx_len) {
@@ -331,6 +342,12 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,list_for_each_entry (xfer, &message->transfers, transfer_list)if (xfer->rx_buf) { +/* Reject transfers that would overflow the FIFO window */ +if (fifo_pos + xfer->len > +AMD_SPI_FIFO_BASE +AMD_SPI_FIFO_SIZE ) { + message->status = -EMSGSIZE ; + goto fin_msg; + } buf = (u8 *)xfer->rx_buf;/* Read data from FIFO to receive buffer */ for (i =0 ; i < xfer->len; i++)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1134/3318 spi: amd: validate FIFO usage before executing message
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 aed0c7475d6af333fb9b37848ed5e4f92a808ffa ]
The RX FIFO bound is checked in the drain loop, after amd_spi_execute_opcode(). A message whose cumulative RX length exceeds AMD_SPI_FIFO_SIZE can therefore issue an SPI transaction before being rejected.
Check tx_len + rx_len while walking the message and drop the drain-loop check. This validates the complete message before executing the command.
Tested with a user-space replica covering TX, RX and mixed messages at the 70/71-byte boundary. Oversized split-RX messages are now rejected without executing the command. No AMD SPI hardware was available.
--- drivers/spi/spi-amd.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/spi/spi-amd.c +10 -14
@@ -293,13 +293,6 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,else amd_set_spi_freq (amd_spi, spi->max_speed_hz); -/* Reject transfers that would overflow the FIFO window */ -if (fifo_pos + xfer->len > -AMD_SPI_FIFO_BASE +AMD_SPI_FIFO_SIZE ) { - message->status = -EMSGSIZE ; - goto fin_msg; - } -if (xfer->tx_buf) { buf = (u8 *)xfer->tx_buf;if (!tx_len) {
@@ -308,6 +301,10 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi, xfer->len--; } tx_len += xfer->len; +if (tx_len + rx_len >AMD_SPI_FIFO_SIZE ) { + message->status = -EMSGSIZE ; + goto fin_msg; + }/* Write data into the FIFO. */ for (i =0 ; i < xfer->len; i++)
@@ -317,8 +314,13 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi, }/* Store no. of bytes to be received from FIFO */ -if (xfer->rx_buf) +if (xfer->rx_buf) { rx_len += xfer->len; +if (tx_len + rx_len >AMD_SPI_FIFO_SIZE ) { + message->status = -EMSGSIZE ; + goto fin_msg; + } + } }if (!buf) {
@@ -342,12 +344,6 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,list_for_each_entry (xfer, &message->transfers, transfer_list)if (xfer->rx_buf) { -/* Reject transfers that would overflow the FIFO window */ -if (fifo_pos + xfer->len > -AMD_SPI_FIFO_BASE +AMD_SPI_FIFO_SIZE ) { - message->status = -EMSGSIZE ; - goto fin_msg; - } buf = (u8 *)xfer->rx_buf;/* Read data from FIFO to receive buffer */ for (i =0 ; i < xfer->len; i++)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1135/3318 erofs: use on-disk blkszbits for lz4 max pcluster bound
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gyokhan Kochmarla <[email protected]>
[ Upstream commit 90b7e4a7a16443d9f6807b5c1dde52074d9f74c0 ]
z_erofs_load_lz4_config() rejects a valid LZ4 image when the kernel's page size differs from the image's block size. It bounds the on-disk max_pclusterblks with erofs_blknr(sb, Z_EROFS_PCLUSTER_MAX_SIZE), which expands to Z_EROFS_PCLUSTER_MAX_SIZE >> sb->s_blocksize_bits.
At the point this runs, sb->s_blocksize_bits still holds PAGE_SHIFT:erofs_fc_fill_super() seeds s_blocksize_bits to PAGE_SHIFT before reading the superblock, and only corrects it down to the on-disk blkszbits after erofs_read_superblock() returns. The LZ4 config is parsed inside erofs_read_superblock(), before that correction, so the bound is computed with the wrong shift.
On a 64K-page kernel mounting a 4K-block image (e.g. one built with mkfs.erofs -C 262144 on a 4K-page host), the bound evaluates to 1 MiB >> 16 = 16 blocks instead of the correct 1 MiB >> 12 = 256 blocks. The image's legitimate max_pclusterblks of 64 then fails the check, mount returns -EINVAL, and booting from such an image as the root filesystem panics:
erofs (device dm-0): too large lz4 pclusterblks 64
Kernel panic - not syncing: VFS: Unable to mount root fs
sbi->blkszbits already holds the on-disk block size at this point, so compute the bound from it directly. This makes the check independent of the host page size and of superblock-parse ordering.
commit 3acea5fc3354 ("erofs: avoid hardcoded blocksize for subpage block support") already handled the same ordering hazard for the superblock checksum path by using sbi->blkszbits in erofs_superblock_csum_verify(); the lz4 config path was missed.
--- fs/erofs/decompressor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/decompressor.c +1 -1
@@ -34,7 +34,7 @@ static int z_erofs_load_lz4_config(struct super_block *sb,if (!sbi->lz4.max_pclusterblks) { sbi->lz4.max_pclusterblks =1 ;/* reserved case */ }else if (sbi->lz4.max_pclusterblks > -erofs_blknr (sb,Z_EROFS_PCLUSTER_MAX_SIZE )) { +Z_EROFS_PCLUSTER_MAX_SIZE >> sbi->blkszbits) {erofs_err (sb,"too large lz4 pclusterblks %u" , sbi->lz4.max_pclusterblks);return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1136/3318 dax: Return errors from dax_core_init()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianyun Gao <[email protected]>
[ Upstream commit 4da700e2cadf84a6e858391d5be51d64dcba080f ]
dax_core_init() returns success when either the character device number allocation or DAX bus registration fails, even though the error paths have already released the initialized resources.
For modular DAX, this allows the module to remain loaded despite failed initialization, leaving subsequent users and module removal to access resources that have already been released.
Return the error code from the failed operation so that module loading fails rather than reporting successful initialization after the resources have been released.
--- drivers/dax/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dax/super.c +1 -1
@@ -588,7 +588,7 @@ static int __init dax_core_init(void)unregister_chrdev_region (dax_devt,MINORMASK +1 ); err_chrdev:dax_fs_exit (); -return 0 ; +return rc; } static void __exit dax_core_exit(void)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1137/3318 dax: fix dax_range_compare_iter() to use correct size and address offset
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianyun Gao <[email protected]>
[ Upstream commit a4bfbfb4e98a62b589ac7ca9e73e9612bfe8cab7 ]
dax_range_compare_iter() has two bugs in how it calls dax_iomap_direct_access() and uses the returned addresses:
1. The size argument passed to dax_iomap_direct_access() is ALIGN(pos + len, PAGE_SIZE), which is an absolute file offset rather than a length. This causes the underlying dax_direct_access() to request a massively inflated nr_pages via PHYS_PFN(size).
2. The addresses returned by dax_iomap_direct_access() are page-aligned starting addresses, but memcmp() compares from saddr/daddr directly without adding the page-in-page offset of pos1/pos2. When pos1/pos2 are not page-aligned, this compares the wrong data.
Fix the size by computing ALIGN(len + offset_in_page(pos), PAGE_SIZE), matching the pattern used in dax_iomap_copy_around(). Fix the address by adding offset_in_page(pos1)/offset_in_page(pos2) to saddr/daddr in the memcmp() call.
--- fs/dax.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/dax.c +7 -5
@@ -2006,6 +2006,7 @@ static loff_t dax_range_compare_iter(struct iomap_iter *it_src,const struct iomap *dmap = &it_dest->iomap;loff_t pos1 = it_src->pos, pos2 = it_dest->pos;void *saddr, *daddr; +size_t size1, size2;int id, ret; len =min (len,min (smap->length, dmap->length));
@@ -2021,17 +2022,18 @@ static loff_t dax_range_compare_iter(struct iomap_iter *it_src, } id =dax_read_lock (); - ret =dax_iomap_direct_access (smap, pos1,ALIGN (pos1 + len,PAGE_SIZE ), - &saddr,NULL ); + size1 =ALIGN (len +offset_in_page (pos1),PAGE_SIZE ); + ret =dax_iomap_direct_access (smap, pos1, size1, &saddr,NULL );if (ret <0 ) goto out_unlock; - ret =dax_iomap_direct_access (dmap, pos2,ALIGN (pos2 + len,PAGE_SIZE ), - &daddr,NULL ); + size2 =ALIGN (len +offset_in_page (pos2),PAGE_SIZE ); + ret =dax_iomap_direct_access (dmap, pos2, size2, &daddr,NULL );if (ret <0 ) goto out_unlock; - *same = !memcmp (saddr, daddr, len); + *same = !memcmp (saddr +offset_in_page (pos1), + daddr +offset_in_page (pos2), len);if (!*same) len =0 ;dax_read_unlock (id);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1138/3318 net: skbuff: dont BUG() on a bad csum_start in skb_copy_and_csum_dev()
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 56453199d28f0072a8196fba14b2d702632e2219 ]
skb_copy_and_csum_dev() copies everything up to the checksum start out of the linear area, and BUG()s if the checksum start is past the end of the linear area. It misses the other direction: a CHECKSUM_PARTIAL skb that has been pulled past its csum_start gives a negative offset, which gets past the check and becomes a ~4GB copy. It also trusts csum_offset when it stores the folded checksum. So far skb_copy_and_csum_bits() BUG()ing on a short skb has covered for that, but once it returns instead, a bad csum_offset would write past the end of the caller's buffer.
The function returns void and its callers are drivers copying a frame into a bounce buffer just before handing it to the hardware. There's nothing for them to back out of, so check both ends of csum_start and that the checksum field fits in the frame, and if not, copy the whole frame with skb_copy_bits() without filling in the checksum, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The frame
goes out with a bad checksum and is dropped by the receiver. If even that copy fails, zero the buffer so the driver doesn't send stale bytes.
--- net/core/skbuff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/core/skbuff.c +12 -1
@@ -3665,7 +3665,18 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else csstart =skb_headlen (skb); -BUG_ON (csstart >skb_headlen (skb)); +if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + (skb->ip_summed ==CHECKSUM_PARTIAL && + csstart + skb->csum_offset +sizeof (__sum16) > + skb->len))) { +DEBUG_NET_WARN_ON_ONCE (1 ); +/* Send the frame without the checksum filled in, or send +* zeroes if we can't even copy it. +*/ +if (skb_copy_bits (skb,0 , to, skb->len)) +memset (to,0 , skb->len); +return ; + }skb_copy_from_linear_data (skb, to, csstart);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1139/3318 ipv6: defrag: orphan skb before queuing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zixuan Chai <[email protected]>
[ Upstream commit 5dfa91a5ec53cfbf907a1fca095ac3ac7a4e94c9 ]
IPv4 and nf_conntrack fragment queues orphan skbs before returning -EINPROGRESS, but ip6_frag_queue() leaves the socket association intact.
Commit 18685451fc4e ("inet: inet_defrag: prevent sk release while still in use") moved skb_orphan() into ip_frag_queue() and nf_ct_frag6_queue(), but missed ip6_frag_queue().
Without orphaning, inet_frag_reasm_finish() clears fp->sk on frag_list skbs but leaves fp->destructor set to sock_pfree. Freeing the reassembled skb then calls sock_pfree() with a NULL socket. A socket using SOCK_RCU_FREE may also be released while its fragment is queued, leaving a stale socket pointer; this is a second consequence of the same missing orphan.
Orphan the skb before returning -EINPROGRESS so the queued fragment no longer retains the socket association or destructor.
--- net/ipv6/reassembly.c | 1 + 1 file changed, 1 insertion(+)
net/ipv6/reassembly.c +1 -0
@@ -227,6 +227,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, }skb_dst_drop (skb); +skb_orphan (skb);return -EINPROGRESS ; insert_error:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1140/3318 sctp: hold transport reference across connect wait
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seung Min Shin <[email protected]>
[ Upstream commit 5bef8649bb9ac4b2a014bcc227202ebd2df824be ]
sctp_sendmsg_to_asoc() selects a transport before waiting for a new interleaved association to become established. sctp_wait_for_connect() drops the socket lock while sleeping.
While the lock is dropped, backlog processing can handle a COOKIE ACK and an ASCONF DEL-IP that removes the selected transport. sctp_assoc_rm_peer() then marks the transport dead and drops its association-owned reference. The transport can be freed through RCU before the send path resumes.
After the wait, the stale pointer is assigned to newly created DATA or I-DATA chunks and later dereferenced by sctp_outq_select_transport().
Hold a reference to the selected transport across sctp_wait_for_connect(). After the socket lock is reacquired, abort the send if the transport was marked dead. Callers without a selected transport pass NULL and retain their existing behavior.
--- net/sctp/socket.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
net/sctp/socket.c +19 -7
@@ -75,7 +75,8 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc,struct sctp_transport *transport, long *timeo_p, size_t msg_len);static int sctp_wait_for_packet (struct sock *sk,int *err,long *timeo_p); -static int sctp_wait_for_connect (struct sctp_association *,long *timeo_p); +static int sctp_wait_for_connect (struct sctp_association *, +struct sctp_transport *,long *timeo_p);static int sctp_wait_for_accept (struct sock *sk,long timeo);static void sctp_wait_for_close (struct sock *sk,long timeo);static void sctp_destruct_sock (struct sock *sk);
@@ -1244,7 +1245,7 @@ static int __sctp_connect(struct sock *sk, struct sockaddr *kaddrs, *assoc_id = asoc->assoc_id; timeo =sock_sndtimeo (sk, flags &O_NONBLOCK ); -return sctp_wait_for_connect (asoc, &timeo); +return sctp_wait_for_connect (asoc,NULL , &timeo); out_free: pr_debug("%s: took out_free path with asoc:%p kaddrs:%p err:%d\n",
@@ -1846,7 +1847,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,if (asoc->ep->intl_enable) { timeo =sock_sndtimeo (sk,0 ); - err =sctp_wait_for_connect (asoc, &timeo); + err =sctp_wait_for_connect (asoc, transport, &timeo);if (err || sk->sk_shutdown &RCV_SHUTDOWN ) { err = -ESRCH ; goto err;
@@ -1889,7 +1890,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,if (unlikely (wait_connect)) { timeo =sock_sndtimeo (sk, msg->msg_flags &MSG_DONTWAIT ); -sctp_wait_for_connect (asoc, &timeo); +sctp_wait_for_connect (asoc,NULL , &timeo); } err = msg_len;
@@ -9358,7 +9359,9 @@ static bool sctp_writeable(const struct sock *sk)/* Wait for an association to go into ESTABLISHED state. If timeout is 0, * returns immediately with EINPROGRESS. */ -static int sctp_wait_for_connect (struct sctp_association *asoc,long *timeo_p) +static int sctp_wait_for_connect (struct sctp_association *asoc, +struct sctp_transport *transport, +long *timeo_p) {struct sock *sk = asoc->base.sk;int err =0 ;
@@ -9367,12 +9370,16 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)pr_debug ("%s: asoc:%p, timeo:%ld\n" , __func__, asoc, *timeo_p); -/* Increment the association's refcnt. */ +/* Hold references while the socket lock is dropped. */ +if (transport) +sctp_transport_hold (transport);sctp_association_hold (asoc);for (;;) {prepare_to_wait_exclusive (&asoc->wait, &wait,TASK_INTERRUPTIBLE ); +if (transport && transport->dead) + goto do_transport_dead;if (!*timeo_p) goto do_nonblock;if (sk->sk_shutdown &RCV_SHUTDOWN )
@@ -9401,7 +9408,8 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) out:finish_wait (&asoc->wait, &wait); -/* Release the association's refcnt. */ +if (transport) +sctp_transport_put (transport);sctp_association_put (asoc);return err;
@@ -9420,6 +9428,10 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) do_nonblock: err = -EINPROGRESS ; goto out; + +do_transport_dead: + err = -EAGAIN ; + goto out; }static int sctp_wait_for_accept (struct sock *sk,long timeo)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1141/3318 RDS/IB: validate receive fragment completions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shubham Antil <[email protected]>
[ Upstream commit 65cf6863606b0507a7c3bd1711317e4f5d6b8b7e ]
rds_ib_process_recv() accounts every receive fragment as contributing min(i_recv_data_rem, RDS_FRAG_SIZE) bytes, regardless of the completion length. When a completion is shorter than the header-declared amount, receive accounting can advance beyond the payload supplied by the completion.
Only an IB_WC_RECV completion has the buffer layout expected by this receive path. Other successful completion opcodes must not be interpreted as ordinary receive completions.
Reject successful completions with any other opcode before processing their length. For ordinary receive completions, require enough payload to cover the amount accounted to the fragment before linking its page into the incoming message.
This is compatible with the current transmit paths. MSG_ZEROCOPY is restricted to RDS/TCP, while RDS/IB copied and page-vector messages use full-sized non-final scatterlist entries.
Found during an LLM-assisted source audit and validated under KMSAN with a malformed short receive completion.
--- net/rds/ib_recv.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/rds/ib_recv.c +12 -1
@@ -949,6 +949,12 @@ static void rds_ib_process_recv(struct rds_connection *conn, } } +if (data_len <min_t (u32, ic->i_recv_data_rem,RDS_FRAG_SIZE )) { +rds_ib_conn_error (conn, +"fragment shorter than header-declared length; forcing reconnect\n" ); + goto done; + } +list_add_tail (&recv->r_frag->f_item, &ibinc->ii_frags); recv->r_frag =NULL ;
@@ -1004,7 +1010,12 @@ void rds_ib_recv_cqe_handler(struct rds_ib_connection *ic,* event is processed. */ if (wc->status ==IB_WC_SUCCESS ) { -rds_ib_process_recv (conn, recv, wc->byte_len, state); +if (wc->opcode !=IB_WC_RECV ) +rds_ib_conn_error (conn, +"recv completion had unexpected opcode %u, disconnecting and reconnecting\n" , + wc->opcode); +else +rds_ib_process_recv (conn, recv, wc->byte_len, state); }else {/* We expect errors as the qp is drained during shutdown */ if (rds_conn_up (conn) ||rds_conn_connecting (conn))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1142/3318 mptcp: reset msk state on early connect failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quanye Yang <[email protected]>
[ Upstream commit 29afe67082b2d33ab2e90c56c337235d725f023f ]
mptcp_connect() can fall back before the subflow SYN is sent, for example when the netns is in an MPTCP blackhole, token allocation fails, or MD5SIG is in use. If the subsequent subflow connect() fails immediately (EAFNOSUPPORT, ENETUNREACH, ...), __inet_stream_connect() returns while the socket is still SS_UNCONNECTED and never calls ->disconnect(). This was reported by Clashiko [1].
The error path only dropped the token and moved the msk back to TCP_CLOSE. MPTCP_FALLBACK_DONE, allow_subflows and request_mptcp were left as after early fallback, so a later connect() on the same fd stayed TCP-only.
--- net/mptcp/protocol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +8 -1
@@ -3952,9 +3952,16 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)* subflow_finish_connect() */ if (unlikely (err)) { -/* avoid leaving a dangling token in an unconnected socket */ mptcp_token_destroy (msk);mptcp_set_state (sk,TCP_CLOSE ); + +spin_lock_bh (&msk->fallback_lock); + msk->allow_subflows = true; + msk->allow_infinite_fallback = true; +clear_bit (MPTCP_FALLBACK_DONE , &msk->flags); +spin_unlock_bh (&msk->fallback_lock); + +mptcp_subflow_ctx_reset (mptcp_subflow_ctx (ssk));return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1143/3318 ALSA: seq: oss: Skip events until fully initialized
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 68d4a6ea6cc6091a05836f783bc17d525d266d0b ]
When an OSS sequencer device is opened, it creates a sequencer port, then further initializes the internal states like a timer instance, etc. Since the sequencer port is published, an event can be already delivered, and this may hit unexpected event handling, which can eventually cause a NULL dereference (like the timer start/stop event triggered before the timer initialization).
For avoiding such a race, introduce a simple guard and skips the event processing until the port is fully initialized.
At releasing the device, in turn, clear this guard, so that any input events will be discarded during the teardown.
--- sound/core/seq/oss/seq_oss_device.h | 1 + sound/core/seq/oss/seq_oss_event.c | 3 +++ sound/core/seq/oss/seq_oss_init.c | 2 ++ 3 files changed, 6 insertions(+)
sound/core/seq/oss/seq_oss_device.h +1 -0
@@ -73,6 +73,7 @@ struct seq_oss_devinfo {int cseq;/* sequencer client number */ int port;/* sequencer port number */ int queue;/* sequencer queue number */ +bool initialized;struct snd_seq_addr addr;/* address of this device */
sound/core/seq/oss/seq_oss_event.c +3 -0
@@ -427,6 +427,9 @@ snd_seq_oss_event_input(struct snd_seq_event *ev, int direct, void *private_datastruct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private_data;union evrec *rec; +if (!dp || !smp_load_acquire (&dp->initialized)) +return 0 ;/* ignored */ +if (ev->type !=SNDRV_SEQ_EVENT_ECHO )return snd_seq_oss_midi_input (ev, direct, private_data);
sound/core/seq/oss/seq_oss_init.c +2 -0
@@ -263,6 +263,7 @@ snd_seq_oss_open(struct file *file, int level) client_table[dp->index] = dp; num_clients++; +smp_store_release (&dp->initialized, true);return 0 ;
@@ -408,6 +409,7 @@ snd_seq_oss_release(struct seq_oss_devinfo *dp) client_table[dp->index] =NULL ; num_clients--; +smp_store_release (&dp->initialized, false);snd_seq_oss_reset (dp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1144/3318 power: supply: generic-adc-battery: fix status with no supplier
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tim Douglas <[email protected]>
[ Upstream commit 8ae5a3f40045ff486826ed6b6a83e39a0f380073 ]
power_supply_am_i_supplied() returns -ENODEV when no registered power supply supplies the battery. generic-adc-battery's gab_work() tests this return value as a boolean, so -ENODEV takes the supplied branch and reports CHARGING, or NOT_CHARGING if the charge-finished GPIO is asserted, instead of DISCHARGING.
This was noticed while bringing up an out-of-tree Linux port to the
WikiReader: the driver reported CHARGING on a device powered by two AAA batteries with no charging hardware.
Only a positive return value indicates an online supplier, so treat zero and negative returns as discharging.
--- drivers/power/supply/generic-adc-battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/generic-adc-battery.c +1 -1
@@ -135,7 +135,7 @@ static void gab_work(struct work_struct *work) adc_bat = container_of(delayed_work, struct gab, bat_work); status = adc_bat->status; -if (!power_supply_am_i_supplied (adc_bat->psy)) +if (power_supply_am_i_supplied (adc_bat->psy) <=0 ) adc_bat->status =POWER_SUPPLY_STATUS_DISCHARGING ;else if (gab_charge_finished (adc_bat)) adc_bat->status =POWER_SUPPLY_STATUS_NOT_CHARGING ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1145/3318 alpha: handle VM_FAULT_HWPOISON in do_page_fault()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Turner <[email protected]>
[ Upstream commit 4bef20bbb9e02568a009efa4d404ce2621289be5 ]
do_page_fault() handles VM_FAULT_OOM, VM_FAULT_SIGSEGV and VM_FAULT_SIGBUS and then falls into BUG() for anything else in VM_FAULT_ERROR. VM_FAULT_HWPOISON and VM_FAULT_HWPOISON_LARGE are in that set, so a fault on a poisoned page takes down the kernel instead of delivering a signal.
Alpha does not select ARCH_SUPPORTS_MEMORY_FAILURE, so the machine check paths cannot produce these. UFFDIO_POISON can: it installs a poison PTE marker without any memory failure support, and a subsequent access returns VM_FAULT_HWPOISON. Registering an anonymous range with userfaultfd, poisoning it and reading it back reliably hits the BUG():
Kernel bug at arch/alpha/mm/fault.c:188
poison(50809): Kernel Bug 1
pc is at do_page_fault+0x4e8/0x550
ra is at do_page_fault+0xfc/0x550
The BUG() fires with mmap_read_lock() still held, so the faulting task is left unkillable in D state holding the lock, and shutdown stalls behind it. A UFFD_USER_MODE_ONLY userfaultfd is always allowed, so any local user can do this.
Deliver SIGBUS with BUS_MCEERR_AR instead, reporting the size of the poisoned area, as the other architectures do. That is the huge page size for VM_FAULT_HWPOISON_LARGE, which becomes reachable once alpha implements huge pages.
Tested on an UP1500 (EV68AL): the reproducer above now takes a SIGBUS and the kernel logs
poison[373]: hardware memory error at 0000020000030000 pc 00000200010007ec
with no oops, no wedged task and no taint.
A backport needs the show_signal_msg() call dropped, since alpha only has it since commit 9ca6af1aac40 ("alpha: select SYSCTL_EXCEPTION_TRACE").
--- arch/alpha/mm/fault.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
arch/alpha/mm/fault.c +19 -0
@@ -8,6 +8,7 @@#include <linux/sched/signal.h> #include <linux/kernel.h> #include <linux/mm.h> +#include <linux/hugetlb.h> #include <asm/io.h> #define __EXTERN_INLINE inline
@@ -89,6 +90,7 @@ do_page_fault(unsigned long address, unsigned long mmcsr,struct mm_struct *mm = current->mm;const struct exception_table_entry *fixup;int si_code =SEGV_MAPERR ; +unsigned int lsb;vm_fault_t fault;unsigned int flags =FAULT_FLAG_DEFAULT ;
@@ -161,6 +163,8 @@ do_page_fault(unsigned long address, unsigned long mmcsr, goto bad_area; else if (fault & VM_FAULT_SIGBUS) goto do_sigbus; + else if (fault & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE)) + goto do_sigbus_mceerr;BUG (); }
@@ -222,6 +226,21 @@ do_page_fault(unsigned long address, unsigned long mmcsr, goto no_context;return ; + do_sigbus_mceerr: +mmap_read_unlock (mm); +if (!user_mode (regs)) + goto no_context; +/* +* Report the size of the poisoned area, which for a hugetlb fault +* is the size of the huge page that could not be mapped. +*/ + lsb =PAGE_SHIFT ; +if (fault &VM_FAULT_HWPOISON_LARGE ) + lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); +show_signal_msg (regs, address,SIGBUS ,"hardware memory error" ); +force_sig_mceerr (BUS_MCEERR_AR , (void __user *) address, lsb); +return ; + do_sigsegv:force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1146/3318 alpha: run check_mmu_context() from finish_arch_post_lock_switch()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit 020d2e70b7538b66eee3c3480d2b8921fb182f0c ]
check_mmu_context() clears asn_lock and acts on need_new_asn, but it runs only as the tail of switch_to(), after alpha_switch_to() returns.
A newly forked user task never gets there: its first context switch resumes at ret_from_fork and reaches schedule_tail() without returning to the code following alpha_switch_to().
asn_lock is left set on that CPU, so the new user task can run with interrupts enabled while shootdown IPIs keep taking the deferred path. The handshake meant to complete those invalidations never runs.
New kernel threads also reach schedule_tail(), but context_switch() does not call switch_mm() for a task without an mm. They therefore do not set asn_lock in the first place and are not affected by this bug.
Move check_mmu_context() to finish_arch_post_lock_switch(), which is called by finish_task_switch() for both existing and newly created tasks. Drop the now redundant call from switch_to().
The hook runs after finish_lock_switch() releases the rq lock and enables interrupts. An IPI arriving before asn_lock is cleared retires the slot through flush_tlb_other(); an IPI arriving afterwards can flush directly, since PAL_swpctx has already installed the incoming context.
Set need_new_asn whether ev5_switch_mm() reuses or allocates an ASN. An IPI in that interval can zero either slot. Without this, the allocated case can return to user space with a live ASN but a zero context slot, which a later context-based shootdown shortcut could mistake for an inactive CPU. check_mmu_context() reloads only when the slot is zero.
Call the hook unconditionally. Alpha selects ARCH_NO_PREEMPT, and neither kthread_use_mm() nor sched_force_init_mm() sleeps between the direct switch and this hook. RCU_STRICT_GRACE_PERIOD can enable PREEMPT_COUNT, but cannot make those callers migrate there. Testing preemptible() would only leave asn_lock set in that configuration.
This requires the preceding direct-switch fix, "alpha: load the MMU context when switch_mm() switches the current task". It installs the borrowed context before kthread_use_mm() reaches this hook, so clearing asn_lock cannot expose a targeted invalidate against the wrong context.
--- arch/alpha/include/asm/mmu_context.h | 15 +++++++++++++-- arch/alpha/include/asm/switch_to.h | 1 - 2 files changed, 13 insertions(+), 3 deletions(-)
arch/alpha/include/asm/mmu_context.h +13 -2
@@ -152,8 +152,8 @@ ev5_switch_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm, next_mm->context[cpu] = mmc; }#ifdef CONFIG_SMP - else - cpu_data[cpu].need_new_asn = 1; +/* A deferred shootdown can also invalidate a newly allocated ASN. */ + cpu_data[cpu].need_new_asn =1 ;#endif /* Always update the PCB ASN. Another thread may have allocated
@@ -201,6 +201,17 @@ do { \#define check_mmu_context () do { } while(0)#endif +/* +* Also called from kthread_use_mm() with preemption enabled. Alpha has +* no kernel preemption, so the task is still on the CPU that ran +* switch_mm(). +*/ +#define finish_arch_post_lock_switch finish_arch_post_lock_switch +static inline void finish_arch_post_lock_switch (void ) +{ +check_mmu_context (); +} + __EXTERN_INLINE voidev5_activate_mm (struct mm_struct *prev_mm,struct mm_struct *next_mm) {
arch/alpha/include/asm/switch_to.h +0 -1
@@ -9,7 +9,6 @@ extern struct task_struct *alpha_switch_to(unsigned long, struct task_struct *);#define switch_to (P ,N ,L ) \ do { \ (L) = alpha_switch_to(virt_to_phys(&task_thread_info(N)->pcb), (P)); \ - check_mmu_context(); \ } while (0)#endif /* __ALPHA_SWITCH_TO_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1147/3318 alpha: only use a targeted tbi() when the target mm is really current
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit 0d92845ac5dbc79e4ac4810b33c673f4c1c227e3 ]
ipi_flush_tlb_page() gates a targeted tbi() on current->active_mm. tbi() acts on the address space context currently loaded on the CPU, so it is only guaranteed to reach an mm's translations when a thread of that mm is running there. current->active_mm is not sufficient: under lazy TLB an idle or kernel task keeps an mm as its active_mm while a different ASN is loaded, so the invalidate is issued against the wrong context and the stale entry can survive. Nothing retires the old ASN afterwards either, mm->context[cpu] still being valid, so the resuming thread can reuse it.
Test current->mm instead and otherwise fall back to flush_tlb_other(), which clears mm->context[cpu] and forces a fresh ASN at the next switch whatever is loaded now.
For an mm borrowed through kthread_use_mm(), patch 1 of this series installs the context before the task can take a shootdown IPI. The current->mm test therefore covers that case as well.
--- arch/alpha/kernel/smp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/alpha/kernel/smp.c +2 -1
@@ -673,7 +673,8 @@ ipi_flush_tlb_page(void *x)struct flush_tlb_page_struct *data = x;struct mm_struct * mm = data->mm; -if (mm == current->active_mm && !asn_locked ()) +/* A targeted tbi() needs a thread of MM to be current. */ +if (mm == current->mm && !asn_locked ())flush_tlb_current_page (mm, data->vma, data->addr);else flush_tlb_other (mm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1148/3318 alpha: invalidate the local context in flush_tlb_page()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit c0db730bf05eb3c10c1fae64b19f6913dce129fc ]
When the target mm is not the calling CPU's active_mm, flush_tlb_page() does nothing locally, and smp_call_function() reaches only the other CPUs. This CPU may still hold translations for the mm and can later reuse the old ASN together with them.
Add the missing else branch. flush_tlb_other() clears mm->context[cpu] so a fresh ASN is taken at the next switch. Add this before changing the current->active_mm test to current->mm: that change will also send lazy callers here, so their local invalidate must already be in place.
The uniprocessor implementations of flush_tlb_mm() and flush_icache_user_page() in asm/tlbflush.h and asm/cacheflush.h already contain exactly this branch.
--- arch/alpha/kernel/smp.c | 3 +++ 1 file changed, 3 insertions(+)
arch/alpha/kernel/smp.c +3 -0
@@ -701,6 +701,9 @@ flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)preempt_enable ();return ; } + }else { +/* smp_call_function() does not call back into this CPU. */ +flush_tlb_other (mm); } data.vma = vma;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1149/3318 alpha: fix the local TLB invalidate in flush_tlb_page()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit 32f4dd420d626f96128fcfeea2ab24760b4f21a6 ]
flush_tlb_page() invalidates the calling CPU itself before asking the others, and gates that on current->active_mm. For a non-executable vma that means a targeted tbi(2, addr), which acts on the context currently loaded and is only guaranteed to invalidate the intended translations when the target mm's context is the loaded one. A lazy active_mm does not establish that, so as in ipi_flush_tlb_page() the target mm's stale translations can survive, and nothing forces the old ASN to be retired afterwards.
Test current->mm instead. A lazy caller then takes the flush_tlb_other() branch added by the previous patch, retiring its local context. Adding that branch first preserves the local invalidate at every step, including on EV7 where a targeted tbi() against a foreign ASN appeared to work.
Which callers reach here with a foreign mm depends on the configuration. folio_mkclean(), from the writeback flusher kworker that has no mm of its own, accounted for about half the calls during writeback of a shared mapping and none at all on anonymous memory. Those counts were measured with CONFIG_COMPACTION=n: with COMPACTION=y, asm/pgtable.h overrides ptep_clear_flush() to call migrate_flush_tlb_page(), which rendezvouses with every CPU and handles the context itself, so folio_mkclean() does not reach this function.
--- arch/alpha/kernel/smp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/alpha/kernel/smp.c +2 -1
@@ -688,7 +688,8 @@ flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)preempt_disable (); -if (mm == current->active_mm) { +/* As in ipi_flush_tlb_page(): a targeted tbi() needs MM current. */ +if (mm == current->mm) {flush_tlb_current_page (mm, vma, addr);if (atomic_read (&mm->mm_users) <=1 ) {int cpu, this_cpu =smp_processor_id ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1150/3318 alpha: fix the local TLB invalidate in the UP flush_tlb_page()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit c825bf802a7a43fd302c879ef25c975e067a2e94 ]
The uniprocessor flush_tlb_page() in asm/tlbflush.h has the same wrong test as the SMP one: a targeted tbi() is only guaranteed to invalidate the intended translations when the target mm's context is loaded, but the gate is current->active_mm, which a lazily borrowed mm also satisfies.
Test current->mm instead. The else branch it falls to already exists here, so unlike the SMP side this is the whole fix. arch/alpha/kernel/smp.c is not built with CONFIG_SMP=n, so this is how the same defect reaches a uniprocessor, where the flusher kworker necessarily shares the only CPU with the writer.
--- arch/alpha/include/asm/tlbflush.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/alpha/include/asm/tlbflush.h +2 -1
@@ -120,7 +120,8 @@ flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) {struct mm_struct *mm = vma->vm_mm; -if (mm == current->active_mm) +/* A targeted tbi() needs a thread of MM to be current. */ +if (mm == current->mm)flush_tlb_current_page (mm, vma, addr);else flush_tlb_other (mm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1151/3318 alpha: invalidate the local context in flush_tlb_mm()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit 721bb7a129771f0ff9cef1dd5abfc106ef65feba ]
flush_tlb_mm() has the same caller-CPU omission that was fixed in flush_tlb_page(): when the target mm is not the calling CPU's active_mm nothing happens locally, and smp_call_function() handles only the other CPUs, so this CPU may later reuse the old ASN together with the translations it still holds.
The active_mm test itself is left alone here. That path calls flush_tlb_current(), which loads a fresh context through __load_new_mm_context() rather than issuing a targeted tbi() against whatever ASN happens to be loaded, so it does not depend on which context is current.
The uniprocessor implementation in asm/tlbflush.h already has the missing branch. Counted over a fork-heavy run, flush_tlb_mm() was entered with the mm not this CPU's active_mm 2934 times, and 632 times while otherwise idle.
The proposed Alpha hugetlb support routes hugetlb invalidations through flush_tlb_range(), which calls this function. Unmapping or migrating a hugetlb folio from another context will also need this local invalidate.
--- arch/alpha/kernel/smp.c | 3 +++ 1 file changed, 3 insertions(+)
arch/alpha/kernel/smp.c +3 -0
@@ -653,6 +653,9 @@ flush_tlb_mm(struct mm_struct *mm)preempt_enable ();return ; } + }else { +/* smp_call_function() does not call back into this CPU. */ +flush_tlb_other (mm); }smp_call_function (ipi_flush_tlb_mm, mm,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1152/3318 alpha: invalidate the local context in flush_icache_user_page()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit 4244c555ac440a445cc168f860b2677099d761f9 ]
flush_icache_user_page() has the same caller-CPU omission that the previous patch fixed in flush_tlb_mm(): when the target mm is not the calling CPU's active_mm nothing happens locally, and smp_call_function() handles only the other CPUs, so this CPU may later reuse the old ASN together with the translations it still holds.
This matters here in particular because the function exists for operating on another process's mappings: the comment above it describes setting breakpoints through ptrace, and access_remote_vm() reaches it through copy_to_user_page(). The calling CPU is therefore often running something other than the target mm.
As in flush_tlb_mm(), the uniprocessor implementation in asm/cacheflush.h already has the missing case.
No imb() is needed, here or in ipi_flush_icache_page(). Alpha's user-space I-cache flush works by allocating a new ASN rather than by invalidating the I-cache: the entries stay, but they are tagged with the old ASN and can no longer match. An imb() is only required when the ASN space wraps and numbers are reused, and __get_new_mm_context() already does one in that case.
--- arch/alpha/kernel/smp.c | 3 +++ 1 file changed, 3 insertions(+)
arch/alpha/kernel/smp.c +3 -0
@@ -762,6 +762,9 @@ flush_icache_user_page(struct vm_area_struct *vma, struct page *page,preempt_enable ();return ; } + }else { +/* smp_call_function() does not call back into this CPU. */ +flush_tlb_other (mm); }smp_call_function (ipi_flush_icache_page, mm,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1153/3318 alpha: do not clear remote MMU contexts in migrate_flush_tlb_page()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit 16266d50c51eb5eb98f1c345c5aa9ff359a305aa ]
After the on_each_cpu() rendezvous, migrate_flush_tlb_page() walks the other CPUs and zeroes their mm->context[cpu] when mm_users is at most one, described as mimicking flush_tlb_mm()'s mm_users<=1 optimization.
It is not one. flush_tlb_mm() tests mm_users before deciding whether to send the IPIs; here every CPU has already been visited and waited for, so nothing is saved. The callback has also just set each CPU's own slot correctly, so the loop only overwrites it, and does so while that CPU may still be running in the address space.
Remove it. The shootdown shortcuts in flush_tlb_mm(), flush_tlb_page() and flush_icache_user_page() clear remote slots too; once the next patch removes those as well, every runtime update of mm->context[cpu] is made by CPU cpu itself. That patch relies on the invariant when it reads those slots to decide whether a shootdown can be skipped, so this one is tagged for stable as its prerequisite.
--- arch/alpha/mm/tlbflush.c | 16 ---------------- 1 file changed, 16 deletions(-)
arch/alpha/mm/tlbflush.c +0 -16
@@ -90,22 +90,6 @@ void migrate_flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)*/ preempt_disable ();on_each_cpu (ipi_flush_mm_and_page, &d,1 ); - -/* -* mimic flush_tlb_mm()'s mm_users<=1 optimization. -*/ -if (atomic_read (&mm->mm_users) <=1 ) { - -int cpu, this_cpu; - this_cpu =smp_processor_id (); - -for (cpu =0 ; cpu <NR_CPUS ; cpu++) { -if (!cpu_online (cpu) || cpu == this_cpu) -continue ; -if (READ_ONCE (mm->context[cpu])) -WRITE_ONCE (mm->context[cpu],0 ); - } - }preempt_enable (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1154/3318 alpha: do not skip TLB shootdown IPIs for kthread-borrowed mms
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Magnus Lindholm <[email protected]>
[ Upstream commit fe221b7b2d3ecd042dd391f74ff6a6fdeb7c2038 ]
flush_tlb_mm(), flush_tlb_page() and flush_icache_user_page() skip the shootdown IPI when mm_users <= 1, on the assumption that no other CPU can be running the mm. A task that borrows an mm through kthread_use_mm() takes mmgrab() rather than mmget(), so it never appears in mm_users, and kthread_use_mm() may be handed an mm that is already the caller's active_mm and loaded on that CPU. Such a CPU was not only left without an IPI, its mm->context[cpu] was cleared from under it.
mm->context[cpu] is already the record of which CPUs hold an ASN for the mm. Test it rather than clearing it: take the shortcut only when no other CPU has one, and otherwise fall through to the IPI, which invalidates those CPUs properly. A CPU that merely ran the mm in the past also holds a context and now costs an IPI, which errs in the safe direction.
Change ipi_flush_tlb_mm(), ipi_flush_icache_page() and the migration callback ipi_flush_mm_and_page() to test current->mm, like ipi_flush_tlb_page(). A CPU that only retains the mm lazily then clears its own slot through flush_tlb_other(), rather than publishing a new ASN on every IPI or migration rendezvous. The migration callback still does its per-VA tbi() afterwards. Returning to the mm allocates a fresh ASN through ev5_switch_mm(), or through the direct-load path when kthread_use_mm() switches current's mm.
Once these historical slots are gone, the shortcut is available again if mm_users remains at most one and no other CPU has taken or kept a context. An explicit kthread_use_mm() borrower has current->mm set and still receives the invalidate it needs.
The caller-side tests in flush_tlb_mm() and flush_icache_user_page() remain current->active_mm. A kernel thread that flushes its lazily held mm can therefore publish its own context slot. Those branches also perform the shortcut check, which excludes the calling CPU's slot, so leave them unchanged. This is distinct from a remote lazy CPU keeping its slot populated through repeated callbacks.
Together with the preceding patch, dropping these clearing loops leaves every runtime write to mm->context[] targeting the writing CPU's own slot, so the array becomes a lockless publication of which CPUs may be using the mm, with a single writer per slot. Mark the two stores that are now observed from other CPUs; flush_tlb_other() already uses WRITE_ONCE(). The uniprocessor flush_icache_user_page() is left alone, as nothing reads another CPU's slot there, and init_new_context() runs before the mm is shared.
Order the slot reads after the page-table changes with smp_mb(). On the publishing CPU, the store in ev5_switch_mm() precedes the mb() in Alpha's arch_spin_unlock(), when finish_lock_switch() drops the rq lock. This relies on Alpha's unlock implementation, not a generic scheduler promise of a full barrier on unlock; document that reliance at the store. Also issue smp_mb() after publishing in __load_new_mm_context(), before loading and using the mm.
This covers every caller, including check_mmu_context(), which can publish a replacement after finish_lock_switch() has already run.
This requires the preceding removal of remote slot clearing from migrate_flush_tlb_page(). It also requires the stale-TLB series to set need_new_asn on both the reused and newly allocated ASN paths. Otherwise an IPI between finish_lock_switch() and check_mmu_context() can zero a new slot while asn_lock is set, and the task can return to user space with a live ASN that the shortcut cannot see.
--- arch/alpha/include/asm/mmu_context.h | 7 +++- arch/alpha/kernel/smp.c | 52 ++++++++++++++-------------- arch/alpha/mm/fault.c | 4 ++- arch/alpha/mm/tlbflush.c | 2 +- 4 files changed, 36 insertions(+), 29 deletions(-)
arch/alpha/include/asm/mmu_context.h +6 -1
@@ -149,7 +149,12 @@ ev5_switch_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm, mmc = next_mm->context[cpu];if ((mmc ^ asn) & ~HARDWARE_ASN_MASK ) { mmc =__get_new_mm_context (next_mm, cpu); - next_mm->context[cpu] = mmc; +/* +* Ordered before any user access through the mm by the +* mb() in arch_spin_unlock(), when finish_lock_switch() +* drops the rq lock. +*/ +WRITE_ONCE (next_mm->context[cpu], mmc); }#ifdef CONFIG_SMP /* A deferred shootdown can also invalidate a newly allocated ASN. */
arch/alpha/kernel/smp.c +26 -26
87 lines not on this page · raw message
arch/alpha/mm/fault.c +3 -1
@@ -46,7 +46,9 @@ __load_new_mm_context(struct mm_struct *next_mm)struct pcb_struct *pcb; mmc =__get_new_mm_context (next_mm,smp_processor_id ()); - next_mm->context[smp_processor_id ()] = mmc; +WRITE_ONCE (next_mm->context[smp_processor_id ()], mmc); +/* Publish the context before this CPU can access the mm. */ +smp_mb (); pcb = ¤t_thread_info ()->pcb; pcb->asn = mmc &HARDWARE_ASN_MASK ;
arch/alpha/mm/tlbflush.c +1 -1
@@ -66,7 +66,7 @@ static void ipi_flush_mm_and_page(void *x)struct tlb_mm_and_addr *d = x;/* Part 1: mm context side (Alpha uses ASN/context as a key mechanism). */ -if (d->mm == current->active_mm && !asn_locked ()) +if (d->mm == current->mm && !asn_locked ())__load_new_mm_context (d->mm);else flush_tlb_other (d->mm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1155/3318 ALSA: hda/via: Apply runtime PM workaround for ASUS X55A
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasiliy Kovalev <[email protected]>
[ Upstream commit f6e8d5ebde5ceb7d3c0eef6e9e4d82862b503ade ]
ASUS X55A requires the same workaround like other machines with VT1802, otherwise it loses the codec power on a few nodes and the sound stays silent.
--- sound/pci/hda/patch_via.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_via.c +1 -0
@@ -1044,6 +1044,7 @@ static const struct hda_fixup via_fixups[] = {static const struct hda_quirk vt2002p_fixups[] = {SND_PCI_QUIRK (0x1043 ,0x13f7 ,"Asus B23E" ,VIA_FIXUP_POWER_SAVE ),SND_PCI_QUIRK (0x1043 ,0x1487 ,"Asus G75" ,VIA_FIXUP_ASUS_G75 ), +SND_PCI_QUIRK (0x1043 ,0x1c33 ,"Asus X55A" ,VIA_FIXUP_POWER_SAVE ),SND_PCI_QUIRK (0x1043 ,0x8532 ,"Asus X202E" ,VIA_FIXUP_INTMIC_BOOST ),SND_PCI_QUIRK_VENDOR (0x1558 ,"Clevo" ,VIA_FIXUP_POWER_SAVE ), {}
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1156/3318 hwmon: (corsair-cpro) Make wait_input_report_lock IRQ safe
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanan Hasanov <[email protected]>
[ Upstream commit e4fdc82f55cf0e3d5df5c88278da5baa76a109d1 ]
ccp_raw_event() is the HID ->raw_event() callback and takes wait_input_report_lock with a plain spin_lock(). This callback can run in very different contexts depending on the transport: from process context (e.g. uhid, via a write() to /dev/uhid) with softirqs and interrupts enabled, and from URB completion, which is softirq context for HCDs using HCD_BH and hard interrupt context for HCDs that do not (e.g. OHCI, UHCI).
Taking the lock from process context with softirqs enabled while the same lock is also taken from softirq context can deadlock if the softirq interrupts the lock holder on the same CPU. Lockdep reports:
WARNING: inconsistent lock state inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
...
spin_lock include/linux/spinlock.h:347 [inline] ccp_raw_event+0x51/0x110 drivers/hwmon/corsair-cpro.c:161 __hid_input_report+0x41c/0x580 drivers/hid/hid-core.c:2175 hid_irq_in+0x492/0x710 drivers/hid/usbhid/hid-core.c:287 __usb_hcd_giveback_urb+0x378/0x540 drivers/usb/core/hcd.c:1657 dummy_timer+0xa91/0x4cc0 drivers/usb/gadget/udc/dummy_hcd.c:2023
For the same reason, the spin_lock_bh() in send_usb_cmd() is not sufficient when ccp_raw_event() is called from hard interrupt context.
Use spin_lock_irqsave() in ccp_raw_event(), since it may be called with interrupts already disabled, and spin_lock_irq() in send_usb_cmd(), which always runs in process context.
--- drivers/hwmon/corsair-cpro.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/hwmon/corsair-cpro.c +5 -4
@@ -128,9 +128,9 @@ static int send_usb_cmd(struct ccp_device *ccp, u8 command, u8 byte1, u8 byte2,* the raw event parsing and marked the ccp->wait_input_report * completion as done. */ -spin_lock_bh (&ccp->wait_input_report_lock); +spin_lock_irq (&ccp->wait_input_report_lock);reinit_completion (&ccp->wait_input_report); -spin_unlock_bh (&ccp->wait_input_report_lock); +spin_unlock_irq (&ccp->wait_input_report_lock); ret =hid_hw_output_report (ccp->hdev, ccp->cmd_buffer,OUT_BUFFER_SIZE );if (ret <0 )
@@ -149,15 +149,16 @@ static int send_usb_cmd(struct ccp_device *ccp, u8 command, u8 byte1, u8 byte2,static int ccp_raw_event (struct hid_device *hdev,struct hid_report *report,u8 *data,int size) {struct ccp_device *ccp =hid_get_drvdata (hdev); +unsigned long flags;/* only copy buffer when requested */ -spin_lock (&ccp->wait_input_report_lock); +spin_lock_irqsave (&ccp->wait_input_report_lock, flags);if (!completion_done (&ccp->wait_input_report)) {memcpy (ccp->buffer, data,min (IN_BUFFER_SIZE , size)); ccp->buffer_recv_size = size;complete_all (&ccp->wait_input_report); } -spin_unlock (&ccp->wait_input_report_lock); +spin_unlock_irqrestore (&ccp->wait_input_report_lock, flags);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1157/3318 netfilter: nf_reject: initialize IPCB at inet ingress
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 73a73d442f9986353fe284bd1b504d0313d0f153 ]
The inet ingress hook runs before ip_rcv_core() and ip6_rcv_core(), so neither IPCB nor IP6CB has been initialized when nft_reject_inet passes a packet to nf_send_unreach() or nf_send_unreach6(). skb->cb can therefore retain metadata from an earlier protocol layer.
For IPv4, icmp_send() treats IPCB(skb)->opt as parsed IPv4 options. Stale option offsets can make __ip_options_echo() copy an attacker-controlled length into its 40-byte reply option buffer and overflow the stack. On an unpatched v7.2-rc5 kernel, the IPv4 reproducer produced:
BUG: KASAN: stack-out-of-bounds in __ip_options_echo() Write of size 255
For IPv6, icmpv6_send() consumes IP6CB(skb) as parsed IPv6 metadata. It always uses iif for source selection and, when MIP6 is enabled, uses dsthao as an extension-header offset. These fields must not be stale.
For NF_INET_INGRESS, clear the address-family-specific control block and restore its input interface before constructing the ICMP error. This matches similar initialization normally performed by ip_rcv_core() and ip6_rcv_core().
--- net/ipv4/netfilter/nf_reject_ipv4.c | 5 +++++ net/ipv6/netfilter/nf_reject_ipv6.c | 5 +++++ 2 files changed, 10 insertions(+)
net/ipv4/netfilter/nf_reject_ipv4.c +5 -0
@@ -350,6 +350,11 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)if (!skb_valid_dst (skb_in) &&nf_reject_fill_skb_dst (skb_in) <0 )return ; +if (hook ==NF_INET_INGRESS ) { +memset (IPCB (skb_in),0 ,sizeof (*IPCB (skb_in))); +IPCB (skb_in)->iif = skb_in->skb_iif; + } +if (skb_csum_unnecessary (skb_in) || !nf_reject_verify_csum (skb_in, dataoff, proto)) {icmp_send (skb_in,ICMP_DEST_UNREACH , code,0 );
net/ipv6/netfilter/nf_reject_ipv6.c +5 -0
@@ -431,6 +431,11 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,if (hooknum ==NF_INET_LOCAL_OUT && skb_in->dev ==NULL ) skb_in->dev = net->loopback_dev; +if (hooknum ==NF_INET_INGRESS ) { +memset (IP6CB (skb_in),0 ,sizeof (*IP6CB (skb_in))); +IP6CB (skb_in)->iif = skb_in->skb_iif; + } +if (!skb_valid_dst (skb_in) &&nf_reject6_fill_skb_dst (skb_in) <0 )return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1158/3318 f2fs: flush SIT journal during filesystem resize
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenjie Qi <[email protected]>
[ Upstream commit a6ede405455106bf42164ec96fd84008c5aabdd9 ]
During a filesystem resize, SBI_IS_RESIZEFS prevents new SIT entries from being added to the journal and forces existing entries to the SIT area. However, f2fs_flush_sit_entries() returns early when there are no new dirty sentries, leaving existing journal entries behind.
After the main area shrinks, a later checkpoint can access a journal entry whose segment number is outside the new geometry and trigger f2fs_bug_on().
Only take the zero-dirty fast path when entries may be written back to the journal. This lets resize drain existing entries through remove_sits_in_journal() even when there are no new dirty sentries.
--- fs/f2fs/segment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/segment.c +1 -1
@@ -4315,7 +4315,7 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)down_write (&sit_i->sentry_lock); -if (!sit_i->dirty_sentries) +if (!sit_i->dirty_sentries && to_journal) goto out;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1159/3318 f2fs: fix submit accounting for IPU writeback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seongjae Jeong <[email protected]>
[ Upstream commit 6d1f622b9c069378cdb83088be2b15a9b480b8a3 ]
f2fs_write_cache_pages() uses the submitted count, which is set to fio.submitted in f2fs_write_single_data_page(), to update nwritten and decrement wbc->nr_to_write.
In the OPU path, f2fs_submit_page_write() sets fio->submitted to 1. However, in the IPU path, fio->submitted is never set and remains zero. As a result, successful IPU writes are not accounted for. This can cause asynchronous writeback to continue beyond its budget.
Set fio->submitted in f2fs_inplace_write_data() after a page is successfully merged into a bio or submitted, so that successful IPU writes are included in the writeback accounting.
--- fs/f2fs/segment.c | 1 + 1 file changed, 1 insertion(+)
fs/f2fs/segment.c +1 -0
@@ -3720,6 +3720,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)else err =f2fs_submit_page_bio (fio);if (!err) { + fio->submitted =1 ;f2fs_update_device_state (fio->sbi, fio->ino, fio->new_blkaddr,1 ); f2fs_update_iostat(fio->sbi, fio->page->mapping->host,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1160/3318 rtc: cmos: Disable ACPI RTC event before handling it
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit 3f67038df8b5cba07254d1cff60d73e988b49ab7 ]
Users of RTC_UIE_ON can stop receiving update interrupts when rtc-cmos handles alarms through ACPI. In one 50-run test, 40 runs passed and 10 timed out after receiving between one and four of five expected events.
The ACPI ff_rt_clk counter stopped at 218, exactly matching the number of events delivered to userspace, and reported:
218 STS disabled unmasked
rtc_handler() runs in the threaded ACPI SCI handler and calls cmos_interrupt(), which schedules rtc->irqwork. The work can run before rtc_handler() returns:
ACPI SCI thread rtc->irqwork
cmos_interrupt()
schedule_work()
__rtc_set_alarm()
rtc_wake_on()
acpi_clear_event()
acpi_disable_event()The SCI thread then disables the event that the worker enabled for the next alarm. That alarm sets its status while delivery remains disabled, so no update interrupt reaches userspace.
Clear and disable the current ACPI RTC event before cmos_interrupt() schedules the work. The worker can then enable the next event without the handler undoing it. With this ordering, 150 runs delivered all 750 events without a stall.
--- drivers/rtc/rtc-cmos.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/rtc-cmos.c +3 -3
@@ -757,7 +757,9 @@ static u32 rtc_handler(void *context)unsigned char rtc_intr;unsigned long flags; - +/* Quiesce this event before rtc->irqwork can arm the next one. */ +acpi_clear_event (ACPI_EVENT_RTC ); +acpi_disable_event (ACPI_EVENT_RTC ,0 );/* * Always update rtc irq when ACPI is used as RTC Alarm. * Or else, ACPI SCI is enabled during suspend/resume only,
@@ -780,8 +782,6 @@ static u32 rtc_handler(void *context) }pm_wakeup_hard_event (dev); -acpi_clear_event (ACPI_EVENT_RTC ); -acpi_disable_event (ACPI_EVENT_RTC ,0 );return ACPI_INTERRUPT_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1161/3318 platform/x86/amd/pmc: Fix RTC reference leak in amd_pmc_verify_czn_rtc()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Ke <[email protected]>
[ Upstream commit 22b9306f1fcf86f80b55f05f08d10a9951ba970a ]
amd_pmc_verify_czn_rtc() opens the RTC with rtc_class_open(), which takes both a device reference and a module reference on the RTC driver. The matching release is rtc_class_close(), and it is never called. Every return path after the device has been opened, the ones that return 0 as well as the ones that report an error, leaves both references behind, so each S0i3 suspend leaks them.
Release the reference with a __free() cleanup on the declaration, which covers every return path without adding labels.
rtc_class_close() does not accept a NULL argument, so the cleanup helper has to guard against one: rtc_class_open() may fail and the declaration still has to be cleaned up.
Found by code review.
--- drivers/platform/x86/amd/pmc/pmc.c | 5 +++-- include/linux/rtc.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/platform/x86/amd/pmc/pmc.c +3 -2
@@ -14,6 +14,7 @@#include <linux/acpi.h> #include <linux/bitfield.h> #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/debugfs.h> #include <linux/delay.h> #include <linux/dmi.h>
@@ -746,7 +747,6 @@ static int amd_pmc_wa_irq1(struct amd_pmc_dev *pdev)static int amd_pmc_verify_czn_rtc (struct amd_pmc_dev *pdev,u32 *arg) { -struct rtc_device *rtc_device;time64_t then, now, duration;struct rtc_wkalrm alarm;struct rtc_time tm;
@@ -762,7 +762,8 @@ static int amd_pmc_verify_czn_rtc(struct amd_pmc_dev *pdev, u32 *arg)if (pdev->major <64 || (pdev->major ==64 && pdev->minor <53 ))return 0 ; - rtc_device =rtc_class_open ("rtc0" ); + struct rtc_device *rtc_device __free(rtc_class_close) = +rtc_class_open ("rtc0" );if (!rtc_device)return 0 ; rc =rtc_read_alarm (rtc_device, &alarm);
include/linux/rtc.h +2 -0
@@ -13,6 +13,7 @@#define _LINUX_RTC_H_ +#include <linux/cleanup.h> #include <linux/types.h> #include <linux/interrupt.h> #include <linux/nvmem-provider.h>
@@ -198,6 +199,7 @@ extern void rtc_update_irq(struct rtc_device *rtc,extern struct rtc_device *rtc_class_open (const char *name);extern void rtc_class_close (struct rtc_device *rtc); +DEFINE_FREE(rtc_class_close, struct rtc_device *, if (_T) rtc_class_close(_T));extern int rtc_irq_set_state (struct rtc_device *rtc,int enabled);extern int rtc_irq_set_freq (struct rtc_device *rtc,int freq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1162/3318 hwmon: (sht3x) Return the consumed count for heater writes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baek Kyu, Kim <[email protected]>
[ Upstream commit 817ac527100c8e20684211eb919ffd6d875adc7a ]
heater_enable_store() returns the result of i2c_master_send(), which is the two-byte command length on success rather than the sysfs input count. This can report more bytes than were supplied, or a partial write for a fully processed input. For example, writing "on\n" returns two instead of three, so a caller retrying the remaining newline gets -EINVAL even though the heater command succeeded. Retrying the remainder of "off\n" can also send the heater-off command twice.
Return count after a complete command transfer. Preserve negative I2C errors and return -EIO for nonnegative incomplete transfers, so a zero-message transfer is not reported as a successful zero-byte write. Keep the existing boolean parsing, command selection and locking.
--- drivers/hwmon/sht3x.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/sht3x.c +4 -1
@@ -540,7 +540,10 @@ static ssize_t heater_enable_store(struct device *dev,mutex_unlock (&data->i2c_lock); -return ret; +if (ret !=SHT3X_CMD_LENGTH ) +return ret <0 ? ret : -EIO ; + +return count; }static int update_interval_read (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1163/3318 cgroup: fix cgroup.kill for exited thread group leader
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kir Kolyshkin <[email protected]>
[ Upstream commit da13e0e72a7329c95642c44b2d03d194ab071e04 ]
cgroup.kill does not work in case a process' thread group leader is gone but other threads are still running. This is because __cgroup_kill() only walks the thread group leaders and sends SIGKILL to each of them with send_sig(), which uses PIDTYPE_PID:
1. The exited leader is still listed by CSS_TASK_ITER_PROCS as long as the process has live threads, but a signal directed at a single exiting task never takes effect: complete_signal() does not look for another thread to deliver it to, and __send_signal_locked() now drops it altogether. The process keeps running.
2. The live threads of such a process can be migrated to another cgroup by writing any of their IDs to cgroup.procs, while the exited leader stays behind. The destination cgroup has no thread group leader to iterate, so writing to its cgroup.kill does nothing at all.
In both cases the cgroup stays populated after cgroup.kill, and a process inside a container can use this to survive the container being killed. This also works with a private PID namespace when the init of the container is the process, as the PID namespace is not torn down while init has live threads.
Case 1 can be fixed by using do_send_sig_info(..., PIDTYPE_TGID) instead of send_sig(), so that the signal is taken by a live thread even if the task found by the iterator is exiting. Note it was pointed out by Eric in [1] while reviewing v2 of cgroup.kill patchset, and v3 was meant to switch to it, but the change was only made in cgroup_post_fork(), leaving __cgroup_kill() with send_sig().
Case 2 can only be fixed by iterating over all threads, so this is what the fix also does. Once a thread group is being killed, its other threads are skipped since they already have a fatal signal pending.
I ran some performance checks and the added cost is ~60 ns per every thread on my laptop (and less than a millisecond for 10K threads), which seems low. The time to "populated 0" seems unchanged.
The issue was found in crun by Anthropic's OSS Scanner, and crun is getting a workaround for it [2] (which does what we needed to do before cgroup.kill was added).
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/containers/crun/pull/2351
--- kernel/cgroup/cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cgroup.c +2 -2
@@ -3976,7 +3976,7 @@ static void __cgroup_kill(struct cgroup *cgrp) cgrp->kill_seq++;spin_unlock_irq (&css_set_lock); -css_task_iter_start (&cgrp->self,CSS_TASK_ITER_PROCS |CSS_TASK_ITER_THREADED , &it); +css_task_iter_start (&cgrp->self,CSS_TASK_ITER_THREADED , &it);while ((task =css_task_iter_next (&it))) {/* Ignore kernel threads here. */ if (task->flags &PF_KTHREAD )
@@ -3986,7 +3986,7 @@ static void __cgroup_kill(struct cgroup *cgrp)if (__fatal_signal_pending (task))continue ; -send_sig (SIGKILL , task,0 ); +do_send_sig_info (SIGKILL ,SEND_SIG_NOINFO , task,PIDTYPE_TGID ); }css_task_iter_end (&it); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1164/3318 netdevsim: reject cls_bpf programs bound to another device
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 5820ca58b409402505b9e904d1ded4908e0b6b81 ]
The issue:nsim_bpf_setup_tc_block_cb() installs any device-bound SCHED_CLS program without checking that its offload device matches the target netdev. The core cls_bpf attach path rejects a mismatching program, but a netdev that joins a shared block later is replayed the stored filter by cls_bpf_reoffload() before it is inserted into block->ports, so the attach-time check cannot see it. The driver callback is the authoritative per-device acceptance boundary and must enforce the match itself, as nfp already does in nfp_net_bpf_offload().
Without the check, replaying a device-bound program onto a different bpf_offload_dev installs it into that device's netdevsim state, which trips the WARN in nsim_bpf_uninit() (ns->bpf_offloaded set on a foreign device) and can dereference a NULL prog->aux->offload in nsim_prog_set_loaded().
The Fix:
Reject a device-bound program whose offload device does not match the target netdev, with -EINVAL and an extack so the rejected replay is not silent. The check is intentionally narrower than nfp's: it fires only for a dev-bound program, so nsim's bpf_tc_non_bound_accept mode (which admits an unbound program onto the device) is unaffected. Teardown is never blocked: the guard is on the program being installed and an unbind passes cls_bpf.prog = NULL.
Conditions to recreate the bug:
- CONFIG_NETDEVSIM=y, CONFIG_NET_CLS_BPF=y
- load and pin a dev-bound SCHED_CLS program for netdevsim device B
- install the program on a shared block owned by B
- add an independently backed netdevsim device C to that block; the bind replays the filter to C's callback, and C's ports/0/bpf_offloaded_id takes the B-bound program id.
The reported Sashiko review is at
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]
--- drivers/net/netdevsim/bpf.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/netdevsim/bpf.c +11 -0
@@ -150,6 +150,17 @@ int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,return -EOPNOTSUPP ; } +/* A dev-bound program can be replayed here when a netdev joins +* a shared block, after the core attach-time check has run; +* enforce the device match as nfp does. +*/ +if (prog &&bpf_prog_is_dev_bound (prog->aux) && + !bpf_offload_dev_match (prog, ns->netdev)) { +NSIM_EA (cls_bpf->common.extack, +"program bound to a different device" ); +return -EINVAL ; + } +if (cls_bpf->command !=TC_CLSBPF_OFFLOAD )return -EOPNOTSUPP ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1165/3318 net: gro: dont chain linear parts larger than gso_size into frag_list
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sorah Fukumori <[email protected]>
[ Upstream commit 679f6929a66db9f5a6611dad37545fbd705962d5 ]
skb_gro_receive() chains an skb into the frag_list of the held packet when its payload cannot be attached as page frags: when its head is not a page fragment and still holds payload, or when its head and frags would overflow the frags[] array of the last packet. Since commit 5eddb24901ee ("gro: add support of (hw)gro packets to gro stack"), that skb may itself be a GSO packet whose linear part holds several gso_size segments. skb_segment() cannot split the linear part of a frag_list member across segments, so segmenting the aggregate in software, e.g. when forwarding it to a device without NETIF_F_FRAGLIST, hits
BUG_ON(skb_headlen(list_skb) > len);
Fully linear GSO packets come from generic XDP. When the program does not support frags, netif_skb_check_for_xdp() linearizes any nonlinear skb with pskb_expand_head() and skb_linearize() and keeps its GSO metadata. GRO on the device runs before generic XDP, so each aggregate passed by the program carries all of its payload in a kmalloc'ed head. A tunnel that decapsulates these packets and runs GRO again through gro_cells then builds the bad frag_list. This was first seen on a router that forwards TCP received over VXLAN, with a non-frags XDP program attached in SKB mode to the underlying bond because one slave lacks native XDP:
kernel BUG at net/core/skbuff.c:4917!
RIP: 0010:skb_segment+0xbb6/0xf40 Call Trace: tcp_gso_segment ipv6_gso_segment skb_mac_gso_segment __skb_gso_segment validate_xmit_skb __dev_queue_xmit ip6_output ip6_sublist_rcv_finish ipv6_list_rcv netif_receive_skb_list_internal gro_complete dev_gro_receive gro_receive_skb gro_cell_poll __napi_poll net_rx_action
It reproduces with three network namespaces: TCP sent over VXLAN on an IPv6 veth link to a router namespace that has an XDP_PASS program without frags support attached to the underlay veth in generic mode and GRO enabled on its VXLAN device, and forwards to a veth with tx-scatter-gather-fraglist disabled.
A program with frags support in generic mode gives similar packets. skb_pp_cow_data() rebuilds the skb with up to about a page of linear data in a page_pool head_frag and keeps the GSO metadata, so once frags[] is full the next such packet is chained through frag_list with more than gso_size bytes in its head as well.
Refuse the merge when the linear part to be chained exceeds the held packet's gso_size. tcp_gro_receive() then flushes the held packet and the skb starts a new GRO packet as its head, whose linear length skb_segment() handles.
--- net/core/gro.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/gro.c +4 -0
@@ -193,6 +193,10 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) } merge: +/* skb_segment() cannot split the linear part of a frag_list member. */ +if (unlikely (headlen > offset +skb_shinfo (p)->gso_size)) +return -E2BIG ; +/* sk ownership - if any - completely transferred to the aggregated packet */ skb->destructor =NULL ; skb->sk =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1166/3318 ALSA: compress: add missing OPEN-state gate to SET_METADATA
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 931f5714b7921290cd1a4742e185aeeae7270ee6 ]
snd_compr_set_metadata() calls stream->ops->set_metadata() straight after copy_from_user(), without ever checking runtime->state, even though the function's own comment says a parameter change should only be allowed once the stream has left the OPEN state. Every other metadata/param entry point in this file (SET_PARAMS, WRITE, ...) enforces that gate.
A codec driver's set_metadata callback can assume SET_PARAMS has already run and initialised its private state; calling it while the stream is still OPEN can operate on that uninitialised state.
Add the OPEN-state check the existing comment already documents.
--- sound/core/compress_offload.c | 3 +++ 1 file changed, 3 insertions(+)
sound/core/compress_offload.c +3 -0
@@ -677,6 +677,9 @@ snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg)* we should allow parameter change only when stream has been * opened not in other cases */ +if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN ) +return -EBADFD ; +if (copy_from_user (&metadata, (void __user *)arg,sizeof (metadata)))return -EFAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1167/3318 gpio: davinci: Clear interrupt status in every bank on suspend
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sahaj Chaudhari <[email protected]>
[ Upstream commit 800d7627f552bbf602a1736b638aee0ada3fbf87 ]
davinci_gpio_save_context() saves the registers of each 32-GPIO register bank, but clears interrupt status only after the loop. At that point g refers to the last bank, so pending status in all preceding banks is left uncleared.
Move the interrupt-status write into the per-bank loop so that the existing suspend-time clearing covers every register bank. Single-bank controllers retain the same behavior.
--- drivers/gpio/gpio-davinci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpio-davinci.c +3 -3
@@ -642,10 +642,10 @@ static void davinci_gpio_save_context(struct davinci_gpio_controller *chips, context->set_data =readl_relaxed (&g->set_data); context->set_rising =readl_relaxed (&g->set_rising); context->set_falling =readl_relaxed (&g->set_falling); - } -/* Clear all interrupt status registers */ -writel_relaxed (GENMASK (31 ,0 ), &g->intstat); +/* Clear stale interrupt status for this bank. */ +writel_relaxed (GENMASK (31 ,0 ), &g->intstat); + } } static void davinci_gpio_restore_context(struct davinci_gpio_controller *chips,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1168/3318 blk-mq: clear stale inactive flag on hctx reuse
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nirmoy Das <[email protected]>
[ Upstream commit afc1de47a7ab607ae6403c4bfda36b0bf3cd342f ]
When the last CPU mapped to an hctx goes offline, blk_mq_hctx_notify_offline() sets BLK_MQ_S_INACTIVE. Updating the number of hardware queues exits every hctx and parks it on q->unused_hctx_list. A later update can reuse a parked hctx through blk_mq_alloc_and_init_hctx(), at any queue index, and nothing clears the flag.
If the reused hctx is mapped to an online CPU, blk_mq_get_tag() keeps returning BLK_MQ_NO_TAG for it. __blk_mq_alloc_requests() sleeps and retries, expecting CPU hotplug to move the task to another CPU, so a task that stays on that CPU never gets a tag. Onlining the original CPU doesn't recover it either, because blk_mq_hctx_notify_online() only clears the flag on the hctx that CPU now maps to.
Clear BLK_MQ_S_INACTIVE in blk_mq_init_hctx() so a reused hctx starts like a freshly allocated one. A reused hctx has no cpuhp instances at that point, so the offline callback can't set the flag again before blk_mq_add_hw_queues_cpuhp() registers it. Clearing the flag in blk_mq_exit_hctx() is not enough, because a parked hctx keeps its cpuhp instances until blk_mq_remove_hw_queues_cpuhp(). Preserve the other hctx state flags.
Reproduced with null_blk on v7.3 in a four-vCPU arm64 QEMU/KVM guest:
modprobe null_blk nr_devices=0
mkdir /sys/kernel/config/nullb/nullb0
cd /sys/kernel/config/nullb/nullb0
echo 4 > submit_queues; echo 1 > memory_backed; echo 16 > size echo 1 > power
echo 0 > /sys/devices/system/cpu/cpu3/online
echo 2 > submit_queues
echo 4 > submit_queues
Offlining CPU3 marks hctx3 inactive. After the two updates it comes back as hctx1 and is mapped to CPU0:
# cat /sys/block/nullb0/mq/1/cpu_list 0 # cat /sys/kernel/debug/block/nullb0/hctx1/state INACTIVE
A 4K O_DIRECT read pinned to CPU0 hangs in D state, while the same read on CPU1 and CPU2 completes. Onlining CPU3 again leaves hctx1 inactive and the CPU0 read still hangs. With this change hctx1 state is empty and the reads on CPU0, CPU1 and CPU2 complete, before and after onlining CPU3.
--- block/blk-mq.c | 1 + 1 file changed, 1 insertion(+)
block/blk-mq.c +1 -0
@@ -3841,6 +3841,7 @@ static int blk_mq_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, unsigned hctx_idx) { hctx->queue_num = hctx_idx; +clear_bit (BLK_MQ_S_INACTIVE , &hctx->state); hctx->tags = set->tags[hctx_idx];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1169/3318 drm/amdgpu: require _PR3 for BOCO
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luigi Lauro <[email protected]>
[ Upstream commit 28f3d169f162ca7e803c5a1f7e1bb55bdc915d1c ]
amdgpu_device_supports_boco() returns true for an AMD_IS_PX device on a system with a hybrid ATPX method even when the device has no ACPI power resource (_PR3). On an APU mini PC with a discrete GPU attached over OCuLink, the iGPU's ATPX method reports hybrid graphics, the dGPU is flagged AMD_IS_PX, and runtime PM in auto mode picks BOCO:
amdgpu: ATPX Hybrid Graphics
amdgpu 0000:c6:00.0: Using BOCO for runtime pm
In BOCO mode the driver leaves powering the device off to the PCI core, which can only do it through _PR3 on the upstream bridge. No device on this dGPU's path has _PR3, so when it runtime suspends the card stays powered, with its fans at about 700 rpm.
Require has_pr3 for BOCO, as the function's description ("dGPU with ACPI power resources") says. The same card then picks BACO, which powers it down:
amdgpu 0000:c6:00.0: Using BACO for runtime pm
This only changes systems with a hybrid ATPX method and no _PR3 on the dGPU's upstream bridge, where BOCO cannot cut the power today. Tested on one such system only, an RX 9070 XT (Navi 48) over OCuLink with a Ryzen AI 9 HX 470, with the change backported to 7.2.9: the stock module logs "Using BOCO", the patched one "Using BACO"; BACO runtime suspend powers the card off and it resumes cleanly. Not tested on a hybrid laptop or a Thunderbolt eGPU.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -4
@@ -201,10 +201,8 @@ bool amdgpu_device_supports_boco(struct drm_device *dev) {struct amdgpu_device *adev =drm_to_adev (dev); -if (adev->has_pr3 || - ((adev->flags &AMD_IS_PX ) &&amdgpu_is_atpx_hybrid ())) -return true; -return false; +/* BOCO needs a platform power resource (_PR3) to cut the power */ +return adev->has_pr3; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1170/3318 drm/amdgpu: reset CIK ASIC on Apple boards with VRAM at 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Kucharek <[email protected]>
[ Upstream commit 095f634ea0aa5b9da19495520b5fc1a155b2c137 ]
On MacBookPros with switchable graphics, the firmware puts VRAM at MC address 0 when the iGPU is enabled. A later post (S3 resume, GPU reset) moves VRAM back to the VBIOS default. The SI fix resets and posts the ASIC at load, so the driver uses the VBIOS layout from the start:
"drm/amdgpu: reset SI ASIC on MacBookPros with VRAM at 0"
No MacBookPro has a CIK GPU, and no affected CIK board is known. Add the same test to cik_need_reset_on_init(), so that SI, CIK and VI handle this firmware layout in the same way. gmc_v7_0 reads MC_VM_FB_LOCATION once at init and does not reprogram it. A CIK board with VRAM at 0 therefore has the same problem as the SI boards.
After the reset, FB_BASE is not 0, so the new test does not fire again on a module reload.
Only compile-tested.
--- drivers/gpu/drm/amd/amdgpu/cik.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/cik.c +10 -0
@@ -1947,6 +1947,16 @@ static bool cik_need_reset_on_init(struct amdgpu_device *adev) {u32 clock_cntl, pc; +/* +* MacBookPros with switchable graphics put VRAM at 0 when the iGPU +* is enabled. Any later post (S3 resume, GPU reset) moves it back to +* the vbios default, so reset and post on load to start with the +* vbios layout. +*/ +if (adev->pdev->subsystem_vendor ==PCI_VENDOR_ID_APPLE && + !(RREG32 (mmMC_VM_FB_LOCATION) &MC_VM_FB_LOCATION__FB_BASE_MASK )) +return true; +if (adev->flags &AMD_IS_APU )return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1171/3318 drm/amdgpu: reset VI ASIC on Apple boards with VRAM at 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Kucharek <[email protected]>
[ Upstream commit 92a5184787b81e67f7b831ad860ca9b053505cf8 ]
On MacBookPros with switchable graphics, the firmware puts VRAM at MC address 0 when the iGPU is enabled. A later post (S3 resume, GPU reset) moves VRAM back to the VBIOS default. gmc_v8_0 reads MC_VM_FB_LOCATION once at init and reprograms it only on SR-IOV. On bare metal, the driver then keeps using the old layout.
vi_reset_quirks[] handles this for the MacBookPro14,3 by PCI ID:
commit b6b1d9721851 ("drm/amdgpu: reset VI ASIC on MacBookPro14,3")
Add the test that SI and CIK use: an Apple subsystem vendor and VRAM at
0. Other Polaris MacBookPros then get the same reset at load, for example the MacBookPro13,3 if its firmware leaves VRAM at 0. These boards are not tested.
Keep vi_reset_quirks[]. Its MacBookPro15,1 entries fix a different failure, a module reload after S3:
commit a5be7ad8f5f0 ("drm/amdgpu: reset VI ASIC on MacBookPro15,1")
VRAM is not at 0 at that point, so the new test may not cover it.
After the reset, FB_BASE is not 0, so the new test does not fire again on a module reload.
Only compile-tested.
--- drivers/gpu/drm/amd/amdgpu/vi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vi.c +10 -0
@@ -1427,6 +1427,16 @@ static bool vi_need_reset_on_init(struct amdgpu_device *adev)unsigned int i;u32 clock_cntl, pc; +/* +* MacBookPros with switchable graphics put VRAM at 0 when the iGPU +* is enabled. Any later post (S3 resume, GPU reset) moves it back to +* the vbios default, so reset and post on load to start with the +* vbios layout. +*/ +if (adev->pdev->subsystem_vendor ==PCI_VENDOR_ID_APPLE && + !(RREG32 (mmMC_VM_FB_LOCATION) &MC_VM_FB_LOCATION__FB_BASE_MASK )) +return true; +for (i =0 ; i <ARRAY_SIZE (vi_reset_quirks); i++) if (adev->pdev->device == vi_reset_quirks[i].device && adev->pdev->subsystem_vendor == vi_reset_quirks[i].subsystem_vendor &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1172/3318 drm/amd/display: dont WARN when removing an unallocated MST payload
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit b18a7c6d75bcc883b39497863cc88c9ef4c6c85f ]
[Why]
On an MST teardown that runs through the reset path (dcn31_reset_hw_ctx_wrap -> link_set_dpms_off -> deallocate_mst_payload), fill_dc_mst_payload_table_from_drm() is asked to remove a payload whose vcpi is not present in link->mst_stream_alloc_table and trips:
WARNING: .../amdgpu_dm_helpers.c:275 fill_dc_mst_payload_table_from_drm
This is a legitimate case, not an error: deallocate_mst_payload() can be called for a stream whose MST payload was never programmed into DC's HW-maintained table (a new stream created for a modeset whose enable never completed, as already documented in deallocate_mst_payload()). There is simply nothing to remove.
[How]
Drop the ASSERT and fall through to the fill loop, which rebuilds the allocation table from the remaining entries. The table ends up unchanged, which is correct: the payload being removed was never in it.
Note the loop must not early-return here - the caller passes a zeroed proposed_table, so returning early would zero the whole link's table and drop the other MST streams sharing the link.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +1 -1
@@ -191,7 +191,7 @@ fill_dc_mst_payload_table_from_drm(struct dc_link *link,break ; } } -ASSERT (i != copy_of_link_table.stream_count); +/* Payload absent from HW table when never allocated: nothing to remove. */ }/* Fill payload info*/
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1173/3318 drm/amdgpu: reject ANONONLY userptrs that span multiple VMAs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit d577b68a854d0f590f480777249b041507d0708c ]
For AMDGPU_GEM_USERPTR_ANONONLY, amdgpu_ttm_tt_get_user_pages() only checks the VMA at the start of the range for a backing file, and amdgpu_hmm_range_get_pages() then faults in the whole range, across any other VMAs. The check used to reject ranges ending beyond the first VMA (vma->vm_end < end), which got lost when the code moved to HMM.
An ANONONLY userptr over one page of file-backed memory is rejected with -EPERM, but one over an anonymous page followed by the same file-backed page is accepted.
Restore the check and reject ANONONLY userptrs that cross more than one VMA. The second userptr is now rejected too.
v2: reject ranges spanning multiple VMAs instead of walking every VMA
(Christian)
v3: cast num_pages to u64 to avoid an overflow (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
@@ -723,7 +723,8 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages, goto out_unlock; }if (unlikely ((gtt->userflags &AMDGPU_GEM_USERPTR_ANONONLY ) && - vma->vm_file)) { + (vma->vm_file || + vma->vm_end < start + (u64 )ttm->num_pages *PAGE_SIZE ))) { r = -EPERM ; goto out_unlock; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1174/3318 drm/amd/display: Fix swap in median3() for DSC rate control
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Keita Morisaki <[email protected]>
[ Upstream commit 7b23bf82ccbdb4cf0752f2b8686e7319a7ce497f ]
median3() is meant to return the median of three values, but its last compare-and-swap step swaps b and c instead of a and b. When c is smaller than both a and b, it returns max(a, b) instead of min(a, b). For example, median3(2, 3, 1) returns 3 instead of 2.
_do_calc_rc_params() always passes 0 as the first argument, and the second argument is never below 12. So whenever the third argument is negative, first_line_bpg_offset (and second_line_bpg_offset for 4:2:0) is set to the second argument instead of 0.
Fix this by swapping a and b in the last step, as intended.
Note that this change does not affect valid DSC configurations. The third argument is negative only when bits per pixel exceeds the uncompressed rate of the colour format:
- 3 * bpc for 4:4:4, 3 * bpc + 2 for RGB
- 2 * bpc for 4:2:2
- 1.5 * bpc for 4:2:0
--- drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.c +1 -1
@@ -46,7 +46,7 @@ static int median3(int a, int b, int c)if (b > c)swap (b, c);if (a > b) -swap (b, c); +swap (a, b);return b; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1175/3318 ipv6: remove ifaddr from hash during ifdown list cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit 6ace56ed7b13a9c6d4cb7ef0d82d3a3d53324a63 ]
addrconf_ifdown() clears the address hash before snapshotting the per-device address list. A concurrent ipv6_add_addr() can publish an address after the hash scan and before the list snapshot.
The ifdown path then removes the address from the device list and drops the list-owned reference while it is still linked in the hash. Once the remaining references are released, inet6_ifa_finish_destroy() warns, but a DEAD address continues to kfree_rcu(). The hash therefore points to freed memory that later RCU walkers can dereference.
This follow-on was found by source review and was not separately triggered at runtime.
Remove each non-kept address from the hash immediately before removing it from the per-device list. Keeping it hashed through the delete notification blocks same-address publication until NETDEV_DOWN has been delivered. hlist_del_init_rcu() is safe when the earlier hash scan already removed the address.
This handles a late publisher captured by the list snapshot. The next change serializes publication with teardown so an add cannot miss both observations. Both changes are required when backporting the complete fix.
--- net/ipv6/addrconf.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/addrconf.c +4 -0
@@ -3992,6 +3992,10 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) }if (!keep) { +spin_lock_bh (&net->ipv6.addrconf_hash_lock); +hlist_del_init_rcu (&ifa->addr_lst); +spin_unlock_bh (&net->ipv6.addrconf_hash_lock); +write_lock_bh (&idev->lock);list_del_rcu (&ifa->if_list);write_unlock_bh (&idev->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1176/3318 ipv6: serialize address publication with device teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit 06227034e2d93942119b922cf05f2de9da0ad848 ]
ipv6_add_addr() checks idev state before allocating an ifaddr, but publishes the object later. addrconf_ifdown() can mark and detach the idev between the check and publication.
This happens when a non-loopback device MTU falls below IPV6_MIN_MTU. A forced interleaving published an address on a dead idev, and ipv6_get_ifaddr() still returned it after teardown. Later device deletion remained blocked with:
unregister_netdevice: waiting for ac0 to become free. Usage count = 3
Protect the dead indication with idev->lock and keep that lock across both hash and device-list publication. Recheck dead before publishing; if teardown wins the lock, reject the unpublished object.
Non-unregister teardown does not set dead. The preceding change covers an add that misses the initial hash scan but reaches the per-device list snapshot. Both changes are required when backporting this fix.
--- net/ipv6/addrconf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
net/ipv6/addrconf.c +9 -3
@@ -1165,14 +1165,18 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg,rcu_read_lock (); - err =ipv6_add_addr_hash (idev->dev, ifa); +write_lock_bh (&idev->lock); + +if (idev->dead) + err = -ENODEV ; +else + err =ipv6_add_addr_hash (idev->dev, ifa);if (err <0 ) { +write_unlock_bh (&idev->lock);rcu_read_unlock (); goto out; } -write_lock_bh (&idev->lock); -/* Add to inet6_dev unicast addr list. */ ipv6_link_dev_addr (idev, ifa);
@@ -3870,7 +3874,9 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)* Do not dev_put! */ if (unregister) { +write_lock_bh (&idev->lock);WRITE_ONCE (idev->dead,1 ); +write_unlock_bh (&idev->lock);/* protected by rtnl_lock */ RCU_INIT_POINTER (dev->ip6_ptr,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1177/3318 ipv6: initialize temporary ifaddr before publication
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit ed7f278812e540db507f683e5bf9b6d0a1f5bc1e ]
ipv6_create_tempaddr() holds a reference to the public ifaddr, publishes the new temporary address through ipv6_add_addr(), and only then stores the reference and final timestamps.
addrconf_ifdown() can remove the temporary address before ifpub is stored, leaking the public ifaddr reference. Publishing ifpub alone is
insufficient: manage_tempaddrs() can then find the object before cstamp and tstamp are final, update its lifetimes, and have the constructor overwrite its timestamp with an older value.
This follow-on was found by source review and was not separately triggered at runtime.
Pass the public ifaddr and both timestamps in ifa6_config. Initialize all three fields before adding the temporary address to either the hash or per-device lists. On success the existing public-ifaddr reference transfers to the temporary object. On error it remains owned and released by ipv6_create_tempaddr().
--- include/net/addrconf.h | 3 +++ net/ipv6/addrconf.c | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-)
include/net/addrconf.h +3 -0
@@ -75,6 +75,9 @@ struct ifa6_config {u8 ifa_proto;const struct in6_addr *peer_pfx; +struct inet6_ifaddr *ifpub; +unsigned long cstamp; +unsigned long tstamp;u32 rt_priority;u32 ifa_flags;
net/ipv6/addrconf.c +13 -7
@@ -1152,10 +1152,19 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, ifa->flags |=IFA_F_TENTATIVE ; ifa->valid_lft = cfg->valid_lft; ifa->prefered_lft = cfg->preferred_lft; - ifa->cstamp = ifa->tstamp = jiffies; ifa->tokenized = false; ifa->rt = f6i; + ifa->ifpub = cfg->ifpub; +if (cfg->ifpub) { + ifa->cstamp = cfg->cstamp; + ifa->tstamp = cfg->tstamp; + }else { +unsigned long now = jiffies; + + ifa->cstamp = now; + ifa->tstamp = now; + } ifa->idev = idev;in6_dev_hold (idev);
@@ -1456,6 +1465,9 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) cfg.pfx = &addr; cfg.scope =ipv6_addr_scope (cfg.pfx); + cfg.ifpub = ifp; + cfg.cstamp = now; + cfg.tstamp = tmp_tstamp; ift =ipv6_add_addr (idev, &cfg, block,NULL );if (IS_ERR (ift)) {
@@ -1466,12 +1478,6 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) goto retry; } -spin_lock_bh (&ift->lock); - ift->ifpub = ifp; - ift->cstamp = now; - ift->tstamp = tmp_tstamp; -spin_unlock_bh (&ift->lock); -addrconf_dad_start (ift);in6_ifa_put (ift);in6_dev_put (idev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1178/3318 ipv6: do not restart DAD for a dead ifaddr
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit ffb668669ce4144347973d8b2fad449e9be0563d ]
addrconf_dad_failure() can create a stable-privacy replacement without RTNL. After ipv6_add_addr() publishes it, addrconf_ifdown() can mark the new ifaddr DEAD, clear its route, and unlink it before the recovery path takes ifp2->lock.
The recovery path then unconditionally changes the state back to PREDAD and queues delayed DAD work. The MTU teardown path can leave IF_READY set. For an optimistic address, addrconf_dad_begin() can consequently pass the cleared NULL route to ip6_ins_rt().
This follow-on was found by source review and was not separately triggered at runtime.
The new ifaddr is already initialized in PREDAD. Under ifp2->lock, record the retry and queue DAD only if teardown has not changed the state to DEAD. If teardown wins after this check, the work observes DEAD and exits without reviving the address.
This complements the existing lock_errdad check that preserves the original ifaddr's DEAD state after the same function reacquires its lock.
--- net/ipv6/addrconf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/ipv6/addrconf.c +7 -3
@@ -2162,6 +2162,7 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) ifp->idev->dev->name, &ifp->addr, eth_hdr(skb)->h_source);if (ifp->flags &IFA_F_STABLE_PRIVACY ) { +bool start_dad = false;struct in6_addr new_addr;struct inet6_ifaddr *ifp2;int retries = ifp->stable_privacy_retry +1 ;
@@ -2200,11 +2201,14 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) goto lock_errdad;spin_lock_bh (&ifp2->lock); - ifp2->stable_privacy_retry = retries; - ifp2->state =INET6_IFADDR_STATE_PREDAD ; +if (ifp2->state !=INET6_IFADDR_STATE_DEAD ) { + ifp2->stable_privacy_retry = retries; + start_dad = true; + }spin_unlock_bh (&ifp2->lock); -addrconf_mod_dad_work (ifp2, net->ipv6.sysctl.idgen_delay); +if (start_dad) +addrconf_mod_dad_work (ifp2, net->ipv6.sysctl.idgen_delay);in6_ifa_put (ifp2); lock_errdad:spin_lock_bh (&ifp->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1179/3318 fbdev: bitblit: Fix glyph clipping when fbcon pans
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tingjie Zhong <[email protected]>
[ Upstream commit 06fccf840640d8f6b0e08a1756f8d2f0435b4cbe ]
Commit 3637d34b35b2 ("fbdev: Add bounds checking in bit_putcs to fix vmalloc-out-of-bounds") made bit_putcs() clip glyphs to var.yres. When fbcon scrolls by panning, it draws text rows up to var.yres_virtual, so after the first pan most new text is not drawn until the next full redraw. This affects fbdev drivers that set FBINFO_HWACCEL_YPAN or FBINFO_HWACCEL_YWRAP, such as vesafb with the ypan option, when CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION=y.
Clip to GETVYRES() instead, which fbcon_ud.c and fbcon_ccw.c already use as the drawing area height. When fbcon does not pan, GETVYRES() returns var.yres, keeping the existing bound. When fbcon pans, it returns var.yres_virtual, which the framebuffer memory must cover anyway for panning to work.
--- drivers/video/fbdev/core/bitblit.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/video/fbdev/core/bitblit.c +5 -2
@@ -18,6 +18,7 @@#include <linux/console.h> #include <asm/types.h> #include "fbcon.h" +#include "fbcon_rotate.h" /* * Accelerated handlers.
@@ -151,7 +152,9 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info, const unsigned short *s, int count, int yy, int xx, int fg, int bg) { + struct fbcon_par *par = info->fbcon_par;struct fb_image image; +u32 vyres =GETVYRES (par->p, info);u32 width =DIV_ROUND_UP (vc->vc_font.width,8 );u32 cellsize = width * vc->vc_font.height;u32 maxcnt = info->pixmap.size/cellsize;
@@ -168,10 +171,10 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info, image.height = vc->vc_font.height; image.depth =1 ; -if (image.dy >= info->var.yres) +if (image.dy >= vyres)return ; - image.height =min (image.height, info->var.yres - image.dy); + image.height =min (image.height, vyres - image.dy);if (attribute) { buf =kmalloc (cellsize,GFP_ATOMIC );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1180/3318 net/rds: ib: dont enable IRQs in rds_ib_conn_free()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Ngoc Thang <[email protected]>
[ Upstream commit f6fa1d60ec3ceb7e6c26aa91eadfef34f94014e1 ]
__rds_conn_create() calls trans->conn_free() with rds_conn_lock held and IRQs disabled when it loses the race to insert a connection. rds_ib_conn_free() takes the device list lock with spin_lock_irq() and releases it with spin_unlock_irq(), so IRQs are turned on while rds_conn_lock is still held:
raw_local_irq_restore() called with IRQs enabled
WARNING: kernel/locking/irqflag-debug.c:10 at warn_bogus_irq_restore+0xc/0x20 _raw_spin_unlock_irqrestore+0x67/0x80 __rds_conn_create+0x1de5/0x2290 rds_conn_create_outgoing+0x43/0x60 rds_sendmsg+0xfca/0x20e0 __sys_sendto+0x408/0x5a0
It needs an RDS socket bound to an address on an RDMA device (e.g. rxe) and two concurrent sendto() calls to the same new destination.
The TCP and loopback ->conn_free() callbacks already use irqsave, so do the same here.
--- net/rds/ib_cm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/rds/ib_cm.c +4 -2
@@ -1271,6 +1271,7 @@ void rds_ib_conn_free(void *arg) {struct rds_ib_connection *ic = arg;spinlock_t *lock_ptr; +unsigned long flags;rdsdebug ("ic %p\n" , ic);
@@ -1281,9 +1282,10 @@ void rds_ib_conn_free(void *arg)*/ lock_ptr = ic->rds_ibdev ? &ic->rds_ibdev->spinlock : &ib_nodev_conns_lock; -spin_lock_irq (lock_ptr); +/* May be called with IRQs already disabled (see __rds_conn_create()) */ +spin_lock_irqsave (lock_ptr, flags);list_del (&ic->ib_node); -spin_unlock_irq (lock_ptr); +spin_unlock_irqrestore (lock_ptr, flags);rds_ib_recv_free_caches (ic);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1181/3318 net: unix: reject negative max_dgram_qlen values
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingjie Wang <[email protected]>
[ Upstream commit 1a4e7bc6e3457ad95515a9d2c042452c3161bb2c ]
net.unix.max_dgram_qlen is parsed as a signed int and copied to the u32 sock::sk_max_ack_backlog when an AF_UNIX socket is created. Consequently, a negative value such as -1 is accepted and converted to UINT_MAX. Since the receive queue length is also u32, its fullness check cannot become true for that limit.
max_dgram_qlen has no documented negative sentinel. Its existing signed interface represents nonnegative values only through INT_MAX; negative bit patterns are not a supported encoding for the upper half of the u32 consumer range.
Switch to proc_dointvec_minmax and make the established 0..INT_MAX input range explicit. This rejects negative values without adding new accepted values or changing the default and zero-value behavior. Very large valid values can still make the queue limit impractical to reach; this change corrects the input domain rather than imposing a new resource ceiling.
--- Documentation/networking/ip-sysctl.rst | 3 ++- net/unix/sysctl_net_unix.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
Documentation/networking/ip-sysctl.rst +2 -1
@@ -3226,5 +3226,6 @@ l3mdev_accept - BOOLEAN max_dgram_qlen - INTEGER The maximum length of dgram socket receive queue - Default: 10 + Possible values: 0 - INT_MAX + Default: 10
net/unix/sysctl_net_unix.c +3 -1
@@ -17,7 +17,9 @@ static struct ctl_table unix_table[] = { .data = &init_net.unx.sysctl_max_dgram_qlen, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_INT_MAX, }, { } };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1182/3318 net/smc: queue the copied chunk when smc_tx_sendmsg() faults
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit c0703534b223a5c6993e0f000fd1c3abe621fb65 ]
When a send wraps the end of the send buffer, smc_tx_sendmsg() copies the data in two chunks. If memcpy_from_msg() faults on the second one, smc_tx_sendmsg() returns send_done, which already counts the first chunk, but leaves tx_curs_prep and sndbuf_space as they were. send() reports bytes the peer never receives, and the next send() overwrites them. Any caller can hit this on its own stream with a buffer whose tail is unreadable.
On a fault in the second chunk, queue the first one. The next pass retries the rest and returns send_done if it faults again, so send() reports only what it queued, as TCP does.
--- net/smc/smc_tx.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/smc/smc_tx.c +7 -0
@@ -249,6 +249,13 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len) rc =memcpy_from_msg (sndbuf_base + chunk_off, msg, chunk_len);if (rc) { +if (chunk) { +/* send_done counts the first chunk: +* queue it and retry the rest +*/ + copylen -= chunk_len; +break ; + }smc_sndbuf_sync_sg_for_device (conn);if (send_done)return send_done;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1183/3318 alpha: determine tininess after rounding in the FP emulation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Turner <[email protected]>
[ Upstream commit b74843b38da8f1186fd7d447646c835b47096a15 ]
IEEE 754 lets an architecture determine tininess of a floating-point result either before or after rounding, but requires the same choice for every operation. Alpha determines it after rounding, and stdlib's tst-tininess confirms the hardware does so for the results it produces itself.
The soft-fp emulation has no notion of the distinction and always determines tininess before rounding, so a result that the hardware would not consider tiny is reported as underflowing whenever the instruction happens to trap for software completion. The two paths then disagree on the same machine. A multiply of the largest subnormal double by 1 + 2^-52 rounds up to the smallest normal and raises no underflow when the operands are normal, but raises it when an operand is subnormal and the instruction traps:
glibc math testsuite, test-float32x-float64-mul:
Failure: mul_double (0x3.ffffffffffffcp-1024, 0x1.0000000000001p+0):
Exception "Underflow" set
Add _FP_TININESS_AFTER_ROUNDING, as glibc's copy of soft-fp has, and set it for alpha. It determines tininess by rounding a copy of the result as if the exponent range were unbounded, which is what the definition asks for. A plain check of whether the rounded result came out normal is not
equivalent: it differs for values that are still tiny once rounded with an unbounded exponent range but reach the smallest normal on the coarser subnormal grid. That plain check is what the hardware itself does (it decides tininess from the delivered result), and it is why a divide such as -0x4p-128 / 0x1.000002p+0 in FE_DOWNWARD delivers -0x1p-126 and raises nothing although the result is tiny after rounding. Such cases do not trap, so the emulation never sees them; where it does get control, it follows the definition rather than reproducing that deviation, which is what glibc's soft-fp does as well.
The macro defaults to zero, so powerpc, sh and sparc keep determining tininess before rounding as they do now.
--- arch/alpha/include/asm/sfp-machine.h | 4 ++++ include/math-emu/op-common.h | 23 +++++++++++++++++++++-- include/math-emu/soft-fp.h | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-)
arch/alpha/include/asm/sfp-machine.h +4 -0
@@ -59,6 +59,10 @@ R##_c = FP_CLS_NAN; \ }while (0 ) +/* Alpha determines tininess after rounding, so the emulation must do the + same as the hardware does for the results it produces itself. */ +#define _FP_TININESS_AFTER_ROUNDING 1 +/* Obtain the current rounding mode. */ #define FP_ROUNDMODE mode#define FP_RND_NEAREST (FPCR_DYN_NORMAL >> FPCR_DYN_SHIFT)
include/math-emu/op-common.h +21 -2
@@ -135,6 +135,24 @@ do { \ else \ { \/* we've got a denormalized number */ \ +int _FP_PACK_CANONICAL_is_tiny =1 ; \ + if (_FP_TININESS_AFTER_ROUNDING && X##_e == 0) \ + { \ +/* Architectures that detect tininess after rounding \ +only signal underflow if the result is still \ +subnormal once rounded as if the exponent range \ +were unbounded. Round a copy to find out. */ \ + FP_DECL_##fs(_FP_PACK_CANONICAL_T); \ + /* The class field is not used by the rounding below, \ +and is unused entirely where this block is dead. */ \ + (void)_FP_PACK_CANONICAL_T##_c; \ + _FP_FRAC_COPY_##wc(_FP_PACK_CANONICAL_T, X); \ + _FP_PACK_CANONICAL_T##_s = X##_s; \ + _FP_PACK_CANONICAL_T##_e = X##_e; \ + _FP_ROUND(wc, _FP_PACK_CANONICAL_T); \ + if (_FP_FRAC_OVERP_##wc(fs, _FP_PACK_CANONICAL_T)) \ + _FP_PACK_CANONICAL_is_tiny = 0; \ + } \ X##_e = -X##_e + 1; \ if (X##_e <= _FP_WFRACBITS_##fs) \ { \
@@ -161,8 +179,9 @@ do { \ _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \ } \ } \ - if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) || \ - (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW)) \ + if (_FP_PACK_CANONICAL_is_tiny \ + && ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) || \ + (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW))) \ FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \ } \ else \
include/math-emu/soft-fp.h +8 -0
@@ -31,6 +31,14 @@#include <endian.h> #endif +/* Whether the architecture determines tininess of a floating-point +result after rounding rather than before it. IEEE 754 permits either +but requires the same choice for every operation, so this has to agree +with what the hardware does for the results it produces itself. */ +#ifndef _FP_TININESS_AFTER_ROUNDING +#define _FP_TININESS_AFTER_ROUNDING 0 +#endif +#define _FP_WORKBITS 3#define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)#define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1184/3318 ocfs2: reserve metadata for a new xattr block and its value tree
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 8ad5fa0c11246d260d7b12c9672e604b1f431b2e ]
Patch series "ocfs2: fix metadata reservation for xattr value trees".
ocfs2_calc_xattr_set_need() reserves too little metadata for a new xattr value's extent tree on three paths. The reservation cannot be topped up once the transaction has started, so ocfs2_add_clusters_in_btree() gives up with RESTART_META when the value root fills and nothing is left. ocfs2_xattr_extend_allocation() turns that into -ENOSPC, after ocfs2_xa_cleanup_value_truncate() has dropped the entry and leaked the clusters already handed out; before commit 0cdc7dde00ec ("ocfs2: fix missing metadata reservation for large xattrs") it was a BUG_ON() instead. It takes a fragmented cluster allocator to get there, since the first extent always fits in the root.
Patch 1 fixes the create side of meta_guess: commit 3ed2be719eb9 ("ocfs2:
allow for more than one data extent when creating xattr") replaced the block reserved for the new xattr block with the two the value tree needs instead of adding them together.
Patch 2 fixes the arm that moves an xattr back into the inode, which charges credits for a value tree but no metadata for one.
Patch 3 drops a second copy of the same reservation on the path that falls through to meta_guess. That one is cleanup rather than a fix and is not for stable, and it must not be backported without patch 1: the duplicate it removes is what currently covers the shortfall patch 1 fixes.
This patch (of 3):
The create side of meta_guess in ocfs2_calc_xattr_set_need() reserves metadata for the new value's extent tree and nothing for the xattr block that will hold it:
} else {
credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS;
if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
struct ocfs2_extent_list *el = &def_xv.xv.xr_list;
meta_add += ocfs2_extend_meta_needed(el);
...Commit 3ed2be719eb9 ("ocfs2: allow for more than one data extent when creating xattr") meant to add that tree on top of the meta_add += 1 the branch already had, but it moved the 1 into the else arm instead, so the external-value case lost it. The 1 is not optional: it is what ocfs2_create_xattr_block() takes from meta_ac through ocfs2_claim_metadata(), and it is spent before the value tree exists.
ocfs2_extend_meta_needed() on the empty def_xv list returns 2, so the branch reserves 2 where 3 are needed. The xattr block consumes one, and when the cluster allocator is fragmented enough that the value needs more than one extent, ocfs2_add_clusters_in_btree() comes back around with a full value root and ocfs2_alloc_context_bits_left() of 1 against a threshold of 2. It answers RESTART_META, which ocfs2_xattr_extend_allocation() turns into a BUG_ON(). Commit 0cdc7dde00ec ("ocfs2: fix missing metadata reservation for large xattrs") downgraded that to -ENOSPC, at the cost of leaking the clusters already handed out: ocfs2_xa_cleanup_value_truncate() takes its !orig_clusters arm, drops the entry and leaves the clusters for fsck.ocfs2 to reclaim.
Reserve for the block and the tree separately.
--- fs/ocfs2/xattr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +7 -1
@@ -3458,7 +3458,13 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, credits +=OCFS2_XATTR_BLOCK_CREATE_CREDITS ;if (xi->xi_value_len >OCFS2_XATTR_INLINE_SIZE ) {struct ocfs2_extent_list *el = &def_xv.xv.xr_list; - meta_add +=ocfs2_extend_meta_needed (el); +/* +* One block for the xattr block we may have to +* allocate, the rest for growing the value tree it +* would hold. If ocfs2_xattr_ibody_set() succeeds +* instead, that first block goes unused. +*/ + meta_add +=1 +ocfs2_extend_meta_needed (el); credits +=ocfs2_calc_extend_credits (inode->i_sb, el); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1185/3318 ocfs2: reserve value tree metadata when moving an xattr into the inode
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit f5aee8ae5f85f8dfa78160e5c4963494319cdd64 ]
ocfs2_calc_xattr_set_need() charges no metadata for the case where an xattr living in an xattr block or bucket moves back into the inode:
if (old_in_xb) {
if (ocfs2_xattr_can_be_in_inode(inode, xi, xis)) {
clusters_add += new_clusters;
credits += ...;
if (!ocfs2_xattr_is_local(xe))
credits += ocfs2_calc_extend_credits(...);
goto out;
}
}The credits for extending a value tree are there but the matching blocks are not, so meta_add stays 0, ocfs2_init_xattr_set_ctxt() skips ocfs2_reserve_new_metadata_blocks() and ctxt->meta_ac is left NULL.
This is the shape commit 0cdc7dde00ec ("ocfs2: fix missing metadata reservation for large xattrs") fixed for the xattr block case, and it is reached the same way: namevalue_size() charges a value larger than OCFS2_XATTR_INLINE_SIZE as only OCFS2_XATTR_ROOT_SIZE, so ocfs2_xattr_can_be_in_inode() accepts a new value that will be stored outside. ocfs2_xa_prepare_entry() installs a value root from def_xv and grows it, and once the cluster allocator is fragmented enough to need a second extent ocfs2_add_clusters_in_btree() finds the root full with no meta_ac at all and answers RESTART_META. ocfs2_xattr_extend_allocation() turns that into -ENOSPC, or into a BUG_ON() without that commit, and ocfs2_xa_cleanup_value_truncate() takes its !orig_clusters arm, dropping the entry and leaking the clusters already handed out until fsck.ocfs2 reclaims them.
Reserve for the value tree here too. The entry moves back into the inode rather than into a new xattr block, so unlike the create side of meta_guess this needs no block of its own.
--- fs/ocfs2/xattr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ocfs2/xattr.c +8 -0
@@ -3358,6 +3358,14 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, credits +=ocfs2_calc_extend_credits ( inode->i_sb, &def_xv.xv.xr_list); +/* +* A value too big to stay inline is only charged as +* OCFS2_XATTR_ROOT_SIZE above, so it can still need a +* value tree of its own. No xattr block is allocated +* on this path, so the tree is all we reserve for. +*/ +if (xi->xi_value_len >OCFS2_XATTR_INLINE_SIZE ) + meta_add +=ocfs2_extend_meta_needed (&def_xv.xv.xr_list); goto out; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1186/3318 ocfs2: deal with legacy signed dir index name hash values
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit d1b49d5ea1bf43cce2b0e249a7f7a30dde133907 ]
Patch series "ocfs2: deal with legacy signed name hash values", v2.
Commit 3bc753c06dd0 ("kbuild: treat char as always unsigned") turned on -funsigned-char globally, which changed the result of two naked 'char' loads in ocfs2 hashing code:
str2hashbuf() val = msg[i] + (val << 8); ocfs2_xattr_name_hash() hash = (hash << 5) ^ (hash >> 27) ^ *name++;
A name byte >= 0x80 used to sign-extend and now zero-extends. Both results are written to disk, the first into the dx leaf when a directory entry is indexed and the second into xe_name_hash when an xattr is stored, so anything written by a pre-6.2 kernel is looked up under a different hash and is no longer found. readdir and listxattr still list those names because neither of them hashes, which makes this look like the filesystem losing entries rather than like a lookup bug. Anderson Ferneda reported it that way for directories with non-ASCII names [1].
Patches 1 and 3 do what ext4 did in commit f3bbac32475b2 ("ext4: deal with legacy signed xattr name hash values"): look up with the current unsigned hash, retry with the legacy signed one on a miss, and always store new entries under the unsigned hash. The retry is skipped when the two hashes come out equal, so an ASCII name does not walk the index twice. Both hash functions now spell out the signedness instead of leaving it to -funsigned-char, as commit 854f0912f813 ("ext4: make xattr char unsignedness in hash explicit") did, so a backport to a kernel without the flag still computes both variants correctly.
Patch 2 is a separate fix, placed before patch 3 so that every commit in the series is correct on its own. ocfs2_check_xattr_bucket_collision() recomputes the hash of the name to decide whether splitting a full bucket can make room for the entry being set. That is right for a new entry and wrong for one that already exists, since an update leaves xe_name_hash alone. Against a bucket holding legacy hashes the comparison does not match, so the split goes ahead and cannot help: a bucket whose entries all share one hash has no divide position. How that ends depends on where the unsigned hash sorts. Below the legacy ones, the set fails with -ENOSPC after growing the tree for nothing. Above them, it lands in the empty bucket the split just appended and stores a second copy of the entry there while the original stays behind, so listxattr reports the name twice. Using the stored hash closes both.
Nothing retires a legacy hash at runtime. Deleting or updating an entry does not rewrite it, and the only code that rehashes existing dirents is ocfs2_expand_inline_dir() on the inline to extent conversion, so the retry stays for as long as the legacy entries do. Rebuilding the index offline is what removes it for good.
This patch (of 3):
Commit 3bc753c06dd0 ("kbuild: treat char as always unsigned") set -funsigned-char globally, which changed the result of the naked 'char' load in str2hashbuf():
val = msg[i] + (val << 8);
A name byte >= 0x80 used to sign-extend and now zero-extends, so ocfs2_dx_dir_name_hash() computes a different hash pair for every name containing one. The pair is written into the dx leaf when the entry is created, so an index built by an older kernel no longer matches and ocfs2_dx_dir_search() returns -ENOENT for a name that readdir still lists.
Search with the current unsigned hash and, on a miss, retry with the legacy signed one, as ext4 does in commit f3bbac32475b2 ("ext4: deal with legacy signed xattr name hash values"). New entries are always indexed under the unsigned hash. Skip the retry when the two hashes are equal, so that a miss on an ASCII name does not walk the index twice.
The retry costs a second walk of the dx tree, so a negative lookup of a name containing a byte >= 0x80 does twice the work. That is bounded and worth it, and directories whose dx root is still inline pay nothing extra, since there the retry only rescans the root block that is already loaded. Nothing retires it at runtime: a legacy entry keeps its legacy hash, because neither deleting nor updating an entry rewrites the dx hash, and the only code that rehashes existing dirents is ocfs2_expand_inline_dir() on the inline to extent conversion. Rebuilding the index offline is what removes the cost for good.
Also spell out the signedness in str2hashbuf() instead of leaving the current hash to -funsigned-char, as commit 854f0912f813 ("ext4: make xattr char unsignedness in hash explicit") did, so that both variants stay correct if this is backported to a kernel without the flag.
--- fs/ocfs2/dir.c | 76 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 11 deletions(-)
fs/ocfs2/dir.c +65 -11
@@ -221,7 +221,8 @@ static void TEA_transform(__u32 buf[4], __u32 const in[]) buf[1 ] += b1; } -static void str2hashbuf (const char *msg,int len,__u32 *buf,int num) +static void str2hashbuf (const char *msg,int len,__u32 *buf,int num, +bool legacy_signed) {__u32 pad, val;int i;
@@ -235,7 +236,10 @@ static void str2hashbuf(const char *msg, int len, __u32 *buf, int num)for (i =0 ; i < len; i++) {if ((i %4 ) ==0 ) val = pad; - val = msg[i] + (val <<8 ); +if (legacy_signed) + val = (signed char )msg[i] + (val <<8 ); +else + val = (unsigned char )msg[i] + (val <<8 );if ((i %4 ) ==3 ) { *buf++ = val; val = pad;
@@ -248,8 +252,9 @@ static void str2hashbuf(const char *msg, int len, __u32 *buf, int num) *buf++ = pad; } -static void ocfs2_dx_dir_name_hash (struct inode *dir,const char *name,int len, -struct ocfs2_dx_hinfo *hinfo) +static void __ocfs2_dx_dir_name_hash (struct inode *dir,const char *name, +int len,struct ocfs2_dx_hinfo *hinfo, +bool legacy_signed) {struct ocfs2_super *osb =OCFS2_SB (dir->i_sb);const char *p;
@@ -279,7 +284,7 @@ static void ocfs2_dx_dir_name_hash(struct inode *dir, const char *name, int len, p = name;while (len >0 ) { -str2hashbuf (p, len, in,4 ); +str2hashbuf (p, len, in,4 , legacy_signed);TEA_transform (buf, in); len -=16 ; p +=16 ;
@@ -290,6 +295,19 @@ static void ocfs2_dx_dir_name_hash(struct inode *dir, const char *name, int len, hinfo->minor_hash = buf[1 ]; } +static void ocfs2_dx_dir_name_hash (struct inode *dir,const char *name,int len, +struct ocfs2_dx_hinfo *hinfo) +{ +__ocfs2_dx_dir_name_hash (dir, name, len, hinfo, false); +} + +static void ocfs2_dx_dir_name_hash_signed (struct inode *dir,const char *name, +int len, +struct ocfs2_dx_hinfo *hinfo) +{ +__ocfs2_dx_dir_name_hash (dir, name, len, hinfo, true); +} +/* * bh passed here can be an inode block or a dir data block, depending * on the inode inline data flag.
@@ -953,10 +971,10 @@ static int ocfs2_dx_dir_lookup(struct inode *inode,return ret; } -static int ocfs2_dx_dir_search (const char *name,int namelen, -struct inode *dir, -struct ocfs2_dx_root_block *dx_root, -struct ocfs2_dir_lookup_result *res) +static int __ocfs2_dx_dir_search (const char *name,int namelen, +struct inode *dir, +struct ocfs2_dx_root_block *dx_root, +struct ocfs2_dir_lookup_result *res) {int ret, i, found;u64 phys;
@@ -969,8 +987,6 @@ static int ocfs2_dx_dir_search(const char *name, int namelen,struct ocfs2_extent_list *dr_el;struct ocfs2_dx_entry_list *entry_list; -ocfs2_dx_dir_name_hash (dir, name, namelen, &res->dl_hinfo); -if (ocfs2_dx_root_inline (dx_root)) { entry_list = &dx_root->dr_entries; goto search;
@@ -1067,6 +1083,44 @@ static int ocfs2_dx_dir_search(const char *name, int namelen,return ret; } +static int ocfs2_dx_dir_search (const char *name,int namelen, +struct inode *dir, +struct ocfs2_dx_root_block *dx_root, +struct ocfs2_dir_lookup_result *res) +{ +struct ocfs2_dx_hinfo legacy; +int ret; + +ocfs2_dx_dir_name_hash (dir, name, namelen, &res->dl_hinfo); + + ret =__ocfs2_dx_dir_search (name, namelen, dir, dx_root, res); +if (ret != -ENOENT ) +return ret; + +/* +* Nothing under the current hash. The entry may have been indexed by +* an older kernel, which sign-extended the name bytes when hashing. +* New entries are always indexed under the unsigned hash, so only fall +* back to the legacy signed one when it can actually differ: an ASCII +* name hashes the same either way, and a genuine miss on one should +* not have to walk the index twice. +*/ +ocfs2_dx_dir_name_hash_signed (dir, name, namelen, &legacy); +if (legacy.major_hash == res->dl_hinfo.major_hash && + legacy.minor_hash == res->dl_hinfo.minor_hash) +return ret; + + res->dl_hinfo = legacy; + + ret =__ocfs2_dx_dir_search (name, namelen, dir, dx_root, res); +if (ret) +return ret; + +pr_warn_once ("ocfs2: directory index with signed name hash\n" ); + +return 0 ; +} +static int ocfs2_find_entry_dx (const char *name,int namelen,struct inode *dir,struct ocfs2_dir_lookup_result *lookup)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1187/3318 ocfs2: use the stored hash when checking xattr bucket collision
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit e39baff18b85cf8956aee138d7944b6581e8ba36 ]
ocfs2_check_xattr_bucket_collision() decides whether splitting a full bucket can make room for the entry being set by recomputing the hash of the name:
u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name)); if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash)) return 0;
For a new entry that is the hash it will be stored under, so comparing it is correct. An existing entry keeps the hash it already has: an update never rewrites xe_name_hash, since ocfs2_xa_add_entry() is the only writer of that field for a real entry and ocfs2_xa_prepare_entry() calls it only when loc->xl_entry is NULL.
An entry stored by a kernel that sign-extended the name bytes when hashing can still be updated, because ocfs2_xattr_find_entry() searches a non-indexed xattr block by memcmp on the name and never looks at xe_name_hash. Growing it past the space left in the block converts the block into a tree, ocfs2_cp_xattr_block_to_bucket() fills the bucket in stored hash order, and the update runs out of room in the bucket too. The collision check then compares the unsigned hash against the legacy hashes in the bucket and reports no collision.
ocfs2_xattr_set_entry_index_block() goes on to allocate a bucket that ocfs2_divide_xattr_bucket() cannot fill: a bucket whose entries all share one hash has no divide position, so all it does is append an empty bucket with a sentinel hash one above the last entry's.
The re-search that follows depends on where the unsigned hash sorts. Below the legacy ones, it comes back to the full bucket and the set fails with -ENOSPC, having grown the tree for nothing. Above them, it lands on the new empty bucket, which ocfs2_xattr_bucket_find() handles explicitly and ocfs2_find_xe_in_bucket() scans zero times, so the set stores a second copy of the entry under the unsigned hash and returns success. The original stays in the full bucket, listxattr reports the name twice and getxattr returns the new copy.
Pass the hash the entry is stored under instead: the stored one for an existing entry, the unsigned one for a new entry. A tree whose entries are all stored under the unsigned hash sees no change, since there the two are the same value.
--- fs/ocfs2/xattr.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +17 -10
@@ -5755,16 +5755,14 @@ static int ocfs2_rm_xattr_cluster(struct inode *inode,/* * check whether the xattr bucket is filled up with the same hash value. -* If we want to insert the xattr with the same hash, return -ENOSPC. -* If we want to insert a xattr with different hash value, go ahead -* and ocfs2_divide_xattr_bucket will handle this. +* If the entry being set carries that same hash, return -ENOSPC, since +* ocfs2_divide_xattr_bucket() has no divide position to work with. +* Otherwise go ahead and ocfs2_divide_xattr_bucket() will handle this. */ -static int ocfs2_check_xattr_bucket_collision (struct inode *inode, -struct ocfs2_xattr_bucket *bucket, -const char *name) +static int ocfs2_check_xattr_bucket_collision (struct ocfs2_xattr_bucket *bucket, +u32 name_hash) {struct ocfs2_xattr_header *xh =bucket_xh (bucket); -u32 name_hash =ocfs2_xattr_name_hash (inode, name,strlen (name));if (name_hash !=le32_to_cpu (xh->xh_entries[0 ].xe_name_hash))return 0 ;
@@ -5833,6 +5831,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { + u32 name_hash;int ret;trace_ocfs2_xattr_set_entry_index_block (xi->xi_name);
@@ -5852,10 +5851,18 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,* the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. +* +* An existing entry keeps the hash it was stored under, and that is +* the hash a split has to work with. A new entry is stored under the +* unsigned one, which is what ocfs2_xa_add_entry() will write. */ - ret =ocfs2_check_xattr_bucket_collision (inode, - xs->bucket, - xi->xi_name); +if (xs->not_found) + name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, + xi->xi_name_len); +else + name_hash =le32_to_cpu (xs->here->xe_name_hash); + + ret =ocfs2_check_xattr_bucket_collision (xs->bucket, name_hash);if (ret) {mlog_errno (ret); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1188/3318 ocfs2: deal with legacy signed xattr name hash values
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 824d26d11448b4d4f19677bce27c7fe5e962f4c6 ]
Commit 3bc753c06dd0 ("kbuild: treat char as always unsigned") set -funsigned-char globally, which changed the result of the naked 'char' load in ocfs2_xattr_name_hash():
hash = (hash << OCFS2_HASH_SHIFT) ^ (hash >> (8*sizeof(hash) - OCFS2_HASH_SHIFT)) ^ *name++;
A name byte >= 0x80 used to sign-extend and now zero-extends, so the hash no longer matches the xe_name_hash an older kernel stored. An indexed xattr tree is searched by that hash alone, and both the bucket binary search and the entry scan within it stop as soon as the wanted hash falls below an entry's, so the entry is never reached: getxattr, setxattr and removexattr return -ENODATA for a name that listxattr still lists.
Search with the current unsigned hash and, on a miss, retry with the legacy signed one, as ext4 does in commit f3bbac32475b2 ("ext4: deal with legacy signed xattr name hash values"). New entries are always stored under the unsigned hash. Skip the retry when the two hashes are equal, so that a miss on an ASCII name does not walk the tree twice.
A miss is not empty handed: ocfs2_xattr_bucket_find() leaves xs->bucket holding the bucket a new entry would go into. So after a double miss drop it and search once more with the unsigned hash, otherwise a new entry would be placed by its legacy hash and stored under its unsigned one, breaking the ordering the search relies on.
Only indexed trees are affected; inline xattrs and non-indexed xattr blocks compare names with memcmp and never look at the hash.
Also spell out the signedness instead of leaving the current hash to -funsigned-char, as commit 854f0912f813 ("ext4: make xattr char unsignedness in hash explicit") did, so that both variants stay correct if this is backported to a kernel without the flag.
--- fs/ocfs2/xattr.c | 93 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 11 deletions(-)
fs/ocfs2/xattr.c +82 -11
@@ -557,9 +557,10 @@ static inline const char *ocfs2_xattr_prefix(int name_index)return handler ?xattr_prefix (handler) :NULL ; } -static u32 ocfs2_xattr_name_hash (struct inode *inode, -const char *name, -int name_len) +static u32 __ocfs2_xattr_name_hash (struct inode *inode, +const char *name, +int name_len, +bool legacy_signed) {/* Get hash value of uuid from super block */ u32 hash =OCFS2_SB (inode->i_sb)->uuid_hash;
@@ -568,13 +569,30 @@ static u32 ocfs2_xattr_name_hash(struct inode *inode,/* hash extended attribute name */ for (i =0 ; i < name_len; i++) { hash = (hash <<OCFS2_HASH_SHIFT ) ^ - (hash >> (8 *sizeof (hash) -OCFS2_HASH_SHIFT )) ^ - *name++; + (hash >> (8 *sizeof (hash) -OCFS2_HASH_SHIFT )); +if (legacy_signed) + hash ^= (signed char )name[i]; +else + hash ^= (unsigned char )name[i]; }return hash; } +static u32 ocfs2_xattr_name_hash (struct inode *inode, +const char *name, +int name_len) +{ +return __ocfs2_xattr_name_hash (inode, name, name_len, false); +} + +static u32 ocfs2_xattr_name_hash_signed (struct inode *inode, +const char *name, +int name_len) +{ +return __ocfs2_xattr_name_hash (inode, name, name_len, true); +} +static int ocfs2_xattr_entry_real_size (int name_len,size_t value_len) { return namevalue_size(name_len, value_len) +
@@ -4164,11 +4182,12 @@ static int ocfs2_xattr_bucket_find(struct inode *inode,return ret; } -static int ocfs2_xattr_index_block_find (struct inode *inode, -struct buffer_head *root_bh, -int name_index, -const char *name, -struct ocfs2_xattr_search *xs) +static int __ocfs2_xattr_index_block_find (struct inode *inode, +struct buffer_head *root_bh, +int name_index, +const char *name, +u32 name_hash, +struct ocfs2_xattr_search *xs) {int ret; struct ocfs2_xattr_block *xb =
@@ -4177,7 +4196,6 @@ static int ocfs2_xattr_index_block_find(struct inode *inode,struct ocfs2_extent_list *el = &xb_root->xt_list;u64 p_blkno =0 ;u32 first_hash, num_clusters =0 ; -u32 name_hash =ocfs2_xattr_name_hash (inode, name,strlen (name));if (le16_to_cpu (el->l_next_free_rec) ==0 )return -ENODATA ;
@@ -4208,6 +4226,59 @@ static int ocfs2_xattr_index_block_find(struct inode *inode,return ret; } +static int ocfs2_xattr_index_block_find (struct inode *inode, +struct buffer_head *root_bh, +int name_index, +const char *name, +struct ocfs2_xattr_search *xs) +{ +u32 name_hash, legacy_hash; +int name_len =strlen (name); +int ret; + + name_hash =ocfs2_xattr_name_hash (inode, name, name_len); + + ret =__ocfs2_xattr_index_block_find (inode, root_bh, name_index, name, + name_hash, xs); +if (ret != -ENODATA ) +return ret; + +/* +* Nothing under the current hash. The entry may have been stored by +* an older kernel, which sign-extended the name bytes when hashing. +* Skip the retry when the two hashes are equal, so that a name made +* only of ASCII does not have to walk the tree twice. +*/ + legacy_hash =ocfs2_xattr_name_hash_signed (inode, name, name_len); +if (legacy_hash == name_hash) +return ret; + +/* +* A miss still leaves xs->bucket holding the bucket a new entry would +* be inserted into, so drop it before searching again. +*/ +ocfs2_xattr_bucket_relse (xs->bucket); + + ret =__ocfs2_xattr_index_block_find (inode, root_bh, name_index, name, + legacy_hash, xs); +if (!ret) { +pr_warn_once ("ocfs2: xattr tree with signed name hash\n" ); +return ret; + } +if (ret != -ENODATA ) +return ret; + +/* +* Not under either hash. Restore the unsigned placement, since that +* is where a new entry is stored: leaving the bucket where the legacy +* hash put it would break the ordering the search relies on. +*/ +ocfs2_xattr_bucket_relse (xs->bucket); + +return __ocfs2_xattr_index_block_find (inode, root_bh, name_index, name, + name_hash, xs); +} + static int ocfs2_iterate_xattr_buckets(struct inode *inode, u64 blkno, u32 clusters,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1189/3318 ocfs2/cluster: initialize heartbeat regions before publishing them
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit c5b7a30a5172317e1e3cba61d8c9f9c588c497bb ]
A region on o2hb_all_regions must have an initialized config item and name. o2hb_heartbeat_group_make_item() currently links the zeroed region under o2hb_live_lock, drops the lock, and only then initializes hr_item. The lock therefore protects the list without protecting initialization from readers of the published item.
With global heartbeat enabled, a DLM_QUERY_REGION from the current joining node can pass the existing-domain and protocol checks while a configfs mkdir creates another region. The DLM locks are not taken by the constructor, and the network worker does not take the configfs subsystem mutex. The following ordering is possible:
Configfs mkdir O2net receive worker
-------------- --------------------
Allocate reg
Lock o2hb_live_lock
Link into o2hb_all_regions
Unlock o2hb_live_lock
dlm_query_region_handler()
dlm_match_regions()
o2hb_get_all_regions()
Lock o2hb_live_lock Copy 32 bytes from NULL name Unlock o2hb_live_lock
config_item_init_type_name()
The query thus dereferences NULL. Initialize hr_item before linking the region so the existing list lock also orders name initialization before any reader. Reject a failed name allocation, since the initialization helper does not propagate that error.
Use config_item_put() on initialized constructor failures to release the name and respect references retained by o2hb_region_pin(). Initialize the list heads, mutex and delayed works needed by o2hb_region_release() before any such put, and leave the list node self-linked after rollback. Keep the existing handler drain before removing a failed published item.
KASAN report as below:
==================================================================
BUG: KASAN: null-ptr-deref in o2hb_get_all_regions+0xbb/0x1f0
Read of size 32 at addr 0000000000000000 by task kworker/u16:1/14
CPU: 2 UID: 0 PID: 14 Comm: kworker/u16:1 Not tainted 7.3.0-rc4-next-20260921-pmb-ocfs2-functional-v1+ #1 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: o2net o2net_rx_until_empty
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
kasan_report+0xe0/0x110
? o2hb_get_all_regions+0xbb/0x1f0
kasan_check_range+0x105/0x1b0
__asan_memcpy+0x23/0x60
o2hb_get_all_regions+0xbb/0x1f0
dlm_query_region_handler+0x4c2/0xc20
? __pfx_dlm_query_region_handler+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on+0x18/0x160
? srso_alias_return_thunk+0x5/0xfbef5
? kvm_clock_get_cycles+0x31/0x60
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_dlm_query_region_handler+0x10/0x10
o2net_rx_until_empty+0x1a50/0x3200
? reacquire_held_locks+0xdd/0x200
? __pfx_o2net_rx_until_empty+0x10/0x10
? lock_acquire+0x190/0x300
? process_one_work+0x935/0x1b40
? process_one_work+0x834/0x1b40
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x290
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x9a8/0x1b40
? __pfx_process_one_work+0x10/0x10
? lock_acquire+0x190/0x300
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? srso_alias_return_thunk+0x5/0xfbef5
? __kthread_parkme+0x177/0x220
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_worker_thread+0x10/0x10
kthread+0x351/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf70
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
==================================================================--- fs/ocfs2/cluster/heartbeat.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
fs/ocfs2/cluster/heartbeat.c +17 -9
@@ -2116,6 +2116,18 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g } reg->hr_node_num =O2NM_MAX_NODES ; +INIT_LIST_HEAD (®->hr_all_item); +mutex_init (®->hr_arming_mutex); + reg->hr_stopping = true; +INIT_DELAYED_WORK (®->hr_write_timeout_work, o2hb_write_timeout); +INIT_DELAYED_WORK (®->hr_nego_timeout_work, o2hb_nego_timeout); +INIT_LIST_HEAD (®->hr_handler_list); +config_item_init_type_name (®->hr_item, name, &o2hb_region_type); +if (!config_item_name (®->hr_item)) { + ret = -ENOMEM ; + goto put_item; + } +spin_lock (&o2hb_live_lock); reg->hr_region_num =0 ;if (o2hb_global_heartbeat_active ()) {
@@ -2124,26 +2136,19 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *gif (reg->hr_region_num >=O2NM_MAX_REGIONS ) {spin_unlock (&o2hb_live_lock); ret = -EFBIG ; - goto free; + goto put_item; }set_bit (reg->hr_region_num, o2hb_region_bitmap); }list_add_tail (®->hr_all_item, &o2hb_all_regions);spin_unlock (&o2hb_live_lock); -config_item_init_type_name (®->hr_item, name, &o2hb_region_type); -/* this is the same way to generate msg key as dlm, for local heartbeat, * name is also the same, so make initial crc value different to avoid * message key conflict. */ reg->hr_key =crc32_le (reg->hr_region_num +O2NM_MAX_REGIONS , name,strlen (name)); -mutex_init (®->hr_arming_mutex); - reg->hr_stopping = true; -INIT_DELAYED_WORK (®->hr_write_timeout_work, o2hb_write_timeout); -INIT_DELAYED_WORK (®->hr_nego_timeout_work, o2hb_nego_timeout); -INIT_LIST_HEAD (®->hr_handler_list); ret = o2net_register_handler(O2HB_NEGO_TIMEOUT_MSG, reg->hr_key, sizeof(struct o2hb_nego_msg), o2hb_nego_timeout_handler,
@@ -2166,10 +2171,13 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *go2net_unregister_and_flush_handler_list (®->hr_handler_list); remove_item:spin_lock (&o2hb_live_lock); -list_del (®->hr_all_item); +list_del_init (®->hr_all_item);if (o2hb_global_heartbeat_active ())clear_bit (reg->hr_region_num, o2hb_region_bitmap);spin_unlock (&o2hb_live_lock); +put_item: +config_item_put (®->hr_item); +return ERR_PTR (ret); free:kfree (reg);return ERR_PTR (ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1190/3318 Documentation: hyperv: Update documentation for sending VMBus packets
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Kelley <[email protected]>
[ Upstream commit 6a3d77a0a8cf69cf3d234305e6711729eb5d10c4 ]
The functions for sending VMBus packets have changed. vmbus_sendpacket_mpb_desc() can target multiple ranges, and vmbus_sendpacket_pagebuffer() has been removed. vmbus_sendpacket_getid() has been added. Update the documentation accordingly.
--- Documentation/virt/hyperv/vmbus.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
Documentation/virt/hyperv/vmbus.rst +9 -8
@@ -141,14 +141,15 @@ Three functions exist to send VMbus messages: 1. vmbus_sendpacket(): Control-only messages and messages with embedded data -- no GPAs -2. vmbus_sendpacket_pagebuffer(): Message with list of GPAs - identifying data to transfer. An offset and length is - associated with each GPA so that multiple discontinuous areas - of guest memory can be targeted. -3. vmbus_sendpacket_mpb_desc(): Message with list of GPAs - identifying data to transfer. A single offset and length is - associated with a list of GPAs. The GPAs must describe a - single logical area of guest memory to be targeted. +2. vmbus_sendpacket_getid(): Similar to vmbus_sendpacket() but returns + a transaction ID that is matched against a reply from the Hyper-V + host. Useful when the struct completion (or other rendezvous data) + must reside on the caller's stack. By invalidating the transaction + ID before exiting the function due to a timeout or other error, a + late arriving interrupt is assured to not trash the stack. +3. vmbus_sendpacket_mpb_desc(): Message with one or more data ranges + to target. Each range consists of a single offset and length plus + a list of GPAs that describe a logical area of guest memory. Historically, Linux guests have trusted Hyper-V to send well-formed and valid messages, and Linux drivers for synthetic devices did not
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1191/3318 writeback: reset dirtied_when when switching wbs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit 13b9a606dd0a6cf9bac12894c97b9546d22a7425 ]
When switching a dirty inode to another wb, inode_do_switch_wbs() puts it at the newest end of the target b_dirty list instead of searching for its sorted position. This requires updating dirtied_when, which move_expired_inodes() uses to decide where to stop scanning.
However, the switch updates dirtied_time_when instead. This leaves b_dirty out of order and can make the scan stop before reaching older inodes. It also resets the lazytime expiration timestamp, potentially delaying timestamp writeback.
Update dirtied_when instead, preserving both the constant-time insertion and the lazytime expiration timestamp. Correct the field name in the comment and document the distinction between the two inode timestamps.
--- fs/fs-writeback.c | 6 +++--- include/linux/fs.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-)
fs/fs-writeback.c +3 -3
@@ -431,12 +431,12 @@ static bool inode_do_switch_wbs(struct inode *inode,if (inode->i_state &I_DIRTY_ALL ) {/* * We need to keep b_dirty list sorted by -* dirtied_time_when. However properly sorting the +* dirtied_when. However properly sorting the * inode in the list gets too expensive when switching * many inodes. So just attach inode at the end of the -* dirty list and clobber the dirtied_time_when. +* dirty list and clobber the dirtied_when. */ - inode->dirtied_time_when = jiffies; + inode->dirtied_when = jiffies;inode_io_list_move_locked (inode, new_wb, &new_wb->b_dirty); }else {
include/linux/fs.h +3 -1
@@ -691,7 +691,9 @@ struct inode {unsigned long i_state;struct rw_semaphore i_rwsem; -unsigned long dirtied_when;/* jiffies of first dirtying */ +/* Timestamp for writeback list ordering and age checks (jiffies). */ +unsigned long dirtied_when; +/* Start time for deciding when lazytime updates need writeback (jiffies). */ unsigned long dirtied_time_when;struct hlist_node i_hash;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1192/3318 writeback: clear old wb dirty state after inode switches
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit a396fe9f74ea367ae3fab2dcb70b24e83db9f0cb ]
Switching an inode to another wb updates the target wb's dirty-I/O state, but no longer checks whether the source wb's dirty-I/O lists became empty. The check was lost when inode_io_list_del_locked(inode, old_wb) was removed to support tracking clean attached inodes.
If the last dirty inode is moved, WB_has_dirty_io remains set on the old wb and its bandwidth contribution remains in bdi->tot_write_bandwidth. This can keep an empty wb scheduled for periodic writeback and overstate the total bandwidth used to distribute writeback work.
Call wb_io_lists_depopulated() on the old wb after the batch of inode switches, while its list_lock is still held. This clears the flag and removes the bandwidth contribution if its dirty-I/O lists are empty.
--- fs/fs-writeback.c | 1 + 1 file changed, 1 insertion(+)
fs/fs-writeback.c +1 -0
@@ -511,6 +511,7 @@ static void process_inode_switch_wbs(struct bdi_writeback *new_wb, } } +wb_io_lists_depopulated (old_wb);spin_unlock (&new_wb->list_lock);spin_unlock (&old_wb->list_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1193/3318 sh: maple: Use the matching IRQ cookie when invoking free_irq()
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 e3ef44e77b40e3cecfb34757ff3c15ecceea0309 ]
The Maple DMA and VBLANK handlers are registered with &maple_unsupported_device as their dev_id. Passing NULL to free_irq() cannot find either action, so the handlers remain registered and the IRQ core warns.
Use the same cookie when freeing both handlers on the error paths.
--- drivers/sh/maple/maple.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/sh/maple/maple.c +2 -2
@@ -863,10 +863,10 @@ static int __init maple_bus_init(void)kmem_cache_destroy (maple_queue_cache); cleanup_bothirqs: -free_irq (HW_EVENT_VSYNC ,0 ); +free_irq (HW_EVENT_VSYNC , &maple_unsupported_device); cleanup_irq: -free_irq (HW_EVENT_MAPLE_DMA ,0 ); +free_irq (HW_EVENT_MAPLE_DMA , &maple_unsupported_device); cleanup_dma:free_pages ((unsigned long ) maple_sendbuf,MAPLE_DMA_PAGES );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1194/3318 nvmet: take subsys->lock while force-reconnecting in nvmet_subsys_attr_qid_max_store()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Zhang <[email protected]>
[ Upstream commit 9f426f14051181e251590783e68ce589a63e2b1c ]
nvmet_subsys_attr_qid_max_store() sets subsys->max_qid and then walks subsys->ctrls to force every controller to reconnect, but it holds only nvmet_config_sem (for write). subsys->ctrls is protected by subsys->lock:nvmet_alloc_ctrl() adds an entry under subsys->lock, and nvmet_ctrl_free() removes it under subsys->lock with list_del() + kfree() (not kfree_rcu). The free path takes no nvmet_config_sem, so the two locks are independent.
A controller teardown (host disconnect, keep-alive timeout or fatal error -> nvmet_sq_destroy() -> nvmet_ctrl_put() -> nvmet_ctrl_free()) can therefore list_del() an entry while qid_max_store() is iterating the list, corrupting the walk.
KASAN, concurrent "echo 128 > .../subsystems/<nqn>/attr_qid_max" racing nvme-loop controllers connecting and disconnecting, panics in seconds:
BUG: KASAN: null-ptr-deref in nvmet_subsys_attr_qid_max_store+0x10d/0x1b0 Read of size 8 at addr 0000000000000090 Call Trace: nvmet_subsys_attr_qid_max_store+0x10d/0x1b0 configfs_write_iter+0x1a7/0x250 vfs_write+0x5df/0x940 ksys_write+0xfd/0x1e0
(also seen as a general-protection fault dereferencing a LIST_POISON pointer at the same instruction.)
Take subsys->lock around the list_for_each_entry() loop, matching every other subsys->ctrls accessor. ->delete_ctrl() only queues asynchronous controller teardown, so it does not re-enter subsys->lock under the loop.
--- drivers/nvme/target/configfs.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/target/configfs.c +2 -0
@@ -1443,8 +1443,10 @@ static ssize_t nvmet_subsys_attr_qid_max_store(struct config_item *item, subsys->max_qid = qid_max;/* Force reconnect */ +mutex_lock (&subsys->lock);list_for_each_entry (ctrl, &subsys->ctrls, subsys_entry) ctrl->ops->delete_ctrl (ctrl); +mutex_unlock (&subsys->lock);up_write (&nvmet_config_sem);return cnt;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1195/3318 net: wwan: iosm: validate msg_head before indexing msg_ring
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Chao <[email protected]>
[ Upstream commit 46cbf85155e5451b6682ea0c17bc62ec564aec36 ]
ipc_protocol_free_msg_get() reads msg_head from shared memory and uses it directly as an index into msg_ring[]. If the head is out of range, the subsequent memset() writes beyond the message ring.
Validate head against IPC_MEM_MSG_ENTRIES before using it as an index. The ring is a circular buffer, so a value outside the valid range indicates a corrupted head pointer; report the error and fail the allocation instead of writing out of bounds.
--- drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c +5 -0
@@ -14,6 +14,11 @@ ipc_protocol_free_msg_get(struct iosm_protocol *ipc_protocol, int *index)u32 new_head = (head +1 ) %IPC_MEM_MSG_ENTRIES ;union ipc_mem_msg_entry *msg; +if (head >=IPC_MEM_MSG_ENTRIES ) { +dev_err (ipc_protocol->dev,"invalid message head %u" , head); +return NULL ; + } +if (new_head ==le32_to_cpu (ipc_protocol->p_ap_shm->msg_tail)) {dev_err (ipc_protocol->dev,"message ring is full" );return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1196/3318 tipc: fix broadcast sender hang on last acker departure
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 f4377bf85887f57b59abb5479f7660a81ffe4449 ]
TIPC group broadcast senders are blocked while a replicast still has outstanding member acks: tipc_group_bc_cong() returns true as long as grp->bc_ackers is non-zero, and clears *grp->open, which is what tipc_poll() uses to report EPOLLOUT (via tsk->group_is_open).
When the last outstanding acker departs before acking, tipc_group_delete_member() decrements grp->bc_ackers to zero but never restores *grp->open. As a result poll(EPOLLOUT) never fires again. A writer blocked in sendmsg() is only released if some other wakeup happens after the deletion: with TIPC_GROUP_MEMBER_EVTS the leave event delivery calls sk_data_ready() and wakes it, but without member events nothing does and it sleeps indefinitely, since the default send timeout is MAX_SCHEDULE_TIMEOUT.
Commit 99cc2a62e07a ("tipc: reject invalid and unexpected GRP_ACK_MSG to prevent bc_ackers underflow") already calls this out in its changelog as a pre-existing issue.
Restore the open state exactly on the 1->0 transition in the delete path, mirroring the GRP_ACK_MSG completion path, and invoke sk->sk_write_space() from tipc_sk_filter_rcv() when the group just became writable again.
Also make the ack accounting precise. The delete path used to test less(m->bc_acked, grp->bc_snd_nxt - 1), which also matches members that were never counted for the current replicast (JOINING/LEAVING members keep a stale bc_acked), and the GRP_ACK_MSG handler accepted an ack from any member whose bc_acked differed from the expected value. Either could zero bc_ackers on behalf of a member that owes nothing and silently void an ack still owed by a real acker. Track whether a member owes an ack for the current replicast in a new per-member bc_pending flag, set when the member is counted and cleared when its ack arrives, and use it both to accept an ack and to decide on deletion. bc_acked has no remaining user and is removed. Suggested by Tung Quang Nguyen.
This issue was discovered by Tencent CodeBuddy Security.
--- net/tipc/group.c | 19 ++++++++++--------- net/tipc/socket.c | 12 +++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-)
net/tipc/group.c +10 -9
@@ -74,7 +74,7 @@ struct tipc_member {u16 window;u16 bc_rcv_nxt;u16 bc_syncpt; -u16 bc_acked; +bool bc_pending; };struct tipc_group {
@@ -316,7 +316,6 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp, m->node = node; m->port = port; m->instance = instance; - m->bc_acked = grp->bc_snd_nxt -1 ; ret =tipc_group_add_to_tree (grp, m);if (ret <0 ) {kfree (m);
@@ -340,9 +339,12 @@ static void tipc_group_delete_member(struct tipc_group *grp,rb_erase (&m->tree_node, &grp->members); grp->member_cnt--; -/* Check if we were waiting for replicast ack from this member */ -if (grp->bc_ackers &&less (m->bc_acked, grp->bc_snd_nxt -1 )) - grp->bc_ackers--; +/* If this member owed an ack for the current replicast and it +* was the last one, restore the open state so blocked broadcast +* senders can proceed. +*/ +if (grp->bc_ackers && m->bc_pending && !--grp->bc_ackers) + *grp->open = true;list_del_init (&m->list);list_del_init (&m->small_win);
@@ -394,7 +396,6 @@ void tipc_group_update_member(struct tipc_member *m, int len)void tipc_group_update_bc_members (struct tipc_group *grp,int len,bool ack) { -u16 prev = grp->bc_snd_nxt -1 ;struct tipc_member *m;struct rb_node *n;u16 ackers =0 ;
@@ -403,8 +404,8 @@ void tipc_group_update_bc_members(struct tipc_group *grp, int len, bool ack) m = container_of(n, struct tipc_member, tree_node);if (tipc_group_is_receiver (m)) {tipc_group_update_member (m, len); - m->bc_acked = prev; ackers++; + m->bc_pending = ack; } }
@@ -800,9 +801,9 @@ void tipc_group_proto_rcv(struct tipc_group *grp, bool *usr_wakeup,if (!m || !grp->bc_ackers)return ; acked =msg_grp_bc_acked (hdr); -if (acked != grp->bc_snd_nxt || m->bc_acked == acked) +if (acked != grp->bc_snd_nxt || !m->bc_pending)return ; - m->bc_acked = acked; + m->bc_pending = false;if (--grp->bc_ackers)return ;list_del_init (&m->small_win);
net/tipc/socket.c +11 -1
@@ -2360,8 +2360,18 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb,if (unlikely (!msg_isdata (hdr)))tipc_sk_proto_rcv (sk, &inputq, xmitq); -if (unlikely (grp)) +if (unlikely (grp)) { +bool was_open = tsk->group_is_open; +tipc_group_filter_msg (grp, &inputq, xmitq); +/* A departing member may have held the last outstanding +* replicast ack, which can restore the open state inside +* tipc_group_filter_msg(); wake up senders blocked in +* poll()/write() if the group just became writable. +*/ +if (!was_open && tsk->group_is_open) + sk->sk_write_space (sk); + }if (unlikely (!grp) && mtyp ==TIPC_MCAST_MSG )tipc_mcast_filter_msg (net, &tsk->mc_method.deferredq, &inputq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1197/3318 exportfs: Release the get_name() directory file synchronously
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 49184daab01674ca400cbef58ee101dba6dbbb9d ]
get_name() opens the parent directory with dentry_open() and releases it with fput(). From a kernel thread, fput() defers the final __fput() to the delayed_fput work item. NFSD threads are kernel threads, and NFSD reaches get_name() through exportfs_decode_fh() whenever a file handle's dentry is not connected to the root.
On a filesystem with more directories than the dcache retains, nearly every READDIRPLUS needs a reconnect. The deferred releases arrive faster than the work item retires them, and each pending file pins the directory's readdir state. On ext4 that state is the htree fname cache for the last leaf block read. A 64-thread NFSv3 server under a parallel tree walk showed unreclaimable slab growing by about 90 MB per second, and the same workload on a 5.15 kernel ended in a global OOM.
Commit 5ff318f645eb ("nfsd: use __fput_sync() to avoid delayed closing of files.") stopped NFSD's own closes from feeding the delayed_fput queue but did not cover the exportfs reconnect path.
Release the file with __fput_sync(). get_name() opened the file itself, read-only, on a directory, so __fput() involves nothing that could wait on the caller.
Note for LTS backports: Kernels before v6.6 need the __fput_sync() call guarded by current->flags & PF_KTHREAD, with a plain fput() otherwise.
--- fs/exportfs/expfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/exportfs/expfs.c +5 -1
@@ -337,7 +337,11 @@ static int get_name(const struct path *path, char *name, struct dentry *child) } out_close: -fput (file); +/* +* @file is the read-only directory opened above, so __fput() +* cannot block on anything the caller holds. +*/ +__fput_sync (file); out:return error; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1198/3318 ucount: take the rlimit reference before checking the limit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nickolai Zeldovich <[email protected]>
[ Upstream commit b14fcabd34e02c40f72d3cd1e9bd4fd18df40ff1 ]
inc_rlimit_get_ucounts() takes the reference that pins a ucounts level while its rlimit count is non-zero only in the walk whose increment is the 0 -> 1 transition, and only after that walk passed the limit check. A walk that raises the count from zero and then fails the limit backs out without the reference, while a concurrent walk that raised it past one keeps its increment and never takes one either:
CPU0 (obeys the limit) CPU1 (overrides it)
new = add_return(1) -> 1
new = add_return(1) -> 2
new != 1, no get_ucounts() new > max -> dec_unwind
sub_return(1) -> 1 (no put)
The count is 1 with no reference held. When CPU1 drops its charge, dec_rlimit_put_ucounts() takes the count to 0 and puts a reference nobody took, which frees the live struct ucounts, and the user_namespace it pins, with kfree_rcu(). The mirror interleaving leaks the reference instead.
An unprivileged user reaches this on a kernel with CONFIG_USER_NS=y: in a user namespace with RLIMIT_SIGPENDING 0, one process taking synchronous SIGSEGVs (forced, so override_rlimit is set) races a second process in the same namespace and uid that queues real-time signals, which obey the limit. The two hold different sighand->siglock but charge the same per-namespace SIGPENDING ucounts. Unpatched, with rcuref debugging:
rcuref - imbalanced put()
WARNING: lib/rcuref.c:266 at rcuref_put_slowpath+0xf4/0x120 put_ucounts+0x5a/0x180 do_dec_rlimit_put_ucounts+0x70/0x90 __sigqueue_free+0x33/0xc0 get_signal+0x56f/0xd20 arch_do_signal_or_restart+0x87/0x380 irqentry_exit+0x243/0x650 asm_exc_page_fault+0x26/0x30
Take the reference on the 0 -> 1 transition before the limit is checked, so the walk that raises the count from zero owns that level's reference even when its request is rejected, and unwind a rejected level through do_dec_rlimit_put_ucounts(), which releases the reference when the count returns to 0. The get_ucounts() failure path is unchanged. With the patch the same interleaving, forced some 80000 times in a KASAN build, produces no warning and no KASAN report.
--- kernel/ucount.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
kernel/ucount.c +12 -9
@@ -318,23 +318,26 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,for (iter = ucounts; iter; iter = iter->ns->ucounts) {long new =atomic_long_add_return (1 , &iter->rlimit[type]); -if (new <0 || new > max) +/* +* Take the extra reference on the 0 -> 1 transition before the +* limit check: a rejected walk must not leave a concurrent one +* holding the surviving increment with no reference. +*/ +if (new ==1 && !get_ucounts (iter)) goto dec_unwind; +if (new <0 || new > max) { +/* undo iter too, releasing the reference taken above */ +do_dec_rlimit_put_ucounts (ucounts, iter->ns->ucounts, type); +return 0 ; + }if (iter == ucounts) ret = new;if (!override_rlimit) max =get_userns_rlimit_max (iter->ns, type); -/* -* Grab an extra ucount reference for the caller when -* the rlimit count was previously 0. -*/ -if (new !=1 ) -continue ; -if (!get_ucounts (iter)) - goto dec_unwind; }return ret; dec_unwind: +/* get_ucounts() failed for iter: undo iter without a put */ dec =atomic_long_sub_return (1 , &iter->rlimit[type]);WARN_ON_ONCE (dec <0 );do_dec_rlimit_put_ucounts (ucounts, iter, type);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1199/3318 i2c: acpi: Fix adapter reference leak in i2c_acpi_new_device_by_fwnode()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Ke <[email protected]>
[ Upstream commit a65917d0a22f9b10694853b725f9cd399fc3ef4d ]
i2c_acpi_new_device_by_fwnode() obtains an i2c_adapter through i2c_acpi_find_adapter_by_handle(). That helper uses bus_find_device() internally, so it returns the adapter with a reference held:
adapter = i2c_verify_adapter(dev);
if (!adapter)
put_device(dev);
return adapter;The reference is only put on the failure path inside that helper. The caller owns it otherwise. i2c_acpi_new_device_by_fwnode() never drops it, neither on the -EPROBE_DEFER path nor after i2c_new_client_device(), so every call leaks one reference on the adapter and the adapter can never be released.
i2c_new_client_device() does not consume that reference. It registers the new client with the adapter as its parent, and device_add() takes its own reference on the parent, which device_del() releases when the client goes away. The reference obtained by the lookup is a separate one and has to be dropped here.
i2c_acpi_notify() in the same file already does exactly this. It takes the adapter from the same helper, registers the client through i2c_acpi_register_device(), which calls i2c_new_client_device(), and then puts the reference.
i2c_new_client_device() gives the client its own reference on the adapter, so ours can be dropped unconditionally.
Found by code review.
--- drivers/i2c/i2c-core-acpi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/i2c/i2c-core-acpi.c +5 -1
@@ -545,6 +545,7 @@ struct i2c_client *i2c_acpi_new_device_by_fwnode(struct fwnode_handle *fwnode, {struct i2c_acpi_lookup lookup;struct i2c_adapter *adapter; +struct i2c_client *client;struct acpi_device *adev;LIST_HEAD (resource_list);int ret;
@@ -572,7 +573,10 @@ struct i2c_client *i2c_acpi_new_device_by_fwnode(struct fwnode_handle *fwnode,if (!adapter)return ERR_PTR (-EPROBE_DEFER ); -return i2c_new_client_device (adapter, info); + client =i2c_new_client_device (adapter, info); +put_device (&adapter->dev); + +return client; }EXPORT_SYMBOL_GPL (i2c_acpi_new_device_by_fwnode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1200/3318 i2c: designware: queue only one read command for block reads
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Navon John Lukose <[email protected]>
[ Upstream commit 73dae605cad7921800677d982bfaeb81cc930dec ]
i2c_dw_xfer_msg() pre-queues up to rx_fifo_depth read commands based on the initial msg.len. For I2C_M_RECV_LEN transfers the real length is unknown until the first byte arrives and i2c_dw_recv_len() runs. When a large initial length is passed, the surplus pre-queued reads leave rx_outstanding non-zero after i2c_dw_recv_len() adjusts msg.len, so the completion condition is never met and the transfer times out. In a loop, this repeatedly times out the controller and disrupts unrelated driver-bound devices on the same adapter.
Queue only one read command while I2C_M_RECV_LEN is pending. i2c_dw_recv_len() re-enables TX_EMPTY, and the rest are queued once the device-reported length is known.
--- drivers/i2c/busses/i2c-designware-master.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/i2c/busses/i2c-designware-master.c +8 -0
@@ -539,6 +539,14 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)if (dev->rx_outstanding >= dev->rx_fifo_depth)break ; +/* +* For block reads, queue only the length +* byte until i2c_dw_recv_len() runs. +*/ +if ((flags &I2C_M_RECV_LEN ) && + buf_len < msgs[dev->msg_write_idx].len) +break ; +regmap_write (dev->map,DW_IC_DATA_CMD , cmd |0x100 ); rx_limit--;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1201/3318 tpm: tpm_nsc: fix NULL pointer dereference on init failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit 1900449684cf71427a51e0bb1d7914c0c8b39152 ]
tpm_nsc_remove() is used as the release callback of the hand-created platform device and dereferences the chip drvdata unconditionally. If init fails before tpmm_chip_alloc() (e.g. request_region() cannot claim the ports), the error path drops the last device reference and the release callback runs with chip == NULL, crashing module init.
Return early when the chip has not been created yet.
--- drivers/char/tpm/tpm_nsc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_nsc.c +6 -1
@@ -258,7 +258,12 @@ static struct platform_device *pdev = NULL;static void tpm_nsc_remove (struct device *dev) {struct tpm_chip *chip =dev_get_drvdata (dev); -struct tpm_nsc_priv *priv =dev_get_drvdata (&chip->dev); +struct tpm_nsc_priv *priv; + +if (!chip) +return ; + + priv =dev_get_drvdata (&chip->dev);tpm_chip_unregister (chip);release_region (priv->base,2 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1202/3318 tpm: tpm_nsc: stop using the cleanup callback as dev.release
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit df0ef271087623439a1e900f323ed2a57204706d ]
tpm_nsc_remove() is called explicitly from cleanup_nsc() and also runs as the platform device release callback on the final platform_device_put(), so the cleanup executes twice on module exit; the second invocation operates on a chip that has already been freed by the devm cleanup, and the I/O region is released twice.
Overwriting the release callback installed by platform_device_alloc() also keeps platform_device_release() from running, leaking the platform object allocation.
Leave the default release callback in place; the explicit call in cleanup_nsc() remains the single cleanup point.
--- drivers/char/tpm/tpm_nsc.c | 1 - 1 file changed, 1 deletion(-)
drivers/char/tpm/tpm_nsc.c +0 -1
@@ -326,7 +326,6 @@ static int __init init_nsc(void) pdev->num_resources =0 ; pdev->dev.driver = &nsc_drv.driver; - pdev->dev.release = tpm_nsc_remove;if ((rc =platform_device_add (pdev)) <0 ) goto err_put_dev;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1203/3318 tpm: fix zero-length read discarding the pending response
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit 6fc1b05077b8ac7c3193616f0bc419f6185988c6 ]
POSIX requires that a read() with a count of zero returns zero and has no other effects. tpm_common_read() treats such a call as a consumed response: it marks the pending response as read and drops it, so the response can never be retrieved; subsequent reads return zero and the next write() is allowed to overwrite the response buffer, silently breaking the command/response pairing of the TPM character devices.
Return early when the caller passes a zero count, leaving any pending response untouched for the next read. A zero-length read will not report a deferred asynchronous error; POSIX permits read() to skip error detection for a zero count.
--- drivers/char/tpm/tpm-dev-common.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/char/tpm/tpm-dev-common.c +3 -0
@@ -131,6 +131,9 @@ ssize_t tpm_common_read(struct file *file, char __user *buf,ssize_t ret_size =0 ;int rc; +if (!size) +return 0 ; +mutex_lock (&priv->buffer_mutex);if (priv->response_length) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1204/3318 parisc: eisa_enumerator: Fix out-of-bounds reads of the EEPROM buffer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jean Delu <[email protected]>
[ Upstream commit c0a3e153804f0c14f4159ddbd2b73483c9cb3577 ]
eisa_enumerator() trusts the contents of the EISA EEPROM. The number of slots is read from the EEPROM header and used to access the slot records at HPEE_SLOT_INFO(i) = 20 + 48*i within the fixed-size eeprom_buf (HPEE_MAX_LENGTH, 8192 bytes) without any bound check. As struct eeprom_eisa_slot_info is 48 bytes, only 170 records fit into the buffer, but num_slots is a u8 and may be up to 255, so a corrupted EEPROM makes the code read up to about 4 kB past the end of the buffer (e.g. record 254 is accessed at offset 20 + 48*254 = 12212).
parse_slot_config() has the same kind of problem: it clamps config_data_length against HPEE_MAX_LENGTH but does not take config_data_offset into account, so the parser can walk past the end of the buffer even when the offset itself is valid.
Clamp the number of slots so that all slot records fit into the buffer, and hand the number of bytes actually available to parse_slot_config() and bound the parse by it.
--- drivers/parisc/eisa_enumerator.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/parisc/eisa_enumerator.c +12 -3
@@ -311,6 +311,7 @@ static int configure_function(const unsigned char *buf, int *more)static int parse_slot_config (int slot,const unsigned char *buf, +unsigned int buflen,struct eeprom_eisa_slot_info *es,struct resource *io_parent,struct resource *mem_parent)
@@ -333,8 +334,8 @@ static int parse_slot_config(int slot,printk (KERN_INFO "EISA slot %d: %s %s " , slot, board, es->flags&HPEE_FLAG_BOARD_IS_ISA ?"ISA" :"EISA" ); - maxlen = es->config_data_length <HPEE_MAX_LENGTH ? - es->config_data_length :HPEE_MAX_LENGTH ; +/* never parse beyond the data that is actually in the buffer */ + maxlen = min_t(unsigned int, es->config_data_length, buflen);while ((pos < maxlen) && (num_func <= es->num_functions)) { pos+=configure_function (buf+pos, &function_len);
@@ -491,6 +492,13 @@ int eisa_enumerator(unsigned long eeprom_addr,printk (KERN_INFO "Enumerating EISA bus\n" ); eh = (struct eeprom_header *)(eeprom_buf); +/* +* The EEPROM contents are not to be trusted: clamp the number of +* slots so that all slot records fit into eeprom_buf. +*/ + eh->num_slots =min_t (u8, eh->num_slots, + (HPEE_MAX_LENGTH -sizeof (*eh)) / +sizeof (struct eeprom_eisa_slot_info ));for (i=0 ;i<eh->num_slots;i++) {struct eeprom_eisa_slot_info *es;
@@ -503,7 +511,8 @@ int eisa_enumerator(unsigned long eeprom_addr,if (es->config_data_offset <HPEE_MAX_LENGTH ) {if (parse_slot_config (i+1 , &eeprom_buf[es->config_data_offset], - es, io_parent, mem_parent)) { +HPEE_MAX_LENGTH - es->config_data_offset, + es, io_parent, mem_parent)) {return -1 ; } }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1205/3318 ASoC: tlv320aic32x4: Prevent division by zero in divider callbacks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Kazinsky <[email protected]>
[ Upstream commit 8cf9607d2d855629260fc78e6b54ea7a98525708 ]
A zero rate requested through clk_set_rate() or clk_round_rate() reaches clk_aic32x4_div_determine_rate() when the minimum rate is zero. Clamping the requested rate to the allowed range leaves it unchanged, causing division by zero when calculating the divisor.
A zero parent rate can also cause division by zero in determine_rate(). For example, if reading a parent divider's register fails, clk_aic32x4_div_recalc_rate() returns zero, which the clock framework caches as the parent's rate. A subsequent rate request for a child divider receives this value in best_parent_rate. With a nonzero requested rate, the calculated divisor is zero. It passes the existing upper-bound check and causes division by zero in the resulting rate calculation.
The set_rate callback can receive a zero rate when an ancestor's rate changes. clk_calc_subtree() calculates descendant rates through recalc_rate() without calling their determine_rate callbacks. If reading a descendant divider's register fails, clk_aic32x4_div_recalc_rate() returns zero. This becomes the descendant's new_rate, which clk_change_rate() passes to clk_aic32x4_div_set_rate(), causing division by zero.
Reject zero rates in both callbacks and reject a zero divisor in clk_aic32x4_div_determine_rate().
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- sound/soc/codecs/tlv320aic32x4-clk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
sound/soc/codecs/tlv320aic32x4-clk.c +7 -1
@@ -320,6 +320,9 @@ static int clk_aic32x4_div_set_rate(struct clk_hw *hw, unsigned long rate,struct clk_aic32x4 *div =to_clk_aic32x4 (hw);u8 divisor; +if (!rate) +return -EINVAL ; + divisor =DIV_ROUND_UP (parent_rate, rate);if (divisor >AIC32X4_DIV_MAX )return -EINVAL ;
@@ -333,8 +336,11 @@ static int clk_aic32x4_div_determine_rate(struct clk_hw *hw, {unsigned long divisor; +if (!req->rate) +return -EINVAL ; + divisor =DIV_ROUND_UP (req->best_parent_rate, req->rate); -if (divisor >AIC32X4_DIV_MAX ) +if (!divisor || divisor >AIC32X4_DIV_MAX )return -EINVAL ; req->rate =DIV_ROUND_UP (req->best_parent_rate, divisor);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1206/3318 i2c: mt7621: fix copying uninitialized kernel stack with reduced page_len
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Marangi <[email protected]>
[ Upstream commit b7fd977fec0d3f2bdd4f13bb59949c817a365652 ]
When a page_len is less than 5 bytes in mtk_i2c_xfer, uninitialized kernel stack data is copied and written to REG_SM0D1_REG. Equally on the read part, an unnecessary read is done.
Guard these extra copy/write and read for the page_len to fix leaking uninitialized stack memory.
--- drivers/i2c/busses/i2c-mt7621.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-mt7621.c +6 -3
@@ -144,7 +144,6 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,u16 addr;int i, j, ret, len, page_len;u32 cmd; -u32 data[2 ]; i2c =i2c_get_adapdata (adap);
@@ -190,6 +189,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,/* transfer data */ for (len = pmsg->len, j =0 ; len >0 ; len -=8 , j +=8 ) { +u32 data[2 ] = { }; + page_len = (len >=8 ) ?8 : len;if (pmsg->flags &I2C_M_RD ) {
@@ -198,7 +199,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, }else {memcpy (data, &pmsg->buf[j], page_len);iowrite32 (data[0 ], i2c->base +REG_SM0D0_REG ); -iowrite32 (data[1 ], i2c->base +REG_SM0D1_REG ); +if (page_len >4 ) +iowrite32 (data[1 ], i2c->base +REG_SM0D1_REG ); cmd =SM0CTL1_WRITE ; }
@@ -208,7 +210,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,if (pmsg->flags &I2C_M_RD ) { data[0 ] =ioread32 (i2c->base +REG_SM0D0_REG ); - data[1 ] =ioread32 (i2c->base +REG_SM0D1_REG ); +if (page_len >4 ) + data[1 ] =ioread32 (i2c->base +REG_SM0D1_REG );memcpy (&pmsg->buf[j], data, page_len); }else {if (!(pmsg->flags &I2C_M_IGNORE_NAK )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1207/3318 spi: zynq-qspi: fix address buffer corruption and support 4-byte address
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pufan Jin <[email protected]>
[ Upstream commit dc5ca34f5e8dc10c566ef39aa3b1a201a17ca734 ]
In zynq_qspi_exec_mem_op(), when transmitting address bytes, the driver iterates over op->addr.nbytes and populates xqspi->txbuf[i]. However, xqspi->txbuf is never re-assigned before populating the address, meaning it still points to (u8 *)&op->cmd.opcode from the command phase.
This causes two severe issues:
1. Memory corruption: Writing into xqspi->txbuf writes past the opcode buffer on the stack (which was passed as const struct spi_mem_op *). If opcode is zero, xqspi->txbuf is uninitialized.
2. In zynq_qspi_supports_op(), operations with op->addr.nbytes > 3 are rejected. When paired with SPI NOR flashes larger than 16MB (such as Winbond W25Q256), spi_nor_spimem_check_read_pp_op() tests 4-byte address support, which fails and causes spi_nor_select_read() to drop all read capabilities, failing probe with -EINVAL (-22).
The Zynq-7000 QSPI controller hardware in manual I/O mode natively supports transmitting 1 to 4 address bytes via its TXD FIFO registers (ZYNQ_QSPI_TXD_00_00_OFFSET).
Fix this by introducing a local opaddr[4] buffer in zynq_qspi_exec_mem_op() and explicitly setting xqspi->txbuf = opaddr before populating address bytes. Also allow up to 4 address bytes in zynq_qspi_supports_op().
--- drivers/spi/spi-zynq-qspi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/spi/spi-zynq-qspi.c +7 -6
@@ -229,11 +229,10 @@ static bool zynq_qspi_supports_op(struct spi_mem *mem,return false;/* -* The number of address bytes should be equal to or less than 3 bytes. +* The number of address bytes should be equal to or less than 4 bytes. */ -if (op->addr.nbytes >3 ) +if (op->addr.nbytes >4 )return false; -return true; }
@@ -524,6 +523,7 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) {struct zynq_qspi *xqspi =spi_controller_get_devdata (mem->spi->controller); +u8 opaddr[4 ]__aligned(4) ;int err =0 , i;u8 *tmpbuf;
@@ -549,12 +549,13 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem, }if (op->addr.nbytes) { -for (i =0 ; i < op->addr.nbytes; i++) { - xqspi->txbuf[i] = op->addr.val >> +for (i =0 ; i < op->addr.nbytes; i++) + opaddr[i] = op->addr.val >> (8 * (op->addr.nbytes - i -1 )); - }reinit_completion (&xqspi->data_completion); + xqspi->txbuf = opaddr; + xqspi->rxbuf =NULL ; xqspi->tx_bytes = op->addr.nbytes; xqspi->rx_bytes = op->addr.nbytes;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1208/3318 posix-cpu-timers: Fix pid refcount leak in do_cpu_nanosleep() signal path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit 8ccd731b63a0183ca2b0e18f3ca15864b3f37eda ]
do_cpu_nanosleep() sleeps on a temporary k_itimer whose reference on the target's struct pid is taken by posix_cpu_timer_create() and dropped by posix_cpu_timer_del(). When a signal ends the sleep, the timer is disarmed with posix_cpu_timer_set(), but posix_cpu_timer_del() is only called for a result of 0 or TIMER_RETRY. If the target thread or process has exited in the meantime, timer_lock_sighand() finds no task, posix_cpu_timer_set() returns -ESRCH and the pid reference is leaked.
An unprivileged user can trigger this: sleep on the CPU clock of a thread, let that thread exit, then signal the sleeper. Each round leaks one struct pid. Repeating it exhausts unreclaimable slab memory within minutes:
Out of memory: Killed process 150 (poc) total-vm:789292kB, anon-rss:484kB
Kernel panic - not syncing: System is deadlocked on memory
Fix this by also calling posix_cpu_timer_del() on -ESRCH. With the target gone, the deletion is safe. It finds no task either and only drops the pid reference.
--- kernel/time/posix-cpu-timers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/posix-cpu-timers.c +2 -2
@@ -1607,8 +1607,8 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,*/ expires =cpu_timer_getexpires (&timer.it.cpu); error =posix_cpu_timer_set (&timer,0 , &zero_it, &it); -if (!error) { -/* Timer is now unarmed, deletion can not fail. */ +if (error !=TIMER_RETRY ) { +/* Unarmed or target gone (-ESRCH), deletion can not fail. */ posix_cpu_timer_del (&timer); }else {while (error ==TIMER_RETRY ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1209/3318 timekeeping: Update offsets on sequence counter retry in ktime_get_update_offsets_now()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh (Schneider Electric) <[email protected]>
[ Upstream commit 6541fbc942f3b63bb8bd44e34eee6223e0abe719 ]
The sequence counter of the cwsseq target is modified during the sequence counter loop. If the loop retries, cwsseq will now match but the offsets contain the values from the previous loop iteration. These are not guaranteed to be consistent in themselves or with the current loops "now.
Save the target's original sequence counter value so that the update also happens on loop retries.
--- kernel/time/timekeeping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/timekeeping.c +2 -1
@@ -2315,6 +2315,7 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, ktime_t *offs_boot, ktime_t *offs_tai) {struct timekeeper *tk = &tk_core.timekeeper; +u32 cwsseq_orig = *cwsseq;unsigned int seq;ktime_t base;u64 nsecs;
@@ -2326,7 +2327,7 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, nsecs =timekeeping_get_ns (&tk->tkr_mono); base =ktime_add_ns (base, nsecs); -if (*cwsseq != tk->clock_was_set_seq) { +if (cwsseq_orig != tk->clock_was_set_seq) { *cwsseq = tk->clock_was_set_seq; *offs_real = tk->offs_real; *offs_boot = tk->offs_boot;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1210/3318 cgroup: dont kill migrated processes through their exiting threads
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 5f4a3f743acc96987ae5c2e966947942c34ba56c ]
Since commit da13e0e72a73 ("cgroup: fix cgroup.kill for exited thread group leader"), __cgroup_kill() visits every thread in the cgroup and sends SIGKILL with PIDTYPE_TGID, so each visited thread takes down its whole thread group.
A thread that has started exiting can stay in a cgroup after its process has been moved out of it. cgroup_migrate_add_task() skips PF_EXITING tasks, and the thread is only unlinked by cgroup_task_dead() after its final context switch. mm_release() clears the thread's clear_child_tid word and wakes the joiner well before that, so pthread_join() can return while the thread is still in the old cgroup.
If cgroup.kill is written in that window, __cgroup_kill() finds the exiting thread and complete_signal() passes the group-wide SIGKILL on to a live thread, killing a process that already left the cgroup. The cgroup selftest test_stress.sh runs into this: test_cgcore_proc_migration() joins its threads, moves itself back to the root cgroup, and cg_destroy() falls back to cgroup.kill on the old cgroup when rmdir() fails with EBUSY, so test_core kills itself. KernelCI has been reporting "with_stress.sh: line 94: ... Killed" on several arm64 boards since the commit reached linux-next.
Keep visiting every thread, but go back to sending SIGKILL to the thread that was found. A SIGKILL sent to a live thread still kills its whole thread group, so both cases fixed by that commit stay fixed, and task_can_queue_signal() drops one sent to a thread that is already exiting.
--- kernel/cgroup/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup/cgroup.c +1 -1
@@ -3986,7 +3986,7 @@ static void __cgroup_kill(struct cgroup *cgrp)if (__fatal_signal_pending (task))continue ; -do_send_sig_info (SIGKILL ,SEND_SIG_NOINFO , task,PIDTYPE_TGID ); +send_sig (SIGKILL , task,0 ); }css_task_iter_end (&it); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1211/3318 veth: fix stale peer max_mtu on XDP program replacement
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: yanxia <[email protected]>
[ Upstream commit c955325db639e9503941227e14e1f1ccc99442a1 ]
veth_xdp_set() calculates the peer MTU limit from the incoming program's XDP fragment capability, but only stores it when no program was attached. Replacing a program with one having a different fragment capability therefore leaves the peer's max_mtu stale.
Replacing a regular program with an xdp.frags program keeps rejecting otherwise valid jumbo MTUs. The opposite replacement leaves a larger limit in place and permits MTUs which a fresh attachment of the regular program would reject.
Update peer->max_mtu after every successful attachment or replacement. Keep the GSO feature update conditional on the first attachment.
Found during review of the XDP replacement path and confirmed with native XDP on an isolated veth pair. Before the fix, direct replacement rejects MTU 9000 after switching to xdp.frags, and accepts it after switching back to a regular program. Detaching and attaching instead produces the expected results in both directions.
UML tests on net reproduce the problem before this change and match the detach/attach controls afterwards, with both devices up or down and with either endpoint receiving XDP. Failed replacements preserve the previous state; same-type replacements and detach also behave as expected. Small-frame traffic passes in the devices-up cases.
--- drivers/net/veth.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/veth.c +2 -3
@@ -1643,10 +1643,9 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, } } -if (!old_prog) { +if (!old_prog) peer->hw_features &= ~NETIF_F_GSO_SOFTWARE ; - peer->max_mtu = max_mtu; - } + peer->max_mtu = max_mtu;xdp_features_set_redirect_target (peer, true); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1212/3318 scsi: ufs: bsg: Complete the job on error
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 cc0ce3fe8fac073ecded4f32c8ee5b89da1397e8 ]
When ufs_bsg_request() fails, it returns a non-zero status without calling bsg_job_done(). bsg_queue_rq() then ends the request with BLK_STS_IOERR without running bsg_complete(), leaking the job's device reference and mapped scatterlists.
Always complete the job via bsg_job_done() and return 0, matching other BSG transports. Requests failing with a negative errno now return it from SG_IO with the 4-byte result in the reply, while positive status codes still return 0 from SG_IO with the reply header.
--- drivers/ufs/core/ufs_bsg.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/ufs/core/ufs_bsg.c +3 -5
@@ -194,14 +194,12 @@ static int ufs_bsg_request(struct bsg_job *job)ufshcd_rpm_put_sync (hba);kfree (buff); bsg_reply->result = ret; -/* complete the job here only if no error */ -if (ret ==0 ) { +if (ret ==0 ) job->reply_len = rpmb ?sizeof (struct ufs_rpmb_reply ) :sizeof (struct ufs_bsg_reply ); -bsg_job_done (job, ret, bsg_reply->reply_payload_rcv_len); - } +bsg_job_done (job, ret, bsg_reply->reply_payload_rcv_len); -return ret; +return 0 ; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1213/3318 scsi: ufs: bsg: Clear the reply buffer before use
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 2e63ac76cc08ea376ba61fef52f7b7849e35024d ]
The reply buffer is allocated once per tag and reused. Requests that complete with a positive status do not fill all of it, so user space receives bytes from an earlier request on the same tag.
Clear the whole reply buffer on entry to ufs_bsg_request().
--- drivers/ufs/core/ufs_bsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufs_bsg.c +1 -1
@@ -142,7 +142,7 @@ static int ufs_bsg_request(struct bsg_job *job)int ret;bool rpmb = false; - bsg_reply->reply_payload_rcv_len =0 ; +memset (job->reply,0 , job->reply_len);ufshcd_rpm_get_sync (hba);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1214/3318 scsi: ufs: core: Clear stale UIC result byte before peer DME retries
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 e4a9b7640914b248eb7537d4507aa42db080586a ]
Peer DME get and set retry a failed attempt with the same struct uic_command. UIC completion ORs the ConfigResultCode into argument2[7:0], and nothing clears it before the next attempt. Once an attempt fails, every retry keeps reporting that error code, even when the device returns success, so a transient failure becomes a hard failure after three retries. Each such retry also triggers the WARN_ON_ONCE() in ufshcd_dispatch_uic_cmd(). In ufshcd_dme_set_attr(), ufshcd_uic_cmd_compl() also overwrites argument3 with the register readback before the next attempt.
Clear the result byte and restore argument3 in ufshcd_dme_set_attr() when an attempt fails.
--- drivers/ufs/core/ufshcd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +7 -2
@@ -4116,9 +4116,12 @@ int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,do {/* for peer attributes we retry upon failure */ ret =ufshcd_send_uic_cmd (hba, &uic_cmd); -if (ret) +if (ret) {dev_dbg (hba->dev,"%s: attr-id 0x%x val 0x%x error code %d\n" , set,UIC_GET_ATTR_ID (attr_sel), mib_val, ret); + uic_cmd.argument2 &= ~MASK_UIC_COMMAND_RESULT ; + uic_cmd.argument3 = mib_val; + } }while (ret && peer && --retries);if (ret)
@@ -4183,9 +4186,11 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,do {/* for peer attributes we retry upon failure */ ret =ufshcd_send_uic_cmd (hba, &uic_cmd); -if (ret) +if (ret) {dev_dbg (hba->dev,"%s: attr-id 0x%x error code %d\n" , get,UIC_GET_ATTR_ID (attr_sel), ret); + uic_cmd.argument2 &= ~MASK_UIC_COMMAND_RESULT ; + } }while (ret && peer && --retries);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1215/3318 scsi: libiscsi_tcp: Prevent R2T range check overflow
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratnaker Gautam <[email protected]>
[ Upstream commit eb7aa7fd673fdc1582223cd133bcc5f54e7af19f ]
An iSCSI target controls the R2T data offset and length as 32-bit values. Adding them before comparing the result with the SCSI data buffer length can wrap. An R2T with offset 1 and length U32_MAX then passes the check for a 4096-byte write.
The transmit path treats the wrapped range as valid, exhausts the command scatterlist, and dereferences the NULL next entry in iscsi_tcp_segment_done().
Check the offset first, then compare the length with the remaining bytes in the data buffer.
--- drivers/scsi/libiscsi_tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/libiscsi_tcp.c +2 -1
@@ -612,7 +612,8 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr) data_length, session->max_burst); data_offset =be32_to_cpu (rhdr->data_offset); -if (data_offset + data_length > task->sc->sdb.length) { +if (data_offset > task->sc->sdb.length || + data_length > task->sc->sdb.length - data_offset) { iscsi_conn_printk(KERN_ERR, conn, "invalid R2T with data len %u at offset %u " "and total length %d\n", data_length,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1216/3318 scsi: ufs: core: Remove an always-false WARN_ONCE()
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 cd37a69c367b6a5f685db0ac7d01f08545081a30 ]
The WARN_ONCE() in ufshcd_poll() can never fire. completed_reqs is set to ~tr_doorbell & hba->outstanding_reqs on the line above, and hba->outstanding_reqs cannot change in between because ufshcd_poll() holds hba->outstanding_lock. So completed_reqs & ~hba->outstanding_reqs is always zero. Remove it. No functional change.
--- drivers/ufs/core/ufshcd.c | 3 --- 1 file changed, 3 deletions(-)
drivers/ufs/core/ufshcd.c +0 -3
@@ -5621,9 +5621,6 @@ 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; -WARN_ONCE (completed_reqs & ~hba->outstanding_reqs, -"completed: %#lx; outstanding: %#lx\n" , completed_reqs, - 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);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1217/3318 compat: avoid double rounding in times()
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 6b30c39a5e333cfb1475acf0f73de6ef954eea8a ]
do_sys_times() already converts CPU time to USER_HZ ticks. The compat path converts each value back to jiffies before converting it to COMPAT_USER_HZ. This round trip can lose precision even when the two userspace rates match.
With HZ=250 and USER_HZ=COMPAT_USER_HZ=100, one user tick becomes two jiffies and then zero compat ticks. Every odd tick count loses one tick, so any of the four tms fields can underreport CPU time by an additional 10 ms.
Return the value directly when the native and compat units match. Keep the existing conversion for differing rates.
--- kernel/sys.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/sys.c +3 -0
@@ -1036,6 +1036,9 @@ SYSCALL_DEFINE1(times, struct tms __user *, tbuf)#ifdef CONFIG_COMPAT static compat_clock_t clock_t_to_compat_clock_t (clock_t x) { +if (USER_HZ ==COMPAT_USER_HZ ) +return x; +return compat_jiffies_to_clock_t (clock_t_to_jiffies (x)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1218/3318 ocfs2: snapshot the dentry name while tracing file release
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 5898987d4a92b70ae73fd8355cc3a388b4dfa4e6 ]
ocfs2_file_release() passes the live dentry name and length to a trace event while holding oi->ip_lock. This lock protects the open count and delays RCU reclamation of external names, but it does not serialize name changes during rename. The dentry can switch between inline and external names, and a separately loaded length can describe a different name.
The ocfs2__file_ops event sizes and copies its __string separately. A concurrently rewritten inline name need not remain consistent between those operations. External names can also be selected at this call site; the existing spinlock critical section protects their allocation lifetime, while a snapshot additionally pairs a stable name with its length.
Take a name snapshot before acquiring oi->ip_lock and release it after dropping the lock. Keep the trace call and open-count argument inside the original critical section. Cache the event-enabled check so the snapshot stays paired even if tracing is toggled meanwhile.
--- fs/ocfs2/file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
fs/ocfs2/file.c +13 -5
@@ -140,18 +140,26 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)static int ocfs2_file_release (struct inode *inode,struct file *file) {struct ocfs2_inode_info *oi =OCFS2_I (inode); +struct dentry *dentry = file->f_path.dentry; +struct name_snapshot name; +bool trace_enabled =trace_ocfs2_file_release_enabled (); + +if (trace_enabled) +take_dentry_name_snapshot (&name, dentry);spin_lock (&oi->ip_lock);if (!--oi->ip_open_count) oi->ip_flags &= ~OCFS2_INODE_OPEN_DIRECT ; -trace_ocfs2_file_release (inode, file, file->f_path.dentry, - oi->ip_blkno, - file->f_path.dentry->d_name.len, - file->f_path.dentry->d_name.name, - oi->ip_open_count); +if (trace_enabled) +trace_ocfs2_file_release (inode, file, dentry, + oi->ip_blkno, name.name.len, + name.name.name, oi->ip_open_count);spin_unlock (&oi->ip_lock); +if (trace_enabled) +release_dentry_name_snapshot (&name); +ocfs2_free_file_private (inode, file);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1219/3318 ocfs2/cluster: remove zero-address nodes from IP tree on teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 5dd57e77eff4ba3e85b3df126a55417c88245708 ]
o2nm_node_ipv4_address_store() accepts 0.0.0.0. It sets O2NM_NODE_ATTR_ADDRESS and links nd_ip_node into cl_node_ip_tree under cl_nodes_lock, but o2nm_node_group_drop_item() uses nd_ipv4_address as a membership test. A zero address therefore leaves the rbtree node linked when config_item_put() releases and frees struct o2nm_node. A later address store or IP lookup can then walk the stale node and dereference freed memory.
During teardown, drop_item takes cl_nodes_lock, skips rb_erase() for the zero key, and then calls config_item_put(). A later o2nm_node_ipv4_address_store() duplicate check or o2nm_get_node_by_ip() lookup takes the same lock and walks the stale cl_node_ip_tree entry. Use O2NM_NODE_ATTR_ADDRESS for teardown so every published nd_ip_node is erased before configfs can release the node, without rejecting 0.0.0.0 or changing lookup semantics.
--- fs/ocfs2/cluster/nodemanager.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/nodemanager.c +5 -2
@@ -626,8 +626,11 @@ static void o2nm_node_group_drop_item(struct config_group *group,write_lock (&cluster->cl_nodes_lock); -/* XXX sloppy */ -if (node->nd_ipv4_address) +/* +* 0.0.0.0 is a valid configured address, so nd_ipv4_address does +* not tell us whether nd_ip_node was published in the IP tree. +*/ +if (test_bit (O2NM_NODE_ATTR_ADDRESS , &node->nd_set_attributes))rb_erase (&node->nd_ip_node, &cluster->cl_node_ip_tree);/* nd_num might be 0 if the node number hasn't been set.. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1220/3318 mm/madvise: add cond_resched() in THP branch of madvise_cold_or_pageout_pte_range()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Yang <[email protected]>
[ Upstream commit f5cfc8e3b20ad71949a1e5623ff45882c063a71b ]
During stress testing with stress-ng on a 256-CPU system, a softlockup was observed when madvise(MADV_COLD) was called on a 31GB memory region backed by transparent hugepages. The region contains 15935 THP PMD entries, and the softlockup was triggered after 14485 of them had been processed.
The THP branch of madvise_cold_or_pageout_pte_range() has no scheduling point. walk_pmd_range() invokes it once per 2MB PMD entry with no cond_resched() anywhere in the loop. Each iteration calls pmdp_invalidate() which issues a synchronous TLB shootdown (dsb ish) waiting for all CPUs to acknowledge. This operation can be time-consuming under heavy system load, causing the accumulated time across all PMD entries to exceed the softlockup threshold (20s) and panic when softlockup_panic=1. On a CONFIG_PREEMPT_NONE=y kernel, there is no other opportunity to reschedule during this entire traversal.
The regular PTE path already has an unconditional cond_resched() at the function tail (introduced by commit 9c276cc65a58 ("mm: introduce MADV_COLD") and commit 1a4e58cce84e ("mm: introduce MADV_PAGEOUT") when MADV_COLD and MADV_PAGEOUT were first introduced) and a conditional one inside the loop (commit b2f557a21bc8 ("mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()")). The THP branch never received equivalent treatment.
Fix by adding cond_resched() at the huge_unlock exit path after spin_unlock(ptl) and reclaim_pages(), which is the single exit point for all goto paths in the THP branch.
Crash log:
watchdog: BUG: soft lockup - CPU#63 stuck for 23s! [stress-ng-vm:1665914] ... Call trace: pmdp_invalidate+0x48/0x68 madvise_cold_or_pageout_pte_range+0x84c/0xb00 walk_pmd_range.isra.0+0x1ac/0x3b0 walk_pud_range+0x120/0x190 walk_pgd_range+0x170/0x1b8 __walk_page_range+0x184/0x198 walk_page_range_vma+0x94/0x128 madvise_cold+0xd8/0x198 madvise_vma_behavior+0x234/0x638 madvise_walk_vmas.constprop.0+0xdc/0x210 madvise_do_behavior+0xa8/0x328 do_madvise+0xd8/0x140 __arm64_sys_madvise+0x2c/0xe0
--- mm/madvise.c | 1 + 1 file changed, 1 insertion(+)
mm/madvise.c +1 -0
@@ -428,6 +428,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,spin_unlock (ptl);if (pageout)reclaim_pages (&folio_list); +cond_resched ();return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1221/3318 riscv: mm: exclude invalid THP PMDs from page table check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunhui Cui <[email protected]>
[ Upstream commit bdda2887cbf3937c2d0f56589c2124c4167324e1 ]
RISC-V THP splitting uses a temporary invalid PMD state where pmd_mkinvalid() clears _PAGE_PRESENT and _PAGE_PROT_NONE but leaves _PAGE_LEAF set so the MM code can still recognize the PMD as a THP split in-progress entry.
That temporary state no longer describes a user-accessible mapping, but page_table_check currently treats it as one because the RISC-V PMD user-accessibility test only checks whether the PMD is a leaf and has user permissions.
As a result, when a PMD-sized anonymous THP is split during a COW fault, page_table_check can account the invalid intermediate PMD as a live PMD mapping, and then account the replacement PTE mappings again when the split installs the PTE table. This leaves stale PMD accounting behind and later triggers page_table_check failures such as a non-zero anon_map_count when the folio is freed.
Fix this by tightening pmd_user_accessible_page() so PMD page-table-check accounting only considers leaf PMDs that still carry either _PAGE_PRESENT or _PAGE_PROT_NONE. This preserves the THP split semantics required by the MM code while preventing page_table_check from treating invalid split PMDs as live user mappings.
With CONFIG_PAGE_TABLE_CHECK=y and CONFIG_PAGE_TABLE_CHECK_ENFORCED=y, tools/testing/selftests/mm/cow completes successfully on RISC-V after this change.
--- arch/riscv/include/asm/pgtable.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/riscv/include/asm/pgtable.h +8 -1
@@ -731,7 +731,14 @@ static inline bool pte_user_accessible_page(pte_t pte)static inline bool pmd_user_accessible_page (pmd_t pmd) { -return pmd_leaf (pmd) &&pmd_user (pmd); +/* +* page_table_check() must ignore THP split invalidation entries created by +* pmd_mkinvalid(). These retain _PAGE_LEAF so pmd_present()/pmd_leaf() stay +* true during the split, but they no longer describe a user-accessible +* mapping once both _PAGE_PRESENT and _PAGE_PROT_NONE are cleared. +*/ +return (pmd_val (pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE)) && + (pmd_val (pmd) & _PAGE_LEAF) &&pmd_user (pmd); }static inline bool pud_user_accessible_page (pud_t pud)
Signature · 1 line
2.53.0