6.12.114-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 310/869 netfilter: nat: use kfree_rcu to release ops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 6eda0d771f94267f73f57c94630aa47e90957915 ]
Florian Westphal says:
"Historically this is not an issue, even for normal base hooks: the data path doesn't use the original nf_hook_ops that are used to register the callbacks.
However, in v5.14 I added the ability to dump the active netfilter hooks from userspace.
This code will peek back into the nf_hook_ops that are available at the tail of the pointer-array blob used by the datapath.
The nat hooks are special, because they are called indirectly from the central nat dispatcher hook. They are currently invisible to the nfnl hook dump subsystem though.
But once that changes the nat ops structures have to be deferred too."
Update nf_nat_register_fn() to deal with partial exposition of the hooks from error path which can be also an issue for nfnetlink_hook.
--- include/linux/netfilter.h | 2 ++ net/ipv4/netfilter/iptable_nat.c | 4 ++-- net/ipv6/netfilter/ip6table_nat.c | 4 ++-- net/netfilter/nf_nat_core.c | 10 ++++++---- 4 files changed, 12 insertions(+), 8 deletions(-)
include/linux/netfilter.h +2 -0
@@ -95,6 +95,8 @@ enum nf_hook_ops_type { };struct nf_hook_ops { +struct rcu_head rcu; +/* User fills in from here down. */ nf_hookfn *hook;struct net_device *dev;
net/ipv4/netfilter/iptable_nat.c +2 -2
@@ -79,7 +79,7 @@ static int ipt_nat_register_lookups(struct net *net)while (i)nf_nat_ipv4_unregister_fn (net, &ops[--i]); -kfree (ops); +kfree_rcu (ops, rcu);return ret; } }
@@ -100,7 +100,7 @@ static void ipt_nat_unregister_lookups(struct net *net)for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv4_ops); i++)nf_nat_ipv4_unregister_fn (net, &ops[i]); -kfree (ops); +kfree_rcu (ops, rcu); }static int iptable_nat_table_init (struct net *net)
net/ipv6/netfilter/ip6table_nat.c +2 -2
@@ -81,7 +81,7 @@ static int ip6t_nat_register_lookups(struct net *net)while (i)nf_nat_ipv6_unregister_fn (net, &ops[--i]); -kfree (ops); +kfree_rcu (ops, rcu);return ret; } }
@@ -102,7 +102,7 @@ static void ip6t_nat_unregister_lookups(struct net *net)for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv6_ops); i++)nf_nat_ipv6_unregister_fn (net, &ops[i]); -kfree (ops); +kfree_rcu (ops, rcu); }static int ip6table_nat_table_init (struct net *net)
net/netfilter/nf_nat_core.c +6 -4
@@ -1247,9 +1247,11 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, ret =nf_register_net_hooks (net, nat_ops, ops_count);if (ret <0 ) {mutex_unlock (&nf_nat_proto_mutex); -for (i =0 ; i < ops_count; i++) -kfree (nat_ops[i].priv); -kfree (nat_ops); +for (i =0 ; i < ops_count; i++) { + priv = nat_ops[i].priv; +kfree_rcu (priv, rcu_head); + } +kfree_rcu (nat_ops, rcu);return ret; }
@@ -1313,7 +1315,7 @@ void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, } nat_proto_net->nat_hook_ops =NULL ; -kfree (nat_ops); +kfree_rcu (nat_ops, rcu); } unlock:mutex_unlock (&nf_nat_proto_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 311/869 ice: fix double-free of tx_buf skb
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Schmidt <[email protected]>
[ Upstream commit 1a303baa715e6b78d6a406aaf335f87ff35acfcd ]
If ice_tso() or ice_tx_csum() fail, the error path in ice_xmit_frame_ring() frees the skb, but the 'first' tx_buf still points to it and is marked as valid (ICE_TX_BUF_SKB).
'next_to_use' remains unchanged, so the potential problem will likely fix itself when the next packet is transmitted and the tx_buf gets overwritten. But if there is no next packet and the interface is brought down instead, ice_clean_tx_ring() -> ice_unmap_and_free_tx_buf() will find the tx_buf and free the skb for the second time.
The fix is to reset the tx_buf type to ICE_TX_BUF_EMPTY in the error path, so that ice_unmap_and_free_tx_buf().
Move the initialization of 'first' up, to ensure it's already valid in case we hit the linearization error path.
The bug was spotted by AI while I had it looking for something else. It also proposed an initial version of the patch.
I reproduced the bug and tested the fix by adding code to inject failures, on a build with KASAN.
I looked for similar bugs in related Intel drivers and did not find any.
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +4 -2
@@ -2344,6 +2344,9 @@ ice_xmit_frame_ring(struct sk_buff *skb, struct ice_tx_ring *tx_ring)ice_trace (xmit_frame_ring, tx_ring, skb); +/* record the location of the first descriptor for this packet */ + first = &tx_ring->tx_buf[tx_ring->next_to_use]; +if (unlikely (ipv6_hopopt_jumbo_remove (skb))) goto out_drop;
@@ -2372,8 +2375,6 @@ ice_xmit_frame_ring(struct sk_buff *skb, struct ice_tx_ring *tx_ring) offload.tx_ring = tx_ring; -/* record the location of the first descriptor for this packet */ - first = &tx_ring->tx_buf[tx_ring->next_to_use]; first->skb = skb; first->type =ICE_TX_BUF_SKB ; first->bytecount = max_t(unsigned int, skb->len, ETH_ZLEN);
@@ -2437,6 +2438,7 @@ ice_xmit_frame_ring(struct sk_buff *skb, struct ice_tx_ring *tx_ring) out_drop:ice_trace (xmit_frame_ring_drop, tx_ring, skb);dev_kfree_skb_any (skb); + first->type =ICE_TX_BUF_EMPTY ;return NETDEV_TX_OK ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 312/869 f2fs: fix data loss caused by incorrect use of nat_entry flag
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongpeng Yang <[email protected]>
[ Upstream commit 238e14eb7226f883b72caccd2d37bf5707df066b ]
Data loss can occur when fsync is performed on a newly created file (before any checkpoint has been written) concurrently with a checkpoint operation. The scenario is as follows:
create & write & fsync 'file A' write checkpoint
- f2fs_do_sync_file // inline inode
- f2fs_write_inode // inode folio is dirty
- f2fs_write_checkpoint
- f2fs_flush_merged_writes
- f2fs_sync_node_pages
- f2fs_flush_nat_entries
- f2fs_fsync_node_pages // no dirty node
- f2fs_need_inode_block_update // return false
SPO and lost 'file A'
f2fs_flush_nat_entries() sets the IS_CHECKPOINTED and HAS_LAST_FSYNC flags for the nat_entry, but this does not mean that the checkpoint has actually completed successfully. However, f2fs_need_inode_block_update() checks these flags and incorrectly assumes that the checkpoint has finished.
The root cause is that the semantics of IS_CHECKPOINTED and HAS_LAST_FSYNC are only guaranteed after the checkpoint write fully completes.
This patch modifies f2fs_need_inode_block_update() to acquire the sbi->node_write lock before reading the nat_entry flags, ensuring that once IS_CHECKPOINTED and HAS_LAST_FSYNC are observed to be set, the checkpoint operation has already completed.
--- fs/f2fs/node.c | 2 ++ 1 file changed, 2 insertions(+)
fs/f2fs/node.c +2 -0
@@ -419,6 +419,7 @@ bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino)struct nat_entry *e;bool need_update = true; +f2fs_down_read (&sbi->node_write);f2fs_down_read (&nm_i->nat_tree_lock); e =__lookup_nat_cache (nm_i, ino); if (e && get_nat_flag(e, HAS_LAST_FSYNC) &&
@@ -426,6 +427,7 @@ bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino) get_nat_flag(e, HAS_FSYNCED_INODE))) need_update = false;f2fs_up_read (&nm_i->nat_tree_lock); +f2fs_up_read (&sbi->node_write);return need_update; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 313/869 f2fs: avoid reading already updated pages during GC
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianan Huang <[email protected]>
[ Upstream commit 570e2ccc7cb35fe720106964e65060602d3d2ac4 ]
We found the following issue during fuzz testing:
page: refcount:3 mapcount:0 mapping:00000000b6e89c65 index:0x18b2dc pfn:0x161ba9 memcg:f8ffff800e269c00 aops:f2fs_meta_aops ino:2 flags: 0x52880000000080a9(locked|waiters|uptodate|lru|private|zone=1|kasantag=0x4a) raw: 52880000000080a9 fffffffec6e17588 fffffffec0ccc088 a7ffff8067063618 raw: 000000000018b2dc 0000000000000009 00000003ffffffff f8ffff800e269c00 page dumped because: VM_BUG_ON_FOLIO(folio_test_uptodate(folio)) page_owner tracks the page as allocated post_alloc_hook+0x58c/0x5ec prep_new_page+0x34/0x284 get_page_from_freelist+0x2dcc/0x2e8c __alloc_pages_noprof+0x280/0x76c __folio_alloc_noprof+0x18/0xac __filemap_get_folio+0x6bc/0xdc4 pagecache_get_page+0x3c/0x104 do_garbage_collect+0x5c78/0x77a4 f2fs_gc+0xd74/0x25f0 gc_thread_func+0xb28/0x2930 kthread+0x464/0x5d8 ret_from_fork+0x10/0x20 ------------[ cut here ]------------ kernel BUG at mm/filemap.c:1563! folio_end_read+0x140/0x168 f2fs_finish_read_bio+0x5c4/0xb80 f2fs_read_end_io+0x64c/0x708 bio_endio+0x85c/0x8c0 blk_update_request+0x690/0x127c scsi_end_request+0x9c/0xb8c scsi_io_completion+0xf0/0x250 scsi_finish_command+0x430/0x45c scsi_complete+0x178/0x6d4 blk_mq_complete_request+0xcc/0x104 scsi_done_internal+0x214/0x454 scsi_done+0x24/0x34
which is similar to the problem reported by syzbot:
https://syzkaller.appspot.com/bug?extid=3686758660f980b402dc
This case is consistent with the description in commit 9bf1a3f ("f2fs: avoid GC causing encrypted file corrupted"):
Page 1 is moved from blkaddr A to blkaddr B by move_data_block, and after being written it is marked as uptodate. Then, Page 1 is moved from blkaddr B to blkaddr C, VM_BUG_ON_FOLIO was triggered in the endio initiated by ra_data_block.
There is no need to read Page 1 again from blkaddr B, since it has already been updated. Therefore, avoid initiating I/O in this case.
--- fs/f2fs/gc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/gc.c +4 -1
@@ -1222,7 +1222,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index) .encrypted_page = NULL, .in_list = 0, }; -int err; +int err =0 ;f2fs_down_read (&F2FS_I (inode)->i_sem);if (f2fs_is_cow_file (inode)) {
@@ -1287,6 +1287,9 @@ static int ra_data_block(struct inode *inode, pgoff_t index) goto put_page; } +if (PageUptodate (fio.encrypted_page)) + goto put_encrypted_page; + err =f2fs_submit_page_bio (&fio);if (err) goto put_encrypted_page;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 314/869 greybus: raw: fix use-after-free on cdev close
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Riégel <[email protected]>
[ Upstream commit 983cc2c7efbce04ecbf6328448d895044dd6ab31 ]
This addresses a use-after-free bug when a raw bundle is disconnected but its chardev is still opened by an application. When the application releases the cdev, it causes the following panic when init on free is enabled (CONFIG_INIT_ON_FREE_DEFAULT_ON=y):
refcount_t: underflow; use-after-free.
WARNING: CPU: 0 PID: 139 at lib/refcount.c:28 refcount_warn_saturate+0xd0/0x130
...
Call Trace:
<TASK>
cdev_put+0x18/0x30
__fput+0x255/0x2a0
__x64_sys_close+0x3d/0x80
do_syscall_64+0xa4/0x290
entry_SYSCALL_64_after_hwframe+0x77/0x7fThe cdev is contained in the "gb_raw" structure, which is freed in the disconnect operation. When the cdev is released at a later time, cdev_put gets an address that points to freed memory.
To fix this use-after-free, convert the struct device from a pointer to being embedded, that makes the lifetime of the cdev and of this device the same. Then, use cdev_device_add, which guarantees that the device won't be released until all references to the cdev have been released. Finally, delegate the freeing of the structure to the device release function, instead of freeing immediately in the disconnect callback.
--- drivers/staging/greybus/raw.c | 67 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-)
drivers/staging/greybus/raw.c +33 -34
@@ -21,9 +21,8 @@ struct gb_raw {struct list_head list;int list_data;struct mutex list_lock; -dev_t dev;struct cdev cdev; -struct device *device; +struct device dev; };struct raw_data {
@@ -148,6 +147,15 @@ static int gb_raw_send(struct gb_raw *raw, u32 len, const char __user *data)return retval; } +static void raw_dev_release (struct device *dev) +{ + struct gb_raw *raw = container_of(dev, struct gb_raw, dev); + +ida_free (&minors,MINOR (raw->dev.devt)); + +kfree (raw); +} +static int gb_raw_probe (struct gb_bundle *bundle,const struct greybus_bundle_id *id) {
@@ -164,15 +172,30 @@ static int gb_raw_probe(struct gb_bundle *bundle,if (cport_desc->protocol_id !=GREYBUS_PROTOCOL_RAW )return -ENODEV ; + minor =ida_alloc (&minors,GFP_KERNEL ); +if (minor <0 ) +return minor; + raw =kzalloc (sizeof (*raw),GFP_KERNEL ); -if (!raw) +if (!raw) { +ida_free (&minors, minor);return -ENOMEM ; + } + +device_initialize (&raw->dev); + raw->dev.devt =MKDEV (raw_major, minor); + raw->dev.class = &raw_class; + raw->dev.parent = &bundle->dev; + raw->dev.release = raw_dev_release; + retval =dev_set_name (&raw->dev,"gb!raw%d" , minor); +if (retval) + goto error_put_device; connection =gb_connection_create (bundle,le16_to_cpu (cport_desc->id), gb_raw_request_handler);if (IS_ERR (connection)) { retval =PTR_ERR (connection); - goto error_free; + goto error_put_device; }INIT_LIST_HEAD (&raw->list);
@@ -181,46 +204,26 @@ static int gb_raw_probe(struct gb_bundle *bundle, raw->connection = connection;greybus_set_drvdata (bundle, raw); - minor =ida_alloc (&minors,GFP_KERNEL ); -if (minor <0 ) { - retval = minor; - goto error_connection_destroy; - } - - raw->dev =MKDEV (raw_major, minor);cdev_init (&raw->cdev, &raw_fops); retval =gb_connection_enable (connection);if (retval) - goto error_remove_ida; + goto error_connection_destroy; - retval =cdev_add (&raw->cdev, raw->dev,1 ); + retval =cdev_device_add (&raw->cdev, &raw->dev);if (retval) goto error_connection_disable; - raw->device =device_create (&raw_class, &connection->bundle->dev, - raw->dev, raw,"gb!raw%d" , minor); -if (IS_ERR (raw->device)) { - retval =PTR_ERR (raw->device); - goto error_del_cdev; - } -return 0 ; -error_del_cdev: -cdev_del (&raw->cdev); - error_connection_disable:gb_connection_disable (connection); -error_remove_ida: -ida_free (&minors, minor); - error_connection_destroy:gb_connection_destroy (connection); -error_free: -kfree (raw); +error_put_device: +put_device (&raw->dev);return retval; }
@@ -231,11 +234,8 @@ static void gb_raw_disconnect(struct gb_bundle *bundle)struct raw_data *raw_data;struct raw_data *temp; -// FIXME - handle removing a connection when the char device node is open. -device_destroy (&raw_class, raw->dev); -cdev_del (&raw->cdev); +cdev_device_del (&raw->cdev, &raw->dev);gb_connection_disable (connection); -ida_free (&minors,MINOR (raw->dev));gb_connection_destroy (connection);mutex_lock (&raw->list_lock);
@@ -244,8 +244,7 @@ static void gb_raw_disconnect(struct gb_bundle *bundle)kfree (raw_data); }mutex_unlock (&raw->list_lock); - -kfree (raw); +put_device (&raw->dev); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 315/869 net: pull headers in qdisc_pkt_len_segs_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 7fb4c19670110f052c04e1ec1d2b953b9f4f57e4 ]
Most ndo_start_xmit() methods expects headers of gso packets to be already in skb->head.
net/core/tso.c users are particularly at risk, because tso_build_hdr() does a memcpy(hdr, skb->data, hdr_len);
qdisc_pkt_len_segs_init() already does a dissection of gso packets.
Use pskb_may_pull() instead of skb_header_pointer() to make sure drivers do not have to reimplement this.
Some malicious packets could be fed, detect them so that we can drop them sooner with a new SKB_DROP_REASON_SKB_BAD_GSO drop_reason.
--- include/net/dropreason-core.h | 3 ++ net/core/dev.c | 81 +++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 31 deletions(-)
include/net/dropreason-core.h +3 -0
@@ -66,6 +66,7 @@ FN(UNHANDLED_PROTO) \ FN(SKB_CSUM) \ FN(SKB_GSO_SEG) \ + FN(SKB_BAD_GSO) \ FN(SKB_UCOPY_FAULT) \ FN(DEV_HDR) \ FN(DEV_READY) \
@@ -331,6 +332,8 @@ enum skb_drop_reason {SKB_DROP_REASON_SKB_CSUM ,/** @SKB_DROP_REASON_SKB_GSO_SEG: gso segmentation error */ SKB_DROP_REASON_SKB_GSO_SEG , +/** @SKB_DROP_REASON_SKB_BAD_GSO: malicious gso packet. */ + SKB_DROP_REASON_SKB_BAD_GSO,/** * @SKB_DROP_REASON_SKB_UCOPY_FAULT: failed to copy data from user space, * e.g., via zerocopy_sg_from_iter() or skb_orphan_frags_rx()
net/core/dev.c +50 -31
118 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 316/869 wifi: mt76: mt7925: fix potential deadlock in mt7925_roc_abort_sync
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Wang <[email protected]>
[ Upstream commit dd08ca3f092f4185ece69ce2a835c23198b1628a ]
roc_abort_sync() can deadlock with roc_work(). roc_work() holds dev->mt76.mutex, while cancel_work_sync() waits for roc_work() to finish. If the caller already owns the same mutex, both sides block and no progress is possible.
This deadlock can occur during station removal when mt76_sta_state() -> mt76_sta_remove() -> mt7925_mac_sta_remove_link() -> mt7925_mac_link_sta_remove() -> mt7925_roc_abort_sync() invokes cancel_work_sync() while roc_work() is still running and holding dev->mt76.mutex.
This avoids the mutex deadlock and preserves exactly-once work ownership.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +9 -5
@@ -473,12 +473,16 @@ void mt7925_roc_abort_sync(struct mt792x_dev *dev) {struct mt792x_phy *phy = &dev->phy; +if (!test_and_clear_bit (MT76_STATE_ROC , &phy->mt76->state)) +return ; +del_timer_sync (&phy->roc_timer); -cancel_work_sync (&phy->roc_work); -if (test_and_clear_bit (MT76_STATE_ROC , &phy->mt76->state)) -ieee80211_iterate_interfaces (mt76_hw (dev), -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7925_roc_iter, (void *)phy); + +cancel_work (&phy->roc_work); + +ieee80211_iterate_interfaces (mt76_hw (dev), +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7925_roc_iter, (void *)phy); }EXPORT_SYMBOL_GPL (mt7925_roc_abort_sync);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 317/869 wifi: mt76: Fix memory leak destroying device
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit 6b470f36616e3448d44b0ef4b1de2a3e3a31b5be ]
All MT76 rx queues have an associated page_pool even if the queue is not associated to a NAPI (e.g. WED RRO queues with WED enabled). Destroy the page_pool running mt76_dma_cleanup routine during module unload. Moreover returns pages to the page pool if WED is not enabled for WED RRO queues.
--- drivers/net/wireless/mediatek/mt76/dma.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/dma.c +5 -5
@@ -769,7 +769,11 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q)if (!buf)break ; -if (!mt76_queue_is_wed_rro (q)) +if (mtk_wed_device_active (&dev->mmio.wed) && +mt76_queue_is_wed_rro (q)) +continue ; + +if (!mt76_queue_is_wed_rro_ind (q))mt76_put_page_pool_buf (buf, false); }while (1 );
@@ -1033,10 +1037,6 @@ void mt76_dma_cleanup(struct mt76_dev *dev)mt76_for_each_q_rx (dev, i) {struct mt76_queue *q = &dev->q_rx[i]; -if (mtk_wed_device_active (&dev->mmio.wed) && -mt76_queue_is_wed_rro (q)) -continue ; -netif_napi_del (&dev->napi[i]);mt76_dma_rx_cleanup (dev, q);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 318/869 powerpc/64s: Fix unmap race with PMD migration entries
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ritesh Harjani (IBM) <[email protected]>
[ Upstream commit bbcbf045d6c778e82b47a35fc8728387708e9a3d ]
The following race is possible with migration swap entries or device-private THP entries. e.g. when move_pages is called on a PMD THP page, then there maybe an intermediate state, where PMD entry acts as a migration swap entry (pmd_present() is true). Then if an munmap happens at the same time, then this VM_BUG_ON() can happen in pmdp_huge_get_and_clear_full().
This patch fixes that.
Thread A: move_pages() syscall
add_folio_for_migration()
mmap_read_lock(mm)
folio_isolate_lru(folio)
mmap_read_unlock(mm)
do_move_pages_to_node()
migrate_pages()
try_to_migrate_one()
spin_lock(ptl)
set_pmd_migration_entry()
pmdp_invalidate() # PMD: _PAGE_INVALID | _PAGE_PTE | pfn
set_pmd_at() # PMD: migration swap entry (pmd_present=0)
spin_unlock(ptl)
[page copy phase] # <--- RACE WINDOW -->
Thread B: munmap()
mmap_write_downgrade(mm)
unmap_vmas() -> zap_pmd_range()
zap_huge_pmd()
__pmd_trans_huge_lock()
pmd_is_huge(): # !pmd_present && !pmd_none -> TRUE (swap entry)
pmd_lock() -> # spin_lock(ptl), waits for Thread A to release ptl
pmdp_huge_get_and_clear_full()
VM_BUG_ON(!pmd_present(*pmdp)) # HITS![ 287.738700][ T1867] ------------[ cut here ]------------
[ 287.743843][ T1867] kernel BUG at arch/powerpc/mm/book3s64/pgtable.c:187!
cpu 0x0: Vector: 700 (Program Check) at [c00000044037f4f0]
pc: c000000000094ca4: pmdp_huge_get_and_clear_full+0x6c/0x23c
lr: c000000000645dec: zap_huge_pmd+0xb0/0x868
sp: c00000044037f790
msr: 800000000282b033
current = 0xc0000004032c1a00
paca = 0xc000000004fe0000 irqmask: 0x03 irq_happened: 0x09
pid = 1867, comm = a.outkernel BUG at :187!
Linux version 6.19.0-12136-g14360d4f917c-dirty (powerpc64le-linux-gnu-gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #27 SMP PREEMPT Sun Feb 22 10:38:56 IST 2026 enter ? for help
[link register ] c000000000645dec zap_huge_pmd+0xb0/0x868
[c00000044037f790] c00000044037f7d0 (unreliable)
[c00000044037f7d0] c000000000645dcc zap_huge_pmd+0x90/0x868
[c00000044037f840] c0000000005724cc unmap_page_range+0x176c/0x1f40
[c00000044037fa00] c000000000572ea0 unmap_vmas+0xb0/0x1d8
[c00000044037fa90] c0000000005af254 unmap_region+0xb4/0x128
[c00000044037fb50] c0000000005af400 vms_complete_munmap_vmas+0x138/0x310
[c00000044037fbe0] c0000000005b0f1c do_vmi_align_munmap+0x1ec/0x238
[c00000044037fd30] c0000000005b3688 __vm_munmap+0x170/0x1f8
[c00000044037fdf0] c000000000587f74 sys_munmap+0x2c/0x40
[c00000044037fe10] c000000000032668 system_call_exception+0x128/0x350
[c00000044037fe50] c00000000000d05c system_call_vectored_common+0x15c/0x2ec
---- Exception: 3000 (System Call Vectored) at 0000000010064a2c
SP (7fff9b1ee9c0) is in userspace
0:mon> zh
commit a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages"), enabled migration for device-private PMD entries. Hence this is one
other path where this warning could get trigger from.
------------[ cut here ]------------ WARNING: arch/powerpc/mm/book3s64/hash_pgtable.c:199 at hash__pmd_hugepage_update+0x48/0x284, CPU#3: hmm-tests/1905 Modules linked in: test_hmm CPU: 3 UID: 0 PID: 1905 Comm: hmm-tests Tainted: G B W L N 7.0.0-rc1-01438-g7e2f0ee7581c #21 PREEMPT Tainted: [B]=BAD_PAGE, [W]=WARN, [L]=SOFTLOCKUP, [N]=TEST Hardware name: IBM pSeries (emulated by qemu) POWER10 (architected) 0x801200 0xf000006 of:SLOF,git-ee03ae pSeries NIP [c000000000096b70] hash__pmd_hugepage_update+0x48/0x284 LR [c000000000096e7c] hash__pmdp_huge_get_and_clear+0xd0/0xd4 Call Trace: [c000000604707670] [c000000004e102b8] 0xc000000004e102b8 (unreliable) [c000000604707700] [c00000000064ec3c] set_pmd_migration_entry+0x414/0x498 [c000000604707760] [c00000000063e5a4] migrate_vma_collect_pmd+0x12e8/0x16c4 [c000000604707890] [c00000000059282c] walk_pgd_range+0x7fc/0xd2c [c000000604707990] [c000000000592e40] __walk_page_range+0xe4/0x2ac [c000000604707a10] [c000000000593534] walk_page_range_mm_unsafe+0x204/0x2a4 [c000000604707ab0] [c00000000063af10] migrate_vma_setup+0x1dc/0x2e8 [c000000604707b10] [c008000006a21838] dmirror_migrate_to_system.constprop.0+0x210/0x4b0 [test_hmm] [c000000604707c30] [c008000006a245b0] dmirror_fops_unlocked_ioctl+0x454/0xa5c [test_hmm] [c000000604707d20] [c0000000006aab84] sys_ioctl+0x4ec/0x1178 [c000000604707e10] [c0000000000326a8] system_call_exception+0x128/0x350 [c000000604707e50] [c00000000000d05c] system_call_vectored_common+0x15c/0x2ec ---- interrupt: 3000 at 0x7fffbe44f50c
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 15 +++++++++++++++ arch/powerpc/mm/book3s64/pgtable.c | 13 +++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +15 -0
@@ -1304,6 +1304,21 @@ extern int pudp_test_and_clear_young(struct vm_area_struct *vma,static inline pmd_t pmdp_huge_get_and_clear (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp) { +/* +* Non-present PMDs can be migration entries or device-private THP +* entries. This can happen at 2 places: +* - When the address space is being unmapped zap_huge_pmd(), and we +* encounter non-present pmds. +* - migrate_vma_collect_huge_pmd() could calls this during migration +* of device-private pmd entries. +*/ +if (!pmd_present (*pmdp)) { +pmd_t old_pmd =READ_ONCE (*pmdp); + +pmd_clear (pmdp); +return old_pmd; + } +if (radix_enabled ())return radix__pmdp_huge_get_and_clear (mm, addr, pmdp);return hash__pmdp_huge_get_and_clear (mm, addr, pmdp);
arch/powerpc/mm/book3s64/pgtable.c +9 -4
@@ -191,16 +191,21 @@ pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmdp, int full) { pmd_t pmd; +bool was_present =pmd_present (*pmdp); +VM_BUG_ON (addr & ~HPAGE_PMD_MASK ); -VM_BUG_ON ((pmd_present (*pmdp) && !pmd_trans_huge (*pmdp) && - !pmd_devmap (*pmdp)) || !pmd_present (*pmdp)); +VM_BUG_ON (was_present && !pmd_trans_huge (*pmdp) && !pmd_devmap (*pmdp)); +/* +* Check pmdp_huge_get_and_clear() for non-present pmd case. +*/ pmd =pmdp_huge_get_and_clear (vma->vm_mm, addr, pmdp);/* * if it not a fullmm flush, then we can possibly end up converting * this PMD pte entry to a regular level 0 PTE by a parallel page fault. -* Make sure we flush the tlb in this case. +* Make sure we flush the tlb in this case. TLB flush not needed for +* non-present case. */ -if (!full) +if (was_present && !full)flush_pmd_tlb_range (vma, addr, addr +HPAGE_PMD_SIZE );return pmd; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 319/869 powerpc/pgtable-frag: Fix bad page state in pte_frag_destroy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ritesh Harjani (IBM) <[email protected]>
[ Upstream commit fda4d71651f71c44b35829d13f3c8bf920032f77 ]
powerpc uses pt_frag_refcount as a reference counter for tracking it's pte and pmd page table fragments. For PTE table, in case of Hash with 64K pagesize, we have 16 fragments of 4K size in one 64K page.
Patch series [1] "mm: free retracted page table by RCU"
added pte_free_defer() to defer the freeing of PTE tables when retract_page_tables() is called for madvise MADV_COLLAPSE on shmem range.
[1]: https://lore.kernel.org/all/[email protected]/
pte_free_defer() sets the active flag on the corresponding fragment's folio & calls pte_fragment_free(), which reduces the pt_frag_refcount. When pt_frag_refcount reaches 0 (no active fragment using the folio), it checks if the folio active flag is set, if set, it calls call_rcu to free the folio, it the active flag is unset then it calls pte_free_now().
Now, this can lead to following problem in a corner case...
[ 265.351553][ T183] BUG: Bad page state in process a.out pfn:20d62 [ 265.353555][ T183] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x20d62 [ 265.355457][ T183] flags: 0x3ffff800000100(active|node=0|zone=0|lastcpupid=0x7ffff) [ 265.358719][ T183] raw: 003ffff800000100 0000000000000000 5deadbeef0000122 0000000000000000 [ 265.360177][ T183] raw: 0000000000000000 c0000000119caf58 00000000ffffffff 0000000000000000 [ 265.361438][ T183] page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set [ 265.362572][ T183] Modules linked in: [ 265.364622][ T183] CPU: 0 UID: 0 PID: 183 Comm: a.out Not tainted 6.18.0-rc3-00141-g1ddeaaace7ff-dirty #53 VOLUNTARY [ 265.364785][ T183] Hardware name: IBM pSeries (emulated by qemu) POWER10 (architected) 0x801200 0xf000006 of:SLOF,git-ee03ae pSeries [ 265.364908][ T183] Call Trace: [ 265.364955][ T183] [c000000011e6f7c0] [c000000001cfaa18] dump_stack_lvl+0x130/0x148 (unreliable) [ 265.365202][ T183] [c000000011e6f7f0] [c000000000794758] bad_page+0xb4/0x1c8 [ 265.365384][ T183] [c000000011e6f890] [c00000000079c020] __free_frozen_pages+0x838/0xd08 [ 265.365554][ T183] [c000000011e6f980] [c0000000000a70ac] pte_frag_destroy+0x298/0x310 [ 265.365729][ T183] [c000000011e6fa30] [c0000000000aa764] arch_exit_mmap+0x34/0x218 [ 265.365912][ T183] [c000000011e6fa80] [c000000000751698] exit_mmap+0xb8/0x820 [ 265.366080][ T183] [c000000011e6fc30] [c0000000001b1258] __mmput+0x98/0x300 [ 265.366244][ T183] [c000000011e6fc80] [c0000000001c81f8] do_exit+0x470/0x1508 [ 265.366421][ T183] [c000000011e6fd70] [c0000000001c95e4] do_group_exit+0x88/0x148 [ 265.366602][ T183] [c000000011e6fdc0] [c0000000001c96ec] pid_child_should_wake+0x0/0x178 [ 265.366780][ T183] [c000000011e6fdf0] [c00000000003a270] system_call_exception+0x1b0/0x4e0 [ 265.366958][ T183] [c000000011e6fe50] [c00000000000d05c] system_call_vectored_common+0x15c/0x2ec
The bad page state error occurs when such a folio gets freed (with active flag set), from do_exit() path in parallel.
... this can happen when the pte fragment was allocated from this folio, but when all the fragments get freed, the pte_frag_refcount still had some unused fragments. Now, if this process exits, with such folio as it's cached pte_frag in mm->context, then during pte_frag_destroy(), we simply call pagetable_dtor() and pagetable_free(), meaning it doesn't clear the active flag. This, can lead to the above bug. Since we are anyway in do_exit() path, then if the refcount is 0, then I guess it should be ok to simply clear the folio active flag before calling pagetable_dtor() & pagetable_free().
--- arch/powerpc/mm/pgtable-frag.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/mm/pgtable-frag.c +1 -0
@@ -25,6 +25,7 @@ void pte_frag_destroy(void *pte_frag) count = ((unsigned long )pte_frag & ~PAGE_MASK ) >>PTE_FRAG_SIZE_SHIFT ;/* We allow PTE_FRAG_NR fragments from a PTE page */ if (atomic_sub_and_test (PTE_FRAG_NR - count, &ptdesc->pt_frag_refcount)) { +folio_clear_active (ptdesc_folio (ptdesc));pagetable_pte_dtor (ptdesc);pagetable_free (ptdesc); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 320/869 vdpa: use generic driver_override infrastructure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danilo Krummrich <[email protected]>
[ Upstream commit 85bb534ff12aab6916058897b39c748940a7a4c6 ]
When a driver is probed through __driver_attach(), the bus' match() callback is called without the device lock held, thus accessing the driver_override field without a lock, which can cause a UAF.
Fix this by using the driver-core driver_override infrastructure taking care of proper locking internally.
Note that calling match() from __driver_attach() without the device lock held is intentional. [1]
--- drivers/vdpa/vdpa.c | 48 +++++--------------------------------------- include/linux/vdpa.h | 4 ---- 2 files changed, 5 insertions(+), 47 deletions(-)
drivers/vdpa/vdpa.c +5 -43
@@ -67,57 +67,20 @@ static void vdpa_dev_remove(struct device *d)static int vdpa_dev_match (struct device *dev,const struct device_driver *drv) { -struct vdpa_device *vdev =dev_to_vdpa (dev); +int ret;/* Check override first, and if set, only use the named driver */ -if (vdev->driver_override) -return strcmp (vdev->driver_override, drv->name) ==0 ; + ret =device_match_driver_override (dev, drv); +if (ret >=0 ) +return ret;/* Currently devices must be supported by all vDPA bus drivers */ return 1 ; } -static ssize_t driver_override_store (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -struct vdpa_device *vdev =dev_to_vdpa (dev); -int ret; - - ret =driver_set_override (dev, &vdev->driver_override, buf, count); -if (ret) -return ret; - -return count; -} - -static ssize_t driver_override_show (struct device *dev, -struct device_attribute *attr,char *buf) -{ -struct vdpa_device *vdev =dev_to_vdpa (dev); -ssize_t len; - -device_lock (dev); - len =sysfs_emit (buf,"%s\n" , vdev->driver_override); -device_unlock (dev); - -return len; -} -static DEVICE_ATTR_RW (driver_override); - -static struct attribute *vdpa_dev_attrs[] = { - &dev_attr_driver_override.attr, -NULL , -}; - -static const struct attribute_group vdpa_dev_group = { - .attrs = vdpa_dev_attrs, -}; -__ATTRIBUTE_GROUPS (vdpa_dev); -static const struct bus_type vdpa_bus = { .name ="vdpa" , - .dev_groups = vdpa_dev_groups, + .driver_override = true, .match = vdpa_dev_match, .probe = vdpa_dev_probe, .remove = vdpa_dev_remove,
@@ -132,7 +95,6 @@ static void vdpa_release_dev(struct device *d) ops->free (vdev);ida_free (&vdpa_index_ida, vdev->index); -kfree (vdev->driver_override);kfree (vdev); }
include/linux/vdpa.h +0 -4
@@ -71,9 +71,6 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA -* @driver_override: driver name to force a match; do not set directly, -* because core frees it; use driver_set_override() to -* set or clear it. * @config: the configuration ops for this device. * @cf_lock: Protects get and set access to configuration layout. * @index: device index
@@ -88,7 +85,6 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; -const char *driver_override;const struct vdpa_config_ops *config;struct rw_semaphore cf_lock;/* Protects get/set config */ unsigned int index;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 321/869 staging: rtl8723bs: rtw_mlme: add bounds checks before ie_length subtraction
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salman Alghamdi <[email protected]>
[ Upstream commit 88e994c57a79f62d5338231d8d37ee8dd98baffe ]
Add guards to ensure ie_length is large enough before subtracting fixed IE offsets to prevent unsigned integer underflow.
--- drivers/staging/rtl8723bs/core/rtw_mlme.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme.c +10 -4
@@ -590,6 +590,8 @@ int rtw_is_desired_network(struct adapter *adapter, struct wlan_network *pnetwor privacy = pnetwork->network.privacy;if (check_fwstate (pmlmepriv,WIFI_UNDER_WPS )) { +if (pnetwork->network.ie_length < _FIXED_IE_LENGTH_) +return false;if (rtw_get_wps_ie (pnetwork->network.ies+_FIXED_IE_LENGTH_, pnetwork->network.ie_length-_FIXED_IE_LENGTH_,NULL , &wps_ielen))return true;else
@@ -604,11 +606,15 @@ int rtw_is_desired_network(struct adapter *adapter, struct wlan_network *pnetwor bselected = false;if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK) { - p =rtw_get_ie (pnetwork->network.ies + _BEACON_IE_OFFSET_,WLAN_EID_RSN , &ie_len, (pnetwork->network.ie_length - _BEACON_IE_OFFSET_)); -if (p && ie_len >0 ) - bselected = true; -else +if (pnetwork->network.ie_length < _BEACON_IE_OFFSET_) { bselected = false; + }else { + p =rtw_get_ie (pnetwork->network.ies + _BEACON_IE_OFFSET_,WLAN_EID_RSN , &ie_len, (pnetwork->network.ie_length - _BEACON_IE_OFFSET_)); +if (p && ie_len >0 ) + bselected = true; +else + bselected = false; + } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 322/869 sctp: validate embedded INIT chunk and address list lengths in cookie
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
[ Upstream commit 6f4c80a2a7e6d06753b89a578b710a2499a5e62b ]
sctp_unpack_cookie() only checked that the embedded INIT chunk length did not exceed the remaining cookie payload, but did not ensure that the INIT chunk is large enough to contain a complete INIT header.
A malformed COOKIE_ECHO can therefore carry a truncated INIT chunk whose length field is smaller than sizeof(struct sctp_init_chunk). Later, sctp_process_init() accesses INIT parameters unconditionally, which may lead to out-of-bounds reads.
In addition, raw_addr_list_len is not fully validated against the remaining cookie payload. When cookie authentication is disabled, an attacker can supply an oversized raw_addr_list_len and cause sctp_raw_to_bind_addrs() to read beyond the end of the cookie. The address parser also lacks sufficient bounds checks for parameter headers and lengths, allowing malformed address parameters to trigger out-of-bounds reads.
Fix this by:
- requiring the embedded INIT chunk length to be at least sizeof(struct sctp_init_chunk);
- validating that the INIT chunk and raw address list together fit within the cookie payload;
- verifying sufficient data exists for each address parameter header and payload before parsing it.
Note that sctp_verify_init() must be called after sctp_unpack_cookie() and before sctp_process_init() when cookie authentication is disabled. This will be addressed in a separate patch.
--- net/sctp/bind_addr.c | 11 ++++++++++- net/sctp/sm_make_chunk.c | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-)
net/sctp/bind_addr.c +10 -1
@@ -275,6 +275,16 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list, param = (struct sctp_paramhdr *)raw_addr_list; rawaddr = (union sctp_addr_param *)raw_addr_list; +if (addrs_len <sizeof (*param)) { + retval = -EINVAL ; + goto out_err; + } + len =ntohs (param->length); +if (addrs_len < len) { + retval = -EINVAL ; + goto out_err; + } + af =sctp_get_af_specific (param_type2af (param->type));if (unlikely (!af) || !af->from_addr_param (&addr, rawaddr,htons (port),0 )) {
@@ -291,7 +301,6 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list, goto out_err; next: - len =ntohs (param->length); addrs_len -= len; raw_addr_list += len; }
net/sctp/sm_make_chunk.c +11 -1
@@ -1750,8 +1750,9 @@ struct sctp_association *sctp_unpack_cookie(struct sk_buff *skb = chunk->skb;struct sctp_cookie *bear_cookie;__u8 *digest = ep->digest; +struct sctp_chunkhdr *ch; +unsigned int len, chlen;enum sctp_scope scope; -unsigned int len;ktime_t kt;/* Header size is static data prior to the actual cookie, including
@@ -1779,6 +1780,15 @@ struct sctp_association *sctp_unpack_cookie( cookie = chunk->subh.cookie_hdr; bear_cookie = &cookie->c; + ch = (struct sctp_chunkhdr *)(bear_cookie +1 ); + chlen =ntohs (ch->length); +if (chlen <sizeof (struct sctp_init_chunk )) + goto malformed; +if (chlen > len - fixed_size) + goto malformed; +if (bear_cookie->raw_addr_list_len > len - fixed_size - chlen) + goto malformed; +if (!sctp_sk (ep->base.sk)->hmac) goto no_hmac;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 323/869 wifi: fix leak if split 6 GHz scanning fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fedor Pchelkin <[email protected]>
[ Upstream commit e8694f7cc29287e843648d1075177b9a2000d957 ]
rdev->int_scan_req is leaked if cfg80211_scan() fails. Note that it's supposed to be released at ___cfg80211_scan_done() but this doesn't happen as rdev->scan_req is NULL at that point, too, leading to the early return from the freeing function.
unreferenced object 0xffff8881161d0800 (size 512):
comm "wpa_supplicant", pid 379, jiffies 4294749765 hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 f0 81 13 16 81 88 ff ff ................
backtrace (crc c867fdb6):
kmemleak_alloc+0x89/0x90
__kmalloc_noprof+0x2fd/0x410
cfg80211_scan+0x133/0x730
nl80211_trigger_scan+0xc69/0x1cc0
genl_family_rcv_msg_doit+0x204/0x2f0
genl_rcv_msg+0x431/0x6b0
netlink_rcv_skb+0x143/0x3f0
genl_rcv+0x27/0x40
netlink_unicast+0x4f6/0x820
netlink_sendmsg+0x797/0xce0
__sock_sendmsg+0xc4/0x160
____sys_sendmsg+0x5e4/0x890
___sys_sendmsg+0xf8/0x180
__sys_sendmsg+0x136/0x1e0
__x64_sys_sendmsg+0x76/0xc0
x64_sys_call+0x13f0/0x17d0Found by Linux Verification Center (linuxtesting.org).
--- net/wireless/scan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/wireless/scan.c +8 -1
@@ -1030,6 +1030,7 @@ int cfg80211_scan(struct cfg80211_registered_device *rdev)struct cfg80211_scan_request *request;struct cfg80211_scan_request *rdev_req = rdev->scan_req;u32 n_channels =0 , idx, i; +int err;if (!(rdev->wiphy.flags &WIPHY_FLAG_SPLIT_SCAN_6GHZ ))return rdev_scan (rdev, rdev_req);
@@ -1056,8 +1057,14 @@ int cfg80211_scan(struct cfg80211_registered_device *rdev) } rdev_req->scan_6ghz = false; + err =rdev_scan (rdev, request); +if (err) { +kfree (request); +return err; + } + rdev->int_scan_req = request; -return rdev_scan (rdev, request); +return 0 ; } void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 324/869 KVM: arm64: Take the SRCU lock for page table walks in fault injection and AT emulation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunwoo Kim <[email protected]>
[ Upstream commit f2ca45b50d4216c9cc7ffabf50d9ad1932209251 ]
walk_s1() and kvm_walk_nested_s2() expect to be called while holding kvm->srcu to guard against memslot changes. While this is generally the case, __kvm_at_s12() and __kvm_find_s1_desc_level() call into the respective walkers without taking kvm->srcu.
Fix by acquiring kvm->srcu prior to the table walk in both instances.
--- arch/arm64/kvm/at.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/at.c +2 -1
@@ -1087,7 +1087,8 @@ void __kvm_at_s12(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)/* Do the stage-2 translation */ ipa = (par &GENMASK_ULL (47 ,12 )) | (vaddr &GENMASK_ULL (11 ,0 )); out.esr =0 ; - ret =kvm_walk_nested_s2 (vcpu, ipa, &out); +scoped_guard (srcu, &vcpu->kvm->srcu) + ret = kvm_walk_nested_s2(vcpu, ipa, &out);if (ret <0 )return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 325/869 iommu/vt-d: Avoid NULL pointer dereference or refcount corruption
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenzhong Duan <[email protected]>
[ Upstream commit 79ea2feb917b05366b49d85573c9c5331f043b2c ]
Commit 60f030f7418d ("iommu/vt-d: Avoid use of NULL after WARN_ON_ONCE") fixed a NULL pointer dereference in an unlikely situation partly.
If dev_pasid is not found in the dev_pasids list, it remains NULL. However, the teardown operations are executed unconditionally, this lead to a NULL pointer dereference or refcount corruption.
If the domain was never attached to this IOMMU, info will be NULL, which would cause an immediate dereference when checking --info->refcnt.
Even if info is not NULL, decrementing the refcount without having removed a valid PASID might unbalance the count. This could lead to premature dropping of the refcount to 0, potentially causing a use-after-free for the remaining active devices sharing the domain.
Fix it by returning early if dev_pasid is NULL, before executing the teardown operations.
Issue found by AI review and suggested by Kevin Tian.
https://sashiko.dev/#/patchset/20260421031347.1408890-1-zhenzhong.duan%40intel.com
--- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +2 -2
@@ -4339,9 +4339,9 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid, }spin_unlock_irqrestore (&dmar_domain->lock, flags); -cache_tag_unassign_domain (dmar_domain, dev, pasid); -domain_detach_iommu (dmar_domain, iommu);if (!WARN_ON_ONCE (!dev_pasid)) { +cache_tag_unassign_domain (dmar_domain, dev, pasid); +domain_detach_iommu (dmar_domain, iommu);intel_iommu_debugfs_remove_dev_pasid (dev_pasid);kfree (dev_pasid); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 326/869 btrfs: only release the dirty pages io tree after successful writes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 4066c55e109475a06d18a1f127c939d551211956 ]
[WARNING]
With extra warning on dirty extent buffers at umount (aka, the next patch in the series), test case generic/388 can trigger the following warning about dirty extent buffers at unmount time:
BTRFS critical (device dm-2 state E): emergency shutdown
BTRFS error (device dm-2 state E): error while writing out transaction: -30
BTRFS warning (device dm-2 state E): Skipping commit of aborted transaction.
BTRFS error (device dm-2 state EA): Transaction 9 aborted (error -30)
BTRFS: error (device dm-2 state EA) in cleanup_transaction:2068: errno=-30 Readonly filesystem BTRFS info (device dm-2 state EA): forced readonly
BTRFS info (device dm-2 state EA): last unmount of filesystem 4fbf2e15-f941-49a0-bc7c-716315d2777c
------------[ cut here ]------------ WARNING: disk-io.c:3311 at invalidate_and_check_btree_folios+0xfd/0x1ca [btrfs], CPU#8: umount/914368 CPU: 8 UID: 0 PID: 914368 Comm: umount Tainted: G OE 7.1.0-rc1-custom+ #372 PREEMPT(full) 2de38db8d1deae71fde295430a0ff3ab98ccf596 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS unknown 02/02/2022 RIP: 0010:invalidate_and_check_btree_folios+0xfd/0x1ca [btrfs] Call Trace: <TASK> close_ctree+0x52e/0x574 [btrfs d2f0b1cd330d1287e7a9919d112eadfc0e914efd] generic_shutdown_super+0x89/0x1a0 kill_anon_super+0x16/0x40 btrfs_kill_super+0x16/0x20 [btrfs d2f0b1cd330d1287e7a9919d112eadfc0e914efd] deactivate_locked_super+0x2d/0xb0 cleanup_mnt+0xdc/0x140 task_work_run+0x5a/0xa0 exit_to_user_mode_loop+0x123/0x4b0 do_syscall_64+0x243/0x7c0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 </TASK> ---[ end trace 0000000000000000 ]--- BTRFS warning (device dm-2 state EA): unable to release extent buffer 30539776 owner 9 gen 9 refs 2 flags 0x7 BTRFS warning (device dm-2 state EA): unable to release extent buffer 30621696 owner 257 gen 9 refs 2 flags 0x7 BTRFS warning (device dm-2 state EA): unable to release extent buffer 30638080 owner 258 gen 9 refs 2 flags 0x7 BTRFS warning (device dm-2 state EA): unable to release extent buffer 30654464 owner 7 gen 9 refs 2 flags 0x7 BTRFS warning (device dm-2 state EA): unable to release extent buffer 30703616 owner 2 gen 9 refs 2 flags 0x7 BTRFS warning (device dm-2 state EA): unable to release extent buffer 30720000 owner 10 gen 9 refs 2 flags 0x7 BTRFS warning (device dm-2 state EA): unable to release extent buffer 30736384 owner 4 gen 9 refs 2 flags 0x7 BTRFS warning (device dm-2 state EA): unable to release extent buffer 30752768 owner 11 gen 9 refs 2 flags 0x7
I'm using a stripped down version, which seems to trigger the warning more reliably:
_fsstress_pid=""
workload()
{
dmesg -C
mkfs.btrfs -f -K $dev > /dev/null
echo 1 > /sys/kernel/debug/clear_warn_once
mount $dev $mnt
$fsstress -w -n 1024 -p 4 -d $mnt &
_fsstress_pid=$!
sleep 0
$godown $mnt
pkill --echo -PIPE fsstress > /dev/null
wait $_fsstress_pid
unset _fsstress_pid
umount $mnt if dmesg | grep -q "WARNING"; then
fail
fi
}
for (( i = 0; i < $runtime; i++ )); do
echo "=== $i/$runtime ==="
workload
done
[CAUSE]
Inside btrfs_write_and_wait_transaction(), we first try to write all dirty ebs, then wait for them to finish.
After that we call btrfs_extent_io_tree_release() to free all extent states from dirty_pages io tree.
However if we hit an error from btrfs_write_marked_extent(), then we still call btrfs_extent_io_tree_release() to clear that dirty_pages io tree, which may contain dirty records that we haven't yet submitted.
Furthermore, the later transaction cleanup path will utilize that dirty_pages io tree to properly cleanup those dirty ebs, but since it's already empty, no dirty ebs are properly cleaned up, thus will later trigger the warnings inside invalidate_btree_folios().
[FIX]
Normally such dirty ebs won't cause problems, as when the iput() is called on the btree inode, the dirty ebs will be forcibly written back, and since the fs is already in an error status, such writeback will not reach disk and finish immediately.
But it's still better to get rid of such dirty ebs, if we ended up with dirty ebs but the fs is not in an error status, then such writeback at iput() time will be too late, as all workers are already stopped but writeback will utilize workers, which will lead to NULL pointer dereferences.
Instead of unconditionally calling btrfs_extent_io_tree_release(), only call it if btrfs_write_and_wait_transaction() finished successfully, so that @dirty_pages extent io tree is kept untouched for transaction cleanup.
--- fs/btrfs/disk-io.c | 1 + fs/btrfs/transaction.c | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/disk-io.c +1 -0
@@ -4693,6 +4693,7 @@ static void btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info,free_extent_buffer_stale (eb); } } +extent_io_tree_release (dirty_pages); } static void btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
fs/btrfs/transaction.c +4 -5
@@ -1281,14 +1281,13 @@ static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans)blk_finish_plug (&plug); ret2 =btrfs_wait_extents (fs_info, dirty_pages); -extent_io_tree_release (&trans->transaction->dirty_pages); -if (ret)return ret; -else if (ret2) +if (ret2)return ret2; -else -return 0 ; + +extent_io_tree_release (&trans->transaction->dirty_pages); +return 0 ; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 327/869 drm/amd/display: Wrap DCN32 phantom-plane allocation in DC_RUN_WITH_PREEMPTION_ENABLED
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Gavrilov <[email protected]>
[ Upstream commit 183182235f6d53bac62c6c39014738a54a68dfa6 ]
[Why]dcn32_validate_bandwidth() wraps dcn32_internal_validate_bw() with DC_FP_START()/DC_FP_END(). In x86 non-RT, DC_FP_START takes fpregs_lock(), which disables local softirqs.
The DML1 path through dcn32_enable_phantom_plane() calls kvzalloc() to allocate ~335 KiB for dc_plane_state. This triggers the vmalloc path, which calls BUG_ON(in_interrupt()) because it's invoked within the FPU-enabled (softirq disabled) region, leading to a kernel crash.
[How]
Wrap the dc_state_create_phantom_plane() call with the DC_RUN_WITH_PREEMPTION_ENABLED() macro to allow preemption during this memory allocation.
--- .../drm/amd/display/dc/resource/dcn32/dcn32_resource.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c +7 -1
@@ -90,9 +90,14 @@#include "dml/dcn32/dcn32_fpu.h" #include "dc_state_priv.h" +#include "dc_fpu.h" #include "dml2/dml2_wrapper.h" +#if !defined(DC_RUN_WITH_PREEMPTION_ENABLED ) +#define DC_RUN_WITH_PREEMPTION_ENABLED (code) code +#endif +#define DC_LOGGER_INIT (logger)enum dcn32_clk_src_array_id {
@@ -1649,7 +1654,8 @@ static void dcn32_enable_phantom_plane(struct dc *dc,if (curr_pipe->top_pipe && curr_pipe->top_pipe->plane_state == curr_pipe->plane_state) phantom_plane = prev_phantom_plane;else - phantom_plane =dc_state_create_phantom_plane (dc, context, curr_pipe->plane_state); +DC_RUN_WITH_PREEMPTION_ENABLED (phantom_plane = +dc_state_create_phantom_plane (dc, context, curr_pipe->plane_state));if (!phantom_plane)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 328/869 net: phonet: do not BUG_ON() in pn_socket_autobind() on failed bind
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Morduan Zang <[email protected]>
[ Upstream commit 5b0c911bcdbd982f7748d11c0b39ec5808eae2de ]
syzbot reported a kernel BUG triggered from pn_socket_sendmsg() via pn_socket_autobind():
kernel BUG at net/phonet/socket.c:213!
RIP: 0010:pn_socket_autobind net/phonet/socket.c:213 [inline] RIP: 0010:pn_socket_sendmsg+0x240/0x250 net/phonet/socket.c:421 Call Trace: sock_sendmsg_nosec+0x112/0x150 net/socket.c:797 __sock_sendmsg net/socket.c:812 [inline] __sys_sendto+0x402/0x590 net/socket.c:2280 ...
pn_socket_autobind() calls pn_socket_bind() with port 0 and, on -EINVAL, assumes the socket was already bound and asserts that the port is non-zero:
err = pn_socket_bind(sock, ..., sizeof(struct sockaddr_pn));
if (err != -EINVAL)
return err;
BUG_ON(!pn_port(pn_sk(sock->sk)->sobject));
return 0; /* socket was already bound */However pn_socket_bind() also returns -EINVAL when sk->sk_state is not TCP_CLOSE, even when the socket has never been bound and pn_port() is still 0. In that case the BUG_ON() fires and panics the kernel from a user-triggerable path.
Treat the "bind returned -EINVAL but pn_port() is still 0" case as a regular error and propagate -EINVAL to the caller instead of crashing. Existing callers already translate a non-zero return from pn_socket_autobind() into -ENOBUFS/-EAGAIN, so returning -EINVAL here only changes behaviour from panic to a normal errno.
--- net/phonet/socket.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/phonet/socket.c +8 -2
@@ -208,9 +208,15 @@ static int pn_socket_autobind(struct socket *sock) sa.spn_family =AF_PHONET ; err =pn_socket_bind (sock, (struct sockaddr *)&sa,sizeof (struct sockaddr_pn )); -if (err != -EINVAL ) +/* +* pn_socket_bind() also returns -EINVAL when sk_state != TCP_CLOSE +* without a prior bind, so -EINVAL alone is not sufficient to infer +* that the socket was already bound. Only treat it as "already +* bound" when the port is non-zero; otherwise propagate the error +* instead of crashing the kernel. +*/ +if (err != -EINVAL ||unlikely (!pn_port (pn_sk (sock->sk)->sobject)))return err; -BUG_ON (!pn_port (pn_sk (sock->sk)->sobject));return 0 ;/* socket was already bound */ }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 329/869 net: mana: Guard mana_remove against double invocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Erni Sri Satya Vennela <[email protected]>
[ Upstream commit 50271d7ec95144d26808025b508f463780517d3c ]
If PM resume fails (e.g., mana_attach() returns an error), mana_probe() calls mana_remove(), which tears down the device and sets gd->gdma_context = NULL and gd->driver_data = NULL.
However, a failed resume callback does not automatically unbind the driver. When the device is eventually unbound, mana_remove() is invoked a second time. Without a NULL check, it dereferences gc->dev with gc == NULL, causing a kernel panic.
Add an early return if gdma_context or driver_data is NULL so the second invocation is harmless. Move the dev = gc->dev assignment after the guard so it cannot dereference NULL.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +6 -1
@@ -3006,11 +3006,16 @@ void mana_remove(struct gdma_dev *gd, bool suspending)struct gdma_context *gc = gd->gdma_context;struct mana_context *ac = gd->driver_data;struct mana_port_context *apc; -struct device *dev = gc->dev; +struct device *dev;struct net_device *ndev;int err;int i; +if (!gc || !ac) +return ; + + dev = gc->dev; +/* adev currently doesn't support suspending, always remove it */ if (gd->adev)remove_adev (gd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 330/869 io_uring/napi: protect concurrent io_napi_entry timeout accesses
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olivier Langlois <[email protected]>
[ Upstream commit 2f3cc8e441c9f657ff036c56baaab7dddbd0b350 ]
io_napi_entry timeout value can be updated while accessed from the poll functions.
Its concurrent accesses are wrapped with READ_ONCE()/WRITE_ONCE() macros to avoid incorrect compiler optimizations.
Stable-dep-of: df8599ee18c0 ("io_uring/napi: cap busy_poll_to 10 msec")
--- io_uring/napi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
io_uring/napi.c +2 -2
@@ -60,7 +60,7 @@ void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock)rcu_read_lock (); e =io_napi_hash_find (hash_list, napi_id);if (e) { - e->timeout = jiffies +NAPI_TIMEOUT ; +WRITE_ONCE (e->timeout, jiffies +NAPI_TIMEOUT );rcu_read_unlock ();return ; }
@@ -155,7 +155,7 @@ static bool __io_napi_do_busy_loop(struct io_ring_ctx *ctx,napi_busy_loop_rcu (e->napi_id, loop_end, loop_end_arg, ctx->napi_prefer_busy_poll,BUSY_POLL_BUDGET ); -if (time_after (jiffies, e->timeout)) +if (time_after (jiffies,READ_ONCE (e->timeout))) is_stale = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 331/869 io_uring/napi: improve __io_napi_add
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olivier Langlois <[email protected]>
[ Upstream commit a5e26f49fef9485bc4ae24666d984a6de11e058c ]
1. move the sock->sk pointer validity test outside the function to avoid the function call overhead and to make the function more more reusable
2. change its name to __io_napi_add_id to be more precise about it is doing
3. return an error code to report errors
Stable-dep-of: df8599ee18c0 ("io_uring/napi: cap busy_poll_to 10 msec")
--- io_uring/napi.c | 19 ++++++------------- io_uring/napi.h | 6 +++--- 2 files changed, 9 insertions(+), 16 deletions(-)
io_uring/napi.c +6 -13
@@ -38,22 +38,14 @@ static inline ktime_t net_to_ktime(unsigned long t)return ns_to_ktime (t <<10 ); } -void __io_napi_add (struct io_ring_ctx *ctx,struct socket *sock) +int __io_napi_add_id (struct io_ring_ctx *ctx,unsigned int napi_id) {struct hlist_head *hash_list; -unsigned int napi_id; -struct sock *sk;struct io_napi_entry *e; - sk = sock->sk; -if (!sk) -return ; - - napi_id =READ_ONCE (sk->sk_napi_id); -/* Non-NAPI IDs can be rejected. */ if (napi_id <MIN_NAPI_ID ) -return ; +return -EINVAL ; hash_list = &ctx->napi_ht[hash_min (napi_id,HASH_BITS (ctx->napi_ht))];
@@ -62,13 +54,13 @@ void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock)if (e) {WRITE_ONCE (e->timeout, jiffies +NAPI_TIMEOUT );rcu_read_unlock (); -return ; +return -EEXIST ; }rcu_read_unlock (); e =kmalloc (sizeof (*e),GFP_NOWAIT );if (!e) -return ; +return -ENOMEM ; e->napi_id = napi_id; e->timeout = jiffies +NAPI_TIMEOUT ;
@@ -77,12 +69,13 @@ void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock)if (unlikely (io_napi_hash_find (hash_list, napi_id))) {spin_unlock (&ctx->napi_lock);kfree (e); -return ; +return -EEXIST ; }hlist_add_tail_rcu (&e->node, hash_list);list_add_tail_rcu (&e->list, &ctx->napi_list);spin_unlock (&ctx->napi_lock); +return 0 ; }static void __io_napi_remove_stale (struct io_ring_ctx *ctx)
io_uring/napi.h +3 -3
@@ -15,7 +15,7 @@ void io_napi_free(struct io_ring_ctx *ctx);int io_register_napi (struct io_ring_ctx *ctx,void __user *arg);int io_unregister_napi (struct io_ring_ctx *ctx,void __user *arg); -void __io_napi_add (struct io_ring_ctx *ctx,struct socket *sock); +int __io_napi_add_id (struct io_ring_ctx *ctx,unsigned int napi_id);void __io_napi_busy_loop (struct io_ring_ctx *ctx,struct io_wait_queue *iowq);int io_napi_sqpoll_busy_poll (struct io_ring_ctx *ctx);
@@ -48,8 +48,8 @@ static inline void io_napi_add(struct io_kiocb *req)return ; sock =sock_from_file (req->file); -if (sock) - __io_napi_add(ctx, sock); +if (sock && sock->sk) + __io_napi_add_id(ctx, READ_ONCE(sock->sk->sk_napi_id)); }#else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 332/869 io_uring/napi: Use lock guards
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olivier Langlois <[email protected]>
[ Upstream commit db1e1adf6f993b1c2cef605d86eff709a8db5052 ]
Convert napi locks to use the shiny new Scope-Based Resource Management machinery.
Stable-dep-of: df8599ee18c0 ("io_uring/napi: cap busy_poll_to 10 msec")
--- io_uring/napi.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
io_uring/napi.c +21 -19
@@ -49,14 +49,13 @@ int __io_napi_add_id(struct io_ring_ctx *ctx, unsigned int napi_id) hash_list = &ctx->napi_ht[hash_min (napi_id,HASH_BITS (ctx->napi_ht))]; -rcu_read_lock (); - e =io_napi_hash_find (hash_list, napi_id); -if (e) { -WRITE_ONCE (e->timeout, jiffies +NAPI_TIMEOUT ); -rcu_read_unlock (); -return -EEXIST ; +scoped_guard (rcu) { + e =io_napi_hash_find (hash_list, napi_id); +if (e) { +WRITE_ONCE (e->timeout, jiffies +NAPI_TIMEOUT ); +return -EEXIST ; + } } -rcu_read_unlock (); e =kmalloc (sizeof (*e),GFP_NOWAIT );if (!e)
@@ -65,6 +64,10 @@ int __io_napi_add_id(struct io_ring_ctx *ctx, unsigned int napi_id) e->napi_id = napi_id; e->timeout = jiffies +NAPI_TIMEOUT ; +/* +* guard(spinlock) is not used to manually unlock it before calling +* kfree() +*/ spin_lock (&ctx->napi_lock);if (unlikely (io_napi_hash_find (hash_list, napi_id))) {spin_unlock (&ctx->napi_lock);
@@ -82,7 +85,7 @@ static void __io_napi_remove_stale(struct io_ring_ctx *ctx) {struct io_napi_entry *e; -spin_lock (&ctx->napi_lock); +guard (spinlock)(&ctx->napi_lock);/* * list_for_each_entry_safe() is not required as long as: * 1. list_del_rcu() does not reset the deleted node next pointer
@@ -96,7 +99,6 @@ static void __io_napi_remove_stale(struct io_ring_ctx *ctx)kfree_rcu (e, rcu); } } -spin_unlock (&ctx->napi_lock); }static inline void io_napi_remove_stale (struct io_ring_ctx *ctx,bool is_stale)
@@ -168,11 +170,12 @@ static void io_napi_blocking_busy_loop(struct io_ring_ctx *ctx,if (list_is_singular (&ctx->napi_list)) loop_end_arg = iowq; -rcu_read_lock (); -do { - is_stale =__io_napi_do_busy_loop (ctx, loop_end_arg); - }while (!io_napi_busy_loop_should_end (iowq, start_time) && !loop_end_arg); -rcu_read_unlock (); +scoped_guard (rcu) { +do { + is_stale =__io_napi_do_busy_loop (ctx, loop_end_arg); + }while (!io_napi_busy_loop_should_end (iowq, start_time) && + !loop_end_arg); + }io_napi_remove_stale (ctx, is_stale); }
@@ -203,13 +206,12 @@ void io_napi_free(struct io_ring_ctx *ctx) {struct io_napi_entry *e; -spin_lock (&ctx->napi_lock); +guard (spinlock)(&ctx->napi_lock);list_for_each_entry (e, &ctx->napi_list, list) {hash_del_rcu (&e->node);kfree_rcu (e, rcu); }INIT_LIST_HEAD_RCU (&ctx->napi_list); -spin_unlock (&ctx->napi_lock); }/*
@@ -305,9 +307,9 @@ int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)if (list_empty_careful (&ctx->napi_list))return 0 ; -rcu_read_lock (); - is_stale =__io_napi_do_busy_loop (ctx,NULL ); -rcu_read_unlock (); +scoped_guard (rcu) { + is_stale =__io_napi_do_busy_loop (ctx,NULL ); + }io_napi_remove_stale (ctx, is_stale);return 1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 333/869 io_uring/napi: clean up __io_napi_do_busy_loop
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olivier Langlois <[email protected]>
[ Upstream commit 71afd926f292bb8f3ca86e6c3c40123037f109c6 ]
__io_napi_do_busy_loop now requires to have loop_end in its parameters. This makes the code cleaner and also has the benefit of removing a branch since the only caller not passing NULL for loop_end_arg is also setting the value conditionally.
Stable-dep-of: df8599ee18c0 ("io_uring/napi: cap busy_poll_to 10 msec")
--- io_uring/napi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
io_uring/napi.c +8 -7
@@ -137,15 +137,12 @@ static bool io_napi_busy_loop_should_end(void *data, }static bool __io_napi_do_busy_loop (struct io_ring_ctx *ctx, +bool (*loop_end)(void *,unsigned long ),void *loop_end_arg) {struct io_napi_entry *e; -bool (*loop_end)(void *,unsigned long ) =NULL ;bool is_stale = false; -if (loop_end_arg) - loop_end = io_napi_busy_loop_should_end; -list_for_each_entry_rcu (e, &ctx->napi_list, list) {napi_busy_loop_rcu (e->napi_id, loop_end, loop_end_arg, ctx->napi_prefer_busy_poll,BUSY_POLL_BUDGET );
@@ -161,18 +158,22 @@ static void io_napi_blocking_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq) {unsigned long start_time =busy_loop_current_time (); +bool (*loop_end)(void *,unsigned long ) =NULL ;void *loop_end_arg =NULL ;bool is_stale = false;/* Singular lists use a different napi loop end check function and are * only executed once. */ -if (list_is_singular (&ctx->napi_list)) +if (list_is_singular (&ctx->napi_list)) { + loop_end = io_napi_busy_loop_should_end; loop_end_arg = iowq; + }scoped_guard (rcu) {do { - is_stale =__io_napi_do_busy_loop (ctx, loop_end_arg); + is_stale =__io_napi_do_busy_loop (ctx, loop_end, + loop_end_arg); }while (!io_napi_busy_loop_should_end (iowq, start_time) && !loop_end_arg); }
@@ -308,7 +309,7 @@ int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)return 0 ;scoped_guard (rcu) { - is_stale =__io_napi_do_busy_loop (ctx,NULL ); + is_stale =__io_napi_do_busy_loop (ctx,NULL ,NULL ); }io_napi_remove_stale (ctx, is_stale);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 334/869 io_uring/napi: cap busy_poll_to 10 msec
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
[ Upstream commit df8599ee18c0e5fe343ffe0b4c379636b8bb839a ]
Currently there's no cap on the maximum amount of time that napi is allowed to poll if no events are found, which can lead to kernel complaints on a task being stuck as there's no conditional rescheduling done within that loop.
Just cap it to 10 msec in total, that's already way above any kind of sane value that will reap any benefits, yet low enough that it's nowhere near being able to trigger preemption complaints.
--- io_uring/napi.c | 2 ++ 1 file changed, 2 insertions(+)
io_uring/napi.c +2 -0
@@ -240,6 +240,8 @@ int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)if (copy_to_user (arg, &curr,sizeof (curr)))return -EFAULT ; +/* cap NAPI at 10 msec of spin time */ + napi.busy_poll_to =min (10000 , napi.busy_poll_to);WRITE_ONCE (ctx->napi_busy_poll_dt, napi.busy_poll_to *NSEC_PER_USEC );WRITE_ONCE (ctx->napi_prefer_busy_poll, !!napi.prefer_busy_poll);WRITE_ONCE (ctx->napi_enabled, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 335/869 drm/amd/display: Fix out-of-bounds read in dp_get_eq_aux_rd_interval()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Wentland <[email protected]>
[ Upstream commit e8b4d37eba05141ee01794fc6b7f2da808cee83b ]
[Why & How]
The aux_rd_interval array in struct dc_lttpr_caps is declared with MAX_REPEATER_CNT - 1 (7) elements, indexed 0..6. However, the offset parameter passed to dp_get_eq_aux_rd_interval() can be as large as MAX_REPEATER_CNT (8) when a sink reports 8 LTTPR repeaters via DPCD. This leads to an out-of-bounds read of aux_rd_interval[7] when offset is 8.
Fix this by growing aux_rd_interval to MAX_REPEATER_CNT elements to accommodate the full range of valid repeater counts defined by the DP spec.
--- drivers/gpu/drm/amd/display/dc/dc_dp_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc_dp_types.h +1 -1
@@ -1112,7 +1112,7 @@ struct dc_lttpr_caps {union dp_main_link_channel_coding_lttpr_cap main_link_channel_coding;union dp_128b_132b_supported_lttpr_link_rates supported_128b_132b_rates;union dp_alpm_lttpr_cap alpm; -uint8_t aux_rd_interval[MAX_REPEATER_CNT -1 ]; +uint8_t aux_rd_interval[MAX_REPEATER_CNT ]; };struct dc_dongle_dfp_cap_ext {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 336/869 f2fs: fix fsck inconsistency caused by incorrect nat_entry flag usage
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongpeng Yang <[email protected]>
[ Upstream commit 019f9dda7f66e55eb94cd32e1d3fff5835f73fbc ]
f2fs_need_dentry_mark() reads nat_entry flags without mutual exclusion with the checkpoint path, which can result in an incorrect inode block marking state. The scenario is as follows:
create & write & fsync 'file A' write checkpoint
- f2fs_do_sync_file // inline inode
- f2fs_write_inode // inode folio is dirty
- f2fs_write_checkpoint
- f2fs_flush_merged_writes
- f2fs_sync_node_pages
- f2fs_fsync_node_pages // no dirty node
- f2fs_need_inode_block_update // return true
- f2fs_fsync_node_pages // inode dirtied
- f2fs_need_dentry_mark //return true
- f2fs_flush_nat_entries
- f2fs_write_checkpoint end
- __write_node_folio // inode with DENT_BIT_SHIFT set
SPO, "fsck --dry-run" find inode has already checkpointed but still with DENT_BIT_SHIFT set
The state observed by f2fs_need_dentry_mark() can differ from the state observed in __write_node_folio() after acquiring sbi->node_write. The root cause is that the semantics of IS_CHECKPOINTED and HAS_FSYNCED_INODE are only guaranteed after the checkpoint write has fully completed.
This patch moves set_dentry_mark() into __write_node_folio() and protects it with the sbi->node_write lock.
--- fs/f2fs/node.c | 3 --- 1 file changed, 3 deletions(-)
fs/f2fs/node.c +0 -3
@@ -1878,9 +1878,6 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,if (is_inode_flag_set (inode,FI_DIRTY_INODE ))f2fs_update_inode (inode, page); -if (!atomic) -set_dentry_mark (page, -f2fs_need_dentry_mark (sbi, ino)); }/* may be written by other thread */ if (!PageDirty (page))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 337/869 drm/msm: always recover the gpu
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anna Maniscalco <[email protected]>
[ Upstream commit 01a0d6cd7032e9993feea19fadb03ef9d5b488f2 ]
Previously, in case there was no more work to do, recover worker wouldn't trigger recovery and would instead rely on the gpu going to sleep and then resuming when more work is submitted.
Recover_worker will first increment the fence of the hung ring so, if there's only one job submitted to a ring and that causes an hang, it will early out.
There's no guarantee that the gpu will suspend and resume before more work is submitted and if the gpu is in a hung state it will stay in that state and probably trigger a timeout again.
Just stop checking and always recover the gpu.
Patchwork: https://patchwork.freedesktop.org/patch/704066/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/msm_gpu.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
drivers/gpu/drm/msm/msm_gpu.c +14 -16
@@ -421,25 +421,23 @@ static void recover_worker(struct kthread_work *work)msm_update_fence (ring->fctx, fence); } -if (msm_gpu_active (gpu)) { - gpu->funcs->recover (gpu); + gpu->funcs->recover (gpu); -/* retire completed submits, plus the one that hung: */ -retire_submits (gpu); +/* retire completed submits, plus the one that hung: */ +retire_submits (gpu); -/* -* Replay all remaining submits starting with highest priority -* ring -*/ -for (i =0 ; i < gpu->nr_rings; i++) { -struct msm_ringbuffer *ring = gpu->rb[i]; -unsigned long flags; +/* +* Replay all remaining submits starting with highest priority +* ring +*/ +for (i =0 ; i < gpu->nr_rings; i++) { +struct msm_ringbuffer *ring = gpu->rb[i]; +unsigned long flags; -spin_lock_irqsave (&ring->submit_lock, flags); -list_for_each_entry (submit, &ring->submits, node) - gpu->funcs->submit (gpu, submit); -spin_unlock_irqrestore (&ring->submit_lock, flags); - } +spin_lock_irqsave (&ring->submit_lock, flags); +list_for_each_entry (submit, &ring->submits, node) + gpu->funcs->submit (gpu, submit); +spin_unlock_irqrestore (&ring->submit_lock, flags); }pm_runtime_put (&gpu->pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 338/869 fbdev: omap2: fix inconsistent lock returns in omapfb_mmap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit 98cf7df6e0844f7076df1db690c1ede9d69b61ff ]
Fix the warning about inconsistent returns for '&rg->lock' in omapfb_mmap() function. The warning arises because the error path uses 'ofbi->region' while the normal path uses 'rg'.
smatch warnings:drivers/video/fbdev/omap2/omapfb/omapfb-main.c:1126 omapfb_mmap()
warn: inconsistent returns '&rg->lock'.
Stable-dep-of: 7958e67375aa ("fbdev: omap2: fix use-after-free in omapfb_mmap")
--- drivers/video/fbdev/omap2/omapfb/omapfb-main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/omap2/omapfb/omapfb-main.c +1 -1
@@ -1121,7 +1121,7 @@ static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)return 0 ; error: -omapfb_put_mem_region (ofbi->region); +omapfb_put_mem_region (rg);return r; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 339/869 fbdev: omap2: fix use-after-free in omapfb_mmap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit 7958e67375aa111522086286bba13cfc0816ce8d ]
omapfb_mmap() has a race condition with OMAPFB_SETUP_PLANE ioctl that can lead to use-after-free:
The fb_mmap() entry point holds mm_lock but not lock (fb_info->lock), while ioctl handlers like OMAPFB_SETUP_PLANE hold lock but not mm_lock. This allows concurrent execution.
In omapfb_mmap():
1. rg = omapfb_get_mem_region(ofbi->region); // Get old region ref
2. start = omapfb_get_region_paddr(ofbi); // Read from NEW region
3. len = fix->smem_len; // Read from NEW region
4. vm_iomap_memory(vma, start, len); // Map NEW region memory
5. atomic_inc(&rg->map_count); // Increment OLD region!
Concurrently, OMAPFB_SETUP_PLANE can:
- Reassign ofbi->region = new_rg
- Update fix->smem_len
- OMAPFB_SETUP_MEM then checks NEW region's map_count (0!) and frees it
This leaves userspace with a mapping to freed physical memory.
The fix is to read all required values (start, len) from the same region reference (rg) that will have its map_count incremented, preventing the region from being freed while still mapped.
--- drivers/video/fbdev/omap2/omapfb/omapfb-main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/video/fbdev/omap2/omapfb/omapfb-main.c +8 -1
@@ -1099,7 +1099,11 @@ static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma) rg =omapfb_get_mem_region (ofbi->region); - start =omapfb_get_region_paddr (ofbi); +if (ofbi->rotation_type ==OMAP_DSS_ROT_VRFB ) + start = rg->vrfb.paddr[0 ]; +else + start = rg->paddr; + len = fix->smem_len; DBG("user mmap region start %lx, len %d, off %lx\n", start, len,
@@ -1109,6 +1113,8 @@ static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma) vma->vm_ops = &mmap_user_ops; vma->vm_private_data = rg; +atomic_inc (&rg->map_count); + r =vm_iomap_memory (vma, start, len);if (r) goto error;
@@ -1121,6 +1127,7 @@ static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)return 0 ; error: +atomic_dec (&rg->map_count);omapfb_put_mem_region (rg);return r;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 340/869 f2fs: read COW data with the original inode during atomic write
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Lobanov <[email protected]>
[ Upstream commit a41075acde0124d2f8a5f563068a5d63e8ffd57b ]
When updating an atomic-write file, f2fs_write_begin() may read the previously written data back from the COW inode:prepare_atomic_write_begin() locates the block in the COW inode and sets use_cow, and the read bio is then built with the COW inode:
f2fs_submit_page_read(use_cow ? F2FS_I(inode)->cow_inode : inode, ...);
and f2fs_grab_read_bio() decides whether to schedule fs-layer decryption (STEP_DECRYPT) for the bio based on that inode via fscrypt_inode_uses_fs_layer_crypto().
However, the folio being filled belongs to the original inode (folio->mapping->host == inode), and the data stored in the COW block was encrypted (or left as plaintext) using the original inode's context, not the COW inode's -- see f2fs_encrypt_one_page(), which keys off fio->page->mapping->host. fscrypt_decrypt_pagecache_blocks() likewise operates on folio->mapping->host.
The COW inode is created as a tmpfile in the parent directory and inherits its encryption policy from there. With test_dummy_encryption the newly created COW inode gets the dummy policy and becomes encrypted, while a pre-existing regular file -- created before the policy applied, e.g. already present in the on-disk image -- stays unencrypted. The read path then sets STEP_DECRYPT based on the encrypted COW inode and calls fscrypt_decrypt_pagecache_blocks() on a folio whose host (the unencrypted original inode) has a NULL ->i_crypt_info, dereferencing it:
Oops: general protection fault, probably for non-canonical address ... KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:fscrypt_decrypt_pagecache_blocks+0xa0/0x310 Workqueue: f2fs_post_read_wq f2fs_post_read_work Call Trace: fscrypt_decrypt_bio+0x1eb/0x340 f2fs_post_read_work+0xba/0x140 process_one_work+0x91c/0x1a40 worker_thread+0x677/0xe90 kthread+0x2bc/0x3a0
The COW inode is only needed to locate the on-disk block, and that block address is already resolved into @blkaddr by prepare_atomic_write_begin() via __find_data_block(cow_inode, ...); f2fs_submit_page_read() then reads from that physical @blkaddr directly, so the inode argument only selects the post-read crypto context, not which block is fetched. Reading with @inode therefore returns the same (latest, not-yet-committed) COW data, while making both the fs-layer decryption decision and the inline crypto path use the correct (original inode's) key.
With the COW inode no longer used at the read site, the use_cow flag has no remaining consumer; drop it from f2fs_write_begin() and prepare_atomic_write_begin().
--- fs/f2fs/data.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
fs/f2fs/data.c +16 -11
@@ -3593,7 +3593,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,static int prepare_atomic_write_begin (struct f2fs_sb_info *sbi,struct folio *folio,loff_t pos,unsigned int len, -block_t *blk_addr,bool *node_changed,bool *use_cow) +block_t *blk_addr,bool *node_changed) {struct inode *inode = folio->mapping->host;struct inode *cow_inode =F2FS_I (inode)->cow_inode;
@@ -3608,14 +3608,14 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,/* Look for the block in COW inode first */ err =__find_data_block (cow_inode, index, blk_addr); -if (err) { +if (err)return err; - }else if (__is_valid_data_blkaddr (*blk_addr)) { - *use_cow = true; + +if (__is_valid_data_blkaddr (*blk_addr))return 0 ; - }else if (*blk_addr ==NEW_ADDR ) { + +if (*blk_addr ==NEW_ADDR ) cow_has_reserved_block = true; - }if (is_inode_flag_set (inode,FI_ATOMIC_REPLACE )) goto reserve_block;
@@ -3648,7 +3648,6 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,struct folio *folio;pgoff_t index = pos >>PAGE_SHIFT ;bool need_balance = false; -bool use_cow = false;block_t blkaddr =NULL_ADDR ;int err =0 ;
@@ -3710,7 +3709,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,if (f2fs_is_atomic_file (inode)) err =prepare_atomic_write_begin (sbi, folio, pos, len, - &blkaddr, &need_balance, &use_cow); + &blkaddr, &need_balance);else err =prepare_write_begin (sbi, folio, pos, len, &blkaddr, &need_balance);
@@ -3750,9 +3749,15 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, err = -EFSCORRUPTED ; goto put_folio; } - err =f2fs_submit_page_read (use_cow ? -F2FS_I (inode)->cow_inode : inode, - folio, blkaddr,0 , true); +/* +* Although the block may be stored in the COW inode, the folio +* belongs to @inode and its data was encrypted (or not) using +* @inode's context (see f2fs_encrypt_one_page()). Read with +* @inode so the post-read decryption decision matches the +* folio's owner; otherwise an unencrypted @inode whose COW inode +* is encrypted hits a NULL ->i_crypt_info on decryption. +*/ + err =f2fs_submit_page_read (inode, folio, blkaddr,0 , true);if (err) goto put_folio;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 341/869 gcov: use atomic counter updates to fix concurrent access crashes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Khorenko <[email protected]>
[ Upstream commit 56cb9b7d96b28a1173a510ab25354b6599ad3a33 ]
GCC's GCOV instrumentation can merge global branch counters with loop induction variables as an optimization. In inflate_fast(), the inner copy loops get transformed so that the GCOV counter value is loaded multiple times to compute the loop base address, start index, and end bound. Since GCOV counters are global (not per-CPU), concurrent execution on different CPUs causes the counter to change between loads, producing inconsistent values and out-of-bounds memory writes.
The crash manifests during IPComp (IP Payload Compression) processing when inflate_fast() runs concurrently on multiple CPUs:
BUG: unable to handle page fault for address: ffffd0a3c0902ffa RIP: inflate_fast+1431 Call Trace: zlib_inflate __deflate_decompress crypto_comp_decompress ipcomp_decompress [xfrm_ipcomp] ipcomp_input [xfrm_ipcomp] xfrm_input
At the crash point, the compiler generated three loads from the same global GCOV counter (__gcov0.inflate_fast+216) to compute base, start, and end for an indexed loop. Another CPU modified the counter between loads, making the values inconsistent - the write went 3.4 MB past a 65 KB buffer.
Add -fprofile-update=prefer-atomic to CFLAGS_GCOV at the global level in the top-level Makefile, guarded by a try-run compile test. The test compiles a minimal program with and without -fprofile-update=prefer-atomic using the full KBUILD_CFLAGS, then compares undefined symbols in the resulting object files. If prefer-atomic introduces new undefined references (such as __atomic_fetch_add_8 on i386 or __aarch64_ldadd8_relax on arm64 with outline-atomics), the flag is not added -- the kernel does not link against libatomic.
On architectures where GCC inlines 64-bit atomic counter updates (x86_64, s390, ...) the test passes and the flag is enabled, preventing the compiler from merging counters with loop induction variables and fixing the observed concurrent-access crash.
On architectures where the flag would introduce libatomic dependencies, it is silently omitted and behaviour is no worse than before this patch.
Move the CFLAGS_GCOV block from its original position (before the arch Makefile include) to after the core KBUILD_CFLAGS assignments but before the scripts/Makefile.gcc-plugins include. This placement ensures the try-run test sees arch-specific flags (-m32, -march=, -mno-outline-atomics) while avoiding GCC plugin flags (-fplugin=) that would break the test on clean builds when plugin shared objects do not yet exist.
--- Makefile | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
Makefile +21 -6
@@ -753,12 +753,6 @@ endif # KBUILD_EXTMOD # Defaults to vmlinux, but the arch makefile usually adds further targets all: vmlinux -CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -ifdef CONFIG_CC_IS_GCC -CFLAGS_GCOV += -fno-tree-loop-im -endif -export CFLAGS_GCOV - # The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later. ifdef CONFIG_FUNCTION_TRACER CC_FLAGS_FTRACE := -pg
@@ -1027,6 +1021,27 @@ KBUILD_CFLAGS += -fno-builtin-wcslen # Ensure compilers do not transform certain loops into calls to wcslen() KBUILD_CFLAGS += -fno-builtin-wcslen +CFLAGS_GCOV := -fprofile-arcs -ftest-coverage +ifdef CONFIG_CC_IS_GCC +CFLAGS_GCOV += -fno-tree-loop-im +# Use atomic counter updates to avoid concurrent-access crashes in GCOV. +# Only enable if -fprofile-update=prefer-atomic does not introduce new +# undefined symbols (e.g. libatomic calls that the kernel cannot link). +CFLAGS_GCOV += $(call try-run,\ + echo 'long long x; void f(void){x++;}' | \ + $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \ + -ftest-coverage -x c - -c -o "$$TMP.base" && \ + echo 'long long x; void f(void){x++;}' | \ + $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \ + -ftest-coverage -fprofile-update=prefer-atomic \ + -x c - -c -o "$$TMP" && \ + $(NM) "$$TMP.base" | grep ' U ' > "$$TMP.ubase" || true ; \ + $(NM) "$$TMP" | grep ' U ' > "$$TMP.utest" || true ; \ + cmp -s "$$TMP.ubase" "$$TMP.utest",\ + -fprofile-update=prefer-atomic) +endif +export CFLAGS_GCOV + # change __FILE__ to the relative path from the srctree KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 342/869 wifi: mt76: add wcid publish check in mt76_sta_add
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiajia Liu <[email protected]>
[ Upstream commit 20b126920a259df4d7dcae19fcfe2c57a74d6b2e ]
Since mt7925_mac_sta_add publishes wcid, add publish check in mt76_sta_add to avoid reinitializing the wcid->poll_list.
Found dev->sta_poll_list corruption when using mt7925 and 7.1-rc4. According to the corruption information, prev->next was changed to itself.
wlan0: disconnect from AP 90:fb:5d:94:8b:e3 for new auth to 90:fb:5d:94:8b:e2
wlan0: authenticate with 90:fb:5d:94:8b:e2 (local address=84:9e:56:9c:7e:6b)
wlan0: send auth to 90:fb:5d:94:8b:e2 (try 1/3)
slab kmalloc-8k start ffff8c80958a6000 pointer offset 4160 size 8192list_add corruption. prev->next should be next (ffff8c808a7488f8), but was ffff8c80958a7040. (prev=ffff8c80958a7040).
mt76_wcid_add_poll+0x95/0xd0 [mt76] mt7925_mac_add_txs.part.0+0xa5/0xe0 [mt7925_common] mt7925_rx_check+0xa7/0xc0 [mt7925_common] mt76_dma_rx_poll+0x50d/0x790 [mt76] mt792x_poll_rx+0x52/0xe0 [mt792x_lib]
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +16 -6
@@ -1486,6 +1486,7 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif, {struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;struct mt76_dev *dev = phy->dev; +struct mt76_wcid *published;int ret;int i;
@@ -1505,13 +1506,22 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif, mtxq->wcid = wcid->idx; } -ewma_signal_init (&wcid->rssi); -if (phy->band_idx ==MT_BAND1 ) -mt76_wcid_mask_set (dev->wcid_phy_mask, wcid->idx); - wcid->phy_idx = phy->band_idx; -rcu_assign_pointer (dev->wcid[wcid->idx], wcid); + published =rcu_dereference_protected (dev->wcid[wcid->idx], +lockdep_is_held (&dev->mutex)); +if (published != wcid) { +WARN_ON_ONCE (published); +ewma_signal_init (&wcid->rssi); +if (phy->band_idx ==MT_BAND1 ) +mt76_wcid_mask_set (dev->wcid_phy_mask, wcid->idx); + wcid->phy_idx = phy->band_idx; +rcu_assign_pointer (dev->wcid[wcid->idx], wcid); +mt76_wcid_init (wcid); + }else { +if (phy->band_idx ==MT_BAND1 ) +mt76_wcid_mask_set (dev->wcid_phy_mask, wcid->idx); + wcid->phy_idx = phy->band_idx; + } -mt76_wcid_init (wcid); out:mutex_unlock (&dev->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 343/869 drm/amdgpu/vcn: set no_user_fence for VCN v4.0 enc ring
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yinjie Yao <[email protected]>
[ Upstream commit 51f694221047c84fa185be98210eb2c354ffb8c6 ]
VCN encoder and decoder rings do not support 64-bit user fence writes, reject CS submissions with user fences.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -0
@@ -1926,6 +1926,7 @@ static struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = { .type = AMDGPU_RING_TYPE_VCN_ENC, .align_mask = 0x3f, .nop = VCN_ENC_CMD_NO_OP, + .no_user_fence = true, .extra_dw = sizeof(struct amdgpu_vcn_rb_metadata), .get_rptr = vcn_v4_0_unified_ring_get_rptr, .get_wptr = vcn_v4_0_unified_ring_get_wptr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 344/869 net: airoha: Do not read uninitialized fragment address in airoha_dev_xmit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit bde34e84edc8b5571fbde7e941e175a4293ee1eb ]
The transmit loop in airoha_dev_xmit() reads fragment address and length during its final iteration, when the loop index equals skb_shinfo(skb)->nr_frags, at which point the fragment data is uninitialized. While these values are never consumed, the read itself is unsafe and may trigger a page fault. Fix this by avoiding the fragment read on the last iteration.
Additionally, move the skb pointer from the first to the last used packet descriptor, so that airoha_qdma_tx_napi_poll() defers freeing the skb until the final descriptor is processed.
--- drivers/net/ethernet/airoha/airoha_eth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +4 -1
@@ -2592,10 +2592,13 @@ static netdev_tx_t airoha_dev_xmit(struct sk_buff *skb,WRITE_ONCE (desc->msg1,cpu_to_le32 (msg1));WRITE_ONCE (desc->msg2,cpu_to_le32 (0xffff )); - e->skb = i ?NULL : skb; + e->skb = i == nr_frags -1 ? skb :NULL ; e->dma_addr = addr; e->dma_len = len; +if (i == nr_frags -1 ) +continue ; + data =skb_frag_address (frag); len =skb_frag_size (frag); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 345/869 net: airoha: Add missing bits in airoha_qdma_cleanup_tx_queue()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit 3309965fe44c00fd65af7cef5016e9e782c021a7 ]
Similar to airoha_qdma_cleanup_rx_queue(), reset DMA TX descriptors in airoha_qdma_cleanup_tx_queue routine. Moreover, reset TX_DMA_IDX to TX_CPU_IDX to notify the NIC the QDMA TX ring is empty.
--- drivers/net/ethernet/airoha/airoha_eth.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +21 -1
@@ -1901,20 +1901,40 @@ static int airoha_qdma_init_tx(struct airoha_qdma *qdma)static void airoha_qdma_cleanup_tx_queue (struct airoha_queue *q) { -struct airoha_eth *eth = q->qdma->eth; +struct airoha_qdma *qdma = q->qdma; +struct airoha_eth *eth = qdma->eth; +int qid = q - &qdma->q_tx[0 ];spin_lock_bh (&q->lock);while (q->queued) {struct airoha_queue_entry *e = &q->entry[q->tail]; +struct airoha_qdma_desc *desc = &q->desc[q->tail];dma_unmap_single (eth->dev, e->dma_addr, e->dma_len,DMA_TO_DEVICE );dev_kfree_skb_any (e->skb); e->skb =NULL ; +/* Reset DMA descriptor */ +WRITE_ONCE (desc->ctrl,0 ); +WRITE_ONCE (desc->addr,0 ); +WRITE_ONCE (desc->data,0 ); +WRITE_ONCE (desc->msg0,0 ); +WRITE_ONCE (desc->msg1,0 ); +WRITE_ONCE (desc->msg2,0 ); + q->tail = (q->tail +1 ) % q->ndesc; q->queued--; } + +/* Set TX_DMA_IDX to TX_CPU_IDX to notify the hw the QDMA TX ring is +* empty. +*/ +airoha_qdma_rmw (qdma,REG_TX_CPU_IDX (qid),TX_RING_CPU_IDX_MASK , +FIELD_PREP (TX_RING_CPU_IDX_MASK , q->head)); +airoha_qdma_rmw (qdma,REG_TX_DMA_IDX (qid),TX_RING_DMA_IDX_MASK , +FIELD_PREP (TX_RING_DMA_IDX_MASK , q->head)); +spin_unlock_bh (&q->lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 346/869 drm/amdgpu: fix amdgpu_hmm_range_get_pages
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian König <[email protected]>
[ Upstream commit 962d684b5dc0741dcd93485d41b450de402d5592 ]
The notifier sequence must only be read once or otherwise we could work with invalid pages.
While at it also fix the coding style, e.g. drop the pre-initialized return value and use the common define for 2G range.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +8 -8
@@ -51,8 +51,6 @@#include "amdgpu_amdkfd.h" #include "amdgpu_hmm.h" -#define MAX_WALK_BYTE (2UL << 30) -/** * amdgpu_hmm_invalidate_gfx - callback to notify about mm change *
@@ -170,12 +168,14 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, void *owner, struct page **pages, struct hmm_range **phmm_range) { + const u64 max_bytes = SZ_2G; +struct hmm_range *hmm_range; -unsigned long end;unsigned long timeout; -unsigned long i;unsigned long *pfns; -int r =0 ; +unsigned long end; +unsigned long i; +int r; hmm_range =kzalloc (sizeof (*hmm_range),GFP_KERNEL );if (unlikely (!hmm_range))
@@ -196,8 +196,9 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, end = start + npages *PAGE_SIZE ; hmm_range->dev_private_owner = owner; + hmm_range->notifier_seq =mmu_interval_read_begin (notifier); do { - hmm_range->end = min(hmm_range->start + MAX_WALK_BYTE, end); + hmm_range->end = min(hmm_range->start + max_bytes, end); pr_debug("hmm range: start = 0x%lx, end = 0x%lx", hmm_range->start, hmm_range->end);
@@ -205,7 +206,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, timeout = jiffies +msecs_to_jiffies (HMM_RANGE_DEFAULT_TIMEOUT ); retry: - hmm_range->notifier_seq =mmu_interval_read_begin (notifier); r =hmm_range_fault (hmm_range);if (unlikely (r)) {if (r == -EBUSY && !time_after (jiffies, timeout))
@@ -215,7 +215,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,if (hmm_range->end == end)break ; - hmm_range->hmm_pfns +=MAX_WALK_BYTE >>PAGE_SHIFT ; + hmm_range->hmm_pfns += max_bytes >>PAGE_SHIFT ; hmm_range->start = hmm_range->end; }while (hmm_range->end < end);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 347/869 net/handshake: hand off the pinned file reference to accept_doit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit f4251190e58b209999c1ba9e6d2976136a1be055 ]
handshake_req_next() removes the request from the per-net pending list and drops hn_lock before handshake_nl_accept_doit() reads req->hr_sk->sk_socket and dereferences sock->file (once in FD_PREPARE() and again in get_file()). In that window a consumer running tls_handshake_cancel() followed by sockfd_put() (svc_sock_free) or __fput_sync() (xs_reset_transport) releases sock->file. sock_release() then runs sock_orphan(), zeroing sk_socket, and frees the struct socket. The accept-side code either reads NULL through sk_socket or chases freed memory.
The submit-side sock_hold() does not prevent this. sk_refcnt protects struct sock, but struct socket and sock->file are independently refcounted via the file descriptor the consumer owns. Pinning sk leaves sock and sock->file unprotected.
Retarget the accept-side dereferences at req->hr_file, which was pinned at submit time, instead of req->hr_sk->sk_socket->file. Pinning on its own is not sufficient: a consumer that cancels between handshake_req_next() returning and accept_doit reaching FD_PREPARE() takes the !remove_pending() branch in handshake_req_cancel() and drops hr_file before the accept side takes its own reference. Hand off an additional file reference inside handshake_req_next(), under hn_lock, so the accept side operates on a reference that no concurrent handshake_req_cancel() can revoke. FD_PREPARE() consumes that handed-off reference, either by transferring it to the new fd in fd_publish() or by dropping it in the cleanup destructor on error; the explicit get_file() that previously balanced FD_PREPARE() is therefore redundant and goes away.
Update handshake_req_cancel_test2 and _test3 to simulate the FD_PREPARE() consumption with an fput() so the kunit file-count assertions stay balanced.
--- net/handshake/handshake-test.c | 8 ++++++++ net/handshake/netlink.c | 6 +++--- net/handshake/request.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-)
net/handshake/handshake-test.c +8 -0
@@ -375,6 +375,10 @@ static void handshake_req_cancel_test2(struct kunit *test)/* Pretend to accept this request */ next =handshake_req_next (hn,HANDSHAKE_HANDLER_CLASS_TLSHD );KUNIT_ASSERT_PTR_EQ (test, req, next); +/* Simulate FD_PREPARE() consuming the file reference handed +* off by handshake_req_next(); see handshake_nl_accept_doit(). +*/ +fput (filp);/* Act */ result =handshake_req_cancel (sock->sk);
@@ -417,6 +421,10 @@ static void handshake_req_cancel_test3(struct kunit *test)/* Pretend to accept this request */ next =handshake_req_next (hn,HANDSHAKE_HANDLER_CLASS_TLSHD );KUNIT_ASSERT_PTR_EQ (test, req, next); +/* Simulate FD_PREPARE() consuming the file reference handed +* off by handshake_req_next(); see handshake_nl_accept_doit(). +*/ +fput (filp);/* Pretend to complete this request */ handshake_complete (next, -ETIMEDOUT ,NULL );
net/handshake/netlink.c +3 -3
@@ -92,7 +92,6 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)struct net *net =sock_net (skb->sk);struct handshake_net *hn =handshake_pernet (net);struct handshake_req *req =NULL ; -struct socket *sock;int class, fd, err; err = -EOPNOTSUPP ;
@@ -109,9 +108,9 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)if (!req) goto out_status; - sock = req->hr_sk->sk_socket; fd =get_unused_fd_flags (O_CLOEXEC );if (fd <0 ) { +fput (req->hr_file);/* drop ref from handshake_req_next() */ err = fd; goto out_complete; }
@@ -119,10 +118,11 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info) err = req->hr_proto->hp_accept (req, info, fd);if (err) {put_unused_fd (fd); +fput (req->hr_file);/* drop ref from handshake_req_next() */ goto out_complete; } -fd_install (fd,get_file (sock->file)); +fd_install (fd, req->hr_file);trace_handshake_cmd_accept (net, req, req->hr_sk, fd);return 0 ;
net/handshake/request.c +18 -0
@@ -181,6 +181,17 @@ static bool remove_pending(struct handshake_net *hn, struct handshake_req *req)return ret; } +/** +* handshake_req_next - Return the next queued handshake request +* @hn: per-net handshake state +* @class: handler class to match +* +* On a non-NULL return, the caller owns an extra reference +* on @req->hr_file. FD_PREPARE() consumes it on success; on +* the FD_PREPARE() failure path the caller must fput() it. +* +* Return: pointer to a removed handshake_req, or NULL. +*/ struct handshake_req *handshake_req_next (struct handshake_net *hn,int class) {struct handshake_req *req, *pos;
@@ -191,6 +202,13 @@ struct handshake_req *handshake_req_next(struct handshake_net *hn, int class)if (pos->hr_proto->hp_handler_class != class)continue ;__remove_pending_locked (hn, pos); +/* Hand off a file reference to the accept side under +* hn_lock. A concurrent handshake_req_cancel() can drop +* hr_file before accept reaches FD_PREPARE(); this extra +* reference keeps the file alive until FD_PREPARE() takes +* ownership. +*/ +get_file (pos->hr_file); req = pos;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 348/869 ethtool: module: call ethnl_ops_complete() on module flash errors
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 84371fb58423f997939aacdcbc02d128d76a54e5 ]
When validate() fails we are skipping over ethnl_ops_complete() even tho we already called ethnl_ops_begin().
--- net/ethtool/module.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ethtool/module.c +2 -1
@@ -425,10 +425,11 @@ int ethnl_act_module_fw_flash(struct sk_buff *skb, struct genl_info *info) ret =ethnl_module_fw_flash_validate (dev, info->extack);if (ret <0 ) - goto out_rtnl; + goto out_complete; ret =module_flash_fw (dev, tb, skb, info); +out_complete:ethnl_ops_complete (dev); out_rtnl:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 349/869 ethtool: rss: fix indir_table and hkey leak on get_rxfh failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 266297692f97008ca48bc311775c087c59bd7fe3 ]
rss_prepare_get() allocates the indirection table and hash key buffer via rss_get_data_alloc(), then calls ops->get_rxfh() to populate them. If get_rxfh() fails, the function returns an error without freeing the allocation.
--- net/ethtool/rss.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ethtool/rss.c +3 -1
@@ -88,8 +88,10 @@ rss_prepare_get(const struct rss_req_info *request, struct net_device *dev, rxfh.key = data->hkey; ret = ops->get_rxfh (dev, &rxfh); -if (ret) +if (ret) { +kfree (rss_config); goto out_ops; + } data->hfunc = rxfh.hfunc; data->input_xfrm = rxfh.input_xfrm;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 350/869 netfilter: nf_tables: fix dst corruption in same register operation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 18014147d3ee7831dce53fe65d7fc8d428b02552 ]
For lshift and rshift, the shift operations are performed in a loop over 32-bit words. The loop calculates the shifted value and write it to dst, and then immediately reads from src to calculate the carry for the next iteration. Because src and dst could point to the same memory location, the carry is incorrectly calculated using the newly modified dst value instead of the original src value.
Adding a temporary local variable to cache the original value before writing to dst and using it for the carry calculation solves the problem. In addition, partial overlap is rejected from control plane for all kind of operations including byteorder. This was tested with the following bytecode:
table test_table ip flags 0 use 1 handle 1
ip test_table test_chain use 3 type filter hook input prio 0 policy accept packets 0 bytes 0 flags 1 ip test_table test_chain 2
[ immediate reg 1 0x44332211 0x88776655 ]
[ bitwise reg 1 = ( reg 1 << 0x08000000 ) ]
[ cmp eq reg 1 0x66443322 0x00887766 ]
[ counter pkts 0 bytes 0 ]
ip test_table test_chain 4 3
[ immediate reg 1 0x44332211 0x88776655 ]
[ bitwise reg 1 = ( reg 1 << 0x08000000 ) ]
[ cmp eq reg 1 0x55443322 0x00887766 ]
[ counter pkts 21794 bytes 1917798 ]
--- include/net/netfilter/nf_tables.h | 7 +++++++ net/netfilter/nft_bitwise.c | 15 +++++++++++---- net/netfilter/nft_byteorder.c | 13 ++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-)
include/net/netfilter/nf_tables.h +7 -0
@@ -177,6 +177,13 @@ static inline u64 nft_reg_load64(const u32 *sreg)return get_unaligned ((u64 *)sreg); } +static inline bool nft_reg_overlap (u8 src,u8 dst,u32 len) +{ +unsigned int n =DIV_ROUND_UP (len,sizeof (u32)); + +return src != dst && src < dst + n && dst < src + n; +} +static inline void nft_data_copy (u32 *dst,const struct nft_data *src,unsigned int len) {
net/netfilter/nft_bitwise.c +11 -4
@@ -42,8 +42,10 @@ static void nft_bitwise_eval_lshift(u32 *dst, const u32 *src,u32 carry =0 ;for (i =DIV_ROUND_UP (priv->len,sizeof (u32)); i >0 ; i--) { - dst[i -1 ] = (src[i -1 ] << shift) | carry; - carry = src[i -1 ] >> (BITS_PER_TYPE (u32) - shift); +u32 tmp_src = src[i -1 ]; + + dst[i -1 ] = (tmp_src << shift) | carry; + carry = tmp_src >> (BITS_PER_TYPE (u32) - shift); } }
@@ -55,8 +57,10 @@ static void nft_bitwise_eval_rshift(u32 *dst, const u32 *src,u32 carry =0 ;for (i =0 ; i <DIV_ROUND_UP (priv->len,sizeof (u32)); i++) { - dst[i] = carry | (src[i] >> shift); - carry = src[i] << (BITS_PER_TYPE (u32) - shift); +u32 tmp_src = src[i]; + + dst[i] = carry | (tmp_src >> shift); + carry = tmp_src << (BITS_PER_TYPE (u32) - shift); } }
@@ -183,6 +187,9 @@ static int nft_bitwise_init(const struct nft_ctx *ctx,if (err <0 )return err; +if (nft_reg_overlap (priv->sreg, priv->dreg, priv->len)) +return -EINVAL ; +if (tb[NFTA_BITWISE_OP ]) { priv->op =ntohl (nla_get_be32 (tb[NFTA_BITWISE_OP ]));switch (priv->op) {
net/netfilter/nft_byteorder.c +10 -3
@@ -144,9 +144,16 @@ static int nft_byteorder_init(const struct nft_ctx *ctx,if (err <0 )return err; -return nft_parse_register_store (ctx, tb[NFTA_BYTEORDER_DREG ], - &priv->dreg,NULL ,NFT_DATA_VALUE , - priv->len); + err =nft_parse_register_store (ctx, tb[NFTA_BYTEORDER_DREG ], + &priv->dreg,NULL ,NFT_DATA_VALUE , + priv->len); +if (err <0 ) +return err; + +if (nft_reg_overlap (priv->sreg, priv->dreg, priv->len)) +return -EINVAL ; + +return 0 ; } static int nft_byteorder_dump(struct sk_buff *skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 351/869 tcp: Remove sk->sk_prot->orphan_count.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 7051b54fb5aa2d0b77657aef7c272471b36c0327 ]
TCP tracks the number of orphaned (SOCK_DEAD but not yet destructed) sockets in tcp_orphan_count.
In some code that was shared with DCCP, tcp_orphan_count is referenced via sk->sk_prot->orphan_count.
Let's reference tcp_orphan_count directly.
inet_csk_prepare_for_destroy_sock() is moved to inet_connection_sock.c due to header dependency.
Only the TCP-only users are converted: the code paths shared with DCCP keep using sk->sk_prot->orphan_count, so DCCP orphan accounting is not affected, and the struct proto member stays.
Stable-dep-of: 1bbf0ced1d9d ("tcp: fix stale per-CPU tcp_tw_isn leak enabling ISN prediction")
--- .../ethernet/chelsio/inline_crypto/chtls/chtls_cm.c | 4 ++-- .../ethernet/chelsio/inline_crypto/chtls/chtls_cm.h | 1 - include/net/tcp.h | 10 ++++++++++ net/ipv4/tcp.c | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c +2 -2
@@ -505,7 +505,7 @@ static void reset_listen_child(struct sock *child)chtls_send_reset (child,CPL_ABORT_SEND_RST , skb);sock_orphan (child); -INC_ORPHAN_COUNT (child); +tcp_orphan_count_inc ();if (child->sk_state ==TCP_CLOSE )inet_csk_destroy_sock (child); }
@@ -870,7 +870,7 @@ static void do_abort_syn_rcv(struct sock *child, struct sock *parent)* created only after 3 way handshake is done. */ sock_orphan (child); -INC_ORPHAN_COUNT (child); +tcp_orphan_count_inc ();chtls_release_resources (child);chtls_conn_done (child); }else {
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h +0 -1
@@ -95,7 +95,6 @@ struct deferred_skb_cb {#define WSCALE_OK (tp) ((tp)->rx_opt.wscale_ok)#define TSTAMP_OK (tp) ((tp)->rx_opt.tstamp_ok)#define SACK_OK (tp) ((tp)->rx_opt.sack_ok) -#define INC_ORPHAN_COUNT (sk) this_cpu_inc(*(sk)->sk_prot->orphan_count)/* TLS SKB */ #define skb_ulp_tls_inline (skb) (ULP_SKB_CB(skb)->ulp.tls.ofld)
include/net/tcp.h +10 -0
@@ -54,6 +54,16 @@ extern struct inet_hashinfo tcp_hashinfo; DECLARE_PER_CPU(unsigned int, tcp_orphan_count);int tcp_orphan_count_sum (void ); +static inline void tcp_orphan_count_inc (void ) +{ +this_cpu_inc (tcp_orphan_count); +} + +static inline void tcp_orphan_count_dec (void ) +{ +this_cpu_dec (tcp_orphan_count); +} +DECLARE_PER_CPU (u32, tcp_tw_isn);void tcp_time_wait (struct sock *sk,int state,int timeo);
net/ipv4/tcp.c +1 -1
@@ -3163,7 +3163,7 @@ void __tcp_close(struct sock *sk, long timeout)/* remove backlog if any, without releasing ownership. */ __release_sock (sk); -this_cpu_inc (tcp_orphan_count); +tcp_orphan_count_inc ();/* Have we already been destroyed by a softirq or backlog? */ if (state !=TCP_CLOSE && sk->sk_state ==TCP_CLOSE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 352/869 tcp: fix stale per-CPU tcp_tw_isn leak enabling ISN prediction
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 1bbf0ced1d9db73ac7893c2187f3459288603e0d ]
Blamed commit moved the TIME_WAIT-derived ISN from the skb control block to a per-CPU variable, assuming the value would always be consumed by tcp_conn_request() for the same packet that wrote it. That assumption is violated by multiple drop paths between the producer (__this_cpu_write(tcp_tw_isn, isn) in tcp_v{4,6}_rcv()) and the consumer (tcp_conn_request()):
- min_ttl / min_hopcount check
- xfrm policy check
- tcp_inbound_hash() MD5/AO mismatch
- tcp_filter() eBPF/SO_ATTACH_FILTER drop
- th->syn && th->fin discard in tcp_rcv_state_process() TCP_LISTEN
- psp_sk_rx_policy_check() in tcp_v{4,6}_do_rcv()
- tcp_checksum_complete() in tcp_v{4,6}_do_rcv()
- tcp_v{4,6}_cookie_check() returning NULL
When a packet is dropped on any of these paths, tcp_tw_isn is left set.
The next SYN processed on the same CPU then consumes the non zero value in tcp_conn_request(), receiving a potentially predictable ISN.
This patch moves back tcp_tw_isn to skb->cb[], getting rid of the per-cpu variable.
Note that tcp_v{4,6}_fill_cb() do not set it.
Very litle impact on overall code size/complexity:
$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new add/remove: 0/0 grow/shrink: 2/1 up/down: 8/-15 (-7) Function old new delta tcp_v6_rcv 3038 3042 +4 tcp_v4_rcv 3035 3039 +4 tcp_conn_request 2938 2923 -15 Total: Before=24436060, After=24436053, chg -0.00%
--- include/net/tcp.h | 7 ++++--- net/ipv4/tcp.c | 3 --- net/ipv4/tcp_input.c | 15 ++++++--------- net/ipv4/tcp_ipv4.c | 3 ++- net/ipv6/tcp_ipv6.c | 3 ++- 5 files changed, 14 insertions(+), 17 deletions(-)
include/net/tcp.h +4 -3
@@ -64,8 +64,6 @@ static inline void tcp_orphan_count_dec(void)this_cpu_dec (tcp_orphan_count); } -DECLARE_PER_CPU (u32, tcp_tw_isn); -void tcp_time_wait (struct sock *sk,int state,int timeo);#define MAX_TCP_HEADER L1_CACHE_ALIGN(128 + MAX_HEADER)
@@ -947,10 +945,13 @@ struct tcp_skb_cb {__u32 seq;/* Starting sequence number */ __u32 end_seq;/* SEQ + FIN + SYN + datalen */ union { -/* Note : +/* Notes : +* tcp_tw_isn is used in input path only +* (isn chosen by tcp_timewait_state_process()) * tcp_gso_segs/size are used in write queue only, * cf tcp_skb_pcount()/tcp_skb_mss() */ +u32 tcp_tw_isn;struct {u16 tcp_gso_segs;u16 tcp_gso_size;
net/ipv4/tcp.c +0 -3
@@ -297,9 +297,6 @@ enum { DEFINE_PER_CPU(unsigned int, tcp_orphan_count);EXPORT_PER_CPU_SYMBOL_GPL (tcp_orphan_count); -DEFINE_PER_CPU (u32, tcp_tw_isn); -EXPORT_PER_CPU_SYMBOL_GPL (tcp_tw_isn); -long sysctl_tcp_mem[3 ]__read_mostly ;EXPORT_IPV6_MOD (sysctl_tcp_mem);
net/ipv4/tcp_input.c +6 -9
@@ -7242,6 +7242,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, struct sock *sk, struct sk_buff *skb) { struct tcp_fastopen_cookie foc = { .len = -1 }; +u32 isn =TCP_SKB_CB (skb)->tcp_tw_isn;struct tcp_options_received tmp_opt;struct tcp_sock *tp =tcp_sk (sk);struct net *net =sock_net (sk);
@@ -7252,20 +7253,16 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,struct dst_entry *dst;struct flowi fl;u8 syncookies; -u32 isn;#ifdef CONFIG_TCP_AO const struct tcp_ao_hdr *aoh;#endif - isn =__this_cpu_read (tcp_tw_isn); -if (isn) { -/* TW buckets are converted to open requests without -* limitations, they conserve resources and peer is -* evidently real one. -*/ -__this_cpu_write (tcp_tw_isn,0 ); - }else { +/* If isn is non-zero, this SYN originally matched a TIME_WAIT socket. +* TW sockets are converted to open requests without limitations, +* we skip the queue limits and syncookie checks in the block below. +*/ +if (!isn) { syncookies =READ_ONCE (net->ipv4.sysctl_tcp_syncookies);if (syncookies ==2 ||inet_csk_reqsk_queue_is_full (sk)) {
net/ipv4/tcp_ipv4.c +2 -1
@@ -2311,6 +2311,7 @@ int tcp_v4_rcv(struct sk_buff *skb) } } + isn =0 ; process:if (static_branch_unlikely (&ip4_min_ttl)) {/* min_ttl can be changed concurrently from do_ip_setsockopt() */
@@ -2340,6 +2341,7 @@ int tcp_v4_rcv(struct sk_buff *skb) th = (const struct tcphdr *)skb->data; iph =ip_hdr (skb);tcp_v4_fill_cb (skb, iph, th); +TCP_SKB_CB (skb)->tcp_tw_isn = isn; skb->dev =NULL ;
@@ -2424,7 +2426,6 @@ int tcp_v4_rcv(struct sk_buff *skb) sk = sk2;tcp_v4_restore_cb (skb); refcounted = false; -__this_cpu_write (tcp_tw_isn, isn); goto process; } }
net/ipv6/tcp_ipv6.c +2 -1
@@ -1853,6 +1853,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) } } + isn =0 ; process:if (static_branch_unlikely (&ip6_min_hopcount)) {/* min_hopcount can be changed concurrently from do_ipv6_setsockopt() */
@@ -1882,6 +1883,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) th = (const struct tcphdr *)skb->data; hdr =ipv6_hdr (skb);tcp_v6_fill_cb (skb, hdr, th); +TCP_SKB_CB (skb)->tcp_tw_isn = isn; skb->dev =NULL ;
@@ -1968,7 +1970,6 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) sk = sk2;tcp_v6_restore_cb (skb); refcounted = false; -__this_cpu_write (tcp_tw_isn, isn); goto process; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 353/869 cgroup/rstat: validate cpu before css_rstat_cpu() access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Ming <[email protected]>
[ Upstream commit 8817005efbdfdf5d4e4814cb5dc52b53d12917d7 ]
css_rstat_updated() is exposed as a BPF kfunc and accepts a caller-provided cpu argument. The function uses cpu for per-cpu rstat lookups without checking whether it refers to a valid possible CPU.
A BPF iter/cgroup program with CAP_BPF and CAP_PERFMON can pass an invalid cpu value. On an unfixed UBSCAN_BOUNDS test kernel, cpu == 0x7fffffff triggers:
UBSAN: array-index-out-of-bounds in kernel/cgroup/rstat.c:31:9
index 2147483647 is out of range for type 'long unsigned int [64]'
Call Trace:
css_rstat_updated
bpf_iter_run_prog
cgroup_iter_seq_show
bpf_seq_readAdd cpu validation to the BPF-facing css_rstat_updated() kfunc and move the common implementation to __css_rstat_updated() for in-kernel callers.
--- block/blk-cgroup.c | 2 +- include/linux/cgroup.h | 1 + kernel/cgroup/rstat.c | 19 ++++++++++++++++--- mm/memcontrol.c | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-)
block/blk-cgroup.c +1 -1
@@ -2189,7 +2189,7 @@ void blk_cgroup_bio_start(struct bio *bio) }u64_stats_update_end_irqrestore (&bis->sync, flags); -cgroup_rstat_updated (blkcg->css.cgroup, cpu); +__cgroup_rstat_updated (blkcg->css.cgroup, cpu);put_cpu (); }
include/linux/cgroup.h +1 -0
@@ -688,6 +688,7 @@ static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen)/* * cgroup scalable recursive statistics. */ +void __cgroup_rstat_updated (struct cgroup *cgrp,int cpu);void cgroup_rstat_updated (struct cgroup *cgrp,int cpu);void cgroup_rstat_flush (struct cgroup *cgrp);void cgroup_rstat_flush_hold (struct cgroup *cgrp);
kernel/cgroup/rstat.c +16 -3
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only #include "cgroup-internal.h" +#include <linux/cpumask.h> #include <linux/sched/cputime.h> #include <linux/bpf.h>
@@ -74,7 +75,7 @@ void _cgroup_rstat_cpu_unlock(raw_spinlock_t *cpu_lock, int cpu, }/** -* cgroup_rstat_updated - keep track of updated rstat_cpu +* __cgroup_rstat_updated - keep track of updated rstat_cpu * @cgrp: target cgroup * @cpu: cpu on which rstat_cpu was updated *
@@ -82,7 +83,7 @@ void _cgroup_rstat_cpu_unlock(raw_spinlock_t *cpu_lock, int cpu,* rstat_cpu->updated_children list. See the comment on top of * cgroup_rstat_cpu definition for details. */ -__bpf_kfunc void cgroup_rstat_updated(struct cgroup *cgrp, int cpu) +void __cgroup_rstat_updated (struct cgroup *cgrp,int cpu) {raw_spinlock_t *cpu_lock =per_cpu_ptr (&cgroup_rstat_cpu_lock, cpu);unsigned long flags;
@@ -129,6 +130,18 @@ __bpf_kfunc void cgroup_rstat_updated(struct cgroup *cgrp, int cpu)_cgroup_rstat_cpu_unlock (cpu_lock, cpu, cgrp, flags, true); } +/* +* BPF-facing wrapper for __cgroup_rstat_updated(). Validate the +* caller-provided CPU before passing it to the internal rstat updater. +*/ +__bpf_kfunc void cgroup_rstat_updated(struct cgroup *cgrp, int cpu) +{ +if (unlikely (cpu <0 || cpu >= nr_cpu_ids || !cpu_possible (cpu))) +return ; + +__cgroup_rstat_updated (cgrp, cpu); +} +/** * cgroup_rstat_push_children - push children cgroups into the given list * @head: current head of the list (= subtree root)
@@ -511,7 +524,7 @@ static void cgroup_base_stat_cputime_account_end(struct cgroup *cgrp, unsigned long flags) {u64_stats_update_end_irqrestore (&rstatc->bsync, flags); -cgroup_rstat_updated (cgrp,smp_processor_id ()); +__cgroup_rstat_updated (cgrp,smp_processor_id ());put_cpu_ptr (rstatc); }
mm/memcontrol.c +1 -1
@@ -569,7 +569,7 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val)if (!val)return ; -cgroup_rstat_updated (memcg->css.cgroup, cpu); +__cgroup_rstat_updated (memcg->css.cgroup, cpu); statc =this_cpu_ptr (memcg->vmstats_percpu);for (; statc; statc = statc->parent) { stats_updates =READ_ONCE (statc->stats_updates) +abs (val);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 354/869 hwmon: (lm90) Stop work before releasing hwmon device
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit b09a45601094c7f4ec4db8090b825fa61e169d93 ]
Sashiko reports:
In lm90_probe(), the devm action to cancel the alert_work and report_work (lm90_restore_conf) is registered in lm90_init_client() before devm_hwmon_device_register_with_info() is called.
Because devm executes cleanup actions in reverse order during module unbind or probe failure, the hwmon device is unregistered and freed first.
If lm90_alert_work() or lm90_report_alarms() runs in the window between the hwmon device being freed and the delayed works being cancelled, lm90_update_alarms() will dereference the freed data->hwmon_dev here.
Fix the problem by canceling the workers separately after registering the hwmon device and before registering the interrupt handler. This ensures that the workers are canceled after interrupts are disabled and before the hwmon device is released. Add "shutdown" flag to indicate that device shutdown is in progress to prevent workers from being re-armed.
--- drivers/hwmon/lm90.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/hwmon/lm90.c +20 -4
@@ -695,6 +695,7 @@ struct lm90_data {struct mutex update_lock;struct delayed_work alert_work;struct work_struct report_work; +bool shutdown;/* true if shutting down */ bool valid;/* true if register values are valid */ bool alarms_valid;/* true if status register values are valid */ unsigned long last_updated;/* in jiffies */
@@ -1113,6 +1114,9 @@ static void lm90_report_alarms(struct work_struct *work)static int lm90_update_alarms_locked (struct lm90_data *data,bool force) { +if (data->shutdown) +return 0 ; +if (force || !data->alarms_valid ||time_after (jiffies, data->alarms_updated +msecs_to_jiffies (data->update_interval))) {struct i2c_client *client = data->client;
@@ -2522,15 +2526,23 @@ static void lm90_restore_conf(void *_data)struct lm90_data *data = _data;struct i2c_client *client = data->client; -cancel_delayed_work_sync (&data->alert_work); -cancel_work_sync (&data->report_work); -/* Restore initial configuration */ if (data->flags &LM90_HAVE_CONVRATE )lm90_write_convrate (data, data->convrate_orig);lm90_write_reg (client,LM90_REG_CONFIG1 , data->config_orig); } +static void lm90_stop_work (void *_data) +{ +struct lm90_data *data = _data; + +mutex_lock (&data->update_lock); + data->shutdown = true; +mutex_unlock (&data->update_lock); +cancel_delayed_work_sync (&data->alert_work); +cancel_work_sync (&data->report_work); +} +static int lm90_init_client (struct i2c_client *client,struct lm90_data *data) {struct device_node *np = client->dev.of_node;
@@ -2841,6 +2853,10 @@ static int lm90_probe(struct i2c_client *client) data->hwmon_dev = hwmon_dev; + err =devm_add_action_or_reset (&client->dev, lm90_stop_work, data); +if (err) +return err; +if (client->irq) {dev_dbg (dev,"IRQ: %d\n" , client->irq); err = devm_request_threaded_irq(dev, client->irq,
@@ -2869,7 +2885,7 @@ static void lm90_alert(struct i2c_client *client, enum i2c_alert_protocol type,*/ struct lm90_data *data =i2c_get_clientdata (client); -if ((data->flags &LM90_HAVE_BROKEN_ALERT ) && +if (!data->shutdown && (data->flags &LM90_HAVE_BROKEN_ALERT ) && (data->current_alarms & data->alert_alarms)) {if (!(data->config &0x80 )) {dev_dbg (&client->dev,"Disabling ALERT#\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 355/869 netfs: Fix leak of request in netfs_write_begin() error handling
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 5046a34f0643441f05b0253ea64e1a3af87efe14 ]
Fix netfs_write_begin() to not leak our ref on the request in the event that we get an error from netfs_wait_for_read().
--- fs/netfs/buffered_read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/netfs/buffered_read.c +1 -1
@@ -753,9 +753,9 @@ int netfs_write_begin(struct netfs_inode *ctx,netfs_read_to_pagecache (rreq); ret =netfs_wait_for_read (rreq); +netfs_put_request (rreq, false, netfs_rreq_trace_put_return);if (ret <0 ) goto error; -netfs_put_request (rreq, false, netfs_rreq_trace_put_return); have_folio: ret =folio_wait_private_2_killable (folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 356/869 netfs: Fix missing locking around retry adding new subreqs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit cce18c263e9623872327ba3c956012f73c1179cc ]
Fix netfs_retry_read_subrequests() and netfs_retry_write_stream() to take the appropriate lock when adding extra subrequests into stream->subrequests.
--- fs/netfs/write_collect.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/netfs/write_collect.c +5 -1
@@ -263,7 +263,9 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,list_for_each_entry_safe_from (subreq, tmp, &stream->subrequests, rreq_link) {trace_netfs_sreq (subreq, netfs_sreq_trace_discard); +spin_lock_bh (&wreq->lock);list_del (&subreq->rreq_link); +spin_unlock_bh (&wreq->lock);netfs_put_subrequest (subreq, false, netfs_sreq_trace_put_done);if (subreq == to)break ;
@@ -287,8 +289,10 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq, netfs_sreq_trace_new);trace_netfs_sreq (subreq, netfs_sreq_trace_split); +spin_lock_bh (&wreq->lock);list_add (&subreq->rreq_link, &to->rreq_link); - to =list_next_entry (to, rreq_link); +spin_unlock_bh (&wreq->lock); + to = subreq;trace_netfs_sreq (subreq, netfs_sreq_trace_retry); stream->sreq_max_len = len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 357/869 netfilter: bridge: eb_tables: close module init race
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 27414ff1b287ea9a2a11675149ec28e05539f3cc ]
sashiko reports for unrelated patch:
Does the core ebtables initialization in ebtables.c suffer from a similar race? Once nf_register_sockopt() completes, the sockopts are exposed globally.
sockopt has to be registered last, just like in ip/ip6/arptables.
--- net/bridge/netfilter/ebtables.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/bridge/netfilter/ebtables.c +6 -5
@@ -2607,19 +2607,20 @@ static int __init ebtables_init(void) {int ret; - ret =xt_register_target (&ebt_standard_target); + ret =register_pernet_subsys (&ebt_net_ops);if (ret <0 )return ret; - ret =nf_register_sockopt (&ebt_sockopts); + + ret =xt_register_target (&ebt_standard_target);if (ret <0 ) { -xt_unregister_target (&ebt_standard_target); +unregister_pernet_subsys (&ebt_net_ops);return ret; } - ret =register_pernet_subsys (&ebt_net_ops); + ret =nf_register_sockopt (&ebt_sockopts);if (ret <0 ) { -nf_unregister_sockopt (&ebt_sockopts);xt_unregister_target (&ebt_standard_target); +unregister_pernet_subsys (&ebt_net_ops);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 358/869 netfilter: ebtables: move to two-stage removal scheme
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit b7f0544d86d439cb946515d2ef6a0a75e8626710 ]
Like previous patches for x_tables, follow same pattern in ebtables. We can't reuse xt helpers: ebt_table struct layout is incompatible.
table->ops assignment is now done while still holding the ebt mutex to make sure we never expose partially-filled table struct.
--- net/bridge/netfilter/ebtable_broute.c | 2 +- net/bridge/netfilter/ebtable_filter.c | 2 +- net/bridge/netfilter/ebtable_nat.c | 2 +- net/bridge/netfilter/ebtables.c | 60 +++++++++++++++++---------- 4 files changed, 40 insertions(+), 26 deletions(-)
net/bridge/netfilter/ebtable_broute.c +1 -1
@@ -128,8 +128,8 @@ static int __init ebtable_broute_init(void) static void __exit ebtable_broute_fini(void) { -unregister_pernet_subsys (&broute_net_ops);ebt_unregister_template (&broute_table); +unregister_pernet_subsys (&broute_net_ops); }module_init (ebtable_broute_init);
net/bridge/netfilter/ebtable_filter.c +1 -1
@@ -109,8 +109,8 @@ static int __init ebtable_filter_init(void) static void __exit ebtable_filter_fini(void) { -unregister_pernet_subsys (&frame_filter_net_ops);ebt_unregister_template (&frame_filter); +unregister_pernet_subsys (&frame_filter_net_ops); }module_init (ebtable_filter_init);
net/bridge/netfilter/ebtable_nat.c +1 -1
@@ -109,8 +109,8 @@ static int __init ebtable_nat_init(void) static void __exit ebtable_nat_fini(void) { -unregister_pernet_subsys (&frame_nat_net_ops);ebt_unregister_template (&frame_nat); +unregister_pernet_subsys (&frame_nat_net_ops); }module_init (ebtable_nat_init);
net/bridge/netfilter/ebtables.c +37 -23
115 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 359/869 netfilter: x_tables: allow initial table replace without emitting audit log message
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 8e72510db9fa2d41f2b06d5c01fe9020e076fee4 ]
At the moment we emit the audit log a bit too early, which makes it necessary to also emit an unregister log in case we have to unwind errors after possible hook register failure.
Followup patch will be slightly simpler if we can delay the register message until after the hooks have been wired up.
Stable-dep-of: b62eb8dcf2c4 ("netfilter: x_tables: allocate hook ops while under mutex")
--- net/netfilter/x_tables.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
net/netfilter/x_tables.c +20 -9
@@ -1404,11 +1404,9 @@ struct xt_counters *xt_counters_alloc(unsigned int counters) }EXPORT_SYMBOL (xt_counters_alloc); -struct xt_table_info * -xt_replace_table (struct xt_table *table, -unsigned int num_counters, -struct xt_table_info *newinfo, -int *error) +static struct xt_table_info * +do_replace_table (struct xt_table *table,unsigned int num_counters, +struct xt_table_info *newinfo,int *error) {struct xt_table_info *private;unsigned int cpu;
@@ -1463,10 +1461,23 @@ xt_replace_table(struct xt_table *table, } } -audit_log_nfcfg (table->name, table->af, private->number, - !private->number ?AUDIT_XT_OP_REGISTER : -AUDIT_XT_OP_REPLACE , -GFP_KERNEL ); +return private; +} + +struct xt_table_info * +xt_replace_table (struct xt_table *table,unsigned int num_counters, +struct xt_table_info *newinfo, +int *error) +{ +struct xt_table_info *private; + + private =do_replace_table (table, num_counters, newinfo, error); +if (private) +audit_log_nfcfg (table->name, table->af, private->number, + !private->number ?AUDIT_XT_OP_REGISTER : +AUDIT_XT_OP_REPLACE , +GFP_KERNEL ); +return private; }EXPORT_SYMBOL_GPL (xt_replace_table);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 360/869 netfilter: x_tables: allocate hook ops while under mutex
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit b62eb8dcf2c47d4d676a434efbd57c4f776f7829 ]
arp/ip(6)t_register_table() add the table to the per-netns list via xt_register_table() before allocating the per-netns hook ops copy via kmemdup_array(). This leaves a window where the table is visible in the list with ops=NULL.
If the pernet exit happens runs concurrently the pre_exit callback finds the table via xt_find_table() and passes the NULL ops pointer to nf_unregister_net_hooks(), causing a NULL dereference:
general protection fault in nf_unregister_net_hooks+0xbc/0x150
RIP: nf_unregister_net_hooks (net/netfilter/core.c:613)
Call Trace:
ipt_unregister_table_pre_exit
iptable_mangle_net_pre_exit
ops_pre_exit_list
cleanup_netFix by moving the ops allocation into the xtables core so the table is never in the list without valid ops. Also ensure the table is no longer processing packets before its torn down on error unwind. nf_register_net_hooks might have published at least one hook; call synchronize_rcu() if there was an error.
audit log register message gets deferred until all operations have passed, this avoids need to emit another ureg message in case of error unwinding.
Based on earlier patch by Tristan Madani.
--- include/linux/netfilter/x_tables.h | 1 + net/ipv4/netfilter/arp_tables.c | 35 +++------------------ net/ipv4/netfilter/ip_tables.c | 41 +++--------------------- net/ipv6/netfilter/ip6_tables.c | 38 +++-------------------- net/netfilter/x_tables.c | 50 +++++++++++++++++++++++++----- 5 files changed, 55 insertions(+), 110 deletions(-)
include/linux/netfilter/x_tables.h +1 -0
@@ -307,6 +307,7 @@ struct xt_counters *xt_counters_alloc(unsigned int counters);struct xt_table *xt_register_table (struct net *net,const struct xt_table *table, +const struct nf_hook_ops *template_ops,struct xt_table_info *bootstrap,struct xt_table_info *newinfo);void *xt_unregister_table (struct xt_table *table);
net/ipv4/netfilter/arp_tables.c +4 -31
@@ -1519,13 +1519,11 @@ int arpt_register_table(struct net *net,const struct arpt_replace *repl, const struct nf_hook_ops *template_ops) { - struct nf_hook_ops *ops; -unsigned int num_ops; -int ret, i; -struct xt_table_info *newinfo; struct xt_table_info bootstrap = {0}; -void *loc_cpu_entry; +struct xt_table_info *newinfo;struct xt_table *new_table; +void *loc_cpu_entry; +int ret; newinfo =xt_alloc_table_info (repl->size);if (!newinfo)
@@ -1540,7 +1538,7 @@ int arpt_register_table(struct net *net,return ret; } - new_table =xt_register_table (net, table, &bootstrap, newinfo); + new_table =xt_register_table (net, table, template_ops, &bootstrap, newinfo);if (IS_ERR (new_table)) {struct arpt_entry *iter;
@@ -1550,31 +1548,6 @@ int arpt_register_table(struct net *net,return PTR_ERR (new_table); } - num_ops =hweight32 (table->valid_hooks); -if (num_ops ==0 ) { - ret = -EINVAL ; - goto out_free; - } - - ops =kmemdup_array (template_ops, num_ops,sizeof (*ops),GFP_KERNEL ); -if (!ops) { - ret = -ENOMEM ; - goto out_free; - } - -for (i =0 ; i < num_ops; i++) - ops[i].priv = new_table; - - new_table->ops = ops; - - ret =nf_register_net_hooks (net, ops, num_ops); -if (ret !=0 ) - goto out_free; - -return ret; - -out_free: -__arpt_unregister_table (net, new_table);return ret; }
net/ipv4/netfilter/ip_tables.c +4 -37
61 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +4 -34
@@ -1735,13 +1735,11 @@ int ip6t_register_table(struct net *net, const struct xt_table *table,const struct ip6t_replace *repl, const struct nf_hook_ops *template_ops) { - struct nf_hook_ops *ops; -unsigned int num_ops; -int ret, i; -struct xt_table_info *newinfo; struct xt_table_info bootstrap = {0}; -void *loc_cpu_entry; +struct xt_table_info *newinfo;struct xt_table *new_table; +void *loc_cpu_entry; +int ret; newinfo =xt_alloc_table_info (repl->size);if (!newinfo)
@@ -1756,7 +1754,7 @@ int ip6t_register_table(struct net *net, const struct xt_table *table,return ret; } - new_table =xt_register_table (net, table, &bootstrap, newinfo); + new_table =xt_register_table (net, table, template_ops, &bootstrap, newinfo);if (IS_ERR (new_table)) {struct ip6t_entry *iter;
@@ -1766,34 +1764,6 @@ int ip6t_register_table(struct net *net, const struct xt_table *table,return PTR_ERR (new_table); } -if (!template_ops) -return 0 ; - - num_ops =hweight32 (table->valid_hooks); -if (num_ops ==0 ) { - ret = -EINVAL ; - goto out_free; - } - - ops =kmemdup_array (template_ops, num_ops,sizeof (*ops),GFP_KERNEL ); -if (!ops) { - ret = -ENOMEM ; - goto out_free; - } - -for (i =0 ; i < num_ops; i++) - ops[i].priv = new_table; - - new_table->ops = ops; - - ret =nf_register_net_hooks (net, ops, num_ops); -if (ret !=0 ) - goto out_free; - -return ret; - -out_free: -__ip6t_unregister_table (net, new_table);return ret; }
net/netfilter/x_tables.c +42 -8
90 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 361/869 wifi: mac80211: fix missing RX bitrate update for mesh forwarding path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sarika Sharma <[email protected]>
[ Upstream commit cc18fffa3a51792637169872886df3407bd5bb84 ]
Currently, RX bitrate statistics are not updated for packets received on the mesh forwarding path during fast RX processing. This results in incomplete RX rate tracking in station dump outputs for mesh scenarios.
Update ieee80211_invoke_fast_rx() to record the RX rate using sta_stats_encode_rate() and store it in the last_rate field of ieee80211_sta_rx_stats when RX_QUEUED is returned from ieee80211_rx_mesh_data(). This ensures that RX bitrate is properly accounted for in both RSS and non-RSS paths.
Stable-dep-of: d71c841be5d9 ("wifi: mac80211: capture fast-RX rate before mesh reuses skb->cb")
--- net/mac80211/rx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
net/mac80211/rx.c +7 -5
@@ -4968,6 +4968,11 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,/* after this point, don't punt to the slowpath! */ +if (fast_rx->uses_rss) + stats =this_cpu_ptr (rx->link_sta->pcpu_rx_stats); +else + stats = &rx->link_sta->rx_stats; +if (rx->key && !(status->flag &RX_FLAG_MIC_STRIPPED ) &&pskb_trim (skb, skb->len - fast_rx->icv_len)) goto drop;
@@ -5002,6 +5007,8 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx, res =ieee80211_rx_mesh_data (rx->sdata, rx->sta, rx->skb);switch (res) {case RX_QUEUED : + stats->last_rx = jiffies; + stats->last_rate =sta_stats_encode_rate (status);return true;case RX_CONTINUE :break ;
@@ -5015,11 +5022,6 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx, drop:dev_kfree_skb (skb); -if (fast_rx->uses_rss) - stats =this_cpu_ptr (rx->link_sta->pcpu_rx_stats); -else - stats = &rx->link_sta->rx_stats; - stats->dropped++;return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 362/869 wifi: mac80211: capture fast-RX rate before mesh reuses skb->cb
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit d71c841be5d9e586ee7f36c0dc8ed4db0d9a1349 ]
ieee80211_invoke_fast_rx() reads RX status through IEEE80211_SKB_RXCB(skb), which aliases the same skb->cb storage that ieee80211_rx_mesh_data() reuses as IEEE80211_TX_INFO. In the unicast forward path, mesh_data does:
info = IEEE80211_SKB_CB(fwd_skb); memset(info, 0, sizeof(*info));
on the same skb the caller still names via rx->skb, then either queues the skb for TX (success) or kfree_skb()'s it (no-route) before returning RX_QUEUED. The caller's RX_QUEUED arm then calls sta_stats_encode_rate(status) on memory that is either zeroed (success path) or freed (no-route path). The latter is KASAN slab-use-after-free in ieee80211_prepare_and_rx_handle.
Fix by encoding the rate from status before invoking ieee80211_rx_mesh_data(), so the RX_QUEUED arm consumes a value captured while status was still backed by valid memory.
--- net/mac80211/rx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/mac80211/rx.c +5 -1
@@ -4897,6 +4897,7 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,u8 sa[ETH_ALEN ]; } addrs__aligned(2) ;struct ieee80211_sta_rx_stats *stats; +u32 encoded_rate;/* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write * to a common data structure; drivers can implement that per queue
@@ -5004,11 +5005,14 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,/* push the addresses in front */ memcpy (skb_push (skb,sizeof (addrs)), &addrs,sizeof (addrs)); +/* capture before mesh forward may memset or free skb->cb */ + encoded_rate =sta_stats_encode_rate (status); + res =ieee80211_rx_mesh_data (rx->sdata, rx->sta, rx->skb);switch (res) {case RX_QUEUED : stats->last_rx = jiffies; - stats->last_rate =sta_stats_encode_rate (status); + stats->last_rate = encoded_rate;return true;case RX_CONTINUE :break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 363/869 erofs: fix metabuf leak in inode xattr initialization
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Zhu <[email protected]>
[ Upstream commit 79b09c54c6563df9846ca3094bcfd72082c3e1d7 ]
commit bb88e8da0025 ("erofs: use meta buffers for xattr operations") converted xattr operations to use on-stack erofs_buf instances. erofs_init_inode_xattrs() uses such a metabuf while reading the inline xattr header and shared xattr id array.
Some error paths after erofs_read_metabuf() leave through out_unlock without dropping the metabuf, so the folio reference can leak.
Consolidate the cleanup at out_unlock. erofs_put_metabuf() is a no-op if no folio has been acquired, and this keeps all paths after taking EROFS_I_BL_XATTR_BIT covered by a single cleanup site.
--- fs/erofs/xattr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/erofs/xattr.c +3 -3
@@ -47,6 +47,8 @@ static int erofs_init_inode_xattrs(struct inode *inode)if (wait_on_bit_lock (&vi->flags,EROFS_I_BL_XATTR_BIT ,TASK_KILLABLE ))return -ERESTARTSYS ; + it.buf = __EROFS_BUF_INITIALIZER; +/* someone has initialized xattrs for us? */ if (test_bit (EROFS_I_EA_INITED_BIT , &vi->flags)) goto out_unlock;
@@ -76,7 +78,6 @@ static int erofs_init_inode_xattrs(struct inode *inode) goto out_unlock; } - it.buf = __EROFS_BUF_INITIALIZER;erofs_init_metabuf (&it.buf, sb); it.pos =erofs_iloc (inode) + vi->inode_isize;
@@ -93,7 +94,6 @@ static int erofs_init_inode_xattrs(struct inode *inode) vi->xattr_shared_xattrs =kmalloc_array (vi->xattr_shared_count,sizeof (uint),GFP_KERNEL );if (!vi->xattr_shared_xattrs) { -erofs_put_metabuf (&it.buf); ret = -ENOMEM ; goto out_unlock; }
@@ -112,13 +112,13 @@ static int erofs_init_inode_xattrs(struct inode *inode) vi->xattr_shared_xattrs[i] =le32_to_cpu (*(__le32 *)it.kaddr); it.pos +=sizeof (__le32); } -erofs_put_metabuf (&it.buf);/* paired with smp_mb() at the beginning of the function. */ smp_mb ();set_bit (EROFS_I_EA_INITED_BIT , &vi->flags); out_unlock: +erofs_put_metabuf (&it.buf);clear_and_wake_up_bit (EROFS_I_BL_XATTR_BIT , &vi->flags);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 364/869 drm/msm/adreno: Fix a reference leak in a6xx_gpu_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
[ Upstream commit e64bca63647db1d5518198d6c5ca2dbcc66b182b ]
In a6xx_gpu_init(), node is obtained via of_parse_phandle(). While there was a manual of_node_put() at the end of the common path, several early error returns would bypass this call, resulting in a reference leak.
Fix this by using the __free(device_node) cleanup handler to release the reference when the variable goes out of scope.
Patchwork: https://patchwork.freedesktop.org/patch/700661/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +2 -3
@@ -2277,7 +2277,6 @@ struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)struct msm_drm_private *priv = dev->dev_private;struct platform_device *pdev = priv->gpu_pdev;struct adreno_platform_config *config = pdev->dev.platform_data; -struct device_node *node;struct a6xx_gpu *a6xx_gpu;struct adreno_gpu *adreno_gpu;struct msm_gpu *gpu;
@@ -2296,7 +2295,8 @@ struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) adreno_gpu->registers =NULL ;/* Check if there is a GMU phandle and set it up */ - node =of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 ); + struct device_node *node __free(device_node) = +of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 );/* FIXME: How do we gracefully handle this? */ BUG_ON (!node);
@@ -2341,7 +2341,6 @@ struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) ret =a6xx_gmu_wrapper_init (a6xx_gpu, node); else ret =a6xx_gmu_init (a6xx_gpu, node); -of_node_put (node);if (ret) {a6xx_destroy (&(a6xx_gpu->base.base));return ERR_PTR (ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 365/869 netfs: Fix zeropoint update where i_size > remote_i_size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 4543a4d737944134a1394afe797622546fbcc98a ]
Fix the update of the zero point[*] by netfs_release_folio() when there is uncommitted data in the pagecache beyond the folio being released but the on-server EOF is in this folio (ie. i_size > remote_i_size). The update needs to limit zero_point to remote_i_size, not i_size as i_size is a local phenomenon reflecting updates made locally to the pagecache, not stuff written to the server. remote_i_size tracks the server's i_size.
[*] The zero point is the file position from which we can assume that the
server will just return zeros, so we can avoid generating reads.
Note that netfs_invalidate_folio() probably doesn't need fixing as zero_point should be updated by setattr after truncation or fallocate.
Found with:
fsx -q -N 1000000 -p 10000 -o 128000 -l 600000 \
/xfstest.test/junk --replay-ops=junk.fsxopsusing the following as junk.fsxops:
truncate 0x0 0x1bbae 0x82864
write 0x3ef2e 0xf9c8 0x1bbae
write 0x67e05 0xcb5a 0x4e8f6
mapread 0x57781 0x85b6 0x7495f
copy_range 0x5d3d 0x10329 0x54fac 0x7495f
write 0x64710 0x1c2b 0x7495f
mapread 0x64000 0x1000 0x7495fon cifs with the default cache option.
It shows read-gaps on folio 0x64 failing with a short read (ie. it hits EOF) if the FMODE_READ check is commented out in netfs_perform_write():
if (//(file->f_mode & FMODE_READ) ||
netfs_is_cache_enabled(ctx)) {and no fscache. This was initially found with the generic/522 xfstest.
--- fs/netfs/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/netfs/misc.c +1 -1
@@ -315,7 +315,7 @@ bool netfs_release_folio(struct folio *folio, gfp_t gfp)if (folio_test_dirty (folio))return false; - end =umin (folio_pos (folio) +folio_size (folio),i_size_read (&ctx->inode)); + end =umin (folio_pos (folio) +folio_size (folio), ctx->remote_i_size);if (end > ctx->zero_point) ctx->zero_point = end;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 366/869 hwmon: (lm90) Add lock protection to lm90_alert
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 873e919e3101063a7a75989510ccfc125a4391cf ]
Sashiko reports:
lm90_alert() executes in the smbus alert context and calls lm90_update_confreg() to disable the hardware alert line, without acquiring hwmon_lock.
Concurrently, sysfs write operations (such as lm90_write_convrate) hold the hwmon_lock, temporarily modify data->config, and then restore it.
If an alert interrupt occurs concurrently with a sysfs write, the sysfs path will overwrite the alert handler's modifications to data->config and the hardware register.
This unintentionally re-enables the hardware alert line while the alarm is still active, causing an interrupt storm.
Add the missing lock to lm90_alert() to solve the problem.
--- drivers/hwmon/lm90.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/lm90.c +2 -0
@@ -2885,6 +2885,7 @@ static void lm90_alert(struct i2c_client *client, enum i2c_alert_protocol type,*/ struct lm90_data *data =i2c_get_clientdata (client); +mutex_lock (&data->update_lock);if (!data->shutdown && (data->flags &LM90_HAVE_BROKEN_ALERT ) && (data->current_alarms & data->alert_alarms)) {if (!(data->config &0x80 )) {
@@ -2894,6 +2895,7 @@ static void lm90_alert(struct i2c_client *client, enum i2c_alert_protocol type,schedule_delayed_work (&data->alert_work,max_t (int,HZ ,msecs_to_jiffies (data->update_interval))); } +mutex_unlock (&data->update_lock); }else {dev_dbg (&client->dev,"Everything OK\n" ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 367/869 KVM: guest_memfd: Treat memslot binding offset+size as unsigned values
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit eba85fee7fc6cf28fec38a5bf3c378bef9a79ca6 ]
When binding a memslot to a guest_memfd file, treat the offset and size as unsigned values to fix a bug where the sum of the two can result in a false negative when checking for overflow against the size of the file. Passing unsigned values also avoids relying on somewhat obscure checks in other flows for safety, and tracks the offset and size as they are intended to be tracked, as unsigned values.
On 64-bit kernels, the number of pages a memslot contains and thus the size (and offset) of its guest_memfd binding are unsigned 64-bit values. Taking the offset+size as an loff_t instead of a uoff_t inadvertently converts the unsigned value to a signed value if the offset and/or size is massive.
Locally storing the offset and size as signed values is benign in and of itself (though even that is *extremely* difficult to discern), but operating on their sum is not.
For the offset, KVM explicitly checks against a negative value, which might seem like a bug as KVM could incorrectly reject a legitimate binding, but that's not actually the case as KVM_CREATE_GUEST_MEMFD takes a signed value for its size, i.e. a would-be-negative offset is also greater than the maximum possible size of any guest_memfd file.
Regarding the size, while KVM lacks an explicit check for a negative value, i.e. seemingly has a flawed overflow check, KVM restricts the number of pages in a single memslot to the largest positive signed 32-bit value:
if (id < KVM_USER_MEM_SLOTS &&
(mem->memory_size >> PAGE_SHIFT) > KVM_MEM_MAX_NR_PAGES)
return -EINVAL;and so that maximum "size" will ever be is 0x7fffffff000.
The sum of the two is, however, problematic. While the size is restricted by KVM's memslot logic, the offset is not, i.e. the offset is completely unchecked until the "offset + size > i_size_read(inode)" check. If the offset is the (nearly) largest possible _positive_ value, then adding size to the offset can result in a signed, negative 64-bit value. When compared against the size of the file (guaranteed to be positive), the negative sum is always smaller, and KVM incorrectly allows the absurd offset.
Opportunistically add missing includes in kvm_mm.h (instead of relying on its parents).
--- virt/kvm/guest_memfd.c | 8 ++++---- virt/kvm/kvm_mm.h | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-)
virt/kvm/guest_memfd.c +4 -4
@@ -473,15 +473,16 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args) }int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot, -unsigned int fd,loff_t offset) +unsigned int fd,u64 offset) { -loff_t size = slot->npages <<PAGE_SHIFT ; +u64 size = slot->npages <<PAGE_SHIFT ;unsigned long start, end;struct kvm_gmem *gmem;struct inode *inode;struct file *file;int r = -EINVAL ; +BUILD_BUG_ON (sizeof (gpa_t) !=sizeof (offset));BUILD_BUG_ON (sizeof (gfn_t) !=sizeof (slot->gmem.pgoff)); file =fget (fd);
@@ -497,8 +498,7 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot, inode =file_inode (file); -if (offset <0 || !PAGE_ALIGNED (offset) || - offset + size >i_size_read (inode)) +if (!PAGE_ALIGNED (offset) || offset + size >i_size_read (inode)) goto err;filemap_invalidate_lock (inode->i_mapping);
virt/kvm/kvm_mm.h +5 -2
@@ -3,6 +3,9 @@#ifndef __KVM_MM_H__#define __KVM_MM_H__ 1 +#include <linux/kvm.h> +#include <linux/kvm_types.h> +/* * Architectures can choose whether to use an rwlock or spinlock * for the mmu_lock. These macros, for use in common code
@@ -39,7 +42,7 @@ static inline void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm,void kvm_gmem_init (struct module *module);int kvm_gmem_create (struct kvm *kvm,struct kvm_create_guest_memfd *args);int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot, -unsigned int fd,loff_t offset); +unsigned int fd,u64 offset);void kvm_gmem_unbind (struct kvm_memory_slot *slot);#else static inline void kvm_gmem_init (struct module *module)
@@ -49,7 +52,7 @@ static inline void kvm_gmem_init(struct module *module)static inline int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot, -unsigned int fd,loff_t offset) +unsigned int fd,u64 offset) {WARN_ON_ONCE (1 );return -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 368/869 smb/client: fix chown/chgrp with SMB3 POSIX Extensions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ralph Boehme <[email protected]>
[ Upstream commit 760ef2c579c2609cf17fb1cd5392f64d42d43d33 ]
Ownership (chown) and group (chgrp) modifications were being ignored when mounting with SMB3 POSIX Extensions unless CIFS_MOUNT_CIFS_ACL or CIFS_MOUNT_MODE_FROM_SID were also explicitly set.
Fix this by checking for posix_extensions in cifs_setattr_nounix() when updating UID and GID, ensuring that id_mode_to_cifs_acl() is called to map and set the ownership/group information on the server.
--- fs/smb/client/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/smb/client/inode.c +2 -1
@@ -3296,7 +3296,8 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) gid = attrs->ia_gid;if ((cifs_sb->mnt_cifs_flags &CIFS_MOUNT_CIFS_ACL ) || - (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MODE_FROM_SID )) { + (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MODE_FROM_SID ) || +cifs_sb_master_tcon (cifs_sb)->posix_extensions) {if (uid_valid (uid) ||gid_valid (gid)) { mode =NO_CHANGE_64 ; rc = id_mode_to_cifs_acl(inode, full_path, &mode,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 369/869 ksmbd: validate NTLMv2 response before updating session key
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haofeng Li <[email protected]>
[ Upstream commit 954d196bebb2b50151cb96454c72dc113b2af1ac ]
ksmbd_auth_ntlmv2() derives the NTLMv2 session key into sess->sess_key before it verifies the NTLMv2 response. ksmbd_decode_ntlmssp_auth_blob() then continues into KEY_XCH even when ksmbd_auth_ntlmv2() failed.
With SMB3 multichannel binding, the failed authentication operates on an existing session and the session setup error path does not expire binding sessions. A client can send a binding session setup with a bad NT proof and KEY_XCH and still modify sess->sess_key before STATUS_LOGON_FAILURE is returned.
Relevant path:
smb2_sess_setup()
-> conn->binding = true
-> ntlm_authenticate()
-> session_user()
-> ksmbd_decode_ntlmssp_auth_blob()
-> ksmbd_auth_ntlmv2()
-> calc_ntlmv2_hash()
-> hmac_md5_usingrawkey(..., sess->sess_key)
-> crypto_memneq() returns mismatch
-> KEY_XCH arc4_crypt(..., sess->sess_key, ...)
-> out_err without expiring the binding sessionDerive the base session key into a local buffer and copy it to sess->sess_key only after the proof matches. Return immediately on authentication failure so KEY_XCH is only processed after successful authentication.
--- fs/smb/server/auth.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/smb/server/auth.c +8 -6
@@ -278,15 +278,15 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,ksmbd_release_crypto_ctx (ctx); ctx =NULL ; - rc =ksmbd_gen_sess_key (sess, ntlmv2_hash, ntlmv2_rsp); -if (rc) { -ksmbd_debug (AUTH ,"Could not generate sess key\n" ); +if (crypto_memneq (ntlmv2->ntlmv2_hash, ntlmv2_rsp, +CIFS_HMAC_MD5_HASH_SIZE )) { + rc = -EINVAL ; goto out; } -if (crypto_memneq (ntlmv2->ntlmv2_hash, ntlmv2_rsp, -CIFS_HMAC_MD5_HASH_SIZE )) - rc = -EINVAL ; + rc =ksmbd_gen_sess_key (sess, ntlmv2_hash, ntlmv2_rsp); +if (rc) +ksmbd_debug (AUTH ,"Could not generate sess key\n" ); out:if (ctx)ksmbd_release_crypto_ctx (ctx);
@@ -348,6 +348,8 @@ int ksmbd_decode_ntlmssp_auth_blob(struct authenticate_message *authblob, nt_len -CIFS_ENCPWD_SIZE , domain_name, conn->ntlmssp.cryptkey);kfree (domain_name); +if (ret) +return ret;/* The recovered secondary session key */ if (conn->ntlmssp.client_flags &NTLMSSP_NEGOTIATE_KEY_XCH ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 370/869 ksmbd: prevent path traversal bypass by restricting caseless retry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 54bab9ba5a9f156ffa9324fcbe5a356fd0242f95 ]
ksmbd_vfs_path_lookup() enforces LOOKUP_BENEATH to restrict path resolution within the share root. When a crafted path attempts to escape the share boundary using parent-directory components ('..'), vfs_path_parent_lookup() detects this and immediately fails, returning -EXDEV.
However, a bug exists in __ksmbd_vfs_kern_path() under caseless mode. The function fails to intercept the -EXDEV error and erroneously falls through to the caseless retry logic, which is intended only for genuinely missing files. During this retry process, the path is reconstructed, leading to an unintended LOOKUP_BENEATH bypass that allows write-capable users to create zero-length files or directories outside the exported share.
Fix this by ensuring that the execution only proceeds to the caseless lookup retry when the error is specifically -ENOENT. Any other errors, such as -EXDEV from a path traversal attempt, must be returned immediately.
--- fs/smb/server/vfs.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/server/vfs.c +2 -0
@@ -1245,6 +1245,8 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name, path);if (!err)return 0 ; +if (err != -ENOENT ) +return err;if (caseless) {char *filepath;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 371/869 KVM: x86: Drop superfluous kvm_lapic_set_base() call when setting APIC state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 8166d25579120590ad0ec4ece02afd00a3c54f6a ]
Now that kvm_lapic_set_base() does nothing if the "new" APIC base MSR is the same as the current value, drop the kvm_lapic_set_base() call in the KVM_SET_LAPIC flow that passes in the current value, as it too does nothing.
Note, the purpose of invoking kvm_lapic_set_base() was purely to set apic->base_address (see commit 5dbc8f3fed0b ("KVM: use kvm_lapic_set_base() to change apic_base")). And there is no evidence that explicitly setting apic->base_address in KVM_SET_LAPIC ever had any functional impact; even in the original commit 96ad2cc61324 ("KVM: in-kernel LAPIC save and restore support"), all flows that set apic_base also set apic->base_address to the same address. E.g. svm_create_vcpu() did open code a write to apic_base,
svm->vcpu.apic_base = 0xfee00000 | MSR_IA32_APICBASE_ENABLE;
but it also called kvm_create_lapic() when irqchip_in_kernel() is true.
Stable-dep-of: bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
--- arch/x86/kvm/lapic.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/lapic.c +0 -1
@@ -3107,7 +3107,6 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s)kvm_x86_call (apicv_pre_state_restore)(vcpu); -kvm_lapic_set_base (vcpu, vcpu->arch.apic_base);/* set SPIV separately to get count of SW disabled APICs right */ apic_set_spiv (apic, *((u32 *)(s->regs +APIC_SPIV )));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 372/869 KVM: x86: Move kvm_set_apic_base() implementation to lapic.c (from x86.c)
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit c9c9acfcd5738fb292e670a582e4333a1187004c ]
Move kvm_set_apic_base() to lapic.c so that the bulk of KVM's local APIC code resides in lapic.c, regardless of whether or not KVM is emulating the local APIC in-kernel. This will also allow making various helpers visible only to lapic.c.
No functional change intended.
Stable-dep-of: bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
--- arch/x86/kvm/lapic.c | 21 +++++++++++++++++++++ arch/x86/kvm/x86.c | 21 --------------------- 2 files changed, 21 insertions(+), 21 deletions(-)
arch/x86/kvm/lapic.c +21 -0
@@ -2656,6 +2656,27 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value) } } +int kvm_set_apic_base (struct kvm_vcpu *vcpu,struct msr_data *msr_info) +{ +enum lapic_mode old_mode =kvm_get_apic_mode (vcpu); +enum lapic_mode new_mode =kvm_apic_mode (msr_info->data); +u64 reserved_bits =kvm_vcpu_reserved_gpa_bits_raw (vcpu) |0x2ff | + (guest_cpuid_has (vcpu,X86_FEATURE_X2APIC ) ?0 :X2APIC_ENABLE ); + +if ((msr_info->data & reserved_bits) !=0 || new_mode ==LAPIC_MODE_INVALID ) +return 1 ; +if (!msr_info->host_initiated) { +if (old_mode ==LAPIC_MODE_X2APIC && new_mode ==LAPIC_MODE_XAPIC ) +return 1 ; +if (old_mode ==LAPIC_MODE_DISABLED && new_mode ==LAPIC_MODE_X2APIC ) +return 1 ; + } + +kvm_lapic_set_base (vcpu, msr_info->data); +kvm_recalculate_apic_map (vcpu->kvm); +return 0 ; +} +void kvm_apic_update_apicv (struct kvm_vcpu *vcpu) {struct kvm_lapic *apic = vcpu->arch.apic;
arch/x86/kvm/x86.c +0 -21
@@ -658,27 +658,6 @@ static void drop_user_return_notifiers(void)kvm_on_user_return (&msrs->urn); } -int kvm_set_apic_base (struct kvm_vcpu *vcpu,struct msr_data *msr_info) -{ -enum lapic_mode old_mode =kvm_get_apic_mode (vcpu); -enum lapic_mode new_mode =kvm_apic_mode (msr_info->data); -u64 reserved_bits =kvm_vcpu_reserved_gpa_bits_raw (vcpu) |0x2ff | - (guest_cpuid_has (vcpu,X86_FEATURE_X2APIC ) ?0 :X2APIC_ENABLE ); - -if ((msr_info->data & reserved_bits) !=0 || new_mode ==LAPIC_MODE_INVALID ) -return 1 ; -if (!msr_info->host_initiated) { -if (old_mode ==LAPIC_MODE_X2APIC && new_mode ==LAPIC_MODE_XAPIC ) -return 1 ; -if (old_mode ==LAPIC_MODE_DISABLED && new_mode ==LAPIC_MODE_X2APIC ) -return 1 ; - } - -kvm_lapic_set_base (vcpu, msr_info->data); -kvm_recalculate_apic_map (vcpu->kvm); -return 0 ; -} -/* * Handle a fault on a hardware virtualization (VMX or SVM) instruction. *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 373/869 KVM: x86: Rename APIC base setters to better capture their relationship
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 7d1cb7cee94ffd913cb3b70aa1c3538f195c1f23 ]
Rename kvm_set_apic_base() and kvm_lapic_set_base() to kvm_apic_set_base() and __kvm_apic_set_base() respectively to capture that the underscores version is a "special" variant (it exists purely to avoid recalculating the optimized map multiple times when stuffing the RESET value).
Opportunistically add a comment explaining why kvm_lapic_reset() uses the inner helper. Note, KVM deliberately invokes kvm_arch_vcpu_create() while kvm->lock is NOT held so that vCPU setup isn't serialized if userspace is creating multiple/all vCPUs in parallel. I.e. triggering an extra recalculation is not limited to theoretical/rare edge cases, and so is worth avoiding.
No functional change intended.
Stable-dep-of: bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
--- arch/x86/kvm/lapic.c | 15 +++++++++++---- arch/x86/kvm/lapic.h | 3 +-- arch/x86/kvm/regs.c | 2 +- arch/x86/kvm/x86.c | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-)
arch/x86/kvm/lapic.c +11 -4
@@ -2608,7 +2608,7 @@ u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu)return (tpr &0xf0 ) >>4 ; } -void kvm_lapic_set_base (struct kvm_vcpu *vcpu,u64 value) +static void __kvm_apic_set_base (struct kvm_vcpu *vcpu,u64 value) {u64 old_value = vcpu->arch.apic_base;struct kvm_lapic *apic = vcpu->arch.apic;
@@ -2656,7 +2656,7 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value) } } -int kvm_set_apic_base (struct kvm_vcpu *vcpu,struct msr_data *msr_info) +int kvm_apic_set_base (struct kvm_vcpu *vcpu,struct msr_data *msr_info) {enum lapic_mode old_mode =kvm_get_apic_mode (vcpu);enum lapic_mode new_mode =kvm_apic_mode (msr_info->data);
@@ -2672,7 +2672,7 @@ int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info)return 1 ; } -kvm_lapic_set_base (vcpu, msr_info->data); +__kvm_apic_set_base (vcpu, msr_info->data);kvm_recalculate_apic_map (vcpu->kvm);return 0 ; }
@@ -2787,7 +2787,14 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) msr_val =APIC_DEFAULT_PHYS_BASE |MSR_IA32_APICBASE_ENABLE ;if (kvm_vcpu_is_reset_bsp (vcpu)) msr_val |=MSR_IA32_APICBASE_BSP ; -kvm_lapic_set_base (vcpu, msr_val); + +/* +* Use the inner helper to avoid an extra recalcuation of the +* optimized APIC map if some other task has dirtied the map. +* The recalculation needed for this vCPU will be done after +* all APIC state has been initialized (see below). +*/ +__kvm_apic_set_base (vcpu, msr_val); }if (!apic)
arch/x86/kvm/lapic.h +1 -2
@@ -95,7 +95,6 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event);u64 kvm_lapic_get_cr8 (struct kvm_vcpu *vcpu);void kvm_lapic_set_tpr (struct kvm_vcpu *vcpu,unsigned long cr8);void kvm_lapic_set_eoi (struct kvm_vcpu *vcpu); -void kvm_lapic_set_base (struct kvm_vcpu *vcpu,u64 value);void kvm_recalculate_apic_map (struct kvm *kvm);void kvm_apic_set_version (struct kvm_vcpu *vcpu);void kvm_apic_after_set_mcg_cap (struct kvm_vcpu *vcpu);
@@ -117,7 +116,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map);void kvm_apic_send_ipi (struct kvm_lapic *apic,u32 icr_low,u32 icr_high); -int kvm_set_apic_base (struct kvm_vcpu *vcpu,struct msr_data *msr_info); +int kvm_apic_set_base (struct kvm_vcpu *vcpu,struct msr_data *msr_info);int kvm_apic_get_state (struct kvm_vcpu *vcpu,struct kvm_lapic_state *s);int kvm_apic_set_state (struct kvm_vcpu *vcpu,struct kvm_lapic_state *s);void kvm_apic_update_hwapic_isr (struct kvm_vcpu *vcpu);
arch/x86/kvm/regs.c +1 -1
@@ -572,7 +572,7 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs, apic_base_msr.data = sregs->apic_base; apic_base_msr.host_initiated = true; -if (kvm_set_apic_base (vcpu, &apic_base_msr)) +if (kvm_apic_set_base (vcpu, &apic_base_msr))return -EINVAL ;if (vcpu->arch.guest_state_protected)
arch/x86/kvm/x86.c +1 -1
@@ -3454,7 +3454,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)case MSR_MTRRdefType:return kvm_mtrr_set_msr (vcpu, msr, data);case MSR_IA32_APICBASE : -return kvm_set_apic_base (vcpu, msr_info); +return kvm_apic_set_base (vcpu, msr_info); case APIC_BASE_MSR ... APIC_BASE_MSR + 0xff:return kvm_x2apic_msr_write (vcpu, msr, data);case MSR_IA32_TSC_DEADLINE :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 374/869 KVM: x86: Move update_cr8_intercept() to lapic.c
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit c7722e5e1daeeabbd9f969554d52bb7158120b27 ]
Move update_cr8_intercept() to lapic.c so that it's globally visible in anticipation of extracting most of the register-specific code out of x86.c and into a new compilation unit. Opportunistically prefix the helper kvm_lapic_ to make its role/scope more obvious.
No functional change intended.
Stable-dep-of: bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
--- arch/x86/kvm/lapic.c | 26 ++++++++++++++++++++++++++ arch/x86/kvm/lapic.h | 1 + arch/x86/kvm/regs.c | 2 +- arch/x86/kvm/x86.c | 31 ++----------------------------- arch/x86/kvm/x86.h | 1 - 5 files changed, 30 insertions(+), 31 deletions(-)
arch/x86/kvm/lapic.c +26 -0
@@ -2608,6 +2608,32 @@ u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu)return (tpr &0xf0 ) >>4 ; } +void kvm_lapic_update_cr8_intercept (struct kvm_vcpu *vcpu) +{ +int max_irr, tpr; + +if (!kvm_x86_ops.update_cr8_intercept) +return ; + +if (!lapic_in_kernel (vcpu)) +return ; + +if (vcpu->arch.apic->apicv_active) +return ; + +if (!vcpu->arch.apic->vapic_addr) + max_irr =kvm_lapic_find_highest_irr (vcpu); +else + max_irr =-1 ; + +if (max_irr !=-1 ) + max_irr >>=4 ; + + tpr =kvm_lapic_get_cr8 (vcpu); + +kvm_x86_call (update_cr8_intercept)(vcpu, tpr, max_irr); +} +static void __kvm_apic_set_base (struct kvm_vcpu *vcpu,u64 value) {u64 old_value = vcpu->arch.apic_base;
arch/x86/kvm/lapic.h +1 -0
@@ -94,6 +94,7 @@ int kvm_apic_accept_events(struct kvm_vcpu *vcpu);void kvm_lapic_reset (struct kvm_vcpu *vcpu,bool init_event);u64 kvm_lapic_get_cr8 (struct kvm_vcpu *vcpu);void kvm_lapic_set_tpr (struct kvm_vcpu *vcpu,unsigned long cr8); +void kvm_lapic_update_cr8_intercept (struct kvm_vcpu *vcpu);void kvm_lapic_set_eoi (struct kvm_vcpu *vcpu);void kvm_recalculate_apic_map (struct kvm *kvm);void kvm_apic_set_version (struct kvm_vcpu *vcpu);
arch/x86/kvm/regs.c +1 -1
@@ -621,7 +621,7 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,kvm_set_segment (vcpu, &sregs->tr,VCPU_SREG_TR );kvm_set_segment (vcpu, &sregs->ldt,VCPU_SREG_LDTR ); -update_cr8_intercept (vcpu); +kvm_lapic_update_cr8_intercept (vcpu);/* Older userspace won't unhalt the vcpu on reset. */ if (kvm_vcpu_is_bsp(vcpu) && kvm_rip_read(vcpu) == 0xfff0 &&
arch/x86/kvm/x86.c +2 -29
@@ -4697,7 +4697,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, r =kvm_apic_set_state (vcpu, s);if (r)return r; -update_cr8_intercept (vcpu); +kvm_lapic_update_cr8_intercept (vcpu);return 0 ; }
@@ -9765,33 +9765,6 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu) kvm_run->flags |=KVM_RUN_X86_GUEST_MODE ; } -void update_cr8_intercept (struct kvm_vcpu *vcpu) -{ -int max_irr, tpr; - -if (!kvm_x86_ops.update_cr8_intercept) -return ; - -if (!lapic_in_kernel (vcpu)) -return ; - -if (vcpu->arch.apic->apicv_active) -return ; - -if (!vcpu->arch.apic->vapic_addr) - max_irr =kvm_lapic_find_highest_irr (vcpu); -else - max_irr =-1 ; - -if (max_irr !=-1 ) - max_irr >>=4 ; - - tpr =kvm_lapic_get_cr8 (vcpu); - -kvm_x86_call (update_cr8_intercept)(vcpu, tpr, max_irr); -} - -int kvm_check_nested_events (struct kvm_vcpu *vcpu) {if (kvm_test_request (KVM_REQ_TRIPLE_FAULT , vcpu)) {
@@ -10494,7 +10467,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)kvm_x86_call (enable_irq_window)(vcpu);if (kvm_lapic_enabled (vcpu)) { -update_cr8_intercept (vcpu); +kvm_lapic_update_cr8_intercept (vcpu);kvm_lapic_sync_to_vapic (vcpu); } }
arch/x86/kvm/x86.h +0 -1
@@ -641,6 +641,5 @@ int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu, struct kvm_debugregs *dbgregs);void kvm_invalidate_pcid (struct kvm_vcpu *vcpu,unsigned long pcid);void kvm_handle_exception_payload_quirk (struct kvm_vcpu *vcpu); -void update_cr8_intercept (struct kvm_vcpu *vcpu);#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/869 KVM: x86: Unconditionally recompute CR8 intercept on PPR update
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carlos López <[email protected]>
[ Upstream commit bb365a506b1e6fb050c0fceaad354fe395385ef0 ]
The TPR_THRESHOLD field in the VMCS is used by VMX to induce VM exits when the guest's virtual TPR falls under the specified threshold, allowing KVM to inject previously masked interrupts.
KVM handles these VM exits in handle_tpr_below_threshold(). Commit eb90f3417a0c ("KVM: vmx: speed up TPR below threshold vmexits") optimized this function by calling apic_update_ppr() instead of raising KVM_REQ_EVENT. apic_update_ppr() then raises KVM_REQ_EVENT if there is a pending, deliverable interrupt.
However, if there are no new interrupts pending, apic_update_ppr() does not issue the request. Thus, kvm_lapic_update_cr8_intercept() and vmx_update_cr8_intercept() are not called before VM entry, which results in a high, stale TPR_THRESHOLD. This is problematic due to the following sentence in 28.2.1.1 "VM-Execution Control Fields" in the SDM:
The following check is performed if the “use TPR shadow” VM-execution control is 1 and the “virtualize APIC accesses” and “virtual-interrupt delivery” VM-execution controls are both 0: the value of bits 3:0 of the TPR threshold VM-execution control field should not be greater than the value of bits 7:4 of VTPR.
This error condition is typically not observed when KVM runs on a bare metal system because modern processors support APICv, which enables virtual-interrupt delivery, and which KVM uses when possible. This causes the processor to no longer generate TPR-below-threshold exits and to no longer check TPR_THRESHOLD on entry. However, when running on older platforms, or under nested virtualization on a hypervisor that does not support virtual-interrupt delivery and enforces this check (like Hyper-V) this can cause a VM entry failure with hardware error 0x7, as seen in [1].
Call kvm_lapic_update_cr8_intercept() if apic_update_ppr() does not find a deliverable interrupt (and thus does not raise KVM_REQ_EVENT). Remove calls to kvm_lapic_update_cr8_intercept() on paths that end up in apic_update_ppr(), as they now become redundant. This ensures that any path that updates the guest's PPR also figures out if KVM needs to wait for a TPR change (using TPR_THRESHOLD on VMX or CR8 intercepts on SVM).
Message-ID: <[email protected]>
--- arch/x86/kvm/lapic.c | 2 ++ arch/x86/kvm/regs.c | 4 +--- arch/x86/kvm/x86.c | 1 - 3 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/kvm/lapic.c +2 -0
@@ -994,6 +994,8 @@ static void apic_update_ppr(struct kvm_lapic *apic)if (__apic_update_ppr (apic, &ppr) &&apic_has_interrupt_for_ppr (apic, ppr) !=-1 )kvm_make_request (KVM_REQ_EVENT , apic->vcpu); +else +kvm_lapic_update_cr8_intercept (apic->vcpu); }void kvm_apic_update_ppr (struct kvm_vcpu *vcpu)
arch/x86/kvm/regs.c +1 -3
@@ -591,8 +591,6 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,kvm_register_mark_dirty (vcpu,VCPU_EXREG_CR3 );kvm_x86_call (post_set_cr3)(vcpu, sregs->cr3); -kvm_set_cr8 (vcpu, sregs->cr8); - *mmu_reset_needed |= vcpu->arch.efer != sregs->efer;kvm_x86_call (set_efer)(vcpu, sregs->efer);
@@ -621,7 +619,7 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,kvm_set_segment (vcpu, &sregs->tr,VCPU_SREG_TR );kvm_set_segment (vcpu, &sregs->ldt,VCPU_SREG_LDTR ); -kvm_lapic_update_cr8_intercept (vcpu); +kvm_set_cr8 (vcpu, sregs->cr8);/* Older userspace won't unhalt the vcpu on reset. */ if (kvm_vcpu_is_bsp(vcpu) && kvm_rip_read(vcpu) == 0xfff0 &&
arch/x86/kvm/x86.c +0 -1
@@ -4697,7 +4697,6 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, r =kvm_apic_set_state (vcpu, s);if (r)return r; -kvm_lapic_update_cr8_intercept (vcpu);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/869 KVM: nVMX: Put vmcs12 pages if nested VM-Enter fails due to invalid guest state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 2f2312c422fd2695da772cecb30c69994b795964 ]
Put all vmcs12 pages if KVM synthesizes a nested VM-Exit due to invalid guest while emulating VMLAUNCH or VMRESUME. The invalid guest state path doesn't use nested_vmx_vmexit() as that API is intended to be used if and only if L2 is active, and the open coded equivalent neglects to put the vmcs12 pages. Failure to put the vmcs12 pages leaks any pinned pages (and/or mappings) if L1 retries VMLAUNCH/VMRESUME.
Note, the !from_vmenter scenario doesn't suffer the same problem, as vmx_get_nested_state_pages() only gets/pins/maps the vmcs12 pages if L2 is active, i.e. if a "full" VM-Exit is guaranteed before KVM will retry getting vmcs12 pages.
--- arch/x86/kvm/vmx/nested.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kvm/vmx/nested.c +5 -0
@@ -3692,6 +3692,11 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,if (!from_vmentry)return NVMX_VMENTRY_VMEXIT ; +kvm_vcpu_unmap (vcpu, &vmx->nested.apic_access_page_map, false); +kvm_vcpu_unmap (vcpu, &vmx->nested.virtual_apic_map, true); +kvm_vcpu_unmap (vcpu, &vmx->nested.pi_desc_map, true); + vmx->nested.pi_desc =NULL ; +load_vmcs12_host_state (vcpu, vmcs12); vmcs12->vm_exit_reason = exit_reason.full;if (enable_shadow_vmcs ||nested_vmx_is_evmptr12_valid (vmx))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/869 drm/amdgpu: Fix kernel panic during driver load failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harish Kasiviswanathan <[email protected]>
[ Upstream commit a279bd143b3c184358b658e43a057e31ee8c4de5 ]
Avoid kernel panic if MES init fails during driver load. The KIQ ring is falsely marked as ready as ASICs that use MES, KIQ is owned by MES.
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:gfx_v12_1_wait_reg_mem+0x5a/0x1f0 [amdgpu] Call Trace: gfx_v12_1_ring_emit_reg_write_reg_wait+0x1f/0x30 [amdgpu] amdgpu_gmc_fw_reg_write_reg_wait+0xb2/0x190 [amdgpu] amdgpu_gmc_flush_gpu_tlb+0x1cc/0x230 [amdgpu] amdgpu_gart_invalidate_tlb+0x81/0xa0 [amdgpu] amdgpu_gart_unbind+0x72/0x90 [amdgpu] amdgpu_ttm_backend_unbind+0xa4/0xb0 [amdgpu] amdgpu_ttm_tt_unpopulate+0x13/0xd0 [amdgpu] amdttm_tt_unpopulate+0x29/0x70 [amdttm] ttm_bo_put+0x1eb/0x360 [amdttm] amdgpu_bo_free_kernel+0xf9/0x1f0 [amdgpu] amdgpu_ih_ring_fini+0x5a/0x90 [amdgpu] amdgpu_irq_fini_hw+0x58/0x80 [amdgpu] amdgpu_device_fini_hw+0x4e0/0x5b0 [amdgpu] amdgpu_driver_load_kms+0x60/0xa0 [amdgpu] amdgpu_pci_probe+0x28e/0x6d0 [amdgpu] pci_device_probe+0x19f/0x220 really_probe+0x1ed/0x340 driver_probe_device+0x1e/0x80 __driver_attach+0xd3/0x1a0 bus_for_each_dev+0x68/0xa0 bus_add_driver+0x19f/0x270 driver_register+0x5d/0xf0 do_one_initcall+0xac/0x200 do_init_module+0x1ec/0x280 __se_sys_finit_module+0x2de/0x310 do_syscall_64+0x6a/0x250 entry_SYSCALL_64_after_hwframe+0x4b/0x53
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +11 -2
@@ -3398,10 +3398,19 @@ static int gfx_v12_0_cp_resume(struct amdgpu_device *adev)gfx_v12_0_cp_gfx_enable (adev, true); } -if (adev->enable_mes_kiq && adev->mes.kiq_hw_init) +if (adev->enable_mes_kiq && adev->mes.kiq_hw_init) { r =amdgpu_mes_kiq_hw_init (adev); -else +/* +* With MES, GFX KIQ ring is owned by the MES and is never +* initialized/used directly by the driver, so it must +* not be left flagged as ready. mes_v12_0_hw_init() clears +* but clear here if MES init fails +*/ +if (r) + adev->gfx.kiq[0 ].ring.sched.ready = false; + }else { r =gfx_v12_0_kiq_resume (adev); + }if (r)return r;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/869 media: stm32: dcmipp: use v4l2_subdev_is_streaming
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alain Volmat <[email protected]>
[ Upstream commit 255e0cc62b9b1afad9b9ba7738d5c53cd0d157fb ]
Rely on v4l2_subdev_is_streaming in order to know if the subdev is streaming or not instead of relying on a local variable.
Stable-dep-of: ffc8eec06378 ("media: stm32-dcmipp: Return queued buffers on start_streaming() failure")
--- .../media/platform/st/stm32/stm32-dcmipp/dcmipp-byteproc.c | 6 +----- .../media/platform/st/stm32/stm32-dcmipp/dcmipp-parallel.c | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-)
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-byteproc.c +1 -5
@@ -78,7 +78,6 @@ struct dcmipp_byteproc_device {struct v4l2_subdev sd;struct device *dev;void __iomem *regs; -bool streaming; };static const struct v4l2_mbus_framefmt fmt_default = {
@@ -239,11 +238,10 @@ static int dcmipp_byteproc_set_fmt(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - struct dcmipp_byteproc_device *byteproc = v4l2_get_subdevdata(sd); struct v4l2_mbus_framefmt *mf;struct v4l2_rect *crop, *compose; -if (byteproc->streaming) +if (v4l2_subdev_is_streaming (sd))return -EBUSY ; mf =v4l2_subdev_state_get_format (sd_state, fmt->pad);
@@ -495,8 +493,6 @@ static int dcmipp_byteproc_s_stream(struct v4l2_subdev *sd, int enable) } } - byteproc->streaming = enable; -return 0 ; }
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-parallel.c +1 -4
@@ -129,7 +129,6 @@ struct dcmipp_par_device {struct v4l2_subdev sd;struct device *dev;void __iomem *regs; -bool streaming; };static const struct v4l2_mbus_framefmt fmt_default = {
@@ -230,7 +229,7 @@ static int dcmipp_par_set_fmt(struct v4l2_subdev *sd,struct dcmipp_par_device *par =v4l2_get_subdevdata (sd);struct v4l2_mbus_framefmt *mf; -if (par->streaming) +if (v4l2_subdev_is_streaming (sd))return -EBUSY ; mf =v4l2_subdev_state_get_format (sd_state, fmt->pad);
@@ -370,8 +369,6 @@ static int dcmipp_par_s_stream(struct v4l2_subdev *sd, int enable)reg_clear (par,DCMIPP_PRCR ,DCMIPP_PRCR_ENABLE ); } - par->streaming = enable; -return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/869 media: stm32: dcmipp: replace s_stream with enable/disable_streams
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alain Volmat <[email protected]>
[ Upstream commit b0f3cc70893289d0d74a1523e26d60346f747ebe ]
Replace s_stream ops with enable_streams and disable_streams. At the same time, use v4l2_subdev_enable_streams and v4l2_subdev_disable_streams functions instead of direct s_stream calls.
Stable-dep-of: ffc8eec06378 ("media: stm32-dcmipp: Return queued buffers on start_streaming() failure")
--- .../st/stm32/stm32-dcmipp/dcmipp-bytecap.c | 49 ++++---- .../st/stm32/stm32-dcmipp/dcmipp-byteproc.c | 98 +++++++++------- .../st/stm32/stm32-dcmipp/dcmipp-parallel.c | 107 ++++++++++-------- 3 files changed, 139 insertions(+), 115 deletions(-)
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-bytecap.c +20 -29
@@ -112,6 +112,7 @@ struct dcmipp_bytecap_device {u32 sequence;struct media_pipeline pipe;struct v4l2_subdev *s_subdev; +u32 s_subdev_pad_nb;enum dcmipp_state state;
@@ -337,33 +338,6 @@ static const struct v4l2_ioctl_ops dcmipp_bytecap_ioctl_ops = { .vidioc_streamoff = vb2_ioctl_streamoff, }; -static int dcmipp_pipeline_s_stream (struct dcmipp_bytecap_device *vcap, -int state) -{ -struct media_pad *pad; -int ret; - -/* -* Get source subdev - since link is IMMUTABLE, pointer is cached -* within the dcmipp_bytecap_device structure -*/ -if (!vcap->s_subdev) { - pad =media_pad_remote_pad_first (&vcap->vdev.entity.pads[0 ]); -if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) -return -EINVAL ; - vcap->s_subdev =media_entity_to_v4l2_subdev (pad->entity); - } - - ret =v4l2_subdev_call (vcap->s_subdev, video, s_stream, state); -if (ret <0 ) { -dev_err (vcap->dev,"failed to %s streaming (%d)\n" , - state ?"start" :"stop" , ret); -return ret; - } - -return 0 ; -} -static void dcmipp_start_capture (struct dcmipp_bytecap_device *vcap,struct dcmipp_buf *buf) {
@@ -395,11 +369,24 @@ static int dcmipp_bytecap_start_streaming(struct vb2_queue *vq,struct dcmipp_bytecap_device *vcap =vb2_get_drv_priv (vq);struct media_entity *entity = &vcap->vdev.entity;struct dcmipp_buf *buf; +struct media_pad *pad;int ret; vcap->sequence =0 ;memset (&vcap->count,0 ,sizeof (vcap->count)); +/* +* Get source subdev - since link is IMMUTABLE, pointer is cached +* within the dcmipp_bytecap_device structure +*/ +if (!vcap->s_subdev) { + pad =media_pad_remote_pad_first (&vcap->vdev.entity.pads[0 ]); +if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) +return -EINVAL ; + vcap->s_subdev =media_entity_to_v4l2_subdev (pad->entity); + vcap->s_subdev_pad_nb = pad->index; + } + ret =pm_runtime_resume_and_get (vcap->dev);if (ret <0 ) { dev_err(vcap->dev, "%s: Failed to start streaming, cannot get sync (%d)\n",
@@ -414,7 +401,8 @@ static int dcmipp_bytecap_start_streaming(struct vb2_queue *vq, goto err_pm_put; } - ret =dcmipp_pipeline_s_stream (vcap,1 ); + ret =v4l2_subdev_enable_streams (vcap->s_subdev, + vcap->s_subdev_pad_nb,BIT_ULL (0 ));if (ret) goto err_media_pipeline_stop;
@@ -482,7 +470,10 @@ static void dcmipp_bytecap_stop_streaming(struct vb2_queue *vq)int ret;u32 status; -dcmipp_pipeline_s_stream (vcap,0 ); + ret =v4l2_subdev_disable_streams (vcap->s_subdev, + vcap->s_subdev_pad_nb,BIT_ULL (0 )); +if (ret) +dev_warn (vcap->dev,"Failed to disable stream\n" );/* Stop the media pipeline */ media_pipeline_stop (vcap->vdev.entity.pads);
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-byteproc.c +57 -41
133 lines not on this page · raw message
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-parallel.c +62 -45
143 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/869 media: stm32-dcmipp: Return queued buffers on start_streaming() failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valery Borovsky <[email protected]>
[ Upstream commit ffc8eec06378a340d708c889184ab3e14b57d540 ]
The vb2 framework hands buffers to the driver via buf_queue() before calling start_streaming(). If start_streaming() returns an error without first returning those buffers via vb2_buffer_done(), vb2_start_streaming() fires WARN_ON(owned_by_drv_count) and the queued buffers leak.
dcmipp_bytecap_start_streaming() returned -EINVAL when the source subdevice could not be resolved from the media graph, before pm_runtime_resume_and_get() and media_pipeline_start() had been called. The remaining error paths already converge on the err_buffer_done label, which calls dcmipp_bytecap_all_buffers_done(..., VB2_BUF_STATE_QUEUED). Jump to that label directly: the intermediate err_pm_put / err_media_pipeline_stop labels are skipped, which is correct because nothing they would undo has happened yet.
This mirrors the uvcvideo fix in commit 4cf3b6fd54eb ("media: uvcvideo:
Return queued buffers on start_streaming() failure").
--- .../media/platform/st/stm32/stm32-dcmipp/dcmipp-bytecap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-bytecap.c +4 -2
@@ -381,8 +381,10 @@ static int dcmipp_bytecap_start_streaming(struct vb2_queue *vq,*/ if (!vcap->s_subdev) { pad =media_pad_remote_pad_first (&vcap->vdev.entity.pads[0 ]); -if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) -return -EINVAL ; +if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) { + ret = -EINVAL ; + goto err_buffer_done; + } vcap->s_subdev =media_entity_to_v4l2_subdev (pad->entity); vcap->s_subdev_pad_nb = pad->index; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/869 drm/vc4: Shut down BO cache timer before teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
[ Upstream commit 6273dd3ffb54ec581855b82ae77331b66028249c ]
The BO cache timer callback schedules time_work, and time_work can rearm the timer through vc4_bo_cache_free_old().
vc4_bo_cache_destroy() deletes the timer and then cancels the work, which does not break that cycle: the work being cancelled can rearm the timer, and the timer then queues work again after teardown.
Use timer_shutdown_sync() instead, so the timer cannot be rearmed and the cycle ends with cancel_work_sync().
--- drivers/gpu/drm/vc4/vc4_bo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_bo.c +1 -1
@@ -1050,7 +1050,7 @@ static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)struct vc4_dev *vc4 =to_vc4_dev (dev);int i; -del_timer (&vc4->bo_cache.time_timer); +timer_shutdown_sync (&vc4->bo_cache.time_timer);cancel_work_sync (&vc4->bo_cache.time_work);vc4_bo_cache_purge (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/869 drm/amdgpu: Use dbg level for VBIOS check messages
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lijo Lazar <[email protected]>
[ Upstream commit 635c659fceed82f934623188471ff604e098aab7 ]
Driver has different ways to fetch VBIOS. If one of the methods doesn't find an authentic one, it will show misleading info messages eventhough a subsequent method finds a valid VBIOS. Keep the message level at debug and add device context.
Stable-dep-of: 65bff2661760 ("drm/amdgpu: Release VFCT ACPI table reference")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +14 -12
@@ -48,35 +48,37 @@/* Check if current bios is an ATOM BIOS. * Return true if it is ATOM BIOS. Otherwise, return false. */ -static bool check_atom_bios (uint8_t *bios,size_t size) +static bool check_atom_bios (struct amdgpu_device *adev,size_t size) {uint16_t tmp, bios_header_start; +uint8_t *bios = adev->bios;if (!bios || size <0x49 ) { -DRM_INFO ("vbios mem is null or mem size is wrong\n" ); +dev_dbg (adev->dev,"VBIOS mem is null or mem size is wrong\n" );return false; }if (!AMD_IS_VALID_VBIOS (bios)) { -DRM_INFO ("BIOS signature incorrect %x %x\n" , bios[0 ], bios[1 ]); +dev_dbg (adev->dev,"VBIOS signature incorrect %x %x\n" , bios[0 ], + bios[1 ]);return false; } bios_header_start = bios[0x48 ] | (bios[0x49 ] <<8 );if (!bios_header_start) { -DRM_INFO ("Can't locate bios header\n" ); +dev_dbg (adev->dev,"Can't locate VBIOS header\n" );return false; } tmp = bios_header_start +4 ;if (size < tmp) { -DRM_INFO ("BIOS header is broken\n" ); +dev_dbg (adev->dev,"VBIOS header is broken\n" );return false; }if (!memcmp (bios + tmp,"ATOM" ,4 ) || !memcmp (bios + tmp,"MOTA" ,4 )) { -DRM_DEBUG ("ATOMBIOS detected\n" ); +dev_dbg (adev->dev,"ATOMBIOS detected\n" );return true; }
@@ -119,7 +121,7 @@ static bool amdgpu_read_bios_from_vram(struct amdgpu_device *adev)memcpy_fromio (adev->bios, bios, size);iounmap (bios); -if (!check_atom_bios (adev->bios, size)) { +if (!check_atom_bios (adev, size)) {kfree (adev->bios);return false; }
@@ -147,7 +149,7 @@ bool amdgpu_read_bios(struct amdgpu_device *adev)memcpy_fromio (adev->bios, bios, size);pci_unmap_rom (adev->pdev, bios); -if (!check_atom_bios (adev->bios, size)) { +if (!check_atom_bios (adev, size)) {kfree (adev->bios);return false; }
@@ -187,7 +189,7 @@ static bool amdgpu_read_bios_from_rom(struct amdgpu_device *adev)/* read complete BIOS */ amdgpu_asic_read_bios_from_rom (adev, adev->bios, len); -if (!check_atom_bios (adev->bios, len)) { +if (!check_atom_bios (adev, len)) {kfree (adev->bios);return false; }
@@ -217,7 +219,7 @@ static bool amdgpu_read_platform_bios(struct amdgpu_device *adev)memcpy_fromio (adev->bios, bios, romlen);iounmap (bios); -if (!check_atom_bios (adev->bios, romlen)) +if (!check_atom_bios (adev, romlen)) goto free_bios; adev->bios_size = romlen;
@@ -325,7 +327,7 @@ static bool amdgpu_atrm_get_bios(struct amdgpu_device *adev)break ; } -if (!check_atom_bios (adev->bios, size)) { +if (!check_atom_bios (adev, size)) {kfree (adev->bios);return false; }
@@ -425,7 +427,7 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev) vhdr->ImageLength, GFP_KERNEL); -if (!check_atom_bios (adev->bios, vhdr->ImageLength)) { +if (!check_atom_bios (adev, vhdr->ImageLength)) {kfree (adev->bios);return false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/869 drm/amdgpu: Add wrapper for freeing vbios memory
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lijo Lazar <[email protected]>
[ Upstream commit e986e89659e18ba986db044df58f165042817dc3 ]
Use bios_release wrapper to release memory allocated for vbios image and reset the variables.
v2:
Use the same wrapper for clean up in sw_fini (Alex Deucher)
Stable-dep-of: 65bff2661760 ("drm/amdgpu: Release VFCT ACPI table reference")
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 20 ++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +-- 3 files changed, 16 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -409,6 +409,7 @@ bool amdgpu_get_bios(struct amdgpu_device *adev);bool amdgpu_read_bios (struct amdgpu_device *adev);bool amdgpu_soc15_read_bios_from_rom (struct amdgpu_device *adev,u8 *bios,u32 length_bytes); +void amdgpu_bios_release (struct amdgpu_device *adev);/* * Clocks */
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +14 -6
@@ -85,6 +85,13 @@ static bool check_atom_bios(struct amdgpu_device *adev, size_t size)return false; } +void amdgpu_bios_release (struct amdgpu_device *adev) +{ +kfree (adev->bios); + adev->bios =NULL ; + adev->bios_size =0 ; +} +/* If you boot an IGP board with a discrete card as the primary, * the IGP rom is not accessible via the rom bar as the IGP rom is * part of the system bios. On boot, the system bios puts a
@@ -122,7 +129,7 @@ static bool amdgpu_read_bios_from_vram(struct amdgpu_device *adev)iounmap (bios);if (!check_atom_bios (adev, size)) { -kfree (adev->bios); +amdgpu_bios_release (adev);return false; }
@@ -150,7 +157,7 @@ bool amdgpu_read_bios(struct amdgpu_device *adev)pci_unmap_rom (adev->pdev, bios);if (!check_atom_bios (adev, size)) { -kfree (adev->bios); +amdgpu_bios_release (adev);return false; }
@@ -190,7 +197,7 @@ static bool amdgpu_read_bios_from_rom(struct amdgpu_device *adev)amdgpu_asic_read_bios_from_rom (adev, adev->bios, len);if (!check_atom_bios (adev, len)) { -kfree (adev->bios); +amdgpu_bios_release (adev);return false; }
@@ -226,7 +233,8 @@ static bool amdgpu_read_platform_bios(struct amdgpu_device *adev)return true; free_bios: -kfree (adev->bios); +amdgpu_bios_release (adev); +return false; }
@@ -328,7 +336,7 @@ static bool amdgpu_atrm_get_bios(struct amdgpu_device *adev) }if (!check_atom_bios (adev, size)) { -kfree (adev->bios); +amdgpu_bios_release (adev);return false; } adev->bios_size = size;
@@ -428,7 +436,7 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev) GFP_KERNEL);if (!check_atom_bios (adev, vhdr->ImageLength)) { -kfree (adev->bios); +amdgpu_bios_release (adev);return false; } adev->bios_size = vhdr->ImageLength;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -2
@@ -4793,8 +4793,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)if (amdgpu_emu_mode !=1 )amdgpu_atombios_fini (adev); -kfree (adev->bios); - adev->bios =NULL ; +amdgpu_bios_release (adev);kfree (adev->fru_info); adev->fru_info =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/869 drm/amdgpu: Release VFCT ACPI table reference
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 65bff26617607c1331283232016c0e89088c5b78 ]
amdgpu_acpi_vfct_bios() fetches the VFCT table with acpi_get_table() but never releases it. acpi_get_table() takes a reference on the table (incrementing its validation_count and mapping it on the 0->1 transition); without a paired acpi_put_table() the mapping is leaked on every call, whether or not a matching VBIOS image is found.
Route all exit paths after the table is acquired through a common acpi_put_table(). The VBIOS image is copied out with kmemdup() before the table is released, so it remains valid for the caller.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +11 -6
@@ -401,13 +401,14 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)acpi_size tbl_size;UEFI_ACPI_VFCT *vfct;unsigned int offset; +bool r = false;if (!ACPI_SUCCESS (acpi_get_table ("VFCT" ,1 , &hdr)))return false; tbl_size = hdr->length;if (tbl_size <sizeof (UEFI_ACPI_VFCT )) {dev_info (adev->dev,"ACPI VFCT table present but broken (too short #1),skipping\n" ); -return false; + goto out; } vfct = (UEFI_ACPI_VFCT *)hdr;
@@ -420,13 +421,13 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev) offset +=sizeof (VFCT_IMAGE_HEADER );if (offset > tbl_size) {dev_info (adev->dev,"ACPI VFCT image header truncated,skipping\n" ); -return false; + goto out; } offset += vhdr->ImageLength;if (offset > tbl_size) {dev_info (adev->dev,"ACPI VFCT image truncated,skipping\n" ); -return false; + goto out; } if (vhdr->ImageLength &&
@@ -437,15 +438,19 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)if (!check_atom_bios (adev, vhdr->ImageLength)) {amdgpu_bios_release (adev); -return false; + goto out; } adev->bios_size = vhdr->ImageLength; - return true; + r = true; + goto out; } }dev_info (adev->dev,"ACPI VFCT table present but broken (too short #2),skipping\n" ); -return false; + +out: +acpi_put_table (hdr); +return r; }#else static inline bool amdgpu_acpi_vfct_bios (struct amdgpu_device *adev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/869 drm/i915/mst: limit DP MST ESI service loop
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jani Nikula <[email protected]>
[ Upstream commit 005771c18c5b2c98cb4e7517661aea460990fd3f ]
The loop in intel_dp_check_mst_status() keeps servicing interrupts originating from the sink without bound. Add an upper bound to the new interrupts occurring during interrupt processing to not get stuck on potentially stuck sink devices. Use arbitrary 32 tries to clear incoming interrupts in one go.
Discovered using AI-assisted static analysis confirmed by Intel Product Security.
Note: The condition likely pre-dates the commit in the Fixes: tag, but this is about as far back as a backport has any chance of succeeding. Before that, the retry had a goto.
--- drivers/gpu/drm/i915/display/intel_dp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_dp.c +7 -1
@@ -5202,10 +5202,11 @@ intel_dp_check_mst_status(struct intel_dp *intel_dp)struct intel_encoder *encoder = &dig_port->base;bool link_ok = true;bool reprobe_needed = false; +int tries =33 ;drm_WARN_ON_ONCE (&i915->drm, intel_dp->mst.active_links <0 ); -for (;;) { +while (--tries) {u8 esi[4 ] = {};u8 ack[4 ] = {};
@@ -5248,6 +5249,11 @@ intel_dp_check_mst_status(struct intel_dp *intel_dp)if (!link_ok || intel_dp->link.force_retrain)intel_encoder_link_check_queue_work (encoder,0 ); +if (!tries) { +drm_dbg_kms (&i915->drm,"DPRX ESI not clearing, device may be stuck\n" ); + reprobe_needed = true; + } +return !reprobe_needed; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/869 drm/i915/gt: Fix NULL deref on sched_engine alloc failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonas Lahtinen <[email protected]>
[ Upstream commit 82ec992c404c3dc774c5e9f3d4aa858e97187675 ]
Avoid using intel_context_put() before intel_context_init() in execlists_create_virtual() as the kref_put() inside would lead to NULL deref on the IOCTL path when sched_engine allocation fails.
Discovered using AI-assisted static analysis confirmed by Intel Product Security.
--- .../drm/i915/gt/intel_execlists_submission.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +10 -9
@@ -3935,11 +3935,11 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count,struct drm_i915_private *i915 = siblings[0 ]->i915;struct virtual_engine *ve;unsigned int n; -int err; +int err = -ENOMEM ; ve =kzalloc (struct_size (ve, siblings, count),GFP_KERNEL );if (!ve) -return ERR_PTR (-ENOMEM ); + goto err; ve->base.i915 = i915; ve->base.gt = siblings[0 ]->gt;
@@ -3971,10 +3971,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count,intel_engine_init_execlists (&ve->base); ve->base.sched_engine =i915_sched_engine_create (ENGINE_VIRTUAL ); -if (!ve->base.sched_engine) { - err = -ENOMEM ; - goto err_put; - } +if (!ve->base.sched_engine) + goto err_noput; ve->base.sched_engine->private_data = &ve->base; ve->base.cops = &virtual_context_ops;
@@ -3990,10 +3988,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count,intel_context_init (&ve->context, &ve->base); ve->base.breadcrumbs =intel_breadcrumbs_create (NULL ); -if (!ve->base.breadcrumbs) { - err = -ENOMEM ; +if (!ve->base.breadcrumbs) goto err_put; - }for (n =0 ; n < count; n++) {struct intel_engine_cs *sibling = siblings[n];
@@ -4068,8 +4064,13 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count,virtual_engine_initial_hint (ve);return &ve->context; +err_noput: +kfree (ve); + goto err; + err_put:intel_context_put (&ve->context); +err:return ERR_PTR (err); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/869 drm/amdkfd: Check bounds on CRIU restore queue type and mqd size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Francis <[email protected]>
[ Upstream commit 47ea05f246bebc81c7796f56265cffd812cf0601 ]
We weren't checking whether the values provided in the private data in kfd CRIU restore were within bounds.
For queue type, add a KFD_QUEUE_TYPE_MAX and ensure the provided type is less than it.
For mqd_size, add new function mqd_size_from_queue_type and confirm that the provided mqd_size matches expectations.
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 6 +++++ .../drm/amd/amdkfd/kfd_device_queue_manager.h | 2 ++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 ++- .../amd/amdkfd/kfd_process_queue_manager.c | 24 +++++++++++++------ 4 files changed, 27 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -0
@@ -3575,6 +3575,12 @@ bool kfd_dqm_is_queue_in_process(struct device_queue_manager *dqm,dqm_unlock (dqm);return r; } + +size_t mqd_size_from_queue_type (struct device_queue_manager *dqm,enum kfd_queue_type type) +{ +return dqm->mqd_mgrs[get_mqd_type_from_queue_type (type)]->mqd_size; +} +#if defined(CONFIG_DEBUG_FS ) static void seq_reg_dump(struct seq_file *m,
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +2 -0
@@ -327,6 +327,8 @@ int debug_refresh_runlist(struct device_queue_manager *dqm);bool kfd_dqm_is_queue_in_process (struct device_queue_manager *dqm,struct qcm_process_device *qpd,int doorbell_off,u32 *queue_format); +size_t mqd_size_from_queue_type (struct device_queue_manager *dqm, +enum kfd_queue_type type);static inline unsigned int get_sh_mem_bases_32 (struct kfd_process_device *pdd) {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
@@ -440,7 +440,8 @@ enum kfd_queue_type {KFD_QUEUE_TYPE_HIQ ,KFD_QUEUE_TYPE_DIQ ,KFD_QUEUE_TYPE_SDMA_XGMI , -KFD_QUEUE_TYPE_SDMA_BY_ENG_ID +KFD_QUEUE_TYPE_SDMA_BY_ENG_ID , + KFD_QUEUE_TYPE_MAX, }; enum kfd_queue_format {
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +17 -7
@@ -1015,6 +1015,23 @@ int kfd_criu_restore_queue(struct kfd_process *p, goto exit; } + pdd =kfd_process_device_data_by_id (p, q_data->gpu_id); +if (!pdd) { +pr_err ("Failed to get pdd\n" ); + ret = -EINVAL ; + goto exit; + } + +if (q_data->type >=KFD_QUEUE_TYPE_MAX ) { + ret = -EINVAL ; + goto exit; + } + +if (q_data->mqd_size !=mqd_size_from_queue_type (pdd->dev->dqm, q_data->type)) { + ret = -EINVAL ; + goto exit; + } + *priv_data_offset +=sizeof (*q_data); q_extra_data_size = (uint64_t )q_data->ctl_stack_size + q_data->mqd_size;
@@ -1037,13 +1054,6 @@ int kfd_criu_restore_queue(struct kfd_process *p, *priv_data_offset += q_extra_data_size; - pdd =kfd_process_device_data_by_id (p, q_data->gpu_id); -if (!pdd) { -pr_err ("Failed to get pdd\n" ); - ret = -EINVAL ; - goto exit; - } -/* data stored in this order: mqd, ctl_stack */ mqd = q_extra_data; ctl_stack = mqd + q_data->mqd_size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/869 idpf: fix max_vport related crash on allocation error during init
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Emil Tantilov <[email protected]>
[ Upstream commit 237f1f7653b8729169af11fae79f01b90d00b87e ]
Set adapter->max_vports only after successful allocation of vports, netdevs and vport_config buffers. This fixes possible crashes on reset or rmmod, following failed allocation on init
[ 305.981402] idpf 0000:83:00.0: enabling device (0100 -> 0102) [ 305.994464] idpf 0000:83:00.0: Device HW Reset initiated [ 320.416872] BUG: kernel NULL pointer dereference, address: 0000000000000000 [ 320.416918] #PF: supervisor read access in kernel mode [ 320.416942] #PF: error_code(0x0000) - not-present page [ 320.416963] PGD 2099657067 P4D 0 [ 320.416983] Oops: Oops: 0000 [#1] SMP NOPTI ... [ 320.417093] RIP: 0010:idpf_remove+0x118/0x200 [idpf] [ 320.417130] Code: 8b bb 98 09 00 00 e8 17 0f 5b e5 48 8b bb e8 08 00 00 e8 0b 0f 5b e5 66 83 bb 28 06 00 00 00 48 8b bb 20 06 00 00 74 49 31 ed <48> 8b 04 ef 48 85 c0 74 2f 48 8b 78 20 e8 66 58 91 e5 48 8b 83 20 [ 320.417183] RSP: 0018:ff7322212903fdb8 EFLAGS: 00010246 [ 320.417205] RAX: 0000000000000000 RBX: ff4463de40300000 RCX: ff7322212903fd4c [ 320.417228] RDX: 0000000000000001 RSI: ffffffffa7f7d100 RDI: 0000000000000000 [ 320.417250] RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000000 [ 320.417272] R10: 0000000000000001 R11: ff4463de3a638f58 R12: ff4463be89ac7000 [ 320.417294] R13: ff4463be89ac7198 R14: ff4463be94fc7198 R15: ffffffffc0f10f20 [ 320.417317] FS: 00007f963c0e6740(0000) GS:ff4463fdd65d8000(0000) knlGS:0000000000000000 [ 320.417342] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 320.417362] CR2: 0000000000000000 CR3: 00000020ba674002 CR4: 0000000000773ef0 [ 320.417385] PKRU: 55555554 [ 320.417398] Call Trace: [ 320.417412] <TASK> [ 320.417429] pci_device_remove+0x42/0xb0 [ 320.417459] device_release_driver_internal+0x1a9/0x210 [ 320.417492] driver_detach+0x4b/0x90 [ 320.417516] bus_remove_driver+0x70/0x100 [ 320.417539] pci_unregister_driver+0x2e/0xb0 [ 320.417564] __do_sys_delete_module.constprop.0+0x190/0x2f0 [ 320.417592] ? kmem_cache_free+0x31e/0x550 [ 320.417619] ? lockdep_hardirqs_on_prepare+0xde/0x190 [ 320.417644] ? do_syscall_64+0x38/0x6b0 [ 320.417665] do_syscall_64+0xc8/0x6b0 [ 320.417683] ? clear_bhb_loop+0x30/0x80 [ 320.417706] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 320.417727] RIP: 0033:0x7f963bb30beb
--- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +6 -1
@@ -2999,7 +2999,6 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)pci_sriov_set_totalvfs (adapter->pdev,idpf_get_max_vfs (adapter)); num_max_vports =idpf_get_max_vports (adapter); - adapter->max_vports = num_max_vports; adapter->vports =kcalloc (num_max_vports,sizeof (*adapter->vports),GFP_KERNEL );if (!adapter->vports)
@@ -3022,6 +3021,12 @@ int idpf_vc_core_init(struct idpf_adapter *adapter) goto err_netdev_alloc; } +/* Set max_vports only after vports, netdevs and vport_config buffers +* are allocated to make sure max_vport bound loops don't end up +* crashing, following allocation errors on init. +*/ + adapter->max_vports = num_max_vports; +/* Start the mailbox task before requesting vectors. This will ensure * vector information response from mailbox is handled */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/869 LoongArch: BPF: Zero-extend signed ALU32 div/mod results
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Dudar <[email protected]>
[ Upstream commit dacd348b8a993373576fe2ee2d8b114740ba57a6 ]
ALU32 operations write a 32-bit result and leave the upper 32 bits of the BPF register zero. The LoongArch JIT sign-extends the result of signed ALU32 BPF_DIV and BPF_MOD (off=1), so a negative 32-bit quotient or remainder leaves bits 63:32 set in JITted code while the verifier and interpreter model those bits as zero.
Keep sign-extension on the operands, which signed divide needs, and zero-extend the ALU32 result after the divide or modulo instruction, matching the unsigned ALU32 div/mod paths and every other ALU32 operation in this JIT.
--- arch/loongarch/net/bpf_jit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/loongarch/net/bpf_jit.c +4 -4
@@ -564,7 +564,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extmove_reg (ctx, t1, src);emit_sext_32 (ctx, t1, is32);emit_insn (ctx, divd, dst, dst, t1); -emit_sext_32 (ctx, dst, is32); +emit_zext_32 (ctx, dst, is32); }break ;
@@ -581,7 +581,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extemit_sext_32 (ctx, t1, is32);emit_sext_32 (ctx, dst, is32);emit_insn (ctx, divd, dst, dst, t1); -emit_sext_32 (ctx, dst, is32); +emit_zext_32 (ctx, dst, is32); }break ;
@@ -599,7 +599,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extmove_reg (ctx, t1, src);emit_sext_32 (ctx, t1, is32);emit_insn (ctx, modd, dst, dst, t1); -emit_sext_32 (ctx, dst, is32); +emit_zext_32 (ctx, dst, is32); }break ;
@@ -616,7 +616,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extemit_sext_32 (ctx, t1, is32);emit_sext_32 (ctx, dst, is32);emit_insn (ctx, modd, dst, dst, t1); -emit_sext_32 (ctx, dst, is32); +emit_zext_32 (ctx, dst, is32); }break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/869 cifs: prevent readdir from changing file size due to stale directory metadata
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
[ Upstream commit e8a8d54c2d508891c142a928fc7d298c4c8bd0dd ]
Windows Server's directory enumeration metadata lags behind the actual file size after a write+close or rename. A concurrent readdir() in the window between close() returning to userspace and stat() being called overwrites the correct cached i_size with the stale server value, causing stat() to return the wrong size.
Once _cifsFileInfo_put() removes the last writable handle from openFileList, is_size_safe_to_change() permits readdir to overwrite i_size. smb2_close_getattr() then stamps cifs_i->time = jiffies, making the corrupt cached value appear fresh to the next stat().
The existing check (see Fixes:) only blocked stale size updates while an active RW lease was held, not after the last writable handle closes.
Add cifsInodeInfo->time_last_write, written via smp_store_release() at writable close and on setattr/truncate. is_size_safe_to_change() checks is_inode_writable() first (acquiring open_file_lock), then rejects a readdir size update if time_last_write falls within acregmax jiffies. The spinlock release in _cifsFileInfo_put() forms a store-release barrier that pairs with the spin_lock() (load-acquire) in is_inode_writable(), ensuring the subsequent smp_load_acquire() on time_last_write observes any update from a concurrent close(). When a size update is rejected and the server value differs from the cached one, cifs_i->time is cleared to force a fresh QUERY_INFO on the next stat().
readdir is also blocked from changing i_size while writable handles are open or an RW lease is held, even on direct-IO mounts.
For deferred close (closetimeo > 0), time_last_write is refreshed at the actual server close in smb2_deferred_work_close() and in the cifs_close_deferred_file*() drain paths invoked by lease/oplock breaks and tcon teardown, anchoring the protection window to the real close time rather than the earlier userspace close.
time_last_write == 0 skips the time_before() check to avoid false positives near boot on 32-bit systems where jiffies starts close to INITIAL_JIFFIES.
Does not reproduce against Samba or with actimeo=0.
Stable-dep-of: c2f2e83e3bbc ("cifs: fix cifsFileInfo leak on kmalloc failure in deferred close drain paths")
--- fs/smb/client/cifsfs.c | 1 + fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 70 ++++++++++++++++++++++++++++++++++++---- fs/smb/client/inode.c | 6 ++++ fs/smb/client/misc.c | 27 ++++++++++++++-- 5 files changed, 96 insertions(+), 9 deletions(-)
fs/smb/client/cifsfs.c +1 -0
@@ -434,6 +434,7 @@ cifs_alloc_inode(struct super_block *sb)return NULL ; cifs_inode->cifsAttrs =0x20 ;/* default */ cifs_inode->time =0 ; + cifs_inode->time_last_write =0 ;/* * Until the file is open and we have gotten oplock info back from the * server, can not assume caching of file data or metadata.
fs/smb/client/cifsglob.h +1 -0
@@ -1535,6 +1535,7 @@ struct cifsInodeInfo {spinlock_t writers_lock;unsigned int writers;/* Number of writers on this inode */ unsigned long time;/* jiffies of last update of inode */ +unsigned long time_last_write;/* jiffies of last writable close or truncate */ u64 uniqueid;/* server inode number */ u64 createtime;/* creation time on server */ __u8 lease_key[SMB2_LEASE_KEY_SIZE ];/* lease key for this inode */
fs/smb/client/file.c +64 -6
104 lines not on this page · raw message
fs/smb/client/inode.c +6 -0
@@ -242,6 +242,8 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,* calculating num blocks. */ inode->i_blocks = (512 -1 + fattr->cf_bytes) >>9 ; + }else if (from_readdir &&i_size_read (inode) != fattr->cf_eof) { + cifs_i->time =0 ; }if (S_ISLNK (fattr->cf_mode) && fattr->cf_symlink_target) {
@@ -3188,6 +3190,8 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)if ((attrs->ia_valid &ATTR_SIZE ) && attrs->ia_size !=i_size_read (inode)) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&cifsInode->time_last_write, jiffies);truncate_setsize (inode, attrs->ia_size);netfs_resize_file (&cifsInode->netfs, attrs->ia_size, true);fscache_resize_cookie (cifs_inode_cookie (inode), attrs->ia_size);
@@ -3407,6 +3411,8 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)if ((attrs->ia_valid &ATTR_SIZE ) && attrs->ia_size !=i_size_read (inode)) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&cifsInode->time_last_write, jiffies);truncate_setsize (inode, attrs->ia_size);netfs_resize_file (&cifsInode->netfs, attrs->ia_size, true);fscache_resize_cookie (cifs_inode_cookie (inode), attrs->ia_size);
fs/smb/client/misc.c +24 -3
@@ -798,7 +798,14 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)spin_unlock (&cifs_inode->open_file_lock);list_for_each_entry_safe (tmp_list, tmp_next_list, &file_head, list) { -_cifsFileInfo_put (tmp_list->cfile, false, false); +struct cifsFileInfo *cfile = tmp_list->cfile; + +if (OPEN_FMODE (cfile->f_flags) &FMODE_WRITE ) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&CIFS_I (d_inode (cfile->dentry))->time_last_write, + jiffies); + } +_cifsFileInfo_put (cfile, false, false);list_del (&tmp_list->list);kfree (tmp_list); }
@@ -830,7 +837,14 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)spin_unlock (&tcon->open_file_lock);list_for_each_entry_safe (tmp_list, tmp_next_list, &file_head, list) { -_cifsFileInfo_put (tmp_list->cfile, true, false); +struct cifsFileInfo *cfile = tmp_list->cfile; + +if (OPEN_FMODE (cfile->f_flags) &FMODE_WRITE ) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&CIFS_I (d_inode (cfile->dentry))->time_last_write, + jiffies); + } +_cifsFileInfo_put (cfile, true, false);list_del (&tmp_list->list);kfree (tmp_list); }
@@ -899,7 +913,14 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,spin_unlock (&tcon->open_file_lock);list_for_each_entry_safe (tmp_list, tmp_next_list, &file_head, list) { -_cifsFileInfo_put (tmp_list->cfile, true, false); +struct cifsFileInfo *cfile = tmp_list->cfile; + +if (OPEN_FMODE (cfile->f_flags) &FMODE_WRITE ) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&CIFS_I (d_inode (cfile->dentry))->time_last_write, + jiffies); + } +_cifsFileInfo_put (cfile, true, false);list_del (&tmp_list->list);kfree (tmp_list); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/869 cifs: fix cifsFileInfo leak on kmalloc failure in deferred close drain paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
[ Upstream commit c2f2e83e3bbc5483730fd4ee903182761f1ae50f ]
In cifs_close_deferred_file(), cifs_close_all_deferred_files(), and cifs_close_deferred_file_under_dentry(), when a pending deferred close is cancelled via cancel_delayed_work(), the subsequent kmalloc_obj() to add the file to the local processing list may fail under memory pressure. The loop breaks immediately, but the cancelled work is no longer pending (it would have called _cifsFileInfo_put()), and the cfile is never added to file_head for processing. The cifsFileInfo reference and the open server handle both leak.
Fix by saving the cfile that failed allocation in a local variable, breaking as before, and calling _cifsFileInfo_put() on it after releasing the lock. Any files later in the iteration are unaffected since their deferred work is still pending and will fire normally.
--- fs/smb/client/misc.c | 45 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-)
fs/smb/client/misc.c +39 -6
@@ -772,7 +772,7 @@ cifs_del_deferred_close(struct cifsFileInfo *cfile)void cifs_close_deferred_file (struct cifsInodeInfo *cifs_inode) { -struct cifsFileInfo *cfile =NULL ; +struct cifsFileInfo *cfile =NULL , *failed_cfile =NULL ;struct file_list *tmp_list, *tmp_next_list;LIST_HEAD (file_head);
@@ -788,8 +788,10 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)spin_unlock (&cifs_inode->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC ); -if (tmp_list ==NULL ) +if (tmp_list ==NULL ) { + failed_cfile = cfile;break ; + } tmp_list->cfile = cfile;list_add_tail (&tmp_list->list, &file_head); }
@@ -797,6 +799,15 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode) }spin_unlock (&cifs_inode->open_file_lock); +if (failed_cfile) { +if (OPEN_FMODE (failed_cfile->f_flags) &FMODE_WRITE ) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&CIFS_I (d_inode (failed_cfile->dentry))->time_last_write, + jiffies); + } +_cifsFileInfo_put (failed_cfile, false, false); + } +list_for_each_entry_safe (tmp_list, tmp_next_list, &file_head, list) {struct cifsFileInfo *cfile = tmp_list->cfile;
@@ -814,7 +825,7 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)void cifs_close_all_deferred_files (struct cifs_tcon *tcon) { -struct cifsFileInfo *cfile; +struct cifsFileInfo *cfile, *failed_cfile =NULL ;struct file_list *tmp_list, *tmp_next_list;LIST_HEAD (file_head);
@@ -827,8 +838,10 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC ); -if (tmp_list ==NULL ) +if (tmp_list ==NULL ) { + failed_cfile = cfile;break ; + } tmp_list->cfile = cfile;list_add_tail (&tmp_list->list, &file_head); }
@@ -836,6 +849,15 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon) }spin_unlock (&tcon->open_file_lock); +if (failed_cfile) { +if (OPEN_FMODE (failed_cfile->f_flags) &FMODE_WRITE ) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&CIFS_I (d_inode (failed_cfile->dentry))->time_last_write, + jiffies); + } +_cifsFileInfo_put (failed_cfile, true, false); + } +list_for_each_entry_safe (tmp_list, tmp_next_list, &file_head, list) {struct cifsFileInfo *cfile = tmp_list->cfile;
@@ -891,7 +913,7 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, struct dentry *dentry) {struct file_list *tmp_list, *tmp_next_list; -struct cifsFileInfo *cfile; +struct cifsFileInfo *cfile, *failed_cfile =NULL ;LIST_HEAD (file_head);spin_lock (&tcon->open_file_lock);
@@ -904,14 +926,25 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC ); -if (tmp_list ==NULL ) +if (tmp_list ==NULL ) { + failed_cfile = cfile;break ; + } tmp_list->cfile = cfile;list_add_tail (&tmp_list->list, &file_head); } }spin_unlock (&tcon->open_file_lock); +if (failed_cfile) { +if (OPEN_FMODE (failed_cfile->f_flags) &FMODE_WRITE ) { +/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ +smp_store_release (&CIFS_I (d_inode (failed_cfile->dentry))->time_last_write, + jiffies); + } +_cifsFileInfo_put (failed_cfile, true, false); + } +list_for_each_entry_safe (tmp_list, tmp_next_list, &file_head, list) {struct cifsFileInfo *cfile = tmp_list->cfile;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/869 tipc: serialize udp bearer replicast list updates
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 350e592ff4e30e48ffb55e142d11a73e63f4869c ]
tipc_udp_rcast_add() and cleanup_bearer() both update ub->rcast.list with list_add_rcu() / list_del_rcu(), but nothing serializes them. The add runs from the encap receive softirq (via tipc_udp_rcast_disc()) without rtnl_lock(), so it can race the cleanup delete and corrupt the list:
list_del corruption. prev->next should be ffff8880298d7ab8,
but was ffff88802449ad38. (prev=ffff888027e3ec98) kernel BUG at lib/list_debug.c:62! RIP: __list_del_entry_valid_or_report+0x17a/0x200 Workqueue: events cleanup_bearer Call Trace: cleanup_bearer (net/tipc/udp_media.c:811) process_one_work (kernel/workqueue.c:3302) worker_thread (kernel/workqueue.c:3466)
The bearer can be enabled from an unprivileged user namespace, as the TIPCv2 generic-netlink ops carry no GENL_ADMIN_PERM.
Add a spinlock to struct udp_bearer and take it around the list_add_rcu() in tipc_udp_rcast_add() and the list_del_rcu() loop in cleanup_bearer() so the two writers can no longer corrupt the list.
Reject a duplicate peer under the same lock before allocating, and remove tipc_udp_is_known_peer(). The old lockless pre-check in tipc_udp_rcast_disc() was racy: two softirqs discovering the same peer could both find it absent and add it twice.
cleanup_bearer() runs from a workqueue after tipc_udp_disable() clears the bearer's up bit, so an encap softirq can still reach tipc_udp_rcast_add() and add a peer after cleanup_bearer() has already emptied the list, leaking that entry when the bearer is freed. Mark the bearer disabled under rcast_lock once the list is emptied and refuse further additions.
--- net/tipc/udp_media.c | 56 +++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 29 deletions(-)
net/tipc/udp_media.c +27 -29
@@ -94,6 +94,8 @@ struct udp_replicast {* @ifindex: local address scope * @work: used to schedule deferred work on a bearer * @rcast: associated udp_replicast container +* @rcast_lock: serialize updates to @rcast.list against concurrent updaters +* @disabled: bearer is being torn down; reject further @rcast.list additions */ struct udp_bearer {struct tipc_bearer __rcu *bearer;
@@ -101,6 +103,8 @@ struct udp_bearer {u32 ifindex;struct work_struct work;struct udp_replicast rcast; +spinlock_t rcast_lock; +bool disabled; };static int tipc_udp_is_mcast_addr (struct udp_media_addr *addr)
@@ -279,26 +283,6 @@ static int tipc_udp_send_msg(struct net *net, struct sk_buff *skb,return err; } -static bool tipc_udp_is_known_peer (struct tipc_bearer *b, -struct udp_media_addr *addr) -{ -struct udp_replicast *rcast, *tmp; -struct udp_bearer *ub; - - ub =rcu_dereference_rtnl (b->media_ptr); -if (!ub) { -pr_err_ratelimited ("UDP bearer instance not found\n" ); -return false; - } - -list_for_each_entry_safe (rcast, tmp, &ub->rcast.list, list) { -if (!memcmp (&rcast->addr, addr,sizeof (struct udp_media_addr ))) -return true; - } - -return false; -} -static int tipc_udp_rcast_add (struct tipc_bearer *b,struct udp_media_addr *addr) {
@@ -309,16 +293,34 @@ static int tipc_udp_rcast_add(struct tipc_bearer *b,if (!ub)return -ENODEV ; +spin_lock_bh (&ub->rcast_lock); +if (ub->disabled) { +spin_unlock_bh (&ub->rcast_lock); +return 0 ; + } +list_for_each_entry (rcast, &ub->rcast.list, list) { +if (!memcmp (&rcast->addr, addr,sizeof (*addr))) { +spin_unlock_bh (&ub->rcast_lock); +return 0 ; + } + } + rcast =kmalloc (sizeof (*rcast),GFP_ATOMIC ); -if (!rcast) +if (!rcast) { +spin_unlock_bh (&ub->rcast_lock);return -ENOMEM ; + }if (dst_cache_init (&rcast->dst_cache,GFP_ATOMIC )) { +spin_unlock_bh (&ub->rcast_lock);kfree (rcast);return -ENOMEM ; }memcpy (&rcast->addr, addr,sizeof (struct udp_media_addr )); +list_add_rcu (&rcast->list, &ub->rcast.list); + b->bcast_addr.broadcast =TIPC_REPLICAST_SUPPORT ; +spin_unlock_bh (&ub->rcast_lock);if (ntohs (addr->proto) ==ETH_P_IP )pr_info ("New replicast peer: %pI4\n" , &rcast->addr.ipv4);
@@ -326,8 +328,6 @@ static int tipc_udp_rcast_add(struct tipc_bearer *b, else if (ntohs(addr->proto) == ETH_P_IPV6) pr_info("New replicast peer: %pI6\n", &rcast->addr.ipv6);#endif - b->bcast_addr.broadcast =TIPC_REPLICAST_SUPPORT ; -list_add_rcu (&rcast->list, &ub->rcast.list);return 0 ; }
@@ -362,9 +362,6 @@ static int tipc_udp_rcast_disc(struct tipc_bearer *b, struct sk_buff *skb)return 0 ; } -if (likely (tipc_udp_is_known_peer (b, &src))) -return 0 ; -return tipc_udp_rcast_add (b, &src); }
@@ -646,9 +643,6 @@ int tipc_udp_nl_bearer_add(struct tipc_bearer *b, struct nlattr *attr)return -EINVAL ; } -if (tipc_udp_is_known_peer (b, &addr)) -return 0 ; -return tipc_udp_rcast_add (b, &addr); }
@@ -680,6 +674,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,return -ENOMEM ;INIT_LIST_HEAD (&ub->rcast.list); +spin_lock_init (&ub->rcast_lock);if (!attrs[TIPC_NLA_BEARER_UDP_OPTS ]) goto err;
@@ -809,11 +804,14 @@ static void cleanup_bearer(struct work_struct *work)struct udp_replicast *rcast, *tmp;struct tipc_net *tn; +spin_lock_bh (&ub->rcast_lock);list_for_each_entry_safe (rcast, tmp, &ub->rcast.list, list) {dst_cache_destroy (&rcast->dst_cache);list_del_rcu (&rcast->list);kfree_rcu (rcast, rcu); } + ub->disabled = true; +spin_unlock_bh (&ub->rcast_lock); tn =tipc_net (sock_net (ub->ubsock->sk));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/869 fwctl/bnxt_en: Refactor aux bus functions to be more generic
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavan Chebbi <[email protected]>
[ Upstream commit 2c7c85c8c7881d57c5fa1114f4b0dbd7fc53a36f ]
Up until now there was only one auxiliary device that bnxt created and that was for RoCE driver. bnxt fwctl is also going to use an aux bus device that bnxt should create. This requires some nomenclature changes and refactoring of the existing bnxt aux dev functions.
Convert 'aux_priv' and 'edev' members of struct bnxt into arrays where each element contains supported auxbus device's data. Move struct bnxt_aux_priv from bnxt.h to ulp.h because that is where it belongs. Make aux bus init/uninit/add/del functions more generic which will loop through all the aux device types. Make bnxt_ulp_start/stop functions (the only other common functions applicable to any aux device) loop through the aux devices to update their config and states. Make callers of bnxt_ulp_start() call it only when there are no errors.
Also, as an improvement in code, bnxt_register_dev() can skip unnecessary dereferencing of edev from bp, instead use the edev pointer from the function parameter.
Future patches will reuse these functions to add an aux bus device for fwctl.
Stable-dep-of: 1cb8553c02e9 ("bnxt_en: Handle partially initialized auxiliary devices")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 47 ++- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 19 +- .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 8 +- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 336 +++++++++++------- drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h | 25 +- 6 files changed, 272 insertions(+), 165 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +28 -19
@@ -6674,7 +6674,8 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)#endif if ((bp->flags &BNXT_FLAG_STRIP_VLAN ) || def_vlan) req->flags |=cpu_to_le32 (VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE ); -if (vnic->vnic_id ==BNXT_VNIC_DEFAULT &&bnxt_ulp_registered (bp->edev)) +if (vnic->vnic_id ==BNXT_VNIC_DEFAULT && +bnxt_ulp_registered (bp->edev[BNXT_AUXDEV_RDMA ])) req->flags |=cpu_to_le32 (bnxt_get_roce_vnic_mode (bp));return hwrm_req_send (bp, req);
@@ -7758,6 +7759,7 @@ static int bnxt_get_avail_msix(struct bnxt *bp, int num);static int __bnxt_reserve_rings (struct bnxt *bp) { +struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA ];struct bnxt_hw_rings hwr = {0 };int rx_rings, old_rx_rings, rc;int cp = bp->cp_nr_rings;
@@ -7768,7 +7770,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)if (!bnxt_need_reserve_rings (bp))return 0 ; -if (BNXT_NEW_RM (bp) && !bnxt_ulp_registered (bp->edev)) { +if (BNXT_NEW_RM (bp) && !bnxt_ulp_registered (edev)) { ulp_msix =bnxt_get_avail_msix (bp, bp->ulp_num_msix_want);if (!ulp_msix)bnxt_set_ulp_stat_ctxs (bp,0 );
@@ -7821,8 +7823,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp) } rx_rings =min_t (int, rx_rings, hwr.grp); hwr.cp =min_t (int, hwr.cp, bp->cp_nr_rings); -if (bnxt_ulp_registered (bp->edev) && - hwr.stat >bnxt_get_ulp_stat_ctxs (bp)) +if (bnxt_ulp_registered (edev) && hwr.stat >bnxt_get_ulp_stat_ctxs (bp)) hwr.stat -=bnxt_get_ulp_stat_ctxs (bp); hwr.cp =min_t (int, hwr.cp, hwr.stat); rc =bnxt_trim_rings (bp, &rx_rings, &hwr.tx, hwr.cp, sh);
@@ -7861,7 +7862,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp) !netif_is_rxfh_configured(bp->dev))bnxt_set_dflt_rss_indir_tbl (bp,NULL ); -if (!bnxt_ulp_registered (bp->edev) &&BNXT_NEW_RM (bp)) { +if (!bnxt_ulp_registered (edev) &&BNXT_NEW_RM (bp)) {int resv_msix, resv_ctx, ulp_ctxs;struct bnxt_hw_resc *hw_resc;
@@ -11099,6 +11100,7 @@ static void bnxt_clear_int_mode(struct bnxt *bp)int bnxt_reserve_rings (struct bnxt *bp,bool irq_re_init) { +struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA ];bool irq_cleared = false;bool irq_change = false;int tcs = bp->num_tc;
@@ -11108,7 +11110,7 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)if (!bnxt_need_reserve_rings (bp))return 0 ; -if (BNXT_NEW_RM (bp) && !bnxt_ulp_registered (bp->edev)) { +if (BNXT_NEW_RM (bp) && !bnxt_ulp_registered (edev)) {int ulp_msix =bnxt_get_avail_msix (bp, bp->ulp_num_msix_want);if (ulp_msix > bp->ulp_num_msix_want)
@@ -13997,7 +13999,7 @@ static void bnxt_fw_echo_reply(struct bnxt *bp)static void bnxt_ulp_restart (struct bnxt *bp) {bnxt_ulp_stop (bp); -bnxt_ulp_start (bp,0 ); +bnxt_ulp_start (bp); }static void bnxt_sp_task (struct work_struct *work)
@@ -14157,7 +14159,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, hwr.cp_p5 = hwr.tx + rx; rc =bnxt_hwrm_check_rings (bp, &hwr);if (!rc &&pci_msix_can_alloc_dyn (bp->pdev)) { -if (!bnxt_ulp_registered (bp->edev)) { +if (!bnxt_ulp_registered (bp->edev[BNXT_AUXDEV_RDMA ])) { hwr.cp +=bnxt_get_ulp_msix_num (bp); hwr.cp =min_t (int, hwr.cp,bnxt_get_max_func_irqs (bp)); }
@@ -14659,7 +14661,7 @@ static void bnxt_fw_reset_task(struct work_struct *work)bnxt_dl_health_fw_status_update (bp, true); }rtnl_unlock (); -bnxt_ulp_start (bp,0 ); +bnxt_ulp_start (bp);bnxt_reenable_sriov (bp);rtnl_lock ();bnxt_vf_reps_alloc (bp);
@@ -14681,7 +14683,8 @@ static void bnxt_fw_reset_task(struct work_struct *work)bnxt_fw_reset_abort (bp, rc);rtnl_unlock (); ulp_start: -bnxt_ulp_start (bp, rc); +if (!rc) +bnxt_ulp_start (bp); }static int bnxt_init_board (struct pci_dev *pdev,struct net_device *dev)
@@ -15654,12 +15657,13 @@ static void bnxt_remove_one(struct pci_dev *pdev)if (BNXT_PF (bp))bnxt_sriov_disable (bp); -bnxt_rdma_aux_device_del (bp); +bnxt_aux_devices_del (bp);unregister_netdev (dev);bnxt_ptp_clear (bp); -bnxt_rdma_aux_device_uninit (bp); +bnxt_aux_devices_uninit (bp); +bnxt_auxdev_id_free (bp, bp->auxdev_id);bnxt_free_l2_filters (bp, true);bnxt_free_ntp_fltrs (bp, true);
@@ -16283,7 +16287,9 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)__bnxt_set_rx_skb_mode (bp, false);bnxt_set_tpa_flags (bp);bnxt_set_ring_params (bp); -bnxt_rdma_aux_device_init (bp); +mutex_init (&bp->auxdev_lock); +if (!bnxt_auxdev_id_alloc (bp)) +bnxt_aux_devices_init (bp); rc =bnxt_set_dflt_rings (bp, true);if (rc) {if (BNXT_VF (bp) && rc == -ENODEV ) {
@@ -16345,7 +16351,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)bnxt_dl_fw_reporters_create (bp); -bnxt_rdma_aux_device_add (bp); +bnxt_aux_devices_add (bp);bnxt_print_device_info (bp);
@@ -16353,7 +16359,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; init_err_cleanup: -bnxt_rdma_aux_device_uninit (bp); +bnxt_aux_devices_uninit (bp); +bnxt_auxdev_id_free (bp, bp->auxdev_id);bnxt_dl_unregister (bp); init_err_dl:bnxt_shutdown_tc (bp);
@@ -16481,9 +16488,10 @@ static int bnxt_resume(struct device *device) resume_exit:rtnl_unlock (); -bnxt_ulp_start (bp, rc); -if (!rc) +if (!rc) { +bnxt_ulp_start (bp);bnxt_reenable_sriov (bp); + }return rc; }
@@ -16657,9 +16665,10 @@ static void bnxt_io_resume(struct pci_dev *pdev)netif_device_attach (netdev);rtnl_unlock (); -bnxt_ulp_start (bp, err); -if (!err) +if (!err) { +bnxt_ulp_start (bp);bnxt_reenable_sriov (bp); + } }static const struct pci_error_handlers bnxt_err_handler = {
drivers/net/ethernet/broadcom/bnxt/bnxt.h +10 -9
@@ -24,12 +24,12 @@#include <linux/interrupt.h> #include <linux/rhashtable.h> #include <linux/crash_dump.h> -#include <linux/auxiliary_bus.h> #include <net/devlink.h> #include <net/dst_metadata.h> #include <net/xdp.h> #include <linux/dim.h> #include <linux/io-64-nonatomic-lo-hi.h> +#include "bnxt_ulp.h" #ifdef CONFIG_TEE_BNXT_FW #include <linux/firmware/broadcom/tee_bnxt_fw.h> #endif
@@ -2049,12 +2049,6 @@ struct bnxt_fw_health {#define BNXT_FW_IF_RETRY 10#define BNXT_FW_SLOT_RESET_RETRY 4 -struct bnxt_aux_priv { -struct auxiliary_device aux_dev; -struct bnxt_en_dev *edev; -int id; -}; -enum board_idx {BCM57301 ,BCM57302 ,
@@ -2288,8 +2282,8 @@ struct bnxt {#define BNXT_CHIP_P5_AND_MINUS (bp) \ (BNXT_CHIP_P3(bp) || BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp)) -struct bnxt_aux_priv *aux_priv; -struct bnxt_en_dev *edev; +struct bnxt_aux_priv *aux_priv[__BNXT_AUXDEV_MAX]; +struct bnxt_en_dev *edev[__BNXT_AUXDEV_MAX];struct bnxt_napi **bnapi;
@@ -2669,6 +2663,13 @@ struct bnxt {struct bnxt_ctx_pg_info *fw_crash_mem;u32 fw_crash_len; +int auxdev_id; +/* synchronize validity checks of available aux devices */ +struct mutex auxdev_lock; +u8 auxdev_state[__BNXT_AUXDEV_MAX]; +#define BNXT_ADEV_STATE_NONE 0 +#define BNXT_ADEV_STATE_INIT 1 +#define BNXT_ADEV_STATE_ADD 2 };#define BNXT_NUM_RX_RING_STATS 8
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4 -4
@@ -443,12 +443,12 @@ static int bnxt_dl_reload_down(struct devlink *dl, bool netns_change,NL_SET_ERR_MSG_MOD (extack,"reload is unsupported while VFs are allocated or being configured" );rtnl_unlock (); -bnxt_ulp_start (bp,0 ); +bnxt_ulp_start (bp);return -EOPNOTSUPP ; }if (bp->dev->reg_state ==NETREG_UNREGISTERED ) {rtnl_unlock (); -bnxt_ulp_start (bp,0 ); +bnxt_ulp_start (bp);return -ENODEV ; }if (netif_running (bp->dev))
@@ -571,8 +571,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action actidev_close (bp->dev); }rtnl_unlock (); -if (action ==DEVLINK_RELOAD_ACTION_DRIVER_REINIT ) -bnxt_ulp_start (bp, rc); +if (!rc && action ==DEVLINK_RELOAD_ACTION_DRIVER_REINIT ) +bnxt_ulp_start (bp);return rc; }
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -1
@@ -4871,7 +4871,7 @@ static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,memset (buf,0 ,sizeof (u64) * bp->num_tests);if (etest->flags Ð_TEST_FL_OFFLINE && -bnxt_ulp_registered (bp->edev)) { +bnxt_ulp_registered (bp->edev[BNXT_AUXDEV_RDMA ])) { etest->flags |=ETH_TEST_FL_FAILED ;netdev_warn (dev,"Offline tests cannot be run with RoCE driver loaded\n" );return ;
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +209 -127
484 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h +20 -5
@@ -10,6 +10,8 @@#ifndef BNXT_ULP_H #define BNXT_ULP_H +#include <linux/auxiliary_bus.h> +#define BNXT_ROCE_ULP 0#define BNXT_MAX_ULP 1
@@ -23,6 +25,17 @@struct hwrm_async_event_cmpl ;struct bnxt ; +enum bnxt_auxdev_type { +BNXT_AUXDEV_RDMA =0 , + __BNXT_AUXDEV_MAX +}; + +struct bnxt_aux_priv { +struct auxiliary_device aux_dev; +struct bnxt_en_dev *edev; +int id; +}; +struct bnxt_msix_entry {u32 vector;u32 ring_idx;
@@ -109,19 +122,21 @@ void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ctxs);int bnxt_get_ulp_stat_ctxs_in_use (struct bnxt *bp);void bnxt_set_dflt_ulp_stat_ctxs (struct bnxt *bp);void bnxt_ulp_stop (struct bnxt *bp); -void bnxt_ulp_start (struct bnxt *bp,int err); +void bnxt_ulp_start (struct bnxt *bp);void bnxt_ulp_sriov_cfg (struct bnxt *bp,int num_vfs);void bnxt_ulp_irq_stop (struct bnxt *bp);void bnxt_ulp_irq_restart (struct bnxt *bp,int err);void bnxt_ulp_async_events (struct bnxt *bp,struct hwrm_async_event_cmpl *cmpl); -void bnxt_rdma_aux_device_uninit (struct bnxt *bp); -void bnxt_rdma_aux_device_del (struct bnxt *bp); -void bnxt_rdma_aux_device_add (struct bnxt *bp); -void bnxt_rdma_aux_device_init (struct bnxt *bp); +void bnxt_aux_devices_uninit (struct bnxt *bp); +void bnxt_aux_devices_del (struct bnxt *bp); +void bnxt_aux_devices_add (struct bnxt *bp); +void bnxt_aux_devices_init (struct bnxt *bp);int bnxt_register_dev (struct bnxt_en_dev *edev,struct bnxt_ulp_ops *ulp_ops,void *handle);void bnxt_unregister_dev (struct bnxt_en_dev *edev);int bnxt_send_msg (struct bnxt_en_dev *edev,struct bnxt_fw_msg *fw_msg);int bnxt_register_async_events (struct bnxt_en_dev *edev,unsigned long *events_bmap,u16 max_id); +int bnxt_auxdev_id_alloc (struct bnxt *bp); +void bnxt_auxdev_id_free (struct bnxt *bp,int id);#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/869 bnxt_en: Handle partially initialized auxiliary devices
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 1cb8553c02e93e5a150cebd42f9ee3db0ece4707 ]
bnxt_aux_devices_init() calls auxiliary_device_init() before all fields used by bnxt_aux_dev_release() are initialized. After auxiliary_device_init() succeeds, later errors must unwind with auxiliary_device_uninit(), which invokes the release callback.
The release callback assumes that aux_priv->id, aux_priv->edev, edev->net and edev->ulp_tbl are all populated. If allocation fails after auxiliary_device_init(), the release path can otherwise dereference or clear partially initialized state.
Allocate and attach the bnxt_en_dev and ULP table before calling auxiliary_device_init(), so the release callback only sees a fully initialized auxiliary private object. If auxiliary_device_init() itself fails, free those allocations directly because device_initialize() has not run and the release callback will not be invoked.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +20 -19
@@ -517,6 +517,18 @@ void bnxt_aux_devices_init(struct bnxt *bp)if (!aux_priv) goto next_auxdev; + edev =kzalloc_obj (*edev); +if (!edev) + goto aux_priv_free; + aux_priv->edev = edev; +bnxt_set_edev_info (edev, bp); + + ulp =kzalloc_obj (*ulp); +if (!ulp) + goto edev_free; + edev->ulp_tbl = ulp; + aux_priv->id = idx; + aux_dev = &aux_priv->aux_dev; aux_dev->id = bp->auxdev_id; aux_dev->name = bnxt_aux_devices[idx].name;
@@ -524,37 +536,26 @@ void bnxt_aux_devices_init(struct bnxt *bp) aux_dev->dev.release = bnxt_aux_dev_release; rc =auxiliary_device_init (aux_dev); -if (rc) { -kfree (aux_priv); - goto next_auxdev; - } +if (rc) + goto ulp_free; bp->aux_priv[idx] = aux_priv;/* From this point, all cleanup will happen via the .release * callback & any error unwinding will need to include a call * to auxiliary_device_uninit. */ - edev =kzalloc_obj (*edev); -if (!edev) - goto aux_dev_uninit; - - aux_priv->edev = edev; -bnxt_set_edev_info (edev, bp); - - ulp =kzalloc_obj (*ulp); -if (!ulp) - goto aux_dev_uninit; - - edev->ulp_tbl = ulp; bp->edev[idx] = edev;if (idx ==BNXT_AUXDEV_RDMA ) bp->ulp_num_msix_want =bnxt_set_dflt_ulp_msix (bp); - aux_priv->id = idx;bnxt_auxdev_set_state (bp, idx,BNXT_ADEV_STATE_INIT );continue ; -aux_dev_uninit: -auxiliary_device_uninit (aux_dev); +ulp_free: +kfree (ulp); +edev_free: +kfree (edev); +aux_priv_free: +kfree (aux_priv); next_auxdev:if (idx ==BNXT_AUXDEV_RDMA ) bp->flags &= ~BNXT_FLAG_ROCE_CAP ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/869 drm/xe/guc: Keep scheduler timeline name alive
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arvind Yadav <[email protected]>
[ Upstream commit 299bc6d50b1bed7d1f408391736712f01a0855e2 ]
The scheduler keeps a pointer to the timeline name, but q->name is freed with the exec queue while scheduler fences can still reference it.
Store the name in struct xe_guc_exec_queue so it shares the scheduler's RCU-deferred lifetime.
--- drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 5 +++++ drivers/gpu/drm/xe/xe_guc_submit.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h +5 -0
@@ -10,6 +10,7 @@#include <linux/workqueue.h> #include "xe_gpu_scheduler_types.h" +#include "xe_hw_fence_types.h" struct dma_fence ;struct xe_exec_queue ;
@@ -24,6 +25,10 @@ struct xe_guc_exec_queue {struct rcu_head rcu;/** @sched: GPU scheduler for this xe_exec_queue */ struct xe_gpu_scheduler sched; +/** +* @name: Scheduler timeline name, kept with @sched until RCU free. +*/ +char name[MAX_FENCE_NAME_LEN ];/** @entity: Scheduler entity for this xe_exec_queue */ struct xe_sched_entity entity;/**
drivers/gpu/drm/xe/xe_guc_submit.c +3 -1
@@ -1472,7 +1472,7 @@ static int guc_exec_queue_init(struct xe_exec_queue *q) err =xe_sched_init (&ge->sched, &drm_sched_ops, &xe_sched_ops,NULL , q->lrc[0 ]->ring.size /MAX_JOB_SIZE_BYTES ,64 , timeout,guc_to_gt (guc)->ordered_wq,NULL , - q->name,gt_to_xe (q->gt)->drm.dev); + ge->name,gt_to_xe (q->gt)->drm.dev);if (err) goto err_free;
@@ -1499,6 +1499,8 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)xe_exec_queue_assign_name (q, q->guc->id); +strscpy (ge->name, q->name,sizeof (ge->name)); +trace_xe_exec_queue_create (q);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/869 Bluetooth: hci_sync: extend conn_hash lookup critical sections
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit d5efd6e4b8b0634af6843178fe1a7dd2b2178a3d ]
Using RCU-protected pointers outside the critical sections without refcount is incorrect and may result to UAF.
Extend critical section to cover both hci_conn_hash lookup and use of the returned conn.
Add surrounding rcu_read_lock() also when return value is not used, in preparation for RCU lockdep requirement to hci_lookup_le_connect().
This avoids concurrent deletion of the conn before we are done dereferencing it.
Also, make sure to hold hdev->lock when accessing hdev->accept_list.
--- net/bluetooth/hci_sync.c | 42 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
net/bluetooth/hci_sync.c +39 -3
@@ -1077,14 +1077,19 @@ static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa)* In this kind of scenario skip the update and let the random * address be updated at the next cycle. */ +rcu_read_lock (); +if (bacmp (&hdev->random_addr,BDADDR_ANY ) && (hci_dev_test_flag (hdev,HCI_LE_ADV ) ||hci_lookup_le_connect (hdev))) {bt_dev_dbg (hdev,"Deferring random address update" );hci_dev_set_flag (hdev,HCI_RPA_EXPIRED ); +rcu_read_unlock ();return 0 ; } +rcu_read_unlock (); +return __hci_cmd_sync_status (hdev,HCI_OP_LE_SET_RANDOM_ADDR ,6 , rpa,HCI_CMD_TIMEOUT ); }
@@ -2757,12 +2762,17 @@ static int hci_pause_addr_resolution(struct hci_dev *hdev)/* Cannot disable addr resolution if scanning is enabled or * when initiating an LE connection. */ +rcu_read_lock (); +if (hci_dev_test_flag (hdev,HCI_LE_SCAN ) ||hci_lookup_le_connect (hdev)) { +rcu_read_unlock ();bt_dev_err (hdev,"Command not allowed when scan/LE connect" );return -EPERM ; } +rcu_read_unlock (); +/* Cannot disable addr resolution if advertising is enabled. */ err =hci_pause_advertising_sync (hdev);if (err) {
@@ -2900,6 +2910,8 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)if (hci_dev_test_flag (hdev,HCI_PA_SYNC )) {struct hci_conn *conn; +rcu_read_lock (); + conn =hci_conn_hash_lookup_create_pa_sync (hdev);if (conn) {struct conn_params pa;
@@ -2909,6 +2921,8 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)bacpy (&pa.addr, &conn->dst); pa.addr_type = conn->dst_type; +rcu_read_unlock (); +/* Clear first since there could be addresses left * behind. */
@@ -2918,6 +2932,8 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) err =hci_le_add_accept_list_sync (hdev, &pa, &num_entries); goto done; + }else { +rcu_read_unlock (); } }
@@ -2928,10 +2944,13 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)* the controller. */ list_for_each_entry_safe (b, t, &hdev->le_accept_list, list) { -if (hci_conn_hash_lookup_le (hdev, &b->bdaddr, b->bdaddr_type)) +rcu_read_lock (); + +if (hci_conn_hash_lookup_le (hdev, &b->bdaddr, b->bdaddr_type)) { +rcu_read_unlock ();continue ; + } -/* Pointers not dereferenced, no locks needed */ pend_conn =hci_pend_le_action_lookup (&hdev->pend_le_conns, &b->bdaddr, b->bdaddr_type);
@@ -2939,6 +2958,8 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) &b->bdaddr, b->bdaddr_type); +rcu_read_unlock (); +/* If the device is not likely to connect or report, * remove it from the acceptlist. */
@@ -3071,6 +3092,8 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type,if (sent) {struct hci_conn *conn; +rcu_read_lock (); + conn =hci_conn_hash_lookup_ba (hdev,PA_LINK , &bdaddr);if (conn) {
@@ -3095,8 +3118,12 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, phy++; } +rcu_read_unlock (); +if (num_phy) goto done; + }else { +rcu_read_unlock (); } } }
@@ -3347,12 +3374,16 @@ int hci_update_passive_scan_sync(struct hci_dev *hdev)/* If there is at least one pending LE connection, we should * keep the background scan running. */ +bool exists;/* If controller is connecting, we should not start scanning * since some controllers are not able to scan and connect at * the same time. */ -if (hci_lookup_le_connect (hdev)) +rcu_read_lock (); + exists =hci_lookup_le_connect (hdev); +rcu_read_unlock (); +if (exists)return 0 ;bt_dev_dbg (hdev,"start background scanning" );
@@ -3570,6 +3601,7 @@ int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable) }static bool disconnected_accept_list_entries (struct hci_dev *hdev) + __must_hold(&hdev->lock) {struct bdaddr_list *b;
@@ -3610,12 +3642,16 @@ int hci_update_scan_sync(struct hci_dev *hdev)if (hdev->scanning_paused)return 0 ; +hci_dev_lock (hdev); +if (hci_dev_test_flag (hdev,HCI_CONNECTABLE ) ||disconnected_accept_list_entries (hdev)) scan =SCAN_PAGE ;else scan =SCAN_DISABLED ; +hci_dev_unlock (hdev); +if (hci_dev_test_flag (hdev,HCI_DISCOVERABLE )) scan |=SCAN_INQUIRY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/869 bpf: Disable migration when destroying sock storage
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hou Tao <[email protected]>
[ Upstream commit 7d1032d1e3031ef38d1a360380d755f75cb639b8 ]
When destroying sock storage, it invokes bpf_local_storage_destroy() to remove all storage elements saved in the sock storage. The destroy procedure will call bpf_selem_free() to free the element, and bpf_selem_free() calls bpf_obj_free_fields() to free the special fields in map value (e.g., kptr). Since kptrs may be allocated from bpf memory allocator, migrate_{disable|enable} pairs are necessary for the freeing of these kptrs.
To simplify reasoning about when migrate_disable() is needed for the freeing of these dynamically-allocated kptrs, let the caller to guarantee migration is disabled before invoking bpf_obj_free_fields(). Therefore, the patch adds migrate_{disable|enable} pair in bpf_sock_storage_free(). The migrate_{disable|enable} pairs in the underlying implementation of bpf_obj_free_fields() will be removed by The following patch.
Stable-dep-of: 7cbd0c4cebe4 ("bpf: Fix UAF in sock clone early bailouts")
--- net/core/bpf_sk_storage.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/core/bpf_sk_storage.c +5 -4
@@ -50,15 +50,16 @@ void bpf_sk_storage_free(struct sock *sk) {struct bpf_local_storage *sk_storage; +migrate_disable ();rcu_read_lock (); sk_storage =rcu_dereference (sk->sk_bpf_storage); -if (!sk_storage) { -rcu_read_unlock (); -return ; - } +if (!sk_storage) + goto out;bpf_local_storage_destroy (sk_storage); +out:rcu_read_unlock (); +migrate_enable (); }static void bpf_sk_storage_map_free (struct bpf_map *map)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/869 bpf: Disable migration when cloning sock storage
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hou Tao <[email protected]>
[ Upstream commit dfccfc47bde53f5df5bf42486d12a8a2ecdcea60 ]
bpf_sk_storage_clone() will call bpf_selem_free() to free the clone element when the allocation of new sock storage fails. bpf_selem_free() will call check_and_free_fields() to free the special fields in the element. Since the allocated element is not visible to bpf syscall or bpf program when bpf_local_storage_alloc() fails, these special fields in the element must be all zero when invoking bpf_selem_free().
To be uniform with other callers of bpf_selem_free(), disabling migration when cloning sock storage. Adding migrate_{disable|enable} pair also benefits the potential switching from kzalloc to bpf memory allocator for sock storage.
Stable-dep-of: 7cbd0c4cebe4 ("bpf: Fix UAF in sock clone early bailouts")
--- net/core/bpf_sk_storage.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/bpf_sk_storage.c +2 -0
@@ -161,6 +161,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)RCU_INIT_POINTER (newsk->sk_bpf_storage,NULL ); +migrate_disable ();rcu_read_lock (); sk_storage =rcu_dereference (sk->sk_bpf_storage);
@@ -213,6 +214,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk) out:rcu_read_unlock (); +migrate_enable ();/* In case of an error, don't free anything explicitly here, the * caller is responsible to call bpf_sk_storage_free.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/869 rcu: add rcu_read_lock_dont_migrate()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Menglong Dong <[email protected]>
[ Upstream commit 1b93c03fb319d72a1f5f4723abd5df15ce40f4e2 ]
migrate_disable() is called to disable migration in the kernel, and it is often used together with rcu_read_lock().
However, with PREEMPT_RCU disabled, it's unnecessary, as rcu_read_lock() will always disable preemption, which will also disable migration.
Introduce rcu_read_lock_dont_migrate() and rcu_read_unlock_migrate(), which will do the migration enable and disable only when PREEMPT_RCU.
Stable-dep-of: 7cbd0c4cebe4 ("bpf: Fix UAF in sock clone early bailouts")
--- include/linux/rcupdate.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/rcupdate.h +14 -0
@@ -971,6 +971,20 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)preempt_enable_notrace (); } +static __always_inline void rcu_read_lock_dont_migrate(void) +{ +if (IS_ENABLED (CONFIG_PREEMPT_RCU )) +migrate_disable (); +rcu_read_lock (); +} + +static inline void rcu_read_unlock_migrate (void ) +{ +rcu_read_unlock (); +if (IS_ENABLED (CONFIG_PREEMPT_RCU )) +migrate_enable (); +} +/** * RCU_INIT_POINTER() - initialize an RCU protected pointer * @p: The pointer to be initialized.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/869 bpf: Use rcu_read_lock_dont_migrate in bpf_sk_storage.c
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fushuai Wang <[email protected]>
[ Upstream commit 0db4941d9dae159d887e7e2eac7e54e60c3aac87 ]
Use rcu_read_lock_dont_migrate() and rcu_read_unlock_migrate() in bpf_sk_storage.c to obtain better performance when PREEMPT_RCU is not enabled.
Stable-dep-of: 7cbd0c4cebe4 ("bpf: Fix UAF in sock clone early bailouts")
--- net/core/bpf_sk_storage.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
net/core/bpf_sk_storage.c +4 -8
@@ -50,16 +50,14 @@ void bpf_sk_storage_free(struct sock *sk) {struct bpf_local_storage *sk_storage; -migrate_disable (); -rcu_read_lock (); +rcu_read_lock_dont_migrate (); sk_storage =rcu_dereference (sk->sk_bpf_storage);if (!sk_storage) goto out;bpf_local_storage_destroy (sk_storage); out: -rcu_read_unlock (); -migrate_enable (); +rcu_read_unlock_migrate (); }static void bpf_sk_storage_map_free (struct bpf_map *map)
@@ -161,8 +159,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)RCU_INIT_POINTER (newsk->sk_bpf_storage,NULL ); -migrate_disable (); -rcu_read_lock (); +rcu_read_lock_dont_migrate (); sk_storage =rcu_dereference (sk->sk_bpf_storage);if (!sk_storage ||hlist_empty (&sk_storage->list))
@@ -213,8 +210,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk) } out: -rcu_read_unlock (); -migrate_enable (); +rcu_read_unlock_migrate ();/* In case of an error, don't free anything explicitly here, the * caller is responsible to call bpf_sk_storage_free.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/869 bpf: Fix UAF in sock clone early bailouts
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Bobrowski <[email protected]>
[ Upstream commit 7cbd0c4cebe4c9f678d15e6b9ba975e1155a107f ]
Similar to recent commit 9b51a6155d14 ("bpf,fork: wipe ->bpf_storage before bailouts that access it"), sk_clone() performs an initial shallow copy of the socket field ->sk_bpf_storage via sock_copy() for the cloned socket newsk.
If sk_clone() bails out early (e.g. if sk_filter_charge() fails) prior to calling bpf_sk_storage_clone(), newsk->sk_bpf_storage still points to the parent socket's BPF local storage. When newsk is subsequently freed via sk_free(), the deallocation path (__sk_destruct() -> bpf_sk_storage_free()) destroys the parent socket's BPF local storage, leading to a use-after-free (UAF) on the parent socket.
Fix this by resetting newsk->sk_bpf_storage to NULL immediately after sock_copy() in sk_clone(), and remove the now redundant initialization from bpf_sk_storage_clone().
--- net/core/bpf_sk_storage.c | 2 -- net/core/sock.c | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
net/core/bpf_sk_storage.c +0 -2
@@ -157,8 +157,6 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)struct bpf_local_storage_elem *selem;int ret =0 ; -RCU_INIT_POINTER (newsk->sk_bpf_storage,NULL ); -rcu_read_lock_dont_migrate (); sk_storage =rcu_dereference (sk->sk_bpf_storage);
net/core/sock.c +3 -0
@@ -2411,6 +2411,9 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)sock_copy (newsk, sk); newsk->sk_prot_creator = prot; +#ifdef CONFIG_BPF_SYSCALL +RCU_INIT_POINTER (newsk->sk_bpf_storage,NULL ); +#endif /* SANITY */ if (likely (newsk->sk_net_refcnt)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/869 firmware: arm_ffa: Fix out-of-bound writes in ffa_setup_and_transmit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mostafa Saleh <[email protected]>
[ Upstream commit 3383ffb7ef937317361713ffcc21921a7848511a ]
Sashiko (locally) reports multiple out-of-bound issues in ffa_setup_and_transmit:
1) Writing ep_mem_access->reserved can write out of bounds for FFA versions < 1.2 as ffa_emad_size_get() returns 16 bytes in that case while reserved has an offset of 24.
Instead of zeroing fields, memset the struct to zero first based on the FFA version.
2) Make sure there is enough size to write constituents.
While at it, convert the only sizeof() in the driver that uses a type instead of variable.
--- drivers/firmware/arm_ffa/driver.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/firmware/arm_ffa/driver.c +3 -4
@@ -637,11 +637,10 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, drv_info->version);for (idx =0 ; idx < args->nattrs; idx++, ep_mem_access++) { +memset (ep_mem_access,0 ,sizeof (*ep_mem_access)); ep_mem_access->receiver = args->attrs[idx].receiver; ep_mem_access->attrs = args->attrs[idx].attrs; ep_mem_access->composite_off = composite_offset; - ep_mem_access->flag =0 ; - ep_mem_access->reserved =0 ; } mem_region->handle =0 ; mem_region->ep_count = args->nattrs;
@@ -684,7 +683,7 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, constituents = buffer; } -if ((void *)constituents - buffer > max_fragsize) { +if ((void *)constituents +sizeof (*constituents) - buffer > max_fragsize) {pr_err ("Memory Region Fragment > Tx Buffer size\n" );return -EFAULT ; }
@@ -693,7 +692,7 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, constituents->pg_cnt = args->sg->length /FFA_PAGE_SIZE ; constituents->reserved =0 ; constituents++; - frag_len +=sizeof (struct ffa_mem_region_addr_range ); + frag_len +=sizeof (*constituents); }while ((args->sg =sg_next (args->sg))); return ffa_transmit_fragment(func_id, addr, buf_sz, frag_len,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/869 wifi: cfg80211: use wiphy work for socket owner autodisconnect
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 0c2ed186bbe14304415476d6707b747dddcd8583 ]
nl80211_netlink_notify() walks the cfg80211 wireless device list when a NETLINK_GENERIC socket is released. If the socket owns a connection, the notifier queues the embedded wdev->disconnect_wk work item.
That work is a plain work_struct today. NETDEV_GOING_DOWN cancels it, but a NETLINK_URELEASE notifier that already observed conn_owner_nlportid can queue it after that cancel returns. _cfg80211_unregister_wdev() then removes the wdev from the list and waits for RCU readers, but synchronize_net() does not drain work queued by such a reader.
Make the autodisconnect work a wiphy_work instead. The callback already needs the wiphy mutex, and wiphy_work runs under that mutex. This lets teardown cancel pending autodisconnect work while holding the mutex, without a cancel_work_sync() vs. worker locking concern.
Also cancel the wiphy work after list_del_rcu() and synchronize_net(). Any NETLINK_URELEASE notifier that had already reached the wdev list has then either queued the work and it is removed, or can no longer find the wdev.
--- include/net/cfg80211.h | 2 +- net/wireless/core.c | 7 ++++--- net/wireless/core.h | 2 +- net/wireless/nl80211.c | 3 ++- net/wireless/sme.c | 6 ++---- 5 files changed, 10 insertions(+), 10 deletions(-)
include/net/cfg80211.h +1 -1
@@ -6389,7 +6389,7 @@ struct wireless_dev {enum ieee80211_bss_type conn_bss_type;u32 conn_owner_nlportid; -struct work_struct disconnect_wk; +struct wiphy_work disconnect_wk;u8 disconnect_bssid[ETH_ALEN ];struct list_head event_list;
net/wireless/core.c +4 -3
@@ -1280,6 +1280,7 @@ static void _cfg80211_unregister_wdev(struct wireless_dev *wdev,list_del_rcu (&wdev->list);synchronize_net (); rdev->devlist_generation++; +wiphy_work_cancel (wdev->wiphy, &wdev->disconnect_wk);cfg80211_mlme_purge_registrations (wdev);
@@ -1463,7 +1464,7 @@ void cfg80211_init_wdev(struct wireless_dev *wdev) wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr) wdev->netdev->priv_flags |= IFF_DONT_BRIDGE; -INIT_WORK (&wdev->disconnect_wk, cfg80211_autodisconnect_wk); +wiphy_work_init (&wdev->disconnect_wk, cfg80211_autodisconnect_wk); } void cfg80211_register_wdev(struct cfg80211_registered_device *rdev,
@@ -1571,9 +1572,9 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb, scoped_guard(wiphy, &rdev->wiphy) {cfg80211_leave (rdev, wdev);cfg80211_remove_links (wdev); +/* since we just did cfg80211_leave() nothing to do there */ +wiphy_work_cancel (wdev->wiphy, &wdev->disconnect_wk); } -/* since we just did cfg80211_leave() nothing to do there */ -cancel_work_sync (&wdev->disconnect_wk);break ;case NETDEV_DOWN :wiphy_lock (&rdev->wiphy);
net/wireless/core.h +1 -1
@@ -418,7 +418,7 @@ void __cfg80211_port_authorized(struct wireless_dev *wdev, const u8 *peer_addr, const u8 *td_bitmap, u8 td_bitmap_len);int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev,struct wireless_dev *wdev); -void cfg80211_autodisconnect_wk (struct work_struct *work); +void cfg80211_autodisconnect_wk (struct wiphy *wiphy,struct wiphy_work *work);/* SME implementation */ void cfg80211_conn_work (struct work_struct *work);
net/wireless/nl80211.c +2 -1
@@ -20153,7 +20153,8 @@ static int nl80211_netlink_notify(struct notifier_block * nb, wdev->nl_owner_dead = true;schedule_work (&rdev->destroy_work); }else if (wdev->conn_owner_nlportid == notify->portid) { -schedule_work (&wdev->disconnect_wk); +wiphy_work_queue (wdev->wiphy, + &wdev->disconnect_wk); }cfg80211_release_pmsr (wdev, notify->portid);
net/wireless/sme.c +2 -4
@@ -1578,13 +1578,11 @@ int cfg80211_disconnect(struct cfg80211_registered_device *rdev,* Used to clean up after the connection / connection attempt owner socket * disconnects */ -void cfg80211_autodisconnect_wk (struct work_struct *work) +void cfg80211_autodisconnect_wk (struct wiphy *wiphy,struct wiphy_work *work) {struct wireless_dev *wdev = container_of(work, struct wireless_dev, disconnect_wk); -struct cfg80211_registered_device *rdev =wiphy_to_rdev (wdev->wiphy); - -guard (wiphy)(wdev->wiphy); +struct cfg80211_registered_device *rdev =wiphy_to_rdev (wiphy);if (wdev->conn_owner_nlportid) {switch (wdev->iftype) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/869 wifi: mac80211: refactor populating mesh related fields in sinfo
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sarika Sharma <[email protected]>
[ Upstream commit e5328c14590d034dc586e56aaab88e966d06efa7 ]
Introduce the sta_set_mesh_sinfo() to populate mesh related fields in sinfo structure for station statistics.
This will allow for the simplified population of other fields in the sinfo structure for link level in a subsequent patch to add support for MLO station statistics.
No functionality changes added.
Stable-dep-of: aa2eb6252518 ("wifi: mac80211: defer link RX stats percpu free to RCU")
--- net/mac80211/sta_info.c | 64 ++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 29 deletions(-)
net/mac80211/sta_info.c +35 -29
@@ -2573,6 +2573,39 @@ static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)return value; } +#ifdef CONFIG_MAC80211_MESH +static void sta_set_mesh_sinfo (struct sta_info *sta, +struct station_info *sinfo) +{ +struct ieee80211_local *local = sta->sdata->local; + + sinfo->filled |=BIT_ULL (NL80211_STA_INFO_LLID ) | +BIT_ULL (NL80211_STA_INFO_PLID ) | +BIT_ULL (NL80211_STA_INFO_PLINK_STATE ) | +BIT_ULL (NL80211_STA_INFO_LOCAL_PM ) | +BIT_ULL (NL80211_STA_INFO_PEER_PM ) | +BIT_ULL (NL80211_STA_INFO_NONPEER_PM ) | +BIT_ULL (NL80211_STA_INFO_CONNECTED_TO_GATE ) | +BIT_ULL (NL80211_STA_INFO_CONNECTED_TO_AS ); + + sinfo->llid = sta->mesh->llid; + sinfo->plid = sta->mesh->plid; + sinfo->plink_state = sta->mesh->plink_state; +if (test_sta_flag (sta,WLAN_STA_TOFFSET_KNOWN )) { + sinfo->filled |=BIT_ULL (NL80211_STA_INFO_T_OFFSET ); + sinfo->t_offset = sta->mesh->t_offset; + } + sinfo->local_pm = sta->mesh->local_pm; + sinfo->peer_pm = sta->mesh->peer_pm; + sinfo->nonpeer_pm = sta->mesh->nonpeer_pm; + sinfo->connected_to_gate = sta->mesh->connected_to_gate; + sinfo->connected_to_as = sta->mesh->connected_to_as; + + sinfo->filled |=BIT_ULL (NL80211_STA_INFO_AIRTIME_LINK_METRIC ); + sinfo->airtime_link_metric =airtime_link_metric_get (local, sta); +} +#endif +void sta_set_sinfo (struct sta_info *sta,struct station_info *sinfo,bool tidstats) {
@@ -2757,31 +2790,10 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,sta_set_tidstats (sta, &sinfo->pertid[i], i); } -if (ieee80211_vif_is_mesh (&sdata->vif)) {#ifdef CONFIG_MAC80211_MESH - sinfo->filled |=BIT_ULL (NL80211_STA_INFO_LLID ) | -BIT_ULL (NL80211_STA_INFO_PLID ) | -BIT_ULL (NL80211_STA_INFO_PLINK_STATE ) | -BIT_ULL (NL80211_STA_INFO_LOCAL_PM ) | -BIT_ULL (NL80211_STA_INFO_PEER_PM ) | -BIT_ULL (NL80211_STA_INFO_NONPEER_PM ) | -BIT_ULL (NL80211_STA_INFO_CONNECTED_TO_GATE ) | -BIT_ULL (NL80211_STA_INFO_CONNECTED_TO_AS ); - - sinfo->llid = sta->mesh->llid; - sinfo->plid = sta->mesh->plid; - sinfo->plink_state = sta->mesh->plink_state; -if (test_sta_flag (sta,WLAN_STA_TOFFSET_KNOWN )) { - sinfo->filled |=BIT_ULL (NL80211_STA_INFO_T_OFFSET ); - sinfo->t_offset = sta->mesh->t_offset; - } - sinfo->local_pm = sta->mesh->local_pm; - sinfo->peer_pm = sta->mesh->peer_pm; - sinfo->nonpeer_pm = sta->mesh->nonpeer_pm; - sinfo->connected_to_gate = sta->mesh->connected_to_gate; - sinfo->connected_to_as = sta->mesh->connected_to_as; +if (ieee80211_vif_is_mesh (&sdata->vif)) +sta_set_mesh_sinfo (sta, sinfo);#endif - } sinfo->bss_param.flags =0 ;if (sdata->vif.bss_conf.use_cts_prot)
@@ -2837,12 +2849,6 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo, sinfo->filled |=BIT_ULL (NL80211_STA_INFO_ACK_SIGNAL_AVG ); } - -if (ieee80211_vif_is_mesh (&sdata->vif)) { - sinfo->filled |=BIT_ULL (NL80211_STA_INFO_AIRTIME_LINK_METRIC ); - sinfo->airtime_link_metric = -airtime_link_metric_get (local, sta); - } }u32 sta_get_expected_throughput (struct sta_info *sta)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/869 wifi: cfg80211: add link_station_info structure to support MLO statistics
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sarika Sharma <[email protected]>
[ Upstream commit d2329fff7e527e8b350086be2e7cbf0d190177a3 ]
Current implementation of NL80211_GET_STATION does not work for multi-link operation(MLO) since in case of MLO only deflink (or one of the links) is considered and not all links.
Therefore to support for MLO, add link_station_info structure to account link level statistics for station.
Additionally, add valid_links in station_info structure to indicate bitmap of valid links for MLO. This will be helpful to check the link related statistics during MLO.
Stable-dep-of: aa2eb6252518 ("wifi: mac80211: defer link RX stats percpu free to RCU")
--- include/net/cfg80211.h | 101 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+)
include/net/cfg80211.h +101 -0
@@ -2049,6 +2049,99 @@ struct cfg80211_tid_stats {#define IEEE80211_MAX_CHAINS 4 +/** +* struct link_station_info - link station information +* +* Link station information filled by driver for get_station() and +* dump_station(). +* @filled: bit flag of flags using the bits of &enum nl80211_sta_info to +* indicate the relevant values in this struct for them +* @connected_time: time(in secs) since a link of station is last connected +* @inactive_time: time since last activity for link station(tx/rx) +* in milliseconds +* @assoc_at: bootime (ns) of the last association of link of station +* @rx_bytes: bytes (size of MPDUs) received from this link of station +* @tx_bytes: bytes (size of MPDUs) transmitted to this link of station +* @signal: The signal strength, type depends on the wiphy's signal_type. +* For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_. +* @signal_avg: Average signal strength, type depends on the wiphy's +* signal_type. For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_ +* @chains: bitmask for filled values in @chain_signal, @chain_signal_avg +* @chain_signal: per-chain signal strength of last received packet in dBm +* @chain_signal_avg: per-chain signal strength average in dBm +* @txrate: current unicast bitrate from this link of station +* @rxrate: current unicast bitrate to this link of station +* @rx_packets: packets (MSDUs & MMPDUs) received from this link of station +* @tx_packets: packets (MSDUs & MMPDUs) transmitted to this link of station +* @tx_retries: cumulative retry counts (MPDUs) for this link of station +* @tx_failed: number of failed transmissions (MPDUs) (retries exceeded, no ACK) +* @rx_dropped_misc: Dropped for un-specified reason. +* @bss_param: current BSS parameters +* @beacon_loss_count: Number of times beacon loss event has triggered. +* @expected_throughput: expected throughput in kbps (including 802.11 headers) +* towards this station. +* @rx_beacon: number of beacons received from this peer +* @rx_beacon_signal_avg: signal strength average (in dBm) for beacons received +* from this peer +* @rx_duration: aggregate PPDU duration(usecs) for all the frames from a peer +* @tx_duration: aggregate PPDU duration(usecs) for all the frames to a peer +* @airtime_weight: current airtime scheduling weight +* @pertid: per-TID statistics, see &struct cfg80211_tid_stats, using the last +* (IEEE80211_NUM_TIDS) index for MSDUs not encapsulated in QoS-MPDUs. +* Note that this doesn't use the @filled bit, but is used if non-NULL. +* @ack_signal: signal strength (in dBm) of the last ACK frame. +* @avg_ack_signal: average rssi value of ack packet for the no of msdu's has +* been sent. +* @rx_mpdu_count: number of MPDUs received from this station +* @fcs_err_count: number of packets (MPDUs) received from this station with +* an FCS error. This counter should be incremented only when TA of the +* received packet with an FCS error matches the peer MAC address. +* @addr: For MLO STA connection, filled with address of the link of station. +*/ +struct link_station_info { +u64 filled; +u32 connected_time; +u32 inactive_time; +u64 assoc_at; +u64 rx_bytes; +u64 tx_bytes; +s8 signal; +s8 signal_avg; + +u8 chains; +s8 chain_signal[IEEE80211_MAX_CHAINS ]; +s8 chain_signal_avg[IEEE80211_MAX_CHAINS ]; + +struct rate_info txrate; +struct rate_info rxrate; +u32 rx_packets; +u32 tx_packets; +u32 tx_retries; +u32 tx_failed; +u32 rx_dropped_misc; +struct sta_bss_parameters bss_param; + +u32 beacon_loss_count; + +u32 expected_throughput; + +u64 tx_duration; +u64 rx_duration; +u64 rx_beacon; +u8 rx_beacon_signal_avg; + +u16 airtime_weight; + +s8 ack_signal; +s8 avg_ack_signal; +struct cfg80211_tid_stats *pertid; + +u32 rx_mpdu_count; +u32 fcs_err_count; + +u8 addr[ETH_ALEN ]__aligned(2) ; +}; +/** * struct station_info - station information *
@@ -2133,6 +2226,11 @@ struct cfg80211_tid_stats {* dump_station() callbacks. User space needs this information to determine * the accepted and rejected affiliated links of the connected station. * @assoc_resp_ies_len: Length of @assoc_resp_ies buffer in octets. +* @valid_links: bitmap of valid links, or 0 for non-MLO. Drivers fill this +* information in cfg80211_new_sta(), cfg80211_del_sta_sinfo(), +* get_station() and dump_station() callbacks. +* @links: reference to Link sta entries for MLO STA, all link specific +* information is accessed through links[link_id]. */ struct station_info {u64 filled;
@@ -2198,6 +2296,9 @@ struct station_info {u8 mld_addr[ETH_ALEN ]__aligned(2) ;const u8 *assoc_resp_ies;size_t assoc_resp_ies_len; + +u16 valid_links; +struct link_station_info *links[IEEE80211_MLD_MAX_NUM_LINKS ]; };/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/869 wifi: mac80211: defer link RX stats percpu free to RCU
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
[ Upstream commit aa2eb62525188269cdd402a583b9a8ed94657ff0 ]
sta_remove_link() frees a removed MLO link's RX stats percpu buffer right away, but defers only the link container to RCU:
sta_info_free_link(&alloc->info); kfree_rcu(alloc, rcu_head);
The RX fast path reads link_sta under rcu_read_lock and writes the percpu stats. A reader that resolved link_sta before the removal keeps the pointer. The container stays alive from the kfree_rcu, so the read still works. But the percpu block it points to is already freed. This needs uses_rss. That is when pcpu_rx_stats exists.
The full STA teardown frees the deflink stats only after synchronize_net(). The link removal path had no such barrier. The race is hard to win in practice, but the free should still wait for RCU.
Free the link together with its data from a single RCU callback, so the percpu block is reclaimed only after readers drain.
--- net/mac80211/sta_info.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
net/mac80211/sta_info.c +11 -4
@@ -355,6 +355,15 @@ static void sta_info_free_link(struct link_sta_info *link_sta)free_percpu (link_sta->pcpu_rx_stats); } +static void sta_link_free_rcu (struct rcu_head *head) +{ +struct sta_link_alloc *alloc = + container_of(head, struct sta_link_alloc, rcu_head); + +sta_info_free_link (&alloc->info); +kfree (alloc); +} +static void sta_remove_link (struct sta_info *sta,unsigned int link_id,bool unhash) {
@@ -379,10 +388,8 @@ static void sta_remove_link(struct sta_info *sta, unsigned int link_id, sta->sta.valid_links &= ~BIT (link_id);RCU_INIT_POINTER (sta->link[link_id],NULL );RCU_INIT_POINTER (sta->sta.link[link_id],NULL ); -if (alloc) { -sta_info_free_link (&alloc->info); -kfree_rcu (alloc, rcu_head); - } +if (alloc) +call_rcu (&alloc->rcu_head, sta_link_free_rcu);ieee80211_sta_recalc_aggregates (&sta->sta); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/869 wifi: cfg80211: Fix an error handling path in cfg80211_wext_siwscan()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit c6659f66d4ee4841aafae5659d2ef5e4c5c63cb6 ]
If the test against IEEE80211_MAX_SSID_LEN fails, then 'creq' leaks. Use the existing error handling path to fix it.
--- net/wireless/scan.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/wireless/scan.c +4 -2
@@ -3574,8 +3574,10 @@ int cfg80211_wext_siwscan(struct net_device *dev,/* translate "Scan for SSID" request */ if (wreq) {if (wrqu->data.flags &IW_SCAN_THIS_ESSID ) { -if (wreq->essid_len >IEEE80211_MAX_SSID_LEN ) -return -EINVAL ; +if (wreq->essid_len >IEEE80211_MAX_SSID_LEN ) { + err = -EINVAL ; + goto out; + }memcpy (creq->ssids[0 ].ssid, wreq->essid, wreq->essid_len); creq->ssids[0 ].ssid_len = wreq->essid_len; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/869 RDMA/irdma: Prevent user-triggered null deref on QP create
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Moroni <[email protected]>
[ Upstream commit b9b0889071569d43623c260074e159cd8f26adb1 ]
Previously, the user QP creation path would only attempt to populate iwqp->iwpbl if the user-provided req.user_wqe_bufs field was non-zero. The problem is that iwqp->iwpbl is unconditionally dereferenced later on in irdma_setup_virt_qp.
While there was a check for iwqp->iwpbl != NULL, this check would only occur if req.user_wqe_bufs was non-zero. The end result is that a user could send a zero user_wqe_bufs value and trigger a null ptr deref.
Fix this by unconditionally calling irdma_get_pbl and bailing if it fails, similar to the CQ and SRQ paths.
--- drivers/infiniband/hw/irdma/verbs.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/infiniband/hw/irdma/verbs.c +11 -11
@@ -602,18 +602,18 @@ static int irdma_setup_umode_qp(struct ib_udata *udata, iwqp->ctx_info.qp_compl_ctx = req.user_compl_ctx; iwqp->user_mode =1 ; -if (req.user_wqe_bufs) { - info->qp_uk_init_info.legacy_mode = ucontext->legacy_mode; -spin_lock_irqsave (&ucontext->qp_reg_mem_list_lock, flags); - iwqp->iwpbl =irdma_get_pbl ((unsigned long )req.user_wqe_bufs, - &ucontext->qp_reg_mem_list); -spin_unlock_irqrestore (&ucontext->qp_reg_mem_list_lock, flags); -if (!iwqp->iwpbl) { - ret = -ENODATA ; -ibdev_dbg (&iwdev->ibdev,"VERBS: no pbl info\n" ); -return ret; - } + info->qp_uk_init_info.legacy_mode = ucontext->legacy_mode; + +spin_lock_irqsave (&ucontext->qp_reg_mem_list_lock, flags); + iwqp->iwpbl =irdma_get_pbl ((unsigned long )req.user_wqe_bufs, + &ucontext->qp_reg_mem_list); +spin_unlock_irqrestore (&ucontext->qp_reg_mem_list_lock, flags); + +if (!iwqp->iwpbl) { + ret = -ENODATA ; +ibdev_dbg (&iwdev->ibdev,"VERBS: no pbl info\n" ); +return ret; }if (!ucontext->use_raw_attrs) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/869 sched_ext: Dont warn on core-sched forced idle in put_prev_task_scx()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
[ Upstream commit b7d9c359e5cf867f7eb23df3bb1c6b9e58af24da ]
put_prev_task_scx() warns when a runnable task drops to a lower sched_class without SCX_OPS_ENQ_LAST, on the assumption that balance_one() would have kept it running. Core scheduling breaks that: a forced-idle SMT sibling reschedules through the core_pick fast path in pick_next_task(), which skips pick_task_scx() and thus balance_one(), so a runnable task can drop to idle with ENQ_LAST unset.
Gate the warning on sched_cpu_cookie_match(): a cookie mismatch means core scheduling forced the idle, while a match (or core scheduling off) still catches a genuine missing-ENQ_LAST drop.
--- kernel/sched/ext.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/sched/ext.c +6 -1
@@ -3085,9 +3085,14 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,* sched_class, %SCX_OPS_ENQ_LAST must be set. Tell * ops.enqueue() that @p is the only one available for this cpu, * which should trigger an explicit follow-up scheduling event. +* +* Core scheduling can force this CPU idle while @p stays +* runnable. @p's cookie then won't match the core's, so skip +* the warning in that case. */ if (sched_class_above (&ext_sched_class, next->sched_class)) { -WARN_ON_ONCE (!static_branch_unlikely (&scx_ops_enq_last)); +WARN_ON_ONCE (sched_cpu_cookie_match (rq, p) && + !static_branch_unlikely (&scx_ops_enq_last));do_enqueue_task (rq, p,SCX_ENQ_LAST ,-1 ); }else {do_enqueue_task (rq, p,0 ,-1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/869 xfrm: fix stale skb->prev after async crypto steals a GSO segment
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Wozniak <[email protected]>
[ Upstream commit 3f4c3919baf0944ad96580467c302bc6c7758b00 ]
skb_gso_segment() leaves the segment list head with ->prev pointing at the last segment, an invariant validate_xmit_skb_list() relies on when it sets its tail pointer (tail = skb->prev).
When validate_xmit_xfrm() walks a GSO list and some segments are stolen by async crypto (->xmit() returns -EINPROGRESS), those segments are unlinked from the list but the head ->prev is never updated. If the last segment is the one stolen, the returned head still has ->prev pointing at it, even though it is now owned by the crypto engine and may be freed. validate_xmit_skb_list() later does tail->next = skb, writing through that stale pointer -- a use-after-free.
Repoint skb->prev at the last retained segment before returning.
--- net/xfrm/xfrm_device.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/xfrm/xfrm_device.c +8 -0
@@ -226,6 +226,14 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featur pskb = skb2; } +/* skb_gso_segment() set skb->prev to the last segment, but async +* crypto may have stolen it above without updating ->prev. Repoint +* it at the last retained segment so validate_xmit_skb_list() does +* not chain onto a segment now owned by the crypto engine. +*/ +if (skb) + skb->prev = pskb; +return skb; }EXPORT_SYMBOL_GPL (validate_xmit_xfrm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/869 LoongArch: Fix address space mismatch in kexec command line lookup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: George Guo <[email protected]>
[ Upstream commit 485ed44db5694d8d2e5027f63ad608e705286f30 ]
When searching the loaded segments for the "kexec" command line marker, the kexec_load(2) path (file_mode == 0) passes the user-space segment buffer straight to strncmp() through a bogus (char __user *) cast. This dereferences a user pointer in kernel context, which is wrong and is flagged by sparse:
arch/loongarch/kernel/machine_kexec.c:84:51: sparse: incorrect type in argument 2 (different address spaces) @@ expected char const * @@ got char [noderef] __user *
Here copy the marker-sized prefix of each segment into a small on-stack buffer with copy_from_user() before comparing, and skip segments that fault. The subsequent copy_from_user() that stages the full command line into the safe area is left unchanged.
--- arch/loongarch/kernel/machine_kexec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/loongarch/kernel/machine_kexec.c +4 -1
@@ -62,6 +62,7 @@ static void kexec_image_info(const struct kimage *kimage)int machine_kexec_prepare (struct kimage *kimage) {int i; +char head[8 ];char *bootloader ="kexec" ;void *cmdline_ptr = (void *)KEXEC_CMDLINE_ADDR ;
@@ -72,7 +73,9 @@ int machine_kexec_prepare(struct kimage *kimage)/* Find the command line */ for (i =0 ; i < kimage->nr_segments; i++) { -if (!strncmp (bootloader, (char __user *)kimage->segment[i].buf,strlen (bootloader))) { +if (copy_from_user (head, kimage->segment[i].buf,strlen (bootloader))) +continue ; +if (!strncmp (bootloader, head,strlen (bootloader))) {if (!copy_from_user (cmdline_ptr, kimage->segment[i].buf,COMMAND_LINE_SIZE )) kimage->arch.cmdline_ptr = (unsigned long )cmdline_ptr;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/869 drm/amd/display: use kvzalloc to allocate struct dc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Honglei Huang <[email protected]>
[ Upstream commit 75050390151a14802be433c3856ddcb483cecd24 ]
struct dc has grown large over time (most of it the two inlined dc_scratch_space copies) and now sits close to the page allocator's 4 MiB contiguous allocation limit. Its actual size is not fixed by the source alone, it also depends on the compiler and the .config, so it can easily cross 4 MiB, e.g. with a newer GCC or a config change.
dc_create() allocates it with kzalloc(). Once struct dc exceeds 4 MiB the request is rounded up to order 11 (8 MiB), which is above MAX_PAGE_ORDER, so the page allocator warns and returns NULL. dc_create() then fails, DM init fails and amdgpu probe aborts with -EINVAL:
WARNING: mm/page_alloc.c:5197 at __alloc_frozen_pages_noprof+0x2f9/0x380 dc_create+0x38/0x660 [amdgpu] amdgpu_dm_init+0x2d9/0x510 [amdgpu] dm_hw_init+0x1b/0x90 [amdgpu] amdgpu_device_init.cold+0x150d/0x1e13 [amdgpu] amdgpu_driver_load_kms+0x19/0x80 [amdgpu] amdgpu_pci_probe+0x1e2/0x4c0 [amdgpu]
dc_create() then returns NULL and DM init fails, which aborts the whole GPU init and makes amdgpu probe fail with -EINVAL ("hw_init of IP block <dm> failed -22"), leaving the display unusable. The subsequent amdgpu_irq_put() warnings during teardown are just fallout of unwinding a half-initialized device.
struct dc is a software-only bookkeeping structure that is never handed to hardware DMA and is only ever kept as an opaque pointer, so it does not require physically contiguous memory. Allocate it with kvzalloc() (and free it with kvfree()) so that the allocator can fall back to vmalloc() when a contiguous allocation of that size is not available, which also avoids the MAX_PAGE_ORDER warning entirely.
v2:
- Rebase to amd-staging-drm-next.
--- drivers/gpu/drm/amd/display/dc/core/dc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +3 -3
@@ -1377,7 +1377,7 @@ static void disable_vbios_mode_if_required(struct dc *dc_create (const struct dc_init_data *init_params) { -struct dc *dc =kzalloc (sizeof (*dc),GFP_KERNEL ); +struct dc *dc =kvzalloc (sizeof (*dc),GFP_KERNEL );unsigned int full_pipe_count;if (!dc)
@@ -1425,7 +1425,7 @@ struct dc *dc_create(const struct dc_init_data *init_params) destruct_dc:dc_destruct (dc); -kfree (dc); +kvfree (dc);return NULL ; }
@@ -1474,7 +1474,7 @@ void dc_deinit_callbacks(struct dc *dc)void dc_destroy (struct dc **dc) {dc_destruct (*dc); -kfree (*dc); +kvfree (*dc); *dc =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/869 net/sched: Handle TC_ACT_REDIRECT from qdisc filter chains
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit ec48b3be2c8595dd290be883dbd4fb8b2f9f5d5e ]
When a TC filter attached to a qdisc filter chain returns TC_ACT_REDIRECT (ex: via an eBPF program calling bpf_redirect() or an act_bpf action), the redirect was silently lost i.e no qdisc classify function handled TC_ACT_REDIRECT, so the packet fell through the switch and was enqueued normally instead of being redirected.
This has been broken since bpf_redirect() was introduced for TC in commit 27b29f63058d ("bpf: add bpf_redirect() helper"). We got lucky for a long time because bpf_net_context was a per-CPU variable that was always available.
commit 401cb7dae813 ("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.") turned bpf_net_context into a task_struct member that is only set up by explicit callers. Without a caller setting it up, bpf_redirect() itself crashes with a NULL pointer dereference in bpf_net_ctx_get_ri(). However, even with bpf_net_context available, TC_ACT_REDIRECT from qdisc filter chains cannot be honored without adding skb_do_redirect() calls to every qdisc classify function, which would require changes across net/sched/. Isolate it to ebpf core where it belongs.
Instead, add a tcf_classify_qdisc() inline helper in pkt_cls.h, as a wrapper around tcf_classify() for use by qdisc classify functions and tcf_qevent_handle(). When the classify verdict is TC_ACT_REDIRECT, the wrapper converts it to TC_ACT_SHOT, dropping the packet rather than letting it continue silently. Dropping is preferred over letting the packet through because the user immediately sees packet loss. Silently passing the packet through would hide the problem and leave the user wondering why their redirect is not working.
The clsact fast path, tc_run() continues to call tcf_classify() directly and is unaffected: TC_ACT_REDIRECT is returned as-is and handled by sch_handle_egress/ingress() calling skb_do_redirect() as before.
--- include/net/pkt_cls.h | 14 +++++++++++++- net/sched/cls_api.c | 4 +--- net/sched/sch_cake.c | 2 +- net/sched/sch_drr.c | 2 +- net/sched/sch_ets.c | 2 +- net/sched/sch_fq_codel.c | 2 +- net/sched/sch_fq_pie.c | 2 +- net/sched/sch_hfsc.c | 2 +- net/sched/sch_htb.c | 2 +- net/sched/sch_multiq.c | 2 +- net/sched/sch_prio.c | 2 +- net/sched/sch_qfq.c | 2 +- net/sched/sch_sfb.c | 2 +- net/sched/sch_sfq.c | 2 +- 14 files changed, 26 insertions(+), 16 deletions(-)
include/net/pkt_cls.h +13 -1
@@ -156,8 +156,20 @@ static inline int tcf_classify(struct sk_buff *skb, {return TC_ACT_UNSPEC ; } -#endif +static inline int tcf_classify_qdisc (struct sk_buff *skb, +const struct tcf_proto *tp, +struct tcf_result *res,bool compat_mode) +{ +int ret =tcf_classify (skb,NULL , tp, res, compat_mode); + +/* TC_ACT_REDIRECT from qdisc filter chains is not supported. +* Use BPF via tcx or mirred redirect instead. +*/ +if (unlikely (ret ==TC_ACT_REDIRECT )) + ret =TC_ACT_SHOT ; +return ret; +}static inline unsigned long __cls_set_class (unsigned long *clp,unsigned long cl)
net/sched/cls_api.c +1 -3
@@ -4071,9 +4071,7 @@ struct sk_buff *tcf_qevent_handle(struct tcf_qevent *qe, struct Qdisc *sch, stru fl =rcu_dereference_bh (qe->filter_chain); -switch (tcf_classify (skb,NULL , fl, &cl_res, false)) { -case TC_ACT_REDIRECT : - fallthrough; +switch (tcf_classify_qdisc (skb, fl, &cl_res, false)) {case TC_ACT_SHOT :qdisc_qstats_drop (sch);__qdisc_drop (skb, to_free);
net/sched/sch_cake.c +1 -1
@@ -1704,7 +1704,7 @@ static u32 cake_classify(struct Qdisc *sch, struct cake_tin_data **t, goto hash; *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; - result =tcf_classify (skb,NULL , filter, &res, false); + result =tcf_classify_qdisc (skb, filter, &res, false);if (result >=0 ) {#ifdef CONFIG_NET_CLS_ACT
net/sched/sch_drr.c +1 -1
@@ -313,7 +313,7 @@ static struct drr_class *drr_classify(struct sk_buff *skb, struct Qdisc *sch, *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; fl =rcu_dereference_bh (q->filter_list); - result =tcf_classify (skb,NULL , fl, &res, false); + result =tcf_classify_qdisc (skb, fl, &res, false);if (result >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {
net/sched/sch_ets.c +1 -1
@@ -389,7 +389,7 @@ static struct ets_class *ets_classify(struct sk_buff *skb, struct Qdisc *sch, *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;if (TC_H_MAJ (skb->priority) != sch->handle) { fl =rcu_dereference_bh (q->filter_list); - err =tcf_classify (skb,NULL , fl, &res, false); + err =tcf_classify_qdisc (skb, fl, &res, false);#ifdef CONFIG_NET_CLS_ACT switch (err) {case TC_ACT_STOLEN :
net/sched/sch_fq_codel.c +1 -1
@@ -91,7 +91,7 @@ static unsigned int fq_codel_classify(struct sk_buff *skb, struct Qdisc *sch,return fq_codel_hash (q, skb) +1 ; *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; - result =tcf_classify (skb,NULL , filter, &res, false); + result =tcf_classify_qdisc (skb, filter, &res, false);if (result >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {
net/sched/sch_fq_pie.c +1 -1
@@ -96,7 +96,7 @@ static unsigned int fq_pie_classify(struct sk_buff *skb, struct Qdisc *sch,return fq_pie_hash (q, skb) +1 ; *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; - result =tcf_classify (skb,NULL , filter, &res, false); + result =tcf_classify_qdisc (skb, filter, &res, false);if (result >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {
net/sched/sch_hfsc.c +1 -1
@@ -1154,7 +1154,7 @@ hfsc_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) head = &q->root; drift =HFSC_CLASSIFY_MAX_DRIFT ; tcf =rcu_dereference_bh (q->root.filter_list); -while (tcf && (result =tcf_classify (skb,NULL , tcf, &res, false)) >=0 ) { +while (tcf && (result =tcf_classify_qdisc (skb, tcf, &res, false)) >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {case TC_ACT_QUEUED :
net/sched/sch_htb.c +1 -1
@@ -243,7 +243,7 @@ static struct htb_class *htb_classify(struct sk_buff *skb, struct Qdisc *sch, } *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; -while (tcf && (result =tcf_classify (skb,NULL , tcf, &res, false)) >=0 ) { +while (tcf && (result =tcf_classify_qdisc (skb, tcf, &res, false)) >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {case TC_ACT_QUEUED :
net/sched/sch_multiq.c +1 -1
@@ -36,7 +36,7 @@ multiq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)int err; *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; - err =tcf_classify (skb,NULL , fl, &res, false); + err =tcf_classify_qdisc (skb, fl, &res, false);#ifdef CONFIG_NET_CLS_ACT switch (err) {case TC_ACT_STOLEN :
net/sched/sch_prio.c +1 -1
@@ -39,7 +39,7 @@ prio_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;if (TC_H_MAJ (skb->priority) != sch->handle) { fl =rcu_dereference_bh (q->filter_list); - err =tcf_classify (skb,NULL , fl, &res, false); + err =tcf_classify_qdisc (skb, fl, &res, false);#ifdef CONFIG_NET_CLS_ACT switch (err) {case TC_ACT_STOLEN :
net/sched/sch_qfq.c +1 -1
@@ -712,7 +712,7 @@ static struct qfq_class *qfq_classify(struct sk_buff *skb, struct Qdisc *sch, *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; fl =rcu_dereference_bh (q->filter_list); - result =tcf_classify (skb,NULL , fl, &res, false); + result =tcf_classify_qdisc (skb, fl, &res, false);if (result >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {
net/sched/sch_sfb.c +1 -1
@@ -260,7 +260,7 @@ static bool sfb_classify(struct sk_buff *skb, struct tcf_proto *fl,struct tcf_result res;int result; - result =tcf_classify (skb,NULL , fl, &res, false); + result =tcf_classify_qdisc (skb, fl, &res, false);if (result >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {
net/sched/sch_sfq.c +1 -1
@@ -171,7 +171,7 @@ static unsigned int sfq_classify(struct sk_buff *skb, struct Qdisc *sch,return sfq_hash (q, skb) +1 ; *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; - result =tcf_classify (skb,NULL , fl, &res, false); + result =tcf_classify_qdisc (skb, fl, &res, false);if (result >=0 ) {#ifdef CONFIG_NET_CLS_ACT switch (result) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/869 drm/amdkfd: clamp v9 CRIU control stack checkpoint copy to BO size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongqiang Sun <[email protected]>
[ Upstream commit 426ffae6ecc7ec77d32bf8be065c21a1b881b084 ]
CRIU checkpoint copies the MQD control stack using cp_hqd_cntl_stack_size from hardware without bounding it to the allocated BO region. If the HW field is larger than the queue's control stack allocation, memcpy reads past the BO into adjacent GTT memory and can leak kernel data to userspace.
Store the page-aligned control stack BO size in mqd_manager and clamp checkpoint copies and reported checkpoint sizes to min(cp_hqd_cntl_stack_size, mm->ctl_stack_size). Apply the same bound for multi-XCC v9.4.3 checkpoint layout.
--- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +9 -2
@@ -27,6 +27,7 @@#include <linux/uaccess.h> #include "kfd_priv.h" #include "kfd_mqd_manager.h" +#include "kfd_topology.h" #include "v9_structs.h" #include "gc/gc_9_0_offset.h" #include "gc/gc_9_0_sh_mask.h"
@@ -375,20 +376,26 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd,static void get_checkpoint_info (struct mqd_manager *mm,void *mqd,u32 *ctl_stack_size) {struct v9_mqd *m =get_mqd (mqd); +struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (mm->dev->id); +u32 bo_size = topo_dev ?ALIGN (topo_dev->node_props.ctl_stack_size,PAGE_SIZE ) :0 ; - *ctl_stack_size = m->cp_hqd_cntl_stack_size; + *ctl_stack_size =min_t (u32, m->cp_hqd_cntl_stack_size, bo_size); }static void checkpoint_mqd (struct mqd_manager *mm,void *mqd,void *mqd_dst,void *ctl_stack_dst) {struct v9_mqd *m; +struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (mm->dev->id); +u32 bo_size = topo_dev ?ALIGN (topo_dev->node_props.ctl_stack_size,PAGE_SIZE ) :0 ; +u32 ctl_stack_copy_size;/* Control stack is located one page after MQD. */ void *ctl_stack = (void *)((uintptr_t )mqd +PAGE_SIZE ); m =get_mqd (mqd); + ctl_stack_copy_size =min_t (u32, m->cp_hqd_cntl_stack_size, bo_size);memcpy (mqd_dst, m,sizeof (struct v9_mqd )); -memcpy (ctl_stack_dst, ctl_stack, m->cp_hqd_cntl_stack_size); +memcpy (ctl_stack_dst, ctl_stack, ctl_stack_copy_size); } static void restore_mqd(struct mqd_manager *mm, void **mqd,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/869 ovl: check access to copy_file_range source with src mounter creds
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit a1e0eb8f55cfe09bb31a202a388babc411292656 ]
Commit 5dae222a5ff0c ("vfs: allow copy_file_range to copy across devices") allowed filesystems that implement the copy_file_range() f_op to decide if they want to access cross-sb copy from/to the same fs type.
The same commit added checks to verify same sb copy for filesystems that implement ->copy_file_range() and do not support cross-sb copy at the time, namely, to ceph, fuse and nfs.
The two remaining fs which implement ->copy_file_range(), cifs and overlayfs started to support cross-sb copy from this time.
While overlayfs does support cross-sb copy when the two underlying files are on the same base fs, the copy operation on the two real files from two different overalyfs filesystems is performed with the mounter creds of the destination overlayfs and the read permission access hook for the source file was called with the wrong creds.
This could cause either deny of access to copy which would otherwise be allowed (e.g. with splice) or allow read access to file which would otherwise be denied.
Fix the latter case by explicitly verifying read access to source file with the source overlayfs mounter creds.
The former case remains a quirk of cross-sb overlayfs copy, but userspace could fall back to regular copy so no harm done.
--- fs/overlayfs/file.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
fs/overlayfs/file.c +16 -1
@@ -488,6 +488,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int flags, enum ovl_copyop op) { + struct inode *inode_in = file_inode(file_in);struct inode *inode_out =file_inode (file_out);struct fd real_in, real_out;const struct cred *old_cred;
@@ -512,7 +513,20 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, goto out_unlock; } - old_cred =ovl_override_creds (file_inode (file_out)->i_sb); +/* +* For cross-sb copy, vfs_copy_file_range() will verify read access with +* the mounter creds of the dest fs mounter, so we need to explicitly +* verify read access with the source mounter creds. +*/ +if (unlikely (inode_in->i_sb != inode_out->i_sb)) { + old_cred =ovl_override_creds (inode_in->i_sb); + ret =rw_verify_area (READ ,fd_file (real_in), &pos_in, len); +revert_creds (old_cred); +if (unlikely (ret)) + goto out_fdput; + } + + old_cred =ovl_override_creds (inode_out->i_sb);switch (op) {case OVL_COPY : ret = vfs_copy_file_range(fd_file(real_in), pos_in,
@@ -535,6 +549,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,/* Update size */ ovl_file_modified (file_out); +out_fdput:fdput (real_in);fdput (real_out);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/869 s390/zcrypt: Fix buffer over-read in cca_cipher2protkey
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
[ Upstream commit 36b230835b8a008266aad22168ca52afacc8a58d ]
Add validation of both the actual key buffer size and token length fields in all the cca_check_sec*token() functions. Additionally check in cca_gencipherkey() for possible underflow with returned key size.
The CCA token structures contain user-controlled len fields that were used in operations without proper validation against both the actual buffer size and minimum token structure size. An attacker could set this field larger than the actual buffer size, leading to reading beyond buffer boundaries. This may result in a kernel crash or exposure of memory via sending this as part of a request down to the crypto card. Also an attacker could have used a very small len value and thus enforce a buffer under-run which may produce similar effects as a over-read.
So now a key must
- key buf length must be at least sizeof the token struct
- the key len field inside the token must fit into the range of sizeof key token struct ... key buf length
--- drivers/s390/crypto/pkey_cca.c | 11 +++-- drivers/s390/crypto/zcrypt_ccamisc.c | 64 +++++++++++++++++++++++----- drivers/s390/crypto/zcrypt_ccamisc.h | 6 +-- 3 files changed, 62 insertions(+), 19 deletions(-)
drivers/s390/crypto/pkey_cca.c +5 -6
@@ -227,7 +227,7 @@ static int cca_key2protkey(const struct pkey_apqn *apqns, size_t nr_apqns,/* CCA AES data key */ if (keylen !=sizeof (struct secaeskeytoken ))return -EINVAL ; -if (cca_check_secaeskeytoken (pkey_dbf_info,3 , key,0 )) +if (cca_check_secaeskeytoken (pkey_dbf_info,3 , key, keylen,0 ))return -EINVAL ; }else if (hdr->type ==TOKTYPE_CCA_INTERNAL && hdr->version ==TOKVER_CCA_VLSC ) {
@@ -235,12 +235,10 @@ static int cca_key2protkey(const struct pkey_apqn *apqns, size_t nr_apqns,if (keylen < hdr->len || keylen >MAXCCAVLSCTOKENSIZE )return -EINVAL ;if (cca_check_secaescipherkey (pkey_dbf_info, -3 , key,0 ,1 )) +3 , key, keylen,0 ,1 ))return -EINVAL ; }else if (hdr->type ==TOKTYPE_CCA_INTERNAL_PKA ) {/* CCA ECC (private) key */ -if (keylen <sizeof (struct eccprivkeytoken )) -return -EINVAL ;if (cca_check_sececckeytoken (pkey_dbf_info,3 , key, keylen,1 ))return -EINVAL ; }else {
@@ -474,7 +472,7 @@ static int cca_verifykey(const u8 *key, u32 keylen, hdr->version == TOKVER_CCA_AES) {struct secaeskeytoken *t = (struct secaeskeytoken *)key; - rc =cca_check_secaeskeytoken (pkey_dbf_info,3 , key,0 ); + rc =cca_check_secaeskeytoken (pkey_dbf_info,3 , key, keylen,0 );if (rc) goto out; *keytype =PKEY_TYPE_CCA_DATA ;
@@ -501,7 +499,8 @@ static int cca_verifykey(const u8 *key, u32 keylen, hdr->version == TOKVER_CCA_VLSC) {struct cipherkeytoken *t = (struct cipherkeytoken *)key; - rc =cca_check_secaescipherkey (pkey_dbf_info,3 , key,0 ,1 ); + rc =cca_check_secaescipherkey (pkey_dbf_info,3 , + key, keylen,0 ,1 );if (rc) goto out; *keytype =PKEY_TYPE_CCA_CIPHER ;
drivers/s390/crypto/zcrypt_ccamisc.c +54 -10
141 lines not on this page · raw message
drivers/s390/crypto/zcrypt_ccamisc.h +3 -3
@@ -135,7 +135,7 @@ struct eccprivkeytoken {* also checked. Returns 0 on success or errno value on failure. */ int cca_check_secaeskeytoken (debug_info_t *dbg,int dbflvl, -const u8 *token,int keybitsize); +const u8 *token,u32 keysize,int keybitsize);/* * Simple check if the token is a valid CCA secure AES cipher key
@@ -145,8 +145,8 @@ int cca_check_secaeskeytoken(debug_info_t *dbg, int dbflvl,* Returns 0 on success or errno value on failure. */ int cca_check_secaescipherkey (debug_info_t *dbg,int dbflvl, -const u8 *token,int keybitsize, -int checkcpacfexport); +const u8 *token,u32 keysize, +int keybitsize,int checkcpacfexport);/* * Simple check if the token is a valid CCA secure ECC private
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/869 wifi: mac80211: validate extension-frame layout before RX
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit 57d503ce32eccfa7650065ca4c560f7e29a2e676 ]
Extension frames only have the extension header at the regular 802.11 header offset. The generic RX path can still reach helpers and interface dispatch code that read regular header address fields before unsupported extension subtypes are dropped.
mac80211 currently only handles S1G beacon extension frames. Drop other extension subtypes before they can reach regular-header RX processing. For S1G beacons, linearize the SKB with the management-frame path and require the fixed S1G beacon header, including optional fixed fields indicated by frame control, before generic RX dispatch.
Route S1G beacons through the station/default-link RX path without regular-header station lookup. Avoid regular-header address reads in the mac80211 RX paths that process S1G extension beacons, including accept-frame, duplicate-detection, address-copy, and MLO address-translation paths.
Also make ieee80211_get_bssid() length-safe before returning the S1G source-address pointer.
--- net/mac80211/rx.c | 34 ++++++++++++++++++++++++++++++++-- net/mac80211/util.c | 3 +++ 2 files changed, 35 insertions(+), 2 deletions(-)
net/mac80211/rx.c +32 -2
@@ -1425,6 +1425,9 @@ ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)if (status->flag &RX_FLAG_DUP_VALIDATED )return RX_CONTINUE ; +if (ieee80211_is_ext (hdr->frame_control)) +return RX_CONTINUE ; +/* * Drop duplicate 802.11 retransmissions * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
@@ -4447,8 +4450,12 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)struct ieee80211_hdr *hdr = (void *)skb->data;struct ieee80211_rx_status *status =IEEE80211_SKB_RXCB (skb);u8 *bssid =ieee80211_get_bssid (hdr, skb->len, sdata->vif.type); -bool multicast =is_multicast_ether_addr (hdr->addr1) || -ieee80211_is_s1g_beacon (hdr->frame_control); +bool multicast; + +if (ieee80211_is_s1g_beacon (hdr->frame_control)) +return sdata->vif.type ==NL80211_IFTYPE_STATION && bssid; + + multicast =is_multicast_ether_addr (hdr->addr1);switch (sdata->vif.type) {case NL80211_IFTYPE_STATION :
@@ -5087,6 +5094,11 @@ static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, hdr = (struct ieee80211_hdr *)rx->skb->data; } +if (ieee80211_is_s1g_beacon (hdr->frame_control)) { +ieee80211_invoke_rx_handlers (rx); +return true; + } + if (unlikely(rx->sta && rx->sta->sta.mlo) && is_unicast_ether_addr(hdr->addr1) && !ieee80211_is_probe_resp(hdr->frame_control) &&
@@ -5171,6 +5183,13 @@ static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx,struct sta_info *sta;int link_id =-1 ; +if (ieee80211_is_s1g_beacon (hdr->frame_control)) { +if (!ieee80211_rx_data_set_sta (rx,NULL ,-1 )) +return false; + +return ieee80211_prepare_and_rx_handle (rx, skb, consume); + } +/* * Look up link station first, in case there's a * chance that they might have a link address that
@@ -5230,6 +5249,17 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, err = -ENOBUFS ; else err =skb_linearize (skb); + }else if (ieee80211_is_s1g_beacon (fc)) { +size_t s1g_hdr_len = offsetof(struct ieee80211_ext , + u.s1g_beacon.variable) + +ieee80211_s1g_optional_len (fc); + +if (skb->len < s1g_hdr_len) + err = -ENOBUFS ; +else + err =skb_linearize (skb); + }else if (ieee80211_is_ext (fc)) { + err = -EINVAL ; }else { err = !pskb_may_pull (skb,ieee80211_hdrlen (fc)); }
net/mac80211/util.c +3 -0
@@ -73,6 +73,9 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,if (ieee80211_is_s1g_beacon (fc)) {struct ieee80211_ext *ext = (void *) hdr; + if (len < offsetofend(struct ieee80211_ext, u.s1g_beacon.sa)) +return NULL ; +return ext->u.s1g_beacon.sa; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/869 wifi: ieee80211: validate MLE common info length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit 293baeae9b2434a3e432629d7720b5603db2d77e ]
ieee80211_mle_common_size() uses the first common-info octet as the common information length for all known MLE types. However, ieee80211_mle_size_ok() only validates that octet for Basic, Probe Request, and TDLS MLEs.
Reconfiguration MLEs also skipped the length octet when calculating the minimum common size, and Priority Access MLEs skipped validation of the advertised common information length.
Account for the Reconfiguration common-info length octet and validate the advertised common information length for all known MLE types. Keep unknown-type handling unchanged.
--- include/linux/ieee80211.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
include/linux/ieee80211.h +4 -8
@@ -5348,7 +5348,7 @@ static inline bool ieee80211_mle_size_ok(const u8 *data, size_t len)const struct ieee80211_multi_link_elem *mle = (const void *)data;u8 fixed =sizeof (*mle);u8 common =0 ; -bool check_common_len = false; +u8 common_len;u16 control;if (!data || len < fixed)
@@ -5359,7 +5359,6 @@ static inline bool ieee80211_mle_size_ok(const u8 *data, size_t len)switch (u16_get_bits (control,IEEE80211_ML_CONTROL_TYPE )) {case IEEE80211_ML_CONTROL_TYPE_BASIC : common +=sizeof (struct ieee80211_mle_basic_common_info ); - check_common_len = true;if (control &IEEE80211_MLC_BASIC_PRES_LINK_ID ) common +=1 ;if (control &IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT )
@@ -5377,15 +5376,14 @@ static inline bool ieee80211_mle_size_ok(const u8 *data, size_t len) common +=sizeof (struct ieee80211_mle_preq_common_info );if (control &IEEE80211_MLC_PREQ_PRES_MLD_ID ) common +=1 ; - check_common_len = true;break ;case IEEE80211_ML_CONTROL_TYPE_RECONF : + common +=1 ;if (control &IEEE80211_MLC_RECONF_PRES_MLD_MAC_ADDR ) common +=ETH_ALEN ;break ;case IEEE80211_ML_CONTROL_TYPE_TDLS : common +=sizeof (struct ieee80211_mle_tdls_common_info ); - check_common_len = true;break ;case IEEE80211_ML_CONTROL_TYPE_PRIO_ACCESS : common =ETH_ALEN +1 ;
@@ -5398,11 +5396,9 @@ static inline bool ieee80211_mle_size_ok(const u8 *data, size_t len)if (len < fixed + common)return false; -if (!check_common_len) -return true; + common_len = mle->variable[0 ]; -/* if present, common length is the first octet there */ -return mle->variable[0 ] >= common; +return common_len >= common && common_len <= len - fixed; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/869 ata: libata-core: Disable LPM on Silicon Motion MD619{H,G}XCLDE3TC
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 6ce0dd9f54ea9773c0aedfaab7b858fc68a848ba ]
According to a user report, the Silicon Motion MD619HXCLDE3TC SSD and the Silicon Motion MD619GXCLDE3TC SSD have problems with LPM.
Stable-dep-of: 462775c62019 ("ata: libata-core: Add NOLPM quirk for PNY CS900 1TB SSD")
--- drivers/ata/libata-core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/ata/libata-core.c +4 -0
@@ -4226,6 +4226,10 @@ static const struct ata_dev_quirks_entry __ata_dev_quirks[] = {/* Apacer models with LPM issues */ { "Apacer AS340*", NULL, ATA_QUIRK_NOLPM }, +/* Silicon Motion models with LPM issues */ + { "MD619HXCLDE3TC", "TCVAID", ATA_QUIRK_NOLPM }, + { "MD619GXCLDE3TC", "TCV35D", ATA_QUIRK_NOLPM }, +/* These specific Samsung models/firmware-revs do not handle LPM well */ { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_QUIRK_NOLPM }, { "SAMSUNG SSD PM830 mSATA *", "CXM13D1Q", ATA_QUIRK_NOLPM },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/869 ata: libata-core: Add NOLPM quirk for PNY CS900 1TB SSD
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit 462775c620197adaabc983ce847e5b9878ff4cb0 ]
The PNY CS900 1TB SSD (Phison PS3111-S11, DRAM-less) drops off the bus after entering Device-Initiated Slumber during idle. With the default med_power_with_dipm policy the link goes down (SStatus 1 SControl 300) and does not recover, forcing the filesystem read-only. Forcing max_performance keeps the link stable across prolonged idle.
Add a NOLPM quirk so link power management is disabled for this drive specifically, leaving it intact for other devices on the host.
--- drivers/ata/libata-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/ata/libata-core.c +3 -0
@@ -4226,6 +4226,9 @@ static const struct ata_dev_quirks_entry __ata_dev_quirks[] = {/* Apacer models with LPM issues */ { "Apacer AS340*", NULL, ATA_QUIRK_NOLPM }, +/* PNY CS900 (Phison PS3111-S11, DRAM-less) drops the link on DIPM */ + { "PNY CS900 1TB SSD", NULL, ATA_QUIRK_NOLPM }, +/* Silicon Motion models with LPM issues */ { "MD619HXCLDE3TC", "TCVAID", ATA_QUIRK_NOLPM }, { "MD619GXCLDE3TC", "TCV35D", ATA_QUIRK_NOLPM },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/869 mmc: vub300: Use devm_mmc_alloc_host() helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Binbin Zhou <[email protected]>
[ Upstream commit dcfdd698dc521c6046e9b80c16281575efb25d23 ]
Use new function devm_mmc_alloc_host() to simplify the code.
Stable-dep-of: a3b5f242997a ("mmc: vub300: fix use-after-free on probe failure")
--- drivers/mmc/host/vub300.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/mmc/host/vub300.c +6 -10
@@ -369,13 +369,11 @@ struct vub300_mmc_host {static void vub300_delete (struct kref *kref) {/* kref callback - softirq */ struct vub300_mmc_host *vub300 =kref_to_vub300_mmc_host (kref); -struct mmc_host *mmc = vub300->mmc;usb_free_urb (vub300->command_out_urb); vub300->command_out_urb =NULL ;usb_free_urb (vub300->command_res_urb); vub300->command_res_urb =NULL ;usb_put_dev (vub300->udev); -mmc_free_host (mmc);/* * and hence also frees vub300 * which is contained at the end of struct mmc
@@ -2122,7 +2120,7 @@ static int vub300_probe(struct usb_interface *interface, goto error1; }/* this also allocates memory for our VUB300 mmc host device */ - mmc =mmc_alloc_host (sizeof (struct vub300_mmc_host ), &udev->dev); + mmc =devm_mmc_alloc_host (&udev->dev,sizeof (*vub300));if (!mmc) { retval = -ENOMEM ;dev_err (&udev->dev,"not enough memory for the mmc_host\n" );
@@ -2279,7 +2277,7 @@ static int vub300_probe(struct usb_interface *interface,dev_err (&vub300->udev->dev,"Could not find two sets of bulk-in/out endpoint pairs\n" ); retval = -EINVAL ; - goto error5; + goto error4; } retval = usb_control_msg(vub300->udev, usb_rcvctrlpipe(vub300->udev, 0),
@@ -2288,14 +2286,14 @@ static int vub300_probe(struct usb_interface *interface,0x0000 ,0x0000 , &vub300->hc_info, sizeof(vub300->hc_info), 1000);if (retval <0 ) - goto error5; + goto error4; retval =usb_control_msg (vub300->udev,usb_sndctrlpipe (vub300->udev,0 ),SET_ROM_WAIT_STATES ,USB_DIR_OUT |USB_TYPE_VENDOR |USB_RECIP_DEVICE , firmware_rom_wait_states,0x0000 ,NULL ,0 ,1000 );if (retval <0 ) - goto error5; + goto error4; dev_info(&vub300->udev->dev, "operating_mode = %s %s %d MHz %s %d byte USB packets\n", (mmc->caps & MMC_CAP_SDIO_IRQ) ? "IRQs" : "POLL",
@@ -2310,7 +2308,7 @@ static int vub300_probe(struct usb_interface *interface,0x0000 ,0x0000 , &vub300->system_port_status, sizeof(vub300->system_port_status), 1000);if (retval <0 ) { - goto error5; + goto error4; }else if (sizeof (vub300->system_port_status) == retval) { vub300->card_present = (0x0001 & vub300->system_port_status.port_flags) ?1 :0 ;
@@ -2318,7 +2316,7 @@ static int vub300_probe(struct usb_interface *interface, (0x0010 & vub300->system_port_status.port_flags) ?1 :0 ; }else { retval = -EINVAL ; - goto error5; + goto error4; }usb_set_intfdata (interface, vub300);INIT_DELAYED_WORK (&vub300->pollwork, vub300_pollwork_thread);
@@ -2348,8 +2346,6 @@ static int vub300_probe(struct usb_interface *interface,return 0 ; error6:del_timer_sync (&vub300->inactivity_timer); -error5: -mmc_free_host (mmc);/* * and hence also frees vub300 * which is contained at the end of struct mmc
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/869 mmc: vub300: fix use-after-free on disconnect
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 8f4d20a710225ec7a565f6a0459862d3b1f32330 ]
The vub300 driver maintains an explicit reference count for the controller and its driver data and the last reference can in theory be dropped after the driver has been unbound.
This specifically means that the controller allocation must not be device managed as that can lead to use-after-free.
Note that the lifetime is currently also incorrectly tied the parent USB device rather than interface, which can lead to memory leaks if the driver is unbound without its device being physically disconnected (e.g. on probe deferral).
Fix both issues by reverting to non-managed allocation of the controller.
Stable-dep-of: a3b5f242997a ("mmc: vub300: fix use-after-free on probe failure")
--- drivers/mmc/host/vub300.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/mmc/host/vub300.c +15 -9
@@ -369,11 +369,14 @@ struct vub300_mmc_host {static void vub300_delete (struct kref *kref) {/* kref callback - softirq */ struct vub300_mmc_host *vub300 =kref_to_vub300_mmc_host (kref); +struct mmc_host *mmc = vub300->mmc; +usb_free_urb (vub300->command_out_urb); vub300->command_out_urb =NULL ;usb_free_urb (vub300->command_res_urb); vub300->command_res_urb =NULL ;usb_put_dev (vub300->udev); +mmc_free_host (mmc);/* * and hence also frees vub300 * which is contained at the end of struct mmc
@@ -2120,7 +2123,7 @@ static int vub300_probe(struct usb_interface *interface, goto error1; }/* this also allocates memory for our VUB300 mmc host device */ - mmc =devm_mmc_alloc_host (&udev->dev,sizeof (*vub300)); + mmc =mmc_alloc_host (sizeof (*vub300), &udev->dev);if (!mmc) { retval = -ENOMEM ;dev_err (&udev->dev,"not enough memory for the mmc_host\n" );
@@ -2277,7 +2280,7 @@ static int vub300_probe(struct usb_interface *interface,dev_err (&vub300->udev->dev,"Could not find two sets of bulk-in/out endpoint pairs\n" ); retval = -EINVAL ; - goto error4; + goto err_free_host; } retval = usb_control_msg(vub300->udev, usb_rcvctrlpipe(vub300->udev, 0),
@@ -2286,14 +2289,14 @@ static int vub300_probe(struct usb_interface *interface,0x0000 ,0x0000 , &vub300->hc_info, sizeof(vub300->hc_info), 1000);if (retval <0 ) - goto error4; + goto err_free_host; retval =usb_control_msg (vub300->udev,usb_sndctrlpipe (vub300->udev,0 ),SET_ROM_WAIT_STATES ,USB_DIR_OUT |USB_TYPE_VENDOR |USB_RECIP_DEVICE , firmware_rom_wait_states,0x0000 ,NULL ,0 ,1000 );if (retval <0 ) - goto error4; + goto err_free_host; dev_info(&vub300->udev->dev, "operating_mode = %s %s %d MHz %s %d byte USB packets\n", (mmc->caps & MMC_CAP_SDIO_IRQ) ? "IRQs" : "POLL",
@@ -2308,7 +2311,7 @@ static int vub300_probe(struct usb_interface *interface,0x0000 ,0x0000 , &vub300->system_port_status, sizeof(vub300->system_port_status), 1000);if (retval <0 ) { - goto error4; + goto err_free_host; }else if (sizeof (vub300->system_port_status) == retval) { vub300->card_present = (0x0001 & vub300->system_port_status.port_flags) ?1 :0 ;
@@ -2316,7 +2319,7 @@ static int vub300_probe(struct usb_interface *interface, (0x0010 & vub300->system_port_status.port_flags) ?1 :0 ; }else { retval = -EINVAL ; - goto error4; + goto err_free_host; }usb_set_intfdata (interface, vub300);INIT_DELAYED_WORK (&vub300->pollwork, vub300_pollwork_thread);
@@ -2341,11 +2344,14 @@ static int vub300_probe(struct usb_interface *interface, interface_to_InterfaceNumber(interface)); retval =mmc_add_host (mmc);if (retval) - goto error6; + goto err_delete_timer;return 0 ; -error6: -del_timer_sync (&vub300->inactivity_timer); + +err_delete_timer: +timer_delete_sync (&vub300->inactivity_timer); +err_free_host: +mmc_free_host (mmc);/* * and hence also frees vub300 * which is contained at the end of struct mmc
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/869 mmc: vub300: rename probe error labels
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 5b8b35d6f4fa758dd5e8ae18526ea1c73f6787e0 ]
Error labels should be named after what they do.
Rename the probe error labels.
Stable-dep-of: a3b5f242997a ("mmc: vub300: fix use-after-free on probe failure")
--- drivers/mmc/host/vub300.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/mmc/host/vub300.c +7 -6
@@ -2115,19 +2115,19 @@ static int vub300_probe(struct usb_interface *interface, command_out_urb =usb_alloc_urb (0 ,GFP_KERNEL );if (!command_out_urb) { retval = -ENOMEM ; - goto error0; + goto err_put_udev; } command_res_urb =usb_alloc_urb (0 ,GFP_KERNEL );if (!command_res_urb) { retval = -ENOMEM ; - goto error1; + goto err_free_out_urb; }/* this also allocates memory for our VUB300 mmc host device */ mmc =mmc_alloc_host (sizeof (*vub300), &udev->dev);if (!mmc) { retval = -ENOMEM ;dev_err (&udev->dev,"not enough memory for the mmc_host\n" ); - goto error4; + goto err_free_res_urb; }/* MMC core transfer sizes tunable parameters */ mmc->caps =0 ;
@@ -2356,12 +2356,13 @@ static int vub300_probe(struct usb_interface *interface,* and hence also frees vub300 * which is contained at the end of struct mmc */ -error4: +err_free_res_urb:usb_free_urb (command_res_urb); -error1: +err_free_out_urb:usb_free_urb (command_out_urb); -error0: +err_put_udev:usb_put_dev (udev); +return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/869 mmc: vub300: fix use-after-free on probe failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit a3b5f242997a3be7404112fd48784881560aea57 ]
The vub300 driver lifetime-manages its controller state using vub300->kref, with vub300_delete() freeing the mmc host when the last reference is dropped. The probe error path after the inactivity timer has been armed still bypasses that lifetime rule, however, and falls through to mmc_free_host() directly if mmc_add_host() fails.
The race window is between arming the inactivity timer and reaching the probe error unwind after mmc_add_host() fails:
probe thread timer/workqueue
------------ ---------------
kref_init(&vub300->kref) ref = 1
kref_get(&vub300->kref) ref = 2, timer ref
add_timer(inactivity_timer) fires after one second
|
| race window
|<---------------------------------------------------->
| mmc_add_host(mmc)
inactivity timer fires vub300_queue_dead_work()
kref_get() ref = 3
queue_work(deadwork)
mmc_add_host() fails
timer_delete_sync()
mmc_free_host(mmc)
frees vub300
deadwork runs
use-after-free
The inactivity timeout is one second, so this would require mmc_add_host() to both fail and take more than one second to do so. This is unlikely to happen in practice, but the error path is still wrong.
timer_delete_sync() only waits for the timer callback itself. It does not flush deadwork that the callback may already have queued. As a result, queued deadwork can still hold a kref while the probe error path directly frees the backing mmc host, including the vub300 storage.
Fix this by using the same lifetime mechanism as disconnect. Clear vub300->interface so that the timer callback and any queued deadwork return early and drop their references, then drop the initial probe reference and return without falling through to err_free_host.
--- drivers/mmc/host/vub300.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/mmc/host/vub300.c +7 -3
@@ -2344,12 +2344,16 @@ static int vub300_probe(struct usb_interface *interface, interface_to_InterfaceNumber(interface)); retval =mmc_add_host (mmc);if (retval) - goto err_delete_timer; + goto err_stop_io;return 0 ; -err_delete_timer: -timer_delete_sync (&vub300->inactivity_timer); +err_stop_io: + vub300->interface =NULL ; +kref_put (&vub300->kref, vub300_delete); + +return retval; + err_free_host:mmc_free_host (mmc);/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/869 dm-verity: fix buffer overflow in FEC calculation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit 31d6e6c0ba8d5a7bd59660035a089307100c5e8e ]
There's a buffer overflow in dm-verity-fec:
if (neras && *neras <= v->fec->roots)
fio->erasures[(*neras)++] = i;
This allows *neras to reach roots + 1 (the post-increment pushes it past roots). This value is then passed as no_eras to decode_rs8(). Inside the RS decoder (lib/reed_solomon/decode_rs.c:113-121), the erasure locator polynomial loop writes lambda[j] where j can reach nroots + 1 — one element past the end of lambda[] (which is sized nroots + 1, valid indices 0..nroots). The out-of-bounds write lands on syn[0], corrupting the syndrome buffer.
--- drivers/md/dm-verity-fec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-verity-fec.c +2 -2
@@ -263,7 +263,7 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io, (unsigned long long)block, PTR_ERR(bbuf));/* assume the block is corrupted */ -if (neras && *neras <= v->fec->roots) +if (neras && *neras < v->fec->roots) fio->erasures[(*neras)++] = i;continue ;
@@ -281,7 +281,7 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io,* skip if we have already found the theoretical * maximum number (i.e. fec->roots) of erasures */ -if (neras && *neras <= v->fec->roots && +if (neras && *neras < v->fec->roots &&fec_is_erasure (v, io, want_digest, bbuf)) fio->erasures[(*neras)++] = i; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/869 ocfs2: correct l_next_free_rec in online check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit fdbb6cd96ed51da002bd9a5a142586a74a436784 ]
Correct the value of l_next_free_rec to l_count during the online check, as done in the check_el() function in ocfs2_tools.
Stable-dep-of: 452a8467be81 ("ocfs2: fix UBSAN array-index-out-of-bounds in ocfs2_sum_rightmost_rec")
--- fs/ocfs2/inode.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/ocfs2/inode.c +24 -0
@@ -233,6 +233,20 @@ struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,return inode; } +static int ocfs2_dinode_has_extents (struct ocfs2_dinode *di) +{ +/* inodes flagged with other stuff in id2 */ +if (di->i_flags & (OCFS2_SUPER_BLOCK_FL |OCFS2_LOCAL_ALLOC_FL | +OCFS2_CHAIN_FL |OCFS2_DEALLOC_FL )) +return 0 ; +/* i_flags doesn't indicate when id2 is a fast symlink */ +if (S_ISLNK (di->i_mode) && di->i_size && di->i_clusters ==0 ) +return 0 ; +if (di->i_dyn_features &OCFS2_INLINE_DATA_FL ) +return 0 ; + +return 1 ; +}/* * here's how inodes get read from disk:
@@ -1728,6 +1742,16 @@ static int ocfs2_filecheck_repair_inode_block(struct super_block *sb, le32_to_cpu(di->i_fs_generation)); } +if (ocfs2_dinode_has_extents (di) && +le16_to_cpu (di->id2.i_list.l_next_free_rec) >le16_to_cpu (di->id2.i_list.l_count)) { + di->id2.i_list.l_next_free_rec = di->id2.i_list.l_count; + changed =1 ; +mlog (ML_ERROR , +"Filecheck: reset dinode #%llu: l_next_free_rec to %u\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->id2.i_list.l_next_free_rec)); + } +if (changed ||ocfs2_validate_meta_ecc (sb, bh->b_data, &di->i_check)) {ocfs2_compute_meta_ecc (sb, bh->b_data, &di->i_check);mark_buffer_dirty (bh);
Signature · 1 line
2.53.0