6.18.54-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 250/398 net/sched: hhf: cap hh_flows_limit at change time
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
commit 2cef2588c995722a901368def30befeef9ae55c6 upstream.
hhf_change() stores TCA_HHF_HH_FLOWS_LIMIT with no upper bound. A huge hh_flows_limit lets each new heavy-hitter flow pass the hh_flows_current_cnt check in alloc_new_hh() and forces a fixed-size kzalloc(GFP_ATOMIC) per flow under spoofed traffic, for unbounded memory growth.
Bound the attribute with NLA_POLICY_MAX() at 2*HH_FLOWS_CNT (the hhf_init() default) and report the rejected value via extack. The deprecated nested parse is kept: legacy tc does not set NLA_F_NESTED on TCA_OPTIONS. Configs relying on hh_limit above the default were relying on unbounded, unsafe behaviour and are not supported going forward.
hhf_init() also ran hhf_change() before setting the default hh_flows_limit, so a user-supplied hh_limit at add time was clobbered back to 2048. Set the default before hhf_change() so the configured value sticks.
This is a follow-up to commit eb56a495f59b ("net/sched: hhf: clamp quantum in change and init paths"), which bounded the quantum of the same qdisc; the hh_flows_limit bound is the remaining unbounded knob of that series' scope.
Conditions to recreate the bug: CAP_NET_ADMIN in a user namespace; tc qdisc change dev X root hhf hh_limit 4294967295 succeeds and the value is echoed by tc qdisc show, unbounding heavy-hitter flow allocations; also tc qdisc add dev X root hhf hh_limit 500 stores 2048 instead of 500.
--- net/sched/sch_hhf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/sched/sch_hhf.c +5 -4
@@ -526,7 +526,7 @@ static void hhf_destroy(struct Qdisc *scstatic const struct nla_policy hhf_policy[TCA_HHF_MAX +1 ] = { [TCA_HHF_BACKLOG_LIMIT ] = { .type =NLA_U32 }, [TCA_HHF_QUANTUM ] = { .type =NLA_U32 }, - [TCA_HHF_HH_FLOWS_LIMIT ] = { .type =NLA_U32 }, + [TCA_HHF_HH_FLOWS_LIMIT ] =NLA_POLICY_MAX (NLA_U32 ,2 *HH_FLOWS_CNT ), [TCA_HHF_RESET_TIMEOUT ] = { .type =NLA_U32 }, [TCA_HHF_ADMIT_BYTES ] = { .type =NLA_U32 }, [TCA_HHF_EVICT_TIMEOUT ] = { .type =NLA_U32 },
@@ -545,7 +545,7 @@ static int hhf_change(struct Qdisc *sch,u32 new_hhf_non_hh_weight = q->hhf_non_hh_weight; err =nla_parse_nested_deprecated (tb,TCA_HHF_MAX , opt, hhf_policy, -NULL ); + extack);if (err <0 )return err;
@@ -623,6 +623,9 @@ static int hhf_init(struct Qdisc *sch, s q->hhf_evict_timeout =HZ ;/* 1 sec */ q->hhf_non_hh_weight =2 ; +/* Cap max active HHs at twice len of hh_flows table. */ + q->hh_flows_limit =2 *HH_FLOWS_CNT ; +if (opt) {int err =hhf_change (sch, opt, extack);
@@ -639,8 +642,6 @@ static int hhf_init(struct Qdisc *sch, sfor (i =0 ; i <HH_FLOWS_CNT ; i++)INIT_LIST_HEAD (&q->hh_flows[i]); -/* Cap max active HHs at twice len of hh_flows table. */ - q->hh_flows_limit =2 *HH_FLOWS_CNT ; q->hh_flows_overlimit =0 ; q->hh_flows_total_cnt =0 ; q->hh_flows_current_cnt =0 ;
Greg Kroah-Hartman
maintainerPATCH 251/398 net/packet: clear RX owner on VNET header error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Amirkan <[email protected]>
commit 33ff111d7ba3beb86e28938d6382bb5beabd865a upstream.
Commit 61fad6816fc1 ("net/packet: tpacket_rcv: avoid a producer race condition") added rx_owner_map and made tpacket_rcv() claim a V1 or V2 ring slot before converting the virtio-net header. If the conversion fails, the drop path leaves the slot claimed.
With a one-frame TPACKET_V2 ring, an unsupported UDP GSO packet leaves the only slot unavailable, so the ring also drops the next valid packet.
Clear the ownership bit on this error path. TPACKET_V3 already clears its block state here.
--- net/packet/af_packet.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/packet/af_packet.c +3 -1
@@ -2383,7 +2383,9 @@ static int tpacket_rcv(struct sk_buff *s virtio_net_hdr_from_skb(skb, h.raw + macoff - sizeof(struct virtio_net_hdr), vio_le(), true, 0)) { -if (po->tp_version ==TPACKET_V3 ) +if (po->tp_version <=TPACKET_V2 ) +__clear_bit (slot_id, po->rx_ring.rx_owner_map); +else prb_clear_blk_fill_status (&po->rx_ring); goto drop_n_account; }
Greg Kroah-Hartman
maintainerPATCH 252/398 net/packet: avoid truncating TPACKET_V3 private size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Amirkan <[email protected]>
commit 37213e61120297920ae4c937fcb326a360da5084 upstream.
tpacket_req3.tp_sizeof_priv is an unsigned int, and packet_set_ring() validates the full value against the block size. init_prb_bdqc() then stores it in the unsigned short blk_sizeof_priv field.
Commit 2b6867c2ce76 ("net/packet: fix overflow in check for priv area size") fixed the validation arithmetic, but an accepted value above USHRT_MAX still narrows when it is stored.
For a 131072-byte block, tp_sizeof_priv=65536 is valid. The narrowing makes offset_to_first_pkt 48 instead of 65584, so packet records can be placed in the private area that userspace asked the kernel to preserve.
blk_sizeof_priv is internal state, so widen it to hold the validated UAPI value.
--- net/packet/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/internal.h +1 -1
@@ -21,7 +21,7 @@ struct tpacket_kbdq_core {unsigned int hdrlen;unsigned char reset_pending_on_curr_blk;unsigned short kactive_blk_num; -unsigned short blk_sizeof_priv; +unsigned int blk_sizeof_priv;unsigned short version;
Greg Kroah-Hartman
maintainerPATCH 253/398 scsi: core: Validate MODE SENSE lengths in scsi_cdl_enable()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alberto Carboneri <[email protected]>
commit 3d676e458fe0c566f5a62753dc696b6a862fc412 upstream.
scsi_cdl_enable() uses length fields returned by MODE SENSE to locate the ATA feature mode page in a 64-byte stack buffer. A target can report a total length shorter than its mode header and block descriptors. The unsigned subtraction used for the MODE SELECT length can wrap, and the separately computed buf_data can point beyond buf.
During automatic scan, enable is false, so the read-modify-write of buf_data[4] can clear the low two bits of a target-selected out-of-bounds stack byte. scsi_mode_select() can then copy up to 64 bytes from outside the buffer into the outgoing MODE SELECT payload, disclosing stack contents to the target.
This is reachable while scanning a USB storage device that identifies as an ATA device and advertises CDL support. No filesystem mount or userspace access to the block device is required.
On upstream commit cee9395acd80 ("Linux 7.3-rc1"), a build-specific, one-vCPU QEMU/Raw Gadget proof using QEMU-only multi-UDC allocator sampling executed a fixed proof command inside the guest and created a UID-0-owned marker during automatic enumeration, with KASLR and NX enabled.
The issue was independently found during security research at Drivesec S.r.l.
Cap the available length to the buffer size. Validate and consume the mode header and block descriptor lengths before using the page, and require the five bytes needed to access the CDL field.
--- drivers/scsi/scsi.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/scsi/scsi.c +19 -5
@@ -722,6 +722,7 @@ int scsi_cdl_enable(struct scsi_device *struct scsi_mode_data data;struct scsi_sense_hdr sshdr;char *buf_data; +size_t avail, offset;int len; ret = scsi_mode_sense(sdev, 0x08, 0x0a, 0xf2, buf, sizeof(buf),
@@ -730,11 +731,24 @@ int scsi_cdl_enable(struct scsi_device *return -EINVAL ;/* Enable or disable CDL using the ATA feature page */ - len =min_t (size_t,sizeof (buf), - data.length - data.header_length - - data.block_descriptor_length); - buf_data = buf + data.header_length + - data.block_descriptor_length; + avail =min_t (size_t, data.length,sizeof (buf)); +if (data.header_length > avail) +return -EINVAL ; + + offset = data.header_length; + avail -= data.header_length; + +if (data.block_descriptor_length > avail) +return -EINVAL ; + + offset += data.block_descriptor_length; + avail -= data.block_descriptor_length; + +if (avail <5 ) +return -EINVAL ; + + buf_data = buf + offset; + len = avail;/* * If we want to enable CDL and CDL is already enabled on the
Greg Kroah-Hartman
maintainerPATCH 254/398 xfrm: serialize state GC with device state flush
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 89fefad9f971bc637fb22373078144f2563c4be9 upstream.
The deferred-device pass in xfrm_dev_state_flush() finds states under xfrm_state_dev_gc_lock, but drops the lock before calling xfrm_dev_state_free() because the driver callback may sleep. The device GC list does not hold an xfrm_state reference, so the state GC worker can destroy the same state concurrently.
The race can proceed as follows:
CPU 0 CPU 1
find x on the device GC list
drop xfrm_state_dev_gc_lock
read x->xso.dev
xfrm_state_gc_destroy(x) xfrm_dev_state_free(x) xfrm_state_free(x)
continue xfrm_dev_state_free(x)
Both paths can invoke the driver callback and drop the device reference. CPU 0 can also access the xfrm_state after CPU 1 has freed it.
KASAN reported:
BUG: KASAN: slab-use-after-free in xfrm_dev_state_free+0x24c/0x2a0 Read of size 8 at addr ffff88810bbaa960 by task poc/102 Call Trace: xfrm_dev_state_free+0x24c/0x2a0 xfrm_dev_state_flush+0x353/0x400 xfrm_dev_event+0x26d/0x3a0 notifier_call_chain+0xc0/0x280 __dev_notify_flags+0x169/0x250 netif_change_flags+0xe7/0x160 dev_change_flags+0x96/0x220 devinet_ioctl+0x7f4/0x1880 Allocated by task 87: xfrm_state_alloc+0x1e/0x5c0 xfrm_add_sa+0xe7f/0x5820 xfrm_user_rcv_msg+0x4f3/0x940 Freed by task 57: kmem_cache_free+0xcb/0x3d0 xfrm_state_gc_task+0x4a8/0x650 process_one_work+0x63a/0x1070
Serialize xfrm_state destruction against the deferred-device pass with a mutex. Keep xfrm_state_dev_gc_lock limited to list operations and retain the existing callback and device-reference release ordering.
--- net/xfrm/xfrm_state.c | 5 +++++ 1 file changed, 5 insertions(+)
net/xfrm/xfrm_state.c +5 -0
@@ -226,6 +226,7 @@ static struct xfrm_state_afinfo __rcu *xstatic DEFINE_SPINLOCK (xfrm_state_gc_lock);static DEFINE_SPINLOCK (xfrm_state_dev_gc_lock); +static DEFINE_MUTEX (xfrm_state_gc_mutex);int __xfrm_state_delete (struct xfrm_state *x);
@@ -632,8 +633,10 @@ static void xfrm_state_gc_task(struct wosynchronize_rcu (); +mutex_lock (&xfrm_state_gc_mutex);hlist_for_each_entry_safe (x, tmp, &gc_list, gclist)xfrm_state_gc_destroy (x); +mutex_unlock (&xfrm_state_gc_mutex); }static enum hrtimer_restart xfrm_timer_handler (struct hrtimer *me)
@@ -1000,6 +1003,7 @@ restart: out:spin_unlock_bh (&net->xfrm.xfrm_state_lock); +mutex_lock (&xfrm_state_gc_mutex);spin_lock_bh (&xfrm_state_dev_gc_lock); restart_gc:hlist_for_each_entry_safe (x, tmp, &xfrm_state_dev_gc_list, dev_gclist) {
@@ -1014,6 +1018,7 @@ restart_gc: }spin_unlock_bh (&xfrm_state_dev_gc_lock); +mutex_unlock (&xfrm_state_gc_mutex);xfrm_flush_gc ();
Greg Kroah-Hartman
maintainerPATCH 255/398 xfrm: use hlist_del_init_rcu for state_cache and state_cache_input
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
commit 2afb8dc1f4390f164db8352f8e685e126e9db566 upstream.
Commit 14acf9652e56 ("xfrm: defensively unhash xfrm_state lists in __xfrm_state_delete") converted bydst/bysrc/byseq/byspi from hlist_del_rcu() to hlist_del_init_rcu() so that a second __xfrm_state_delete() on the same object becomes a no-op rather than a write through LIST_POISON pprev. It missed state_cache and state_cache_input, which kept hlist_del_rcu():
- hlist_del_rcu() leaves pprev = LIST_POISON2 (non-NULL), so hlist_unhashed() returns false.
- hlist_del_init_rcu() leaves pprev = NULL, so hlist_unhashed() returns true.
A second __xfrm_state_delete() therefore enters __hlist_del() on the already-deleted state_cache/state_cache_input nodes and does WRITE_ONCE(*pprev, next) through LIST_POISON2 — a write use-after-free once the slab is reused. The corruption can in turn cause a subsequent hlist_for_each_entry_rcu traversal to follow a dangling next pointer, producing the read use-after-free reported in xfrm_input_state_lookup().
Switch state_cache and state_cache_input to hlist_del_init_rcu() to match the other four lists, closing the write use-after-free and, with it, the read use-after-free it spawns.
--- net/xfrm/xfrm_state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_state.c +2 -2
@@ -826,9 +826,9 @@ int __xfrm_state_delete(struct xfrm_statif (!hlist_unhashed (&x->byseq))hlist_del_init_rcu (&x->byseq);if (!hlist_unhashed (&x->state_cache)) -hlist_del_rcu (&x->state_cache); +hlist_del_init_rcu (&x->state_cache);if (!hlist_unhashed (&x->state_cache_input)) -hlist_del_rcu (&x->state_cache_input); +hlist_del_init_rcu (&x->state_cache_input);if (!hlist_unhashed (&x->byspi))hlist_del_init_rcu (&x->byspi);
Greg Kroah-Hartman
maintainerPATCH 256/398 soc: samsung: exynos-pmu: fix use-after-free of interrupt generator node
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Klimov <[email protected]>
commit 4dd1999783d7d12434006289338373e49492dc96 upstream.
The setup_cpuhp_and_cpuidle() parses the device tree node for the interrupt generation block via of_parse_phandle() and decrements its reference count using of_node_put() immediately after fetching the resource address. However, later the intr_gen_node pointer is passed into of_syscon_register_regmap().
Fix this by declaring intr_gen_node with __free() and removing of_node_put().
--- drivers/soc/samsung/exynos-pmu.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/soc/samsung/exynos-pmu.c +2 -5
@@ -540,13 +540,12 @@ static struct notifier_block exynos_cpupstatic int setup_cpuhp_and_cpuidle (struct device *dev) { -struct device_node *intr_gen_node; + struct device_node *intr_gen_node __free(device_node) = +of_parse_phandle (dev->of_node,"google,pmu-intr-gen-syscon" ,0 );struct resource intrgen_res;void __iomem *virt_addr;int ret, cpu; - intr_gen_node =of_parse_phandle (dev->of_node, -"google,pmu-intr-gen-syscon" ,0 );if (!intr_gen_node) {/* * To maintain support for older DTs that didn't specify syscon
@@ -562,8 +561,6 @@ static int setup_cpuhp_and_cpuidle(struc* syscon provided regmap. */ ret =of_address_to_resource (intr_gen_node,0 , &intrgen_res); -of_node_put (intr_gen_node); - virt_addr =devm_ioremap (dev, intrgen_res.start,resource_size (&intrgen_res));if (!virt_addr)
Greg Kroah-Hartman
maintainerPATCH 257/398 memcg: avoid charging the root memcg from obj_cgroup_charge_pages()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
commit 6e673d0879ef78c395cfe0d3ba316690a60055d8 upstream.
obj_cgroup_charge_pages() resolves the objcg to its memcg and calls try_charge_memcg(), which does not short circuit the root memcg. That memcg can be the root memcg: obj_cgroup_is_root() reflects the memcg the objcg was created for and is never updated, while memcg_reparent_objcgs() does redirect objcg->memcg to the parent on rmdir. An objcg of a dying child of root therefore passes every obj_cgroup_is_root() filter but resolves to the root memcg.
Folios keep the objcg they were charged with, so this is easy to reach through zswap: allocate anon memory in a cgroup, move the task out, remove the cgroup, then write to the root cgroup's memory.reclaim. The reclaimed folios are charged through the reparented objcg and end up in refill_stock() with the root memcg:
WARNING: mm/memcontrol.c:2198 at refill_stock+0x644/0x940 refill_stock+0x644/0x940 try_charge_memcg+0x12d6/0x1570 __obj_cgroup_charge+0x35/0xf0 obj_cgroup_charge+0x1de/0x210 obj_cgroup_charge_zswap+0x83/0x270 zswap_store+0x1620/0x2000 swap_writeout+0x94c/0x14c0 shrink_folio_list+0x3388/0x52b0 [...] try_to_free_mem_cgroup_pages+0x30d/0x830 user_proactive_reclaim+0x504/0x840 memory_reclaim+0x1f/0x30
Beyond the warning, the charge is asymmetric: obj_cgroup_uncharge_pages() skips refill_stock() for the root memcg, so the root's page counter grows and is never uncharged. It is not user visible, since memory.current is not exposed on the root, but it is a leak.
Use try_charge(), which returns early for the root memcg, restoring the symmetry with obj_cgroup_uncharge_pages().
The above sequence was scripted into a standalone reproducer (zswap on, swap on a virtio disk, 512MB of anon memory faulted in inside a child of the root cgroup, the task then migrated to the root cgroup, the child removed, followed by "echo 600M swappiness=max > memory.reclaim" on the root) and run in a CONFIG_DEBUG_VM=y VM. It reproduces the splat on the first zswap store of a reparented folio, with the same call chain as the report. With this patch applied the splat is gone while the zswap store count over the run is unchanged, so the same path is still exercised. cgroup selftests test_zswap, test_kmem and test_memcontrol show no new failures.
--- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c +1 -1
@@ -2812,7 +2812,7 @@ static int obj_cgroup_charge_pages(struc memcg =get_mem_cgroup_from_objcg (objcg); - ret =try_charge_memcg (memcg, gfp, nr_pages); + ret =try_charge (memcg, gfp, nr_pages);if (ret) goto out;
Greg Kroah-Hartman
maintainerPATCH 258/398 memstick: ms_block: destroy io_queue workqueue on removal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifei Gao <[email protected]>
commit 90af7fde083e1b22c349c3a8b1626728e44e474c upstream.
msb_init_disk() creates the per-card ordered workqueue msb->io_queue with alloc_ordered_workqueue(). It is torn down with destroy_workqueue() only on the init error path; msb_remove() never destroys it. msb_stop() merely flushes the queue, and neither msb_data_clear() nor put_disk() free it. As a result every card insert/remove cycle leaks the workqueue and its kworker, exhausting kernel memory over repeated cycles.
Destroy the workqueue in msb_remove() after the disk has been removed and the queue drained.
--- drivers/memstick/core/ms_block.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/memstick/core/ms_block.c +2 -0
@@ -2205,6 +2205,8 @@ static void msb_remove(struct memstick_dmsb_data_clear (msb);mutex_unlock (&msb_disk_lock); +destroy_workqueue (msb->io_queue); +put_disk (msb->disk);memstick_set_drvdata (card,NULL ); }
Greg Kroah-Hartman
maintainerPATCH 259/398 mm, swap: fix SWAP_USAGE_OFFLIST_BIT collision with real usage count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nhat Pham <[email protected]>
commit 12e9ac7bc5b254048f886bf421e3a15491106c1f upstream.
SWAP_USAGE_OFFLIST_BIT is embedded in the si->inuse_pages usage counter, and is meant to sit above any value that counter can reach. However, it is defined from BITS_PER_TYPE(atomic_t), so it is bit 30. On a system with 4 KiB pages the flag collides with the usage count once that count reaches 4 TiB.
swap_usage_in_pages() masks bit 30 out, so whenever the real count has that bit set, every caller of it reads 4 TiB low:
* /proc/swaps understates Used by 4 TiB.
* A raw count of exactly 2^30 masks to zero, so try_to_unuse() takes its "if (!swap_usage_in_pages(si)) goto success;" early exit and swapoff tears the device down while pages are still swapped out. Nothing in the rest of swapoff aborts the teardown, so those pages are lost.
Independently of swapoff, the collision also corrupts the counter and the plist. On a device in normal use, a free that leaves bit 30 set in the count makes swap_usage_sub() see the flag where there is only count, and call add_to_avail_list(). It clears the bit with fetch_and(~SWAP_USAGE_OFFLIST_BIT), leaving the stored count 4 TiB below the real one, and calls plist_add() on a device that is already listed, tripping the WARN_ON(!plist_node_empty(node)) in plist_add() and linking the node a second time.
Change the definition of SWAP_USAGE_OFFLIST_BIT to be based on atomic_long_t instead. Note that the usage counter field itself is of this same type, so it is still a valid bit.
--- mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/swapfile.c +1 -1
@@ -162,7 +162,7 @@ static inline unsigned char swap_count(u* This bit will be set if the device is not on the plist and not * usable, will be cleared if the device is on the plist. */ -#define SWAP_USAGE_OFFLIST_BIT (1UL << (BITS_PER_TYPE(atomic_t) - 2)) +#define SWAP_USAGE_OFFLIST_BIT (1UL << (BITS_PER_TYPE(atomic_long_t) - 2))#define SWAP_USAGE_COUNTER_MASK (~SWAP_USAGE_OFFLIST_BIT)static long swap_usage_in_pages (struct swap_info_struct *si) {
Greg Kroah-Hartman
maintainerPATCH 260/398 mm/mlock: use the IRQ-safe accessor for NR_MLOCK in __munlock_folio()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
commit e14a3454806468b086fe2e4ca2e1bff95b528531 upstream.
NR_MLOCK is updated from interrupt context. __free_pages_prepare() clears a stray PG_mlocked and adjusts NR_MLOCK, and a folio can reach it with the flag still set from a bio completion handler:
__free_pages_ok+0x6af/0x7a0 <IRQ> __bio_release_pages+0xde/0x260 __iomap_dio_bio_end_io+0x16e/0x1a0 blk_update_request+0x14b/0x3d0 blk_mq_end_request+0x18/0x30 blk_done_softirq+0x49/0x60
The folio gets there like this. A MAP_SHARED file mapping is mlocked, so its page cache folios carry PG_mlocked, and an O_DIRECT write sourced from that mapping GUP-pins those same folios. munlock() then runs mlock_vma_pages_range(), which clears VM_LOCKED before walking the page tables to munlock each folio. A concurrent hole punch reaches the folio through the rmap (i_mmap_rwsem, not mmap_lock) and can land inside that
window: __folio_remove_rmap() -> munlock_vma_folio() sees VM_LOCKED already clear, so it neither queues the folio on the mlock batch nor takes a reference, and the pte it clears makes the pending mlock_pte_range() walk skip the folio at its !pte_present() check. filemap_remove_folio() then drops the page cache reference, leaving the bio's pin as the last one, released from the completion handler above.
So __zone_stat_mod_folio() here needs interrupts disabled, not merely preemption, and __munlock_folio() has a path where they are not: when the folio has already been taken off the LRU by somebody else the function jumps straight to the counter update without taking the lruvec lock. The read-modify-write of the per-CPU NR_MLOCK diff can then be interrupted by the softirq above, and one of the two decrements is lost, leaving Mlocked in /proc/meminfo permanently overstated.
Use zone_stat_mod_folio(). mod_zone_state()'s this_cpu_try_cmpxchg() is atomic against a same-CPU interrupt and retries, and on the path where the lruvec lock is held its cost is negligible next to the lock itself.
The UNEVICTABLE_PG* events are deliberately left on the __ accessors: they occupy different vm_event_states slots from the UNEVICTABLE_PGCLEARED that __free_pages_prepare() bumps, and nothing updates those two from interrupt context.
--- mm/mlock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mlock.c +1 -1
@@ -141,7 +141,7 @@ static struct lruvec *__munlock_folio(st munlock:if (folio_test_clear_mlocked (folio)) { -__zone_stat_mod_folio (folio,NR_MLOCK , -nr_pages); +zone_stat_mod_folio (folio,NR_MLOCK , -nr_pages);if (isolated || !folio_test_unevictable (folio))__count_vm_events (UNEVICTABLE_PGMUNLOCKED , nr_pages);else
Greg Kroah-Hartman
maintainerPATCH 262/398 mm: filemap: retain mapped dropbehind folios
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenjie Qi <[email protected]>
commit 848d2ce2fce15fbdc083fbf9691bfa72911033c4 upstream.
Fault-around can map ready dropbehind folios without going through the normal page-cache lookup that clears dropbehind. A mapping represents a competing cached user, so retain the folio instead of forcibly unmapping it when writeback completes.
For a mapped folio, folio_unmap_invalidate() can call unmap_mapping_folio(), which takes i_mmap_rwsem and may sleep. Retaining mapped folios avoids this path when folio_end_dropbehind() runs in non-preemptible task context.
Tal was able to trigger a sleeping-in-atomic warning due to this [1].
Unmapped dropbehind folios continue through the existing invalidation path.
--- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
@@ -1624,7 +1624,7 @@ static void filemap_end_dropbehind(strucreturn ;if (!folio_test_clear_dropbehind (folio))return ; -if (mapping) +if (mapping && !folio_mapped (folio))folio_unmap_invalidate (mapping, folio,0 ); }
Greg Kroah-Hartman
maintainerPATCH 263/398 KEYS: encrypted: fix integer overflow of datablob_len
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
commit 8697c431e297eb0d0ab13dda6bc172b48a34f05c upstream.
encrypted_key_alloc() stores datablob_len in a u16. It is computed from multiple string and payload lengths. If the result exceeds U16_MAX, the assignment truncates the allocation size. KASAN reports a 32760-byte slab-out-of-bounds write when __ekey_init() copies the master key description into the undersized buffer.
The total payload length stored in key->datalen is also a u16. Use check_add_overflow() to reject values that do not fit either destination, and use kzalloc_flex() for the flexible-array allocation.
--- security/keys/encrypted-keys/encrypted.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
security/keys/encrypted-keys/encrypted.c +14 -6
@@ -18,6 +18,7 @@#include <linux/parser.h> #include <linux/string.h> #include <linux/err.h> +#include <linux/overflow.h> #include <keys/user-type.h> #include <keys/trusted-type.h> #include <keys/encrypted-type.h>
@@ -578,6 +579,7 @@ static struct encrypted_key_payload *enc {struct encrypted_key_payload *epayload =NULL ;unsigned short datablob_len; +unsigned short payload_totallen;unsigned short decrypted_datalen;unsigned short payload_datalen;unsigned int encrypted_datalen;
@@ -631,16 +633,22 @@ static struct encrypted_key_payload *enc encrypted_datalen =roundup (decrypted_datalen, blksize); - datablob_len = format_len +1 +strlen (master_desc) +1 - +strlen (datalen) +1 + ivsize +1 + encrypted_datalen; +if (check_add_overflow (format_len +1 +strlen (master_desc) +1 + +strlen (datalen) +1 + ivsize +1 , + encrypted_datalen, &datablob_len)) +return ERR_PTR (-EINVAL ); + +if (check_add_overflow (datablob_len, + payload_datalen +HASH_SIZE +1 , + &payload_totallen)) +return ERR_PTR (-EINVAL ); - ret =key_payload_reserve (key, payload_datalen + datablob_len - +HASH_SIZE +1 ); + ret =key_payload_reserve (key, payload_totallen);if (ret <0 )return ERR_PTR (ret); - epayload =kzalloc (sizeof (*epayload) + payload_datalen + - datablob_len +HASH_SIZE +1 ,GFP_KERNEL ); + epayload =kzalloc_flex (*epayload, payload_data, payload_totallen, +GFP_KERNEL );if (!epayload)return ERR_PTR (-ENOMEM );
Greg Kroah-Hartman
maintainerPATCH 264/398 keys: translate request_key_auth pid for the reading procfs instance
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 0d6a4268b06084baafd8ee5d66955c7e1c2e053b upstream.
request_key_auth_describe() prints rka->pid into /proc/keys as a raw pid_t in the initial pid namespace. A reader can open /proc/keys through a mount in another pid namespace. That reader sees a number with no meaning there. The number can even name an unrelated task. The line needs VIEW on the key. So the reader either shares the key owner's uid or possesses the key.
The fix keeps a struct pid. Commit 4f82f45730c6 ("net ip6 flowlabel:
Make owner a union of struct pid * and kuid_t") gave /proc/net/ip6_flowlabel the same storage. The print goes through pid_nr_ns(). It renders against the pid namespace of the procfs instance the line is read through. Commit ad08978ab41c ("ipv6/flowlabel: simplify pid namespace lookup") moved that print to the same anchor. Output through an initial namespace /proc does not change. The line shows 0 for a requestor with no number in that namespace.
Translating at read time was the alternative. find_pid_ns() can resolve a recycled number. The line would then name a live task with no connection to the key. A stored struct pid gives 0 instead when the requestor has no number there.
--- include/keys/request_key_auth-type.h | 2 +- security/keys/request_key_auth.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
include/keys/request_key_auth-type.h +1 -1
@@ -22,7 +22,7 @@ struct request_key_auth {const struct cred *cred;void *callout_info;size_t callout_len; -pid_t pid; +struct pid *pid;char op[8 ]; } __randomize_layout;
security/keys/request_key_auth.c +9 -3
@@ -9,6 +9,8 @@#include <linux/sched.h> #include <linux/err.h> +#include <linux/pid.h> +#include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -73,7 +75,10 @@ static void request_key_auth_describe(coseq_puts (m,"key:" );seq_puts (m, key->description);if (key_is_positive (key)) -seq_printf (m," pid:%d ci:%zu" , rka->pid, rka->callout_len); +seq_printf (m," pid:%d ci:%zu" , +pid_nr_ns (rka->pid, +proc_pid_ns (file_inode (m->file)->i_sb)), + rka->callout_len); }/*
@@ -113,6 +118,7 @@ static void free_request_key_auth(structif (rka->cred)put_cred (rka->cred);kfree (rka->callout_info); +put_pid (rka->pid);kfree (rka); }
@@ -226,14 +232,14 @@ struct key *request_key_auth_new(struct irka = cred->request_key_auth->payload.data[0 ]; rka->cred =get_cred (irka->cred); - rka->pid = irka->pid; + rka->pid =get_pid (irka->pid);up_read (&cred->request_key_auth->sem); }else {/* it isn't - use this process as the context */ rka->cred =get_cred (cred); - rka->pid = current->pid; + rka->pid =get_pid (task_pid (current)); } rka->target_key =key_get (target);
Greg Kroah-Hartman
maintainerPATCH 265/398 KEYS: trusted: Fix tpm2_load_cmd() boundary check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit 114f00d738f15dd8c7318369edcdc53dd6d08763 upstream.
tpm2_load_cmd() does boundary checks against the ASN.1 size i.e., payload->blob_len. Address this by passing the decoded blob size to tpm2_load_cmd(), and use it for the boundary checks.
--- security/keys/trusted-keys/trusted_tpm2.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
security/keys/trusted-keys/trusted_tpm2.c +7 -5
@@ -108,7 +108,7 @@ struct tpm2_key_context {static int tpm2_key_decode (struct trusted_key_payload *payload,struct trusted_key_options *options, -u8 **buf) +u8 **buf,unsigned int *blob_len) {int ret;struct tpm2_key_context ctx;
@@ -129,6 +129,7 @@ static int tpm2_key_decode(struct trustereturn -ENOMEM ; *buf = blob; + *blob_len = ctx.priv_len + ctx.pub_len; options->keyhandle = ctx.parent;memcpy (blob, ctx.priv, ctx.priv_len);
@@ -402,10 +403,11 @@ static int tpm2_load_cmd(struct tpm_chipint rc;u32 attrs; - rc =tpm2_key_decode (payload, options, &blob); + rc =tpm2_key_decode (payload, options, &blob, &blob_len);if (rc) {/* old form */ blob = payload->blob; + blob_len = payload->blob_len; payload->old_format =1 ; }else {/* Bind for cleanup: */
@@ -417,17 +419,17 @@ static int tpm2_load_cmd(struct tpm_chipreturn -EINVAL ;/* must be big enough for at least the two be16 size counts */ -if (payload->blob_len <4 ) +if (blob_len <4 )return -EINVAL ; private_len =get_unaligned_be16 (blob);/* must be big enough for following public_len */ -if (private_len +2 +2 > (payload->blob_len)) +if (private_len +2 +2 > blob_len)return -E2BIG ; public_len =get_unaligned_be16 (blob +2 + private_len); -if (private_len +2 + public_len +2 > payload->blob_len) +if (private_len +2 + public_len +2 > blob_len)return -E2BIG ; pub = blob +2 + private_len +2 ;
Greg Kroah-Hartman
maintainerPATCH 266/398 i2c: at91: release DMA channels on remove and probe error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit f7eeb1af8537b05953fb1c88ab8b59d94059a381 upstream.
at91_twi_configure_dma() requests exclusive tx/rx DMA channels, but nothing ever releases them on driver detach, and the probe error path after the channels are acquired (i2c_add_numbered_adapter() failure) returns without releasing them either, because the remove callback is not invoked after a failed probe.
Move the release into a helper, call it from the existing configure-failure path, the adapter-registration failure path, and at91_twi_remove().
--- drivers/i2c/busses/i2c-at91-core.c | 3 +++ drivers/i2c/busses/i2c-at91-master.c | 12 +++++++++++- drivers/i2c/busses/i2c-at91.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-at91-core.c +3 -0
@@ -255,6 +255,7 @@ static int at91_twi_probe(struct platforif (rc) {pm_runtime_disable (dev->dev);pm_runtime_set_suspended (dev->dev); +at91_twi_dma_release (dev);return rc; }
@@ -270,6 +271,8 @@ static void at91_twi_remove(struct platfi2c_del_adapter (&dev->adapter); +at91_twi_dma_release (dev); +pm_runtime_disable (dev->dev);pm_runtime_set_suspended (dev->dev); }
drivers/i2c/busses/i2c-at91-master.c +11 -1
@@ -817,11 +817,21 @@ static int at91_twi_configure_dma(struct error:if (ret != -EPROBE_DEFER )dev_info (dev->dev,"can't get DMA channel, continue without DMA support\n" ); +at91_twi_dma_release (dev); +return ret; +} + +void at91_twi_dma_release (struct at91_twi_dev *dev) +{ +struct at91_twi_dma *dma = &dev->dma; +if (dma->chan_rx)dma_release_channel (dma->chan_rx);if (dma->chan_tx)dma_release_channel (dma->chan_tx); -return ret; + dma->chan_rx =NULL ; + dma->chan_tx =NULL ; + dev->use_dma = false; } static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
drivers/i2c/busses/i2c-at91.h +1 -0
@@ -172,6 +172,7 @@ void at91_twi_irq_restore(struct at91_twvoid at91_init_twi_bus (struct at91_twi_dev *dev);void at91_init_twi_bus_master (struct at91_twi_dev *dev); +void at91_twi_dma_release (struct at91_twi_dev *dev);int at91_twi_probe_master (struct platform_device *pdev,u32 phy_addr,struct at91_twi_dev *dev);
Greg Kroah-Hartman
maintainerPATCH 267/398 i2c: atr: fix dangling adapter pointer on add failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit ad34235808b63a70ca4989b7a2852923193d06ef upstream.
i2c_atr_add_adapter() stores atr->adapter[chan_id] before i2c_add_adapter() so that the I2C bus notifier can match child clients during registration. On failure the channel is freed but the slot was left pointing at freed memory, which can lead to use-after-free in i2c_atr_del_adapter() / cleanup and also block reuse with -EEXIST.
Clear the slot on the i2c_add_adapter() error path before freeing chan.
--- drivers/i2c/i2c-atr.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/i2c-atr.c +1 -0
@@ -864,6 +864,7 @@ int i2c_atr_add_adapter(struct i2c_atr * ret =i2c_add_adapter (&chan->adap);if (ret) { + atr->adapter[chan_id] =NULL ;dev_err (dev,"failed to add atr-adapter %u (error=%d)\n" , chan_id, ret); goto err_free_alias_pool;
Greg Kroah-Hartman
maintainerPATCH 268/398 i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Zhenlong <[email protected]>
commit 7362a1553eb09a8cdf8be7e509bd5309a8342486 upstream.
The of_node_put() matching of_node_get() runs after i2c_del_adapter(), whose trailing memset() zeroes adap->dev and thus adap->dev.of_node, making the put a no-op and leaking the node on every adapter removal and error cleanup.
Use a devm action: the pointer is captured at registration, out of reach of that memset(), and devres runs the put once on probe failure and detach, replacing the three manual of_node_put() calls. The setup loop uses the scoped iterator form so the child node is released automatically if devm_add_action_or_reset() fails mid-loop.
--- drivers/i2c/busses/i2c-qcom-cci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +11 -9
@@ -499,10 +499,14 @@ static const struct dev_pm_ops qcom_cci_ SET_RUNTIME_PM_OPS(cci_suspend_runtime, cci_resume_runtime, NULL) }; +static void cci_put_of_node (void *data) +{ +of_node_put (data); +} +static int cci_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct device_node *child;struct resource *r;struct cci *cci;int ret, i;
@@ -518,7 +522,7 @@ static int cci_probe(struct platform_devif (!cci->data)return -ENOENT ; -for_each_available_child_of_node (dev->of_node, child) { +for_each_available_child_of_node_scoped (dev->of_node, child) {struct cci_master *master;u32 idx;
@@ -539,6 +543,9 @@ static int cci_probe(struct platform_dev master->adap.algo = &cci_algo; master->adap.dev.parent = dev; master->adap.dev.of_node =of_node_get (child); + ret =devm_add_action_or_reset (dev, cci_put_of_node, child); +if (ret) +return ret; master->master = idx; master->cci = cci;
@@ -610,10 +617,8 @@ static int cci_probe(struct platform_devcontinue ; ret =i2c_add_adapter (&cci->master[i].adap); -if (ret <0 ) { -of_node_put (cci->master[i].adap.dev.of_node); +if (ret <0 ) goto error_i2c; - } }return 0 ;
@@ -621,10 +626,8 @@ static int cci_probe(struct platform_dev error_i2c:for (--i ; i >=0 ; i--) { -if (cci->master[i].cci) { +if (cci->master[i].cci)i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node); - } } disable_clocks:cci_disable_clocks (cci);
@@ -640,7 +643,6 @@ static void cci_remove(struct platform_dfor (i =0 ; i < cci->data->num_masters; i++) {if (cci->master[i].cci) {i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node);cci_halt (cci, i); } }
Greg Kroah-Hartman
maintainerPATCH 269/398 i2c: imx: release DMA channels on probe error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit e9f03b9625e2eeaca357b065c92d5b14064a1583 upstream.
i2c_imx_dma_request() acquires exclusive tx/rx DMA channels and is
optional: on errors other than -EPROBE_DEFER the driver falls back to PIO mode and probe continues. If i2c_add_numbered_adapter() then fails, probe returns through clk_notifier_unregister without releasing the channels, because the remove callback is not invoked after a failed probe.
Release the channels on the probe error path, mirroring i2c_imx_remove().
--- drivers/i2c/busses/i2c-imx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-imx.c +2 -0
@@ -1880,6 +1880,8 @@ static int i2c_imx_probe(struct platform clk_notifier_unregister:clk_notifier_unregister (i2c_imx->clk, &i2c_imx->clk_change_nb); +if (i2c_imx->dma) +i2c_imx_dma_free (i2c_imx);free_irq (irq, i2c_imx); rpm_disable:pm_runtime_put_noidle (&pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 270/398 i2c: imx: disable autosuspend on remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit e0c3e9d76adbe522dd420a766ce42d03ce887c29 upstream.
i2c_imx_probe() enables runtime PM autosuspend with pm_runtime_use_autosuspend(). The probe error path correctly undoes this setting with pm_runtime_dont_use_autosuspend(), but the normal remove path only disables runtime PM.
The runtime PM API requires pm_runtime_use_autosuspend() to be undone with pm_runtime_dont_use_autosuspend() at driver exit unless runtime PM was enabled with devm_pm_runtime_enable(). Leaving the autosuspend flag set therefore leaves the runtime PM state incompletely cleaned up after the driver is unbound.
Add the missing pm_runtime_dont_use_autosuspend() call to the remove path.
This issue was found by manual code inspection.
--- drivers/i2c/busses/i2c-imx.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/busses/i2c-imx.c +1 -0
@@ -1922,6 +1922,7 @@ static void i2c_imx_remove(struct platfopm_runtime_put_noidle (&pdev->dev);pm_runtime_disable (&pdev->dev); +pm_runtime_dont_use_autosuspend (&pdev->dev); }static int i2c_imx_runtime_suspend (struct device *dev)
Greg Kroah-Hartman
maintainerPATCH 271/398 IB/mlx4: Fix use-after-free on pkey sysfs registration failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangpeng Bai <[email protected]>
commit 1af874e9f4ce22ccf8b10ab5462f32c70d3be21a upstream.
register_pkey_tree() ignores errors from register_one_pkey_tree() and continues registering the remaining slaves. The per-slave error path has already released the pkey parent kobjects, but their pointers remain stored in the device. A later device cleanup therefore passes the stale pointers to kobject_put(), causing a use-after-free.
Clear the parent pointers after releasing a failed slave tree and skip unregistered trees during device cleanup. This preserves the existing best-effort registration behavior while preventing a second cleanup of the failed tree.
--- drivers/infiniband/hw/mlx4/sysfs.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/hw/mlx4/sysfs.c +4 -0
@@ -753,11 +753,13 @@ err_add:kobject_put (p); }kobject_put (dev->dev_ports_parent[slave]); + dev->dev_ports_parent[slave] =NULL ; err_ports:kobject_put (dev->pkeys.device_parent[slave]);/* extra put for the device_parent create_and_add */ kobject_put (dev->pkeys.device_parent[slave]); + dev->pkeys.device_parent[slave] =NULL ; fail_dev:kobject_put (dev->iov_parent);
@@ -787,6 +789,8 @@ static void unregister_pkey_tree(structreturn ;for (slave = device->dev->persist->num_vfs; slave >=0 ; --slave) { +if (!device->pkeys.device_parent[slave]) +continue ;list_for_each_entry_safe (p, t, &device->pkeys.pkey_port_list[slave], entry) {
Greg Kroah-Hartman
maintainerPATCH 272/398 IB/hfi1: Resolve the credit-return buffer through the send contexts node
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
commit 975396b9e5a4028e649f4b9a6a5ca5dfb76a824b upstream.
hfi1_file_mmap()'s PIO_CRED case derives this context's credit-return page offset, and the DMA handle for it, from dd->cr_base[uctxt->numa_id]. uctxt->numa_id is the node of whichever CPU the process happened to be running on, but the entry itself lives in the credit-return allocation of the send context's own node:
sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index];
and user send contexts are allocated with sc_alloc(dd, SC_USER, ..., dd->node), the HFI-local node. On a multi-socket host with the process running off that node the two allocations differ, so the subtraction produces an offset into an unrelated buffer and the DMA handle belongs to the wrong allocation.
Use the send context's own node for all three references. The continuation lines are reindented at the same time; they mixed spaces and tabs.
--- drivers/infiniband/hw/hfi1/file_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +4 -4
@@ -382,10 +382,10 @@ static int hfi1_file_mmap(struct file *f* of enabled contexts > 64 and 128 respectively). */ cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) & -PAGE_MASK ; - memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; - memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; + (u64 )dd->cr_base[uctxt->sc->node].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; + memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
Greg Kroah-Hartman
maintainerPATCH 273/398 IB/hfi1: Fix the PIO_CRED credit-return mmap
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
commit 62f0f34fbd2b2d5653d33d3b9d42fdcabb1c0101 upstream.
hfi1_file_mmap()'s PIO_CRED case must hand user space the single credit-return page that holds this context's entry. That page is the second or third page of the per-node credit-return allocation once the hardware send context index reaches 64 or 128, so the failure below is
intermittent: when the entry lands on the first page the offset is zero and everything works.
Two things are wrong.
First, cr_page_offset is a byte offset but .va is a struct credit_return *, so adding it is pointer arithmetic and scales the offset by sizeof(struct credit_return) == 64. memvirt then lands 256 KiB or 512 KiB past a 10240-byte allocation. With an IOMMU translating, that address is inside the vmalloc range but in no vm_area, so dma_mmap_coherent() -> iommu_dma_mmap() finds no pages, vmalloc_to_pfn() returns page_to_pfn(NULL), and remap_pfn_range() installs a frame above MAXPHYADDR. The first user read then takes:
psm2_ep_open_pr: Corrupted page table at address 7a14d007e000 PGD 800000013886a067 P4D 800000013886a067 PUD 13886b067 PMD 13886c067
PTE 800049168e911235 Oops: Bad pagetable: 000d [#1] SMP PTI
Second, and still wrong once the arithmetic is corrected, dma_mmap_coherent() describes a whole coherent buffer and selects the page within it with vma->vm_pgoff. Offsetting cpu_addr has no effect:
for a vmap'd allocation iommu_dma_mmap() uses cpu_addr only to locate the vm_area and then maps pages[vm_pgoff], which hfi1_file_mmap() has just set to 0. User space therefore always receives the first credit-return page, every credit read is for the wrong context, and send PIO stalls forever.
Use the DMA API as intended: pass the base of the allocation with its full length and select the page with vm_pgoff. A separate length is needed because memlen must keep describing the VMA for the existing size check. The dma-direct path stays correct as well, since dma_direct_mmap() adds the same vm_pgoff to the base pfn.
Tested on a Dell T7610 (Xeon E5-2650 v2, Intel IOMMU in DMA-FQ mode) against a Threadripper PRO 3995WX peer, both Omni-Path 100. Before this change psm2_ep_open() Oopses the kernel; with only the arithmetic corrected psm2_ep_open() succeeds but any transfer that uses send PIO hangs, PSM2_SDMA=2 (send PIO disabled) completing normally while PSM2_SDMA=0 (send PIO only) hangs every time. With this change send PIO, send DMA and the default mixed mode all work.
--- drivers/infiniband/hw/hfi1/file_ops.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +16 -5
@@ -326,6 +326,7 @@ static int hfi1_file_mmap(struct file *fvoid *memvirt =NULL ;dma_addr_t memdma =0 ;u8 subctxt, mapio =0 , vmf =0 , type; +size_t memdmalen =0 ;ssize_t memlen =0 ;int ret =0 ;u16 ctxt;
@@ -371,7 +372,9 @@ static int hfi1_file_mmap(struct file *f mapio =1 ;break ;case PIO_CRED : { +struct credit_return_base *cr = &dd->cr_base[uctxt->sc->node];u64 cr_page_offset; +if (flags &VM_WRITE ) { ret = -EPERM ; goto done;
@@ -381,11 +384,18 @@ static int hfi1_file_mmap(struct file *f* second or third page allocated for credit returns (if number * of enabled contexts > 64 and 128 respectively). */ - cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->sc->node].va) & + cr_page_offset = ((u64 )uctxt->sc->hw_free - (u64 )cr->va) &PAGE_MASK ; - memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; - memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; +/* +* dma_mmap_coherent() describes the whole coherent buffer and +* selects the page within it with vma->vm_pgoff, so pass the +* base of the allocation and its length and let vm_pgoff pick +* the page. +*/ + vma->vm_pgoff = cr_page_offset >>PAGE_SHIFT ; + memvirt = cr->va; + memdma = cr->dma; + memdmalen =TXE_NUM_CONTEXTS *sizeof (struct credit_return ); memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
@@ -567,7 +577,8 @@ static int hfi1_file_mmap(struct file *f ret =0 ; }else if (memdma) { ret =dma_mmap_coherent (&dd->pcidev->dev, vma, - memvirt, memdma, memlen); + memvirt, memdma, + memdmalen ? memdmalen : memlen); }else if (mapio) { ret = io_remap_pfn_range(vma, vma->vm_start, PFN_DOWN(memaddr),
Greg Kroah-Hartman
maintainerPATCH 274/398 selinux: preserve user SID across nested backing files
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 8c0c602202b9a4909b00bc3354e3c0355bc69e65 upstream.
SELinux saves the user file SID in a backing-file security blob so it remains available after mmap() replaces vma->vm_file with a backing file.
For nested backing files (overlayfs over overlayfs, or FUSE passthrough backed by overlayfs), user_file may itself be a backing file. Its fsec->sid is the SID of the mounter that opened it, rather than the user that opened the top-level file. mprotect() then checks fd { use } against the mounter SID. This can incorrectly deny access without a domain transition, or check the wrong target SID after one.
Copy the saved user SID when user_file is a backing file. Keep using the regular file SID for the first backing layer.
With two nested overlayfs mounts and SELinux enforcing, mprotect(PROT_READ) returns EACCES with an fd { use } denial against the mounter SID. With this change, mprotect() succeeds.
Tested on arm64 QEMU with a small BusyBox initramfs and a purpose-built SELinux policy. The original test was also repeated with Fedora Cloud Base 44 userspace and gave the same result.
--- security/selinux/hooks.c | 9 ++++++++- security/selinux/include/objsec.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-)
security/selinux/hooks.c +8 -1
@@ -3822,13 +3822,20 @@ static int selinux_file_alloc_security(sreturn 0 ; } +static inline u32 selinux_file_user_sid (const struct file *file) +{ +if (unlikely (file->f_mode &FMODE_BACKING )) +return selinux_backing_file (file)->uf_sid; +return selinux_file (file)->sid; +} +static int selinux_backing_file_alloc (struct file *backing_file,const struct file *user_file) {struct backing_file_security_struct *bfsec; bfsec =selinux_backing_file (backing_file); - bfsec->uf_sid =selinux_file (user_file)->sid; + bfsec->uf_sid =selinux_file_user_sid (user_file);return 0 ; }
security/selinux/include/objsec.h +1 -1
@@ -87,7 +87,7 @@ struct file_security_struct { };struct backing_file_security_struct { -u32 uf_sid;/* associated user file fsec->sid */ +u32 uf_sid;/* top-level user file fsec->sid */ };struct superblock_security_struct {
Greg Kroah-Hartman
maintainerPATCH 275/398 selinux: recheck intermediate backing files on mprotect()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 78fc54b934bfb2c18aad8154c7302067146946f9 upstream.
mprotect() can be used to bypass the SELinux checks that mmap() performs against the intermediate layers of a stacked filesystem.
mmap() checks every backing layer as the request descends through the stack. mprotect() only has the lowest backing file in vma->vm_file, so it rechecks the top-level user and the lowest mounter, but skips the mounters of every layer in between. With two nested overlayfs mounts and a policy denying mounter_t -> middle_file_t:file { execute }, a direct mmap(PROT_EXEC) is denied:
avc: denied { execute } for pid=71 comm="nested_exec"
path="/payload" dev="overlay" ino=9 scontext=user_u:base_r:mounter_t tcontext=user_u:object_r:middle_file_t tclass=file permissive=0
while mmap(PROT_NONE) followed by mprotect(PROT_EXEC) succeeds.
Preserve each intermediate path, mounter SID and file-description SID in the backing-file security blob, copying the saved entries when another backing layer is opened. Allocate the array only for nested backing files, and release it and the path references in the backing_file_free hook.
During mprotect(), recheck fd { use } and the requested inode permissions for every saved mounter, and include the intermediate layers in the execmod checks. Policy for nested stacking may then need to grant intermediate mounters what a direct mmap() already requires, and execmod on intermediate labels for binaries using text relocations.
Tested on arm64 QEMU with a small BusyBox initramfs and a purpose-built SELinux policy, on a mainline tree containing
commit f2381b546e7e ("fs: fix user path of nested backing files").
--- security/selinux/hooks.c | 141 +++++++++++++++++++++++++++++++++----- security/selinux/include/objsec.h | 8 ++ 2 files changed, 133 insertions(+), 16 deletions(-)
security/selinux/hooks.c +125 -16
@@ -1665,26 +1665,32 @@ static int cred_has_capability(const strreturn rc; } -/* Check whether a task has a particular permission to an inode. -The 'adp' parameter is optional and allows other audit -data to be passed (e.g. the dentry). */ -static int inode_has_perm (const struct cred *cred, -struct inode *inode, -u32 perms, -struct common_audit_data *adp) +/* +* Check whether a SID has a particular permission to an inode. The 'adp' +* parameter is optional and allows other audit data to be passed (e.g. the +* dentry). +*/ +static int inode_sid_has_perm (u32 sid,struct inode *inode,u32 perms, +struct common_audit_data *adp) {struct inode_security_struct *isec; -u32 sid;if (unlikely (IS_PRIVATE (inode)))return 0 ; - sid =cred_sid (cred); isec =selinux_inode (inode);return avc_has_perm (sid, isec->sid, isec->sclass, perms, adp); } +static int inode_has_perm (const struct cred *cred, +struct inode *inode, +u32 perms, +struct common_audit_data *adp) +{ +return inode_sid_has_perm (cred_sid (cred), inode, perms, adp); +} +/* Same as inode_has_perm, but pass explicit audit data containing the dentry to help the auditing code to more easily generate the pathname if needed. */
@@ -3833,13 +3839,63 @@ static int selinux_backing_file_alloc(st const struct file *user_file) {struct backing_file_security_struct *bfsec; +const struct backing_file_security_struct *ubfsec; +struct backing_file_security_layer *layer; +u32 i; bfsec =selinux_backing_file (backing_file); bfsec->uf_sid =selinux_file_user_sid (user_file); +if (!(user_file->f_mode &FMODE_BACKING )) +return 0 ; + + ubfsec =selinux_backing_file (user_file); +/* a wrapped count would make kmalloc_array() return ZERO_SIZE_PTR */ +if (unlikely (ubfsec->layer_count ==U32_MAX )) +return -EOVERFLOW ; + +/* +* The final VMA only retains the lowest backing file, so record the +* whole chain here rather than in the mmap hook, where concurrent +* mappings would have to be serialized. Size it dynamically: erofs +* inode sharing adds a backing file without bumping s_stack_depth. +*/ + bfsec->layers =kmalloc_array (ubfsec->layer_count +1 , +sizeof (*bfsec->layers),GFP_KERNEL ); +if (!bfsec->layers) +return -ENOMEM ; + +for (i =0 ; i < ubfsec->layer_count; i++) { + layer = &bfsec->layers[i]; + *layer = ubfsec->layers[i]; +path_get (&layer->path); + } + +/* f_path, not file_user_path(): this layer, not the top-level file */ + layer = &bfsec->layers[i]; + layer->path = user_file->f_path; + layer->mounter_sid =cred_sid (user_file->f_cred); + layer->fd_sid =selinux_file (user_file)->sid; +path_get (&layer->path); + bfsec->layer_count = ubfsec->layer_count +1 ;return 0 ; } +static void selinux_backing_file_free (struct file *backing_file) +{ +struct backing_file_security_struct *bfsec; + +/* security_backing_file_free() may be called twice after an error */ +if (!backing_file_security (backing_file)) +return ; + + bfsec =selinux_backing_file (backing_file); +while (bfsec->layer_count) +path_put (&bfsec->layers[--bfsec->layer_count].path); +kfree (bfsec->layers); + bfsec->layers =NULL ; +} +/* * Check whether a task has the ioctl permission and cmd * operation to an inode.
@@ -3957,6 +4013,53 @@ static int selinux_file_ioctl_compat(strstatic int default_noexec__ro_after_init ; +static u32 file_map_prot_to_av (unsigned long prot,bool shared) +{ +u32 av =FILE__READ ; + +if (shared && (prot &PROT_WRITE )) + av |=FILE__WRITE ; +if (prot &PROT_EXEC ) + av |=FILE__EXECUTE ; + +return av; +} + +static int backing_mounters_has_perm (const struct file *file,u32 av) +{ +const struct backing_file_security_struct *bfsec; +const struct backing_file_security_layer *layer; +struct common_audit_data ad; +struct inode *inode; +u32 i; +int rc; + +if (WARN_ON_ONCE (!(file->f_mode &FMODE_BACKING ))) +return -EIO ; + + bfsec =selinux_backing_file (file); +for (i =0 ; i < bfsec->layer_count; i++) { + layer = &bfsec->layers[i]; + inode =d_inode (layer->path.dentry); + + ad.type =LSM_AUDIT_DATA_PATH ; + ad.u.path = layer->path; + +if (layer->mounter_sid != layer->fd_sid) { + rc =avc_has_perm (layer->mounter_sid, layer->fd_sid, +SECCLASS_FD ,FD__USE , &ad); +if (rc) +return rc; + } + + rc =inode_sid_has_perm (layer->mounter_sid, inode, av, &ad); +if (rc) +return rc; + } + +return 0 ; +} +static int __file_map_prot_check (const struct file *file,unsigned long prot,bool shared,bool mounter_check,bool bf_user_file)
@@ -3990,14 +4093,10 @@ static int __file_map_prot_check(const sif (file) {const struct cred *cred = mounter_check ? file->f_cred :current_cred (); -/* "read" always possible, "write" only if shared */ -u32 av =FILE__READ ; -if (shared && prot_write) - av |=FILE__WRITE ; -if (prot_exec) - av |=FILE__EXECUTE ; -return __file_has_perm (cred, file, av, bf_user_file); +return __file_has_perm (cred, file, +file_map_prot_to_av (prot, shared), + bf_user_file); }return 0 ;
@@ -4092,6 +4191,7 @@ static int selinux_file_mprotect(structint rc;const struct cred *cred =current_cred ();u32 sid =cred_sid (cred); +u32 av;const struct file *file = vma->vm_file;bool backing_file;bool shared = vma->vm_flags &VM_SHARED ;
@@ -4135,6 +4235,10 @@ static int selinux_file_mprotect(structif (rc)return rc;if (backing_file) { + rc =backing_mounters_has_perm (file, +FILE__EXECMOD ); +if (rc) +return rc; rc =file_has_perm (file->f_cred, file,FILE__EXECMOD );if (rc)
@@ -4147,6 +4251,10 @@ static int selinux_file_mprotect(structif (rc)return rc;if (backing_file) { + av =file_map_prot_to_av (prot, shared); + rc =backing_mounters_has_perm (file, av); +if (rc) +return rc; rc =file_map_prot_check (file, prot, shared, true);if (rc)return rc;
@@ -7507,6 +7615,7 @@ static struct security_hook_list selinuxLSM_HOOK_INIT (file_permission, selinux_file_permission),LSM_HOOK_INIT (file_alloc_security, selinux_file_alloc_security),LSM_HOOK_INIT (backing_file_alloc, selinux_backing_file_alloc), +LSM_HOOK_INIT (backing_file_free, selinux_backing_file_free),LSM_HOOK_INIT (file_ioctl, selinux_file_ioctl),LSM_HOOK_INIT (file_ioctl_compat, selinux_file_ioctl_compat), LSM_HOOK_INIT(mmap_file, selinux_mmap_file),
security/selinux/include/objsec.h +8 -0
@@ -86,8 +86,16 @@ struct file_security_struct {u32 pseqno;/* Policy seqno at the time of file open */ }; +struct backing_file_security_layer { +struct path path;/* this layer's real path */ +u32 mounter_sid;/* SID of the mounter that opened it */ +u32 fd_sid;/* SID of its open file description */ +}; +struct backing_file_security_struct {u32 uf_sid;/* top-level user file fsec->sid */ +u32 layer_count;/* number of intermediate backing files */ +struct backing_file_security_layer *layers; };struct superblock_security_struct {
Greg Kroah-Hartman
maintainerPATCH 276/398 selinux: always fill AVC decision in avc_has_perm_noaudit()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
commit 8861db305103107199b1426f25fde1fb6d465583 upstream.
avc_has_perm_noaudit() is documented to return a copy of the access decision in @avd, but its early return for an empty requested permission set leaves the buffer untouched. All callers pass an uninitialized stack variable and afterwards feed it to avc_audit(), and the inode hook even stores it in the per-task decision cache.
Fill in a deny-all, audit-all decision, similar to avd_init(), so every caller receives a defined value at no cost on the hot path.
--- security/selinux/avc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
security/selinux/avc.c +4 -1
@@ -1149,8 +1149,11 @@ inline int avc_has_perm_noaudit(u32 ssidu32 denied;struct avc_node *node; -if (WARN_ON (!requested)) +if (WARN_ON (!requested)) { +/* Provide a deny-all, audit-all decision to the caller. */ + *avd = (struct av_decision ){ .auditdeny =0xffffffff };return -EACCES ; + }rcu_read_lock (); node =avc_lookup (ssid, tsid, tclass);
Greg Kroah-Hartman
maintainerPATCH 277/398 power: sequencing: dont call .post_enable() if pwrseq_unit_enable() failed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
commit 5f90f85eae4e9d2e9628b2019870994ba830b533 upstream.
If the call to pwrseq_unit_enable() failed in pwrseq_enable(), bail out instead of calling target->post_enable() which assumes the target was successfully enabled.
--- drivers/power/sequencing/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/power/sequencing/core.c +2 -0
@@ -913,6 +913,8 @@ int pwrseq_power_on(struct pwrseq_desc *if (!ret) desc->powered_on = true; } +if (ret) +return ret;if (target->post_enable) { ret = target->post_enable (pwrseq);
Greg Kroah-Hartman
maintainerPATCH 278/398 power: sequencing: fix NULL-pointer dereference in pwrseq_unit_new()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
commit 115b303e8e093d964089ec6f3c40d984d77b33d0 upstream.
If memory allocation fails in pwrseq_unit_setup_deps(), pwrseq_unit_put() is called to release the partially initialized unit. However, we've never initialized unit->list and pwrseq_unit_release() will unconditionally call list_del() on it. Initialize unit->list right after allocating the unit struct.
--- drivers/power/sequencing/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/power/sequencing/core.c +1 -0
@@ -101,6 +101,7 @@ static struct pwrseq_unit *pwrseq_unit_n }kref_init (&unit->ref); +INIT_LIST_HEAD (&unit->list);INIT_LIST_HEAD (&unit->deps); unit->enable = data->enable; unit->disable = data->disable;
Greg Kroah-Hartman
maintainerPATCH 279/398 power: sequencing: fix NULL-pointer dereference in pwrseq_device_register()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
commit 242da4318d97380741516b595af3920207b2f0f1 upstream.
If dev_set_name() fails in pwrseq_device_register(), we jump to the err_put_pwrseq label before initializing pwrseq->targets. pwrseq_release() will try to iterate over targets unconditionally and subsequently dereference an invalid pointer. Move the call to dev_set_name() after the list head is initialized.
--- drivers/power/sequencing/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/power/sequencing/core.c +4 -4
@@ -505,10 +505,6 @@ pwrseq_device_register(const struct pwrs*/ device_initialize (&pwrseq->dev); - ret =dev_set_name (&pwrseq->dev,"pwrseq.%d" , pwrseq->id); -if (ret) - goto err_put_pwrseq; - pwrseq->owner = config->owner ?:THIS_MODULE ; pwrseq->match = config->match;
@@ -517,6 +513,10 @@ pwrseq_device_register(const struct pwrsINIT_LIST_HEAD (&pwrseq->targets);INIT_LIST_HEAD (&pwrseq->units); + ret =dev_set_name (&pwrseq->dev,"pwrseq.%d" , pwrseq->id); +if (ret) + goto err_put_pwrseq; + ret =pwrseq_setup_targets (config->targets, pwrseq);if (ret) goto err_put_pwrseq;
Greg Kroah-Hartman
maintainerPATCH 280/398 mmc: core: Cancel SDIO IRQ work before freeing host
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 6feadbecdae60a6324c967f3b1493741083793a3 upstream.
A host controller that uses sdio_signal_irq() schedules host->sdio_irq_work from its interrupt handler. That work is only cancelled on the suspend path (mmc_sdio_suspend()), not on the remove/free path, so a worker armed just before the controller freed its IRQ can run after mmc_host_classdev_release() has freed the host and dereference it through container_of().
Cancel host->sdio_irq_work in mmc_free_host(), like the existing host->detect drain added by commit 1036f69e2513 ("mmc: core: Cancel delayed work before releasing host").
This issue was found by an in-house static analysis tool.
--- drivers/mmc/core/host.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/core/host.c +1 -0
@@ -693,6 +693,7 @@ EXPORT_SYMBOL(mmc_remove_host);void mmc_free_host (struct mmc_host *host) {cancel_delayed_work_sync (&host->detect); +cancel_work_sync (&host->sdio_irq_work);mmc_pwrseq_free (host);put_device (&host->class_dev); }
Greg Kroah-Hartman
maintainerPATCH 281/398 mmc: core: Fix OF node reference leak on card add failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhu Ling <[email protected]>
commit 08b54e16d547d5c1aa61bf7a3595bb1620975eeb upstream.
mmc_of_find_child_device() returns a device node with its reference count incremented. mmc_add_card() stores the reference before calling device_add(), while the card is marked present only after device_add() succeeds.
If device_add() fails, the callers release the card through mmc_remove_card(). However, mmc_remove_card() only drops the OF node reference for a present card, leaking the reference on this error path.
Move of_node_put() outside the present-card conditional so the reference is released for both registered cards and card-add failures.
--- drivers/mmc/core/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/bus.c +1 -1
@@ -417,8 +417,8 @@ void mmc_remove_card(struct mmc_card *ca mmc_hostname(card->host), card->rca); }device_del (&card->dev); -of_node_put (card->dev.of_node); } +of_node_put (card->dev.of_node);if (host->cqe_enabled) { host->cqe_ops->cqe_disable (host);
Greg Kroah-Hartman
maintainerPATCH 282/398 mmc: hsq: Fix use-after-free in retry work
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 5d132990475f02cfa1debe03d50b479432864ebd upstream.
mmc_hsq_pump_requests() queues retry_work when request_atomic() returns -EBUSY; today sdhci-sprd is the only consumer that implements request_atomic(). The work is embedded in a devm-allocated mmc_hsq, but is never cancelled during driver removal. Work still pending at unbind can therefore run after the devm allocation has been released and dereference hsq->mmc and hsq->mrq.
Use devm_work_autocancel() to cancel and drain retry_work before the devm allocation is released. By the time devres cleanup begins, mmc_remove_host() has already stopped the host, so no new requests can arm the work.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mmc_hsq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/host/mmc_hsq.c +7 -1
@@ -7,6 +7,7 @@* Author: Baolin Wang <[email protected]> */ +#include <linux/devm-helpers.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> #include <linux/module.h>
@@ -345,6 +346,7 @@ static const struct mmc_cqe_ops mmc_hsq_int mmc_hsq_init (struct mmc_hsq *hsq,struct mmc_host *mmc) { +int ret;int i; hsq->num_slots =HSQ_NUM_SLOTS ; hsq->next_tag =HSQ_INVALID_TAG ;
@@ -363,7 +365,11 @@ int mmc_hsq_init(struct mmc_hsq *hsq, stfor (i =0 ; i <HSQ_NUM_SLOTS ; i++) hsq->tag_slot[i] =HSQ_INVALID_TAG ; -INIT_WORK (&hsq->retry_work, mmc_hsq_retry_handler); + ret =devm_work_autocancel (mmc_dev (mmc), &hsq->retry_work, + mmc_hsq_retry_handler); +if (ret) +return ret; +spin_lock_init (&hsq->lock);init_waitqueue_head (&hsq->wait_queue);
Greg Kroah-Hartman
maintainerPATCH 283/398 mmc: mmci: Fix use-after-free in busy-timeout work
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 2b19cf3e50cddaff07b657dae1a8f30f06032852 upstream.
ux500_busy_complete() can queue ux500_busy_timeout_work for an R1b command, but mmci_remove() never cancels it. The work can subsequently dereference the devm-allocated mmci_host after it has been released.
Mask the controller interrupts and disable the delayed work during removal. This drains any queued instance and stops an IRQ handler that is still in progress from queueing the work again once it has been disabled.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mmci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/host/mmci.c +3 -0
@@ -2511,6 +2511,9 @@ static void mmci_remove(struct amba_deviwritel (0 , host->base +MMCICOMMAND );writel (0 , host->base +MMCIDATACTRL ); +if (variant->busy_detect) +disable_delayed_work_sync (&host->ux500_busy_timeout_work); +mmci_dma_release (host);clk_disable_unprepare (host->clk); }
Greg Kroah-Hartman
maintainerPATCH 284/398 mmc: mxcmmc: cancel data work and watchdog on remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit d3a421c82412344022982d5b91ba23194a0a6f29 upstream.
mxcmci_remove() frees the host through the devm tail, but neither it nor mmc_remove_host() drains the driver's own asynchronous state. host->watchdog, a 10 s timer armed on the DMA path in mxcmci_setup_data(), is deleted only by the DMA- and IRQ-complete paths, which the remove path does not explicitly drain; it can therefore fire after the host is freed and dereference it in mxcmci_watchdog(). host->datawork, armed from the IRQ handler on the PIO path, is not cancelled by the remove path either.
Free the devm-registered IRQ, then cancel datawork and delete the watchdog in mxcmci_remove(), before dma_release_channel(). Freeing the IRQ first keeps a trailing handler from re-arming datawork between the cancel and the host free. Both callbacks are non-self-rearming.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mxcmmc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/host/mxcmmc.c +4 -0
@@ -1173,6 +1173,10 @@ static void mxcmci_remove(struct platformmc_remove_host (mmc); +devm_free_irq (&pdev->dev,platform_get_irq (pdev,0 ), host); +cancel_work_sync (&host->datawork); +timer_delete_sync (&host->watchdog); +if (host->pdata && host->pdata->exit) host->pdata->exit (&pdev->dev, mmc);
Greg Kroah-Hartman
maintainerPATCH 285/398 mmc: rtsx_pci_sdmmc: ignore broken write-protect on ThinkPad X260
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Maillard <[email protected]>
commit 9c182bc5d7817437a7d04ab96133f9191846d93d upstream.
The Realtek RTS522A card reader in the Lenovo ThinkPad X260 (subsystem 17aa:504a) incorrectly reports inserted SD cards as write-protected.
This causes the MMC core to expose the card as read-only:
mmcblk0: mmc0:aaaa SN256 238 GiB (ro)
and /sys/block/mmcblk0/ro reports 1.
Setting MMC_CAP2_NO_WRITE_PROTECT makes the card writable again. Limit the quirk to the affected Lenovo subsystem.
--- drivers/mmc/host/rtsx_pci_sdmmc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mmc/host/rtsx_pci_sdmmc.c +5 -0
@@ -1501,6 +1501,11 @@ static void realtek_init_host(struct rea mmc->caps = mmc->caps |MMC_CAP_AGGRESSIVE_PM ; mmc->caps2 =MMC_CAP2_NO_PRESCAN_POWERUP |MMC_CAP2_FULL_PWR_CYCLE |MMC_CAP2_NO_SDIO ; + +if (pcr->pci->device ==0x522a && + pcr->pci->subsystem_vendor ==PCI_VENDOR_ID_LENOVO && + pcr->pci->subsystem_device ==0x504a ) + mmc->caps2 |=MMC_CAP2_NO_WRITE_PROTECT ; mmc->max_current_330 =400 ; mmc->max_current_180 =800 ; mmc->ops = &realtek_pci_sdmmc_ops;
Greg Kroah-Hartman
maintainerPATCH 286/398 mmc: sdhci-of-aspeed: Remove children before releasing SDC resources
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 4396d70bb7fec531bcf934fed016b2f3300c670b upstream.
Probe failure and removal leave SDHCI child devices registered after the parent clock and managed resources are released.
Unregister the OF children in reverse order before disabling the parent clock on both paths. Use of_platform_device_destroy() because manual child creation does not set the flag required by of_platform_depopulate().
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/mmc/host/sdhci-of-aspeed.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-of-aspeed.c +4 -1
@@ -555,12 +555,14 @@ static int aspeed_sdc_probe(struct platfif (!cpdev) {of_node_put (child); ret = -ENODEV ; - goto err_clk; + goto err_children; } }return 0 ; +err_children: +device_for_each_child_reverse (&pdev->dev,NULL , of_platform_device_destroy); err_clk:clk_disable_unprepare (sdc->clk);return ret;
@@ -570,6 +572,7 @@ static void aspeed_sdc_remove(struct pla {struct aspeed_sdc *sdc =dev_get_drvdata (&pdev->dev); +device_for_each_child_reverse (&pdev->dev,NULL , of_platform_device_destroy);clk_disable_unprepare (sdc->clk); }
Greg Kroah-Hartman
maintainerPATCH 287/398 mmc: sdio_uart: fix xmit_fifo leak when the port table is full
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
commit 53823e25793a97d07e6e98e0904bbf74cac8bc76 upstream.
sdio_uart_add_port() allocates the transmit fifo before claiming a slot in sdio_uart_table[]. When all UART_NR slots are taken, it returns -EBUSY with the fifo still allocated, but the probe error path only kfree()s the port, leaking the transmit fifo.
Free the fifo in the failure path of sdio_uart_add_port() itself so the function retains nothing on error.
--- drivers/mmc/core/sdio_uart.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/core/sdio_uart.c +3 -0
@@ -104,6 +104,9 @@ static int sdio_uart_add_port(struct sdi }spin_unlock (&sdio_uart_table_lock); +if (ret) +kfifo_free (&port->xmit_fifo); +return ret; }
Greg Kroah-Hartman
maintainerPATCH 288/398 mmc: sh_mmcif: initialize IRQ-thread mutex before requesting interrupt
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit d5ea0d226e8f0801d78702142a124d78c317d822 upstream.
The threaded IRQ handler can run before devm_request_threaded_irq() returns, but thread_lock was initialized afterwards. Initialize it before requesting either interrupt.
--- drivers/mmc/host/sh_mmcif.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mmc/host/sh_mmcif.c +1 -2
@@ -1462,6 +1462,7 @@ static int sh_mmcif_probe(struct platfor host->pd = pdev;spin_lock_init (&host->lock); +mutex_init (&host->thread_lock); mmc->ops = &sh_mmcif_ops;sh_mmcif_init_ocr (host);
@@ -1520,8 +1521,6 @@ static int sh_mmcif_probe(struct platfor } } -mutex_init (&host->thread_lock); - ret =mmc_add_host (mmc);if (ret <0 ) goto err_clk;
Greg Kroah-Hartman
maintainerPATCH 289/398 mmc: spi: reset bytes_xfered before retrying CRC failures
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 8b0cc8707f65e0f51912e764e1b309b2559db1ec upstream.
mmc_spi_data_do() updates data->bytes_xfered after each block has been transferred successfully. If a later block in the same data request fails with a CRC error, data->bytes_xfered may therefore contain the number of bytes completed before the failing block.
mmc_spi_request() has a private recovery path for such CRC failures. It sends STOP_TRANSMISSION, clears data->error and jumps back to crc_recover to issue the same command and data request again. However, it does not clear data->bytes_xfered before the retry.
If the retry succeeds, the request is completed with the bytes from the failed attempt still included in data->bytes_xfered. For a multi-block request this can make the completed request report more bytes than were transferred by the successful retry, and can even exceed the request size when most blocks completed before the CRC error.
This is most likely to be observed on MMC-over-SPI systems where long multi-block transfers occasionally hit a data CRC error but the mmc_spi-internal retry succeeds. The data itself is retried, but the completion accounting is not.
Clear data->bytes_xfered together with data->error before repeating the request so the final completion reports only the bytes transferred by the successful attempt.
--- drivers/mmc/host/mmc_spi.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/mmc_spi.c +1 -0
@@ -952,6 +952,7 @@ crc_recover: status =mmc_spi_command_send (host, mrq, &stop,0 ); crc_retry--; mrq->data->error =0 ; + mrq->data->bytes_xfered =0 ; goto crc_recover; }
Greg Kroah-Hartman
maintainerPATCH 290/398 mmc: sdhci_am654: Move tuning_loop to local variable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit ff894dced1a7ad7523f9c65dbdb53d02474cca0f upstream.
The tuning_loop field in struct sdhci_am654_data is only used within sdhci_am654_platform_execute_tuning() as a loop counter that is initialized to 0 in sdhci_am654_init(). Since it shouldn't persist across function calls, otherwise every failure expends its "budget", move it to a local variable and remove the struct field along with the now-unnecessary initialization.
--- drivers/mmc/host/sdhci_am654.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci_am654.c +2 -5
@@ -151,7 +151,6 @@ struct sdhci_am654_data {u32 flags;u32 quirks;bool dll_enable; -u32 tuning_loop;#define SDHCI_AM654_QUIRK_FORCE_CDTEST BIT(0)#define SDHCI_AM654_QUIRK_SUPPRESS_V1P8_ENA BIT(1)
@@ -576,13 +575,14 @@ static int sdhci_am654_platform_execute_struct sdhci_am654_data *sdhci_am654 =sdhci_pltfm_priv (pltfm_host);unsigned char timing = host->mmc->ios.timing;struct device *dev =mmc_dev (host->mmc); +unsigned int tuning_loop =0 ;int itapdly;do { itapdly =sdhci_am654_do_tuning (host, opcode);if (itapdly >=0 )break ; - }while (++sdhci_am654->tuning_loop <RETRY_TUNING_MAX ); + }while (++tuning_loop <RETRY_TUNING_MAX );if (itapdly <0 ) {dev_err (dev,"Failed to find itapdly, fail tuning\n" );
@@ -806,9 +806,6 @@ static int sdhci_am654_init(struct sdhciregmap_update_bits (sdhci_am654->base,CTL_CFG_3 ,TUNINGFORSDR50_MASK ,TUNINGFORSDR50_MASK ); -/* Use to re-execute tuning */ - sdhci_am654->tuning_loop =0 ; - ret =sdhci_setup_host (host);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 291/398 mmc: sdhci_am654: Reset command and data lines on failed tuning
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit 7197d9107d9545730153b82ea5a411c5208b443f upstream.
The CMD/DATA reset after tuning should be performed regardless of whether tuning succeeded or failed, since tuning data may remain in the buffer in either case. Move the error return after the reset so that the controller is always cleaned up.
--- drivers/mmc/host/sdhci_am654.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mmc/host/sdhci_am654.c +1 -3
@@ -442,15 +442,13 @@ static int sdhci_am654_execute_tuning(ststruct sdhci_host *host =mmc_priv (mmc);int err =sdhci_execute_tuning (mmc, opcode); -if (err) -return err;/* * Tuning data remains in the buffer after tuning. * Do a command and data reset to get rid of it */ sdhci_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA ); -return 0 ; +return err; }static u32 sdhci_am654_cqhci_irq (struct sdhci_host *host,u32 intmask)
Greg Kroah-Hartman
maintainerPATCH 292/398 mmc: sdhci_am654: Clear ITAPDLY on tuning failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit c9f47cc8c37f7659897142ffe216c250fbc1d4ed upstream.
When tuning fails, stale ITAPDLY values can persist and interfere with subsequent I/O accesses, for example in DDR50 mode in cards with no tuning support. Move the ITAPDLY enable setting out of the tuning loop to after successful tuning, and explicitly clear ITAPDLY (delay and enable) when tuning fails so that we are sure only working values are actually left in hardware.
--- drivers/mmc/host/sdhci_am654.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci_am654.c +7 -5
@@ -527,7 +527,6 @@ static int sdhci_am654_do_tuning(struct {struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host);struct sdhci_am654_data *sdhci_am654 =sdhci_pltfm_priv (pltfm_host); -unsigned char timing = host->mmc->ios.timing;struct window fail_window[ITAPDLY_LENGTH ];struct device *dev =mmc_dev (host->mmc);u8 curr_pass, itap;
@@ -536,11 +535,8 @@ static int sdhci_am654_do_tuning(structmemset (fail_window,0 ,sizeof (fail_window)); -/* Enable ITAPDLY */ - sdhci_am654->itap_del_ena[timing] =0x1 ; -for (itap =0 ; itap <ITAPDLY_LENGTH ; itap++) { -sdhci_am654_write_itapdly (sdhci_am654, itap, sdhci_am654->itap_del_ena[timing]); +sdhci_am654_write_itapdly (sdhci_am654, itap,0x1 ); curr_pass = !mmc_send_tuning (host->mmc, opcode,NULL );
@@ -584,10 +580,16 @@ static int sdhci_am654_platform_execute_if (itapdly <0 ) {dev_err (dev,"Failed to find itapdly, fail tuning\n" ); +sdhci_am654_write_itapdly (sdhci_am654,0 ,0 ); + sdhci_am654->itap_del_ena[timing] =0 ; + sdhci_am654->itap_del_sel[timing] =0 ;return -1 ; }dev_dbg (dev,"Passed tuning, final itapdly=%d\n" , itapdly); + +/* Enable ITAPDLY */ + sdhci_am654->itap_del_ena[timing] =0x1 ;sdhci_am654_write_itapdly (sdhci_am654, itapdly, sdhci_am654->itap_del_ena[timing]);/* Save ITAPDLY */ sdhci_am654->itap_del_sel[timing] = itapdly;
Greg Kroah-Hartman
maintainerPATCH 293/398 mmc: sdhci_am654: Fallback to DT-provided itap delay on DDR50 tuning failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit 308d05225281d86150d88141990d6caf8c902349 upstream.
DDR50 mode is not required to support the tuning command CMD19, meaning that calibration may fail on cards that do not implement it, in which case a known-good itap delay value should be programmed into the host controller.
Do this by reading the (already defined) itap delay DT property for DDR50 and, if tuning fails for this mode, fall back to the DT-provided itap delay value. If the DT does not provide a value for DDR50 fallback then this simply disables using itapdly.
--- drivers/mmc/host/sdhci_am654.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci_am654.c +21 -5
@@ -126,7 +126,7 @@ static const struct timing_data td[] = {NULL , MMC_CAP_UHS_SDR104}, [MMC_TIMING_UHS_DDR50] = {"ti,otap-del-sel-ddr50", -NULL , +"ti,itap-del-sel-ddr50" , MMC_CAP_UHS_DDR50}, [MMC_TIMING_MMC_DDR52] = {"ti,otap-del-sel-ddr52", "ti,itap-del-sel-ddr52",
@@ -144,6 +144,8 @@ struct sdhci_am654_data {u32 otap_del_sel[ARRAY_SIZE (td)];u32 itap_del_sel[ARRAY_SIZE (td)];u32 itap_del_ena[ARRAY_SIZE (td)]; +u32 itap_del_sel_dt_ddr50; +u32 itap_del_ena_dt_ddr50;int clkbuf_sel;int trm_icp;int drv_strength;
@@ -579,10 +581,19 @@ static int sdhci_am654_platform_execute_ }while (++tuning_loop <RETRY_TUNING_MAX );if (itapdly <0 ) { -dev_err (dev,"Failed to find itapdly, fail tuning\n" ); -sdhci_am654_write_itapdly (sdhci_am654,0 ,0 ); - sdhci_am654->itap_del_ena[timing] =0 ; - sdhci_am654->itap_del_sel[timing] =0 ; +if (timing ==MMC_TIMING_UHS_DDR50 ) { +dev_dbg (dev,"Failed DDR50 tuning, fallback to DT ITAP\n" ); + sdhci_am654->itap_del_sel[timing] = sdhci_am654->itap_del_sel_dt_ddr50; + sdhci_am654->itap_del_ena[timing] = sdhci_am654->itap_del_ena_dt_ddr50; + }else { +dev_err (dev,"Failed to find itapdly, fail tuning\n" ); + sdhci_am654->itap_del_ena[timing] =0 ; + sdhci_am654->itap_del_sel[timing] =0 ; + } + +sdhci_am654_write_itapdly (sdhci_am654, + sdhci_am654->itap_del_sel[timing], + sdhci_am654->itap_del_ena[timing]);return -1 ; }
@@ -758,6 +769,11 @@ static int sdhci_am654_get_otap_delay(st } } + sdhci_am654->itap_del_sel_dt_ddr50 = + sdhci_am654->itap_del_sel[MMC_TIMING_UHS_DDR50 ]; + sdhci_am654->itap_del_ena_dt_ddr50 = + sdhci_am654->itap_del_ena[MMC_TIMING_UHS_DDR50 ]; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 294/398 Input: adp5588-keys - cache GPIO state before registering the gpiochip
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alvin Šipraga <[email protected]>
commit 21efadc62272cabee9bec27777ae75d84a9ca8a8 upstream.
So as not to clobber any pre-programmed GPIO state in the execution of its gpiochip ops, the driver caches things during probe time. However, since those ops can be called both during and immediately after the call to devm_gpiochip_add_data(), it is imperative that things are cached before that. That's not the case right now, so reorder the two steps to prevent any clobbering.
In the concrete example which motivated this change, a bootloader was preconfiguring an important GPIO output to HIGH before booting the kernel. Linux would then inadvertently set that output to LOW while configuring a GPIO hog on a discrete GPIO line within the same 8-bit bank (because the cached value was 0=LOW).
--- drivers/input/keyboard/adp5588-keys.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/input/keyboard/adp5588-keys.c +6 -6
@@ -447,12 +447,6 @@ static int adp5588_gpio_add(struct adp55mutex_init (&kpad->gpio_lock); - error =devm_gpiochip_add_data (dev, &kpad->gc, kpad); -if (error) { -dev_err (dev,"gpiochip_add failed: %d\n" , error); -return error; - } -for (i =0 ; i <=ADP5588_BANK (ADP5588_MAXGPIO ); i++) { kpad->dat_out[i] =adp5588_read (kpad->client,GPIO_DAT_OUT1 + i);
@@ -460,6 +454,12 @@ static int adp5588_gpio_add(struct adp55 kpad->pull_dis[i] =adp5588_read (kpad->client,GPIO_PULL1 + i); } + error =devm_gpiochip_add_data (dev, &kpad->gc, kpad); +if (error) { +dev_err (dev,"gpiochip_add failed: %d\n" , error); +return error; + } +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 295/398 Input: atkbd - skip deactivate for Xiaomi Redmi Book Pro 16 2026
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Turtanov <[email protected]>
commit aefbda23eeba234c3ff0f135dc5be6e294bd25a6 upstream.
The internal keyboard of the Xiaomi Redmi Book Pro 16 2026 (board TM2425) does not work: atkbd_probe() succeeds and every command is ACKed, but no scancodes ever arrive afterwards.
Testing on the hardware through serio_raw shows that ATKBD_CMD_RESET_DIS (0xF5) is the culprit. After 0xF5 the embedded controller keeps ACKing commands but stops delivering scancodes, and neither ATKBD_CMD_ENABLE (0xF4) nor ATKBD_CMD_RESET_BAT (0xFF) bring them back. Only re-enabling the keyboard interface at the controller level (i8042 command 0xAE, or rewriting the command byte as i8042_port_close() does) revives it. Running the init sequence without 0xF5 (0xED 0x00, 0xF3 0x00, 0xF4) keeps the keyboard working.
'i8042.dumbkbd=1' also works around this, but then the driver never writes to the keyboard and the LEDs cannot be controlled. Use the existing atkbd_deactivate_fixup quirk instead, as done for the sibling TM2424 by commit 3a046db33bb9 ("Input: atkbd - skip deactivate for Xiaomi Book Pro 14's internal keyboard"). Tested on v7.2: keyboard, Caps Lock LED and s2idle suspend/resume all work.
DMI: XIAOMI REDMI Book Pro 16 2026/TM2425, BIOS RMAPT6B0P0909 05/22/2026
--- drivers/input/keyboard/atkbd.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/input/keyboard/atkbd.c +8 -0
@@ -1975,6 +1975,14 @@ static const struct dmi_system_id atkbd_ }, .callback = atkbd_deactivate_fixup, }, + { + /* Xiaomi Redmi Book Pro 16 2026 (TM2425) */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "XIAOMI"), + DMI_MATCH(DMI_PRODUCT_NAME, "REDMI Book Pro 16 2026"), + }, + .callback = atkbd_deactivate_fixup, + }, { } };
Greg Kroah-Hartman
maintainerPATCH 296/398 Input: cyttsp5 - clamp the HID report size before memcpy
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit 85f080fb87ed5cd3e46121be677f52c82f26a0ab upstream.
The size field comes from the device and is used as the memcpy() length into response_buf, which is CY_MAX_INPUT bytes.
--- drivers/input/touchscreen/cyttsp5.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/touchscreen/cyttsp5.c +1 -0
@@ -711,6 +711,7 @@ static irqreturn_t cyttsp5_handle_irq(in size =2 ; }else { report_id = ts->input_buf[2 ]; + size =min (size,CY_MAX_INPUT ); }switch (report_id) {
Greg Kroah-Hartman
maintainerPATCH 297/398 Input: evdev - zero absinfo before partial copy in EVIOCSABS
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
commit 8b852965b8eaf910c314dc346967ed82c8d4f235 upstream.
The EVIOCSABS handler copies at most the user supplied ioctl size into an uninitialized on-stack struct input_absinfo:
if (copy_from_user(&abs, p, min_t(size_t, size, sizeof(struct input_absinfo))))
The size comes from _IOC_SIZE() of the ioctl command and is therefore fully controlled by userspace. A short size leaves the trailing part of the structure holding whatever was on the kernel stack, and the whole structure is then stored into the device:
dev->absinfo[t] = abs;
EVIOCGABS hands that back to userspace, disclosing the stale stack bytes. Only the resolution field is currently cleared, which covers the legacy struct layout but not an arbitrarily short size.
Zero the structure before the copy so any part not supplied by the caller reads back as zero. The existing resolution fixup is kept, since it also handles a size that partially overlaps that field.
--- drivers/input/evdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/evdev.c +2 -0
@@ -1229,6 +1229,8 @@ static long evdev_do_ioctl(struct file * t =_IOC_NR (cmd) &ABS_MAX ; +memset (&abs,0 ,sizeof (abs)); +if (copy_from_user (&abs, p,min_t (size_t, size,sizeof (struct input_absinfo ))))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 298/398 Input: hp_sdc - shut down kicker timer on module exit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 309731e95917125bbd13626a7a5600490a5bf44f upstream.
hp_sdc_kicker() rearms hp_sdc.kicker with mod_timer() after scheduling the tasklet. The module exit path uses timer_delete_sync(). That waits for a callback already running but can still leave the timer rearmed.
A callback can therefore leave the timer pending while hp_sdc_exit() tears down the driver, allowing timer activity to access dismantled driver state.
Use timer_shutdown_sync() for final teardown. It waits for a running callback and prevents rearming after module exit begins.
--- drivers/input/serio/hp_sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/serio/hp_sdc.c +1 -1
@@ -981,7 +981,7 @@ static void hp_sdc_exit(void)free_irq (hp_sdc.irq, &hp_sdc);write_unlock_irq (&hp_sdc.lock); -timer_delete_sync (&hp_sdc.kicker); +timer_shutdown_sync (&hp_sdc.kicker);tasklet_kill (&hp_sdc.task);
Greg Kroah-Hartman
maintainerPATCH 299/398 Input: i8042 - add quirk for Acer Aspire Go 15 AG15-42P
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Sommers <[email protected]>
commit 25e424eb4ae1a662d9c3573218d06ac32f797fc5 upstream.
On the Acer Aspire Go 15 (AG15-42P), the internal keyboard drops out ~5 seconds after boot on both Linux and Linux-LTS kernels. Keystrokes on the built-in keyboard stop registering while the trackpad and external keyboards remain functional.
Testing confirms that booting with the i8042.reset kernel parameter resolves the issue and keeps the internal keyboard responsive.
Add SERIO_QUIRK_RESET_ALWAYS to i8042_dmi_quirk_table for the Acer Aspire AG15-42P to automatically apply this quirk on boot.
--- drivers/input/serio/i8042-acpipnpio.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/serio/i8042-acpipnpio.h +7 -0
@@ -261,6 +261,13 @@ static const struct dmi_system_id i8042_ { .matches = {DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Aspire AG15-42P"), + }, + .driver_data = (void *)(SERIO_QUIRK_RESET_ALWAYS ) + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), DMI_MATCH(DMI_PRODUCT_NAME, "Aspire ES1-132"), }, .driver_data = (void *)(SERIO_QUIRK_RESET_ALWAYS )
Greg Kroah-Hartman
maintainerPATCH 300/398 Input: rmi_smbus - fix out-of-bounds read in rmi_smb_write_block()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 51cfe54f815ae175c7d1126b983d4d7c89715004 upstream.
When chunking writes into SMBus blocks in rmi_smb_write_block(), the loop calculates block_len using the original total length (len) instead of the remaining length (cur_len).
If len is greater than 32 bytes (SMB_MAX_COUNT), block_len remains 32 for every iteration, even on the final partial chunk where fewer than 32 bytes remain. This causes smb_block_write() to read 32 bytes from the advanced data buffer pointer, reading past the end of the input buffer.
Fix this by calculating block_len using cur_len and advancing the buffer and address pointers by block_len.
--- drivers/input/rmi4/rmi_smbus.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/input/rmi4/rmi_smbus.c +5 -5
@@ -140,7 +140,7 @@ static int rmi_smb_write_block(struct rmu8 commandcode;struct rmi_smb_xport *rmi_smb = container_of(xport, struct rmi_smb_xport, xport); -int cur_len = (int )len; +size_t cur_len = len;mutex_lock (&rmi_smb->page_mutex);
@@ -148,7 +148,7 @@ static int rmi_smb_write_block(struct rm/* * break into 32 bytes chunks to write get command code */ -int block_len =min_t (int, len,SMB_MAX_COUNT ); +int block_len =min_t (size_t, cur_len,SMB_MAX_COUNT ); retval =rmi_smb_get_command_code (xport, rmiaddr, block_len, false, &commandcode);
@@ -161,9 +161,9 @@ static int rmi_smb_write_block(struct rm goto exit;/* prepare to write next block of bytes */ - cur_len -=SMB_MAX_COUNT ; - databuff +=SMB_MAX_COUNT ; - rmiaddr +=SMB_MAX_COUNT ; + cur_len -= block_len; + databuff += block_len; + rmiaddr += block_len; } exit:mutex_unlock (&rmi_smb->page_mutex);
Greg Kroah-Hartman
maintainerPATCH 301/398 Input: soc_button_array - fix MS Surface Pro 11 probe failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit ed22ad5fdbdbf9b4cb4ad3003f60314b5a5eb89d upstream.
On the MS Surface Pro 11 soc_button_array probing races with the GPIO driver probing. If soc_button_array wins the race then gpiod_get() returns EPROBE_DEFER, which should normally take care of retrying later, but the soc_button_array code deliberately ignores EPROBE_DEFER causing it to fail its probe() which causes the volume and power buttons to now work.
The ignoring of EPROBE_DEFER is there to deal with a problem specific to older Bay Trail (BYT) and Cherry Trail (CHT) tablets which often use this driver. Modify the error handling to only ignore EPROBE_DEFER on BYT and CHT platforms and propagate EPROBE_DEFER normally on other platforms.
--- drivers/input/misc/soc_button_array.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/input/misc/soc_button_array.c +11 -3
@@ -16,6 +16,7 @@#include <linux/gpio/consumer.h> #include <linux/gpio_keys.h> #include <linux/gpio.h> +#include <linux/platform_data/x86/soc.h> #include <linux/platform_device.h> static bool use_low_level_irq;
@@ -160,7 +161,7 @@ soc_button_device_create(struct platformstruct gpio_keys_platform_data *gpio_keys_pdata;const struct dmi_system_id *dmi_id;int invalid_acpi_index =-1 ; -int error, gpio, irq; +int error, gpio, irq =0 ;int n_buttons =0 ;for (info = button_info; info->name; info++)
@@ -191,8 +192,9 @@ soc_button_device_create(struct platform error =soc_button_lookup_gpio (&pdev->dev, info->acpi_index, &gpio, &irq);if (error || irq <0 ) {/* -* Skip GPIO if not present. Note we deliberately -* ignore -EPROBE_DEFER errors here. On some devices +* Propagate -EPROBE_DEFER, skip button on other errors. +* +* -EPROBE_DEFER is ignored on Bay & Cherry Trail. Here * Intel is using so called virtual GPIOs which are not * GPIOs at all but some way for AML code to check some * random status bits without need a custom opregion.
@@ -201,6 +203,12 @@ soc_button_device_create(struct platform* we do not have a driver for these so they will never * show up, therefore we ignore -EPROBE_DEFER. */ +if ((error == -EPROBE_DEFER || irq == -EPROBE_DEFER ) && + !(soc_intel_is_byt () ||soc_intel_is_cht ())) { + error = -EPROBE_DEFER ; + goto err_free_mem; + } +continue ; }
Greg Kroah-Hartman
maintainerPATCH 302/398 Input: soc_button_array - check btns_desc->package.count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit fb5022278b6ea7f1838e3ef78028d5d5e3375f65 upstream.
Check that btns_desc->package.count is not 0 before accessing btns_desc->package.elements[0].
--- drivers/input/misc/soc_button_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/soc_button_array.c +1 -1
@@ -377,7 +377,7 @@ static struct soc_button_info *soc_butto } } -if (!btns_desc) { +if (!btns_desc || !btns_desc->package.count) {dev_err (dev,"ACPI Button Descriptors not found\n" ); button_info =ERR_PTR (-ENODEV ); goto out;
Greg Kroah-Hartman
maintainerPATCH 303/398 Input: synaptics - disable InterTouch on ThinkPad T440p (board id 2722)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphaël Larocque <[email protected]>
commit 26eb3d92c7a4d7adb1ae1740ca6e8e100b11d1ec upstream.
The Lenovo ThinkPad T440p (PNP ID LEN0036, board id 2722) has a Synaptics touchpad whose SMBus companion is not ready at boot and takes roughly 200 seconds to appear. During this window the touchpad and TrackPoint are completely unresponsive on approximately 50% of boots, making the machine unusable until the companion finally registers.
The device is in the topbuttonpad_pnp_ids[] SMBus allowlist, so the kernel attempts to use SMBus/RMI4 mode by default. When the companion is not ready, psmouse_smbus_init() leaves breadcrumbs and returns -EAGAIN, the PS/2 fallback path is taken, but the device does not function properly until the companion appears and RMI4 takes over.
Disable SMBus InterTouch for board id 2722 so the touchpad and TrackPoint work immediately via PS/2 from boot. Users can still force SMBus with psmouse.synaptics_intertouch=1 if needed.
--- drivers/input/mouse/synaptics.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/input/mouse/synaptics.c +8 -0
@@ -1837,6 +1837,14 @@ static int synaptics_setup_intertouch(streturn -ENXIO ; } + +/* Disable intertouch on known-broken board revisions */ +if (info->board_id ==2722 ) { +psmouse_info (psmouse, +"Disabling intertouch for board id %u\n" , + info->board_id); +return -ENXIO ; + } }psmouse_info (psmouse,"Trying to set up SMBus access\n" );
Re: [PATCH 6.18 303/398] Input: synaptics - disable InterTouch on ThinkPad T440p (board id 2722)
Quoted 12 lines · Greg Kroah-Hartman
6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphaël Larocque <[email protected]>
commit
26eb3d92c7a4d7adb1ae1740ca6e8e100b11d1ecupstream.The Lenovo ThinkPad T440p (PNP ID LEN0036, board id 2722) has a Synaptics touchpad whose SMBus companion is not ready at boot and takes roughly 200 seconds to appear.
[...]
Quoted 2 lines
Disable SMBus InterTouch for board id 2722 so the touchpad and TrackPoint work immediately via PS/2 from boot.
I have a concern about this one. Board id 2722 isn't specific to the T440p. My ThinkPad L440 has the same Synaptics board id, and this patch would move it from SMBus/RMI4 to PS/2. I have never hit the issue this commit fixes, and I haven't seen it reported on other potentially affected models either.
I sent a patch [1] that limits the quirk to the T440p. Previous attempts to move these touchpads to PS/2 were rejected [2], as explained in that patch's commit message.
Could this be dropped from the stable queue until it's sorted out upstream?
[1] https://lore.kernel.org/all/20260925230039.236786-1-
[email protected]/
[2] https://lore.kernel.org/linux-
input/[email protected]/
Greg Kroah-Hartman
maintainerRe: [PATCH 6.18 303/398] Input: synaptics - disable InterTouch on ThinkPad T440p (board id 2722)
Quoted 27 lines · Daniel Salmun
Quoted 12 lines · Greg Kroah-Hartman
6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphaël Larocque <[email protected]>
commit
26eb3d92c7a4d7adb1ae1740ca6e8e100b11d1ecupstream.The Lenovo ThinkPad T440p (PNP ID LEN0036, board id 2722) has a Synaptics touchpad whose SMBus companion is not ready at boot and takes roughly 200 seconds to appear.
[...]
Quoted 2 lines
Disable SMBus InterTouch for board id 2722 so the touchpad and TrackPoint work immediately via PS/2 from boot.
I have a concern about this one. Board id 2722 isn't specific to the T440p. My ThinkPad L440 has the same Synaptics board id, and this patch would move it from SMBus/RMI4 to PS/2. I have never hit the issue this commit fixes, and I haven't seen it reported on other potentially affected models either.
I sent a patch [1] that limits the quirk to the T440p. Previous attempts to move these touchpads to PS/2 were rejected [2], as explained in that patch's commit message.
Quoted 8 lines
Could this be dropped from the stable queue until it's sorted out upstream?
[1] https://lore.kernel.org/all/20260925230039.236786-1-
[email protected]/
[2] https://lore.kernel.org/linux-
input/[email protected]/
Let's just queue up whatever gets commited in Linus's tree to resolve this.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerPATCH 304/398 Input: synaptics-rmi4 - fix GPF in suspend and resume when unbound
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit fe10579b6dc3f0dac61e51e1797cacbba5039ac2 upstream.
Transport drivers (such as rmi_i2c and rmi_spi) invoke rmi_driver_suspend() and rmi_driver_resume() on their child rmi_dev device during system power management events. However, transport drivers are fully registered and operational even if the physical RMI driver failed to bind or probe the rmi_dev device.
When rmi_driver_suspend() or rmi_driver_resume() is called on an unbound rmi_dev, dev_get_drvdata() returns NULL. Calling rmi_disable_irq() or rmi_enable_irq() without driver data attached causes a NULL pointer dereference and General Protection Fault when attempting to lock data->enabled_mutex.
Fix this by checking if driver data is attached to rmi_dev in rmi_driver_suspend() and rmi_driver_resume(), exiting early if no driver data is present.
--- drivers/input/rmi4/rmi_driver.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/input/rmi4/rmi_driver.c +13 -0
@@ -947,6 +947,15 @@ int rmi_driver_suspend(struct rmi_device {int retval; +/* +* Transport driver will try to suspend RMI device even if physical +* driver did not bind to the RMI device, because transport device +* (I2C, SPI) is fully registered and operational. Exit early if +* there is no driver data attached to the RMI device. +*/ +if (!dev_get_drvdata (&rmi_dev->dev)) +return 0 ; + retval =rmi_suspend_functions (rmi_dev);if (retval) dev_warn(&rmi_dev->dev, "Failed to suspend functions: %d\n",
@@ -961,6 +970,10 @@ int rmi_driver_resume(struct rmi_device {int retval; +/* Skip if not fully bound to RMI driver */ +if (!dev_get_drvdata (&rmi_dev->dev)) +return 0 ; +rmi_enable_irq (rmi_dev, clear_wake); retval =rmi_resume_functions (rmi_dev);
Greg Kroah-Hartman
maintainerPATCH 305/398 Input: zero ff_effect before compat copy in input_ff_effect_from_user
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
commit f84819ef8d66931ee3998fee3c4f03230f4cb6cc upstream.
In the compat path input_ff_effect_from_user() aliases the caller's native struct ff_effect with the smaller struct ff_effect_compat and copies only the compat sized prefix:
compat_effect = (struct ff_effect_compat *)effect; if (copy_from_user(compat_effect, buffer, sizeof(struct ff_effect_compat)))
The tail of the native structure is never written. Callers pass an uninitialized on-stack object, for example evdev_do_ioctl() for EVIOCSFF, so those bytes keep their previous stack contents. input_ff_upload() then stores the full native structure in ff->effects[id], from where a uinput based force feedback daemon can read it back via UI_BEGIN_FF_UPLOAD, disclosing kernel stack memory to userspace.
Zero the effect before the compat copy.
--- drivers/input/input-compat.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/input-compat.c +2 -0
@@ -76,6 +76,8 @@ int input_ff_effect_from_user(const char*/ compat_effect = (struct ff_effect_compat *)effect; +memset (effect,0 ,sizeof (*effect)); +if (copy_from_user (compat_effect, buffer,sizeof (struct ff_effect_compat )))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 306/398 hwmon: (hp-wmi-sensors) Fix use-after-free in fungible_show()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit e6cb0b4d4ecb8e71fd2200d907ab2e9663356f69 upstream.
nsensor->current_state is dynamically replaced as the sensor's state changes. update_numeric_sensor_from_wobj() does this by freeing the old string and installing a new one:
if (strcmp(trimmed, nsensor->current_state)) {
new_string = hp_wmi_strdup(dev, trimmed);
if (new_string) {
devm_kfree(dev, nsensor->current_state);
nsensor->current_state = new_string;
}
}This function is only ever called from hp_wmi_update_info() while state->lock is held, so the free-and-replace itself is properly serialized against concurrent updates.
fungible_show(), however, reads the same pointer after the lock has already been dropped:
err = hp_wmi_update_info(state, info);
if (err)
return err;
switch (prop) {
...
case HP_WMI_PROPERTY_CURRENT_STATE:
seq_printf(seqf, "%s\n", nsensor->current_state);
break;hp_wmi_update_info() takes state->lock internally and releases it before returning, so by the time fungible_show() dereferences nsensor->current_state in seq_printf(), no lock is held. Two processes reading a sensor's current_state debugfs entry at overlapping times (or one reading it while another read of the same sensor triggers a refresh) can race: one thread's seq_printf() can be part-way through printing the string at the moment another thread's call into update_numeric_sensor_from_wobj() frees it with devm_kfree() and installs a new pointer, causing a use-after-free read.
Take state->lock around the read in fungible_show() as well, so it can never run concurrently with the free-and-replace in update_numeric_sensor_from_wobj().
--- drivers/hwmon/hp-wmi-sensors.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/hp-wmi-sensors.c +2 -0
@@ -1261,7 +1261,9 @@ static int fungible_show(struct seq_filebreak ;case HP_WMI_PROPERTY_CURRENT_STATE : +mutex_lock (&state->lock);seq_printf (seqf,"%s\n" , nsensor->current_state); +mutex_unlock (&state->lock);break ;case HP_WMI_PROPERTY_UNIT_MODIFIER :
Greg Kroah-Hartman
maintainerPATCH 307/398 hwmon: (pmbus/core) increase number of phases and add new mask
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuno Sá <[email protected]>
commit 06bd6794b5fd2163880ac3bfe973d4cc61f359f3 upstream.
Increase the number of phases to 16 as a new upcoming device supports such a number.
While at it, add a new mask for controlling the source of the output voltage.
Note (groeck):
This patch was meant to prepare for support of MAX20826 and compatible devices, which support more than 10 phases per page. However, Sashiko reports that the mp2975 driver already supports up to 14 phases, and the mp2856 driver supports up to 12 phases. This already has the potential for out-of-bounds writes when probing the affected chips, making this patch a bug fix.
--- drivers/hwmon/pmbus/pmbus.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus.h +2 -1
@@ -242,6 +242,7 @@ enum pmbus_regs {/* * OPERATION */ +#define PB_OPERATION_CONTROL_V_SRC GENMASK(5, 4)#define PB_OPERATION_CONTROL_ON BIT(7)/*
@@ -386,7 +387,7 @@ enum pmbus_sensor_classes { };#define PMBUS_PAGES 32/* Per PMBus specification */ -#define PMBUS_PHASES 10/* Maximum number of phases per page */ +#define PMBUS_PHASES 16/* Maximum number of phases per page */ /* Functionality bit mask */ #define PMBUS_HAVE_VIN BIT(0)
Greg Kroah-Hartman
maintainerPATCH 308/398 hwmon: (pmbus/tps53679) Fix TPS53676 phase page decoding
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 1d12fb94ac0975566545871dda100df34df5f845 upstream.
tps53676_identify() reads the USER_DATA_03 phase configuration to count the phases assigned to each channel and derive the number of PMBus pages. In each 16-bit phase descriptor the channel (PAGE) is encoded in bit 4 and the firing order in bits 3:0, but the code tested bit 3 (0x08), which is part of the firing-order field.
TPS53676 supports up to seven phases, so firing-order bit 3 is never set. As a result the existing test classifies every enabled phase as channel A. On a dual-channel configuration the phases assigned to channel B are therefore miscounted as channel A and page 1 is not exposed.
Test the PAGE field (bit 4) instead.
--- drivers/hwmon/pmbus/tps53679.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/tps53679.c +1 -1
@@ -187,7 +187,7 @@ static int tps53676_identify(struct i2c_return -EIO ;for (i =0 ; i <2 *TPS53676_MAX_PHASES ; i +=2 ) {if (buf[i +1 ] &0x80 ) { -if (buf[i] &0x08 ) +if (buf[i] &BIT (4 )) phases_b++;else phases_a++;
Greg Kroah-Hartman
maintainerPATCH 309/398 hwmon: (pmbus/tps53679) Select page 0 for single-page TPS53676
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 089070b51ccbac411462a30a454690274c6e4270 upstream.
tps53676_identify() derives the number of PMBus pages but does not ensure that page 0 is selected for single-page configurations. pmbus_set_page() does not update the PAGE register when info->pages is 1, so if boot firmware leaves PAGE set to another value subsequent register accesses may target the wrong page.
For single-page devices, select page 0 explicitly.
--- drivers/hwmon/pmbus/tps53679.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/hwmon/pmbus/tps53679.c +9 -0
@@ -200,6 +200,15 @@ static int tps53676_identify(struct i2c_if (phases_b >0 ) { info->pages =2 ; info->phases[1 ] = phases_b; + }else { +/* +* pmbus_set_page() does not update the PAGE register on +* single-page devices, so select page 0 explicitly in case +* the boot firmware left the device on another page. +*/ + ret =i2c_smbus_write_byte_data (client,PMBUS_PAGE ,0 ); +if (ret <0 ) +return ret; }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 310/398 hwmon: (pwm-fan) Stop RPM timer before freeing tach data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yibo Tan <[email protected]>
commit 26d5ff79768548efb1e604bb6e8697c101e06269 upstream.
sample_timer() rearms the RPM timer and accesses the devm-managed ctx->tachs and ctx->pulses_per_revolution arrays. The cleanup action which stops the timer is registered before those arrays are allocated.
Since devres releases entries in reverse order, driver detach can free the arrays before pwm_fan_cleanup() shuts down the timer. A timer expiry in that window accesses the freed tach data.
With a KASAN kernel, a test-only kprobe delayed entry to pwm_fan_cleanup() while normal sysfs unbind ran. Each of three runs reported three four-byte reads and two four-byte writes in sample_timer() after its backing devm allocations had been freed. The helper did not invoke the timer callback, cleanup actions or free functions.
With the fix, three matching unbind runs completed without KASAN, BUG, WARNING, Oops or panic. Instrumentation confirmed that timer retirement completed before the first timer backing allocation was released.
Split timer retirement from the power cleanup and register its devres action after the timer backing data and IRQ actions are installed. This preserves the early power rollback action while ensuring the timer is retired before its backing data is released. Use timer_shutdown_sync() because the callback can rearm itself.
--- drivers/hwmon/pwm-fan.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/hwmon/pwm-fan.c +12 -1
@@ -484,7 +484,6 @@ static void pwm_fan_cleanup(void *__ctx) {struct pwm_fan_ctx *ctx = __ctx; -timer_delete_sync (&ctx->rpm_timer);if (ctx->pwm_shutdown) { ctx->enable_mode = pwm_enable_reg_enable;__set_pwm (ctx, ctx->pwm_shutdown);
@@ -495,6 +494,13 @@ static void pwm_fan_cleanup(void *__ctx) } } +static void pwm_fan_timer_cleanup (void *__ctx) +{ +struct pwm_fan_ctx *ctx = __ctx; + +timer_shutdown_sync (&ctx->rpm_timer); +} +static int pwm_fan_probe (struct platform_device *pdev) {struct thermal_cooling_device *cdev;
@@ -649,6 +655,10 @@ static int pwm_fan_probe(struct platform }if (ctx->tach_count >0 ) { + ret =devm_add_action_or_reset (dev, pwm_fan_timer_cleanup, ctx); +if (ret) +return ret; + ctx->sample_start =ktime_get ();mod_timer (&ctx->rpm_timer, jiffies +HZ );
@@ -704,6 +714,7 @@ static void pwm_fan_shutdown(struct plat {struct pwm_fan_ctx *ctx =platform_get_drvdata (pdev); +pwm_fan_timer_cleanup (ctx);pwm_fan_cleanup (ctx); }
Greg Kroah-Hartman
maintainerPATCH 311/398 hwmon: (w83791d) remove fan/pwm 4-5 sysfs group on remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 0ff9c7775e51ac6d47b1bb5c46f06b1434fe58a8 upstream.
When the fan/pwm 4-5 pins are not used as GPIO, w83791d_probe() creates the w83791d_group_fanpwm45 sysfs group on the I2C client device.
The probe error path removes this group when a later initialization step fails, but the normal remove path only removes w83791d_group. As a result, the optional fan/pwm 4-5 sysfs files can remain after the driver is unbound.
The callbacks associated with these files access the driver data, which is devm allocated and released after driver unbind. Leaving the sysfs files behind can therefore result in accesses to stale driver data.
Remove w83791d_group_fanpwm45 during normal teardown as well.
This issue was found by manual code inspection.
--- drivers/hwmon/w83791d.c | 1 + 1 file changed, 1 insertion(+)
drivers/hwmon/w83791d.c +1 -0
@@ -1415,6 +1415,7 @@ static void w83791d_remove(struct i2c_clstruct w83791d_data *data =i2c_get_clientdata (client);hwmon_device_unregister (data->hwmon_dev); +sysfs_remove_group (&client->dev.kobj, &w83791d_group_fanpwm45);sysfs_remove_group (&client->dev.kobj, &w83791d_group); }
Greg Kroah-Hartman
maintainerPATCH 312/398 hwmon: (w83793) release probe data through kref
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit c702a5f18b780e477eccbbab558e590e9673e4cb upstream.
w83793_probe() initializes data->kref to manage the lifetime of the driver data. The normal remove path drops the driver-owned reference with kref_put(), while watchdog users take and release additional references through the same kref.
However, the probe error path still frees data directly with kfree(). This bypasses the kref-managed lifetime and discards the initial reference without a matching kref_put(), leaving the reference accounting unbalanced.
Drop the probe-owned reference with kref_put() instead and let w83793_release_resources() perform the final free, matching the normal remove path.
This issue was found by manual code inspection.
--- drivers/hwmon/w83793.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/w83793.c +3 -1
@@ -1928,7 +1928,9 @@ exit_remove:for (i =0 ; i <ARRAY_SIZE (w83793_temp); i++)device_remove_file (dev, &w83793_temp[i].dev_attr); free_mem: -kfree (data); +mutex_lock (&watchdog_data_mutex); +kref_put (&data->kref, w83793_release_resources); +mutex_unlock (&watchdog_data_mutex); exit:return err; }
Greg Kroah-Hartman
maintainerPATCH 313/398 hwmon: (cgbc-hwmon) Fix current sensors ID lookup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Richard (congatec GmbH) <[email protected]>
commit 7bae83ffb133bc373d098fa6828cef2ef4da49fe upstream.
Current sensors on the Congatec Board Controller don't use consecutive IDs, unlike other sensor types (voltage, temperature, fan). The driver assumed consecutive IDs and performed a simple lookup, which caused an unknown sensor warning. Define current sensor IDs explicitly.
Changes the warning on conga-SA7 (type and channel are correct now). Before:
Board Controller returned an unknown sensor (type=2, channel=17), ignore it
After:
Board Controller returned an unknown sensor (bc_type=1, bc_id=11), ignore it
--- drivers/hwmon/cgbc-hwmon.c | 93 ++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 39 deletions(-)
drivers/hwmon/cgbc-hwmon.c +54 -39
@@ -52,31 +52,36 @@ static const char * const cgbc_hwmon_lab "BOTTOMDIM Temperature", }; +static const char *const cgbc_hwmon_labels_in[] = { +"CPU Voltage" , +"DC Runtime Voltage" , +"DC Standby Voltage" , +"CMOS Battery Voltage" , +"Battery Voltage" , +"AC Voltage" , +"Other Voltage" , +"5V Voltage" , +"5V Standby Voltage" , +"3V3 Voltage" , +"3V3 Standby Voltage" , +"VCore A Voltage" , +"VCore B Voltage" , +"12V Voltage" , +}; + +/* +* Current sensors are a bit special, they don't have consecutive IDs like +* other types of sensors. So they need to be defined explicitly. +*/ static const struct { -enum hwmon_sensor_types type;const char *label; -} cgbc_hwmon_labels_in[] = { - { hwmon_in,"CPU Voltage" }, - { hwmon_in,"DC Runtime Voltage" }, - { hwmon_in,"DC Standby Voltage" }, - { hwmon_in,"CMOS Battery Voltage" }, - { hwmon_in,"Battery Voltage" }, - { hwmon_in,"AC Voltage" }, - { hwmon_in,"Other Voltage" }, - { hwmon_in,"5V Voltage" }, - { hwmon_in,"5V Standby Voltage" }, - { hwmon_in,"3V3 Voltage" }, - { hwmon_in,"3V3 Standby Voltage" }, - { hwmon_in,"VCore A Voltage" }, - { hwmon_in,"VCore B Voltage" }, - { hwmon_in,"12V Voltage" }, - { hwmon_curr,"DC Current" }, - { hwmon_curr,"5V Current" }, - { hwmon_curr,"12V Current" }, +int id; +} cgbc_hwmon_labels_curr[] = { + {"DC Current" ,0x12 }, + {"5V Current" ,0x18 }, + {"12V Current" ,0x1E }, }; -#define CGBC_HWMON_NB_IN_SENSORS 14 -static const char *const cgbc_hwmon_labels_fan[] = {"CPU Fan" ,"Box Fan" ,
@@ -114,7 +119,8 @@ static int cgbc_hwmon_probe_sensors(strufor (i =0 ; i < nb_sensors; i++) {enum cgbc_sensor_types type; -unsigned int channel; +unsigned int channel, id; +int j;/* * No need to request data for the first sensor.
@@ -128,32 +134,49 @@ static int cgbc_hwmon_probe_sensors(stru } type =FIELD_GET (CGBC_HWMON_TYPE_MASK , data[1 ]); - channel =FIELD_GET (CGBC_HWMON_ID_MASK , data[1 ]) -1 ; + id =FIELD_GET (CGBC_HWMON_ID_MASK , data[1 ]); + channel = id -1 ;if (type ==CGBC_HWMON_TYPE_TEMP && channel <ARRAY_SIZE (cgbc_hwmon_labels_temp)) { sensor->type = hwmon_temp; sensor->label = cgbc_hwmon_labels_temp[channel]; - }else if (type ==CGBC_HWMON_TYPE_IN && - channel <ARRAY_SIZE (cgbc_hwmon_labels_in)) { + }else if (type ==CGBC_HWMON_TYPE_IN ) {/* * The Board Controller doesn't differentiate current and voltage sensors. -* Get the sensor type from cgbc_hwmon_labels_in[channel].type instead. +* First check if it is a current sensor. */ - sensor->type = cgbc_hwmon_labels_in[channel].type; - sensor->label = cgbc_hwmon_labels_in[channel].label; +for (j =0 ; j <ARRAY_SIZE (cgbc_hwmon_labels_curr); j++) { +if (id == cgbc_hwmon_labels_curr[j].id) { + sensor->type = hwmon_curr; + sensor->label = cgbc_hwmon_labels_curr[j].label; + channel = j; + } + } + +/* If it's not a current sensor, it may be a voltage sensor. */ +if (!sensor->label && channel <ARRAY_SIZE (cgbc_hwmon_labels_in)) { + sensor->type = hwmon_in; + sensor->label = cgbc_hwmon_labels_in[channel]; + } }else if (type ==CGBC_HWMON_TYPE_FAN && channel <ARRAY_SIZE (cgbc_hwmon_labels_fan)) { sensor->type = hwmon_fan; sensor->label = cgbc_hwmon_labels_fan[channel]; - }else { -dev_warn (dev,"Board Controller returned an unknown sensor (type=%d, channel=%d), ignore it" , - type, channel); + } + +if (!sensor->label) { +dev_warn (dev,"Board Controller returned an unknown sensor (bc_type=%d, bc_id=%d), ignore it" , + type, id);continue ; } sensor->active =FIELD_GET (CGBC_HWMON_ACTIVE_BIT , data[1 ]); sensor->channel = channel; sensor->index = i; + +dev_dbg (dev,"Found sensor: bc_type=%d, bc_id=%d, hwmon_type=%d, hwmon_channel=%d, hwmon_label='%s', active=%d\n" , + type, id, sensor->type, sensor->channel, sensor->label, sensor->active); + sensor++; hwmon->nb_sensors++; }
@@ -167,14 +190,6 @@ static struct cgbc_hwmon_sensor *cgbc_hwstruct cgbc_hwmon_sensor *sensor =NULL ;int i; -/* -* The Board Controller doesn't differentiate current and voltage sensors. -* The channel value (from the Board Controller point of view) shall be computed for current -* sensors. -*/ -if (type == hwmon_curr) - channel +=CGBC_HWMON_NB_IN_SENSORS ; -for (i =0 ; i < hwmon->nb_sensors; i++) {if (hwmon->sensors[i].type == type && hwmon->sensors[i].channel == channel) { sensor = &hwmon->sensors[i];
Greg Kroah-Hartman
maintainerPATCH 314/398 hwmon: (cgbc-hwmon) Add missing sensors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Richard (congatec GmbH) <[email protected]>
commit 3550d1dbbcb9f51b77e077e8958423ee2c401c6c upstream.
Add the following sensors:
- Alternate Board Temperature (temp11_input)
- Top DIMM 1-7 Temperature (temp12_input to temp18_input)
- Bottom DIMM 1 Temperature (temp19_input)
- 12V Standby Voltage (in14_input)
This fixes the following warning on conga-SA7:
Board Controller returned an unknown sensor (bc_type=1, bc_id=11), ignore it
Also update existing labels to match Congatec documentation.
--- Documentation/hwmon/cgbc-hwmon.rst | 42 ++++++++++++++++++----------- drivers/hwmon/cgbc-hwmon.c | 52 ++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 34 deletions(-)
Documentation/hwmon/cgbc-hwmon.rst +26 -16
@@ -28,34 +28,44 @@ system. Name Description ============= ====================== temp1_input CPU temperature -temp2_input Box temperature +temp2_input Case temperature temp3_input Ambient temperature -temp4_input Board temperature -temp5_input Carrier temperature -temp6_input Chipset temperature -temp7_input Video temperature +temp4_input CPU Board temperature +temp5_input Carrier Board temperature +temp6_input System Chipset temperature +temp7_input Video Controller/Board temperature temp8_input Other temperature -temp9_input TOPDIM temperature -temp10_input BOTTOMDIM temperature -in0_input CPU voltage +temp9_input Top DIMM 0 temperature +temp10_input Bottom DIMM 0 temperature +temp11_input Alternate Board temperature +temp12_input Top DIMM 1 temperature +temp13_input Top DIMM 2 temperature +temp14_input Top DIMM 3 temperature +temp15_input Top DIMM 4 temperature +temp16_input Top DIMM 5 temperature +temp17_input Top DIMM 6 temperature +temp18_input Top DIMM 7 temperature +temp19_input Bottom DIMM 1 temperature +in0_input CPU Core voltage in1_input DC Runtime voltage in2_input DC Standby voltage in3_input CMOS Battery voltage -in4_input Battery voltage +in4_input Battery Supply voltage in5_input AC voltage in6_input Other voltage -in7_input 5V voltage +in7_input 5V Runtime voltage in8_input 5V Standby voltage -in9_input 3V3 voltage +in9_input 3V3 Runtime voltage in10_input 3V3 Standby voltage in11_input VCore A voltage in12_input VCore B voltage -in13_input 12V voltage -curr1_input DC current -curr2_input 5V current -curr3_input 12V current +in13_input 12V Runtime voltage +in14_input 12V Standby voltage +curr1_input DC Runtime current +curr2_input 5V Runtime current +curr3_input 12V Runtime current fan1_input CPU fan -fan2_input Box fan +fan2_input Case fan fan3_input Ambient fan fan4_input Chiptset fan fan5_input Video fan
drivers/hwmon/cgbc-hwmon.c +34 -18
94 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 315/398 watchdog: da9063: fix suspend/resume handling of HW_RUNNING watchdog
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Jun <[email protected]>
commit 7cb575b71ab98194d2e040bded3a7281e089c5ed upstream.
da9063_wdt_suspend() and da9063_wdt_resume() only check watchdog_active(), when the watchdog is left running by the driver sets WDOG_HW_RUNNING in da9063_wdt_probe() but userspace never opens the device, so WDOG_ACTIVE remains cleared, the wdt_disable() will not be executed in da9063_wdt_suspend. In this case, the suspend callback is a no-op and the watchdog keeps counting during system suspend, leading to an unexpected system reset.
Check WDOG_HW_RUNNING and wdd,can fix this issue.
--- drivers/watchdog/da9063_wdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/da9063_wdt.c +2 -2
@@ -271,7 +271,7 @@ static int da9063_wdt_suspend(struct devif (!da9063->use_sw_pm)return 0 ; -if (watchdog_active (wdd)) +if (watchdog_active (wdd) ||watchdog_hw_running (wdd))return da9063_wdt_stop (wdd);return 0 ;
@@ -285,7 +285,7 @@ static int da9063_wdt_resume(struct deviif (!da9063->use_sw_pm)return 0 ; -if (watchdog_active (wdd)) +if (watchdog_active (wdd) ||watchdog_hw_running (wdd))return da9063_wdt_start (wdd);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 316/398 watchdog: digicolor: Avoid division by zero
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 400cb663ca019bae6eb878f06f1094ddf7c0b0df upstream.
clk_get_rate() could return 0. Avoid a division by zero panic.
Since get_timeleft() cannot propagate errors, check the clock rate early in probe() and cache the rate in the driver data as it is unlikely to change at runtime.
--- drivers/watchdog/digicolor_wdt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/watchdog/digicolor_wdt.c +9 -4
@@ -25,6 +25,7 @@ struct dc_wdt {void __iomem *base;struct clk *clk;spinlock_t lock; +unsigned long rate; };static unsigned timeout;
@@ -61,7 +62,7 @@ static int dc_wdt_start(struct watchdog_ {struct dc_wdt *wdt =watchdog_get_drvdata (wdog); -dc_wdt_set (wdt, wdog->timeout *clk_get_rate (wdt->clk)); +dc_wdt_set (wdt, wdog->timeout * wdt->rate);return 0 ; }
@@ -79,7 +80,7 @@ static int dc_wdt_set_timeout(struct wat {struct dc_wdt *wdt =watchdog_get_drvdata (wdog); -dc_wdt_set (wdt, t *clk_get_rate (wdt->clk)); +dc_wdt_set (wdt, t * wdt->rate); wdog->timeout = t;return 0 ;
@@ -90,7 +91,7 @@ static unsigned int dc_wdt_get_timeleft(struct dc_wdt *wdt =watchdog_get_drvdata (wdog);uint32_t count =readl_relaxed (wdt->base +TIMER_A_COUNT ); -return count /clk_get_rate (wdt->clk); +return count / wdt->rate; }static const struct watchdog_ops dc_wdt_ops = {
@@ -130,7 +131,11 @@ static int dc_wdt_probe(struct platform_ wdt->clk =devm_clk_get (dev,NULL );if (IS_ERR (wdt->clk))return PTR_ERR (wdt->clk); - dc_wdt_wdd.max_timeout =U32_MAX /clk_get_rate (wdt->clk); + + wdt->rate =clk_get_rate (wdt->clk); +if (!wdt->rate) +return -EINVAL ; + dc_wdt_wdd.max_timeout =U32_MAX / wdt->rate; dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout; dc_wdt_wdd.parent = dev;
Greg Kroah-Hartman
maintainerPATCH 317/398 watchdog: msc313e: Fix premature reset during timeout update
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 22737cfced627ffcb4b5c36d63bb3d4476f63213 upstream.
Updating the 32-bit hardware timeout requires writing to two 16-bit registers sequentially. If the watchdog is actively running, this non-atomic update might trigger a premature system reset.
Clear the watchdog counter before updating the registers to prevent the timer from timing out prematurely against an intermediate threshold.
--- drivers/watchdog/msc313e_wdt.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/watchdog/msc313e_wdt.c +6 -0
@@ -47,6 +47,9 @@ static void msc313e_wdt_set_hw_timeout(s {u32 t = timeout *clk_get_rate (priv->clk); +/* Clear before to prevent premature reset during non-atomic updates. */ +writew (1 , priv->base +REG_WDT_CLR ); +writew (t &0xffff , priv->base +REG_WDT_MAX_PRD_L );writew ((t >>16 ) &0xffff , priv->base +REG_WDT_MAX_PRD_H );writew (1 , priv->base +REG_WDT_CLR );
@@ -77,6 +80,9 @@ static int msc313e_wdt_stop(struct watch {struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); +/* Clear before to prevent premature reset during non-atomic updates. */ +writew (1 , priv->base +REG_WDT_CLR ); +writew (0 , priv->base +REG_WDT_MAX_PRD_L );writew (0 , priv->base +REG_WDT_MAX_PRD_H );writew (0 , priv->base +REG_WDT_CLR );
Greg Kroah-Hartman
maintainerPATCH 318/398 watchdog: msc313e: Propagate error code in resume()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 1d9763f34a85680db1e8233d654fdb85e5f897cc upstream.
If msc313e_wdt_start() fails during system resume, the error is currently ignored. Consequently, the watchdog isn't running without the user's knowledge.
Propagate the error code and print a message if msc313e_wdt_start() fails.
--- drivers/watchdog/msc313e_wdt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/watchdog/msc313e_wdt.c +7 -3
@@ -198,11 +198,15 @@ static int __maybe_unused msc313e_wdt_sustatic int __maybe_unused msc313e_wdt_resume (struct device *dev) {struct msc313e_wdt_priv *priv =dev_get_drvdata (dev); +int ret =0 ; -if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev)) -msc313e_wdt_start (&priv->wdev); +if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev)) { + ret =msc313e_wdt_start (&priv->wdev); +if (ret) +dev_err (dev,"Failed to restart watchdog (err=%d)\n" , ret); + } -return 0 ; +return ret; } static SIMPLE_DEV_PM_OPS(msc313e_wdt_pm_ops, msc313e_wdt_suspend, msc313e_wdt_resume);
Greg Kroah-Hartman
maintainerPATCH 319/398 watchdog: rtd119x: Avoid division by zero
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 5af7d2cbd20f893def03c8310a460ade66a5d822 upstream.
clk_get_rate() could return 0. Avoid a division by zero panic.
--- drivers/watchdog/rtd119x_wdt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/rtd119x_wdt.c +6 -1
@@ -98,6 +98,7 @@ static int rtd119x_wdt_probe(struct plat {struct device *dev = &pdev->dev;struct rtd119x_watchdog_device *data; +unsigned long rate; data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL );if (!data)
@@ -111,10 +112,14 @@ static int rtd119x_wdt_probe(struct platif (IS_ERR (data->clk))return PTR_ERR (data->clk); + rate =clk_get_rate (data->clk); +if (!rate) +return -EINVAL ; + data->wdt_dev.info = &rtd119x_wdt_info; data->wdt_dev.ops = &rtd119x_wdt_ops; data->wdt_dev.timeout =120 ; - data->wdt_dev.max_timeout =0xffffffff /clk_get_rate (data->clk); + data->wdt_dev.max_timeout =0xffffffff / rate; data->wdt_dev.min_timeout =1 ; data->wdt_dev.parent = dev;
Greg Kroah-Hartman
maintainerPATCH 320/398 watchdog: rzv2h: Avoid division by zero
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 6274281c41efa8dd1aa5234c59ad904ff89d7af4 upstream.
clk_get_rate() could return 0. Avoid a division by zero panic.
--- drivers/watchdog/rzv2h_wdt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/rzv2h_wdt.c +6 -1
@@ -280,6 +280,7 @@ static int rzv2h_wdt_probe(struct platfostruct device *dev = &pdev->dev;struct rzv2h_wdt_priv *priv;struct clk *count_clk; +unsigned long rate;int ret; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
@@ -316,8 +317,12 @@ static int rzv2h_wdt_probe(struct platforeturn dev_err_probe (dev, -EINVAL ,"Invalid count source\n" ); } + rate =clk_get_rate (count_clk); +if (!rate) +return dev_err_probe (dev, -EINVAL ,"Invalid clock rate\n" ); + priv->wdev.max_hw_heartbeat_ms = (MILLI * priv->of_data->timeout_cycles * - priv->of_data->cks_div) /clk_get_rate (count_clk); + priv->of_data->cks_div) / rate;dev_dbg (dev,"max hw timeout of %dms\n" , priv->wdev.max_hw_heartbeat_ms); ret =devm_pm_runtime_enable (dev);
Greg Kroah-Hartman
maintainerPATCH 321/398 watchdog: sp5100_tco: Fix pci_dev reference leak in sp5100_tco_init()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 88f113634028ca90a857031837d8061d1a9e1a7b upstream.
sp5100_tco_init() stores the PCI device matched by for_each_pci_dev() in the global sp5100_tco_pci and keeps its reference for the lifetime of the driver, but neither sp5100_tco_exit() nor the error paths of sp5100_tco_init() call pci_dev_put(), leaking the reference on driver registration failure and on every module load/unload cycle.
Drop the reference when the platform driver or device registration fails and when the module is unloaded.
--- drivers/watchdog/sp5100_tco.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/watchdog/sp5100_tco.c +5 -1
@@ -605,8 +605,10 @@ static int __init sp5100_tco_init(void)pr_info ("SP5100/SB800 TCO WatchDog Timer Driver\n" ); err =platform_driver_register (&sp5100_tco_driver); -if (err) +if (err) { +pci_dev_put (sp5100_tco_pci);return err; + } sp5100_tco_platform_device =platform_device_register_simple (TCO_DRIVER_NAME ,-1 ,NULL ,0 );
@@ -619,6 +621,7 @@ static int __init sp5100_tco_init(void) unreg_platform_driver:platform_driver_unregister (&sp5100_tco_driver); +pci_dev_put (sp5100_tco_pci);return err; }
@@ -626,6 +629,7 @@ static void __exit sp5100_tco_exit(void) {platform_device_unregister (sp5100_tco_platform_device);platform_driver_unregister (&sp5100_tco_driver); +pci_dev_put (sp5100_tco_pci); }module_init (sp5100_tco_init);
Greg Kroah-Hartman
maintainerPATCH 322/398 watchdog: starfive-wdt: Fix runtime PM leak in starfive_wdt_pm_start()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 8f0ca55016a7647109ae2bc91bcb346fc8b13785 upstream.
starfive_wdt_pm_start() takes a runtime PM reference with pm_runtime_get_sync(), which increments the usage counter even when it fails, and returns the error without dropping it again. The watchdog core does not invoke the stop callback when start fails, so the reference taken on the error path is leaked.
Use pm_runtime_resume_and_get() instead, which keeps the usage counter balanced when the resume fails.
--- drivers/watchdog/starfive-wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/starfive-wdt.c +1 -1
@@ -371,7 +371,7 @@ static void starfive_wdt_stop(struct stastatic int starfive_wdt_pm_start (struct watchdog_device *wdd) {struct starfive_wdt *wdt =watchdog_get_drvdata (wdd); -int ret =pm_runtime_get_sync (wdd->parent); +int ret =pm_runtime_resume_and_get (wdd->parent);if (ret <0 )return ret;
Greg Kroah-Hartman
maintainerPATCH 323/398 wifi: brcmsmac: fix UAF in brcms_free_timer()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
commit 1eeca1d5e0920fbdad6449768fd2d4364e714180 upstream.
brcms_free_timer() calls brcms_del_timer() which uses the non-synchronous cancel_delayed_work() to cancel the timer's underlying delayed work. If the work callback (_brcms_timer) is already running, cancel_delayed_work() returns false without waiting, and brcms_free_timer() proceeds to kfree(t) while the callback still accesses t through container_of().
Add an explicit cancel_delayed_work_sync() after brcms_del_timer() to guarantee that any in-flight callback has completed before the timer structure is freed.
--- drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c +4 -0
@@ -1571,6 +1571,10 @@ void brcms_free_timer(struct brcms_timer/* delete the timer in case it is active */ brcms_del_timer (t); +/* Ensure the callback has finished before freeing the timer +* structure, since brcms_del_timer() uses non-synchronous cancel. +*/ +cancel_delayed_work_sync (&t->dly_wrk);if (wl->timers == t) { wl->timers = wl->timers->next;
Greg Kroah-Hartman
maintainerPATCH 324/398 wifi: iwlegacy: fix broadcast stations deallocation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislaw Gruszka <[email protected]>
commit b5526b780f8b297a76030410b96ba29153afb98f upstream.
On the error path of __il4965_up(), il_dealloc_bcast_stations() clears only IL_STA_UCODE_ACTIVE, leaving IL_STA_BCAST set. This causes the same broadcast stations to be deallocated again by __il4965_down().
This can occur when RF_KILL is toggled during driver startup.
To fix clear the entire 'used' field, since we will not do any other operations on the station.
--- drivers/net/wireless/intel/iwlegacy/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intel/iwlegacy/common.c +1 -1
@@ -2327,7 +2327,7 @@ il_dealloc_bcast_stations(struct il_privif (!(il->stations[i].used &IL_STA_BCAST ))continue ; - il->stations[i].used &= ~IL_STA_UCODE_ACTIVE ; + il->stations[i].used =0 ; il->num_stations--;BUG_ON (il->num_stations <0 );kfree (il->stations[i].lq);
Greg Kroah-Hartman
maintainerPATCH 325/398 wifi: libertas_tf: fix UAF in lbtf_free_adapter()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
commit bbb9a0ab96d44a64529aafc7a16de460a1712f6a upstream.
lbtf_free_adapter() calls lbtf_free_cmd_buffer() to free the command buffers before calling timer_delete_sync() to wait for the command timer callback. If the timer callback (command_timer_fn) is already running when lbtf_free_cmd_buffer() frees the command array, the callback dereferences priv->cur_cmd->cmdbuf which points to freed memory.
Swap the order so that timer_delete_sync() runs first, ensuring any in-flight callback has completed before the command buffers are freed.
--- drivers/net/wireless/marvell/libertas_tf/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/libertas_tf/main.c +1 -1
@@ -173,8 +173,8 @@ static int lbtf_init_adapter(struct lbtfstatic void lbtf_free_adapter (struct lbtf_private *priv) {lbtf_deb_enter (LBTF_DEB_MAIN ); -lbtf_free_cmd_buffer (priv);timer_delete_sync (&priv->command_timer); +lbtf_free_cmd_buffer (priv);lbtf_deb_leave (LBTF_DEB_MAIN ); }
Greg Kroah-Hartman
maintainerPATCH 326/398 wifi: rsi: fix heap OOB write on key removal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit e6c5ed7a98d7bc8b0f7918246f1c90ddb3f79dfa upstream.
When a key is removed (data == NULL), rsi_hal_load_key() runs:
memset(&set_key[FRAME_DESC_SZ], 0, frame_len - FRAME_DESC_SZ);
set_key is a struct rsi_set_key *, so the subscript is scaled by sizeof(struct rsi_set_key) (160 bytes): &set_key[FRAME_DESC_SZ] is skb->data + 2560, and the memset writes 144 zero bytes starting 2.4KB past the end of the 160-byte skb data buffer, corrupting unrelated heap objects. The intended byte offset would have been (u8 *)set_key + FRAME_DESC_SZ.
The write fires on every DISABLE_KEY callback, so plain disconnects, roams and interface teardowns trigger it on real networks.
The memset is redundant: the whole buffer is zeroed right after allocation, so the frame sent to the device is byte-identical without it. Drop the else branch; normal operation is unaffected.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/net/wireless/rsi/rsi_91x_mgmt.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/wireless/rsi/rsi_91x_mgmt.c +0 -2
@@ -852,8 +852,6 @@ int rsi_hal_load_key(struct rsi_common *memcpy (set_key->tx_mic_key, &data[16 ],8 );memcpy (set_key->rx_mic_key, &data[24 ],8 ); } - }else { -memset (&set_key[FRAME_DESC_SZ ],0 , frame_len -FRAME_DESC_SZ ); }skb_put (skb, frame_len);
Greg Kroah-Hartman
maintainerPATCH 327/398 wifi: wcn36xx: Fix potential use-after-free in TX ack timer teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit d9be5e75530772fc31637070d51e5717d6aeaa2a upstream.
wcn36xx_dxe_deinit() tears down the TX ack timer with timer_delete(), which only dequeues the timer and does not wait for a callback that is already executing; the preceding free_irq() calls synchronize the interrupt handlers only. The callback, wcn36xx_dxe_tx_timer(), can therefore be running past the teardown and use the wcn freed along with the ieee80211_hw in wcn36xx_remove(): it takes wcn->dxe_lock, reads wcn->tx_ack_skb and passes wcn->hw to ieee80211_tx_status_irqsafe().
Fix this by using timer_shutdown_sync(), which waits for a running callback and also prevents the timer from being rearmed again. The timer is set up again by wcn36xx_dxe_init() on the next start, so the start/stop cycle is unaffected.
This issue was found by an in-house static analysis tool.
--- drivers/net/wireless/ath/wcn36xx/dxe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/wcn36xx/dxe.c +1 -1
@@ -1055,7 +1055,7 @@ void wcn36xx_dxe_deinit(struct wcn36xx *free_irq (wcn->tx_irq, wcn);free_irq (wcn->rx_irq, wcn); -timer_delete (&wcn->tx_ack_timer); +timer_shutdown_sync (&wcn->tx_ack_timer);if (wcn->tx_ack_skb) {ieee80211_tx_status_irqsafe (wcn->hw, wcn->tx_ack_skb);
Greg Kroah-Hartman
maintainerPATCH 328/398 wifi: wlcore: release runtime PM ref on regdomain config failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 8a1f3cf89ddcc700e25afe42cfad333059adcc94 upstream.
wlcore_regdomain_config() gets a runtime PM reference before sending the regulatory-domain command. When wlcore_cmd_regdomain_config_locked() fails, the function queues recovery and returns without dropping that reference.
Release the reference after handling the command result so both success and failure paths balance the preceding pm_runtime_resume_and_get(). The recovery worker takes a separate runtime PM reference and cannot release the reference held here.
--- drivers/net/wireless/ti/wlcore/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/wireless/ti/wlcore/main.c +1 -3
@@ -3719,10 +3719,8 @@ void wlcore_regdomain_config(struct wl12 goto out; ret =wlcore_cmd_regdomain_config_locked (wl); -if (ret <0 ) { +if (ret <0 )wl12xx_queue_recovery_work (wl); - goto out; - }pm_runtime_mark_last_busy (wl->dev);pm_runtime_put_autosuspend (wl->dev);
Greg Kroah-Hartman
maintainerPATCH 329/398 wifi: wilc1000: fix out-of-bounds read in P2P public action frames
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memis <[email protected]>
commit ba6cb7c0868a412c2eb68e8efd5aa38bfb258a14 upstream.
wilc_wfi_p2p_rx() and mgmt_tx() start parsing a frame once ieee80211_is_public_action() returns true. That helper only verifies the frame is long enough for the action category field, that is offsetofend(struct ieee80211_mgmt, u.action.category), 25 bytes. Both functions then read the P2P public action header up to oui_subtype at offset 30 and pass "size - ie_offset" to cfg80211_find_vendor_ie(), where ie_offset is offsetof(struct ieee80211_mgmt, u) + sizeof(*d), i.e. 32.
A public action frame of 25 to 31 bytes passes the check but is shorter than that 32 byte header, so oui_subtype can be read out of bounds, and because the length is unsigned, "size - ie_offset" underflows to a value close to 4 GiB. cfg80211_find_vendor_ie() takes an unsigned int length, so even the size_t subtraction in mgmt_tx() is truncated to the same value. It then walks far past the buffer searching for a vendor element until it reaches unmapped memory.
In the receive path the frame arrives over the air and needs no association, so a nearby unauthenticated device can crash the host while it is in P2P listen. Reject frames shorter than the P2P public action header in both paths before dereferencing it.
--- drivers/net/wireless/microchip/wilc1000/cfg80211.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +14 -0
@@ -1060,6 +1060,13 @@ void wilc_wfi_p2p_rx(struct wilc_vif *viif (!ieee80211_is_public_action ((struct ieee80211_hdr *)buff, size)) goto out_rx_mgmt; +/* ieee80211_is_public_action() only validates up to the category +* byte, so reject frames too short for the P2P public action header +* before dereferencing it or computing size - ie_offset. +*/ +if (size < ie_offset) + goto out_rx_mgmt; + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);if (d->oui_subtype !=GO_NEG_REQ && d->oui_subtype !=GO_NEG_RSP && d->oui_subtype !=P2P_INV_REQ && d->oui_subtype !=P2P_INV_RSP )
@@ -1208,6 +1215,13 @@ static int mgmt_tx(struct wiphy *wiphy, goto out_set_timeout; } +/* ieee80211_is_public_action() only validates up to the category +* byte, so reject frames too short for the P2P public action header +* before dereferencing it or computing len - ie_offset. +*/ +if (len < ie_offset) + goto out_set_timeout; + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);if (d->oui_type !=WLAN_OUI_TYPE_WFA_P2P || d->oui_subtype !=GO_NEG_CONF ) {
Greg Kroah-Hartman
maintainerPATCH 330/398 wifi: wilc1000: fix RX buffer OOB-write in wilc_wlan_handle_isr_ext()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit c1ba7f7f18465e259cf1b4d9c73fc73853d7f790 upstream.
wilc_wlan_handle_isr_ext() takes the RX transfer size from the device-reported interrupt status register (a 15-bit field shifted left by 2, up to 131068 bytes) and reads that many bytes from the device into rx_buffer, which is only WILC_RX_BUFF_SIZE (96K) large. The wrap check only handles the current offset; the size itself is never compared against the buffer, so a bogus SDIO device can make the driver OOB-write rx_buffer by up to ~32K with data it controls.
The oversized transfer also leaves rx_buffer_offset past the end of the buffer, after which the unsigned wrap check stops working and the overflow can repeat.
Drop any transfer whose size exceeds the RX buffer, acknowledging the data interrupt and re-arming the RX engine so the bogus frame is discarded and reception can continue. This also restores the rx_buffer_offset <= WILC_RX_BUFF_SIZE invariant the wrap check relies on.
This is not expected to change driver behavior in most cases:
without this check, an oversized transfer would most likely corrupt neighboring kernel memory instead of completing anyway, and the drop path performs the same interrupt acknowledgment and RX engine re-arming as the normal path, so subsequent transfers are received unaffected.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/net/wireless/microchip/wilc1000/wlan.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/wireless/microchip/wilc1000/wlan.c +9 -0
@@ -1197,6 +1197,15 @@ static void wilc_wlan_handle_isr_ext(strif (size <=0 )return ; +/* A size exceeding the RX buffer is bogus; drop the transfer +* instead of overflowing the buffer. +*/ +if (size >WILC_RX_BUFF_SIZE ) { + wilc->hif_func->hif_clear_int_ext (wilc, +DATA_INT_CLR |ENABLE_RX_VMM ); +return ; + } +if (WILC_RX_BUFF_SIZE - offset < size) offset =0 ;
Greg Kroah-Hartman
maintainerPATCH 331/398 wifi: p54: validate curve data length in the calibration curve converters
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit ce858fa6b8a214dee5adb82358885fa024cdd887 upstream.
p54_convert_rev0() and p54_convert_rev1() read calibration curve data from the device-supplied EEPROM entry using channel and points-per-channel counts taken verbatim from that same entry, so an entry that declares more data than it carries drives an out-of-bounds read past the EEPROM buffer (verified with a KASAN reproducer of the conversion loop). The sibling converters p54_convert_output_limits() and p54_convert_db() already validate their counts against the entry length; this path was missed.
Reject the entry when the counts do not fit in the entry data.
--- drivers/net/wireless/intersil/p54/eeprom.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/wireless/intersil/p54/eeprom.c +15 -4
@@ -418,17 +418,22 @@ free: }static int p54_convert_rev0 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev0 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +2 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kmalloc (sizeof (*priv->curve_data) + cd_len,GFP_KERNEL );if (!priv->curve_data)
@@ -470,17 +475,22 @@ static int p54_convert_rev0(struct ieee8 }static int p54_convert_rev1 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev1 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +3 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kzalloc (cd_len +sizeof (*priv->curve_data),GFP_KERNEL );if (!priv->curve_data)
@@ -767,6 +777,7 @@ int p54_parse_eeprom(struct ieee80211_hwcase PDR_PRISM_PA_CAL_CURVE_DATA : {struct pda_pa_curve_data *curve_data = (struct pda_pa_curve_data *)entry->data; +if (data_len <sizeof (*curve_data)) { err = -EINVAL ; goto err;
@@ -774,10 +785,10 @@ int p54_parse_eeprom(struct ieee80211_hwswitch (curve_data->cal_method_rev) {case 0 : - err =p54_convert_rev0 (dev, curve_data); + err =p54_convert_rev0 (dev, curve_data, data_len);break ;case 1 : - err =p54_convert_rev1 (dev, curve_data); + err =p54_convert_rev1 (dev, curve_data, data_len);break ;default : wiphy_err(dev->wiphy,
Greg Kroah-Hartman
maintainerPATCH 332/398 wifi: p54: require a full exp_if record in PDR_INTERFACE_LIST
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit d8efd84f49379ed28624098821f80e992657d935 upstream.
The PDR_INTERFACE_LIST loop only checks that the record start is within the entry before reading an entire struct exp_if from it. A truncated trailing record makes the if_id/variant reads cross the entry boundary into the heap beyond the EEPROM buffer (verified with a KASAN reproducer of the loop). The variant also feeds the synth front-end selection, so this is not only a leak.
Advance only while a full record still fits in the entry.
--- drivers/net/wireless/intersil/p54/eeprom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/intersil/p54/eeprom.c +2 -1
@@ -816,7 +816,8 @@ int p54_parse_eeprom(struct ieee80211_hwbreak ;case PDR_INTERFACE_LIST : tmp = entry->data; -while ((u8 *)tmp < entry->data + data_len) { +while ((u8 *)tmp +sizeof (struct exp_if ) <= + entry->data + data_len) {struct exp_if *exp_if = tmp;if (exp_if->if_id ==cpu_to_le16 (IF_ID_ISL39000 )) synth =le16_to_cpu (exp_if->variant);
Greg Kroah-Hartman
maintainerPATCH 333/398 wifi: mwifiex: bound the pairwise-cipher OUI walk to the IE length
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit e667aee1c192d67d27c803007bfa9c6e0873e959 upstream.
mwifiex_search_oui_in_ie() reads a pairwise-cipher (PTK) count from a beacon/probe-response RSN or WPA information element and then walks that many 4-byte OUIs, comparing each with memcmp(). The count comes straight from the (attacker-supplied) IE and is never checked against the element's own length, and the callers admit the element on element_id alone (has_ieee_hdr() / has_vendor_hdr(), no length check). A crafted RSN/WPA IE with a large pairwise count therefore makes the walk read up to 255 * 4 bytes past the element -- an out-of-bounds read of the kmemdup()'d beacon buffer, reachable from any AP whose beacon/probe response is processed during scan-result parsing.
Pass the number of IE bytes available at the OUI list and bound the walk to the element. Keep the length signed and reject a negative value before any unsigned arithmetic, so a small or zero IE length cannot underflow to a large size_t and defeat the bound.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/wireless/marvell/mwifiex/scan.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +22 -3
@@ -104,12 +104,24 @@ has_vendor_hdr(struct ieee_types_vendor_* a given oui in PTK. */ static u8 -mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui) +mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui,int ie_len) { +const size_t ptk_body_offset = offsetof(struct ie_body , ptk_body);u8 count; +/* ie_len is the number of bytes available at iebody. Keep it signed +* and reject a negative (underflowed) length before the unsigned +* comparisons below, so a small or zero IE length cannot wrap. +*/ +if (ie_len <0 || (size_t )ie_len < ptk_body_offset) +return MWIFIEX_OUI_NOT_PRESENT ; + count = iebody->ptk_cnt[0 ]; +/* Reject an OUI count whose list would run past the element. */ +if (ptk_body_offset + count *sizeof (iebody->ptk_body) > (size_t )ie_len) +return MWIFIEX_OUI_NOT_PRESENT ; +/* There could be multiple OUIs for PTK hence 1) Take the length. 2) Check all the OUIs for AES.
@@ -143,11 +155,14 @@ mwifiex_is_rsn_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_ieee_hdr (bss_desc->bcn_rsn_ie,WLAN_EID_RSN )) { +int ie_len = (int )bss_desc->bcn_rsn_ie->ieee_hdr.len - +RSN_GTK_OUI_OFFSET ; + iebody = (struct ie_body *) (((u8 *) bss_desc->bcn_rsn_ie->data) +RSN_GTK_OUI_OFFSET ); oui = &mwifiex_rsn_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
@@ -169,10 +184,14 @@ mwifiex_is_wpa_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_vendor_hdr (bss_desc->bcn_wpa_ie,WLAN_EID_VENDOR_SPECIFIC )) { +int ie_len = (int )bss_desc->bcn_wpa_ie->vend_hdr.len - + (int )sizeof (bss_desc->bcn_wpa_ie->vend_hdr.oui) - +WPA_GTK_OUI_OFFSET ; + iebody = (struct ie_body *)((u8 *)bss_desc->bcn_wpa_ie->data +WPA_GTK_OUI_OFFSET ); oui = &mwifiex_wpa_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
Greg Kroah-Hartman
maintainerPATCH 334/398 wifi: mwifiex: validate scan response extents
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit 3687d7d48070838cc2953431b3a27717cab0aaf6 upstream.
mwifiex_ret_802_11_scan() subtracts the fixed response fields and the firmware-provided BSS length from resp->size without first proving that either extent fits. A short response or oversized BSS length can therefore underflow tlv_buf_size and make the TLV parser walk beyond the command response.
Compute the fixed extent from the selected normal or background scan response. Validate that the fixed fields and BSS data fit before deriving the TLV extent and entering the parser.
--- drivers/net/wireless/marvell/mwifiex/scan.c | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +19 -10
@@ -2117,6 +2117,7 @@ int mwifiex_ret_802_11_scan(struct mwifiu32 bytes_left;u32 idx;u32 tlv_buf_size; +size_t fixed_size;struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;struct chan_band_param_set *chan_band;u8 is_bgscan_resp;
@@ -2132,6 +2133,14 @@ int mwifiex_ret_802_11_scan(struct mwifielse scan_rsp = &resp->params.scan_resp; + scan_resp_size =le16_to_cpu (resp->size); + fixed_size = scan_rsp->bss_desc_and_tlv_buffer - (u8 *)resp; +if (scan_resp_size < fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: response is too short\n" ); + ret =-1 ; + goto check_next_scan; + }if (scan_rsp->number_of_sets >MWIFIEX_MAX_AP ) { mwifiex_dbg(adapter, ERROR,
@@ -2149,8 +2158,6 @@ int mwifiex_ret_802_11_scan(struct mwifi"info: SCAN_RESP: bss_descript_size %d\n" , bytes_left); - scan_resp_size =le16_to_cpu (resp->size); -mwifiex_dbg (adapter,INFO ,"info: SCAN_RESP: returned %d APs before parsing\n" , scan_rsp->number_of_sets);
@@ -2158,15 +2165,17 @@ int mwifiex_ret_802_11_scan(struct mwifi bss_info = scan_rsp->bss_desc_and_tlv_buffer;/* -* The size of the TLV buffer is equal to the entire command response -* size (scan_resp_size) minus the fixed fields (sizeof()'s), the -* BSS Descriptions (bss_descript_size as bytesLef) and the command -* response header (S_DS_GEN) +* The TLV buffer follows the command-specific fixed fields and the BSS +* descriptions. Background-scan responses have an additional fixed +* field before scan_rsp, which is included in fixed_size. */ - tlv_buf_size = scan_resp_size - (bytes_left - +sizeof (scan_rsp->bss_descript_size) - +sizeof (scan_rsp->number_of_sets) - +S_DS_GEN ); +if (bytes_left > scan_resp_size - fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: BSS data exceeds response\n" ); + ret =-1 ; + goto check_next_scan; + } + tlv_buf_size = scan_resp_size - fixed_size - bytes_left; tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp-> bss_desc_and_tlv_buffer +
Greg Kroah-Hartman
maintainerPATCH 335/398 wifi: mwifiex: prevent authentication frame length truncation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
commit fa00193eb991f92b007aefe7afb6a7566976dacf upstream.
mwifiex_cfg80211_authenticate() derives the authentication frame length from req->ie_len and req->auth_data_len, both of type size_t, but stores it in a u16.
NL80211_ATTR_AUTH_DATA only has a minimum length policy. Since nla_len is a u16, a single attribute can carry up to 65531 bytes of payload, so the sum can exceed U16_MAX before it is assigned to pkt_len. The truncated pkt_len determines the skb frame area, while the copy length remains req->auth_data_len - 4, resulting in a heap buffer overflow.
For example, with auth_data_len equal to 65510 and no IEs, the sum is 65546. It is truncated to 10 and then reduced by four to 6. The driver appends only six bytes to the skb with skb_put(), but then copies 65506 user-provided bytes into the authentication body.
Reaching this path requires CAP_NET_ADMIN in the user namespace owning the network namespace, an up station netdev, and a suitable BSS/SAE authentication request.
Compute the length in size_t, reject values that cannot be represented by the firmware's u16 frame length field, and only then assign it to pkt_len.
--- drivers/net/wireless/marvell/mwifiex/cfg80211.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/cfg80211.c +10 -2
@@ -4271,6 +4271,7 @@ mwifiex_cfg80211_authenticate(struct wipstruct mwifiex_adapter *adapter = priv->adapter;struct sk_buff *skb;u16 pkt_len, auth_alg; +size_t frame_len;int ret;struct mwifiex_ieee80211_mgmt *mgmt;struct mwifiex_txinfo *tx_info;
@@ -4343,10 +4344,17 @@ mwifiex_cfg80211_authenticate(struct wipmwifiex_cancel_scan (adapter); - pkt_len = (u16 )req->ie_len + req->auth_data_len + + frame_len = req->ie_len + req->auth_data_len +MWIFIEX_MGMT_HEADER_LEN +MWIFIEX_AUTH_BODY_LEN ;if (req->auth_data_len >=4 ) - pkt_len -=4 ; + frame_len -=4 ; + +if (frame_len >U16_MAX ) { +mwifiex_dbg (priv->adapter,ERROR , +"auth frame too long: %zu bytes\n" , frame_len); +return -EINVAL ; + } + pkt_len = frame_len; skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN + MWIFIEX_MGMT_FRAME_HEADER_SIZE +
Greg Kroah-Hartman
maintainerPATCH 336/398 wifi: mwifiex: validate action frame fixed fields
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
commit 1c25bfad93e69ce13f744a2fb919f02ea396a985 upstream.
mwifiex_process_mgmt_packet() accepts an rx_pkt_length as small as a four-address struct ieee80211_hdr plus the two-byte firmware length prefix. After stripping the prefix, mwifiex_parse_mgmt_packet() can receive a frame equal to sizeof(struct ieee80211_hdr).
For action frames, the parser reads the category byte immediately after that header and, for a public action frame, reads the following action code byte without verifying that either field is present. A truncated frame can therefore make the parser consume up to two bytes past the firmware-declared frame length. If those bytes look like a TDLS discovery response, the malformed frame can spuriously update peer signal state.
Require the category and public action-code fields before reading them. Use sizeof(*ieee_hdr) so the checks and field accesses directly match the firmware four-address layout being parsed before address4 is removed.
--- drivers/net/wireless/marvell/mwifiex/util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/util.c +8 -2
@@ -317,10 +317,16 @@ mwifiex_parse_mgmt_packet(struct mwifiexswitch (stype) {case IEEE80211_STYPE_ACTION : - category = *(payload +sizeof (struct ieee80211_hdr )); +if (len <sizeof (*ieee_hdr) +1 ) +return -1 ; + + category = *(payload +sizeof (*ieee_hdr));switch (category) {case WLAN_CATEGORY_PUBLIC : - action_code = *(payload +sizeof (struct ieee80211_hdr ) +if (len <sizeof (*ieee_hdr) +2 ) +return -1 ; + + action_code = *(payload +sizeof (*ieee_hdr) +1 );if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) { addr2 = ieee_hdr->addr2;
Greg Kroah-Hartman
maintainerPATCH 337/398 wifi: mac80211: avoid WARN in set_bitrate_mask when sdata not in driver
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rik van Riel <[email protected]>
commit da2ca406f45a6e21760243152ed8d2e8e72915c2 upstream.
ieee80211_set_bitrate_mask() checks if the interface is running via ieee80211_sdata_running(), but it does not check if the interface is still present in the driver.
When sdata is running but IEEE80211_SDATA_IN_DRIVER is not set, the call reaches drv_set_bitrate_mask() in driver-ops.h which hits
wlan1: Failed check-sdata-in-driver check, flags: 0x0
WARNING: net/mac80211/driver-ops.h:884 at drv_set_bitrate_mask
Syzkaller triggers this via wext SIOCSIWRATE ioctl. The Call Trace shows wext_ioctl_dispatch() in wext-core.c dispatching the ioctl, calling ioctl_standard_call() for SIOCSIWRATE, which calls cfg80211_wext_siwrate() in wext-compat.c. That builds a bitrate mask and calls rdev_set_bitrate_mask() which ends up in ieee80211_set_bitrate_mask() in cfg.c. The interface is marked running via SDATA_STATE_RUNNING but flags is 0, so check_sdata_in_driver() fails.
When the interface is being torn down, or when wext ioctl is issued during interface bringup before drv_add_interface() sets IN_DRIVER, the running check passes while IN_DRIVER is clear.
Check IEEE80211_SDATA_IN_DRIVER in ieee80211_set_bitrate_mask() before calling the driver, returning -ENETDOWN. This avoids the WARN_ONCE in driver-ops.h and matches other cfg.c operations that bail early when not in driver.
This change should be safe because wiphy mutex is held in cfg80211_wext_siwrate() via guard(wiphy), and IN_DRIVER is set/cleared under RTNL and wiphy paths in drv_add_interface() and drv_remove_interface() in driver-ops.c, so the check is race-free against driver add/remove. Returning -ENETDOWN is the same error other not-running paths use and does not introduce new locking.
--- net/mac80211/cfg.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/cfg.c +3 -0
@@ -3738,6 +3738,9 @@ static int ieee80211_set_bitrate_mask(stif (!ieee80211_sdata_running (sdata))return -ENETDOWN ; +if (!(sdata->flags &IEEE80211_SDATA_IN_DRIVER )) +return -ENETDOWN ; +/* * If active validate the setting and reject it if it doesn't leave * at least one basic rate usable, since we really have to be able
Greg Kroah-Hartman
maintainerPATCH 338/398 drm/gud: fix out-of-bounds write in gud_plane_atomic_check()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sajal Gupta <[email protected]>
commit 59ced288fcba9e91bd38e61a972ad782c4edb7d0 upstream.
The plane property loop uses req->properties[num_properties + i] as write index while simultaneously incrementing num_properties inside the loop. At iteration i, num_properties has also incremented by i, so the write is done at initial_num_properties + 2*i, skipping every other index and advancing by 2 per iteration.
With just 2 connector and 32 plane properties the last write happens at index 64, one slot past the end of the 64-slot (indices 0–63) allocation. A USB device can trigger OOB by advertising the maximum number of properties.
Fix by dropping the redundant + i; num_properties is already the correct running index, as gud_connector_fill_properties() fills the preceding slots.
--- drivers/gpu/drm/gud/gud_pipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/gud/gud_pipe.c +2 -2
@@ -562,8 +562,8 @@ int gud_plane_atomic_check(struct drm_pl goto out; } - req->properties[num_properties + i].prop =cpu_to_le16 (prop); - req->properties[num_properties + i].val =cpu_to_le64 (val); + req->properties[num_properties].prop =cpu_to_le16 (prop); + req->properties[num_properties].val =cpu_to_le64 (val); num_properties++; }
Greg Kroah-Hartman
maintainerPATCH 339/398 drm/gud: Ignore damage clips in full update mode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sophie D <[email protected]>
commit effce1cb87ee0d8b3a8cbe7722968f4ea7efd360 upstream.
When running in full update mode, previously small updates (such as moving the mouse across the screen) would cause many full frames to be generated. This would bog down the bus and lower the effective framerate significantly - I was seeing a drop from 60 FPS to 2 FPS.
Set ignore_damage_clips in full update mode so the damage iterator yields a single full-plane rectangle instead of one per clip.
--- drivers/gpu/drm/gud/gud_pipe.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/gud/gud_pipe.c +3 -0
@@ -482,6 +482,9 @@ int gud_plane_atomic_check(struct drm_plane *plane,if (!new_plane_state->visible)return 0 ; +if (gdrm->flags &GUD_DISPLAY_FLAG_FULL_UPDATE ) + new_plane_state->ignore_damage_clips = true; +if (old_plane_state->rotation != new_plane_state->rotation) crtc_state->mode_changed = true;
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 340/398 drm/msm/adreno: fix autosuspend cleanup during teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 6fbbf1e152f34ad3913e4a6476680aba672c5068 upstream.
adreno_gpu_init() calls pm_runtime_use_autosuspend(), but adreno_gpu_cleanup() does not call the matching pm_runtime_dont_use_autosuspend() during teardown.
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without calling pm_runtime_dont_use_autosuspend() during teardown, this reference is not dropped and usage_count remains unbalanced.
The documentation for pm_runtime_use_autosuspend() also notes that it is important to undo it with pm_runtime_dont_use_autosuspend() at driver exit time, unless runtime PM was initially enabled with devm_pm_runtime_enable().
Add the missing pm_runtime_dont_use_autosuspend() call to adreno_gpu_cleanup().
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/745110/
--- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -0
@@ -1245,6 +1245,8 @@ void adreno_gpu_cleanup(struct adreno_gpfor (i =0 ; i <ARRAY_SIZE (adreno_gpu->info->fw); i++)release_firmware (adreno_gpu->fw[i]); +pm_runtime_dont_use_autosuspend (&gpu->pdev->dev); +if (priv &&pm_runtime_enabled (&priv->gpu_pdev->dev))pm_runtime_disable (&priv->gpu_pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 341/398 drm/msm/dpu: clear pending peripheral flush state
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Saim Shujah <[email protected]>
commit a5b5cc909931572aec446e129c035b76b3f0c1fa upstream.
dpu_hw_ctl_clear_pending_flush() resets the cached per-block state after a flush transaction, but misses pending_periph_flush_mask.
The peripheral flush updater accumulates interface bits in this mask. A later transaction which sets the top-level peripheral flush bit can write stale interface bits to CTL_PERIPH_FLUSH together with the current state.
Peripheral flush support was added after the helper started clearing every individual pending flush mask. Clear the peripheral mask together with the other cached child masks.
Patchwork: https://patchwork.freedesktop.org/patch/748968/
--- drivers/gpu/drm/msm/disp/dpu1/dpu_hw_ctl.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_ctl.c +1 -0
@@ -118,6 +118,7 @@ static inline void dpu_hw_ctl_clear_pend ctx->pending_intf_flush_mask =0 ; ctx->pending_wb_flush_mask =0 ; ctx->pending_cwb_flush_mask =0 ; + ctx->pending_periph_flush_mask =0 ; ctx->pending_merge_3d_flush_mask =0 ; ctx->pending_dsc_flush_mask =0 ; ctx->pending_cdm_flush_mask =0 ;
Greg Kroah-Hartman
maintainerPATCH 342/398 drm/msm/hdmi_phy: fix runtime PM cleanup on probe failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit f4fae975db08a9aeec0b15e145c7d4d0fe02a0ec upstream.
msm_hdmi_phy_probe() enables runtime PM before enabling the PHY resources and initializing the PLL, but failures from either operation return without calling the matching pm_runtime_disable().
The remove path disables runtime PM, but it is not called when probe fails. As a result, runtime PM remains enabled after an unsuccessful probe.
Route failures after pm_runtime_enable() through a common error path and disable runtime PM before returning.
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/753043/
--- drivers/gpu/drm/msm/hdmi/hdmi_phy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/hdmi/hdmi_phy.c +6 -2
@@ -168,13 +168,13 @@ static int msm_hdmi_phy_probe(struct pla ret =msm_hdmi_phy_resource_enable (phy);if (ret) -return ret; + goto err_pm_disable; ret =msm_hdmi_phy_pll_init (pdev, phy->cfg->type);if (ret) {DRM_DEV_ERROR (dev,"couldn't init PLL\n" );msm_hdmi_phy_resource_disable (phy); -return ret; + goto err_pm_disable; }msm_hdmi_phy_resource_disable (phy);
@@ -182,6 +182,10 @@ static int msm_hdmi_phy_probe(struct plaplatform_set_drvdata (pdev, phy);return 0 ; + +err_pm_disable: +pm_runtime_disable (dev); +return ret; }static void msm_hdmi_phy_remove (struct platform_device *pdev)
Greg Kroah-Hartman
maintainerPATCH 343/398 drm/msm: RCU-free the scheduler-containing ring and VM objects
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonghyuk Kim(MalHyuk) <[email protected]>
commit 01c8d1f385f788f1bbbbb7687c4386d614281218 upstream.
Both struct msm_ringbuffer and struct msm_gem_vm embed a struct drm_gpu_scheduler. msm_ringbuffer_destroy() and the VM free callback msm_gem_vm_free() call drm_sched_fini() on the embedded scheduler and then free the containing object with plain kfree().
drm_sched_fence_get_timeline_name() returns fence->sched->name, and the scheduler fence keeps a .release callback so it is not ops-detached on signalling. A finished fence exported to userspace (the submit out-fence, or a VM_BIND fence, via sync_file / drm_syncobj) keeps pointing at the embedded scheduler after the ring/VM is freed, so a later get_timeline_name() -- reachable unprivileged through SYNC_IOC_FILE_INFO -- dereferences freed slab memory (KASAN slab-use-after-free read).
Per the dma-fence lifetime contract the exporter must keep the data backing a signalled fence alive for an RCU grace period. Free the scheduler-containing objects with kfree_rcu() instead of kfree().
Patchwork: https://patchwork.freedesktop.org/patch/750234/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/msm_gem.h | 3 +++ drivers/gpu/drm/msm/msm_gem_vma.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.h | 1 + 4 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_gem.h +3 -0
@@ -68,6 +68,9 @@ struct msm_gem_vm {/** @base: Inherit from drm_gpuvm. */ struct drm_gpuvm base; +/** @rcu: RCU-delayed free so an exported sched fence->sched stays valid. */ +struct rcu_head rcu; +/** * @sched: Scheduler used for asynchronous VM_BIND request. *
drivers/gpu/drm/msm/msm_gem_vma.c +1 -1
@@ -166,7 +166,7 @@ msm_gem_vm_free(struct drm_gpuvm *gpuvm)dma_fence_put (vm->last_fence);put_pid (vm->pid);kfree (vm->log); -kfree (vm); +kfree_rcu (vm, rcu); }/**
drivers/gpu/drm/msm/msm_ringbuffer.c +1 -1
@@ -140,5 +140,5 @@ void msm_ringbuffer_destroy(struct msm_rmsm_gem_kernel_put (ring->bo, ring->gpu->vm); -kfree (ring); +kfree_rcu (ring, rcu); }
drivers/gpu/drm/msm/msm_ringbuffer.h +1 -0
@@ -53,6 +53,7 @@ struct msm_ringbuffer {/* * The job scheduler for this ring. */ +struct rcu_head rcu;struct drm_gpu_scheduler sched;bool sched_initialized;
Greg Kroah-Hartman
maintainerPATCH 344/398 drm/amdgpu: fix rmmio iounmap skipped on device removal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengjun Yao <[email protected]>
commit 5155002b03b24ba3ef91c5c313b8cf0171b24904 upstream.
amdgpu_pci_remove() calls drm_dev_unplug() before fini_sw(), so drm_dev_enter() is already false there and the iounmap() guarded by it is skipped. This .remove path runs on both hot-unplug and plain rmmod, so the register BAR ioremap mapping leaks one instance per unload.
Unmap rmmio unconditionally (guard only on non-NULL) and drop the now unused idx.
--- 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
@@ -5098,7 +5098,7 @@ void amdgpu_device_fini_hw(struct amdgpuvoid amdgpu_device_fini_sw (struct amdgpu_device *adev) { -int i, idx; +int i;bool px;amdgpu_device_ip_fini (adev);
@@ -5140,11 +5140,9 @@ void amdgpu_device_fini_sw(struct amdgpuif ((adev->pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA )vga_client_unregister (adev->pdev); -if (drm_dev_enter (adev_to_drm (adev), &idx)) { - +if (adev->rmmio) {iounmap (adev->rmmio); adev->rmmio =NULL ; -drm_dev_exit (idx); }if (IS_ENABLED (CONFIG_PERF_EVENTS ))
Greg Kroah-Hartman
maintainerPATCH 345/398 smb: client: cancel reconnect work in clean_demultiplex_info()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit c65eae6f61d1778ff7a82e4aae4080e26f486af1 upstream.
clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:
cifs_demultiplex_thread()
cifs_readv_from_socket()
cifs_reconnect()
__cifs_reconnect()
cifs_queue_server_reconn()
mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
clean_demultiplex_info()
cancel_delayed_work_sync(&server->echo) // echo canceled
// reconnect NOT canceled
kfree_sensitive(server) // server freed ...later, on cifsiod_wq:
smb2_reconnect_server()
server->srv_count // UAF read of freed server
Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -1064,6 +1064,7 @@ clean_demultiplex_info(struct TCP_Serverspin_unlock (&server->srv_lock);cancel_delayed_work_sync (&server->echo); +cancel_delayed_work_sync (&server->reconnect);spin_lock (&server->srv_lock); server->tcpStatus = CifsExiting;
Greg Kroah-Hartman
maintainerPATCH 346/398 smb: client: fix rlist race and missing initialization
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit 5f270f091256da1338c3631083e15d7f83cc05e1 upstream.
TCP_Server_Info.rlist is allocated via kzalloc which zeros both ->next and ->prev to NULL instead of pointing to itself, making list_empty() always return false and list_add() dereference a NULL ->prev pointer.
Also, cifs_signal_cifsd_for_reconnect() can be called concurrently from multiple cifsd threads, allowing the same server's rlist node to be added twice into the local list, corrupting it.
--- fs/smb/client/connect.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/connect.c +7 -0
@@ -171,6 +171,8 @@ cifs_signal_cifsd_for_reconnect(struct T nserver = ses->chans[i].server;if (!nserver)continue ; +if (!list_empty (&nserver->rlist)) +continue ; nserver->srv_count++;list_add (&nserver->rlist, &reco); }
@@ -179,11 +181,15 @@ cifs_signal_cifsd_for_reconnect(struct T } } +spin_lock (&cifs_tcp_ses_lock);list_for_each_entry_safe (server, nserver, &reco, rlist) {list_del_init (&server->rlist);set_need_reco (server); +spin_unlock (&cifs_tcp_ses_lock);cifs_put_tcp_session (server,0 ); +spin_lock (&cifs_tcp_ses_lock); } +spin_unlock (&cifs_tcp_ses_lock); }/*
@@ -1823,6 +1829,7 @@ cifs_get_tcp_session(struct smb3_fs_contspin_lock_init (&tcp_ses->mid_counter_lock);INIT_LIST_HEAD (&tcp_ses->tcp_ses_list);INIT_LIST_HEAD (&tcp_ses->smb_ses_list); +INIT_LIST_HEAD (&tcp_ses->rlist);INIT_DELAYED_WORK (&tcp_ses->echo, cifs_echo_request);INIT_DELAYED_WORK (&tcp_ses->reconnect, smb2_reconnect_server);mutex_init (&tcp_ses->reconnect_mutex);
Greg Kroah-Hartman
maintainerPATCH 347/398 smb: client: fix use-after-free of iface in cifs_try_adding_channels()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
commit d034e836eefd7ce75e588f7031cffbeec594f5ac upstream.
cifs_try_adding_channels() iterates ses->iface_list with list_for_each_entry_safe_from(), which captures the next entry (niface) under iface_lock. The loop body then drops iface_lock for the whole duration of cifs_ses_add_channel().
A concurrent interface refresh (SMB3_request_interfaces() -> parse_server_interfaces()) marks all ifaces inactive and removes and frees any that are not re-advertised via list_del() + kref_put(), where release_iface() is a bare kfree(). Since niface typically has no channel holding a reference, the list reference is its last and it can be freed inside the unlocked window. On continue, the iterator advance step then dereferences niface->iface_head.next, and the loop body reads iface->rdma_capable/is_active, both on freed memory.
Fix this by never keeping an unreferenced list pointer across the unlocked window. Each channel attempt now re-scans the list from the head under iface_lock, takes a kref on the selected candidate, and passes only that referenced candidate to cifs_ses_add_channel(). weight_fulfilled still tracks selection progress, so restarting the scan preserves the original weighted distribution and the weight_fulfilled-before-kref_put ordering on the failure path.
Add a per-pass attempts cap so a flapping interface refresh cannot keep the inner loop spinning within a single tries increment.
--- fs/smb/client/sess.c | 106 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 42 deletions(-)
fs/smb/client/sess.c +64 -42
@@ -150,9 +150,9 @@ int cifs_try_adding_channels(struct cifsint old_chan_count, new_chan_count;int left;int rc =0 ; -int tries =0 ; +int tries =0 , attempts;size_t iface_weight =0 , iface_min_speed =0 ; -struct cifs_server_iface *iface =NULL , *niface =NULL ; +struct cifs_server_iface *iface =NULL , *candidate =NULL ;struct cifs_server_iface *last_iface =NULL ;spin_lock (&ses->chan_lock);
@@ -198,67 +198,89 @@ int cifs_try_adding_channels(struct cifsbreak ; } -if (!iface) - iface = list_first_entry(&ses->iface_list, struct cifs_server_iface, - iface_head); last_iface = list_last_entry(&ses->iface_list, struct cifs_server_iface, iface_head); iface_min_speed = last_iface->speed; +spin_unlock (&ses->iface_lock); -list_for_each_entry_safe_from (iface, niface, &ses->iface_list, - iface_head) { -/* do not mix rdma and non-rdma interfaces */ -if (iface->rdma_capable != ses->server->rdma) -continue ; - -/* skip ifaces that are unusable */ -if (!iface->is_active || - (is_ses_using_iface (ses, iface) && - !iface->rss_capable)) -continue ; + attempts =0 ; +while (left >0 ) { +spin_lock (&ses->iface_lock); -/* check if we already allocated enough channels */ - iface_weight = iface->speed / iface_min_speed; +/* +* iface_lock must be dropped while opening a channel, +* and a concurrent interface refresh may remove and +* free entries during that window, so no list entry +* may be kept across it without a reference. Scan +* the list from the beginning each time and only pass +* a referenced candidate to cifs_ses_add_channel(); +* weight_fulfilled tracks the progress so that no +* iface is selected beyond its weight. +*/ + candidate =NULL ; +list_for_each_entry (iface, &ses->iface_list, iface_head) { +/* do not mix rdma and non-rdma interfaces */ +if (iface->rdma_capable != ses->server->rdma) +continue ; + +/* skip ifaces that are unusable */ +if (!iface->is_active || + (is_ses_using_iface (ses, iface) && + !iface->rss_capable)) +continue ; + +/* check if we already allocated enough channels */ + iface_weight = iface->speed / iface_min_speed; + +if (iface->weight_fulfilled >= iface_weight) +continue ; + +/* take ref before unlock */ +kref_get (&iface->refcount); + candidate = iface; +break ; + } -if (iface->weight_fulfilled >= iface_weight) -continue ; +if (!candidate) { +/* no usable iface. reset weight_fulfilled and start over */ +list_for_each_entry (iface, &ses->iface_list, iface_head) + iface->weight_fulfilled =0 ; +spin_unlock (&ses->iface_lock); +break ; + } -/* take ref before unlock */ -kref_get (&iface->refcount); + attempts++; +if (attempts >3 * ses->chan_max) { +kref_put (&candidate->refcount, release_iface); +spin_unlock (&ses->iface_lock); +break ; + }spin_unlock (&ses->iface_lock); - rc =cifs_ses_add_channel (ses, iface); + rc =cifs_ses_add_channel (ses, candidate);spin_lock (&ses->iface_lock);if (rc) {cifs_dbg (VFS ,"failed to open extra channel on iface:%pIS rc=%d\n" , - &iface->sockaddr, + &candidate->sockaddr, rc);/* failure to add chan should increase weight */ - iface->weight_fulfilled++; -kref_put (&iface->refcount, release_iface); + candidate->weight_fulfilled++; +kref_put (&candidate->refcount, release_iface); +spin_unlock (&ses->iface_lock);continue ; } - iface->num_channels++; - iface->weight_fulfilled++; + candidate->num_channels++; + candidate->weight_fulfilled++;cifs_info ("successfully opened new channel on iface:%pIS\n" , - &iface->sockaddr); -break ; - } - -/* reached end of list. reset weight_fulfilled and start over */ -if (list_entry_is_head (iface, &ses->iface_list, iface_head)) { -list_for_each_entry (iface, &ses->iface_list, iface_head) - iface->weight_fulfilled =0 ; + &candidate->sockaddr);spin_unlock (&ses->iface_lock); - iface =NULL ; -continue ; - } -spin_unlock (&ses->iface_lock); - left--; - new_chan_count++; + left--; + new_chan_count++; +break ; + } }return new_chan_count - old_chan_count;
Greg Kroah-Hartman
maintainerPATCH 348/398 smb: client: reject short Next offsets in parse_server_interfaces()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 1b3221bb121079ad79a1f3c3aa360ba649832e7a upstream.
In parse_server_interfaces(), the server-supplied Next offset is validated against bytes_left, but not against the size of the interface structure itself.
A small, non-zero Next value can pass the bounds check but advance the pointer by less than sizeof(*p). This causes the next iteration of the loop to read misaligned, overlapping structure fields.
Fix this by ensuring the Next offset is at least sizeof(*p).
--- fs/smb/client/smb2ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/smb2ops.c +3 -3
@@ -786,9 +786,9 @@ next_iface:break ; }/* Validate that Next doesn't point beyond the buffer */ -if (next > bytes_left) { -cifs_dbg (VFS ,"%s: invalid Next pointer %zu > %zd\n" , - __func__, next, bytes_left); +if (next <sizeof (*p) || next > bytes_left) { +cifs_dbg (VFS ,"%s: invalid Next pointer %zu out of range [%zu, %zd]\n" , + __func__, next,sizeof (*p), bytes_left); rc = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 349/398 smb: client: fix smbd_connection leak on cifs_get_tcp_session() error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit e75c96157d45e498970158c8f7373d90102e33b9 upstream.
When an RDMA connection is successfully established via smbd_get_connection() but cifs_get_tcp_session() later fails (e.g. kthread_create() returns an error), the error path frees tcp_ses without first destroying the smbd_connection.
Fix this by calling smbd_destroy() in the out_err cleanup path before kfree(tcp_ses). smbd_destroy() safely handles the case where smbd_conn is NULL, so it can be called unconditionally.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -1933,6 +1933,7 @@ out_err:kfree (tcp_ses->leaf_fullpath);if (tcp_ses->ssocket)sock_release (tcp_ses->ssocket); +smbd_destroy (tcp_ses);kfree (tcp_ses); }return ERR_PTR (rc);
Greg Kroah-Hartman
maintainerPATCH 350/398 smb: client: fix unaligned access in WSL reparse point parser
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit e1aeaf79dea51e6065da56924bc07e22d59012ac upstream.
When wsl_to_fattr() parses WSL extended attributes, it computes a payload pointer from ea->ea_data + ea_name_length + 1. Since the smb2_file_full_ea_info struct is __packed and all WSL xattr names are 6 bytes long, the value pointer always lands at an odd byte offset, never satisfying __le32 or __le64 alignment requirements.
The code then casts this pointer to __le32 * or __le64 * and dereferences it directly, which may cause alignment faults on some architectures.
Replace all such casts with get_unaligned_le32() and get_unaligned_le64() in reparse_mkdev(), wsl_make_kuid(), wsl_make_kgid() and wsl_to_fattr().
--- fs/smb/client/reparse.c | 4 ++-- fs/smb/client/reparse.h | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-)
fs/smb/client/reparse.c +2 -2
@@ -1156,9 +1156,9 @@ static bool wsl_to_fattr(struct cifs_ope fattr->cf_gid =wsl_make_kgid (cifs_sb, v); else if (!strncmp(name, SMB2_WSL_XATTR_MODE, nlen)) {/* File type in reparse point tag and in xattr mode must match. */ -if (S_DT (fattr->cf_mode) !=S_DT (le32_to_cpu (*(__le32 *)v))) +if (S_DT (fattr->cf_mode) !=S_DT (get_unaligned_le32 (v)))return false; - fattr->cf_mode = (umode_t )le32_to_cpu (*(__le32 *)v); + fattr->cf_mode = (umode_t )get_unaligned_le32 (v); } else if (!strncmp(name, SMB2_WSL_XATTR_DEV, nlen)) { fattr->cf_rdev =reparse_mkdev (v); have_xattr_dev = true;
fs/smb/client/reparse.h +4 -3
@@ -9,6 +9,7 @@#include <linux/fs.h> #include <linux/stat.h> #include <linux/uidgid.h> +#include <linux/unaligned.h> #include "fs_context.h" #include "cifsglob.h"
@@ -22,7 +23,7 @@static inline dev_t reparse_mkdev (void *ptr) { -u64 v =le64_to_cpu (*(__le64 *)ptr); +u64 v =get_unaligned_le64 (ptr);return MKDEV (v &0xffffffff , v >>32 ); }
@@ -30,7 +31,7 @@ static inline dev_t reparse_mkdev(void *static inline kuid_t wsl_make_kuid (struct cifs_sb_info *cifs_sb,void *ptr) { -u32 uid =le32_to_cpu (*(__le32 *)ptr); +u32 uid =get_unaligned_le32 (ptr);if (cifs_sb_flags (cifs_sb) &CIFS_MOUNT_OVERR_UID )return cifs_sb->ctx->linux_uid;
@@ -40,7 +41,7 @@ static inline kuid_t wsl_make_kuid(strucstatic inline kgid_t wsl_make_kgid (struct cifs_sb_info *cifs_sb,void *ptr) { -u32 gid =le32_to_cpu (*(__le32 *)ptr); +u32 gid =get_unaligned_le32 (ptr);if (cifs_sb_flags (cifs_sb) &CIFS_MOUNT_OVERR_GID )return cifs_sb->ctx->linux_gid;
Greg Kroah-Hartman
maintainerPATCH 351/398 smb: client: fix next_buffer UAF and NextCommand bounds in compound PDUs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 05762c5bc1cfdcac36747994fde2c04387a457f1 upstream.
Fix several related bounds checking and pointer lifecycle issues in receive_encrypted_standard()'s handling of compound encrypted frames:
- Clear next_buffer after assigning it to server->bigbuf. A stale next_buffer pointer can lead to a use-after-free on subsequent error paths.
- Update pdu_length to the decrypted plaintext size (buf_size). Using the pre-decryption length allows NextCommand to point into stale ciphertext residue.
- Reject next_cmd values smaller than MID_HEADER_SIZE(server).
- Fix an integer overflow in the upper bound check by verifying pdu_length - next_cmd < MID_HEADER_SIZE(server), ensuring the trailing slice is large enough for a header.
--- fs/smb/client/smb2ops.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +10 -1
@@ -5280,6 +5280,7 @@ receive_encrypted_standard(struct TCP_Se length =decrypt_raw_data (server, buf, buf_size,NULL , false);if (length)return length; + pdu_length = buf_size; next_is_large = server->large_buf; one_more:
@@ -5292,8 +5293,15 @@ one_more: }if (next_cmd) { -if (WARN_ON_ONCE (next_cmd > pdu_length)) +if (next_cmd <MID_HEADER_SIZE (server) || + next_cmd > pdu_length || + pdu_length - next_cmd <MID_HEADER_SIZE (server)) { +unsigned int max_next = pdu_length > (unsigned int )MID_HEADER_SIZE (server) ? + pdu_length - (unsigned int )MID_HEADER_SIZE (server) :0 ; +cifs_server_dbg (VFS ,"invalid NextCommand offset %u out of range [%zu, %u]\n" , + next_cmd,MID_HEADER_SIZE (server), max_next);return -1 ; + }if (next_is_large) next_buffer = (char *)cifs_buf_get ();else
@@ -5329,6 +5337,7 @@ one_more: server->bigbuf = buf = next_buffer; else server->smallbuf = buf = next_buffer; + next_buffer =NULL ; goto one_more; }else if (ret !=0 ) {/*
Greg Kroah-Hartman
maintainerPATCH 352/398 smb: client: fix OOB struct field reads in move_smb2_ea_to_cifs()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit eeb5ef6083e1cefa2ef75041b5597ff228b8d7bb upstream.
In move_smb2_ea_to_cifs(), the while (src_size > 0) loop condition is insufficient. It allows iteration to continue even if the remaining src_size is too small to contain a complete smb2_ea_info structure. Consequently, reads of ea_name_length and ea_value_length can occur out-of-bounds.
Fix this by ensuring src_size >= sizeof(*src) before attempting to read any structure fields. Additionally, reject any next_entry_offset that is smaller than sizeof(*src) or that would advance the pointer beyond the available buffer.
Note that for calls where the server returns a malformed EA list, the error returned to userspace changes from -ENODATA (getxattr) or -ERANGE (listxattr) to -EIO. This correctly signals a server protocol error rather than misleadingly indicating "attribute not present" or "output buffer too small".
--- fs/smb/client/smb2ops.c | 25 +++++++++++++++++-------- fs/smb/client/trace.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-)
fs/smb/client/smb2ops.c +17 -8
@@ -1054,8 +1054,9 @@ move_smb2_ea_to_cifs(char *dst, size_t dchar *name, *value;size_t buf_size = dst_size;size_t name_len, value_len, user_name_len; +u32 next_off; -while (src_size >0 ) { +while (src_size >=sizeof (*src)) { name_len = (size_t )src->ea_name_length; value_len = (size_t )le16_to_cpu (src->ea_value_length);
@@ -1110,14 +1111,22 @@ move_smb2_ea_to_cifs(char *dst, size_t dif (!src->next_entry_offset)break ; -if (src_size <le32_to_cpu (src->next_entry_offset)) { -/* stop before overrun buffer */ - rc = -ERANGE ; -break ; + next_off =le32_to_cpu (src->next_entry_offset); +if (next_off <sizeof (*src) || src_size < next_off) { +cifs_dbg (FYI ,"EA next_entry_offset %u out of range [%zu, %zu]\n" , + next_off,sizeof (*src), src_size); + rc =smb_EIO2 (smb_eio_trace_ea_next_offset, + next_off, src_size); + goto out; + } + src_size -= next_off; + src = (void *)((char *)src + next_off); +if (src_size >0 && src_size <sizeof (*src)) { +cifs_dbg (FYI ,"EA next_entry_offset %u left truncated entry (%zu bytes)\n" , + next_off, src_size); + rc =smb_EIO2 (smb_eio_trace_ea_next_offset, next_off, src_size); + goto out; } - src_size -=le32_to_cpu (src->next_entry_offset); - src = (void *)((char *)src + -le32_to_cpu (src->next_entry_offset)); }/* didn't find the named attribute */
fs/smb/client/trace.h +1 -0
@@ -27,6 +27,7 @@ EM(smb_eio_trace_copychunk_overcopy_c, "copychunk_overcopy_c") \ EM(smb_eio_trace_create_rsp_too_small, "create_rsp_too_small") \ EM(smb_eio_trace_dfsref_no_rsp, "dfsref_no_rsp") \ + EM(smb_eio_trace_ea_next_offset, "ea_next_offset") \ EM(smb_eio_trace_ea_overrun, "ea_overrun") \ EM(smb_eio_trace_extract_will_pin, "extract_will_pin") \EM (smb_eio_trace_forced_shutdown,"forced_shutdown" ) \
Greg Kroah-Hartman
maintainerPATCH 353/398 smb: client: fix potential OOB read in smb3_enum_snapshots()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 4775c3b7a597907e0b97556c7986fda238a377ae upstream.
If snapshot_array_size is smaller than GMT_TOKEN_SIZE, smb3_enum_snapshots() sets ret_data_len tosizeof(struct smb_snapshot_array) without verifying the actual length of the server's reply.
Because SMB2_ioctl() places no lower bound on the server-supplied OutputCount and allocates retbuf to exactly that length, a short reply results in ret_data_len exceeding the size of retbuf. The subsequent copy_to_user() then reads past the end of retbuf, leaking adjacent slab memory to userspace. The subsequent clamp check is ineffective as it only reduces ret_data_len.
Fix this by rejecting replies shorter thansizeof(struct smb_snapshot_array) with -EIO. Note that the bound is set to the 12-byte struct size rather than the 16-byte MIN_SNAPSHOT_ARRAY_SIZE defined in MS-SMB2 3.3.5.15.1, because 12 bytes is exactly what copy_to_user() attempts to read.
--- fs/smb/client/smb2ops.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +7 -1
@@ -2415,8 +2415,14 @@ smb3_enum_snapshots(const unsigned int x* and retry the ioctl again with larger array size sufficient * to hold all of the snapshot GMT tokens on the second try. */ -if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) +if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) { +if (ret_data_len <sizeof (struct smb_snapshot_array )) { + rc = -EIO ; +kfree (retbuf); +return rc; + } ret_data_len =sizeof (struct smb_snapshot_array ); + }/* * We return struct SRV_SNAPSHOT_ARRAY, followed by
Greg Kroah-Hartman
maintainerPATCH 354/398 smb: client: fix server->total_read for compound encrypted PDUs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit f73726b83e4756fdaa099e1bc1143293bd57ad79 upstream.
In receive_encrypted_standard(), server->total_read is left at the full decrypted frame size when walking sub-PDUs of a compound encrypted frame. As a result, cifs_handle_standard() passes this full size to smb2_check_message(), causing the PDU length guards to incorrectly validate the entire compound frame instead of the current sub-PDU.
This allows truncated non-last sub-PDUs to bypass length validation, leading to out-of-bounds reads in smb2_get_data_area_len().
Fix this by setting server->total_read to the true length of the current sub-PDU: next_cmd for non-last sub-PDUs, and the remaining pdu_length for the last one.
--- fs/smb/client/smb2ops.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/smb2ops.c +1 -0
@@ -5301,6 +5301,7 @@ receive_encrypted_standard(struct TCP_Se one_more: shdr = (struct smb2_hdr *)buf; next_cmd =le32_to_cpu (shdr->NextCommand); + server->total_read = next_cmd ? next_cmd : pdu_length;if (*num_mids >=MAX_COMPOUND ) {cifs_server_dbg (VFS ,"too many PDUs in compound\n" );
Greg Kroah-Hartman
maintainerPATCH 355/398 smb: client: fix missing lower-bound check on DFS referral string offsets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit e83330c55edc0c3ac08aa6c95e49e4694c65523b upstream.
parse_dfs_referrals() checks that DfsPathOffset and NetworkAddressOffset do not exceed the buffer end, but fails to check that they don't point inside the referral header itself.
If a server provides an offset smaller thansizeof(struct dfs_referral_level_3), the derived string pointer overlaps with the struct fields, causing cifs_strndup_from_utf16() to interpret header data as UTF-16 strings.
Fix this by enforcing that string offsets are at least sizeof(*ref).
--- fs/smb/client/misc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
fs/smb/client/misc.c +10 -2
@@ -1050,7 +1050,11 @@ parse_dfs_referrals(struct get_dfs_refer node->ref_flag =le16_to_cpu (ref->ReferralEntryFlags);/* copy DfsPath */ -if (le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->DfsPathOffset) <sizeof (*ref) || +le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: DfsPathOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->DfsPathOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
@@ -1064,7 +1068,11 @@ parse_dfs_referrals(struct get_dfs_refer }/* copy link target UNC */ -if (le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->NetworkAddressOffset) <sizeof (*ref) || +le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: NetworkAddressOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->NetworkAddressOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
Greg Kroah-Hartman
maintainerPATCH 356/398 smb: client: fix missing iov bounds check in parse_posix_sids()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit b09d092eb24ad0110f16a9b7c1ed5d2a0c1733dc upstream.
In parse_posix_sids(), sidsbuf_end is calculated using the server-supplied out_len without being validated against the actual length of the received iov (iov_len).
If a server provides an inflated out_len, sidsbuf_end will point past the end of the iov. This defeats the bounds guards in posix_info_sid_size(), allowing out-of-bounds reads into adjacent kernel memory.
Fix this by rejecting responses where the calculated sidsbuf_end would exceed the received iov boundaries or cause pointer wraparound.
--- fs/smb/client/smb2inode.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/client/smb2inode.c +11 -0
@@ -70,6 +70,17 @@ static int parse_posix_sids(struct cifs_ sidsbuf = (u8 *)qi +le16_to_cpu (qi->OutputBufferOffset) + qi_len; sidsbuf_end = sidsbuf + out_len - qi_len; +if (sidsbuf_end < sidsbuf) { +cifs_dbg (VFS ,"%s: server-supplied out_len %u caused pointer wraparound\n" , + __func__, out_len); +return -EINVAL ; + } +if (sidsbuf_end > (u8 *)rsp_iov->iov_base + rsp_iov->iov_len) { +cifs_dbg (VFS ,"%s: server-supplied out_len %u overruns iov by %td bytes\n" , + __func__, out_len, + sidsbuf_end - ((u8 *)rsp_iov->iov_base + rsp_iov->iov_len)); +return -EINVAL ; + } owner_len =posix_info_sid_size (sidsbuf, sidsbuf_end);if (owner_len ==-1 )
Greg Kroah-Hartman
maintainerPATCH 357/398 HID: asus: fortify keyboard handshake
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antheas Kapenekakis <[email protected]>
[ Upstream commit e82ae34af29e910c96d33c8b3a90c60e27f1625e ]
Handshaking with an Asus device involves sending it a feature report with the string "ASUS Tech.Inc." and then reading it back to verify the handshake was successful, under the feature ID the interaction will take place.
Currently, the driver only does the first part. Add the readback to verify the handshake was successful. As this could cause breakages, allow the verification to fail with a dmesg error until we verify all devices work with it (they seem to).
Since the response is more than 16 bytes, increase the buffer size to 64 as well to avoid overflow errors. In addition, add the report ID to prints, to help identify failed handshakes.
--- drivers/hid/hid-asus.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)
drivers/hid/hid-asus.c +30 -4
@@ -48,7 +48,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard an#define FEATURE_REPORT_ID 0x0d#define INPUT_REPORT_ID 0x5d#define FEATURE_KBD_REPORT_ID 0x5a -#define FEATURE_KBD_REPORT_SIZE 16 +#define FEATURE_KBD_REPORT_SIZE 64#define FEATURE_KBD_LED_REPORT_ID1 0x5d#define FEATURE_KBD_LED_REPORT_ID2 0x5e
@@ -393,15 +393,41 @@ static int asus_kbd_set_report(struct histatic int asus_kbd_init (struct hid_device *hdev,u8 report_id) { +/* +* The handshake is first sent as a set_report, then retrieved +* from a get_report. They should be equal. +*/ const u8 buf[] = { report_id,0x41 ,0x53 ,0x55 ,0x53 ,0x20 ,0x54 ,0x65 ,0x63 ,0x68 ,0x2e ,0x49 ,0x6e ,0x63 ,0x2e ,0x00 };int ret; ret =asus_kbd_set_report (hdev, buf,sizeof (buf)); -if (ret <0 ) -hid_err (hdev,"Asus failed to send init command: %d\n" , ret); +if (ret <0 ) { +hid_err (hdev,"Asus handshake %02x failed to send: %d\n" , + report_id, ret); +return ret; + } -return ret; + u8 *readbuf __free(kfree) = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL); +if (!readbuf) +return -ENOMEM ; + + ret =hid_hw_raw_request (hdev, report_id, readbuf, +FEATURE_KBD_REPORT_SIZE ,HID_FEATURE_REPORT , +HID_REQ_GET_REPORT ); +if (ret <0 ) { +hid_warn (hdev,"Asus handshake %02x failed to receive ack: %d\n" , + report_id, ret); + }else if (memcmp (readbuf, buf,sizeof (buf)) !=0 ) { +hid_warn (hdev,"Asus handshake %02x returned invalid response: %*ph\n" , + report_id,FEATURE_KBD_REPORT_SIZE , readbuf); + } + +/* +* Do not return error if handshake is wrong until this is +* verified to work for all devices. +*/ +return 0 ; } static int asus_kbd_get_functions(struct hid_device *hdev,
Greg Kroah-Hartman
maintainerPATCH 358/398 ntsync: Honour callers time namespace for absolute MONOTONIC timeouts
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 180a232ea78003d1dc869b217b4e49106fd58e8f upstream.
ntsync_schedule() takes the absolute timeout from userspace and hands it to schedule_hrtimeout_range_clock() with HRTIMER_MODE_ABS. For the default CLOCK_MONOTONIC path, it does not call timens_ktime_to_host() first.
A process inside a CLOCK_MONOTONIC time namespace computes the absolute timeout in its own clock view. The kernel reads the same value against the host clock. The two differ by the namespace offset. The timeout then fires too early or too late.
Other users of absolute timeouts run the ktime through timens_ktime_to_host() before starting the hrtimer. ntsync was added later and missed that step.
/dev/ntsync is mode 0666. Any user inside a time namespace that can open it is affected. The visible effect is wrong timeout behaviour for Wine in a container that sets a CLOCK_MONOTONIC offset.
Reproducer: unshare --user --time, set the monotonic offset to -10s, issue NTSYNC_IOC_WAIT_ANY with a 100 ms absolute MONOTONIC timeout. The baseline run elapses about 100 ms. The run inside the namespace elapses about 0 ms.
Apply timens_ktime_to_host() to the parsed timeout when the caller did not set NTSYNC_WAIT_REALTIME. The helper does nothing in the initial time namespace, so the fast path is unchanged.
--- drivers/misc/ntsync.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/misc/ntsync.c +3 -0
@@ -19,6 +19,7 @@#include <linux/sched/signal.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/time_namespace.h> #include <uapi/linux/ntsync.h> #define NTSYNC_NAME "ntsync"
@@ -845,6 +846,8 @@ static int ntsync_schedule(const structif (args->flags &NTSYNC_WAIT_REALTIME ) clock =CLOCK_REALTIME ; +else + timeout =timens_ktime_to_host (clock, timeout); do { if (signal_pending(current)) {
Greg Kroah-Hartman
maintainerPATCH 359/398 ntsync: reject wait ioctls with zero owner
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
commit 61611481f7b599e0526a3782c626b1a9deeb48bd upstream.
setup_wait() already validates pad and flags but not owner, while Documentation/userspace-api/ntsync.rst requires EINVAL when owner is zero. Reject early before queueing waiters.
--- drivers/misc/ntsync.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/misc/ntsync.c +3 -0
@@ -884,6 +884,9 @@ static int setup_wait(struct ntsync_deviif (args->pad || (args->flags & ~NTSYNC_WAIT_REALTIME ))return -EINVAL ; +if (!args->owner) +return -EINVAL ; +if (size >=sizeof (fds))return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 360/398 smb: client: fix busy dentry warning on unmount after DIO
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zizhi Wo <[email protected]>
commit 75f5c412fa867efa0bf9b646bffe0d912109e84a upstream.
Commit c68337442f03 ("cifs: Fix busy dentry used after unmounting") fixed the issue in cifs where deferred close of a file led to a dentry reference count not being released in umount, by flushing deferredclose_wq in cifs_kill_sb() to solve it.
However, the cifs DIO path suffers from the same busy-dentry problem caused by a delayed dentry reference-count release:
[dio] [cifsd] [close + umount]
netfs_unbuffered_write_iter_locked
...
cifs_demultiplex_thread
netfs_unbuffered_write
cifs_issue_write netfs_wait_for_in_progress_stream [1]
... netfs_write_subrequest_terminated netfs_subreq_clear_in_progress netfs_wake_collector // wake [1] netfs_put_subrequest netfs_put_request queue_work(system_dfl_wq, xxx) [2] // dio write return cifs_close _cifsFileInfo_put // cfile->count 2->1 --cfile->count [3] // umount cifs_kill_sb kill_anon_super // warning triggered! shrink_dcache_for_umount [4]
[system_dfl_wq] [5]netfs_free_request
...
_cifsFileInfo_put
// cfile->count 1->0
--cfile->count
queue_work(fileinfo_put_wq, xxx)
[fileinfo_put_wq] [6]cifsFileInfo_put_work
cifsFileInfo_put_final
dput
If the umount path is triggered before [5], it results warning:
BUG: Dentry 00000000eab1f070{i=9a917b66ae404fec,n=test} still in use (1)[unmount of cifs cifs]
The existing per-inode ictx->io_count wait in cifs_evict_inode() does not
help: it lives in the inode eviction path, which runs after shrink_dcache_for_umount() has already warned about the busy dentries.
Fix it by adding a per-superblock outstanding-rreq counter that is incremented in cifs_init_request() and decremented in cifs_free_request(). In cifs_kill_sb(), before kill_anon_super(), wait for this counter to reach 0 - which guarantees that all cleanup_work for this sb have run and thus all relevant cfile puts are queued on fileinfo_put_wq or serverclose_wq. Then drain the workqueue so the dentry refs are dropped.
This is a targeted wait, not a flush of the system-wide system_dfl_wq.
--- fs/smb/client/cifs_fs_sb.h | 1 + fs/smb/client/cifsfs.c | 12 ++++++++++++ fs/smb/client/connect.c | 1 + fs/smb/client/file.c | 5 +++++ 4 files changed, 19 insertions(+)
fs/smb/client/cifs_fs_sb.h +1 -0
@@ -57,6 +57,7 @@ struct cifs_sb_info {struct smb3_fs_context *ctx;atomic_t active;atomic_t mnt_cifs_flags; +atomic_t outstanding_rreq;/* nr of rreqs not yet fully deinitialized */ struct delayed_work prune_tlinks;struct rcu_head rcu;
fs/smb/client/cifsfs.c +12 -0
@@ -342,6 +342,18 @@ static void cifs_kill_sb(struct super_bl/* Wait for all opened files to release */ flush_workqueue (deferredclose_wq); +/* +* Wait for all in-flight netfs I/O requests to finish their +* cleanup_work so that any cifsFileInfo final puts they queue +* to fileinfo_put_wq/serverclose_wq have been queued, then +* drain the workqueue so the cfile dentry refs are dropped to +* avoid the busy dentry warning. +*/ +wait_var_event (&cifs_sb->outstanding_rreq, + !atomic_read (&cifs_sb->outstanding_rreq)); +flush_workqueue (serverclose_wq); +flush_workqueue (fileinfo_put_wq); +/* finally release root dentry */ dput (cifs_sb->root); cifs_sb->root =NULL ;
fs/smb/client/connect.c +1 -0
@@ -3597,6 +3597,7 @@ int cifs_setup_cifs_sb(struct cifs_sb_inspin_lock_init (&cifs_sb->tlink_tree_lock); cifs_sb->tlink_tree =RB_ROOT ; +atomic_set (&cifs_sb->outstanding_rreq,0 );cifs_dbg (FYI ,"file mode: %04ho dir mode: %04ho\n" , ctx->file_mode, ctx->dir_mode);
fs/smb/client/file.c +5 -0
@@ -289,6 +289,7 @@ static int cifs_init_request(struct netfreturn -EIO ; } +atomic_inc (&cifs_sb->outstanding_rreq);return 0 ; }
@@ -310,9 +311,13 @@ static void cifs_rreq_done(struct netfs_static void cifs_free_request (struct netfs_io_request *rreq) { struct cifs_io_request *req = container_of(rreq, struct cifs_io_request, rreq); +struct cifs_sb_info *cifs_sb =CIFS_SB (rreq->inode->i_sb);if (req->cfile)cifsFileInfo_put (req->cfile); + +if (atomic_dec_and_test (&cifs_sb->outstanding_rreq)) +wake_up_var (&cifs_sb->outstanding_rreq); }static void cifs_free_subrequest (struct netfs_io_subrequest *subreq)
Greg Kroah-Hartman
maintainerPATCH 361/398 ALSA: usb-audio: Optimize the copy of packet sizes for implicit fb handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 36adb51ac0b19edb32ffeea3fe66b174bad25ead ]
We did manual copies over loop for the packet data update of the implicit feedback, but this can be optimized with a simple memcpy().
Along with it, change the data type of snd_usb_packet_info struct to align with other (from uint32_t to int).
No functional changes but only code optimizations.
Stable-dep-of: 76a986c980bb ("ALSA: usb-audio: Clamp implicit feedback packet count to URB capacity")
--- sound/usb/card.h | 2 +- sound/usb/endpoint.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
sound/usb/card.h +1 -1
@@ -90,7 +90,7 @@ struct snd_usb_endpoint {struct snd_urb_ctx urb[MAX_URBS ];struct snd_usb_packet_info { -uint32_t packet_size[MAX_PACKS_HS ]; +int packet_size[MAX_PACKS_HS ];int packets; } next_packet[MAX_URBS ];unsigned int next_packet_head;/* ring buffer offset to read */
sound/usb/endpoint.c +3 -3
@@ -470,7 +470,7 @@ int snd_usb_queue_pending_output_urbs(stwhile (ep_state_running (ep)) {struct snd_usb_packet_info *packet;struct snd_urb_ctx *ctx =NULL ; -int err, i; +int err; scoped_guard(spinlock_irqsave, &ep->lock) { if ((!implicit_fb || ep->next_packet_queued > 0) &&
@@ -490,8 +490,8 @@ int snd_usb_queue_pending_output_urbs(st/* copy over the length information */ if (implicit_fb) { ctx->packets = packet->packets; -for (i =0 ; i < packet->packets; i++) - ctx->packet_size[i] = packet->packet_size[i]; +memcpy (ctx->packet_size, packet->packet_size, + packet->packets *sizeof (packet->packet_size[0 ])); }/* call the data handler to fill in playback data */
Greg Kroah-Hartman
maintainerPATCH 362/398 ALSA: usb-audio: Clamp implicit feedback packet count to URB capacity
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 76a986c980bb502c7688d605ac7a67fd257a9a1b ]
data_ep_set_params() allocates each data URB for exactly u->packets isochronous frames, so urb->iso_frame_desc[] has u->packets slots and ctx->packets is the driver's only record of that limit. For an implicit feedback sink, snd_usb_queue_pending_output_urbs() overwrites it with the sync source's packet count, which is calculated independently from the capture endpoint's parameters. When that count is larger, prepare_playback_urb() and prepare_silent_urb() can write iso_frame_desc[] past the allocation; their existing bounds limit payload bytes, not the descriptor index.
The reproducer uses a high-speed UAC2 device declaring bInterval 1 for implicit feedback capture (8 packets) and bInterval 4 for playback (1 packet). On the first capture completion after the stream starts, it accesses seven descriptors spanning 112 bytes beyond the one-packet URB:
BUG: KASAN: slab-out-of-bounds in prepare_playback_urb (sound/usb/pcm.c:1560) Write of size 4 at addr ffff88801e696ad0 by task vhci_rx/178 prepare_playback_urb (sound/usb/pcm.c:1560) prepare_outbound_urb (sound/usb/endpoint.c:340) snd_usb_queue_pending_output_urbs (sound/usb/endpoint.c:501) snd_complete_urb (sound/usb/endpoint.c:1834) __usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1657) usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1741) vhci_rx_loop (drivers/usb/usbip/vhci_rx.c:107) kthread (kernel/kthread.c:436) The buggy address belongs to the object at ffff88801e696a00 which belongs to the cache kmalloc-256 of size 256 The buggy address is located 0 bytes to the right of allocated 208-byte region [ffff88801e696a00, ffff88801e696ad0)
Record the allocated packet count per endpoint and clamp both the adopted count and the packet-size copy to it. Fold the Format Type II delimiter into urb_packs before the allocation loop so the recorded limit matches every URB.
--- sound/usb/card.h | 1 + sound/usb/endpoint.c | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-)
sound/usb/card.h +1 -0
@@ -116,6 +116,7 @@ struct snd_usb_endpoint {unsigned int phase;/* phase accumulator */ unsigned int maxpacksize;/* max packet size in bytes */ unsigned int maxframesize;/* max packet size in frames */ +unsigned int max_urb_packs;/* packets allocated per data URB */ unsigned int max_urb_frames;/* max URB size in frames */ unsigned int curpacksize;/* current packet size in bytes (for capture) */ unsigned int curframesize;/* current packet size in frames (for capture) */
sound/usb/endpoint.c +7 -5
@@ -489,9 +489,10 @@ int snd_usb_queue_pending_output_urbs(st/* copy over the length information */ if (implicit_fb) { - ctx->packets = packet->packets; + ctx->packets =min_t (int, packet->packets, + ep->max_urb_packs);memcpy (ctx->packet_size, packet->packet_size, - packet->packets *sizeof (packet->packet_size[0 ])); + ctx->packets *sizeof (packet->packet_size[0 ])); }/* call the data handler to fill in playback data */
@@ -1235,15 +1236,16 @@ static int data_ep_set_params(struct snd ep->nurbs =min (max_urbs, urbs_per_period * ep->cur_buffer_periods); } +if (fmt->fmt_type ==UAC_FORMAT_TYPE_II ) + urb_packs++;/* for transfer delimiter */ + ep->max_urb_packs = urb_packs; +/* allocate and initialize data urbs */ for (i =0 ; i < ep->nurbs; i++) {struct snd_urb_ctx *u = &ep->urb[i]; u->index = i; u->ep = ep; u->packets = urb_packs; - -if (fmt->fmt_type ==UAC_FORMAT_TYPE_II ) - u->packets++;/* for transfer delimiter */ u->buffer_size = maxsize * u->packets; u->urb =usb_alloc_urb (u->packets,GFP_KERNEL );if (!u->urb)
Greg Kroah-Hartman
maintainerPATCH 363/398 signal: Move MMCID exit out of sighand lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
[ Upstream commit 2b1642b881088bbf73fcb1147c474a198ec46729 ]
There is no need anymore to keep this under sighand lock as the current code and the upcoming replacement are not depending on the exit state of a task anymore.
That allows to use a mutex in the exit path.
[Backport to 6.18: Keep the MMCID declarations and CONFIG_SCHED_MM_CID stub in include/linux/mm.h, where they live in this tree, and rename the existing exit helper and its barrier-comment references there and in kernel/sched/core.c. Preserve the stable helper's runqueue locking, mm_cid_active store, memory barrier and per-CPU CID release, as well as the separate sched_mm_cid_before_execve() implementation. This tree does not have the upstream MMCID refactoring that moved the declarations to sched.h and made the exec helper call the exit helper.
Move the existing exit cleanup before exit_signals() in do_exit(), as upstream does. This removes the MMCID calls from the exit_signals() code rewritten by d2710c8d938ae ("signal: Prevent exec() race"), allowing that fix to apply without importing unrelated MMCID changes. No functions are added.]
[ sashal: Reduced backport -- upstream 2b1642b881088 touches 4 file(s), this
backport carries 4. Not backported here:
include/linux/sched.h
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: d2710c8d938a ("signal: Prevent exec() race")
--- include/linux/mm.h | 4 ++-- kernel/exit.c | 1 + kernel/sched/core.c | 6 +++--- kernel/signal.c | 2 -- 4 files changed, 6 insertions(+), 7 deletions(-)
include/linux/mm.h +2 -2
@@ -2516,7 +2516,7 @@ struct zap_details {void sched_mm_cid_before_execve (struct task_struct *t);void sched_mm_cid_after_execve (struct task_struct *t);void sched_mm_cid_fork (struct task_struct *t); -void sched_mm_cid_exit_signals (struct task_struct *t); +void sched_mm_cid_exit (struct task_struct *t);static inline int task_mm_cid (struct task_struct *t) {return t->mm_cid;
@@ -2525,7 +2525,7 @@ static inline int task_mm_cid(struct tasstatic inline void sched_mm_cid_before_execve (struct task_struct *t) { }static inline void sched_mm_cid_after_execve (struct task_struct *t) { }static inline void sched_mm_cid_fork (struct task_struct *t) { } -static inline void sched_mm_cid_exit_signals (struct task_struct *t) { } +static inline void sched_mm_cid_exit (struct task_struct *t) { }static inline int task_mm_cid (struct task_struct *t) {/*
kernel/exit.c +1 -0
@@ -924,6 +924,7 @@ void __noreturn do_exit(long code)user_events_exit (tsk);io_uring_files_cancel (); +sched_mm_cid_exit (tsk);exit_signals (tsk);/* sets PF_EXITING */ seccomp_filter_release (tsk);
kernel/sched/core.c +3 -3
@@ -10545,7 +10545,7 @@ int __sched_mm_cid_migrate_from_try_stea* * The implicit barrier after cmpxchg per-mm/cpu cid before loading * rq->curr->mm_cid_active matches the barrier in -* sched_mm_cid_exit_signals(), sched_mm_cid_before_execve(), and +* sched_mm_cid_exit(), sched_mm_cid_before_execve(), and * sched_mm_cid_after_execve() between store to t->mm_cid_active and * load of per-mm/cpu cid. */
@@ -10665,7 +10665,7 @@ static void sched_mm_cid_remote_clear(st* * The implicit barrier after cmpxchg per-mm/cpu cid before loading * rq->curr->mm_cid_active matches the barrier in -* sched_mm_cid_exit_signals(), sched_mm_cid_before_execve(), and +* sched_mm_cid_exit(), sched_mm_cid_before_execve(), and * sched_mm_cid_after_execve() between store to t->mm_cid_active and * load of per-mm/cpu cid. */
@@ -10810,7 +10810,7 @@ void task_tick_mm_cid(struct rq *rq, strtask_work_add (curr, work,TWA_RESUME ); } -void sched_mm_cid_exit_signals (struct task_struct *t) +void sched_mm_cid_exit (struct task_struct *t) {struct mm_struct *mm = t->mm;struct rq *rq;
kernel/signal.c +0 -2
@@ -3150,7 +3150,6 @@ void exit_signals(struct task_struct *tscgroup_threadgroup_change_begin (tsk);if (thread_group_empty (tsk) || (tsk->signal->flags &SIGNAL_GROUP_EXIT )) { -sched_mm_cid_exit_signals (tsk); tsk->flags |=PF_EXITING ;cgroup_threadgroup_change_end (tsk);return ;
@@ -3161,7 +3160,6 @@ void exit_signals(struct task_struct *ts* From now this task is not visible for group-wide signals, * see wants_signal(), do_signal_stop(). */ -sched_mm_cid_exit_signals (tsk); tsk->flags |=PF_EXITING ;cgroup_threadgroup_change_end (tsk);
Greg Kroah-Hartman
maintainerPATCH 364/398 signal: Prevent exec() race
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
[ Upstream commit d2710c8d938ae6a825a6463158e6e6f31eac792a ]
Hyunwoo debugged the following KASAN UAF splat:
BUG: KASAN: slab-use-after-free in __send_signal_locked+0xb27/0xba0 Write of size 8 at addr ffff888007ed80c8 by task poc/79 ... Call Trace: __send_signal_locked+0xb27/0xba0 do_send_sig_info+0xa7/0x160 do_send_specific+0x76/0xa0 __x64_sys_tgkill+0x193/0x270 ... Allocated by task 80: do_timer_create+0x1a4/0x1030 __x64_sys_timer_create+0x145/0x190 ... Freed by task 12: kmem_cache_free_bulk+0x1f8/0x4a0 kvfree_rcu_bulk+0x14f/0x1c0 kfree_rcu_work+0x128/0x1a0 ... Last potentially related work creation: kvfree_call_rcu+0x39/0x390 __flush_itimer_signals+0x211/0x320 flush_itimer_signals+0x47/0x90 begin_new_exec+0xa6b/0x28c0
It turned out that this happens with a non-leader exec() as Hyunwoo explained:
de_thread() calls exchange_tids() before release_task(leader), so the struct pid held by a SIGEV_THREAD_ID timer created against the leader's tid now points to the thread which called execve(). pid_task() returns that thread and lock_task_sighand() on it succeeds.
If the timer signal is blocked, its sigqueue stays queued on the leader's task::pending. The next expiry of that timer can then run while release_task() flushes the queue.
posixtimer_send_sigqueue() checks whether the sigqueue is already queued with a plain list_empty(), which only reads list_head::next. list_del_init() is not atomic and INIT_LIST_HEAD() stores list_head::next before list_head::prev, so the check can pass in between. list_add_tail() queues the entry on the task::pending of the live thread, and the list_head::prev store from the flush then overwrites the list_head::prev link that list_add_tail() has just set.
__flush_itimer_signals() does not undo that either. With list_head::prev pointing at the entry itself, its list_del_init() only stores the same values again, so the entry is not removed from the list. It is still there after the last reference is dropped and the timer is freed by RCU, and the list_add_tail() of a later tgkill() follows that list_head::prev into the freed timer.
This problem surfaced with the recent commit which moved the sigqueue flush out of the sighand lock held region.
Hyonwoo proposed to fix this by using list_del_init_careful(), but that just papers over the problem. After some disucssions and various attempts to solve it, Eric pointed out that there is no reason to flush task::pending late in release_task() and it should be done in exit_signals() already.
As nothing can collect and deliver signals which are queued in a dying task's pending queue, there is no reason to delay it further.
But it has to be ensured that no signals can be queued into it after that point. exit_signals() sets PF_EXITING in task::flags, which can be used as an indicator for this.
Cure it by:
- Preventing signal queueing for task private signals (PIDTYPE_PID) when the task has PF_EXITING set in __send_signal_locked() and in posixtimer_send_sigqueue().
- Protecting the unlocked setting of PF_EXITING in exit_signals() for the task group empty and the group exit case with sighand lock
- Flushing task::pending signals right there.
Optimize that by moving the whole pending list to an on-stack list head under sighand lock and free the signals without the lock held.
There has been quite some discussion about the lockless flush and the non-leader exec case on weakly ordered systems. The problem is that a third party which tries to send a posix timer signal relies on the PID lookup to find the target task and that lookup might result in the new leader when the signal was originaly directed to the old leader. In case that the signal was queued on the old leader then the lockless flush raised a concern over the following situation:
old_leader new_leader third party
A: flush_list() // list_del_init() stores to sigqueue
LOCK (tasklist)
old_leader->exit_state = EXIT_ZOMBIE;
B: UNLOCK (tasklist)
C: LOCK (tasklist)
if (old_leader->exit_state) transfer_tids() D: store PID posix_timer_send_sigqueue() // Observes #D so t = new_leader
E: t = get_target()
F: LOCK (sighand)
G: if (list_empty(sigqueue))
list_add(sigqueue)
The concern was that the third party might observe #D but not observe #A and therefore would proceed to #G while the list_del() stores (#A) in flush_list() are not visible yet, which could result in list corruption.
That would be possible if looking at it solely from a RELEASE+ACQUIRE ordering point of view, but B-C is a UNLOCK+LOCK hand-over, which is not the same as RELEASE+ACQUIRE:
RELEASE+ACQUIRE: RCpc, only the CPUs involved agree on the ordering
UNLOCK+LOCK: RCtso, the hand-over is store-ordering
As B-C is UNLOCK+LOCK, which is RCtso and that does impose store order, A stores must happen before the D store.
Combine with E-F, which has a data dependency from the LOAD to the LOCK and thereby constraints later LOADs, those sigqueue loads in G that come after F must in fact observe the A stores.
--- kernel/exit.c | 11 ++--- kernel/signal.c | 117 +++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 92 insertions(+), 36 deletions(-)
kernel/exit.c +6 -5
@@ -304,12 +304,13 @@ repeat:free_pids (post.pids);release_thread (p);/* -* This task was already removed from the process/thread/pid lists -* and lock_task_sighand(p) can't succeed. Nobody else can touch -* ->pending or, if group dead, signal->shared_pending. We can call -* flush_sigqueue() lockless. +* This task was already removed from the process/thread/pid lists and +* lock_task_sighand(p) can't succeed. If it's the group leader then +* flush tsk->signal->shared_pending. tsk->pending has been flushed +* already in exit_signals(). Nothing else can touch +* signal->shared_pending anymore, so flush_sigqueue() can be invoked +* lockless. */ -flush_sigqueue (&p->pending);if (thread_group_leader (p))flush_sigqueue (&p->signal->shared_pending);
kernel/signal.c +86 -31
188 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 365/398 xfrm: Refactor xfrm_input lock to reduce contention with RSS
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianbo Liu <[email protected]>
[ Upstream commit 10a11861943902fda74f37f456b45183b2bca270 ]
With newer NICs like mlx5 supporting RSS for IPsec crypto offload, packets for a single Security Association (SA) are scattered across multiple CPU cores for parallel processing. The xfrm_state spinlock (x->lock) is held for each packet during xfrm processing.
When multiple connections or flows share the same SA, this parallelism causes high lock contention on x->lock, creating a performance bottleneck and limiting scalability.
The original xfrm_input() function exacerbated this issue by releasing and immediately re-acquiring x->lock. For hardware crypto offload paths, this unlock/relock sequence is unnecessary and introduces significant overhead. This patch refactors the function to relocate the type_offload->input_tail call for the offload path, performing all necessary work while continuously holding the lock. This reordering is safe, since packets which don't pass the checks below will still fail them with the new code.
Performance testing with iperf using multiple parallel streams over a single IPsec SA shows significant improvement in throughput as the number of queues (and thus CPU cores) increases:
+-----------+---------------+--------------+-----------------+ | RX queues | Before (Gbps) | After (Gbps) | Improvement (%) | +-----------+---------------+--------------+-----------------+ | 2 | 32.3 | 34.4 | 6.5 | | 4 | 34.4 | 40.0 | 16.3 | | 6 | 24.5 | 38.3 | 56.3 | | 8 | 23.1 | 38.3 | 65.8 | | 12 | 18.1 | 29.9 | 65.2 | | 16 | 16.0 | 25.2 | 57.5 | +-----------+---------------+--------------+-----------------+
Stable-dep-of: 3cf5cdecd99c ("xfrm: save input state data before secpath resets")
--- net/xfrm/xfrm_input.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
net/xfrm/xfrm_input.c +7 -7
@@ -504,6 +504,7 @@ int xfrm_input(struct sk_buff *skb, intif (encap_type ==-1 ) { async =1 ; seq =XFRM_SKB_CB (skb)->seq.input.low; +spin_lock (&x->lock); goto resume; }/* GRO call */
@@ -540,6 +541,8 @@ int xfrm_input(struct sk_buff *skb, intXFRM_INC_STATS (net,LINUX_MIB_XFRMINHDRERROR ); goto drop; } + + nexthdr = x->type_offload->input_tail (x, skb); } goto lock;
@@ -637,11 +640,9 @@ lock: goto drop_unlock; } -spin_unlock (&x->lock); -if (xfrm_tunnel_check (skb, x, family)) {XFRM_INC_STATS (net,LINUX_MIB_XFRMINSTATEMODEERROR ); - goto drop; + goto drop_unlock; } seq_hi =htonl (xfrm_replay_seqhi (x, seq));
@@ -649,9 +650,8 @@ lock:XFRM_SKB_CB (skb)->seq.input.low = seq;XFRM_SKB_CB (skb)->seq.input.hi = seq_hi; -if (crypto_done) { - nexthdr = x->type_offload->input_tail (x, skb); - }else { +if (!crypto_done) { +spin_unlock (&x->lock);dev_hold (skb->dev); nexthdr = x->type->input (x, skb);
@@ -662,9 +662,9 @@ lock: }dev_put (skb->dev); +spin_lock (&x->lock); } resume: -spin_lock (&x->lock);if (nexthdr <0 ) {if (nexthdr == -EBADMSG ) { xfrm_audit_state_icvfail(x, skb,
Greg Kroah-Hartman
maintainerPATCH 366/398 xfrm: Fix dev use-after-free in xfrm async resumption
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dong Chenchen <[email protected]>
[ Upstream commit 8045c0df98d4f14c54e5cb875f1c9c0ce89fe4ff ]
xfrm async resumption hold skb->dev refcnt until after transport_finish. However, xfrm_rcv_cb may modify skb->dev to tunnel dev without taking device reference, such as vti_rcv_cb. The subsequent async resumption will decrement the tunnel device's reference count, which lead to uaf of tunnel dev and refcnt leak of orig dev as below:
unregister_netdevice: waiting for vti1 to become free. Usage count = -2
Stash the original skb->dev to fix refcnt imbalance. The new skb->dev set by xfrm_rcv_cb can race with device teardown. Extend rcu protection over xfrm_rcv_cb and transport_finish to prevent races.
Stable-dep-of: 3cf5cdecd99c ("xfrm: save input state data before secpath resets")
--- net/ipv4/xfrm4_input.c | 2 -- net/ipv6/xfrm6_input.c | 2 -- net/xfrm/xfrm_input.c | 29 ++++++++++++++++------------- 3 files changed, 16 insertions(+), 17 deletions(-)
net/ipv4/xfrm4_input.c +0 -2
@@ -76,8 +76,6 @@ int xfrm4_transport_finish(struct sk_bufNF_HOOK (NFPROTO_IPV4 ,NF_INET_PRE_ROUTING ,dev_net (dev),NULL , skb, dev,NULL , xfrm4_rcv_encap_finish); -if (async) -dev_put (dev);return 0 ; }
net/ipv6/xfrm6_input.c +0 -2
@@ -71,8 +71,6 @@ int xfrm6_transport_finish(struct sk_bufNF_HOOK (NFPROTO_IPV6 ,NF_INET_PRE_ROUTING ,dev_net (dev),NULL , skb, dev,NULL , xfrm6_transport_finish2); -if (async) -dev_put (dev);return 0 ; }
net/xfrm/xfrm_input.c +16 -13
@@ -464,6 +464,7 @@ int xfrm_input(struct sk_buff *skb, int {const struct xfrm_state_afinfo *afinfo;struct net *net =dev_net (skb->dev); +struct net_device *dev = skb->dev;int err;__be32 seq;__be32 seq_hi;
@@ -490,7 +491,7 @@ int xfrm_input(struct sk_buff *skb, int LINUX_MIB_XFRMINSTATEINVALID);if (encap_type ==-1 ) -dev_put (skb->dev); +dev_put (dev); goto drop; }
@@ -652,16 +653,16 @@ lock:if (!crypto_done) {spin_unlock (&x->lock); -dev_hold (skb->dev); +dev_hold (dev); nexthdr = x->type->input (x, skb);if (nexthdr == -EINPROGRESS ) {if (async) -dev_put (skb->dev); +dev_put (dev);return 0 ; } -dev_put (skb->dev); +dev_put (dev);spin_lock (&x->lock); } resume:
@@ -696,7 +697,7 @@ resume: err =xfrm_inner_mode_input (x, skb);if (err == -EINPROGRESS ) {if (async) -dev_put (skb->dev); +dev_put (dev);return 0 ; }else if (err) {XFRM_INC_STATS (net,LINUX_MIB_XFRMINSTATEMODEERROR );
@@ -723,9 +724,12 @@ resume_decapped: crypto_done = false; }while (!err); +rcu_read_lock (); err =xfrm_rcv_cb (skb, family, x->type->proto,0 ); -if (err) +if (err) { +rcu_read_unlock (); goto drop; + }nf_reset_ct (skb);
@@ -736,8 +740,9 @@ resume_decapped:if (skb_valid_dst (skb))skb_dst_drop (skb);if (async) -dev_put (skb->dev); +dev_put (dev);gro_cells_receive (&gro_cells, skb); +rcu_read_unlock ();return 0 ; }else { xo =xfrm_offload (skb);
@@ -745,23 +750,21 @@ resume_decapped: xfrm_gro = xo->flags &XFRM_GRO ; err = -EAFNOSUPPORT ; -rcu_read_lock (); afinfo =xfrm_state_afinfo_get_rcu (x->props.family);if (likely (afinfo)) err = afinfo->transport_finish (skb, xfrm_gro || async); -rcu_read_unlock ();if (xfrm_gro) { sp =skb_sec_path (skb);if (sp) sp->olen =0 ;if (skb_valid_dst (skb))skb_dst_drop (skb); -if (async) -dev_put (skb->dev);gro_cells_receive (&gro_cells, skb); -return err; } +if (async) +dev_put (dev); +rcu_read_unlock ();return err; }
@@ -769,7 +772,7 @@ drop_unlock:spin_unlock (&x->lock); drop:if (async) -dev_put (skb->dev); +dev_put (dev);xfrm_rcv_cb (skb, family, x && x->type ? x->type->proto : nexthdr,-1 );kfree_skb (skb);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 367/398 xfrm: save input state data before secpath resets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 3cf5cdecd99c9c186a5ea518d93bbf3045b6e3aa ]
xfrm_input() stores the current xfrm_state in the skb secpath while it continues receive-side processing. Some input paths can reset that secpath before xfrm_input() has finished dereferencing the state.
Receive callback users such as VTI and XFRM interfaces can reset the secpath. The VTI receive path does so before checking whether the packet crosses network namespaces, while the XFRM interface path does so only for cross-network-namespace packets. The XFRM_MAX_DEPTH error path can also reset the secpath before the final drop callback reports the current state's protocol.
If secpath_reset() drops the last state reference while the state is concurrently deleted, xfrm_input() can still dereference the freed state when selecting transport_finish() or reporting the drop callback protocol.
Save the state protocol on the stack while the state is still valid, and use the already saved address family for transport_finish(). A larval XFRM_STATE_ACQ state has no type, so retain nexthdr as its protocol. This preserves the existing drop-path fallback while avoiding the post-reset state dereferences without adding an extra state reference to every received packet.
--- net/xfrm/xfrm_input.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
net/xfrm/xfrm_input.c +8 -3
@@ -471,6 +471,7 @@ int xfrm_input(struct sk_buff *skb, intstruct xfrm_state *x =NULL ;xfrm_address_t *daddr;u32 mark = skb->mark; +u8 xfrm_proto = nexthdr;unsigned int family =AF_UNSPEC ;int decaps =0 ;int async =0 ;
@@ -482,6 +483,7 @@ int xfrm_input(struct sk_buff *skb, intif (encap_type <0 || (xo && (xo->flags &XFRM_GRO || encap_type ==0 || encap_type ==UDP_ENCAP_ESPINUDP ))) { x =xfrm_input_state (skb); + xfrm_proto = x->type ? x->type->proto : nexthdr;if (unlikely (x->km.state !=XFRM_STATE_VALID )) {if (x->km.state ==XFRM_STATE_ACQ )
@@ -589,11 +591,13 @@ int xfrm_input(struct sk_buff *skb, int x =xfrm_input_state_lookup (net, mark, daddr, spi, nexthdr, family);if (x ==NULL ) { + xfrm_proto = nexthdr;secpath_reset (skb);XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOSTATES );xfrm_audit_state_notfound (skb, family, spi, seq); goto drop; } + xfrm_proto = x->type ? x->type->proto : nexthdr;if (unlikely (x->dir && x->dir !=XFRM_SA_DIR_IN )) {secpath_reset (skb);
@@ -601,6 +605,7 @@ int xfrm_input(struct sk_buff *skb, intxfrm_audit_state_notfound (skb, family, spi, seq);xfrm_state_put (x); x =NULL ; + xfrm_proto = nexthdr; goto drop; }
@@ -725,7 +730,7 @@ resume_decapped: }while (!err);rcu_read_lock (); - err =xfrm_rcv_cb (skb, family, x->type->proto,0 ); + err =xfrm_rcv_cb (skb, family, xfrm_proto,0 );if (err) {rcu_read_unlock (); goto drop;
@@ -750,7 +755,7 @@ resume_decapped: xfrm_gro = xo->flags &XFRM_GRO ; err = -EAFNOSUPPORT ; - afinfo =xfrm_state_afinfo_get_rcu (x->props.family); + afinfo =xfrm_state_afinfo_get_rcu (family);if (likely (afinfo)) err = afinfo->transport_finish (skb, xfrm_gro || async);if (xfrm_gro) {
@@ -773,7 +778,7 @@ drop_unlock: drop:if (async)dev_put (dev); -xfrm_rcv_cb (skb, family, x && x->type ? x->type->proto : nexthdr,-1 ); +xfrm_rcv_cb (skb, family, xfrm_proto,-1 );kfree_skb (skb);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 368/398 mm: move vma_kernel_pagesize() from hugetlb to mm.h
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: "David Hildenbrand (Arm)" <[email protected]>
[ Upstream commit 341ffe82a7a3a1e0756b58999405b6df0c2b3e8d ]
Patch series "mm: move vma_(kernel|mmu)_pagesize() out of hugetlb.c", v2.
Looking into vma_(kernel|mmu)_pagesize(), I realized that there is one scenario where DAX would not do the right thing when the kernel is not compiled with hugetlb support.
Without hugetlb support, vma_(kernel|mmu)_pagesize() will always return PAGE_SIZE instead of using the ->pagesize() result provided by dax-device code.
Fix that by moving vma_kernel_pagesize() to core MM code, where it belongs. I don't think this is stable material, but am not 100% sure.
Also, move vma_mmu_pagesize() while at it. Remove the unnecessary hugetlb.h inclusion from KVM code.
This patch (of 4):
In the past, only hugetlb had special "vma_kernel_pagesize()" requirements, so it provided its own implementation.
In commit 05ea88608d4e ("mm, hugetlbfs: introduce ->pagesize() to vm_operations_struct") we generalized that approach by providing a vm_ops->pagesize() callback to be used by device-dax.
Once device-dax started using that callback in commit c1d53b92b95c ("device-dax: implement ->pagesize() for smaps to report MMUPageSize") it was missed that CONFIG_DEV_DAX does not depend on hugetlb support.
So building a kernel with CONFIG_DEV_DAX but without CONFIG_HUGETLBFS would not pick up that value.
Fix it by moving vma_kernel_pagesize() to mm.h, providing only a single implementation. While at it, improve the kerneldoc a bit.
Ideally, we'd move vma_mmu_pagesize() as well to the header. However, its __weak symbol might be overwritten by a PPC variant in hugetlb code. So let's leave it in there for now, as it really only matters for some hugetlb oddities.
This was found by code inspection.
Stable-dep-of: e384abeb559d ("mm/huge_memory: bypass THP tuneables for huge pfnmap mappings")
--- include/linux/hugetlb.h | 7 ------- include/linux/mm.h | 20 ++++++++++++++++++++ mm/hugetlb.c | 17 ----------------- 3 files changed, 20 insertions(+), 24 deletions(-)
include/linux/hugetlb.h +0 -7
@@ -767,8 +767,6 @@ static inline unsigned long huge_page_sireturn (unsigned long )PAGE_SIZE << h->order; } -extern unsigned long vma_kernel_pagesize (struct vm_area_struct *vma); -extern unsigned long vma_mmu_pagesize (struct vm_area_struct *vma);static inline unsigned long huge_page_mask (struct hstate *h)
@@ -1184,11 +1182,6 @@ static inline unsigned long huge_page_mareturn PAGE_MASK ; } -static inline unsigned long vma_kernel_pagesize (struct vm_area_struct *vma) -{ -return PAGE_SIZE ; -} -static inline unsigned long vma_mmu_pagesize (struct vm_area_struct *vma) {return PAGE_SIZE ;
include/linux/mm.h +20 -0
@@ -1020,6 +1020,26 @@ static inline bool vma_is_shared_maywritreturn is_shared_maywrite (vma->vm_flags); } +/** +* vma_kernel_pagesize - Default page size granularity for this VMA. +* @vma: The user mapping. +* +* The kernel page size specifies in which granularity VMA modifications +* can be performed. Folios in this VMA will be aligned to, and at least +* the size of the number of bytes returned by this function. +* +* The default kernel page size is not affected by Transparent Huge Pages +* being in effect. +* +* Return: The default page size granularity for this VMA. +*/ +static inline unsigned long vma_kernel_pagesize (struct vm_area_struct *vma) +{ +if (unlikely (vma->vm_ops && vma->vm_ops->pagesize)) +return vma->vm_ops->pagesize (vma); +return PAGE_SIZE ; +} +static inline struct vm_area_struct *vma_find (struct vma_iterator *vmi,unsigned long max) {
mm/hugetlb.c +0 -17
@@ -1027,23 +1027,6 @@ static pgoff_t vma_hugecache_offset(stru (vma->vm_pgoff >>huge_page_order (h)); } -/** -* vma_kernel_pagesize - Page size granularity for this VMA. -* @vma: The user mapping. -* -* Folios in this VMA will be aligned to, and at least the size of the -* number of bytes returned by this function. -* -* Return: The default size of the folios allocated when backing a VMA. -*/ -unsigned long vma_kernel_pagesize (struct vm_area_struct *vma) -{ -if (vma->vm_ops && vma->vm_ops->pagesize) -return vma->vm_ops->pagesize (vma); -return PAGE_SIZE ; -} -EXPORT_SYMBOL_GPL (vma_kernel_pagesize); -/* * Return the page size being used by the MMU to back a VMA. In the majority * of cases, the page size used by the kernel matches the MMU size. On
Greg Kroah-Hartman
maintainerPATCH 369/398 mm/huge_memory: bypass THP tuneables for huge pfnmap mappings
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Lorenzo Stoakes (ARM)" <[email protected]>
[ Upstream commit e384abeb559d10d6505aec053ede9368d81d4c71 ]
The sysfs THP tuneables at /sys/kernel/mm/transparent_huge_pages/ rather confusingly only control the behaviour of THP in some instances.
They are not applicable to MADV_COLLAPSE operations, nor to DAX mappings.
Long-term, THP is predicated upon compaction being able to obtain large folios to populate THP ranges.
However, vm_normal_folio() returns NULL for PFN map mappings, thus their reference count is maintained by the driver, not core mm.
As a consequence, the folios are not subject to reclaim nor compaction, so are not truly part of the THP mechanism at all.
However, since commit 5dd40721f147 ("mm: allow THP orders for PFNMAPs") introduced the ability to establish huge PFN maps, they have been subject to THP tuneables.
This is incorrect - if a huge PFN map is available (defined by vma->vm_ops->huge_fault being non-NULL for a VMA_PFNMAP_BIT VMA), then it should be mapped huge upon fault-in.
Correct this by explicitly checking for this while ensuring that smaps continues to accurately report THPeligible statistics.
While here, abstract the entire file-backed THP check in vma_can_map_huge_file(), with sensible separation of logic into helper functions.
Note that drm_gem_shmem_mmap() and panthor_gem_mmap() establish huge PFN maps of shmem folios, however they are marked unevictable in drm_gem_get_pages(), and in any case would fail the reference check in __remove_mapping() even if they weren't.
Failing to map huge PFN maps has resulted in significant real-world performance degradation, see links for details.
--- mm/huge_memory.c | 86 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 22 deletions(-)
mm/huge_memory.c +64 -22
@@ -84,7 +84,7 @@ unsigned long huge_anon_orders_madvise _unsigned long huge_anon_orders_inherit__read_mostly ;static bool anon_orders_configured__initdata ; -static inline bool file_thp_enabled (struct vm_area_struct *vma) +static inline bool file_thp_enabled (const struct vm_area_struct *vma) {struct inode *inode;
@@ -102,6 +102,67 @@ static inline bool file_thp_enabled(strureturn !inode_is_open_for_write (inode) &&S_ISREG (inode->i_mode); } +static bool vma_file_bypass_thp_tuneables (const struct vm_area_struct *vma, +enum tva_type type) +{ +const bool has_huge_fault = vma->vm_ops->huge_fault; + +/* MADV_COLLAPSE ignores tuneables. */ +if (type ==TVA_FORCED_COLLAPSE ) +return true; +/* Huge PFN mappings are uncompactable so the policy doesn't apply. */ +if ((vma->vm_flags &VM_PFNMAP ) && has_huge_fault) +return true; +return false; +} + +static bool vma_file_allow_thp_tuneables (vm_flags_t vm_flags) +{ +/* THP=always? */ +if (hugepage_global_always ()) +return true; +/* THP=madvise and marked MADV_HUGEPAGE? */ +if (hugepage_global_enabled () && (vm_flags &VM_HUGEPAGE )) +return true; +return false; +} + +static bool vma_file_check_thp_tuneables (const struct vm_area_struct *vma, +vm_flags_t vm_flags,enum tva_type type) +{ +return vma_file_bypass_thp_tuneables (vma, type) || +vma_file_allow_thp_tuneables (vm_flags); +} + +static bool vma_can_map_huge_file (const struct vm_area_struct *vma, +vm_flags_t vm_flags,enum tva_type type) +{ +const bool has_huge_fault = vma->vm_ops->huge_fault; + +/* +* Enforce THP collapse requirements as necessary. Anonymous vmas +* were already handled in thp_vma_allowable_orders(). +*/ +if (!vma_file_check_thp_tuneables (vma, vm_flags, type)) +return false; + +switch (type) { +case TVA_PAGEFAULT : +/* +* Trust that ->huge_fault() handlers know what they are doing +* in fault path. +*/ +return has_huge_fault; +case TVA_SMAPS : +if (has_huge_fault) +return true; + fallthrough; +default : +/* Only regular file is valid in collapse path. */ +return file_thp_enabled (vma); + } +} + unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, vm_flags_t vm_flags, enum tva_type type,
@@ -174,27 +235,8 @@ unsigned long __thp_vma_allowable_orders vma, vma->vm_pgoff,0 , forced_collapse); -if (!vma_is_anonymous (vma)) { -/* -* Enforce THP collapse requirements as necessary. Anonymous vmas -* were already handled in thp_vma_allowable_orders(). -*/ -if (!forced_collapse && - (!hugepage_global_enabled () || (!(vm_flags &VM_HUGEPAGE ) && - !hugepage_global_always ()))) -return 0 ; - -/* -* Trust that ->huge_fault() handlers know what they are doing -* in fault path. -*/ -if (((in_pf || smaps)) && vma->vm_ops->huge_fault) -return orders; -/* Only regular file is valid in collapse path */ -if (((!in_pf || smaps)) &&file_thp_enabled (vma)) -return orders; -return 0 ; - } +if (!vma_is_anonymous (vma)) +return vma_can_map_huge_file (vma, vm_flags, type) ? orders :0 ;if (vma_is_temporary_stack (vma))return 0 ;
Greg Kroah-Hartman
maintainerPATCH 370/398 cifs: Fix specification of function pointers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 6a86a4cc281a5cfceda7af60ea6fa506b3db7430 ]
Change the mid_receive_t, mid_callback_t and mid_handle_t function pointers to have the pointer marker in the typedef.
Stable-dep-of: c60ae98c5aa6 ("9p: Fix v9fs_issue_write() to update i_size and remote_i_size")
--- fs/smb/client/cifsglob.h | 12 ++++++------ fs/smb/client/cifsproto.h | 8 ++++---- fs/smb/client/transport.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-)
fs/smb/client/cifsglob.h +6 -6
@@ -1663,7 +1663,7 @@ static inline void cifs_stats_bytes_read* Returns zero on a successful receive, or an error. The receive state in * the TCP_Server_Info will also be updated. */ -typedef int (mid_receive_t )(struct TCP_Server_Info *server, +typedef int (*mid_receive_t )(struct TCP_Server_Info *server,struct mid_q_entry *mid);/*
@@ -1674,13 +1674,13 @@ typedef int (mid_receive_t)(struct TCP_S* - it will be called by cifsd, with no locks held * - the mid will be removed from any lists */ -typedef void (mid_callback_t )(struct mid_q_entry *mid); +typedef void (*mid_callback_t )(struct mid_q_entry *mid);/* * This is the protopyte for mid handle function. This is called once the mid * has been recognized after decryption of the message. */ -typedef int (mid_handle_t )(struct TCP_Server_Info *server, +typedef int (*mid_handle_t )(struct TCP_Server_Info *server,struct mid_q_entry *mid);/* one of these for every pending CIFS request to the server */
@@ -1698,9 +1698,9 @@ struct mid_q_entry {unsigned long when_sent;/* time when smb send finished */ unsigned long when_received;/* when demux complete (taken off wire) */ #endif -mid_receive_t *receive;/* call receive callback */ -mid_callback_t *callback;/* call completion callback */ -mid_handle_t *handle;/* call handle mid callback */ +mid_receive_t receive;/* call receive callback */ +mid_callback_t callback;/* call completion callback */ +mid_handle_t handle;/* call handle mid callback */ void *callback_data;/* general purpose pointer for callback */ struct task_struct *creator;void *resp_buf;/* pointer to received SMB header */
fs/smb/client/cifsproto.h +4 -4
@@ -97,10 +97,10 @@ extern int cifs_ipaddr_cmp(struct sockadextern bool cifs_match_ipaddr (struct sockaddr *srcaddr,struct sockaddr *rhs);extern int cifs_discard_remaining_data (struct TCP_Server_Info *server);extern int cifs_call_async (struct TCP_Server_Info *server, -struct smb_rqst *rqst, -mid_receive_t *receive,mid_callback_t *callback, -mid_handle_t *handle,void *cbdata,const int flags, -const struct cifs_credits *exist_credits); +struct smb_rqst *rqst, +mid_receive_t receive,mid_callback_t callback, +mid_handle_t handle,void *cbdata,const int flags, +const struct cifs_credits *exist_credits);extern struct TCP_Server_Info *cifs_pick_channel (struct cifs_ses *ses); extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, struct TCP_Server_Info *server,
fs/smb/client/transport.c +2 -2
@@ -659,8 +659,8 @@ int wait_for_response(struct TCP_Server_*/ int cifs_call_async (struct TCP_Server_Info *server,struct smb_rqst *rqst, -mid_receive_t *receive,mid_callback_t *callback, -mid_handle_t *handle,void *cbdata,const int flags, +mid_receive_t receive,mid_callback_t callback, +mid_handle_t handle,void *cbdata,const int flags,const struct cifs_credits *exist_credits) {int rc;
Greg Kroah-Hartman
maintainerPATCH 371/398 9p: Fix v9fs_issue_write() to update i_size and remote_i_size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit c60ae98c5aa64021751b38ab1313b19d620bf640 ]
Fix v9fs_issue_write() to update i_size and remote_i_size to the new size of the server file if we made it larger, using the start fpos and the count returned by p9_client_write() to calculate the new minimum file size.
This assumes that if the 9P server makes a short write (say it hits ENOSPC), a reduced count is returned.
Message-ID: <[email protected]>
--- fs/9p/vfs_addr.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
fs/9p/vfs_addr.c +28 -1
@@ -54,11 +54,38 @@ static void v9fs_begin_writeback(structstatic void v9fs_issue_write (struct netfs_io_subrequest *subreq) {struct p9_fid *fid = subreq->rreq->netfs_priv; +struct inode *inode = subreq->rreq->inode; +struct netfs_inode *ictx =netfs_inode (inode);int err, len; len =p9_client_write (fid, subreq->start, &subreq->io_iter, &err); -if (len >0 ) +if (len >0 ) { +unsigned long long end = subreq->start + len, i_size, remote; +bool set = false; + +spin_lock (&inode->i_lock); + +/* We can read the sizes directly as we hold i_lock. */ + i_size = inode->i_size; + remote = ictx->remote_i_size; + +if (end > i_size) { + i_size = end; + set = true; + } +if (end > remote) { + remote = end; + set = true; + } + +if (set) { +i_size_write (inode, i_size); + ictx->remote_i_size = remote; + } +spin_unlock (&inode->i_lock); +__set_bit (NETFS_SREQ_MADE_PROGRESS , &subreq->flags); + }netfs_write_subrequest_terminated (subreq, len ?: err); }
# Librecast Test Results
020/020 [ OK ] liblcrq
010/010 [ OK ] libmld
120/120 [ OK ] liblibrecast
CPU/kernel: Linux auntie 6.18.54-rc1-gef437f2f0758 #1 SMP PREEMPT_DYNAMIC Wed Sep 23 14:48:56 -00 2026 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux
Greg Kroah-Hartman
maintainerPATCH 372/398 mm/vma: correctly unaccount on mmap_prepare() failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Lorenzo Stoakes (ARM)" <[email protected]>
[ Upstream commit 6cc27d82196385fe06853319f74312a7d8019726 ]
__mmap_setup() accounts memory for relevant mappings via:
security_vm_enough_memory_mm()
-> __vm_enough_memory()
-> vm_acct_memory()
If __mmap_setup() fails, this indicates that this accounting did not take place, and thus it's appropriate for __mmap_region() to jump to abort_munmap.
However if call_mmap_prepare() fails, it also jumps there and any accounted memory is not correctly unaccounted.
Fix this by handling each error separately.
--- mm/vma.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/vma.c +4 -2
@@ -2693,10 +2693,12 @@ static unsigned long __mmap_region(struc map.check_ksm_early =can_set_ksm_flags_early (&map); error =__mmap_prepare (&map, uf); -if (!error && have_mmap_prepare) - error =call_mmap_prepare (&map);if (error) goto abort_munmap; +if (have_mmap_prepare) + error =call_mmap_prepare (&map); +if (error) + goto unacct_error;if (map.check_ksm_early)update_ksm_flags (&map);
Greg Kroah-Hartman
maintainerPATCH 373/398 wifi: mac80211: track MU-MIMO configuration on disabled interfaces
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Berg <[email protected]>
[ Upstream commit a5aa46f1ac4f53e03b9b75cbf55634131f2f8cac ]
For monitoring, userspace will try to configure the VIF sdata, while the driver may see the monitor_sdata that is created when only monitor interfaces are up. This causes the odd situation that it may not be possible to store the MU-MIMO configuration on monitor_sdata.
Fix this by storing that information on the VIF sdata and updating the monitor_sdata when available and the interface is up. Also, adjust the code that adds monitor_sdata so that it will configure MU-MIMO based on the newly added interface or one of the existing ones.
This should give a mostly consistent behaviour when configuring MU-MIMO on sniffer interfaces. Should the user configure MU-MIMO on multiple sniffer interfaces, then mac80211 will simply select one of the configurations. This behaviour should be good enough and avoids breaking user expectations in the common scenarios.
Stable-dep-of: 2b04d6556964 ("wifi: mac80211: refuse to make a monitor active when it has no queue")
--- net/mac80211/cfg.c | 47 ++++++++++++++++++++++++++++++--------------- net/mac80211/ieee80211_i.h | 3 +- net/mac80211/iface.c | 46 ++++++++++++++++++++++++++++++++++++++------ net/mac80211/util.c | 3 +- 4 files changed, 76 insertions(+), 23 deletions(-)
net/mac80211/cfg.c +32 -15
@@ -63,12 +63,14 @@ static void ieee80211_set_mu_mimo_followmemcpy (sdata->vif.bss_conf.mu_group.position, params->vht_mumimo_groups +WLAN_MEMBERSHIP_LEN ,WLAN_USER_POSITION_LEN ); -ieee80211_link_info_change_notify (sdata, &sdata->deflink, -BSS_CHANGED_MU_GROUPS ); +/* don't care about endianness - just check for 0 */ memcpy (&membership, params->vht_mumimo_groups,WLAN_MEMBERSHIP_LEN ); mu_mimo_groups = membership !=0 ; + +/* Unset following if configured explicitly */ +eth_broadcast_addr (sdata->u.mntr.mu_follow_addr); }if (params->vht_mumimo_follow_addr) {
@@ -76,16 +78,26 @@ static void ieee80211_set_mu_mimo_followis_valid_ether_addr (params->vht_mumimo_follow_addr);ether_addr_copy (sdata->u.mntr.mu_follow_addr, params->vht_mumimo_follow_addr); + +/* Unset current membership until a management frame is RXed */ +memset (sdata->vif.bss_conf.mu_group.membership,0 , +WLAN_MEMBERSHIP_LEN ); } sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow; + +/* Notify only after setting mu_mimo_owner */ +if (sdata->vif.bss_conf.mu_mimo_owner && + sdata->flags &IEEE80211_SDATA_IN_DRIVER ) +ieee80211_link_info_change_notify (sdata, &sdata->deflink, +BSS_CHANGED_MU_GROUPS ); }static int ieee80211_set_mon_options (struct ieee80211_sub_if_data *sdata,struct vif_params *params) {struct ieee80211_local *local = sdata->local; -struct ieee80211_sub_if_data *monitor_sdata; +struct ieee80211_sub_if_data *monitor_sdata =NULL ;/* check flags first */ if (params->flags &&ieee80211_sdata_running (sdata)) {
@@ -103,23 +115,28 @@ static int ieee80211_set_mon_options(strreturn -EBUSY ; } -/* also validate MU-MIMO change */ -if (ieee80211_hw_check (&local->hw,NO_VIRTUAL_MONITOR )) - monitor_sdata = sdata; -else - monitor_sdata =wiphy_dereference (local->hw.wiphy, - local->monitor_sdata); - -if (!monitor_sdata && +/* validate whether MU-MIMO can be configured */ +if (!ieee80211_hw_check (&local->hw,WANT_MONITOR_VIF ) && + !ieee80211_hw_check (&local->hw,NO_VIRTUAL_MONITOR ) && (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))return -EOPNOTSUPP ; +/* Also update dependent monitor_sdata if required */ +if (test_bit (SDATA_STATE_RUNNING , &sdata->state) && + !ieee80211_hw_check (&local->hw,NO_VIRTUAL_MONITOR )) + monitor_sdata =wiphy_dereference (local->hw.wiphy, + local->monitor_sdata); +/* apply all changes now - no failures allowed */ -if (monitor_sdata && - (ieee80211_hw_check (&local->hw,WANT_MONITOR_VIF ) || -ieee80211_hw_check (&local->hw,NO_VIRTUAL_MONITOR ))) -ieee80211_set_mu_mimo_follow (monitor_sdata, params); +if (ieee80211_hw_check (&local->hw,WANT_MONITOR_VIF ) || +ieee80211_hw_check (&local->hw,NO_VIRTUAL_MONITOR )) { +/* This is copied in when the VIF is activated */ +ieee80211_set_mu_mimo_follow (sdata, params); + +if (monitor_sdata) +ieee80211_set_mu_mimo_follow (monitor_sdata, params); + }if (params->flags) {if (ieee80211_sdata_running (sdata)) {
net/mac80211/ieee80211_i.h +2 -1
@@ -2114,7 +2114,8 @@ void ieee80211_adjust_monitor_flags(stru const int offset);int ieee80211_do_open (struct wireless_dev *wdev,bool coming_up);void ieee80211_sdata_stop (struct ieee80211_sub_if_data *sdata); -int ieee80211_add_virtual_monitor (struct ieee80211_local *local); +int ieee80211_add_virtual_monitor (struct ieee80211_local *local, +struct ieee80211_sub_if_data *creator_sdata);void ieee80211_del_virtual_monitor (struct ieee80211_local *local);bool __ieee80211_recalc_txpower (struct ieee80211_link_data *link);
net/mac80211/iface.c +40 -6
82 lines not on this page · raw message
net/mac80211/util.c +2 -1
@@ -2202,9 +2202,10 @@ int ieee80211_reconfig(struct ieee80211_ } } +/* Passing NULL means an interface is picked for configuration */ if (local->virt_monitors >0 && local->virt_monitors == local->open_count) -ieee80211_add_virtual_monitor (local); +ieee80211_add_virtual_monitor (local,NULL );if (!suspended)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 374/398 wifi: mac80211: refuse to make a monitor active when it has no queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 2b04d6556964ae9f89819b86a0a7801e39c3aae5 ]
A monitor interface only gets a TXQ if it's created active, and one can't be added later. Setting the flag on a down interface is still allowed, so the driver is handed a monitor with no queue. ath9k dereferences it:
BUG: kernel NULL pointer dereference, address: 0000000000000066 RIP: 0010:ath_tx_node_init+0x49/0x170 [ath9k] ath9k_add_interface+0x10c/0x140 [ath9k] drv_add_interface+0x54/0x250 [mac80211] ieee80211_do_open+0x32f/0x800 [mac80211]
Reached with CAP_NET_ADMIN by "iw dev X set monitor active" followed by "ip link set X up". RTNL is held, so netlink operations block behind it.
Refuse the flag when there is no queue to give.
--- net/mac80211/cfg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mac80211/cfg.c +4 -0
@@ -115,6 +115,10 @@ static int ieee80211_set_mon_options(strreturn -EBUSY ; } +/* TXQs are reserved in ieee80211_if_add() and cannot be added later */ +if ((params->flags &MONITOR_FLAG_ACTIVE ) && !sdata->vif.txq) +return -EOPNOTSUPP ; +/* validate whether MU-MIMO can be configured */ if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) && !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR) &&
Greg Kroah-Hartman
maintainerPATCH 375/398 scsi: fnic: Rename fnic_scsi_fcpio_reset()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karan Tilak Kumar <[email protected]>
[ Upstream commit 31eda39bfd468a0fbabc0179e913c0755377e3b5 ]
The function has no dependency on SCSI/FCP, so rename it to fnic_fcpio_reset() and move it to fnic_fcs.c
Stable-dep-of: 0cb1fd924126 ("scsi: fnic: Fix missed link-up when critical IRQ targets offline CPU")
--- drivers/scsi/fnic/fdls_disc.c | 4 +-- drivers/scsi/fnic/fip.c | 2 - drivers/scsi/fnic/fnic.h | 1 drivers/scsi/fnic/fnic_fcs.c | 50 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/fnic/fnic_fdls.h | 2 - drivers/scsi/fnic/fnic_scsi.c | 54 ------------------------------------------ 6 files changed, 55 insertions(+), 58 deletions(-)
drivers/scsi/fnic/fdls_disc.c +2 -2
@@ -4613,7 +4613,7 @@ void fnic_fdls_disc_start(struct fnic_ipif (!iport->usefip) {if (iport->flags &FNIC_FIRST_LINK_UP ) {spin_unlock_irqrestore (&fnic->fnic_lock, fnic->lock_flags); -fnic_scsi_fcpio_reset (iport->fnic); +fnic_fcpio_reset (iport->fnic);spin_lock_irqsave (&fnic->fnic_lock, fnic->lock_flags); iport->flags &= ~FNIC_FIRST_LINK_UP ;
@@ -5072,7 +5072,7 @@ void fnic_fdls_link_down(struct fnic_ipo iport->fabric.flags =0 ;spin_unlock_irqrestore (&fnic->fnic_lock, fnic->lock_flags); -fnic_scsi_fcpio_reset (iport->fnic); +fnic_fcpio_reset (iport->fnic);spin_lock_irqsave (&fnic->fnic_lock, fnic->lock_flags);list_for_each_entry_safe (tport, next, &iport->tport_list, links) { FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
drivers/scsi/fnic/fip.c +1 -1
@@ -737,7 +737,7 @@ void fnic_work_on_fip_timer(struct work_if (memcmp (iport->selected_fcf.fcf_mac, zmac,ETH_ALEN ) !=0 ) {if (iport->flags &FNIC_FIRST_LINK_UP ) { -fnic_scsi_fcpio_reset (iport->fnic); +fnic_fcpio_reset (iport->fnic); iport->flags &= ~FNIC_FIRST_LINK_UP ; }
drivers/scsi/fnic/fnic.h +0 -1
@@ -511,7 +511,6 @@ int fnic_host_reset(struct Scsi_Host *shvoid fnic_reset (struct Scsi_Host *shost);int fnic_issue_fc_host_lip (struct Scsi_Host *shost);void fnic_get_host_port_state (struct Scsi_Host *shost); -void fnic_scsi_fcpio_reset (struct fnic *fnic);int fnic_wq_copy_cmpl_handler (struct fnic *fnic,int copy_work_to_do,unsigned int cq_index);int fnic_wq_cmpl_handler (struct fnic *fnic,int );int fnic_flogi_reg_handler (struct fnic *fnic,u32 );
drivers/scsi/fnic/fnic_fcs.c +50 -0
53 lines not on this page · raw message
drivers/scsi/fnic/fnic_fdls.h +1 -1
@@ -410,6 +410,7 @@ void fnic_fdls_add_tport(struct fnic_ipovoid fnic_fdls_remove_tport (struct fnic_iport_s *iport,struct fnic_tport_s *tport,unsigned long flags); +void fnic_fcpio_reset (struct fnic *fnic);/* fip.c */ void fnic_fcoe_send_vlan_req (struct fnic *fnic);
@@ -422,7 +423,6 @@ void fnic_handle_fip_timer(struct timer_extern void fdls_fabric_timer_callback (struct timer_list *t);/* fnic_scsi.c */ -void fnic_scsi_fcpio_reset (struct fnic *fnic);extern void fdls_fabric_timer_callback (struct timer_list *t);void fnic_rport_exch_reset (struct fnic *fnic,u32 fcid); int fnic_fdls_register_portid(struct fnic_iport_s *iport, u32 port_id,
drivers/scsi/fnic/fnic_scsi.c +1 -53
63 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 376/398 scsi: fnic: Bump up version number
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karan Tilak Kumar <[email protected]>
[ Upstream commit 47e088c9d1a06e0f762ac7ea62ae48c9e16c4def ]
Bump up version number.
Stable-dep-of: 0cb1fd924126 ("scsi: fnic: Fix missed link-up when critical IRQ targets offline CPU")
--- drivers/scsi/fnic/fnic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/fnic/fnic.h +1 -1
@@ -30,7 +30,7 @@#define DRV_NAME "fnic"#define DRV_DESCRIPTION "Cisco FCoE HBA Driver" -#define DRV_VERSION "1.8.0.2" +#define DRV_VERSION "1.8.0.3"#define PFX DRV_NAME ": "#define DFX DRV_NAME "%d: "