6.18.64-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 92/686 mtd: rawnand: ndfc: use devm_platform_ioremap_resource()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 0d66f9895f286d2fab396a71e6efeb95c4a7e5a6 ]
Replace the open-coded of_iomap()/iounmap() with the managed devm_platform_ioremap_resource() helper. This fixes a mapping leak on driver remove (the old code never called iounmap()) and simplifies the error path by dropping the manual cleanup in ndfc_probe().
There is no overlapping memory-region concern introduced by this
change: each supported board DT describes a single ndfc node with a unique 0x2000 register region, and the EBC parent uses dcr-reg rather than a MEM reg resource, so the newly added request_mem_region() cannot conflict with an existing reservation. Distinct chip selects map to distinct 64-bit physical addresses, so CS instances do not overlap.
--- drivers/mtd/nand/raw/ndfc.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/mtd/nand/raw/ndfc.c +8 -13
@@ -185,10 +185,15 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,static int ndfc_probe (struct platform_device *ofdev) {struct ndfc_controller *ndfc; +void __iomem *ndfcbase;const __be32 *reg;u32 ccr;u32 cs; -int err, len =0 ; +int len =0 ; + + ndfcbase =devm_platform_ioremap_resource (ofdev,0 ); +if (IS_ERR (ndfcbase)) +return PTR_ERR (ndfcbase);/* Read the reg property to get the chip select */ reg =of_get_property (ofdev->dev.of_node,"reg" , &len);
@@ -210,11 +215,7 @@ static int ndfc_probe(struct platform_device *ofdev) ndfc->ofdev = ofdev;dev_set_drvdata (&ofdev->dev, ndfc); - ndfc->ndfcbase =of_iomap (ofdev->dev.of_node,0 ); -if (!ndfc->ndfcbase) { -dev_err (&ofdev->dev,"failed to get memory\n" ); -return -EIO ; - } + ndfc->ndfcbase = ndfcbase; ccr =NDFC_CCR_BS (ndfc->chip_select);
@@ -232,13 +233,7 @@ static int ndfc_probe(struct platform_device *ofdev)iowrite32be (be32_to_cpup (reg), ndfc->ndfcbase + offset); } - err =ndfc_chip_init (ndfc, ofdev->dev.of_node); -if (err) { -iounmap (ndfc->ndfcbase); -return err; - } - -return 0 ; +return ndfc_chip_init (ndfc, ofdev->dev.of_node); }static void ndfc_remove (struct platform_device *ofdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 93/686 net: bgmac: enable interrupts only after NAPI is ready
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit ac1f6e58cb77bb66b8811f7d98703e0f076a8f65 ]
bgmac_open() calls bgmac_chip_init(), which unmasks the interrupts and enables the MAC receiver, before request_irq() and napi_enable(). bgmac_enet_resume() also enables NAPI only after bgmac_chip_init().
When frames arrive in that window, the first RX interrupt masks all interrupts in bgmac_interrupt() and calls napi_schedule() on a NAPI instance that is still disabled, so nothing is scheduled. Nothing unmasks the interrupts again, the RX ring fills up and the interface stays deaf until it is brought down and up without traffic.
On an Asus RT-N16 (BCM4716) a single "ip link set eth0 down/up" while a host sends UDP to the router left INT_MASK at 0, INT_STATUS with RX pending and the RX DMA idle on a full ring, with the RX packet and interrupt counters no longer moving. With this change, 10 of 10 such cycles recovered on their own.
Request the IRQ and enable NAPI before the chip is initialized.
--- drivers/net/ethernet/broadcom/bgmac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +5 -5
@@ -1183,9 +1183,6 @@ static int bgmac_open(struct net_device *net_dev)if (err)return err; -/* Specs say about reclaiming rings here, but we do that in DMA init */ -bgmac_chip_init (bgmac); - err =request_irq (bgmac->irq, bgmac_interrupt,IRQF_SHARED , net_dev->name, net_dev);if (err <0 ) {
@@ -1195,6 +1192,9 @@ static int bgmac_open(struct net_device *net_dev) }napi_enable (&bgmac->napi); +/* Specs say about reclaiming rings here, but we do that in DMA init */ +bgmac_chip_init (bgmac); +phy_start (net_dev->phydev);netif_start_queue (net_dev);
@@ -1608,10 +1608,10 @@ int bgmac_enet_resume(struct bgmac *bgmac)if (rc)return rc; -bgmac_chip_init (bgmac); -napi_enable (&bgmac->napi); +bgmac_chip_init (bgmac); +netif_tx_lock (bgmac->net_dev);netif_device_attach (bgmac->net_dev);netif_tx_unlock (bgmac->net_dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 94/686 ksmbd: fix tree connection use-after-free in smb2_tree_connect()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft Security FORGE Labs) <[email protected]>
[ Upstream commit b5ec6c462aab1062cf5d1e667ba7c6442f737055 ]
ksmbd_tree_conn_connect() publishes a new tree connection in sess->tree_conns with a single reference and returns its pointer to smb2_tree_connect(). The handler continues to initialize the object and build the response after publication. A concurrent session logoff can erase the connection and drop that reference, freeing the object while the handler still uses it.
BUG: KASAN: slab-use-after-free in smb2_tree_connect+0xe3d/0xf90 smb2_tree_connect (fs/smb/server/smb2pdu.c:2872) handle_ksmbd_work process_one_work worker_thread kthread
After xa_store() succeeds, take a second reference before releasing tree_conns_lock. The original reference belongs to the xarray entry and the second belongs to the creating smb2_tree_connect() handler.
Keep the references balanced in every path:
- On normal exit or an error after publication, smb2_tree_connect() drops its creator reference. Error cleanup also calls ksmbd_tree_conn_disconnect(), which drops the xarray reference only if it removes the exact entry.
- SMB2 TREE_DISCONNECT uses the same helper to remove the entry and drop its xarray reference. The request's existing lookup reference remains owned by the request and is released by the existing cleanup.
- Session LOGOFF removes each entry and drops its xarray reference. If it wins the race, later cleanup sees that the entry is gone and does not drop that reference again.
To enforce this ownership, claim the disconnected state and erase the exact entry atomically under tree_conns_lock. This guarantees one drop for the xarray reference and one drop by each in-flight user, regardless of which teardown path wins. If logoff removes the entry before initialization completes, fail the connect instead of marking the detached object TREE_CONNECTED.
--- fs/smb/server/mgmt/tree_connect.c | 8 ++++++++ fs/smb/server/smb2pdu.c | 32 +++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-)
fs/smb/server/mgmt/tree_connect.c +8 -0
@@ -82,6 +82,8 @@ ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name)down_write (&sess->tree_conns_lock); ret =xa_err (xa_store (&sess->tree_conns, tree_conn->id, tree_conn,KSMBD_DEFAULT_GFP )); +if (!ret) +atomic_inc (&tree_conn->refcount);up_write (&sess->tree_conns_lock);if (ret) { status.ret = -ENOMEM ;
@@ -122,6 +124,12 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess, struct ksmbd_tree_connect *tree_conn) {down_write (&sess->tree_conns_lock); +if (tree_conn->t_state ==TREE_DISCONNECTED || +xa_load (&sess->tree_conns, tree_conn->id) != tree_conn) { +up_write (&sess->tree_conns_lock); +return -ENOENT ; + } + tree_conn->t_state =TREE_DISCONNECTED ;xa_erase (&sess->tree_conns, tree_conn->id);up_write (&sess->tree_conns_lock);
fs/smb/server/smb2pdu.c +15 -17
@@ -2023,6 +2023,7 @@ int smb2_tree_connect(struct ksmbd_work *work)struct ksmbd_session *sess = work->sess;char *treename =NULL , *name =NULL ;struct ksmbd_tree_conn_status status; +struct ksmbd_tree_connect *tree_conn =NULL ;struct ksmbd_share_config *share =NULL ;int rc = -EINVAL ;
@@ -2049,9 +2050,10 @@ int smb2_tree_connect(struct ksmbd_work *work) name, treename); status =ksmbd_tree_conn_connect (work, name); -if (status.ret ==KSMBD_TREE_CONN_STATUS_OK ) +if (status.ret ==KSMBD_TREE_CONN_STATUS_OK ) { + tree_conn = status.tree_conn; rsp->hdr.Id.SyncId.TreeId =cpu_to_le32 (status.tree_conn->id); -else + }else goto out_err1; share = status.tree_conn->share_conf;
@@ -2083,8 +2085,15 @@ int smb2_tree_connect(struct ksmbd_work *work) status.tree_conn->posix_extensions = true;down_write (&sess->tree_conns_lock); - status.tree_conn->t_state =TREE_CONNECTED ; +if (status.tree_conn->t_state ==TREE_DISCONNECTED ) { + status.ret =KSMBD_TREE_CONN_STATUS_ERROR ; + share =NULL ; + }else { + status.tree_conn->t_state =TREE_CONNECTED ; + }up_write (&sess->tree_conns_lock); +if (status.ret !=KSMBD_TREE_CONN_STATUS_OK ) + goto out_err1; rsp->StructureSize =cpu_to_le16 (16 ); out_err1:/*
@@ -2099,9 +2108,6 @@ int smb2_tree_connect(struct ksmbd_work *work) rc =ksmbd_iov_pin_rsp (work, rsp,sizeof (struct smb2_tree_connect_rsp ));if (rc) {if (status.ret ==KSMBD_TREE_CONN_STATUS_OK ) { -down_write (&sess->tree_conns_lock); - status.tree_conn->t_state =TREE_DISCONNECTED ; -up_write (&sess->tree_conns_lock);ksmbd_tree_conn_disconnect (sess, status.tree_conn); status.tree_conn =NULL ; }
@@ -2142,6 +2148,9 @@ int smb2_tree_connect(struct ksmbd_work *work)if (status.ret !=KSMBD_TREE_CONN_STATUS_OK )smb2_set_err_rsp (work); +if (tree_conn) +ksmbd_tree_connect_put (tree_conn); +return rc; }
@@ -2245,17 +2254,6 @@ int smb2_tree_disconnect(struct ksmbd_work *work)ksmbd_close_tree_conn_fds (work); -down_write (&sess->tree_conns_lock); -if (tcon->t_state ==TREE_DISCONNECTED ) { -up_write (&sess->tree_conns_lock); - rsp->hdr.Status =STATUS_NETWORK_NAME_DELETED ; - err = -ENOENT ; - goto err_out; - } - - tcon->t_state =TREE_DISCONNECTED ; -up_write (&sess->tree_conns_lock); - err =ksmbd_tree_conn_disconnect (sess, tcon);if (err) { rsp->hdr.Status =STATUS_NETWORK_NAME_DELETED ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 95/686 nfsd: shorten extack string returned with dodgy listener
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 8d7859d165dbdf6e8d77b76500fc990f26c8310d ]
The kernel test robot reports:
Quoted 1 line
Quoted 1 line
fs/nfsd/nfsctl.c:2253:4: warning: 'snprintf' will always be truncated; specified size is 80, but format string expands to at least 94 [-Wformat-truncation]
Shorten the extack string in this case so that it will fit in 80 chars.
--- fs/nfsd/nfsctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfsctl.c +1 -1
@@ -2188,7 +2188,7 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info) bad_xprt); else if (skipped_rpcb) NL_SET_ERR_MSG_FMT(info->extack, -"cannot create %s listener; rpcbind did not answer earlier, so some listeners are not registered" , +"cannot create %s listener; rpcbind did not answer earlier" , bad_xprt); else NL_SET_ERR_MSG_FMT(info->extack,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 96/686 s390/vmcp: Initialize full session info to zero
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
[ Upstream commit f63eb4ee4a30fc5d8de07a229d92310e3c8d560c ]
The cma_alloc bit as well as the response can contain old data. cma_release will not free the kmalloced memory in that case and the response code might leak kernel stack data to CAP_SYS_ADMIN users.
--- drivers/s390/char/vmcp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/s390/char/vmcp.c +1 -3
@@ -105,13 +105,11 @@ static int vmcp_open(struct inode *inode, struct file *file)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; - session =kmalloc (sizeof (*session),GFP_KERNEL ); + session =kzalloc (sizeof (*session),GFP_KERNEL );if (!session)return -ENOMEM ; session->bufsize =PAGE_SIZE ; - session->response =NULL ; - session->resp_size =0 ;mutex_init (&session->mutex); file->private_data = session;return nonseekable_open (inode, file);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 97/686 PCI: rcar-gen4: Limit Max_Read_Request_Size to 256 Bytes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Vasut <[email protected]>
[ Upstream commit f0a5c6bd797c2b9900034983a1118d27eb2f2f16 ]
R-Car Gen4 PCIe controller has a hardware limitation of 256 Bytes Max_Payload_Size (MPS). PCIe specification indicates that the MPS must not exceed minimum MPS of any element along the packet path. The PCI core already enforces this, but add a check to warn if MPS is ever set larger than 256.
R-Car Gen4 Reference Manual, chapter 104.4.8 Usage notes for MRRS (Max Read Request Size) states:
Please set "Max Read Request Size" to 128 bytes or 256 bytes. If "Max Read Request Size" is set to anything other than the above, the transferred data will not match the expected value.
This limitation also seems to apply to devices doing DMA reads, i.e., issuing MRd TLPs. This limitation can be triggered by using non-HMB NVMe SSD with Max_Read_Request_Size 512 Bytes, for example Crucial P5 Plus. Any write to the SSD (MRd TLP issued by the SSD controller) longer than 256 Bytes wraps around at the 256 Byte boundary, and the same data are written to the SSD starting at offset 0 and at 256 Bytes.
Limit Max_Read_Request_Size to at most 256 Bytes for each device connected to this PCIe controller to avoid this behavior.
A non-HMB (Host Memory Buffer) NVMe SSD can be identified using the following command. Affected SSD reports 'hmpre' field as 0:
$ nvme id-ctrl /dev/nvme0 | grep hmpre hmpre : 0
The symptom is a read from the SSD which wraps around at 256 Byte boundary. The test for this symptom can be implemented by writing 512 Byte of random data into the SSD and reading the data back. If the read back data repeat after 256 Bytes, the device is affected.
$ dd if=/dev/urandom of=/tmp/data.bin bs=256 count=2 ; \
dd if=/tmp/data.bin of=/dev/nvme0n1 bs=256 count=2 ; \
dd if=/dev/nvme0n1 bs=256 count=2 of=/tmp/readback.binExpected data:
$ hexdump -vC /tmp/data.bin 00000000 97 81 b7 3b 0e 38 2b 4d a7 d3 e0 47 ff c2 4b ca 00000010 c1 85 98 f0 4a ac 03 a0 3b ab f3 19 44 dd 06 8b ... 00000100 7a ce 3c b2 e1 d5 d9 11 88 63 10 59 76 3c dc 32 <-- random 00000110 72 32 2a 7d a3 e1 aa 13 7c da 58 a1 7b 21 11 50 <-- data
Faulty readback, collected without this change in place:
$ hexdump -vC /tmp/readback.bin
00000000 97 81 b7 3b 0e 38 2b 4d a7 d3 e0 47 ff c2 4b ca <---.
00000010 c1 85 98 f0 4a ac 03 a0 3b ab f3 19 44 dd 06 8b <-. |
... | |
00000100 97 81 b7 3b 0e 38 2b 4d a7 d3 e0 47 ff c2 4b ca <-:-+- repeated
00000110 c1 85 98 f0 4a ac 03 a0 3b ab f3 19 44 dd 06 8b <-+--- data
^^^
|
'--- Repeat starts at offset 0x100 = 256 Bytes--- drivers/pci/controller/dwc/pcie-rcar-gen4.c | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/pci/controller/dwc/pcie-rcar-gen4.c +54 -0
@@ -305,6 +305,57 @@ static struct rcar_gen4_pcie *rcar_gen4_pcie_alloc(struct platform_device *pdev)return rcar; } +static int rcar_gen4_pcie_enable_device (struct pci_host_bridge *bridge, +struct pci_dev *dev) +{ +/* +* R-Car Gen4 PCIe controller has a hardware limitation of 256 Bytes +* Max_Payload_Size (MPS). PCIe specification indicates that the MPS +* must not exceed minimum MPS of any element along the packet path. +* The controller reports Max_Payload_Size_Supported (MPSS) 256 Bytes +* for header type 0 and 128 Bytes for header type 1. The PCIe core +* will not allow MPS to be set higher than MPSS; warn here in case +* something went very wrong in the core. +* +* For details, refer to chapter "104.1.1 Features" in either of: +* R-Car S4 R19UH0161EJ0140 Rev.1.40 Jul. 31, 2026 or +* R-Car V4H R19UH0186EJ0140 Rev.1.40 Aug. 7, 2026 or +* R-Car V4M R19UH0217EJ0110 Rev.1.10 Jun. 30, 2026. +*/ +WARN_ON (pcie_get_mps (dev) >256 ); + +/* +* R-Car Gen4 Reference Manual, chapter 104.4.8 Usage notes for +* MRRS (Max Read Request Size) states: +* +* Please set "Max Read Request Size" to 128 bytes or 256 bytes. +* If "Max Read Request Size" is set to anything other than the +* above, the transferred data will not match the expected value. +* +* This limitation also seems to apply to devices issuing MRd TLPs. +* This limitation can be triggered by using non-HMB NVMe SSD with +* Max_Read_Request_Size 512 Bytes, for example Crucial P5 Plus. +* Any write into the SSD (MRd TLP issued by the SSD) longer than +* 256 Bytes wraps around at 256 Byte boundary, and the same data +* are written into the SSD starting at offset 0 and at 256 Bytes. +* +* Limit Max_Read_Request_Size to at most 256 Bytes for each +* device connected to this PCIe controller to avoid this behavior. +* +* For details, refer to aforementioned chapter in either of: +* R-Car S4 R19UH0161EJ0140 Rev.1.40 Jul. 31, 2026 or +* R-Car V4H R19UH0186EJ0140 Rev.1.40 Aug. 7, 2026 or +* R-Car V4M R19UH0217EJ0110 Rev.1.10 Jun. 30, 2026. +*/ + bridge->no_inc_mrrs =1 ; +if (pcie_get_readrq (dev) >256 ) { +pci_info (dev,"Limiting MRRS to 256 bytes\n" ); +pcie_set_readrq (dev,256 ); + } + +return 0 ; +} +/* Host mode */ static int rcar_gen4_pcie_host_init (struct dw_pcie_rp *pp) {
@@ -313,6 +364,9 @@ static int rcar_gen4_pcie_host_init(struct dw_pcie_rp *pp)int ret;u32 val; +if (pp->bridge) + pp->bridge->enable_device = rcar_gen4_pcie_enable_device; +gpiod_set_value_cansleep (dw->pe_rst,1 ); ret =rcar_gen4_pcie_common_init (rcar);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 98/686 wifi: mt76: mt792x: fix negative errno truncation in offload capability
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yi Cong <[email protected]>
[ Upstream commit d0115096429ca090a592770c7645f9553a839954 ]
Returning a negative errno as u8 turned -ENOENT into 0xfe, wrongly enabling CNM and NAN caps. Return int and default to no caps on error.
--- drivers/net/wireless/mediatek/mt76/mt792x_core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt792x_core.c +9 -2
@@ -704,7 +704,7 @@ int mt792x_init_wiphy(struct ieee80211_hw *hw) }EXPORT_SYMBOL_GPL (mt792x_init_wiphy); -static u8 +static int mt792x_get_offload_capability (struct device *dev,const char *fw_wm) {const struct mt76_connac2_fw_trailer *hdr;
@@ -766,13 +766,20 @@ mt792x_get_mac80211_ops(struct device *dev, void *drv_data, u8 *fw_features) { struct ieee80211_ops *ops; +int ret; ops =devm_kmemdup (dev, mac80211_ops,sizeof (struct ieee80211_ops ),GFP_KERNEL );if (!ops)return NULL ; - *fw_features =mt792x_get_offload_capability (dev, drv_data); + ret =mt792x_get_offload_capability (dev, drv_data); +if (ret <0 ) { +dev_warn (dev,"failed to read firmware offload caps: %d\n" , ret); + *fw_features =0 ; + }else { + *fw_features = ret; + }if (!(*fw_features & MT792x_FW_CAP_CNM)) { ops->remain_on_channel =NULL ; ops->cancel_remain_on_channel =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 99/686 hwmon: (nct6775) Add ASUS ROG STRIX X870E-H GAMING WIFI7
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maximilian Luz <[email protected]>
[ Upstream commit 03897f9baf3eeea509b2c749bab435072f5e637a ]
The ASUS ROG STRIX X870E-H GAMING WIFI7 has a NCT6799D compatible chip, which is also accessed via ACPI.
--- drivers/hwmon/nct6775-platform.c | 1 + 1 file changed, 1 insertion(+)
drivers/hwmon/nct6775-platform.c +1 -0
@@ -1404,6 +1404,7 @@ static const char * const asus_msi_boards[] = {"ROG STRIX X670E-E GAMING WIFI" ,"ROG STRIX X670E-F GAMING WIFI" ,"ROG STRIX X670E-I GAMING WIFI" , +"ROG STRIX X870E-H GAMING WIFI7" ,"ROG STRIX Z590-A GAMING WIFI" ,"ROG STRIX Z590-A GAMING WIFI II" , "ROG STRIX Z590-E GAMING WIFI",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 100/686 hwmon: (nct6775) Add ASUS X870/W480 to WMI monitoring list
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis Pauk <[email protected]>
[ Upstream commit 21518579cbdeb4e86a6fffbc3d52f52bd74ab87e ]
Boards such as
* G15CE,
* PRIME X870-P WIFI,
* PRIME X870-P,
* Pro WS W480-ACE,
* ProArt X870E-CREATOR WIFI,
* ROG CROSSHAIR X870E APEX,
* ROG CROSSHAIR X870E DARK HERO,
* ROG CROSSHAIR X870E EXTREME,
* ROG CROSSHAIR X870E GLACIAL,
* ROG CROSSHAIR X870E HERO BTF,
* ROG CROSSHAIR X870E HERO,
* ROG STRIX X870-A GAMING WIFI,
* ROG STRIX X870-F GAMING WIFI,
* ROG STRIX X870-I GAMING WIFI,
* ROG STRIX X870E-E GAMING WIFI,
* ROG STRIX X870E-E GAMING WIFI7 R2,
* TUF GAMING X870-PLUS WIFI,
* TUF GAMING X870-PRO WIFI7 W NEO,
* TUF GAMING X870E-PLUS WIFI7,
* W480/SYS,
* X870 AYW GAMING WIFI W,
* X870 MAX GAMING WIFI7 W,
* X870 MAX GAMING WIFI7
have got a nct6775 chip, but by default there's no use of it because of resource conflict with WMI method.
Add the boards to the WMI monitoring list.
--- drivers/hwmon/nct6775-platform.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/hwmon/nct6775-platform.c +23 -0
@@ -1159,6 +1159,7 @@ static const char * const asus_wmi_boards[] = {"Pro A520M-C" ,"Pro A520M-C II" ,"Pro B550M-C" , +"Pro WS W480-ACE" ,"Pro WS X570-ACE" ,"ProArt B550-CREATOR" , "ProArt X570-CREATOR WIFI",
@@ -1258,6 +1259,7 @@ static const char * const asus_wmi_boards[] = {"TUF Z390-PRO GAMING" ,"TUF Z390M-PRO GAMING" ,"TUF Z390M-PRO GAMING (WI-FI)" , +"W480/SYS" ,"WS Z390 PRO" , "Z490-GUNDAM (WI-FI)", };
@@ -1270,6 +1272,7 @@ static const char * const asus_msi_boards[] = {"EX-B760M-V5 D4" ,"EX-H510M-V3" ,"EX-H610M-V3 D4" , +"G15CE" ,"G15CF" ,"PRIME A620M-A" , "PRIME B560-PLUS",
@@ -1320,6 +1323,8 @@ static const char * const asus_msi_boards[] = {"PRIME X670-P" ,"PRIME X670-P WIFI" ,"PRIME X670E-PRO WIFI" , +"PRIME X870-P" , +"PRIME X870-P WIFI" ,"PRIME Z590-A" ,"PRIME Z590-P" , "PRIME Z590-P WIFI",
@@ -1362,11 +1367,18 @@ static const char * const asus_msi_boards[] = {"ProArt B660-CREATOR D4" ,"ProArt B760-CREATOR D4" ,"ProArt X670E-CREATOR WIFI" , +"ProArt X870E-CREATOR WIFI" ,"ProArt Z690-CREATOR WIFI" ,"ProArt Z790-CREATOR WIFI" ,"ROG CROSSHAIR X670E EXTREME" ,"ROG CROSSHAIR X670E GENE" ,"ROG CROSSHAIR X670E HERO" , +"ROG CROSSHAIR X870E APEX" , +"ROG CROSSHAIR X870E DARK HERO" , +"ROG CROSSHAIR X870E EXTREME" , +"ROG CROSSHAIR X870E GLACIAL" , +"ROG CROSSHAIR X870E HERO" , +"ROG CROSSHAIR X870E HERO BTF" ,"ROG MAXIMUS XIII APEX" ,"ROG MAXIMUS XIII EXTREME" , "ROG MAXIMUS XIII EXTREME GLACIAL",
@@ -1404,6 +1416,11 @@ static const char * const asus_msi_boards[] = {"ROG STRIX X670E-E GAMING WIFI" ,"ROG STRIX X670E-F GAMING WIFI" ,"ROG STRIX X670E-I GAMING WIFI" , +"ROG STRIX X870-A GAMING WIFI" , +"ROG STRIX X870-F GAMING WIFI" , +"ROG STRIX X870-I GAMING WIFI" , +"ROG STRIX X870E-E GAMING WIFI" , +"ROG STRIX X870E-E GAMING WIFI7 R2" ,"ROG STRIX X870E-H GAMING WIFI7" ,"ROG STRIX Z590-A GAMING WIFI" , "ROG STRIX Z590-A GAMING WIFI II",
@@ -1451,6 +1468,9 @@ static const char * const asus_msi_boards[] = {"TUF GAMING H770-PRO WIFI" ,"TUF GAMING X670E-PLUS" ,"TUF GAMING X670E-PLUS WIFI" , +"TUF GAMING X870-PLUS WIFI" , +"TUF GAMING X870-PRO WIFI7 W NEO" , +"TUF GAMING X870E-PLUS WIFI7" ,"TUF GAMING Z590-PLUS" ,"TUF GAMING Z590-PLUS WIFI" , "TUF GAMING Z690-PLUS",
@@ -1460,6 +1480,9 @@ static const char * const asus_msi_boards[] = {"TUF GAMING Z790-PLUS D4" ,"TUF GAMING Z790-PLUS WIFI" ,"TUF GAMING Z790-PLUS WIFI D4" , +"X870 AYW GAMING WIFI W" , +"X870 MAX GAMING WIFI7" , +"X870 MAX GAMING WIFI7 W" , "Z590 WIFI GUNDAM EDITION", };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 101/686 wifi: mac80211: queue frames while off-channel
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislaw Gruszka <[email protected]>
[ Upstream commit 13e51269b6656768dc595ed6025e4974f2026543 ]
Drivers without FAST_XMIT and hardware scan support currently drop TX frames during software scanning while being off-channel. This happens in ieee80211_tx_h_check_assoc() before frames reach internal TX queue.
Move the off-channel check to invoke_tx_handlers_late(), after ieee80211_queue_skb(). Frames can then remain queued and be transmitted when the interface returns on-channel. This how TX works currently when code goes via ieee80211_xmit_fast() path.
Below is rt2x00 driver ping output example while scanning, before and after the fix. After the fix, packets are no longer lost. Some have increased latency, what is expected behavior.
BEFORE:
64 bytes from 192.168.0.1: icmp_seq=29 ttl=64 time=3.61 ms 64 bytes from 192.168.0.1: icmp_seq=31 ttl=64 time=3.33 ms # Missed 30 64 bytes from 192.168.0.1: icmp_seq=32 ttl=64 time=4.03 ms 64 bytes from 192.168.0.1: icmp_seq=34 ttl=64 time=3.10 ms # Missed 33 64 bytes from 192.168.0.1: icmp_seq=36 ttl=64 time=3.04 ms # Missed 35 64 bytes from 192.168.0.1: icmp_seq=38 ttl=64 time=3.05 ms # Missed 37 64 bytes from 192.168.0.1: icmp_seq=40 ttl=64 time=4.14 ms # Missed 39 64 bytes from 192.168.0.1: icmp_seq=41 ttl=64 time=4.50 ms
AFTER:
64 bytes from 192.168.0.1: icmp_seq=29 ttl=64 time=3.40 ms 64 bytes from 192.168.0.1: icmp_seq=30 ttl=64 time=6.10 ms 64 bytes from 192.168.0.1: icmp_seq=31 ttl=64 time=4.69 ms 64 bytes from 192.168.0.1: icmp_seq=32 ttl=64 time=4.49 ms 64 bytes from 192.168.0.1: icmp_seq=33 ttl=64 time=148 ms 64 bytes from 192.168.0.1: icmp_seq=34 ttl=64 time=6.83 ms 64 bytes from 192.168.0.1: icmp_seq=35 ttl=64 time=8.66 ms 64 bytes from 192.168.0.1: icmp_seq=36 ttl=64 time=13.0 ms 64 bytes from 192.168.0.1: icmp_seq=37 ttl=64 time=4.78 ms 64 bytes from 192.168.0.1: icmp_seq=38 ttl=64 time=3.85 ms
--- net/mac80211/tx.c | 55 ++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 27 deletions(-)
net/mac80211/tx.c +28 -27
@@ -269,7 +269,6 @@ ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx) static ieee80211_tx_result debug_noinlineieee80211_tx_h_check_assoc (struct ieee80211_tx_data *tx) { -struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb);bool assoc = false;
@@ -277,23 +276,6 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)if (unlikely (info->flags &IEEE80211_TX_CTL_INJECTED ))return TX_CONTINUE ; -if (unlikely (test_bit (SCAN_SW_SCANNING , &tx->local->scanning)) && -test_bit (SDATA_STATE_OFFCHANNEL , &tx->sdata->state) && - !ieee80211_is_probe_req (hdr->frame_control) && - !ieee80211_is_any_nullfunc (hdr->frame_control)) -/* -* When software scanning only nullfunc frames (to notify -* the sleep state to the AP) and probe requests (for the -* active scan) are allowed, all other frames should not be -* sent and we should not get here, but if we do -* nonetheless, drop them to avoid sending them -* off-channel. See the link below and -* ieee80211_start_scan() for more. -* -* http://article.gmane.org/gmane.linux.kernel.wireless.general/30089 -*/ -return TX_DROP ; -if (tx->sdata->vif.type ==NL80211_IFTYPE_OCB )return TX_CONTINUE ;
@@ -806,6 +788,33 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)return TX_CONTINUE ; } +static ieee80211_tx_result debug_noinline +ieee80211_tx_h_check_offchannel (struct ieee80211_tx_data *tx) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb); + +if (unlikely (info->flags &IEEE80211_TX_CTL_INJECTED )) +return TX_CONTINUE ; + +if (unlikely (test_bit (SCAN_SW_SCANNING , &tx->local->scanning)) && +test_bit (SDATA_STATE_OFFCHANNEL , &tx->sdata->state) && + !ieee80211_is_probe_req (hdr->frame_control) && + !ieee80211_is_any_nullfunc (hdr->frame_control)) { +/* +* When software scanning only nullfunc frames (to notify +* the sleep state to the AP) and probe requests (for the +* active scan) are allowed, all other frames should not be +* sent and we should not get here, but if we do +* nonetheless, drop them to avoid sending them +* off-channel. See __ieee80211_start_scan() for more. +*/ +return TX_DROP ; + } + +return TX_CONTINUE ; +} +static __le16 ieee80211_tx_next_seq (struct sta_info *sta,int tid) {u16 *seq = &sta->tid_seq[tid];
@@ -1852,6 +1861,7 @@ static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx) goto txh_done; } +CALL_TXH (ieee80211_tx_h_check_offchannel);CALL_TXH (ieee80211_tx_h_michael_mic_add);CALL_TXH (ieee80211_tx_h_sequence);CALL_TXH (ieee80211_tx_h_fragment);
@@ -4691,10 +4701,6 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, queue =ieee80211_select_queue (sdata, sta, skb);skb_set_queue_mapping (skb, queue); -if (unlikely (test_bit (SCAN_SW_SCANNING , &local->scanning)) && -test_bit (SDATA_STATE_OFFCHANNEL , &sdata->state)) - goto out_free; - skb =skb_share_check (skb,GFP_ATOMIC );if (unlikely (!skb))return ;
@@ -4771,11 +4777,6 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,ieee80211_tpt_led_trig_tx (local, len);ieee80211_tx_8023 (sdata, skb, sta, false); - -return ; - -out_free: -kfree_skb (skb); } static bool ieee80211_check_mcast_offload(struct ieee80211_sub_if_data *sdata,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 102/686 media: uvcvideo: Add autosuspend quirk for AVerMedia Live Gamer HD 2
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit b79251c881bb39f70c6f6fb30ad5d454b78c9f4a ]
A user has reported that this device gets stuck in a loop where every few seconds it will turn off and turn back on, causing audio devices to disappear and reappear, its LED to flash, spamming dmesg, etc. This only happens when not in use; everything is fine when the video device is actually being used.
They also reported that using the AUTOSUSPEND quirk via module parameters fixes the issue.
Add the device to the quirk list.
ID 07ca:1570 AVerMedia Technologies, Inc. AVerMedia USB Device Negotiated speed: High Speed (480Mbps)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.10
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2 [unknown]
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x07ca AVerMedia Technologies, Inc.
idProduct 0x1570 AVerMedia USB Device
bcdDevice 1.00
iManufacturer 6 AVerMedia iProduct 7 AVerMedia USB Device iSerial 3 53106326013650 bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x01d6
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 150mA
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 0
bInterfaceCount 2
bFunctionClass 14 Video
bFunctionSubClass 3 Video Interface Collection
bFunctionProtocol 0
iFunction 8 AVerMedia Live Gamer HD 2
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 14 Video
bInterfaceSubClass 1 Video Control
bInterfaceProtocol 0
iInterface 8 AVerMedia Live Gamer HD 2
VideoControl Interface Descriptor:
bLength 13
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdUVC 1.00
wTotalLength 0x004d
dwClockFrequency 120.000000MHz
bInCollection 1
baInterfaceNr( 0) 1
VideoControl Interface Descriptor:
bLength 18
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0201 Camera Sensor
bAssocTerminal 0
iTerminal 0
wObjectiveFocalLengthMin 0
wObjectiveFocalLengthMax 0
wOcularFocalLength 0
bControlSize 3
bmControls 0x00000000
VideoControl Interface Descriptor:
bLength 11
bDescriptorType 36
bDescriptorSubtype 5 (PROCESSING_UNIT)
Warning: Descriptor too short
bUnitID 3
bSourceID 1
wMaxMultiplier 0
bControlSize 2
bmControls 0x0000000f
Brightness
Contrast
Hue
Saturation
iProcessing 0
bmVideoStandards 0x09
None
SECAM - 625/50
VideoControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 4
iTerminal 0
VideoControl Interface Descriptor:
bLength 28
bDescriptorType 36
bDescriptorSubtype 6 (EXTENSION_UNIT)
bUnitID 4
guidExtensionCode {c66d125b-0480-0844-8c26-b8363a84de63}
bNumControls 17
bNrInPins 1
baSourceID( 0) 3
bControlSize 3
bmControls( 0) 0x07
bmControls( 1) 0xfe
bmControls( 2) 0x01
iExtension 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 14 Video
bInterfaceSubClass 2 Video Streaming
bInterfaceProtocol 0
iInterface 8 AVerMedia Live Gamer HD 2
VideoStreaming Interface Descriptor:
bLength 14
bDescriptorType 36
bDescriptorSubtype 1 (INPUT_HEADER)
bNumFormats 1
wTotalLength 0x00bd
bEndpointAddress 0x89 EP 9 IN
bmInfo 0
bTerminalLink 2
bStillCaptureMethod 0
bTriggerSupport 0
bTriggerUsage 0
bControlSize 1
bmaControls( 0) 0
VideoStreaming Interface Descriptor:
bLength 11
bDescriptorType 36
bDescriptorSubtype 6 (FORMAT_MJPEG)
bFormatIndex 1
bNumFrameDescriptors 5
bFlags 0
Fixed-size samples: No
bDefaultFrameIndex 1
bAspectRatioX 0
bAspectRatioY 0
bmInterlaceFlags 0x00
Interlaced stream or variable: No
Fields per frame: 1 fields
Field 1 first: No
Field pattern: Field 1 only
bCopyProtect 0
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 7 (FRAME_MJPEG)
bFrameIndex 1
bmCapabilities 0x00
Still image unsupported
wWidth 640
wHeight 480
dwMinBitRate 294617088
dwMaxBitRate 294912000
dwMaxVideoFrameBufferSize 614400
dwDefaultFrameInterval 166833
bFrameIntervalType 2
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 7 (FRAME_MJPEG)
bFrameIndex 2
bmCapabilities 0x00
Still image unsupported
wWidth 720
wHeight 480
dwMinBitRate 331444224
dwMaxBitRate 331776000
dwMaxVideoFrameBufferSize 691200
dwDefaultFrameInterval 166833
bFrameIntervalType 2
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 30
bDescriptorType 36
bDescriptorSubtype 7 (FRAME_MJPEG)
bFrameIndex 3
bmCapabilities 0x00
Still image unsupported
wWidth 720
wHeight 576
dwMinBitRate 331776000
dwMaxBitRate 331776000
dwMaxVideoFrameBufferSize 829440
dwDefaultFrameInterval 200000
bFrameIntervalType 1
dwFrameInterval( 0) 200000
VideoStreaming Interface Descriptor:
bLength 38
bDescriptorType 36
bDescriptorSubtype 7 (FRAME_MJPEG)
bFrameIndex 4
bmCapabilities 0x00
Still image unsupported
wWidth 1280
wHeight 720
dwMinBitRate 737280000
dwMaxBitRate 884736000
dwMaxVideoFrameBufferSize 1843200
dwDefaultFrameInterval 166666
bFrameIntervalType 3
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
dwFrameInterval( 2) 200000
VideoStreaming Interface Descriptor:
bLength 46
bDescriptorType 36
bDescriptorSubtype 7 (FRAME_MJPEG)
bFrameIndex 5
bmCapabilities 0x00
Still image unsupported
wWidth 1920
wHeight 1080
dwMinBitRate 994332672
dwMaxBitRate 1990656000
dwMaxVideoFrameBufferSize 4147200
dwDefaultFrameInterval 166666
bFrameIntervalType 5
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
dwFrameInterval( 2) 200000
dwFrameInterval( 3) 333333
dwFrameInterval( 4) 333667
VideoStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 13 (COLORFORMAT)
bColorPrimaries 1 (BT.709,sRGB)
bTransferCharacteristics 1 (BT.709)
bMatrixCoefficients 4 (SMPTE 170M (BT.601))
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 14 Video
bInterfaceSubClass 2 Video Streaming
bInterfaceProtocol 0
iInterface 8 AVerMedia Live Gamer HD 2
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x89 EP 9 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x1400 3x 1024 bytes
bInterval 1
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 2
bInterfaceCount 2
bFunctionClass 1 Audio
bFunctionSubClass 2 Streaming
bFunctionProtocol 0
iFunction 9 AVerMedia Live Gamer HD 2
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 0
iInterface 9 AVerMedia Live Gamer HD 2
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 1.00
wTotalLength 0x003a
bInCollection 1
baInterfaceNr(0) 3
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0602 Digital Audio Interface
bAssocTerminal 0
bNrChannels 1
wChannelConfig 0x0000
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 5
wTerminalType 0x0603 Line Connector
bAssocTerminal 0
bNrChannels 1
wChannelConfig 0x0000
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 3
iTerminal 0
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 3
bSourceID 4
bControlSize 1
bmaControls(0) 0x01
Mute Control
iFeature 0
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 5 (SELECTOR_UNIT)
bUnitID 4
bNrInPins 2
baSourceID(0) 1
baSourceID(1) 5
iSelector 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 9 AVerMedia Live Gamer HD 2
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 9 AVerMedia Live Gamer HD 2
AudioStreaming Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 2
bDelay 1 frames
wFormatTag 0x0001 PCM
AudioStreaming Interface Descriptor:
bLength 11
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize 2
bBitResolution 16
bSamFreqType 1 Discrete
tSamFreq[ 0] 48000
Endpoint Descriptor:
bLength 9
bDescriptorType 5
bEndpointAddress 0x8a EP 10 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x00c0 1x 192 bytes
bInterval 4
bRefresh 0
bSynchAddress 0
AudioStreaming Endpoint Descriptor:
bLength 7
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x01
Sampling Frequency
bLockDelayUnits 0 Undefined
wLockDelay 0x0000
Binary Object Store Descriptor:
bLength 5
bDescriptorType 15
wTotalLength 0x0016
bNumDeviceCaps 2
USB 2.0 Extension Device Capability:
bLength 7
bDescriptorType 16
bDevCapabilityType 2
bmAttributes 0x00000006
BESL Link Power Management (LPM) Supported
SuperSpeed USB Device Capability:
bLength 10
bDescriptorType 16
bDevCapabilityType 3
bmAttributes 0x00
wSpeedsSupported 0x000e
Device can operate at Full Speed (12Mbps)
Device can operate at High Speed (480Mbps) Device can operate at SuperSpeed (5Gbps)
bFunctionalitySupport 1
Lowest fully-functional device speed is Full Speed (12Mbps)
bU1DevExitLat 4 micro seconds
bU2DevExitLat 4 micro seconds
Device Status: 0x0000
(Bus Powered)
--- drivers/media/usb/uvc/uvc_driver.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +9 -0
@@ -2847,6 +2847,15 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, +/* AVerMedia Live Gamer HD 2 capture card */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x07ca, + .idProduct = 0x1570, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_DISABLE_AUTOSUSPEND) }, /* ViMicro Vega */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 103/686 media: uvcvideo: Force UVC version for Avermedia GC515
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 65444446f0c595c0e250368cde88735b59ccc446 ]
The device announces itself as UVC 1.5, but it only accepts UVC 1.1 controls.
The camera can probably be handled by the automatic uvc_version handler, but it is more correct to add a quirk and keep some tracking of what vendors are more or less compliant. Also it might be more robust if we introduce more UVC version-dependent code.
Bus 003 Device 021: ID 07ca:1515 AVerMedia Technologies, Inc. X'tra Go GC515 Negotiated speed: High Speed (480Mbps)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2 [unknown]
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x07ca AVerMedia Technologies, Inc.
idProduct 0x1515 X'tra Go GC515
bcdDevice 0.10
iManufacturer 1 AVerMedia iProduct 2 X'tra Go GC515 iSerial 3 5313180000221 bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x03fd
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 500mA
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 0
bInterfaceCount 2
bFunctionClass 14 Video
bFunctionSubClass 3 Video Interface Collection
bFunctionProtocol 0
iFunction 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 14 Video
bInterfaceSubClass 1 Video Control
bInterfaceProtocol 1
iInterface 0
VideoControl Interface Descriptor:
bLength 13
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdUVC 1.50
wTotalLength 0x0059
dwClockFrequency 30.000000MHz
bInCollection 1
baInterfaceNr( 0) 1
VideoControl Interface Descriptor:
bLength 18
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0201 Camera Sensor
bAssocTerminal 0
iTerminal 0
wObjectiveFocalLengthMin 0
wObjectiveFocalLengthMax 0
wOcularFocalLength 0
bControlSize 3
bmControls 0x00000000
VideoControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 4
iTerminal 0
VideoControl Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 4 (SELECTOR_UNIT)
bUnitID 3
bNrInPins 1
baSource( 0) 1
iSelector 0
VideoControl Interface Descriptor:
bLength 13
bDescriptorType 36
bDescriptorSubtype 5 (PROCESSING_UNIT)
bUnitID 4
bSourceID 3
wMaxMultiplier 0
bControlSize 3
bmControls 0x00000000
iProcessing 0
bmVideoStandards 0x00
VideoControl Interface Descriptor:
bLength 29
bDescriptorType 36
bDescriptorSubtype 6 (EXTENSION_UNIT)
bUnitID 5
guidExtensionCode {55be8e1c-2fdb-4f7a-bd8d-b9b1108d20c3}
bNumControls 24
bNrInPins 1
baSourceID( 0) 4
bControlSize 4
bmControls( 0) 0xff
bmControls( 1) 0xff
bmControls( 2) 0xff
bmControls( 3) 0x00
iExtension 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x85 EP 5 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
VideoControl Endpoint Descriptor:
bLength 5
bDescriptorType 37
bDescriptorSubtype 3 (EP_INTERRUPT)
wMaxTransferSize 64
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 14 Video
bInterfaceSubClass 2 Video Streaming
bInterfaceProtocol 1
iInterface 0
VideoStreaming Interface Descriptor:
bLength 16
bDescriptorType 36
bDescriptorSubtype 1 (INPUT_HEADER)
bNumFormats 3
wTotalLength 0x0303
bEndpointAddress 0x81 EP 1 IN
bmInfo 0
bTerminalLink 2
bStillCaptureMethod 1
bTriggerSupport 0
bTriggerUsage 0
bControlSize 1
bmaControls( 0) 4
bmaControls( 1) 4
bmaControls( 2) 0
VideoStreaming Interface Descriptor:
bLength 28
bDescriptorType 36
bDescriptorSubtype 16 (FORMAT_FRAME_BASED)
bFormatIndex 1
bNumFrameDescriptors 8
guidFormat {34363248-0000-0010-8000-00aa00389b71}
bBitsPerPixel 24
bDefaultFrameIndex 1
bAspectRatioX 0
bAspectRatioY 0
bmInterlaceFlags 0x00
Interlaced stream or variable: No
Fields per frame: 2 fields
Field 1 first: No
Field pattern: Field 1 only
bCopyProtect 1
bVariableSize 1
VideoStreaming Interface Descriptor:
bLength 62
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 1
bmCapabilities 0x01
Still image supported
wWidth 1920
wHeight 1080
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 9
dwBytesPerLine 0
dwFrameInterval( 0) 83333
dwFrameInterval( 1) 83416
dwFrameInterval( 2) 166666
dwFrameInterval( 3) 166833
dwFrameInterval( 4) 200000
dwFrameInterval( 5) 333333
dwFrameInterval( 6) 333667
dwFrameInterval( 7) 400000
dwFrameInterval( 8) 416666
VideoStreaming Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 2
bmCapabilities 0x01
Still image supported
wWidth 3840
wHeight 2160
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 333333
bFrameIntervalType 4
dwBytesPerLine 0
dwFrameInterval( 0) 333333
dwFrameInterval( 1) 333667
dwFrameInterval( 2) 400000
dwFrameInterval( 3) 416666
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 3
bmCapabilities 0x01
Still image supported
wWidth 2560
wHeight 1440
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 4
bmCapabilities 0x01
Still image supported
wWidth 1280
wHeight 800
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 38
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 5
bmCapabilities 0x01
Still image supported
wWidth 1280
wHeight 720
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 3
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
dwFrameInterval( 2) 200000
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 6
bmCapabilities 0x01
Still image supported
wWidth 720
wHeight 576
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 200000
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 200000
dwFrameInterval( 1) 400000
VideoStreaming Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 7
bmCapabilities 0x01
Still image supported
wWidth 720
wHeight 480
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 4
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
dwFrameInterval( 2) 333333
dwFrameInterval( 3) 333667
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 8
bmCapabilities 0x01
Still image supported
wWidth 640
wHeight 480
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 13 (COLORFORMAT)
bColorPrimaries 0 (Unspecified)
bTransferCharacteristics 0 (Unspecified)
bMatrixCoefficients 0 (Unspecified)
VideoStreaming Interface Descriptor:
bLength 28
bDescriptorType 36
bDescriptorSubtype 16 (FORMAT_FRAME_BASED)
bFormatIndex 2
bNumFrameDescriptors 8
guidFormat {43564548-0000-0010-8000-00aa00389b71}
bBitsPerPixel 24
bDefaultFrameIndex 1
bAspectRatioX 0
bAspectRatioY 0
bmInterlaceFlags 0x00
Interlaced stream or variable: No
Fields per frame: 2 fields
Field 1 first: No
Field pattern: Field 1 only
bCopyProtect 1
bVariableSize 1
VideoStreaming Interface Descriptor:
bLength 62
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 1
bmCapabilities 0x01
Still image supported
wWidth 1920
wHeight 1080
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 9
dwBytesPerLine 0
dwFrameInterval( 0) 83333
dwFrameInterval( 1) 83416
dwFrameInterval( 2) 166666
dwFrameInterval( 3) 166833
dwFrameInterval( 4) 200000
dwFrameInterval( 5) 333333
dwFrameInterval( 6) 333667
dwFrameInterval( 7) 400000
dwFrameInterval( 8) 416666
VideoStreaming Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 2
bmCapabilities 0x01
Still image supported
wWidth 3840
wHeight 2160
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 333333
bFrameIntervalType 4
dwBytesPerLine 0
dwFrameInterval( 0) 333333
dwFrameInterval( 1) 333667
dwFrameInterval( 2) 400000
dwFrameInterval( 3) 416666
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 3
bmCapabilities 0x01
Still image supported
wWidth 2560
wHeight 1440
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 4
bmCapabilities 0x01
Still image supported
wWidth 1280
wHeight 800
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 38
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 5
bmCapabilities 0x01
Still image supported
wWidth 1280
wHeight 720
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 3
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
dwFrameInterval( 2) 200000
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 6
bmCapabilities 0x01
Still image supported
wWidth 720
wHeight 576
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 200000
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 200000
dwFrameInterval( 1) 400000
VideoStreaming Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 7
bmCapabilities 0x01
Still image supported
wWidth 720
wHeight 480
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 4
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
dwFrameInterval( 2) 333333
dwFrameInterval( 3) 333667
VideoStreaming Interface Descriptor:
bLength 34
bDescriptorType 36
bDescriptorSubtype 17 (FRAME_FRAME_BASED)
bFrameIndex 8
bmCapabilities 0x01
Still image supported
wWidth 640
wHeight 480
dwMinBitRate 33554432
dwMaxBitRate 268435456
dwDefaultFrameInterval 166666
bFrameIntervalType 2
dwBytesPerLine 0
dwFrameInterval( 0) 166666
dwFrameInterval( 1) 166833
VideoStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 13 (COLORFORMAT)
bColorPrimaries 0 (Unspecified)
bTransferCharacteristics 0 (Unspecified)
bMatrixCoefficients 0 (Unspecified)
VideoStreaming Interface Descriptor:
bLength 11
bDescriptorType 36
bDescriptorSubtype 6 (FORMAT_MJPEG)
bFormatIndex 3
bNumFrameDescriptors 1
bFlags 0
Fixed-size samples: No
bDefaultFrameIndex 1
bAspectRatioX 0
bAspectRatioY 0
bmInterlaceFlags 0x00
Interlaced stream or variable: No
Fields per frame: 1 fields
Field 1 first: No
Field pattern: Field 1 only
bCopyProtect 1
VideoStreaming Interface Descriptor:
bLength 30
bDescriptorType 36
bDescriptorSubtype 7 (FRAME_MJPEG)
bFrameIndex 1
bmCapabilities 0x01
Still image supported
wWidth 1920
wHeight 1080
dwMinBitRate 314572800
dwMaxBitRate 314572800
dwMaxVideoFrameBufferSize 4147200
dwDefaultFrameInterval 166666
bFrameIntervalType 1
dwFrameInterval( 0) 166666
VideoStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 13 (COLORFORMAT)
bColorPrimaries 0 (Unspecified)
bTransferCharacteristics 0 (Unspecified)
bMatrixCoefficients 0 (Unspecified)
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 2
bInterfaceCount 2
bFunctionClass 1 Audio
bFunctionSubClass 2 Streaming
bFunctionProtocol 0
iFunction 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 0
iInterface 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 1.00
wTotalLength 0x0026
bInCollection 1
baInterfaceNr(0) 3
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0602 Digital Audio Interface
bAssocTerminal 0
bNrChannels 2
wChannelConfig 0x0003
Left Front (L)
Right Front (R)
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 3
iTerminal 0
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 3
bSourceID 1
bControlSize 1
bmaControls(0) 0x03
Mute Control
Volume Control
iFeature 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
AudioStreaming Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 2
bDelay 1 frames
wFormatTag 0x0001 PCM
AudioStreaming Interface Descriptor:
bLength 11
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize 2
bBitResolution 16
bSamFreqType 1 Discrete
tSamFreq[ 0] 48000
Endpoint Descriptor:
bLength 9
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x00c4 1x 196 bytes
bInterval 4
bRefresh 0
bSynchAddress 0
AudioStreaming Endpoint Descriptor:
bLength 7
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x01
Sampling Frequency
bLockDelayUnits 0 Undefined
wLockDelay 0x0000
--- drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +11 -0
@@ -2847,6 +2847,17 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_fix_bandwidth }, +/* Avermedia GC515 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x07ca, + .idProduct = 0x1515, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = UVC_PC_PROTOCOL_15, + .driver_info = (kernel_ulong_t)&(const struct uvc_device_info ){ + .uvc_version =0x0110 , + } }, /* AVerMedia Live Gamer HD 2 capture card */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 104/686 mkiss: size the frame buffers for worst-case KISS escaping
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
ax_encaps() accepts a frame for transmission as long as it is not longer than dev->mtu + 73 bytes, and KISS escaping can double every byte of it (END and ESC are each sent as two bytes). The transmit buffer, however, is only max(2 * dev->mtu, 1152) + 4 bytes long, so the 73 bytes of header allowance are not covered once they are doubled.
With the default MTU of 236 the 1152 byte floor hides the problem. As soon as the MTU is raised above 502, a maximum length frame made of END or ESC bytes makes kiss_esc() or kiss_esc_crc() write up to 148 bytes past the end of xbuff. The content of the frame does not have to come from the local machine: it can be traffic forwarded for another station, a routed IP datagram for instance.
Reproduced under KASAN on 6.12.94 with the MTU set to 1024 and a 1097 byte UI frame whose payload is all 0xC0:
BUG: KASAN: slab-out-of-bounds in kiss_esc+0x316/0x390 [mkiss] Write of size 1 at addr ffff888001c9c804 by task init/1 kiss_esc+0x316/0x390 [mkiss] ax_xmit+0x346/0xcd5 [mkiss] dev_hard_start_xmit+0xf8/0x580 sch_direct_xmit+0x131/0xa10 __dev_queue_xmit+0x27f6/0x34b0 packet_sendmsg+0x30c5/0x4a10 The buggy address is located 0 bytes to the right of allocated 2052-byte region [ffff888001c9c000, ffff888001c9c804)
In addition the driver sets no upper bound on the MTU. An MTU of 2^30 or more makes "dev->mtu * 2" negative, which leaves the buffers at their minimum size while the length check in ax_encaps() no longer rejects anything.
Compute the buffer length in one place, from the largest frame that ax_encaps() accepts, and allocate six more bytes for the two END delimiters and the two CRC bytes, which may need escaping too. Set max_mtu so that the computation cannot overflow.
With the change the same test produces no KASAN report, the frames found on the serial line are identical to those sent, with and without CRC (SMACK and FlexNet), and an MTU above 65535 is refused.
--- drivers/net/hamradio/mkiss.c | 49 ++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-)
drivers/net/hamradio/mkiss.c +30 -19
@@ -30,6 +30,7 @@#include <net/ax25.h> #define AX_MTU 236 +#define AX_MAX_MTU 65535/* some arch define END as assembly function ending, just undef it */ #undef END
@@ -355,13 +356,19 @@ static int ax_set_mac_address(struct net_device *dev, void *addr)/*---------------------------------------------------------------------------*/ -static void ax_changedmtu (struct mkiss *ax) -{ -struct net_device *dev = ax->dev; -unsigned char *xbuff, *rbuff, *oxbuff, *orbuff; -int len; +/* +* Length of the frame buffers for the current MTU. +* +* ax_encaps() accepts frames of up to dev->mtu + 73 bytes and KISS escaping +* can double every one of them. The buffers are allocated AX_BUF_SLACK bytes +* larger than this, for the two END delimiters and the two CRC bytes, which +* can need escaping as well. +*/ +#define AX_BUF_SLACK 6 - len = dev->mtu *2 ; +static int ax_buflen (const struct net_device *dev) +{ +int len = (dev->mtu +73 ) *2 ;/* * allow for arrival of larger UDP packets, even if we say not to
@@ -371,8 +378,19 @@ static void ax_changedmtu(struct mkiss *ax)if (len <576 *2 ) len =576 *2 ; - xbuff =kmalloc (len +4 ,GFP_ATOMIC ); - rbuff =kmalloc (len +4 ,GFP_ATOMIC ); +return len; +} + +static void ax_changedmtu (struct mkiss *ax) +{ +struct net_device *dev = ax->dev; +unsigned char *xbuff, *rbuff, *oxbuff, *orbuff; +int len; + + len =ax_buflen (dev); + + xbuff =kmalloc (len +AX_BUF_SLACK ,GFP_ATOMIC ); + rbuff =kmalloc (len +AX_BUF_SLACK ,GFP_ATOMIC );if (xbuff ==NULL || rbuff ==NULL ) { printk(KERN_ERR "mkiss: %s: unable to grow ax25 buffers, "
@@ -581,20 +599,12 @@ static int ax_open(struct net_device *dev)* rbuff Receive buffer. * xbuff Transmit buffer. */ - len = dev->mtu *2 ; - -/* -* allow for arrival of larger UDP packets, even if we say not to -* also fixes a bug in which SunOS sends 512-byte packets even with -* an MSS of 128 -*/ -if (len <576 *2 ) - len =576 *2 ; + len =ax_buflen (dev); -if ((ax->rbuff =kmalloc (len +4 ,GFP_KERNEL )) ==NULL ) +if ((ax->rbuff =kmalloc (len +AX_BUF_SLACK ,GFP_KERNEL )) ==NULL ) goto norbuff; -if ((ax->xbuff =kmalloc (len +4 ,GFP_KERNEL )) ==NULL ) +if ((ax->xbuff =kmalloc (len +AX_BUF_SLACK ,GFP_KERNEL )) ==NULL ) goto noxbuff; ax->mtu = dev->mtu +73 ;
@@ -640,6 +650,7 @@ static void ax_setup(struct net_device *dev) {/* Finish setting up the DEVICE info. */ dev->mtu =AX_MTU ; + dev->max_mtu =AX_MAX_MTU ; dev->hard_header_len =AX25_MAX_HEADER_LEN ; dev->addr_len =AX25_ADDR_LEN ; dev->type =ARPHRD_AX25 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 105/686 mkiss: dont use a tty write error as a byte count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
ax_encaps() and mkiss_write_wakeup() take whatever tty->ops->write() returns as the number of bytes accepted by the tty. Some tty drivers return a negative errno instead, USB serial adapters for instance when the device is gone or the URB cannot be submitted.
A negative value moves ax->xhead to before the start of xbuff and makes ax->xleft larger than the frame, so the next write wakeup sends memory that does not belong to the transmit buffer down the line. It is also added to the tx_bytes counter.
Treat a negative return as a transmit error: count it in tx_errors, drop what is left of the frame and restart the queue, as is already done for an oversized frame.
This path could not be exercised on the test bench, where neither the 8250 driver nor a pty ever returns an error from write(). The change was compile tested and checked for regressions only: 46 frames out of 46 are still sent unchanged.
--- drivers/net/hamradio/mkiss.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/net/hamradio/mkiss.c +16 -0
@@ -526,6 +526,14 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len)set_bit (TTY_DO_WRITE_WAKEUP , &ax->tty->flags); actual = ax->tty->ops->write (ax->tty, ax->xbuff, count); +if (actual <0 ) { +/* The tty refused the frame: drop it. */ +clear_bit (TTY_DO_WRITE_WAKEUP , &ax->tty->flags); + dev->stats.tx_errors++; + ax->xleft =0 ; +netif_start_queue (dev); +return ; + } dev->stats.tx_packets++; dev->stats.tx_bytes += actual;
@@ -939,6 +947,14 @@ static void mkiss_write_wakeup(struct tty_struct *tty) } actual = tty->ops->write (tty, ax->xhead, ax->xleft); +if (actual <0 ) { +/* Give up on the rest of this frame. */ +clear_bit (TTY_DO_WRITE_WAKEUP , &tty->flags); + ax->dev->stats.tx_errors++; + ax->xleft =0 ; +netif_wake_queue (ax->dev); + goto out; + } ax->xleft -= actual; ax->xhead += actual;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 106/686 bpqether: leave the Ethernet devices queue and counters alone
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
bpq_xmit() replaces its "dev" argument with the underlying Ethernet device before it builds the Ethernet header. The three statements that follow were written for the bpq device but now act on the Ethernet one:
- tx_packets and tx_bytes are added to the Ethernet device's statistics, so the bpq device never counts a transmitted frame;
- netif_wake_queue() restarts the transmit queue of the Ethernet device. If its driver had stopped that queue because its transmit ring is full, bpqether overrides the driver's flow control.
Count the frame on the bpq device, which is still at hand in orig_dev, and drop the netif_wake_queue() call. The bpq device does not stop its own queue outside of ndo_stop, so there is nothing to wake.
Tested in a QEMU guest (6.12.94, KASAN and lockdep) with two e1000 ports on the same hub, bpq0 on the first and bpq1 on the second. After 40 UI frames bpq0 reported tx_packets=0 before the change and 40 after. With the transmit queue of eth0 stopped by a small helper module, a frame sent on bpq0 restarted that queue before the change and leaves it stopped after; the frame goes out once the queue is woken. In both cases the 40 frames are received unchanged on bpq1.
--- drivers/net/hamradio/bpqether.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/hamradio/bpqether.c +3 -4
@@ -267,11 +267,10 @@ static netdev_tx_t bpq_xmit(struct sk_buff *skb, struct net_device *dev) skb->protocol =ax25_type_trans (skb, dev);skb_reset_network_header (skb);dev_hard_header (skb, dev,ETH_P_BPQ , bpq->dest_addr,NULL ,0 ); - dev->stats.tx_packets++; - dev->stats.tx_bytes+=skb->len; - + orig_dev->stats.tx_packets++; + orig_dev->stats.tx_bytes += skb->len; +dev_queue_xmit (skb); -netif_wake_queue (dev);return NETDEV_TX_OK ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 107/686 bpqether: fix truncated /proc/net/bpqether on partial reads
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
bpq_seq_start() walks the device list to find the entry at *pos, but never increments its counter. It returns the first device when *pos is 1 and NULL for any larger value.
The seq_file core calls ->start() with the saved position each time a read() needs more data, so the listing stops after the first device as soon as it is not produced in a single pass: when it is read with a small buffer, or when it is longer than a page.
With five bpq devices, reading the file 64 bytes at a time returned the header and one device before the change, and all five devices after.
--- drivers/net/hamradio/bpqether.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/hamradio/bpqether.c +1 -0
@@ -366,6 +366,7 @@ static void *bpq_seq_start(struct seq_file *seq, loff_t *pos)list_for_each_entry_rcu (bpqdev, &bpq_devices, bpq_list) {if (i == *pos)return bpqdev; + i++; }return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 108/686 rose: arm the neighbour timers with mod_timer()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_start_t0timer() and rose_start_ftimer() restart a neighbour timer in two steps: timer_delete(), then a rewrite of .function and .expires followed by add_timer(). Nothing serialises these calls. Two sockets using the same neighbour can reach rose_transmit_link() at the same time on two CPUs, for instance rose_connect() in process context and rose_route_frame() in softirq context, or a connect racing the self-rearm at the end of rose_t0timer_expiry(). Both see the timer idle, both call timer_delete(), and the second add_timer() finds the timer already pending:
WARNING: CPU: 1 PID: 11465 at kernel/time/timer.c:1294 add_timer+0x60/0x90 rose_write_internal+0x3ab/0x15b0 [rose] rose_connect+0x60f/0x1320 [rose]
With panic_on_warn this takes the machine down.
Set the expiry functions once, when the neighbour is created, and start the timers with a single mod_timer() call, which updates a pending timer or arms an idle one atomically.
This also stops rewriting .function on every start, so a start that would come after timer_shutdown_sync() in rose_neigh_put() is ignored, as that function's comment expects, instead of bringing the timer back.
--- include/net/rose.h | 1 + net/rose/rose_link.c | 24 ++++++++++-------------- net/rose/rose_route.c | 6 ++---- 3 files changed, 13 insertions(+), 18 deletions(-)
include/net/rose.h +1 -0
@@ -231,6 +231,7 @@ int rose_rcv_frame(struct sock *sk, struct sk_buff *skb);int rose_backlog_rcv (struct sock *sk,struct sk_buff *skb);/* rose_link.c */ +void rose_neigh_init_timers (struct rose_neigh *neigh);void rose_start_ftimer (struct rose_neigh *);void rose_stop_ftimer (struct rose_neigh *);void rose_stop_t0timer (struct rose_neigh *);
net/rose/rose_link.c +10 -14
@@ -30,26 +30,22 @@ static void rose_t0timer_expiry(struct timer_list *);static void rose_transmit_restart_confirmation (struct rose_neigh *neigh);static void rose_transmit_restart_request (struct rose_neigh *neigh); -void rose_start_ftimer (struct rose_neigh *neigh) +void rose_neigh_init_timers (struct rose_neigh *neigh) { -timer_delete (&neigh->ftimer); - - neigh->ftimer.function = rose_ftimer_expiry; - neigh->ftimer.expires = - jiffies +msecs_to_jiffies (sysctl_rose_link_fail_timeout); +timer_setup (&neigh->ftimer, rose_ftimer_expiry,0 ); +timer_setup (&neigh->t0timer, rose_t0timer_expiry,0 ); +} -add_timer (&neigh->ftimer); +void rose_start_ftimer (struct rose_neigh *neigh) +{ +mod_timer (&neigh->ftimer, + jiffies +msecs_to_jiffies (sysctl_rose_link_fail_timeout)); }static void rose_start_t0timer (struct rose_neigh *neigh) { -timer_delete (&neigh->t0timer); - - neigh->t0timer.function = rose_t0timer_expiry; - neigh->t0timer.expires = - jiffies +msecs_to_jiffies (sysctl_rose_restart_request_timeout); - -add_timer (&neigh->t0timer); +mod_timer (&neigh->t0timer, + jiffies +msecs_to_jiffies (sysctl_rose_restart_request_timeout)); }void rose_stop_ftimer (struct rose_neigh *neigh)
net/rose/rose_route.c +2 -4
@@ -102,8 +102,7 @@ static int __must_check rose_add_node(struct rose_route_struct *rose_route,skb_queue_head_init (&rose_neigh->queue); -timer_setup (&rose_neigh->ftimer,NULL ,0 ); -timer_setup (&rose_neigh->t0timer,NULL ,0 ); +rose_neigh_init_timers (rose_neigh);if (rose_route->ndigis !=0 ) { rose_neigh->digipeat =
@@ -446,8 +445,7 @@ void rose_add_loopback_neigh(void)skb_queue_head_init (&sn->queue); -timer_setup (&sn->ftimer,NULL ,0 ); -timer_setup (&sn->t0timer,NULL ,0 ); +rose_neigh_init_timers (sn);spin_lock_bh (&rose_neigh_list_lock); sn->next = rose_neigh_list;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 109/686 netrom: ignore a BPQ transport timeout below the sysctl minimum
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
A connect request carrying the BPQ extension (37 bytes) ends with the transport timeout the caller proposes, in seconds. nr_rx_frame() takes it as the new circuit's T1 whenever it is smaller than the current one, with no lower bound. A proposal of 0 leaves T1 at 0:
the first unacknowledged information frame is sent N2 times within a few jiffies and the circuit is torn down with ETIMEDOUT. Values of a few seconds are not much better on a slow radio link. The transport_timeout sysctl refuses anything below 5 seconds, and setsockopt(NETROM_T1) anything below 1 second, but a remote node can set what the local administrator cannot.
Ignore proposals below 5 seconds and keep the local T1 in that case.
--- net/netrom/af_netrom.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netrom/af_netrom.c +5 -2
@@ -1027,10 +1027,13 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)if (window < nr_make->window) nr_make->window = window; -/* L4 timeout negotiation */ +/* +* L4 timeout negotiation. Ignore a proposal shorter than the +* smallest transport timeout the sysctl accepts (5 s), such as 0. +*/ if (skb->len ==37 ) { timeout = skb->data[36 ] *256 + skb->data[35 ]; -if (timeout *HZ < nr_make->t1) +if (timeout >=5 && timeout *HZ < nr_make->t1) nr_make->t1 = timeout *HZ ; nr_make->bpqext =1 ; }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 110/686 rose: dont give the same LCI to two calls placed at the same time
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_connect() picks the logical channel of a new call with rose_new_lci(), which looks for an LCI used neither by a socket nor by a through route on the neighbour, and stores the result in rose->lci afterwards. Nothing serialises the search and the store, so two sockets calling through the same neighbour on two CPUs can pick the same LCI. An unbound socket is worse: it is only put on the socket list by the autobind after its LCI was chosen, so it stays invisible to the search for longer. Both calls go out on the same channel, the neighbour accepts one of them, and the other connect() hangs until T1 expires while the neighbour holds a circuit nobody uses.
rose_new_lci() also walks rose_route_list through rose_route_free_lci() without rose_route_list_lock when called from rose_connect(), while rose_route_frame() may add or remove routes on another CPU.
Do the autobind first, so the socket is on the list before it gets an LCI, then choose and store the LCI under rose_route_list_lock, as rose_route_frame() already does for a through route. Assert the lock in rose_route_free_lci().
On a QEMU bench with two 4-CPU guests, eight connect() calls started at the same time through one neighbour, six rounds: before, 14 duplicate LCIs and 14 of the 48 calls timed out; after, no duplicate and 48/48 calls connected.
--- include/net/rose.h | 1 + net/rose/af_rose.c | 32 ++++++++++++++++---------------- net/rose/rose_route.c | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 16 deletions(-)
include/net/rose.h +1 -0
@@ -267,6 +267,7 @@ void rose_link_device_down(struct net_device *);struct net_device *rose_dev_first (void );struct net_device *rose_dev_get (rose_address *);struct rose_route *rose_route_free_lci (unsigned int ,struct rose_neigh *); +unsigned int rose_assign_lci (struct sock *sk);struct rose_neigh *rose_get_neigh (rose_address *,unsigned char *,unsigned char *,int );int rose_rt_ioctl (unsigned int ,void __user *);
net/rose/af_rose.c +16 -16
@@ -330,6 +330,7 @@ struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)/* * Find a unique LCI for a given device. +* The caller holds rose_route_list_lock. */ unsigned int rose_new_lci (struct rose_neigh *neigh) {
@@ -854,20 +855,6 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le sk->sk_state =TCP_CLOSE ; sock->state =SS_UNCONNECTED ; - rose->neighbour =rose_get_neigh (&addr->srose_addr, &cause, - &diagnostic,0 ); -if (!rose->neighbour) { - err = -ENETUNREACH ; - goto out_release; - } - - rose->lci =rose_new_lci (rose->neighbour); -if (!rose->lci) { - err = -ENETUNREACH ; -rose_neigh_put (rose->neighbour); - goto out_release; - } -if (sock_flag (sk,SOCK_ZAPPED )) {/* Must bind first - autobinding in this may or may not work */ struct net_device *dev;
@@ -876,14 +863,12 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le dev =rose_dev_first ();if (!dev) { err = -ENETUNREACH ; -rose_neigh_put (rose->neighbour); goto out_release; } user =ax25_findbyuid (current_euid ());if (!user) { err = -EINVAL ; -rose_neigh_put (rose->neighbour);dev_put (dev); goto out_release; }
@@ -897,6 +882,21 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_lerose_insert_socket (sk);/* Finish the bind */ } + + rose->neighbour =rose_get_neigh (&addr->srose_addr, &cause, + &diagnostic,0 ); +if (!rose->neighbour) { + err = -ENETUNREACH ; + goto out_release; + } + +/* The socket is on the list now, so others see the LCI it gets */ +if (!rose_assign_lci (sk)) { + err = -ENETUNREACH ; +rose_neigh_put (rose->neighbour); + goto out_release; + } + rose->dest_addr = addr->srose_addr; rose->dest_call = addr->srose_call; rose->rand = ((long )rose &0xFFFF ) + rose->lci;
net/rose/rose_route.c +19 -0
@@ -724,6 +724,8 @@ struct rose_route *rose_route_free_lci(unsigned int lci, struct rose_neigh *neig {struct rose_route *rose_route; +lockdep_assert_held (&rose_route_list_lock); +for (rose_route = rose_route_list; rose_route !=NULL ; rose_route = rose_route->next)if ((rose_route->neigh1 == neigh && rose_route->lci1 == lci) || (rose_route->neigh2 == neigh && rose_route->lci2 == lci))
@@ -732,6 +734,23 @@ struct rose_route *rose_route_free_lci(unsigned int lci, struct rose_neigh *neigreturn NULL ; } +/* +* Give a socket placing a call a free LCI on its neighbour. As for a +* through route in rose_route_frame(), the search and the assignment +* are done under rose_route_list_lock, so two calls cannot pick the +* same LCI. The socket must already be on the socket list. +*/ +unsigned int rose_assign_lci (struct sock *sk) +{ +struct rose_sock *rose =rose_sk (sk); + +spin_lock_bh (&rose_route_list_lock); + rose->lci =rose_new_lci (rose->neighbour); +spin_unlock_bh (&rose_route_list_lock); + +return rose->lci; +} +/* * Find a neighbour or a route given a ROSE address. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 111/686 ax25: dont create a second connection for a link on an incoming SABM
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When a SABM arrives for one of our interfaces and no socket listens, ax25_rcv() looks the link up with ax25_find_cb(), creates a control block if there is none, and adds it with ax25_cb_add() at the end. The lookup and the add are not done under one lock. If ax25_send_frame() opens the same link on another CPU in between, for instance a ROSE restart request or a NetRom frame for that neighbour, both control blocks end up on ax25_list. The one created by ax25_send_frame() stays in state 1 with the frames queued on it and never reaches state 3, as the peer's UA and its later frames go to the other one.
ax25_send_frame() already adds its control block with ax25_cb_add_unique() for the same reason. Do the same here before the UA is sent: if a connection for the link exists by then, drop the new control block and give the SABM to the existing one, which answers it from state 1 like a SABM received after the lookup. ax25_send_frame() may find the new control block before it reaches state 3 and only queue its frames, so kick the queue once the connection is up.
The listener path is left alone: the new socket is on the listener's accept queue by then and the race needs a socket connecting from the listening address.
On a QEMU bench with a delay widening the window between the lookup and the add, an incoming SABM crossing a ROSE call to the same neighbour left two connections for the link in 5 rounds out of 6 before, and one connection in state 3 in every round after.
--- net/ax25/ax25_in.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
net/ax25/ax25_in.c +24 -2
@@ -201,7 +201,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,int type =0 , mine =0 , dama;struct sock *make, *sk;ax25_digi dp, reverse_dp; -ax25_cb *ax25; +ax25_cb *ax25, *existing;ax25_dev *ax25_dev;/*
@@ -450,6 +450,24 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ax25->window = ax25_dev->values[AX25_VALUES_WINDOW ]; } +if (!sk) { +/* +* ax25_send_frame() may have created a connection for this +* link since the lookup above: add ours only if there is +* none, otherwise give the SABM to the existing one. Frames +* queued on ours before it reaches state 3 are sent by the +* ax25_kick() below. +*/ + existing =ax25_cb_add_unique (ax25); +if (existing) { +ax25_cb_put (ax25); +if (ax25_process_rx_frame (existing, skb, type, dama) ==0 ) +kfree_skb (skb); +ax25_cb_put (existing); +return 0 ; + } + } +ax25_send_control (ax25,AX25_UA ,AX25_POLLON ,AX25_RESPONSE );#ifdef CONFIG_AX25_DAMA_SLAVE
@@ -459,12 +477,16 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ax25->state =AX25_STATE_3 ; -ax25_cb_add (ax25); +if (sk) +ax25_cb_add (ax25);ax25_start_heartbeat (ax25);ax25_start_t3timer (ax25);ax25_start_idletimer (ax25); +if (!sk) +ax25_kick (ax25); +if (sk) {if (!sock_flag (sk,SOCK_DEAD )) sk->sk_data_ready (sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 112/686 ax25: free a closed socket when its device goes down
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
A SOCK_SEQPACKET socket closed by its owner is marked SOCK_DESTROY and left to its heartbeat, which calls ax25_destroy_socket() once the link is down. A connection that a listener never accepted gets the same treatment when the listener is closed (TCP_LISTEN and SOCK_DEAD). Neither socket has a struct socket left, so nothing else frees it.
If the device goes away during that time, ax25_kill_by_device() calls ax25_disconnect() with ENETUNREACH, which since commit fc6d01ff9ef0 ("ax25: Fix NULL pointer dereferences in ax25 timers") stops the heartbeat with timer_delete_sync() whatever the socket state, and then takes the control block off the list. The socket is never freed and keeps a reference on the ax25 module, so ax25 can no longer be unloaded.
This shows up on a node that closes a connection and restarts kissattach, or unloads bpqether, within the few seconds the heartbeat
needs: each such connection adds one to the ax25 module refcount for good.
Free those sockets in ax25_kill_by_device() with ax25_destroy_socket(), under the same condition the heartbeat uses.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link): three client connections closed and ax0 removed one second later, then a connection left unaccepted by a closed listener and ax0 removed one second later. ax25 refcount after each:
before after
3 closed clients +3 0 unaccepted connection +1 0 control (ax0 removed 0 0
25 s after close)
Same result over five runs, with no KASAN or lockdep report. Also seen on two live nodes over bpqether, where ax25 could no longer be reloaded until a reboot.
--- net/ax25/af_ax25.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
net/ax25/af_ax25.c +15 -1
@@ -78,6 +78,7 @@ static void ax25_kill_by_device(struct net_device *dev)ax25_dev *ax25_dev;ax25_cb *s;struct sock *sk; +bool orphan;if ((ax25_dev =ax25_dev_ax25dev (dev)) ==NULL )return ;
@@ -109,6 +110,16 @@ static void ax25_kill_by_device(struct net_device *dev)sock_hold (sk);spin_unlock_bh (&ax25_list_lock);lock_sock (sk); +/* +* A socket closed by its owner, or a connection left +* unaccepted by a closed listener, is freed by its +* heartbeat once it is down. ax25_disconnect() below +* stops that heartbeat for good, so free the socket +* here, or it is never freed and pins the module. +*/ + orphan =sock_flag (sk,SOCK_DESTROY ) || + (sk->sk_state ==TCP_LISTEN && +sock_flag (sk,SOCK_DEAD ));ax25_disconnect (s,ENETUNREACH );WRITE_ONCE (s->ax25_dev,NULL );if (sk->sk_socket) {
@@ -116,7 +127,10 @@ static void ax25_kill_by_device(struct net_device *dev) &s->dev_tracker);ax25_dev_put (ax25_dev); } -ax25_cb_del (s); +if (orphan) +ax25_destroy_socket (s); +else +ax25_cb_del (s);release_sock (sk);spin_lock_bh (&ax25_list_lock);sock_put (sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 113/686 mkiss: restart the transmit queue when the interface is opened
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
ax_close() stops the transmit queue, but ax_open_dev() never starts it again, and the core does not do it either. After "ip link set ax0 down" followed by "ip link set ax0 up" the queue stays stopped: the qdisc never calls ax_xmit() any more, so the 20 s transmit timeout recovery in ax_xmit() is never reached, and mkiss_write_wakeup() cannot wake the queue because ax_close() cleared TTY_DO_WRITE_WAKEUP. The interface is up but does not transmit a single frame until the line discipline is detached and attached again.
Start the queue in ax_open_dev(), as network drivers do in ndo_open.
--- drivers/net/hamradio/mkiss.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/hamradio/mkiss.c +5 -0
@@ -589,6 +589,11 @@ static int ax_open_dev(struct net_device *dev)if (ax->tty ==NULL )return -ENODEV ; +/* ax_close() stopped the queue: restart it, or the interface +* never transmits again after it is set down and up. +*/ +netif_start_queue (dev); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 114/686 6pack: restart the transmit queue when the interface is opened
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
sp_close() stops the transmit queue, but sp_open_dev() never starts it again. After the interface is set down and up the queue stays stopped, sp_xmit() is never called again and sixpack_write_wakeup() cannot wake it because sp_close() cleared TTY_DO_WRITE_WAKEUP: the interface no longer transmits until the line discipline is detached and attached again.
Start the queue in sp_open_dev(), as mkiss now does.
--- drivers/net/hamradio/6pack.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/hamradio/6pack.c +6 -0
@@ -256,6 +256,12 @@ static int sp_open_dev(struct net_device *dev)if (sp->tty ==NULL )return -ENODEV ; + +/* sp_close() stopped the queue: restart it, or the interface +* never transmits again after it is set down and up. +*/ +netif_start_queue (dev); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 115/686 ax25: dont build a frame header from an uninitialised digipeater list
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
ax25_sendmsg() reads the digipeaters given with the destination only when the address is a full_sockaddr_ax25, but it then points dp at its local ax25_digi whenever sax25_ndigis is not zero. sax25_ndigis is part of the 16 byte struct sockaddr_ax25 as well, so a sendto() with that short address and a non-zero sax25_ndigis makes ax25_sendmsg() build the header from an ax25_digi that was never written: ax25_addr_size() and ax25_addr_build() use whatever ndigi and calls[] the stack holds.
On a datagram socket the frame then goes out with kernel stack bytes as digipeater calls, or skb_push() is asked for more than the headroom and the kernel stops in skb_under_panic(). Any local user who can bind an AX.25 socket can do it, and bind() is open to all with the default uid policy. Kernels built with CONFIG_INIT_STACK_ALL_ZERO hide it, ndigi is then 0.
Point dp at the local list only once the digipeaters have been read into it. A short address now sends without digipeaters, as connect() already does with the same address.
Tested on a QEMU bench (6.12.94 with KASAN, ax0 on mkiss, the frames recorded on the serial line): ten sendto() with a full address and 8 digipeaters, each followed by one with a 16 byte address and sax25_ndigis = 8, ax25 built with -ftrivial-auto-var-init=pattern as with CONFIG_INIT_STACK_ALL_PATTERN:
before: skb_under_panic (put:1793), kernel BUG on the first short one
after: 20 frames, the short ones without digipeaters, the full ones
with their 8 digipeaters, no KASAN report
With the zero init used by most distribution kernels, and on this bench without any init, the stack held 0 there and the short frames already went out without digipeaters before the change.
--- net/ax25/af_ax25.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/ax25/af_ax25.c +2 -5
@@ -1569,7 +1569,7 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)struct sock *sk = sock->sk;struct sockaddr_ax25 sax;struct sk_buff *skb; -ax25_digi dtmp, *dp; +ax25_digi dtmp, *dp =NULL ;ax25_cb *ax25;size_t size;int lv, err, addr_len = msg->msg_namelen;
@@ -1644,6 +1644,7 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) } dtmp.lastrepeat =0 ; + dp = &dtmp; } sax = *usax;
@@ -1652,10 +1653,6 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) err = -EISCONN ; goto out; } -if (usax->sax25_ndigis ==0 ) - dp =NULL ; -else - dp = &dtmp; }else {/* * FIXME: 1003.1g - if the socket is like this because
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 116/686 ax25: dont take a reference on a gone device in ax25_accept()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
A connection made on an incoming SABM waits on the listener's receive queue until accept(). If its device goes down meanwhile, ax25_kill_by_device() finds it on ax25_list, disconnects it and clears its ax25_dev. It drops no device reference, since the socket has not been grafted yet, but the skb stays on the listener's queue. The next accept() then reads ax25->ax25_dev and passes NULL->dev to netdev_hold():
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] RIP: 0010:ax25_accept+0x58f/0x7e0 [ax25]
A listener bound to a device is itself closed by ax25_kill_by_device(), so accept() returns -EINVAL unless it was already waiting and wakes up in between. A listener bound to no device, which any user can create, stays open, and the next accept() crashes every time.
ax25_accept() also grafts the socket and takes the device references without the lock of the new socket, while ax25_kill_by_device() decides under that lock, from sk->sk_socket, whether those references are there to drop.
Graft the socket and take the references under its lock, and take none when the device has already gone. accept() then returns the connection closed, as it is: getpeername() and recv() give -ENOTCONN, and close() frees it.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link). A listens on TESTA-9 bound to no device, B calls it, A removes ax0 by detaching the N_AX25 line discipline, then calls accept():
before: null-ptr-deref in ax25_accept(), kernel panic
after: accept() returns the socket, -ENOTCONN on it, ax25 refcount
back to its starting value once closed, no KASAN or lockdep report, five runs out of five
A plain accept() run before that case behaves the same before and after.
--- net/ax25/af_ax25.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
net/ax25/af_ax25.c +17 -4
@@ -1498,16 +1498,29 @@ static int ax25_accept(struct socket *sock, struct socket *newsock, goto out; newsk = skb->sk; + +/* +* ax25_kill_by_device() detaches a connection from a device going +* down under the lock of its socket, clears its ax25_dev and drops +* the device references if the socket has been grafted by then. +* Graft the socket and take those references under the same lock, +* and take none if the device has already gone: the connection is +* closed then, and the socket is returned as such. +*/ +lock_sock_nested (newsk,SINGLE_DEPTH_NESTING );sock_graft (newsk, newsock); + ax25 =sk_to_ax25 (newsk); + ax25_dev = ax25->ax25_dev; +if (ax25_dev) { +netdev_hold (ax25_dev->dev, &ax25->dev_tracker,GFP_ATOMIC ); +ax25_dev_hold (ax25_dev); + } +release_sock (newsk);/* Now attach up the new socket */ kfree_skb (skb);sk_acceptq_removed (sk); newsock->state =SS_CONNECTED ; - ax25 =sk_to_ax25 (newsk); - ax25_dev = ax25->ax25_dev; -netdev_hold (ax25_dev->dev, &ax25->dev_tracker,GFP_ATOMIC ); -ax25_dev_hold (ax25_dev); out:release_sock (sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 117/686 ax25: dont copy an uninitialised address to recvmsg()s caller
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When the caller asks for the sender's address, ax25_recvmsg() parses the AX.25 header behind the mac header of the frame and copies out the source and the digipeaters, without checking whether ax25_addr_parse() succeeded. ax25_addr_parse() fills neither src nor digi when the header is shorter than 14 bytes.
That is always the case for a message that ax25_rx_fragment() put back
together: the new skb has no address header and no mac header, so skb->data - mac - 1 is negative. ax25_recvmsg() then copies an uninitialised src, sets sax25_ndigis from an uninitialised digi.ndigi, and copies that many entries of digi.calls[] into fsa_digipeater[], reading past digi and writing past the caller's sockaddr_storage on the kernel stack. Any AX.25 peer can send segmented I frames (PID 0x08) to a SOCK_SEQPACKET socket whose owner reads them with recvfrom() or recvmsg() and an address.
Only use the parsed address when there is a mac header and ax25_addr_parse() succeeds, and give an empty AX.25 address otherwise.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link, PID 0x55, paclen 64 on the sender): B connects to A and sends 20 bytes, then 200 bytes that go as fragments; A reads both with recvfrom() and an address. ax25 built with -ftrivial-auto-var-init=pattern, as with CONFIG_INIT_STACK_ALL_PATTERN:
before: 20 bytes from TESTB-1, then
BUG: KASAN: stack-out-of-bounds in ax25_recvmsg
stack-protector: Kernel stack is corrupted in: __sys_recvfrom
after: 20 bytes from TESTB-1, then 200 bytes with an empty address,
no KASAN report, five runs out of fiveBuilt with the zero init used by most distribution kernels, the stack held 0 there and the second address already came back empty.
--- net/ax25/af_ax25.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-)
net/ax25/af_ax25.c +26 -15
@@ -1803,25 +1803,36 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,if (msg->msg_name) {ax25_digi digi;ax25_address src; -const unsigned char *mac =skb_mac_header (skb); +const unsigned char *mac; DECLARE_SOCKADDR(struct sockaddr_ax25 *, sax, msg->msg_name);memset (sax,0 ,sizeof (struct full_sockaddr_ax25 )); -ax25_addr_parse (mac +1 , skb->data - mac -1 , &src,NULL , - &digi,NULL ,NULL ); sax->sax25_family =AF_AX25 ; -/* We set this correctly, even though we may not let the -application know the digi calls further down (because it -did NOT ask to know them). This could get political... **/ - sax->sax25_ndigis = digi.ndigi; - sax->sax25_call = src; - -if (sax->sax25_ndigis !=0 ) { -int ct; -struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)sax; - -for (ct =0 ; ct < digi.ndigi; ct++) - fsa->fsa_digipeater[ct] = digi.calls[ct]; + +/* +* A frame put together from fragments by ax25_rx_fragment() +* has no address header left, and no mac header: give no +* address then. ax25_addr_parse() fills neither src nor digi +* when it fails. +*/ + mac =skb_mac_header_was_set (skb) ?skb_mac_header (skb) :NULL ; +if (mac &&ax25_addr_parse (mac +1 , skb->data - mac -1 , &src, +NULL , &digi,NULL ,NULL )) { +/* +* We set this correctly, even though we may not let the +* application know the digi calls further down (because +* it did NOT ask to know them). This could get political... +*/ + sax->sax25_ndigis = digi.ndigi; + sax->sax25_call = src; + +if (sax->sax25_ndigis !=0 ) { +int ct; +struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)sax; + +for (ct =0 ; ct < digi.ndigi; ct++) + fsa->fsa_digipeater[ct] = digi.calls[ct]; + } } msg->msg_namelen =sizeof (struct full_sockaddr_ax25 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 118/686 ax25: free the old digipeater path of a listed socket under ax25_list_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
ax25_connect() frees the digipeater path left by a previous connect() with only the socket lock held. A bound socket is on ax25_list, where __ax25_find_cb() on the receive path and ax25_info_show() for /proc/net/ax25 read ax25->digipeat under ax25_list_lock, without the socket lock. The path can thus be freed while one of them walks it.
Take the old path off the socket under ax25_list_lock before freeing it, and set the new destination and path under the same lock, so that a reader on the list never sees a freed path, nor a destination with the path of another one.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, ax0 on mkiss):
a bound SOCK_SEQPACKET socket calls an absent station via 8 digipeaters six times, each new non-blocking connect() freeing the path of the previous one, while a thread reads /proc/net/ax25 in a loop:
before: 18 reports such as
BUG: KASAN: slab-use-after-free in ax25_info_show
BUG: KASAN: slab-use-after-free in ax2asc
(90 with an mdelay(300) after the kfree())
after: no report, five runs out of five, and none with the mdelay--- net/ax25/af_ax25.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/ax25/af_ax25.c +12 -2
@@ -1247,7 +1247,7 @@ static int __must_check ax25_connect(struct socket *sock,struct sock *sk = sock->sk;ax25_cb *ax25 =sk_to_ax25 (sk), *ax25t;struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr; -ax25_digi *digi =NULL ; +ax25_digi *digi =NULL , *old_digi;int ct =0 , err =0 ;/*
@@ -1299,8 +1299,16 @@ static int __must_check ax25_connect(struct socket *sock, sk->sk_state =TCP_CLOSE ; sock->state =SS_UNCONNECTED ; -kfree (ax25->digipeat); +/* +* A bound socket is on ax25_list, where the receive path and +* /proc/net/ax25 read its digipeater path under ax25_list_lock: +* take the old path off under that lock before freeing it. +*/ +spin_lock_bh (&ax25_list_lock); + old_digi = ax25->digipeat; ax25->digipeat =NULL ; +spin_unlock_bh (&ax25_list_lock); +kfree (old_digi);/* * Handle digi-peaters to be used.
@@ -1360,8 +1368,10 @@ static int __must_check ax25_connect(struct socket *sock, goto out_release; } +spin_lock_bh (&ax25_list_lock); ax25->dest_addr = fsa->fsa_ax25.sax25_call; ax25->digipeat = digi; +spin_unlock_bh (&ax25_list_lock);/* First the easy one */ if (sk->sk_type !=SOCK_SEQPACKET ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 119/686 ax25: put an incoming connection on the listeners queue once it is set up
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
On a SABM for a listening socket, ax25_rcv() puts the skb on the listener's receive queue as soon as the new socket is made, then releases the listener and only afterwards fills in the connection:
addresses, digipeater path, modulus and window (read from the skb), UA, state 3, ax25_cb_add() and the timers.
accept() can take the socket in between. If its owner closes it at once, ax25_release() finds it in state 0 and frees it, and ax25_rcv() goes on writing to the freed control block, adds it to ax25_list and reads the freed skb.
Keep a place in the listener's backlog when the socket is made, and put the skb on its queue once the connection is complete. If the listener has been closed meanwhile, leave the connection to its heartbeat, as ax25_destroy_socket() does with the connections that were still waiting on its queue.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link). A listens on TESTA-9 and a thread calls accept() in a loop on the non-blocking socket, closing each socket it gets at once; B calls TESTA-9 five times:
before: BUG: KASAN: slab-use-after-free in ax25_rcv (write of 7
bytes), refcount_t: addition on 0, and a stale entry left in /proc/net/ax25, without any delay added
after: no report, ax25 refcount back to its starting value,
/proc/net/ax25 empty, five runs out of five
With an mdelay(300) after the listener is released in ax25_rcv() the results are the same. A third case closes the listener while ax25_rcv() is held just before queueing the skb: the connection is freed by its heartbeat, with no report and nothing left behind, three runs out of three.
--- net/ax25/ax25_in.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
net/ax25/ax25_in.c +24 -6
@@ -401,11 +401,12 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, } } -skb_set_owner_r (skb, make); -skb_queue_head (&sk->sk_receive_queue, skb); - - make->sk_state =TCP_ESTABLISHED ; - +/* +* Keep a place in the backlog, but put the skb on the +* listener's queue only once the connection is set up +* below: accept() takes it from there, and close() on the +* new socket frees the connection. +*/ sk_acceptq_added (sk);bh_unlock_sock (sk); }else {
@@ -488,8 +489,25 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,ax25_kick (ax25);if (sk) { -if (!sock_flag (sk,SOCK_DEAD )) +bh_lock_sock (sk); +skb_set_owner_r (skb, make); +if (sk->sk_state ==TCP_LISTEN && !sock_flag (sk,SOCK_DEAD )) { +skb_queue_head (&sk->sk_receive_queue, skb); sk->sk_data_ready (sk); + }else { +/* +* The listener was closed meanwhile: leave the +* connection to its heartbeat, as +* ax25_destroy_socket() does with the connections +* that were still waiting on its queue. +*/ +sk_acceptq_removed (sk); +kfree_skb (skb); +sock_orphan (make); + make->sk_state =TCP_LISTEN ; + ax25->state =AX25_STATE_0 ; + } +bh_unlock_sock (sk);sock_put (sk); }else { free:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 120/686 ax25: dont test the socket flags of a connection that has no socket
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When T1 runs out in state 2 (DISC sent, awaiting UA or DM), both ax25_std_t1timer_expiry() and ax25_ds_t1_timeout() call sock_flag(ax25->sk, SOCK_DESTROY) without checking ax25->sk. The connections that ROSE, NET/ROM, IP in VC mode and incoming calls to the port callsign make in the kernel have no socket, and reach state 2 when their idle timer sends DISC. If the peer does not answer N2 times before the heartbeat removes the connection, the timer dereferences a NULL socket:
BUG: KASAN: null-ptr-deref in ax25_std_t1timer_expiry+0x3d9/0x4f0 Oops: general protection fault ... RIP: ax25_std_t1timer_expiry
With the default idle_timeout of 0 this cannot happen. With an idle timeout set, it takes a short T1 and a small N2 on the standard path, but on a DAMA slave ax25_ds_t1_timeout() runs on every poll.
A connection with no socket has nothing to destroy afterwards: test the flag only when there is a socket, as ax25_disconnect() does.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link). A sets idle_timeout 1000 ms, t1_timeout 100 ms and N2 1, with no listener; B calls NODEA-0, so A's kernel answers with a connection without socket, then B removes its ax0 and stays silent:
before: null-ptr-deref in ax25_std_t1timer_expiry(), oops
after: the connection is disconnected and freed by its heartbeat,
ax25 refcount back to its starting value, /proc/net/ax25 empty, no report, five runs out of five
The DAMA path was not run on the bench.
--- net/ax25/ax25_ds_timer.c | 2 +- net/ax25/ax25_std_timer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ax25/ax25_ds_timer.c +1 -1
@@ -211,7 +211,7 @@ void ax25_ds_t1_timeout(ax25_cb *ax25)case AX25_STATE_2 :if (ax25->n2count == ax25->n2) {ax25_send_control (ax25,AX25_DISC ,AX25_POLLON ,AX25_COMMAND ); -if (!sock_flag (ax25->sk,SOCK_DESTROY )) +if (!ax25->sk || !sock_flag (ax25->sk,SOCK_DESTROY ))ax25_disconnect (ax25,ETIMEDOUT );return ; }else {
net/ax25/ax25_std_timer.c +1 -1
@@ -143,7 +143,7 @@ void ax25_std_t1timer_expiry(ax25_cb *ax25)case AX25_STATE_2 :if (ax25->n2count == ax25->n2) {ax25_send_control (ax25,AX25_DISC ,AX25_POLLON ,AX25_COMMAND ); -if (!sock_flag (ax25->sk,SOCK_DESTROY )) +if (!ax25->sk || !sock_flag (ax25->sk,SOCK_DESTROY ))ax25_disconnect (ax25,ETIMEDOUT );return ; }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 121/686 ax25: free the copy of an IP packet that ax25_send_frame() turned down
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
In virtual circuit mode, ax25_ip_xmit() copies the IP packet, charges the copy to the sending socket, frees the original and hands the copy to ax25_send_frame(). When ax25_send_frame() gives up, because the device is going down or the connection cannot be allocated, it returns NULL and leaves the skb to its caller, as ROSE and NET/ROM expect. ax25_ip_xmit() only handles the non-NULL case, so the copy is lost, together with the send buffer space it holds on the socket.
Free it when ax25_send_frame() returns NULL.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, ax0 on mkiss with IP 44.0.0.1, static ARP entries to DEST-1 and DEST-2, ip_default_mode 1). The ax25 module of the bench has a parameter that makes ax25_create_cb() fail, as on an allocation failure. A UDP socket sends 300 datagrams to the station behind DEST-2 with that parameter set, and its send queue (SIOCOUTQ) is read 4 s later:
before: 222 datagrams accepted, then the send buffer is full;
213120 bytes left in the send queue for good
after: 300 datagrams accepted, send queue back to 0, five runs out
of five
A control run to DEST-1 without the failure, where the connection times out, empties the queue in both cases.
--- net/ax25/ax25_ip.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/ax25/ax25_ip.c +7 -2
@@ -176,9 +176,14 @@ netdev_tx_t ax25_ip_xmit(struct sk_buff *skb) ax25_dev->values[AX25_VALUES_PACLEN ], &src_c, &dst_c, digipeat, dev); -if (ax25) { +/* +* ax25_send_frame() leaves the skb to its caller +* when it gives up, as ROSE and NET/ROM expect. +*/ +if (ax25)ax25_cb_put (ax25); - } +else +kfree_skb (ourskb); goto put; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 122/686 ax25: dont leave half a message on a connection when fragmenting fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
ax25_output() puts each fragment on the write queue as soon as it is built. If one allocation fails half way, it returns at once: the fragments already queued go out and the peer gets the beginning of a message whose end never comes, and the rest of the original skb is never freed. That skb is charged to the sending socket, so sk_has_allocations() stays true, ax25_destroy_timer() re-arms itself every two seconds for good, and the socket, with its reference on the ax25 module, is never freed.
Build the fragments on a list of our own, free that list and the original skb if an allocation fails, and splice the fragments onto the write queue once the message is complete. Two senders on the same connection, as with several ROSE or NET/ROM circuits, also no longer interleave the fragments of their messages.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link, PID 0x55, paclen 64 on the sender). The ax25 module of the bench has a parameter that makes the allocation of a given fragment fail. B sends 20 bytes, then 200 bytes in four fragments with the third one failing, then 30 bytes, closes the socket and waits 30 s:
before: ax25 refcount left one above its value before the socket,
the socket is never freed
after: ax25 refcount back to its value before the socket, five
runs out of five
A receives the 20 and 30 byte messages in both cases. Without the failure, the 200 byte message is put back together whole by A before and after the change.
--- net/ax25/ax25_out.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
net/ax25/ax25_out.c +16 -1
@@ -137,7 +137,9 @@ EXPORT_SYMBOL(ax25_send_frame);*/ void ax25_output (ax25_cb *ax25,int paclen,struct sk_buff *skb) { +struct sk_buff_head frags;struct sk_buff *skbn; +unsigned long flags;unsigned char *p;int frontlen, len, fragno, ka9qfrag, first =1 ;
@@ -161,11 +163,20 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb) frontlen =skb_headroom (skb);/* Address space + CTRL */ +/* +* Build the fragments on a list of our own: a message that +* cannot be fragmented whole is not sent at all, and its +* fragments go on the write queue one after the other. +*/ +__skb_queue_head_init (&frags); +while (skb->len >0 ) {spin_lock_bh (&ax25_frag_lock);if ((skbn =alloc_skb (paclen +2 + frontlen,GFP_ATOMIC )) ==NULL ) {spin_unlock_bh (&ax25_frag_lock);printk (KERN_CRIT "AX.25: ax25_output - out of memory\n" ); +__skb_queue_purge (&frags); +kfree_skb (skb);return ; }
@@ -200,10 +211,14 @@ void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb) }skb_pull (skb, len); -skb_queue_tail (&ax25->write_queue, skbn);/* Throw it on the queue */ +__skb_queue_tail (&frags, skbn); }kfree_skb (skb); + +spin_lock_irqsave (&ax25->write_queue.lock, flags); +skb_queue_splice_tail_init (&frags, &ax25->write_queue); +spin_unlock_irqrestore (&ax25->write_queue.lock, flags); }else {skb_queue_tail (&ax25->write_queue, skb);/* Throw it on the queue */ }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 123/686 ax25: make 16 the smallest maximum_packet_length of a port
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
The per-port maximum_packet_length sysctl accepts values from 1, while ax25_output() refuses a paclen below 16 with a WARN_ON_ONCE() and drops the frame. A port set below 16 thus loses every frame sent with the port's paclen: IP in virtual circuit mode, and connections whose socket kept the default. AX25_PACLEN in setsockopt() and the SIOCAX25CTLCON ioctl already refuse values below 16.
Raise the lower bound of the sysctl to 16.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, ax0 on mkiss, IP in virtual circuit mode to a static ARP entry):
before: writing 10 is accepted, and the IP datagrams then sent give
WARNING at ax25_output+0x6d4 and are dropped
after: writing 10 gives -EINVAL and the value stays 256, writing 16
is accepted, and no warning
--- net/ax25/sysctl_net_ax25.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ax25/sysctl_net_ax25.c +1 -1
@@ -20,7 +20,7 @@ static int min_t2[] = {1}, max_t2[] = {20000};static int min_t3[1 ], max_t3[] = {3600000 };static int min_idle[1 ], max_idle[] = {65535000 };static int min_n2[] = {1 }, max_n2[] = {31 }; -static int min_paclen[] = {1 }, max_paclen[] = {512 }; +static int min_paclen[] = {16 }, max_paclen[] = {512 };static int min_proto[1 ], max_proto[] = {AX25_PROTO_MAX };#ifdef CONFIG_AX25_DAMA_SLAVE static int min_ds_timeout[1 ], max_ds_timeout[] = {65535000 };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 124/686 ax25: keep the window below 8 when a socket goes back to modulo 8
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
AX25_WINDOW accepts 1 to 63 on a socket in extended mode, but AX25_EXTSEQ set back to 0 leaves the window as it was. With modulo 8, ax25_kick() computes the end of the window as (V(A) + window) % 8: a window of 8, 16, ... 56 gives V(A) itself, the window looks full, and the connection never sends an I frame. Other values wrap round to a smaller window.
Bring the window down to 7 when AX25_EXTSEQ selects modulo 8.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link). B sets AX25_EXTSEQ 1, AX25_WINDOW 16, AX25_EXTSEQ 0, calls A with a SABM and sends 5 messages:
before: window read back 16, A receives none of the 5 messages
after: window read back 7, A receives the 5 messages
--- net/ax25/af_ax25.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ax25/af_ax25.c +6 -0
@@ -708,6 +708,12 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,case AX25_EXTSEQ : ax25->modulus = opt ?AX25_EMODULUS :AX25_MODULUS ; +/* +* A window set for modulo 128 may not fit modulo 8: +* ax25_kick() would then find it full and send nothing. +*/ +if (ax25->modulus ==AX25_MODULUS && ax25->window >7 ) + ax25->window =7 ;break ;case AX25_PIDINCL :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 125/686 ax25: let a socket connect again after a failed or ended connection
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When a connection fails or ends, ax25_disconnect() sets SOCK_DEAD on the socket and shuts it down for sending, although the socket is still open and its owner may call connect() again. ax25_connect() resets the socket states but leaves both:
- the new attempt changes the state under SOCK_DEAD, and both ax25_disconnect() and the UA handling in state 1 skip sk_state_change() on a SOCK_DEAD socket: a blocking connect() is never woken up, whether the new link comes up or fails, and returns only on a signal;
- once connected, every send() fails with -EPIPE, since sendmsg() tests SEND_SHUTDOWN first.
Clear SOCK_DEAD and sk_shutdown when connect() starts a new attempt.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link). A listens on TESTA-9. B calls TESTA-8, where nobody listens, then calls TESTA-9 with the same socket, a 20 s alarm set, and sends a message:
before: the second connect() returns only when the alarm fires
20 s later, send() fails with -EPIPE, A receives nothing
after: the second connect() returns at once, send() succeeds and
A receives the message
Applications that open a new socket for each call are not affected.
--- net/ax25/af_ax25.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/ax25/af_ax25.c +9 -0
@@ -1302,6 +1302,15 @@ static int __must_check ax25_connect(struct socket *sock, goto out_release; } +/* +* A connection that failed or ended through ax25_disconnect() left +* the socket SOCK_DEAD and shut down for sending. The socket is still +* its owner's: start afresh, or the state changes of the new attempt +* would wake no one and every send() would fail with -EPIPE. +*/ +sock_reset_flag (sk,SOCK_DEAD ); + sk->sk_shutdown =0 ; + sk->sk_state =TCP_CLOSE ; sock->state =SS_UNCONNECTED ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 126/686 ax25: dont let connect() find its own socket when calling the same station
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
Before it starts a link, ax25_connect() looks on ax25_list for an existing connection with the same source, destination, digipeater path and device, and returns -EADDRINUSE if there is one. A bound socket is on that list itself, with the destination of its previous attempt, and its digipeater path was just freed. When a connect() failed or the connection ended, a new connect() to the same station without digipeaters thus finds the socket itself, and fails with -EADDRINUSE every time.
Forget the previous destination before the lookup, under ax25_list_lock, where the list readers compare it.
Tested on a QEMU bench (6.12.94 with KASAN and lockdep, two guests over a KISS serial link). A starts listening on TESTA-9 after 7 s. B calls TESTA-9 with one socket before that, which times out, then calls TESTA-9 again with the same socket, non-blocking, and checks 3 s later:
before: -EADDRINUSE on the second call and on the check, A accepts
nothing
after: -EINPROGRESS, then the check returns 0 and A accepts the
connection, three runs out of three
send() on the new connection still fails with -EPIPE unless "ax25: let a socket connect again after a failed or ended connection" is applied as well; with both, and with "ax25: free the old digipeater path of a listed socket under ax25_list_lock", A receives the message.
--- net/ax25/af_ax25.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/ax25/af_ax25.c +9 -0
@@ -1374,6 +1374,15 @@ static int __must_check ax25_connect(struct socket *sock, goto out_release; } +/* +* The socket is on ax25_list with the destination of its previous +* attempt, if any: forget it, or the lookup below finds the socket +* itself when the same station is called again. +*/ +spin_lock_bh (&ax25_list_lock); + ax25->dest_addr = null_ax25_address; +spin_unlock_bh (&ax25_list_lock); +if (sk->sk_type ==SOCK_SEQPACKET && (ax25t=ax25_find_cb (&ax25->source_addr, &fsa->fsa_ax25.sax25_call, digi, ax25->ax25_dev->dev))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 127/686 netrom: dont convert the maximum number of tries to jiffies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_create() sets the number of transport retries of a new socket with
nr->n2 = msecs_to_jiffies(sysctl_netrom_transport_maximum_tries);
but transport_maximum_tries is a count, not a time in milliseconds. The result depends on HZ: with the default of 3 tries, n2 is 3 with HZ=1000 but 1 with HZ=250 or HZ=100, below the minimum of 2 that the sysctl itself enforces. Sockets accepted on a listener copy its n2, so every NET/ROM circuit of such a kernel gives up after a single retry.
Seen on our nodes in /proc/net/nr: n2 is 01 on the Raspberry Pi kernels (HZ=250 and HZ=100) and 03 on the x86 ones (HZ=1000), all with transport_maximum_tries set to 3.
Use the count as is. The other transport values are times and keep their conversion.
--- net/netrom/af_netrom.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/netrom/af_netrom.c +1 -2
@@ -459,8 +459,7 @@ static int nr_create(struct net *net, struct socket *sock, int protocol,msecs_to_jiffies (READ_ONCE (sysctl_netrom_transport_timeout)); nr->t2 =msecs_to_jiffies (READ_ONCE (sysctl_netrom_transport_acknowledge_delay)); - nr->n2 = -msecs_to_jiffies (READ_ONCE (sysctl_netrom_transport_maximum_tries)); + nr->n2 =READ_ONCE (sysctl_netrom_transport_maximum_tries); nr->t4 =msecs_to_jiffies (READ_ONCE (sysctl_netrom_transport_busy_delay)); nr->idle =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 128/686 netrom: dont leak frames in nr_route_frame()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_route_frame() leaks a frame in two cases.
When the frame comes from AX.25 and nr_add_node() fails, it returns the error. AX.25 calls it as a protocol function and takes any non-zero value as "frame consumed", so the frame is never freed. nr_add_node() fails with -EINVAL when the source of the frame is one of our own NET/ROM callsigns, which is what a node sees when its own frames come back through a routing loop, and with -ENOMEM.
When the frame is forwarded, it is sent from a copy, nskb. If ax25_send_frame() returns NULL (device going down, no memory), it has not taken the copy, and nr_route_frame() only frees the original.
Return 0 when nr_add_node() fails, so that AX.25 frees the frame, and free the copy when ax25_send_frame() returns NULL.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A opens an AX.25 link to the NET/ROM callsign of B and sends 400 NET/ROM frames with A's callsign as source, then 400 with B's own callsign as source. Live skbs on B (skbuff_head_cache objects, KASAN quarantine shrunk), 20 s after the last frame:
normal source B's own callsign
before the fix 12 412
after the fix 12 12
No kernel report in either run. The second leak (ax25_send_frame() returning NULL) was checked by reading only.
--- net/netrom/nr_route.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
net/netrom/nr_route.c +16 -5
@@ -774,11 +774,16 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25) nr_dest = (ax25_address *)(skb->data +7 );if (ax25 !=NULL ) { - ret =nr_add_node (nr_src,"" , &ax25->dest_addr, ax25->digipeat, - ax25->ax25_dev->dev,0 , -READ_ONCE (sysctl_netrom_obsolescence_count_initialiser)); -if (ret) -return ret; +/* +* A frame that cannot be noted here (it claims to come from +* one of our own callsigns, or memory is short) is dropped. +* Return 0, not the error: AX.25 takes any other value as +* "frame consumed" and would never free it. +*/ +if (nr_add_node (nr_src,"" , &ax25->dest_addr, ax25->digipeat, + ax25->ax25_dev->dev,0 , +READ_ONCE (sysctl_netrom_obsolescence_count_initialiser))) +return 0 ; }if ((dev =nr_dev_get (nr_dest)) !=NULL ) {/* Its for me */
@@ -848,8 +853,14 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)spin_unlock_bh (&nr_route_lock);nr_node_put (nr_node); +/* +* ax25_send_frame() only returns NULL before taking the frame: +* free our copy then; the caller frees the original. +*/ if (ret)kfree_skb (oskb); +else +kfree_skb (skb);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 129/686 netrom: use the more flag of each frame taken from the resequencing queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_state3_machine() puts every received INFO frame on reseq_queue and then delivers, in sequence order, the frames found there. Each of them is passed to nr_queue_rx_frame() with the more flag of the frame just received, not with its own.
When frames arrive out of order, the frames taken from the queue are not the one just received, and the boundaries of the messages are
wrong: the last fragment of a message can be held as if more followed, so the message is joined to the next one, or a first fragment is delivered as a whole message.
Take the more flag from the frame being delivered.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A sends to a NET/ROM socket on B the second fragment of a message, then its first fragment, then a one-frame message.
before: one message of 120 bytes read (both messages joined)
after: two messages of 80 and 40 bytes read
No kernel report in either run.
--- net/netrom/nr_in.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netrom/nr_in.c +4 -2
@@ -176,7 +176,7 @@ static int nr_state3_machine(struct sock *sk, struct sk_buff *skb, int frametypestruct sk_buff *skbn;unsigned short save_vr;unsigned short nr, ns; -int queued =0 ; +int queued =0 , more; nr = skb->data[18 ];
@@ -258,7 +258,9 @@ static int nr_state3_machine(struct sock *sk, struct sk_buff *skb, int frametypewhile ((skbn =skb_dequeue (&nrom->reseq_queue)) !=NULL ) { ns = skbn->data[17 ];if (ns == nrom->vr) { -if (nr_queue_rx_frame (sk, skbn, frametype &NR_MORE_FLAG ) ==0 ) { +/* The flags of this frame, not of the one just received */ + more = skbn->data[19 ] &NR_MORE_FLAG ; +if (nr_queue_rx_frame (sk, skbn, more) ==0 ) { nrom->vr = (nrom->vr +1 ) %NR_MODULUS ; }else { nrom->condition |=NR_COND_OWN_RX_BUSY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 130/686 netrom: give a frame back intact when it cannot be delivered
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When nr_queue_rx_frame() cannot deliver a frame, it returns 1 and nr_state3_machine() keeps the frame on reseq_queue, sets NR_COND_OWN_RX_BUSY, and tries again later. But the frame given back is not the frame it was given:
- the NET/ROM headers have already been pulled, so the frame is read again later with a wrong N(S), and delivered without its first 20 bytes if that byte happens to match;
- for the last fragment of a message, the frame has been put on frag_queue and freed while building the whole message: the caller then queues a freed skb (use-after-free), or, when the allocation of the whole message fails, an skb that is still on frag_queue.
This happens whenever the receive buffer is full, i.e. as soon as the application reads more slowly than the peer sends.
Make nr_queue_rx_frame() all or nothing: build the whole message from copies, leaving the fragments on frag_queue, and only free them once it is queued. If the message cannot be queued, or allocated, free what was built, push the headers back and return 1: the frame is given back as it came and the earlier fragments are still there.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS. A sends NET/ROM frames over a raw AX.25 link to a listening NET/ROM socket on B, whose receive buffer is set to the minimum and which only starts reading after 15 s: 10 messages of 2 fragments of 200 bytes, then the next frame again every 6 s, as a peer retransmitting would.
before: KASAN slab-use-after-free in skb_queue_tail() called from
nr_process_rx_frame(), then a general protection fault in nr_process_rx_frame() and a kernel panic; 2 messages read
after: 11 messages of 400, ..., 400, 40 bytes read, in order and
intact, no kernel report
--- net/netrom/nr_in.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)
net/netrom/nr_in.c +28 -10
@@ -67,26 +67,44 @@ static int nr_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)return 0 ; } -if (!more && nr->fraglen >0 ) {/* End of fragment */ - nr->fraglen += skb->len; -skb_queue_tail (&nr->frag_queue, skb); - -if ((skbn =alloc_skb (nr->fraglen,GFP_ATOMIC )) ==NULL ) -return 1 ; +if (nr->fraglen >0 ) {/* End of fragment */ + skbn =alloc_skb (nr->fraglen + skb->len,GFP_ATOMIC ); +if (!skbn) + goto busy;skb_reset_transport_header (skbn); -while ((skbo =skb_dequeue (&nr->frag_queue)) !=NULL ) { + skb_queue_walk(&nr->frag_queue, skbo)skb_copy_from_linear_data (skbo,skb_put (skbn, skbo->len), skbo->len); -kfree_skb (skbo); - } +skb_copy_from_linear_data (skb,skb_put (skbn, skb->len), + skb->len); + } + +if (sock_queue_rcv_skb (sk, skbn) !=0 ) { +if (skbn != skb) +kfree_skb (skbn); + goto busy; + } +if (skbn != skb) { +/* The whole message is delivered: drop its pieces */ +skb_queue_purge (&nr->frag_queue); nr->fraglen =0 ; +kfree_skb (skb); } -return sock_queue_rcv_skb (sk, skbn); +return 0 ; + +busy: +/* +* Not delivered: give the frame back as it came, headers included, +* and leave the earlier fragments where they are, so that the +* caller can keep it on reseq_queue and deliver it later. +*/ +skb_push (skb,NR_NETWORK_LEN +NR_TRANSPORT_LEN ); +return 1 ; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 131/686 netrom: dont give the same circuit ID to two sockets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_connect() and nr_rx_frame() pick a circuit ID with nr_find_next_circuit(), which looks for an ID that no socket on nr_list uses, and then store it in the socket and advance the global circuit counter. The search and the assignment are not done under one lock, and in nr_rx_frame() the new socket only goes on nr_list at the end. Two sockets doing it at the same time can get the same ID.
The far end then answers both circuits with the same ID: the CONNACK of one goes to the socket found first, the other connect() never completes, and the frames of the two circuits are mixed up.
Pick the ID and give it to the socket under nr_list_lock, with the socket already on nr_list: nr_connect() runs once the socket is bound, and nr_rx_frame() now puts the new socket on nr_list under the same lock. The global counter is then also only changed under that lock. nr_list_lock is still not taken under a socket lock.
This is the same fix as rose_assign_lci() for ROSE.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A starts eight connect() calls at the same time to a listening socket on B, bound and unbound sockets alternately, six rounds, and looks for duplicate circuit IDs in /proc/net/nr. The "slow" runs add mdelay(2) between the choice of the ID and its assignment, to widen the window.
connected duplicate pairs rounds with duplicates
before, slow 25/48 37 6/6 after, slow 48/48 0 0/6 before 48/48 0 0/6 after 48/48 0 0/6
No kernel report in any run, and no lockdep report for the new nr_list_lock taken in nr_rx_frame().
--- net/netrom/af_netrom.c | 55 ++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-)
net/netrom/af_netrom.c +32 -23
@@ -208,29 +208,40 @@ static struct sock *nr_find_peer(unsigned char index, unsigned char id, }/* -* Find next free circuit ID. +* Give a socket the next free circuit ID. The search and the assignment +* are done under nr_list_lock, which the caller holds, with the socket +* already on nr_list: two sockets cannot pick the same ID. */ -static unsigned short nr_find_next_circuit (void ) +static void nr_assign_circuit (struct nr_sock *nr) {unsigned short id = circuit;unsigned char i, j; -struct sock *sk; +struct sock *s; +bool used; + +lockdep_assert_held (&nr_list_lock);for (;;) { i = id /256 ; j = id %256 ;if (i !=0 && j !=0 ) { - sk =nr_find_socket (i, j,NULL ); -if (!sk) + used = false; +sk_for_each (s, &nr_list) +if (nr_sk (s)->my_index == i &&nr_sk (s)->my_id == j) { + used = true; +break ; + } +if (!used)break ; -sock_put (sk); } id++; } -return id; + nr->my_index = i; + nr->my_id = j; + circuit = id +1 ; }/*
@@ -709,14 +720,10 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr, nr->dest_addr = addr->sax25_call; -release_sock (sk); - circuit =nr_find_next_circuit (); -lock_sock (sk); - - nr->my_index = circuit /256 ; - nr->my_id = circuit %256 ; - - circuit++; +/* The socket is on nr_list now, so others see the ID it gets */ +spin_lock_bh (&nr_list_lock); +nr_assign_circuit (nr); +spin_unlock_bh (&nr_list_lock);/* Move to connecting socket, start sending Connect Requests */ sock->state =SS_CONNECTING ;
@@ -1013,15 +1020,19 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev) nr_make->your_index = circuit_index; nr_make->your_id = circuit_id; +/* +* Put the new socket on nr_list as it gets its circuit ID, under the +* same lock, so that no other socket can be given the same ID. +* nr_list_lock is not taken under a socket lock (nr_info_show() takes +* them the other way round). +*/ bh_unlock_sock (sk); - circuit =nr_find_next_circuit (); +spin_lock_bh (&nr_list_lock); +nr_assign_circuit (nr_make); +sk_add_node (make, &nr_list); +spin_unlock_bh (&nr_list_lock);bh_lock_sock (sk); - nr_make->my_index = circuit /256 ; - nr_make->my_id = circuit %256 ; - - circuit++; -/* Window negotiation */ if (window < nr_make->window) nr_make->window = window;
@@ -1056,8 +1067,6 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)bh_unlock_sock (sk);sock_put (sk); -nr_insert_socket (make); -nr_start_heartbeat (make);nr_start_idletimer (make);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 132/686 netrom: return the peer node in the address given by recvmsg()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_recvmsg() fills the source address with the 7 bytes found at offset 7 of the frame, where the destination of the NET/ROM network header once was. But nr_queue_rx_frame() pulls the network and transport headers before queueing the frame, so these bytes are user data, and for a message shorter than 14 bytes they are read past its end: the caller gets a few bytes of kernel memory as a callsign.
Give the node at the other end of the circuit, nr->dest_addr, which is also what getpeername() returns with the user callsign.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A sends "hello" (5 bytes) then a message of 30 'q' to a NET/ROM socket on B, which reads them with recvfrom().
before: address bytes 16 eb 70 19 f7 91 5d (past the 5 bytes of
data), then 71 71 71 71 71 71 71 ('q' of the message)after: TESTA-1 for both messages
No kernel report in either run.
--- net/netrom/af_netrom.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netrom/af_netrom.c +5 -2
@@ -1225,10 +1225,13 @@ static int nr_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, }if (sax !=NULL ) { +/* +* The NET/ROM headers were pulled when the frame was queued: +* give the node at the other end of the circuit. +*/ memset (sax,0 ,sizeof (*sax)); sax->sax25_family =AF_NETROM ; -skb_copy_from_linear_data_offset (skb,7 , sax->sax25_call.ax25_call, -AX25_ADDR_LEN ); + sax->sax25_call =nr_sk (sk)->dest_addr; msg->msg_namelen =sizeof (*sax); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 133/686 netrom: keep the selected route when a route of a node is removed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
A node has up to three routes, best first, and which selects the one in
use: nr_link_failed() moves it to the next route when the link to a neighbour fails, and which >= count means that no route is left.
nr_dec_obs(), nr_del_node() and nr_rt_device_down() remove a route by moving the routes after it up, but leave which alone. When the removed route was before the selected one, which now selects the route after it, or nothing at all: a node still reachable through its last route is then dropped by nr_route_frame() as unreachable, until a NODES broadcast happens to reset which.
nr_dec_obs() also moves on to the next index after removing a route, so the route that has just moved up into that slot is skipped and its obsolescence count is not decremented in this round.
Remove a route in one helper that moves the routes up and decrements which when the removed route was before the selected one; if it was the selected route, which now selects the next one, as after a link failure. In the loops, only move on when the route stays.
Tested in a QEMU guest (6.12.94, KASAN, lockdep) whose KISS port leads nowhere, so that every AX.25 link fails, with link_fails_count 1:
- node X through N1 (quality 200, obsolescence 1) and N2 (100, 6); a connect() to X makes the link to N1 fail and which select N2 (w 2 in /proc/net/nr_nodes); then SIOCNRDECOBS:
before: "w 2 n 1", obsolescence of N2 still 6; a new connect() to X
makes no attempt at all
after: "w 1 n 1", obsolescence 5; a new connect() opens a link to N2
- node Y through M1 (obsolescence 1) and M2 (2); after one SIOCNRDECOBS:
before: M2 still at 2
after: M2 at 1
No kernel report in either run.
--- net/netrom/nr_route.c | 71 ++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 42 deletions(-)
net/netrom/nr_route.c +29 -42
@@ -344,6 +344,24 @@ static void nr_remove_neigh_locked(struct nr_neigh *nr_neigh)nr_neigh_put (nr_neigh); } +/* +* Remove route i of a node: move the routes after it up, and keep which on +* the route it selected. If that route is the one removed, which now +* selects the next one, as after a link failure. The caller drops the +* route's use of its neighbour. Called with nr_route_lock held. +*/ +static void nr_node_remove_route_locked (struct nr_node *nr_node,int i) +{ +lockdep_assert_held (&nr_route_lock); + +if (i < nr_node->which) + nr_node->which--; + + nr_node->count--; +for (; i < nr_node->count; i++) + nr_node->routes[i] = nr_node->routes[i +1 ]; +} +/* * "Delete" a node. Strictly speaking remove a route to a node. The node * is only deleted if no routes are left to it.
@@ -373,22 +391,10 @@ static int nr_del_node(ax25_address *callsign, ax25_address *neighbour, struct nnr_neigh_route_put_locked (nr_neigh);nr_neigh_put (nr_neigh); - nr_node->count--; +nr_node_remove_route_locked (nr_node, i); -if (nr_node->count ==0 ) { +if (nr_node->count ==0 )nr_remove_node_locked (nr_node); - }else { -switch (i) { -case 0 : - nr_node->routes[0 ] = nr_node->routes[1 ]; - fallthrough; -case 1 : - nr_node->routes[1 ] = nr_node->routes[2 ]; - fallthrough; -case 2 : -break ; - } - }/* Drop the reference taken by __nr_node_get() */ nr_node_put (nr_node); ret =0 ;
@@ -472,34 +478,24 @@ static int nr_dec_obs(void)spin_lock_bh (&nr_route_lock);nr_node_for_each_safe (s, nodet, &nr_node_list) { -for (i =0 ; i < s->count; i++) { +/* i only moves on when route i stays: the next one moves up */ +for (i =0 ; i < s->count; ) {switch (s->routes[i].obs_count) {case 0 :/* A locked entry */ + i++;break ;case 1 :/* From 1 -> 0 */ nr_neigh = s->routes[i].neighbour;nr_neigh_route_put_locked (nr_neigh); - - s->count--; - -switch (i) { -case 0 : - s->routes[0 ] = s->routes[1 ]; - fallthrough; -case 1 : - s->routes[1 ] = s->routes[2 ]; -break ; -case 2 : -break ; - } +nr_node_remove_route_locked (s, i);break ;default : s->routes[i].obs_count--; + i++;break ; - } }
@@ -525,23 +521,14 @@ void nr_rt_device_down(struct net_device *dev)nr_neigh_for_each_safe (s, nodet, &nr_neigh_list) {if (s->dev == dev) {nr_node_for_each_safe (t, node2t, &nr_node_list) { -for (i =0 ; i < t->count; i++) { +for (i =0 ; i < t->count; ) {if (t->routes[i].neighbour == s) { s->count--;nr_neigh_put (s); - t->count--; - -switch (i) { -case 0 : - t->routes[0 ] = t->routes[1 ]; - fallthrough; -case 1 : - t->routes[1 ] = t->routes[2 ]; -break ; -case 2 : -break ; - } +nr_node_remove_route_locked (t, i); + }else { + i++; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 134/686 netrom: drop a frame received with a TTL of 0
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_route_frame() drops a frame to forward when its time to live is 1, then decrements the TTL of the copy it sends on. A frame that arrives with a TTL of 0 passes the test and leaves with a TTL of 255: in a routing loop it can then go round up to 255 more times instead of dying.
Drop frames with a TTL of 0 as well.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A sends B three NET/ROM frames for nodes that B routes through neighbour TESTC, with TTL 0, 1 and 2, and listens as TESTC to see what B sends on.
before: TTL 0 sent on with TTL 255, TTL 1 dropped, TTL 2 sent on with 1
after: TTL 0 dropped, TTL 1 dropped, TTL 2 sent on with 1
No kernel report in either run.
--- net/netrom/nr_route.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/netrom/nr_route.c +5 -3
@@ -785,10 +785,12 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)if (!READ_ONCE (sysctl_netrom_routing_control) && ax25 !=NULL )return 0 ; -/* Its Time-To-Live has expired */ -if (skb->data[14 ] ==1 ) { +/* +* Its Time-To-Live has expired. A frame received with a TTL of 0 +* has expired too: decremented below, it would leave with 255. +*/ +if (skb->data[14 ] <=1 )return 0 ; - } nr_node =nr_node_get (nr_dest);if (nr_node ==NULL )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 135/686 netrom: check the window size given by the peer
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
The window size of a circuit is negotiated in its CONNREQ and CONNACK. On a CONNREQ received, nr_rx_frame() keeps the smaller of ours and the peer's; on a CONNACK, nr_state1_machine() takes the peer's as is.
So a window of 0 from the peer, in either frame, becomes the window of the circuit, and nr_kick() then never sends anything: the circuit is established but stuck. And a CONNACK can raise the window above the one we asked for, even above NR_MAX_WINDOW_SIZE.
Negotiate both in one helper: take a window of 0 as 1 and keep the smaller of ours and the peer's.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS. A speaks NET/ROM itself over a raw AX.25 link and answers B's calls; after each circuit is up, B sends two messages and A counts the INFO frames (A does not acknowledge them):
before after CONNREQ with window 0 wnd 0, 0 frame sent wnd 1, 1 frame sent CONNACK with window 0 wnd 0, 0 frame sent wnd 1, 1 frame sent CONNACK with window 200 wnd 200, 2 frames wnd 4 (ours), 2 frames
No kernel report in either run.
--- include/net/netrom.h | 13 +++++++++++++ net/netrom/af_netrom.c | 3 +-- net/netrom/nr_in.c | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-)
include/net/netrom.h +13 -0
@@ -87,6 +87,19 @@ struct nr_sock {#define nr_sk (sk) ((struct nr_sock *)(sk)) +/* +* Window negotiation, for a CONNREQ received or a CONNACK: use the smaller +* of our window and the peer's. A window of 0 would never let a frame +* out: take it as 1. +*/ +static inline void nr_negotiate_window (struct nr_sock *nr,unsigned char window) +{ +if (window ==0 ) + window =1 ; +if (window < nr->window) + nr->window = window; +} +struct nr_neigh {struct hlist_node neigh_node;ax25_address callsign;
net/netrom/af_netrom.c +1 -2
@@ -1034,8 +1034,7 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)bh_lock_sock (sk);/* Window negotiation */ -if (window < nr_make->window) - nr_make->window = window; +nr_negotiate_window (nr_make, window);/* * L4 timeout negotiation. Ignore a proposal shorter than the
net/netrom/nr_in.c +1 -1
@@ -129,7 +129,7 @@ static int nr_state1_machine(struct sock *sk, struct sk_buff *skb, nr->vl =0 ; nr->state =NR_STATE_3 ; nr->n2count =0 ; - nr->window = skb->data[20 ]; +nr_negotiate_window (nr, skb->data[20 ]); sk->sk_state =TCP_ESTABLISHED ;if (!sock_flag (sk,SOCK_DEAD )) sk->sk_state_change (sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 136/686 netrom: dont send part of a message that cannot be fragmented whole
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_output() cuts a message longer than one frame into fragments and puts each one on the write queue as soon as it is built, the more flag set on all but the last. If allocating a fragment fails, it frees the rest of the message and returns, and nr_sendmsg() still reports the whole length as sent. The allocation waits for send buffer space, so this happens not only when memory is short but whenever a signal interrupts that wait.
The fragments already queued then go out ending with the more flag set:
the peer joins them to the next message. If the first allocation fails, nothing is sent and the caller is told the message went.
Build the fragments on a list of our own and only put them on the write queue once all of them exist; on failure, drop them and return the error, which nr_sendmsg() passes on. This is what ax25_output() does since #56.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS. A speaks NET/ROM itself and never acknowledges; on the circuit it accepted, B sends a 4000-byte message with SIGALRM set to interrupt it after 3 s, then the 4-byte message "fin.":
SO_SNDBUF 6000:
before: send() = 4000; A receives 4 fragments of 236 bytes, all with
the more flag, and "fin." is queued behind them
after: send() = -1 EINTR; A receives "fin." alone
SO_SNDBUF at the minimum:
before: send() = 4000 but nothing of it is sent
after: send() = -1 EINTR
No kernel report in any run.
--- include/net/netrom.h | 2 +- net/netrom/af_netrom.c | 6 +++--- net/netrom/nr_out.c | 23 ++++++++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-)
include/net/netrom.h +1 -1
@@ -202,7 +202,7 @@ void nr_loopback_clear(void);int nr_loopback_queue (struct sk_buff *);/* nr_out.c */ -void nr_output (struct sock *,struct sk_buff *); +int nr_output (struct sock *sk,struct sk_buff *skb);void nr_send_nak_frame (struct sock *);void nr_kick (struct sock *);void nr_transmit_buffer (struct sock *,struct sk_buff *);
net/netrom/af_netrom.c +3 -3
@@ -1173,9 +1173,9 @@ static int nr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) goto out; } -nr_output (sk, skb);/* Shove it onto the queue */ - - err = len; + err =nr_output (sk, skb);/* Shove it onto the queue */ +if (!err) + err = len; out:release_sock (sk);return err;
net/netrom/nr_out.c +20 -3
@@ -28,11 +28,19 @@/* * This is where all NET/ROM frames pass, except for IP-over-NET/ROM which * cannot be fragmented in this manner. +* +* A message too long for one frame is cut into fragments built on a list +* of our own, and only put on the write queue once all of them exist: a +* message that cannot be fragmented whole (no memory, or a signal while +* waiting for send buffer space) is not sent at all, and the error is +* returned. Consumes skb in all cases. */ -void nr_output (struct sock *sk,struct sk_buff *skb) +int nr_output (struct sock *sk,struct sk_buff *skb) { +struct sk_buff_head frags;struct sk_buff *skbn;unsigned char transport[NR_TRANSPORT_LEN ]; +unsigned long flags;int err, frontlen, len;if (skb->len -NR_TRANSPORT_LEN >NR_MAX_PACKET_SIZE ) {
@@ -42,10 +50,13 @@ void nr_output(struct sock *sk, struct sk_buff *skb) frontlen =skb_headroom (skb); +__skb_queue_head_init (&frags); +while (skb->len >0 ) {if ((skbn =sock_alloc_send_skb (sk, frontlen +NR_MAX_PACKET_SIZE ,0 , &err)) ==NULL ) { +__skb_queue_purge (&frags);kfree_skb (skb); -return ; +return err; }skb_reserve (skbn, frontlen);
@@ -63,15 +74,21 @@ void nr_output(struct sock *sk, struct sk_buff *skb)if (skb->len >0 ) skbn->data[4 ] |=NR_MORE_FLAG ; -skb_queue_tail (&sk->sk_write_queue, skbn);/* Throw it on the queue */ +__skb_queue_tail (&frags, skbn); }kfree_skb (skb); + +spin_lock_irqsave (&sk->sk_write_queue.lock, flags); +skb_queue_splice_tail_init (&frags, &sk->sk_write_queue); +spin_unlock_irqrestore (&sk->sk_write_queue.lock, flags); }else {skb_queue_tail (&sk->sk_write_queue, skb);/* Throw it on the queue */ }nr_kick (sk); + +return 0 ; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 137/686 netrom: disconnect sockets under their lock when a device goes down
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
nr_kill_by_device() disconnects every socket bound to the device going down while holding only nr_list_lock. nr_disconnect() stops the timers, purges the queues and changes the state of the socket, but its timers and nr_rx_frame() work on the same socket under bh_lock_sock() only, on other CPUs, and are not kept out by nr_list_lock: a timer can be retransmitting from a queue being purged, or a frame received can move the socket back to another state.
Take the socket lock around nr_disconnect(). nr_info_show() already nests the socket lock inside nr_list_lock in the same way.
The race was not reproduced. Tested for regressions on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A opens eight circuits to B and keeps sending on them; B reads /proc/net/nr in a loop and takes nr0 down. Before and after, all eight circuits on B end with ENETUNREACH and there is no kernel report, lockdep included.
--- net/netrom/af_netrom.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
net/netrom/af_netrom.c +10 -4
@@ -96,16 +96,22 @@ static void nr_remove_socket(struct sock *sk) }/* -* Kill all bound sockets on a dropped device. +* Kill all bound sockets on a dropped device. Each socket is disconnected +* under its lock, which its timers and nr_rx_frame() hold while they work +* on it; nr_info_show() takes the two locks in the same order. */ static void nr_kill_by_device (struct net_device *dev) {struct sock *s;spin_lock_bh (&nr_list_lock); -sk_for_each (s, &nr_list) -if (nr_sk (s)->device == dev) -nr_disconnect (s,ENETUNREACH ); +sk_for_each (s, &nr_list) { +if (nr_sk (s)->device != dev) +continue ; +bh_lock_sock (s); +nr_disconnect (s,ENETUNREACH ); +bh_unlock_sock (s); + }spin_unlock_bh (&nr_list_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 138/686 netrom: only update the BPQ extension flag on circuit set-up frames
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
For a frame received on an existing circuit, nr_rx_frame() sets bpqext when the frame is a CONNACK of 22 bytes and clears it for any other frame. Yet only the set-up frames tell whether the peer uses the BPQ
extension: a CONNACK of 22 bytes, or a CONNREQ of 37 bytes. The first INFO frame of an accepted circuit therefore clears the flag set from the peer's CONNREQ.
When a BPQ peer then repeats its CONNREQ, because our CONNACK was lost, nr_state3_machine() answers with a CONNACK built with bpqext clear, without the TTL byte that the first CONNACK had.
Only change bpqext on a CONNACK or a CONNREQ, from its length.
Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A speaks NET/ROM itself, opens a circuit to a listening socket on B with a 37-byte CONNREQ, sends an INFO frame on it, then repeats the CONNREQ.
before: first CONNACK 22 bytes, second one 21 bytes (no BPQ byte)
after: both CONNACK 22 bytes
No kernel report in either run.
--- net/netrom/af_netrom.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
net/netrom/af_netrom.c +10 -4
@@ -961,10 +961,16 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)bh_lock_sock (sk);skb_reset_transport_header (skb); -if (frametype ==NR_CONNACK && skb->len ==22 ) -nr_sk (sk)->bpqext =1 ; -else -nr_sk (sk)->bpqext =0 ; +/* +* Only the circuit set-up frames tell whether the peer uses +* the BPQ extension: a CONNACK of 22 bytes, or a CONNREQ of +* 37 bytes (repeated, for a circuit already accepted). The +* other frames say nothing about it. +*/ +if (frametype ==NR_CONNACK ) +nr_sk (sk)->bpqext = (skb->len ==22 ); +else if (frametype ==NR_CONNREQ ) +nr_sk (sk)->bpqext = (skb->len ==37 ); ret =nr_process_rx_frame (sk, skb);bh_unlock_sock (sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 139/686 rose: hold the listener while a Call Request is queued on it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_rx_call_request() runs in softirq context for every Call Request addressed to us. It finds the listening socket with rose_find_listener(), which returns it without a reference once rose_list_lock is dropped, then creates the new socket, queues it on the listener's receive queue and wakes the listener up. Nothing stops the process owning the listener from closing it meanwhile:rose_release() destroys a listening socket at once, and the Call Request writes into freed memory. A node daemon that restarts while calls come in does exactly this.
Take a reference in rose_find_listener(), lock the listener in rose_rx_call_request() and refuse the call if it has been closed in the meantime. rose_release() marks the socket dead with sock_orphan() before rose_destroy_socket() empties its queue under the socket lock, so a listener found alive once locked will see the new socket on its queue, either in rose_accept() or when it is destroyed.
On a QEMU bench with two 4-CPU guests (KASAN, lockdep), six threads on A calling B without a break while B opens a listening socket, keeps it 0 to 30 ms and closes it, for 40 s: before, KASAN reports a slab-use-after-free in rose_rx_call_request() a few seconds in, the socket having been freed by close() on B; with a 20 ms delay after rose_find_listener() the corrupted socket list then panics B in rose_neigh_put(). After, no report in either case, with about 400 calls connected as before.
--- net/rose/af_rose.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
net/rose/af_rose.c +27 -5
@@ -278,7 +278,7 @@ static void rose_insert_socket(struct sock *sk)/* * Find a socket that wants to accept the Call Request we just -* received. +* received. A reference is taken on the socket found. */ static struct sock *rose_find_listener (rose_address *addr,ax25_address *call) {
@@ -304,6 +304,8 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call) } s =NULL ; found: +if (s) +sock_hold (s);spin_unlock_bh (&rose_list_lock);return s; }
@@ -1103,12 +1105,31 @@ int rose_rx_call_request(struct sk_buff *skb, struct net_device *dev, struct ros } sk =rose_find_listener (&facilities.source_addr, &facilities.source_call); +if (!sk) { +rose_transmit_clear_request (neigh, lci,ROSE_NETWORK_CONGESTION ,120 ); +return 0 ; + } + +/* +* The listener may be closed by rose_release() at any time. It is +* marked dead before rose_destroy_socket() empties its queue, so +* once it is locked a listener that is not dead will see the new +* socket on its queue, either in rose_accept() or when it is +* destroyed. +*/ +bh_lock_sock (sk);/* * We can't accept the Call Request. */ -if (sk ==NULL ||sk_acceptq_is_full (sk) || - (make =rose_make_new (sk)) ==NULL ) { +if (sock_flag (sk,SOCK_DEAD ) || sk->sk_state !=TCP_LISTEN || +sk_acceptq_is_full (sk)) + make =NULL ; +else + make =rose_make_new (sk); +if (!make) { +bh_unlock_sock (sk); +sock_put (sk);rose_transmit_clear_request (neigh, lci,ROSE_NETWORK_CONGESTION ,120 );return 0 ; }
@@ -1164,8 +1185,9 @@ int rose_rx_call_request(struct sk_buff *skb, struct net_device *dev, struct rosrose_start_heartbeat (make); -if (!sock_flag (sk,SOCK_DEAD )) - sk->sk_data_ready (sk); + sk->sk_data_ready (sk); +bh_unlock_sock (sk); +sock_put (sk);return 1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 140/686 rose: hold the socket a received frame is delivered to
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_route_frame() and rose_loopback_timer() find the socket a frame belongs to with rose_find_socket(), which returns it without a reference once rose_list_lock is dropped, then hand the frame to rose_rcv_frame(), which locks the socket and runs its state machine. The socket can be destroyed in between: by rose_release() on another CPU, or by its heartbeat, which reaps a dead socket in state 0 that nobody owns, such as an incoming call left on the queue of a listener that has been closed. Its LCI is not cleared then, so frames from the neighbour still find it until it is reaped, and the reaping frees it under the frame being delivered.
Take a reference in rose_find_socket() and drop it in its callers once the frame has been handled. rose_new_lci() only needs to know whether an LCI is in use: let it walk the socket list under rose_list_lock itself instead of taking references.
A Call Request that arrives on the LCI of an existing socket tears the old socket down. With the reference held, the socket may by then have been disconnected or reaped, its neighbour reference dropped and rose->neighbour cleared: lock the socket and only tear it down if it still holds that LCI on that neighbour.
On a QEMU bench with two 4-CPU guests (KASAN, lockdep), A places eight calls to B and sends a 100-byte message per second on each; B listens without ever accepting, closes the listener after 10 s, and the calls left on its queue are reaped 5 s later while A's messages keep coming. With frames for sockets in state 0 held 2 s after rose_find_socket(),
before: KASAN reports a slab-use-after-free in rose_rcv_frame(), called from rose_route_frame(), on the socket freed by the heartbeat timer;
after: no report in two runs, and no report without the delay either.
--- net/rose/af_rose.c | 42 ++++++++++++++++++++++++++++++---------- net/rose/rose_loopback.c | 1 + net/rose/rose_route.c | 37 +++++++++++++++++++++-------------- 3 files changed, 56 insertions(+), 24 deletions(-)
net/rose/af_rose.c +32 -10
@@ -312,20 +312,35 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)/* * Find a connected ROSE socket given my LCI and device. +* The caller holds rose_list_lock. */ -struct sock *rose_find_socket (unsigned int lci,struct rose_neigh *neigh) +static struct sock *__rose_find_socket (unsigned int lci,struct rose_neigh *neigh) {struct sock *s; -spin_lock_bh (&rose_list_lock);sk_for_each (s, &rose_list) {struct rose_sock *rose =rose_sk (s);if (rose->lci == lci && rose->neighbour == neigh) - goto found; +return s; } - s =NULL ; -found: + +return NULL ; +} + +/* +* Find a connected ROSE socket given my LCI and device. A reference is +* taken on the socket found: it can be released and destroyed as soon +* as rose_list_lock is dropped. +*/ +struct sock *rose_find_socket (unsigned int lci,struct rose_neigh *neigh) +{ +struct sock *s; + +spin_lock_bh (&rose_list_lock); + s =__rose_find_socket (lci, neigh); +if (s) +sock_hold (s);spin_unlock_bh (&rose_list_lock);return s; }
@@ -336,19 +351,26 @@ struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)*/ unsigned int rose_new_lci (struct rose_neigh *neigh) { +unsigned int res =0 ;int lci; +spin_lock_bh (&rose_list_lock);if (neigh->dce_mode) {for (lci =1 ; lci <= sysctl_rose_maximum_vcs; lci++) -if (rose_find_socket (lci, neigh) ==NULL &&rose_route_free_lci (lci, neigh) ==NULL ) -return lci; +if (!__rose_find_socket (lci, neigh) && !rose_route_free_lci (lci, neigh)) { + res = lci; +break ; + } }else {for (lci = sysctl_rose_maximum_vcs; lci >0 ; lci--) -if (rose_find_socket (lci, neigh) ==NULL &&rose_route_free_lci (lci, neigh) ==NULL ) -return lci; +if (!__rose_find_socket (lci, neigh) && !rose_route_free_lci (lci, neigh)) { + res = lci; +break ; + } } +spin_unlock_bh (&rose_list_lock); -return 0 ; +return res; }/*
net/rose/rose_loopback.c +1 -0
@@ -109,6 +109,7 @@ static void rose_loopback_timer(struct timer_list *unused)if (sk) {if (rose_rcv_frame (sk, skb) ==0 )kfree_skb (skb); +sock_put (sk);continue ; }
net/rose/rose_route.c +23 -14
@@ -1054,25 +1054,34 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)if (frametype ==ROSE_CALL_REQUEST ) {struct rose_sock *rose =rose_sk (sk); -/* Remove an existing unused socket */ -rose_clear_queues (sk); - rose->cause =ROSE_NETWORK_CONGESTION ; - rose->diagnostic =0 ; -rose_neigh_put (rose->neighbour); - rose->neighbour =NULL ; - rose->lci =0 ; - rose->state =ROSE_STATE_0 ; - sk->sk_state =TCP_CLOSE ; - sk->sk_err =0 ; - sk->sk_shutdown |=SEND_SHUTDOWN ; -if (!sock_flag (sk,SOCK_DEAD )) { - sk->sk_state_change (sk); -sock_set_flag (sk,SOCK_DEAD ); +/* +* Remove an existing unused socket, unless it was +* disconnected or reaped since it was found. +*/ +bh_lock_sock (sk); +if (rose->lci == lci && rose->neighbour == rose_neigh) { +rose_clear_queues (sk); + rose->cause =ROSE_NETWORK_CONGESTION ; + rose->diagnostic =0 ; +rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ; + rose->lci =0 ; + rose->state =ROSE_STATE_0 ; + sk->sk_state =TCP_CLOSE ; + sk->sk_err =0 ; + sk->sk_shutdown |=SEND_SHUTDOWN ; +if (!sock_flag (sk,SOCK_DEAD )) { + sk->sk_state_change (sk); +sock_set_flag (sk,SOCK_DEAD ); + } } +bh_unlock_sock (sk); +sock_put (sk); }else {skb_reset_transport_header (skb); res =rose_rcv_frame (sk, skb); +sock_put (sk); goto out; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 141/686 rose: report a timed out call to connect()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
When the Call Request of a connecting socket gets no answer within T1, rose_timer_expiry() sends a Clear Request and moves the socket to state 2, leaving sk_state at TCP_SYN_SENT. The neighbour then confirms the clearing, or clears the call itself, and rose_state2_machine() calls rose_disconnect() with a reason of 0. sk_err stays 0, so a blocking connect() leaves its wait with sock_error() returning 0 and reports success on a call that never got through, and a non-blocking caller reads 0 from SO_ERROR. The first send() then fails with EPIPE.
Report ETIMEDOUT when the socket is cleared from state 2 while it is still connecting, as rose_timer_expiry() already does when T3 runs out. A socket that was released or timed out while connected goes on being cleared without an error.
On a QEMU bench with two guests, B listening with ROSE_DEFER and never accepting, A calling it with T1 set to 3 s, twice blocking and twice
non-blocking: before, connect() or SO_ERROR returned 0 in all four calls; after, ETIMEDOUT in all four. A call to nobody still gets ECONNREFUSED at once.
--- net/rose/rose_in.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/rose/rose_in.c +9 -2
@@ -75,17 +75,24 @@ static int rose_state1_machine(struct sock *sk, struct sk_buff *skb, int frametystatic int rose_state2_machine (struct sock *sk,struct sk_buff *skb,int frametype) {struct rose_sock *rose =rose_sk (sk); +/* +* A call whose Call Request timed out (T1) is cleared from state 2 +* while connect() is still waiting for it: report the timeout, or +* connect() and SO_ERROR would find no error on a call that never +* got through. +*/ +int reason = sk->sk_state ==TCP_SYN_SENT ?ETIMEDOUT :0 ;switch (frametype) {case ROSE_CLEAR_REQUEST :rose_write_internal (sk,ROSE_CLEAR_CONFIRMATION ); -rose_disconnect (sk,0 , skb->data[3 ], skb->data[4 ]); +rose_disconnect (sk, reason, skb->data[3 ], skb->data[4 ]);rose_neigh_put (rose->neighbour); rose->neighbour =NULL ;break ;case ROSE_CLEAR_CONFIRMATION : -rose_disconnect (sk,0 ,-1 ,-1 ); +rose_disconnect (sk, reason,-1 ,-1 );rose_neigh_put (rose->neighbour); rose->neighbour =NULL ;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 142/686 rose: drop the neighbour reference once when a cleared socket is closed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
rose_release() of a socket in state 2, awaiting the Clear Confirmation of its call, drops the neighbour reference but leaves rose->neighbour set, then releases the socket lock before disconnecting the socket. release_sock() runs the frames put on the socket backlog while the lock was held: a Clear Confirmation among them goes through rose_state2_machine() with the socket still in state 2 and drops the same reference again. rose_kill_by_neigh(), which does not take the socket lock, can do the same if the link restarts or fails at that moment. The neighbour refcount then goes below the number of users, and the neighbour is freed while it is still in the tables.
Disconnect the socket before its lock is dropped, so that the frames on the backlog find it in state 0, and take the neighbour off the socket under rose_list_lock, as rose_kill_by_neigh() looks at it, so that only one of them drops the reference.
On a QEMU bench with two guests (KASAN, lockdep), A calls B with T1 set to 2 s, B never accepts, and A closes the socket 200 ms after T1 expired, while the Clear Confirmation is on its way. With 1 s of delay in rose_release() and 500 ms before B sends the Clear Confirmation:
before, the "use" count of the neighbour in /proc/net/rose_neigh goes to -1 on the first close, then KASAN reports a slab-use-after-free on the freed neighbour and A panics; after, it stays at 0 over five calls, with or without the delays.
--- net/rose/af_rose.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
net/rose/af_rose.c +15 -3
@@ -698,6 +698,7 @@ static struct sock *rose_make_new(struct sock *osk)static int rose_release (struct socket *sock) {struct sock *sk = sock->sk; +struct rose_neigh *neigh;struct rose_sock *rose;if (sk ==NULL )return 0 ;
@@ -716,10 +717,21 @@ static int rose_release(struct socket *sock)break ;case ROSE_STATE_2 : -rose_neigh_put (rose->neighbour); -release_sock (sk); +/* +* Disconnect before the socket lock is dropped: frames put on +* the backlog meanwhile, a Clear Confirmation for one, then +* find it in state 0 instead of dropping the neighbour +* reference a second time. rose_kill_by_neigh() does not take +* the socket lock: take the neighbour under rose_list_lock, as +* it does, so that only one of them drops the reference. +*/ rose_disconnect (sk,0 ,-1 ,-1 ); -lock_sock (sk); +spin_lock_bh (&rose_list_lock); + neigh = rose->neighbour; + rose->neighbour =NULL ; +spin_unlock_bh (&rose_list_lock); +if (neigh) +rose_neigh_put (neigh);rose_destroy_socket (sk);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 143/686 rose: swap the AX.25 connection of a neighbour under a lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
Each holder of neigh->ax25 owns a reference on the ax25_cb. rose_send_frame() and rose_link_up() replace it by reading the old pointer, storing the new connection and dropping the reference on the old one. They run from process context (sendmsg, connect, release), from softirq (frames routed or answered on receipt) and from the neighbour timers, under no common lock, and rose_link_failed() clears the pointer under rose_neigh_list_lock alone. When two of them run at the same time for one neighbour, both drop the reference on the same old ax25_cb, which is freed while still in use, and the reference taken by one of them on the new connection is lost.
Do the swap under a spinlock of its own and drop the reference taken off after it, so that it is dropped once; rose_link_failed() only clears the pointer if it still holds the failed connection.
On a QEMU bench with two 4-CPU guests (KASAN, lockdep), four threads on A placing calls to B and sending a message every 20 ms, each echoed by a thread on B: with 50 ms between the read and the update of neigh->ax25, before: KASAN reports a slab-use-after-free in rose_send_frame(), from rose_sendmsg() on B, and refcount_t reports an underflow on the ax25_cb; after: no report. Without the delay, no report either way and the same traffic, 1220 messages.
--- include/net/rose.h | 1 + net/rose/rose_link.c | 61 ++++++++++++++++++++++++++++++++++--------- net/rose/rose_route.c | 5 ++-- 3 files changed, 52 insertions(+), 15 deletions(-)
include/net/rose.h +1 -0
@@ -232,6 +232,7 @@ int rose_backlog_rcv(struct sock *sk, struct sk_buff *skb);/* rose_link.c */ void rose_neigh_init_timers (struct rose_neigh *neigh); +bool rose_neigh_clear_ax25 (struct rose_neigh *neigh,ax25_cb *ax25);void rose_start_ftimer (struct rose_neigh *);void rose_stop_ftimer (struct rose_neigh *);void rose_stop_t0timer (struct rose_neigh *);
net/rose/rose_link.c +49 -12
93 lines not on this page · raw message
net/rose/rose_route.c +2 -3
@@ -936,14 +936,13 @@ void rose_link_failed(ax25_cb *ax25, int reason)spin_lock_bh (&rose_neigh_list_lock); rose_neigh = rose_neigh_list;while (rose_neigh !=NULL ) { -if (rose_neigh->ax25 == ax25) +if (READ_ONCE (rose_neigh->ax25) == ax25)break ; rose_neigh = rose_neigh->next; }if (rose_neigh !=NULL ) { - rose_neigh->ax25 =NULL ; -ax25_cb_put (ax25); +rose_neigh_clear_ax25 (rose_neigh, ax25);rose_del_route_by_neigh (rose_neigh);rose_kill_by_neigh (rose_neigh);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 144/686 rose: give the sysctl timer limits in milliseconds
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
Since commit 82e84249f0ee ("[ROSE]: Eleminate HZ from ROSE kernel interfaces") the ROSE timer sysctls hold milliseconds, converted with msecs_to_jiffies() where they are used, but their limits were left in
jiffies: 1 * HZ to 300 * HZ for T0 to T3 and the holdback, 60 * HZ to 600 * HZ for the link fail timeout, up to 65535 * HZ for the idle timeout. They only match with HZ=1000. With HZ=100, the largest T1 that can be written is 30 s while the default is 200 s, and the default link fail timeout of 120 s is refused: once changed, a default can no longer be put back. With HZ=250 the limit on T0 to T3 is 75 s.
Seen on a Raspberry Pi node (HZ=100): writing back 200000 to call_request_timeout or 120000 to link_fail_timeout fails with EINVAL, and 30000 is the largest call_request_timeout accepted.
Give the limits in milliseconds. With HZ=1000 nothing changes: on a QEMU bench the defaults are accepted, and 999/300001 (T0 to T3), 59999/600001 (link fail) and 65535001 (idle) are refused, as before.
--- net/rose/sysctl_net_rose.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
net/rose/sysctl_net_rose.c +7 -6
@@ -9,13 +9,14 @@#include <net/ax25.h> #include <net/rose.h> -static int min_timer[] = {1 *HZ }; -static int max_timer[] = {300 *HZ }; -static int min_idle[] = {0 *HZ }; -static int max_idle[] = {65535 *HZ }; +/* The timers are given in milliseconds */ +static int min_timer[] = {1 *MSEC_PER_SEC }; +static int max_timer[] = {300 *MSEC_PER_SEC }; +static int min_idle[] = {0 *MSEC_PER_SEC }; +static int max_idle[] = {65535 *MSEC_PER_SEC };static int min_route[1 ], max_route[] = {1 }; -static int min_ftimer[] = {60 *HZ }; -static int max_ftimer[] = {600 *HZ }; +static int min_ftimer[] = {60 *MSEC_PER_SEC }; +static int max_ftimer[] = {600 *MSEC_PER_SEC };static int min_maxvcs[] = {1 }, max_maxvcs[] = {254 };static int min_window[] = {1 }, max_window[] = {7 };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 145/686 mm: page_alloc: make defrag_mode retries follow the promoted order
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
commit 4cd78a2dcfbb13f049f841b98763896a3d1d7750 upstream.
Since commit 7e8756d7ad22 ("mm: page_alloc: fix non-movable reclaim storm in defrag_mode"), direct reclaim and compaction for non-movable requests under defrag_mode run at pageblock_order, to produce the whole blocks that ALLOC_NOFRAGMENT needs. The retry decisions that follow still use the request order. An order-0 request can therefore retry indefinitely without ever reaching the ALLOC_NOFRAGMENT fallback:
- Reclaim at pageblock_order gives up after one pass as soon as a zone looks compaction_ready(), and do_try_to_free_pages() then returns 1 even though nothing was reclaimed. It returns before the retry that would reclaim memory.low-protected cgroups, so when most memory is protected, the pass that did run finds next to nothing.
- Compaction at pageblock_order fails or is deferred.
- should_reclaim_retry() takes the reported progress as progress for the order-0 request and resets no_progress_loops. The request retries.
Order 1-3 requests loop the same way, and should_compact_retry() also checks their pageblock_order compaction result against the request order.
On a production host (64G, defrag_mode, memory.low covering most of the workload), 95% of direct reclaim runs were order-9 runs that returned 1 with nothing reclaimed, at up to 60k runs per second. Across ~200M should_reclaim_retry() calls in a day, no_progress_loops never left 0. The spinning allocations were SLUB slab refills for inode and dentry caches. The time spent registers as memory pressure, and pressure-based OOM killing takes down both workloads and system services.
For promoted requests:
- Reclaim progress does not reset no_progress_loops, as for costly orders.
- should_compact_retry() checks the compaction result at the promoted order and does not retry COMPACT_SKIPPED, since the request can fall back. The compaction priority floor and the COMPACT_SUCCESS retry limit stay those of the request order, so a non-costly request still gets its COMPACT_PRIO_SYNC_FULL pass before it falls back.
When a promoted request takes the fallback, reset the retry counters, so that the fallback attempt gets a full retry budget before the OOM killer is considered. A request whose reclaim was not promoted spent its budget on the request itself and keeps its counters, as Usama Arif pointed out.
__alloc_pages_slowpath() computes the promoted order once per iteration and keeps it in alloc_context for direct reclaim, direct compaction and the two retry helpers, so no callee has to recompute it. Harry Yoo asked for the promoted order to be explicit rather than derived in each callee, and Vlastimil Babka suggested alloc_context over new function parameters.
In a VM reproducer (32G, defrag_mode, inode churn under memory.low):
before after
should_reclaim_retry() calls 63M 293k
peak memory pressure (PSI some avg10) 99% 12%
File creation runs 5.7x faster.
[ kas: alloc_context is in mm/internal.h and compaction_zonelist_suitable()
takes no gfp_mask in 6.18. 6.18 also tries compaction once before the retry loop; set reclaim_compact_order there as well, or that attempt sees order 0 and is skipped. ]
--- mm/internal.h | 2 ++ mm/page_alloc.c | 68 +++++++++++++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 25 deletions(-)
mm/internal.h +2 -0
@@ -594,6 +594,8 @@ struct alloc_context {*/ enum zone_type highest_zoneidx;bool spread_dirty_pages; +/* Set by __alloc_pages_slowpath() before reclaim and compaction */ +unsigned int reclaim_compact_order; };/*
mm/page_alloc.c +43 -25
125 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 146/686 devtmpfs: make devtmpfs_context_ops static
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ben Dooks <[email protected]>
[ Upstream commit 99aa03f98ce56804f2e8936f9dabf8c4f117a661 ]
The 'devtmpfs_context_ops' object is not exported outside the devtmpfs.c file nor defined anywhere for use outside. Make this static to remove the following sparse warning:
drivers/base/devtmpfs.c:88:30: warning: symbol 'devtmpfs_context_ops' was not declared. Should it be static?
Stable-dep-of: 1c7df6fa838a ("devtmpfs: restore mount option reconfiguration on get_tree")
--- drivers/base/devtmpfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/devtmpfs.c +1 -1
@@ -85,7 +85,7 @@ static int devtmpfs_get_tree(struct fs_context *fc) }/* Ops are filled in during init depending on underlying shmem or ramfs type */ -struct fs_context_operations devtmpfs_context_ops = {}; +static struct fs_context_operations devtmpfs_context_ops = {};/* Call the underlying initialization and set to our ops */ static int devtmpfs_init_fs_context (struct fs_context *fc)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 147/686 devtmpfs: restore mount option reconfiguration on get_tree
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Sandeen <[email protected]>
[ Upstream commit 1c7df6fa838a46f0d5090ef134f67511f0592f33 ]
commit cb0e0a8bf4e1 ("devtmpfs: replace ->mount with ->get_tree in public instance") converted the public devtmpfs instance to the new mount API but broke the ability to reconfigure the shared superblock options via subsequent mount() calls, as had been fixed once in a6097180d884 ("devtmpfs regression fix: reconfigure on each mount")
This makes boot-time defaults permanent.
Fix this using an approach suggested by Al Viro: at init_fs_context time, create a reconfigure-mode context via fs_context_for_reconfigure() and save it in fc->fs_private. The devtmpfs parse ops can then use this context to parse options appropriately for the underlying filesystem.
This also removes the devtmpfs_configure_context() one-time ops-copying approach and the global mutable ops table it required.
--- drivers/base/devtmpfs.c | 108 ++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 44 deletions(-)
drivers/base/devtmpfs.c +64 -44
@@ -73,39 +73,90 @@ static struct file_system_type internal_fs_type = { .kill_sb = kill_litter_super, }; -/* Simply take a ref on the existing mount */ +struct devtmpfs_context { +struct fs_context *fc; +}; + +static void devtmpfs_free (struct fs_context *fc) +{ +struct devtmpfs_context *ctx = fc->fs_private; + +if (ctx) { +put_fs_context (ctx->fc); +kfree (ctx); + } +} + +static int devtmpfs_parse_param (struct fs_context *fc,struct fs_parameter *param) +{ +struct devtmpfs_context *ctx = fc->fs_private; + +return ctx->fc->ops->parse_param (ctx->fc, param); +} + +static int devtmpfs_parse_monolithic (struct fs_context *fc,void *data) +{ +struct devtmpfs_context *ctx = fc->fs_private; + +if (ctx->fc->ops->parse_monolithic) +return ctx->fc->ops->parse_monolithic (ctx->fc, data); +return generic_parse_monolithic (ctx->fc, data); +} +static int devtmpfs_get_tree (struct fs_context *fc) { +struct devtmpfs_context *ctx = fc->fs_private;struct super_block *sb = mnt->mnt_sb; +int err;atomic_inc (&sb->s_active);down_write (&sb->s_umount); + +if (ctx->fc->ops->reconfigure) { + err = ctx->fc->ops->reconfigure (ctx->fc); +if (err) { +deactivate_locked_super (sb); +return err; + } + } + fc->root =dget (sb->s_root);return 0 ; } -/* Ops are filled in during init depending on underlying shmem or ramfs type */ -static struct fs_context_operations devtmpfs_context_ops = {}; +static const struct fs_context_operations devtmpfs_context_ops = { + .free = devtmpfs_free, + .parse_param = devtmpfs_parse_param, + .parse_monolithic = devtmpfs_parse_monolithic, + .get_tree = devtmpfs_get_tree, +}; -/* Call the underlying initialization and set to our ops */ static int devtmpfs_init_fs_context (struct fs_context *fc) { -int ret; -#ifdef CONFIG_TMPFS - ret =shmem_init_fs_context (fc); -#else - ret =ramfs_init_fs_context (fc); -#endif -if (ret <0 ) -return ret; +struct devtmpfs_context *ctx; +int err; + + ctx = kzalloc_obj(struct devtmpfs_context); +if (!ctx) +return -ENOMEM ; + +/* Each mount will reconfigure the shared superblock w/ new options */ + ctx->fc =fs_context_for_reconfigure (mnt->mnt_root, + mnt->mnt_sb->s_flags,MS_RMT_MASK ); +if (IS_ERR (ctx->fc)) { + err =PTR_ERR (ctx->fc); +kfree (ctx); +return err; + } + fc->fs_private = ctx; fc->ops = &devtmpfs_context_ops;return 0 ; }static struct file_system_type dev_fs_type = { - .name ="devtmpfs" , + .name ="devtmpfs" , .init_fs_context = devtmpfs_init_fs_context, };
@@ -443,31 +494,6 @@ static int __ref devtmpfsd(void *p)return 0 ; } -/* -* Get the underlying (shmem/ramfs) context ops to build ours -*/ -static int devtmpfs_configure_context (void ) -{ -struct fs_context *fc; - - fc =fs_context_for_reconfigure (mnt->mnt_root, mnt->mnt_sb->s_flags, -MS_RMT_MASK ); -if (IS_ERR (fc)) -return PTR_ERR (fc); - -/* Set up devtmpfs_context_ops based on underlying type */ - devtmpfs_context_ops.free = fc->ops->free; - devtmpfs_context_ops.dup = fc->ops->dup; - devtmpfs_context_ops.parse_param = fc->ops->parse_param; - devtmpfs_context_ops.parse_monolithic = fc->ops->parse_monolithic; - devtmpfs_context_ops.get_tree = &devtmpfs_get_tree; - devtmpfs_context_ops.reconfigure = fc->ops->reconfigure; - -put_fs_context (fc); - -return 0 ; -} -/* * Create devtmpfs instance, driver-core devices will add their device * nodes here.
@@ -483,12 +509,6 @@ int __init devtmpfs_init(void)return PTR_ERR (mnt); } - err =devtmpfs_configure_context (); -if (err) { -pr_err ("unable to configure devtmpfs type %d\n" , err); -return err; - } - err =register_filesystem (&dev_fs_type);if (err) {pr_err ("unable to register devtmpfs type %d\n" , err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 148/686 mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
[ Upstream commit af19aff38d6faea35b10f26cca32d0e54f8aea5e ]
DAMON sysfs interface reads the user-provided size range arguments for hugepage_size type DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the arguments in parallel, an invalid size range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.
User impact of the bug should be trivial. From the core layer's perspective, the invalid size range is not really invalid. It just works as having a weird size range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
--- mm/damon/sysfs-schemes.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/damon/sysfs-schemes.c +2 -3
@@ -2493,12 +2493,11 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { -if (sysfs_filter->sz_range.min > - sysfs_filter->sz_range.max) { + filter->sz_range = sysfs_filter->sz_range; +if (filter->sz_range.min > filter->sz_range.max) {damos_destroy_filter (filter);return -EINVAL ; } - filter->sz_range = sysfs_filter->sz_range; }damos_add_filter (scheme, filter);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 149/686 media: microchip-isc: fix WB offset and gain register field masking
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 6e9eaa3b93870e4edac1bd2539fe113c24663eaf ]
ISC_WB_O_* and ISC_WB_G_* each pack two 13-bit fields. A negative offset sign-extends and corrupts the adjacent field. Add masks for the two fields and write them with FIELD_PREP(), which masks each value into its field, so sign extension can no longer bleed across.
--- .../platform/microchip/microchip-isc-base.c | 16 ++++++++-------- .../platform/microchip/microchip-isc-regs.h | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/media/platform/microchip/microchip-isc-base.c +8 -8
@@ -62,17 +62,17 @@ static inline void isc_update_awb_ctrls(struct isc_device *isc)/* In here we set our actual hw pipeline config */ regmap_write (isc->regmap,ISC_WB_O_RGR , - ((ctrls->offset[ISC_HIS_CFG_MODE_R ])) | - ((ctrls->offset[ISC_HIS_CFG_MODE_GR ]) <<16 )); +FIELD_PREP (ISC_WB_O_LO , ctrls->offset[ISC_HIS_CFG_MODE_R ]) | +FIELD_PREP (ISC_WB_O_HI , ctrls->offset[ISC_HIS_CFG_MODE_GR ]));regmap_write (isc->regmap,ISC_WB_O_BGB , - ((ctrls->offset[ISC_HIS_CFG_MODE_B ])) | - ((ctrls->offset[ISC_HIS_CFG_MODE_GB ]) <<16 )); +FIELD_PREP (ISC_WB_O_LO , ctrls->offset[ISC_HIS_CFG_MODE_B ]) | +FIELD_PREP (ISC_WB_O_HI , ctrls->offset[ISC_HIS_CFG_MODE_GB ]));regmap_write (isc->regmap,ISC_WB_G_RGR , - ctrls->gain[ISC_HIS_CFG_MODE_R ] | - (ctrls->gain[ISC_HIS_CFG_MODE_GR ] <<16 )); +FIELD_PREP (ISC_WB_G_LO , ctrls->gain[ISC_HIS_CFG_MODE_R ]) | +FIELD_PREP (ISC_WB_G_HI , ctrls->gain[ISC_HIS_CFG_MODE_GR ]));regmap_write (isc->regmap,ISC_WB_G_BGB , - ctrls->gain[ISC_HIS_CFG_MODE_B ] | - (ctrls->gain[ISC_HIS_CFG_MODE_GB ] <<16 )); +FIELD_PREP (ISC_WB_G_LO , ctrls->gain[ISC_HIS_CFG_MODE_B ]) | +FIELD_PREP (ISC_WB_G_HI , ctrls->gain[ISC_HIS_CFG_MODE_GB ])); }static inline void isc_reset_awb_ctrls (struct isc_device *isc)
drivers/media/platform/microchip/microchip-isc-regs.h +6 -0
@@ -149,6 +149,12 @@/* ISC White Balance Gain for B, GB Register */ #define ISC_WB_G_BGB 0x0000006c +/* Each WB offset/gain register packs two 13-bit fields, low and high */ +#define ISC_WB_O_LO GENMASK(12, 0)/* R or B offset [12:0] */ +#define ISC_WB_O_HI GENMASK(28, 16)/* GR or GB offset [28:16] */ +#define ISC_WB_G_LO GENMASK(12, 0)/* R or B gain [12:0] */ +#define ISC_WB_G_HI GENMASK(28, 16)/* GR or GB gain [28:16] */ +/* ISC Color Filter Array Control Register */ #define ISC_CFA_CTRL 0x00000070
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 150/686 media: require two-byte Cypress type 04 records
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit e22872703386c3885d8c6bd595124587bc4e5081 ]
Both Cypress Intel HEX parsers read two address bytes from type 04 records. Generic record framing permits any record length, so a short record can make the parser consume the checksum or bytes beyond the firmware record. A longer record also violates the Intel HEX type 04 layout.
Require the type 04 payload length to be exactly two bytes in both implementations.
--- drivers/media/common/cypress_firmware.c | 2 ++ drivers/media/usb/dvb-usb/dvb-usb-firmware.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/media/common/cypress_firmware.c +2 -0
@@ -59,6 +59,8 @@ static int cypress_get_hexline(const struct firmware *fw,if (hx->type ==0x04 ) {/* b[4] and b[5] are the Extended linear address record data * field */ +if (hx->len !=2 ) +return -EINVAL ; hx->addr |= (b[4 ] <<24 ) | (b[5 ] <<16 ); }
drivers/media/usb/dvb-usb/dvb-usb-firmware.c +2 -0
@@ -141,6 +141,8 @@ int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx,if (hx->type ==0x04 ) {/* b[4] and b[5] are the Extended linear address record data field */ +if (hx->len !=2 ) +return -EINVAL ; hx->addr |= (b[4 ] <<24 ) | (b[5 ] <<16 );/* hx->len -= 2; data_offs += 2; */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 151/686 media: adv748x: Fix endpoint reference leaks on probe failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 359db09cf055497075a668b192f4578a0ed00955 ]
adv748x_parse_dt() takes an extra reference for every endpoint saved in state->endpoints. If parsing later fails, adv748x_probe() skips adv748x_dt_cleanup(), so the saved references remain held. A CSI-2 lane parsing error also returns from for_each_endpoint_of_node() without dropping the iterator's reference.
Save the endpoint reference only after lane parsing succeeds. Drop the iterator reference before returning a lane parsing error and route all parse failures through the endpoint cleanup path to release any saved references. This retains the endpoints only for a successful probe.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/media/i2c/adv748x/adv748x-core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/i2c/adv748x/adv748x-core.c +7 -6
@@ -675,9 +675,6 @@ static int adv748x_parse_dt(struct adv748x_state *state)continue ; } -of_node_get (ep_np); - state->endpoints[ep.port] = ep_np; -/* * At least one input endpoint and one output endpoint shall * be defined.
@@ -689,8 +686,13 @@ static int adv748x_parse_dt(struct adv748x_state *state)/* Store number of CSI-2 lanes used for TXA and TXB. */ ret =adv748x_parse_csi2_lanes (state, ep.port, ep_np); -if (ret) +if (ret) { +of_node_put (ep_np);return ret; + } + +of_node_get (ep_np); + state->endpoints[ep.port] = ep_np; }return in_found && out_found ?0 : -ENODEV ;
@@ -739,7 +741,7 @@ static int adv748x_probe(struct i2c_client *client) ret =adv748x_parse_dt (state);if (ret) {adv_err (state,"Failed to parse device tree" ); - goto err_free_mutex; + goto err_cleanup_dt; }/* Configure IO Regmap region */
@@ -809,7 +811,6 @@ static int adv748x_probe(struct i2c_client *client)adv748x_unregister_clients (state); err_cleanup_dt:adv748x_dt_cleanup (state); -err_free_mutex:mutex_destroy (&state->mutex);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 152/686 hwmon: (lm70) Fix rounding of negative temperatures
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridham Khurana <[email protected]>
[ Upstream commit eddb0aaacce4baa9d8176eb2f4bd9e99e867f8fc ]
temp1_input_show() drops the low bits of the temperature register by dividing the raw value (raw / 32 on the LM70). These bits are not part of the temperature: the LM70, LM71, LM74 and TMP122/TMP124 always return some of them as 1, and the TMP125 fills them with copies of the temperature LSB. Division rounds toward zero, so a negative temperature with any of these bits set is reported one LSB too high.
For example, the TMP122 returns 0xffff for -0.0625 degrees C, which the driver reports as 0. The LM70 returns 0xf39f for -25 degrees C, which the driver reports as -24750.
Use an arithmetic right shift instead, which drops the low bits and rounds down.
--- drivers/hwmon/lm70.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/lm70.c +4 -4
@@ -97,21 +97,21 @@ static ssize_t temp1_input_show(struct device *dev,*/ switch (p_lm70->chip) {case LM70_CHIP_LM70 : - val = ((int )raw /32 ) *250 ; + val = ((int )raw >>5 ) *250 ;break ;case LM70_CHIP_TMP121 :case LM70_CHIP_TMP122 :case LM70_CHIP_LM74 : - val = ((int )raw /8 ) *625 /10 ; + val = ((int )raw >>3 ) *625 /10 ;break ;case LM70_CHIP_LM71 : - val = ((int )raw /4 ) *3125 /100 ; + val = ((int )raw >>2 ) *3125 /100 ;break ;case LM70_CHIP_TMP125 : - val = (sign_extend32 (raw,14 ) /32 ) *250 ; + val = (sign_extend32 (raw,14 ) >>5 ) *250 ;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 153/686 iio: pressure: dps310: fix CFG_REG bit definitions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rupesh Majhi <[email protected]>
[ Upstream commit 4334dc4092c271e6cd010c2ee70b7f4415c4c199 ]
Driver defines them as BIT(4), BIT(5) and BIT(6). Per datasheet P_SHIFT is bit 2, FIFO_EN is bit 1 and SPI_MODE is bit 0.
Only P_SHIFT has a user. dps310_set_pres_precision() sets it at oversampling 16 or above, so with wrong bit the result register is never shifted and stops matching the scale factor compensation divides by. in_pressure_input returns -ERANGE at oversampling 16, 32 and 64.
FIFO_EN needed by FIFO support later in this series.
--- drivers/iio/pressure/dps310.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/pressure/dps310.c +3 -3
@@ -50,9 +50,9 @@#define DPS310_CFG_REG 0x09#define DPS310_INT_HL BIT(7)#define DPS310_TMP_SHIFT_EN BIT(3) -#define DPS310_PRS_SHIFT_EN BIT(4) -#define DPS310_FIFO_EN BIT(5) -#define DPS310_SPI_EN BIT(6) +#define DPS310_PRS_SHIFT_EN BIT(2) +#define DPS310_FIFO_EN BIT(1) +#define DPS310_SPI_EN BIT(0)#define DPS310_RESET 0x0c#define DPS310_RESET_MAGIC 0x09#define DPS310_COEF_BASE 0x10
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 154/686 media: mediatek: jpeg: Avoid context access after job finish
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kazuki Hanai <[email protected]>
[ Upstream commit 7c7f31405b76acd95a628c834ee8a2d6da439782 ]
v4l2_m2m_job_finish() publishes job completion and wakes waiters before it returns. A concurrent file release can therefore finish v4l2_m2m_ctx_release() and free the context while the single-core IRQ handler continues with its tail.
Both handlers only need the device for the matching runtime PM put. Use the IRQ-owned jpeg pointer instead of dereferencing ctx after completion has been published. This preserves the get/put pairing and removes the post-completion context access.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +2 -2
@@ -1581,7 +1581,7 @@ static irqreturn_t mtk_jpeg_enc_done(struct mtk_jpeg_dev *jpeg)v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); -pm_runtime_put (ctx->jpeg->dev); +pm_runtime_put (jpeg->dev);return IRQ_HANDLED ; }
@@ -1869,7 +1869,7 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); -pm_runtime_put (ctx->jpeg->dev); +pm_runtime_put (jpeg->dev);return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 155/686 PCI/AER: Fix memory leak in aer_recover_work_func() when pci_dev is missing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Priyank Rathod <[email protected]>
[ Upstream commit d4c842c3af5bc52b3ca0b8a7f116114e43b6ba44 ]
When ACPI APEI/GHES processes PCIe AER error records, it allocates memory for aer_capability_regs (entry.regs) from ghes_estatus_pool and queues the entry into aer_recover_ring.
In aer_recover_work_func(), items are popped from aer_recover_ring via kfifo_get(). If pci_get_domain_bus_and_slot() fails to find a matching pci_dev, the code previously executed 'continue', bypassing the call to ghes_estatus_pool_region_free(). As a result, the memory allocated for entry.regs from ghes_estatus_pool was leaked.
This is reachable whenever the device reported by firmware is not (or is no longer) present in the PCI device tree, e.g. after hot-removal or when firmware reports an error for a device the kernel never enumerated.
Refactor aer_recover_work_func() to ensure ghes_estatus_pool_region_free() is called unconditionally for every dequeued entry, releasing the pool memory even when pci_dev is missing.
--- drivers/pci/pcie/aer.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/pci/pcie/aer.c +12 -11
@@ -1330,14 +1330,13 @@ static void aer_recover_work_func(struct work_struct *work)while (kfifo_get (&aer_recover_ring, &entry)) { pdev =pci_get_domain_bus_and_slot (entry.domain, entry.bus, entry.devfn); -if (!pdev) { +if (!pdev)pr_err_ratelimited ("%04x:%02x:%02x.%x: no pci_dev found\n" , entry.domain, entry.bus,PCI_SLOT (entry.devfn),PCI_FUNC (entry.devfn)); -continue ; - } -pci_print_aer (pdev, entry.severity, entry.regs); +else +pci_print_aer (pdev, entry.severity, entry.regs);/* * Memory for aer_capability_regs(entry.regs) is being
@@ -1349,13 +1348,15 @@ static void aer_recover_work_func(struct work_struct *work)ghes_estatus_pool_region_free ((unsigned long )entry.regs,sizeof (struct aer_capability_regs )); -if (entry.severity ==AER_NONFATAL ) -pcie_do_recovery (pdev, pci_channel_io_normal, - aer_root_reset); -else if (entry.severity ==AER_FATAL ) -pcie_do_recovery (pdev, pci_channel_io_frozen, - aer_root_reset); -pci_dev_put (pdev); +if (pdev) { +if (entry.severity ==AER_NONFATAL ) +pcie_do_recovery (pdev, pci_channel_io_normal, + aer_root_reset); +else if (entry.severity ==AER_FATAL ) +pcie_do_recovery (pdev, pci_channel_io_frozen, + aer_root_reset); +pci_dev_put (pdev); + } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 156/686 mm/memcontrol: fix data-race on reading jiffies_64
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit c20cf1c3c8cdd98618d6fcc794003a0e003ae858 ]
KCSAN reported a data-race between tick_do_update_jiffies64() updating jiffies_64 and mem_cgroup_flush_stats_ratelimited() reading it directly.
Unlike jiffies, jiffies_64 is not volatile, so raw reads are plain accesses and can even be torn on 32-bit. Use get_jiffies_64() instead, and fix the same pattern in mem_cgroup_flush_foreign().
--- mm/memcontrol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/memcontrol.c +3 -3
@@ -604,7 +604,7 @@ static void __mem_cgroup_flush_stats(struct mem_cgroup *memcg, bool force)return ;if (mem_cgroup_is_root (memcg)) -WRITE_ONCE (flush_last_time, jiffies_64); +WRITE_ONCE (flush_last_time,get_jiffies_64 ());css_rstat_flush (&memcg->css); }
@@ -632,7 +632,7 @@ void mem_cgroup_flush_stats(struct mem_cgroup *memcg)void mem_cgroup_flush_stats_ratelimited (struct mem_cgroup *memcg) {/* Only flush if the periodic flusher is one full cycle late */ -if (time_after64 (jiffies_64,READ_ONCE (flush_last_time) +2 *FLUSH_TIME )) +if (time_after64 (get_jiffies_64 (),READ_ONCE (flush_last_time) +2 *FLUSH_TIME ))mem_cgroup_flush_stats (memcg); }
@@ -3512,7 +3512,7 @@ void mem_cgroup_flush_foreign(struct bdi_writeback *wb) {struct mem_cgroup *memcg =mem_cgroup_from_css (wb->memcg_css);unsigned long intv =msecs_to_jiffies (dirty_expire_interval *10 ); -u64 now = jiffies_64; +u64 now =get_jiffies_64 ();int i;for (i =0 ; i <MEMCG_CGWB_FRN_CNT ; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 157/686 KVM: arm64: timers: Compute an offset-applied CVAL from the current count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 49930b1b557ceb698e0ab7f985ea41c99dc8bf22 ]
When the hardware won't apply a timer's offset, KVM programs CVAL + offset and lets it compare that against the raw counter. The compare is unsigned (IsTimerConditionMet, DDI0487M_c J1.4.3.29):
condition_met = (UInt(PhysicalCountInt() - offset) -
UInt(compare_value)) >= 0;so adding the offset to both sides holds only while both sums wrap or neither does. A guest whose counter is ahead of the host's by more than CVAL has an expired timer that never fires, and one behind it can have a far-future timer fire at once.
On a CNTPOFF_EL2 host the first case livelocks: each entry reloads the guest's CVAL, the timer fires, and the exit rewrites it as CVAL + offset before the host can take the interrupt. Without CNTPOFF_EL2 the timer hangs until the vCPU is next loaded, which is what Zenghui reported on a Kunpeng920.
Program the value from the current count instead: CVAL + offset while the deadline is ahead, 0 once the timer has expired for the guest, ~0 past the counter's wrap. KVM recomputes it at load, at exit and on a trapped CVAL write, and an expired timer stays expired in between. The value can't be inverted, so with an offset timer_save_state() keeps the memory copy, and kvm_hyp_handle_timer() returns that copy for a guest hypervisor's read of its physical CVAL rather than subtracting the offset back out.
--- arch/arm64/kvm/arch_timer.c | 27 ++++++++++++--------------- arch/arm64/kvm/hyp/vhe/switch.c | 11 ++++++----- include/kvm/arm_arch_timer.h | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 20 deletions(-)
arch/arm64/kvm/arch_timer.c +12 -15
@@ -502,17 +502,11 @@ static void timer_save_state(struct arch_timer_context *ctx) goto out;switch (index) { -u64 cval; -case TIMER_VTIMER :case TIMER_HVTIMER :timer_set_ctl (ctx,read_sysreg_el0 (SYS_CNTV_CTL )); - cval =read_sysreg_el0 (SYS_CNTV_CVAL ); - -if (has_broken_cntvoff ()) - cval -=timer_get_offset (ctx); - -timer_set_cval (ctx, cval); +if (!has_broken_cntvoff () || !timer_get_offset (ctx)) +timer_set_cval (ctx,read_sysreg_el0 (SYS_CNTV_CVAL ));/* Disable the timer */ write_sysreg_el0 (0 ,SYS_CNTV_CTL );
@@ -538,11 +532,12 @@ static void timer_save_state(struct arch_timer_context *ctx)case TIMER_PTIMER :case TIMER_HPTIMER :timer_set_ctl (ctx,read_sysreg_el0 (SYS_CNTP_CTL )); - cval =read_sysreg_el0 (SYS_CNTP_CVAL ); - - cval -=timer_get_offset (ctx); - -timer_set_cval (ctx, cval); +/* +* With an offset, memory already holds the guest's CVAL (the +* trap handler or __deactivate_traps() wrote it). +*/ +if (!timer_get_offset (ctx)) +timer_set_cval (ctx,read_sysreg_el0 (SYS_CNTP_CVAL ));/* Disable the timer */ write_sysreg_el0 (0 ,SYS_CNTP_CTL );
@@ -621,7 +616,8 @@ static void timer_restore_state(struct arch_timer_context *ctx) offset =timer_get_offset (ctx);if (has_broken_cntvoff ()) {set_cntvoff (0 ); - cval += offset; +if (offset) + cval =timer_apply_offset (cval, offset,kvm_phys_timer_read ()); }else {set_cntvoff (offset); }
@@ -634,7 +630,8 @@ static void timer_restore_state(struct arch_timer_context *ctx) cval =timer_get_cval (ctx); offset =timer_get_offset (ctx);set_cntpoff (offset); - cval += offset; +if (offset) + cval =timer_apply_offset (cval, offset,kvm_phys_timer_read ());write_sysreg_el0 (cval,SYS_CNTP_CVAL );isb ();write_sysreg_el0 (timer_get_ctl (ctx),SYS_CNTP_CTL );
arch/arm64/kvm/hyp/vhe/switch.c +6 -5
@@ -169,7 +169,8 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) offset =read_sysreg_s (SYS_CNTPOFF_EL2 );if (map.direct_ptimer && offset) { -write_sysreg_el0 (val + offset,SYS_CNTP_CVAL ); + val =timer_apply_offset (val, offset,arch_timer_read_cntpct_el0 ()); +write_sysreg_el0 (val,SYS_CNTP_CVAL );isb (); } }
@@ -290,10 +291,10 @@ static bool kvm_hyp_handle_timer(struct kvm_vcpu *vcpu, u64 *exit_code)break ;case SYS_CNTP_CVAL_EL0 :if (vcpu_el2_e2h_is_set (vcpu)) { - val =read_sysreg_el0 (SYS_CNTP_CVAL ); - -if (!has_cntpoff ()) - val -=timer_get_offset (vcpu_hptimer (vcpu)); +if (!has_cntpoff () &&timer_get_offset (vcpu_hptimer (vcpu))) + val =__vcpu_sys_reg (vcpu,CNTHP_CVAL_EL2 ); +else + val =read_sysreg_el0 (SYS_CNTP_CVAL ); }else { val =__vcpu_sys_reg (vcpu,CNTP_CVAL_EL0 ); }
include/kvm/arm_arch_timer.h +15 -0
@@ -186,4 +186,19 @@ static inline void timer_set_offset(struct arch_timer_context *ctxt, u64 offset) WRITE_ONCE(*ctxt->offset.vm_offset, offset); } +/* +* CVAL to program when the hardware won't apply the timer's offset, so that +* its compare against the raw counter matches the guest's at 'now'. An +* expired timer stays expired; one past the wrap never fires. +*/ +static inline u64 timer_apply_offset (u64 cval,u64 offset,u64 now) +{ +u64 hw = cval + offset; + +if (now - offset >= cval) +return 0 ; + +return hw > now ? hw :U64_MAX ; +} +#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 158/686 wifi: mt76: take rcu_read_lock in the USB/SDIO tx completion path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit a7871a7ae5a8625f0ba0a89454ac734c383dd538 ]
The USB and SDIO completion path reads a station pointer that RCU protects, without holding the read lock. Lockdep catches it on the first association:
mt76.h:1305 suspicious rcu_dereference_check() usage! no locks held by mt76-usb-status/1254.
mt7925_usb_sdio_tx_complete_skb+0x119/0x130 [mt7925_common] mt76_queue_tx_complete+0x27/0x60 [mt76] mt76u_status_worker+0xed/0x1e0 [mt76_usb]
mt7925/mac.c:856 suspicious rcu_dereference_check() usage!
mt7925_tx_check_aggr.part.0+0xc2/0xe0 [mt7925_common] mt7925_usb_sdio_tx_complete_skb+0xa0/0x130 [mt7925_common]
mt7921 does the same, and warns once instead of twice because its aggregation check reads the default link directly. The DMA path makes the same reads but completes from softirq, so it stays quiet.
Take the read lock around the lookup and the check.
Tested on 7.2-rc5 with lockdep, fresh module load per arm, 4000 packets each and no change to the link:
splats before after
MT7925 Netgear A9000 2 0
MT7921 Alfa 1 0
mt7921e same kernel 0 0
--- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 3 +++ drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 3 +++ 2 files changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7921/mac.c +3 -0
@@ -826,11 +826,14 @@ void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,u16 idx; idx =le32_get_bits (txwi[1 ],MT_TXD1_WLAN_IDX ); + +rcu_read_lock (); wcid =__mt76_wcid_ptr (mdev, idx); sta =wcid_to_sta (wcid);if (sta &&likely (e->skb->protocol !=cpu_to_be16 (ETH_P_PAE )))mt76_connac2_tx_check_aggr (sta, txwi); +rcu_read_unlock ();skb_pull (e->skb, headroom);mt76_tx_complete_skb (mdev, e->wcid, e->skb);
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +3 -0
@@ -1476,11 +1476,14 @@ void mt7925_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,u16 idx; idx =le32_get_bits (txwi[1 ],MT_TXD1_WLAN_IDX ); + +rcu_read_lock (); wcid =__mt76_wcid_ptr (mdev, idx); sta =wcid_to_sta (wcid);if (sta &&likely (e->skb->protocol !=cpu_to_be16 (ETH_P_PAE )))mt7925_tx_check_aggr (sta, e->skb, wcid); +rcu_read_unlock ();skb_pull (e->skb, headroom);mt76_tx_complete_skb (mdev, e->wcid, e->skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 159/686 mm/page_counter: avoid integer overflow in effective_protection()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridong Chen <[email protected]>
[ Upstream commit 7809ce47b05671e1fa6d74bead892d6ad6c1403b ]
Patch series "mm/mglru: fix ineffective memory protection for non-kswapd reclaim", v4.
For MGLRU, memory.min/low is not honored during non-kswapd global reclaim (global direct reclaim and root-level memory.reclaim), because these paths shrink memcgs using stale protection (emin/elow).
Patch 2 is the actual fix. Patch 1 is a prerequisite: an integer overflow in effective_protection(), spotted by the sashiko review tool, which patch 2's new caller would also be exposed to.
This patch (of 2):
effective_protection() scales a parent's protection by a ratio of page counts, e.g. for recursive protection:
(parent_effective - siblings_protected) * (usage - protected)
/ (parent_usage - siblings_protected)
The multiply is done at unsigned long width before dividing. On systems with >= 16TB RAM the product can exceed 2^64 and wrap, giving a bogus protection value and silently breaking memory.min/low enforcement.
Use mul_u64_u64_div_u64() to multiply in a 128-bit intermediate. Because usage and parent_usage are not read atomically (a child is charged before its parent), usage - protected can briefly exceed the divisor, making the quotient overflow 64 bits and trap (#DE on x86). Cap it so the ratio stays <= 1.
Reported by the sashiko review tool [1].
--- mm/page_counter.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
mm/page_counter.c +15 -6
@@ -8,6 +8,7 @@#include <linux/page_counter.h> #include <linux/atomic.h> #include <linux/kernel.h> +#include <linux/math64.h> #include <linux/string.h> #include <linux/sched.h> #include <linux/bug.h>
@@ -356,7 +357,8 @@ static unsigned long effective_protection(unsigned long usage,* otherwise get a smaller chunk than what they claimed. */ if (siblings_protected > parent_effective) -return protected * parent_effective / siblings_protected; +return mul_u64_u64_div_u64 (protected, parent_effective, + siblings_protected);/* * Ok, utilized protection of all children is within what the
@@ -397,13 +399,20 @@ static unsigned long effective_protection(unsigned long usage,if (parent_effective > siblings_protected && parent_usage > siblings_protected && usage > protected) { -unsigned long unclaimed; +unsigned long parent_unclaimed, parent_unprotected, unprotected; - unclaimed = parent_effective - siblings_protected; - unclaimed *= usage - protected; - unclaimed /= parent_usage - siblings_protected; + parent_unclaimed = parent_effective - siblings_protected; + parent_unprotected = parent_usage - siblings_protected; - ep += unclaimed; +/* +* The usages aren't read atomically, so a child can transiently +* appear to use more than its parent, making the ratio exceed 1 +* and the quotient overflow 64 bits (#DE on x86). Cap it. +*/ + unprotected =min (usage - protected, parent_unprotected); + + ep +=mul_u64_u64_div_u64 (parent_unclaimed, unprotected, + parent_unprotected); }return ep;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 160/686 ACPI: APEI: accumulate the queued flag across error sections
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit f341307a14895e5da056fb419a31ef7fb534ab18 ]
ghes_do_proc() walks every error section of a CPER record, and ghes_handle_arm_hw_error() walks every error-info entry of an ARM processor section. Both assign to "queued" instead of OR-ing into it, so only the last iteration counts: a later section or entry that queues no memory-failure work clears the flag an earlier one set.
Instead of reassigning the variable at every time, just do an OR, so, if there was a single match, it will return "queued" as set.
The comment above the check says "If no memory failure
work is queued", which is the semantics this patch implements. I.e, only SIGBUS if there are queue was not handled at all. If we want to SIGBUS if any event was not handled/queued at all, we will need something more sophisticated.
--- drivers/acpi/apei/ghes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/apei/ghes.c +3 -3
@@ -608,7 +608,7 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,* and don't filter out 'corrected' error here. */ if (is_cache && has_pa) { - queued =ghes_do_memory_failure (err_info->physical_fault_addr, flags); + queued |=ghes_do_memory_failure (err_info->physical_fault_addr, flags); p += err_info->length;continue ; }
@@ -925,11 +925,11 @@ static void ghes_do_proc(struct ghes *ghes,atomic_notifier_call_chain (&ghes_report_chain, sev, mem_err);arch_apei_report_mem_error (sev, mem_err); - queued =ghes_handle_memory_failure (gdata, sev, sync); + queued |=ghes_handle_memory_failure (gdata, sev, sync); }else if (guid_equal (sec_type, &CPER_SEC_PCIE )) {ghes_handle_aer (gdata); }else if (guid_equal (sec_type, &CPER_SEC_PROC_ARM )) { - queued =ghes_handle_arm_hw_error (gdata, sev, sync); + queued |=ghes_handle_arm_hw_error (gdata, sev, sync); }else if (guid_equal (sec_type, &CPER_SEC_CXL_PROT_ERR )) {struct cxl_cper_sec_prot_err *prot_err =acpi_hest_get_payload (gdata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 161/686 fbdev: core: Initialize modelist in framebuffer_alloc()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrey Misiurov <[email protected]>
[ Upstream commit 0c9cb9321cb3863b52bdea4b8ae5a27705762c9e ]
framebuffer_alloc() returns zeroed memory, so info->modelist starts out with NULL next and prev pointers. The list head is initialized only later, by fb_videomode_to_modelist() or by do_register_framebuffer().
The "fix potential memory leak" commits listed below added fb_destroy_modelist(&info->modelist) to the probe error paths of s3fb, tdfxfb, tridentfb, i740fb and carminefb. These paths can run before the list head is initialized:
- s3fb, tdfxfb, tridentfb and i740fb call fb_videomode_to_modelist() only after a successful EDID read, and tridentfb can also hit the error path on an ioremap() or kmalloc() failure before that;
- carminefb jumps to the error path when fb_find_mode() fails, before its fb_videomode_to_modelist() call.
fb_destroy_modelist() then dereferences the NULL head. Reproduced on Debian 12 (6.1.180) by binding s3fb to a VGA device without EDID and forcing fb_alloc_cmap() to fail:
s3fb 0000:00:03.0: cannot allocate colormap
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:fb_destroy_modelist+0x10/0x80 Call Trace: s3_pci_probe.cold+0x12b/0x2bf [s3fb] local_pci_probe+0x41/0x80 pci_device_probe+0xc3/0x240 really_probe+0xde/0x380 __driver_probe_device+0x84/0x150 driver_probe_device+0x1f/0x90 __driver_attach+0xce/0x1c0 bus_for_each_dev+0x87/0xd0 bus_add_driver+0x1ae/0x200 driver_register+0x89/0xe0 do_one_initcall+0x59/0x220 do_init_module+0x4a/0x1f0
Initialize the list head in framebuffer_alloc(), so info->modelist is always a valid, possibly empty, list and fb_destroy_modelist() is safe on every error path. Keep the lazy initialization in do_register_framebuffer(), as drivers that embed struct fb_info rather than calling framebuffer_alloc() still depend on it.
--- drivers/video/fbdev/core/fb_info.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/core/fb_info.c +1 -0
@@ -43,6 +43,7 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev) info->device = dev; info->fbcon_rotate_hint =-1 ; info->blank =FB_BLANK_UNBLANK ; +INIT_LIST_HEAD (&info->modelist);#if IS_ENABLED (CONFIG_FB_BACKLIGHT )mutex_init (&info->bl_curve_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 162/686 mfd: ab8500: Fix child device leaks on probe failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 5bf2ae8b131d4ae9c0ed5f7aa02532645f512022 ]
ab8500_probe() registers MFD child devices before completing the remaining device initialization. If a later MFD registration or sysfs group creation fails, previously registered child devices are not removed.
Use devm_mfd_add_devices() so registered MFD child devices are removed when probe fails.
The issue was identified by a static analysis tool I developed and confirmed by manual review.
--- drivers/mfd/ab8500-core.c | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-)
drivers/mfd/ab8500-core.c +23 -21
@@ -1194,39 +1194,41 @@ static int ab8500_probe(struct platform_device *pdev)return ret;if (is_ab9540 (ab8500)) - ret =mfd_add_devices (ab8500->dev,0 , ab9540_devs, -ARRAY_SIZE (ab9540_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab9540_devs, +ARRAY_SIZE (ab9540_devs),NULL , +0 , ab8500->domain);else if (is_ab8540 (ab8500)) { - ret =mfd_add_devices (ab8500->dev,0 , ab8540_devs, -ARRAY_SIZE (ab8540_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8540_devs, +ARRAY_SIZE (ab8540_devs),NULL , +0 , ab8500->domain);if (ret)return ret;if (is_ab8540_1p2_or_earlier (ab8500)) - ret =mfd_add_devices (ab8500->dev,0 , ab8540_cut1_devs, -ARRAY_SIZE (ab8540_cut1_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , + ab8540_cut1_devs, +ARRAY_SIZE (ab8540_cut1_devs), +NULL ,0 , ab8500->domain);else /* ab8540 >= cut2 */ - ret =mfd_add_devices (ab8500->dev,0 , ab8540_cut2_devs, -ARRAY_SIZE (ab8540_cut2_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , + ab8540_cut2_devs, +ARRAY_SIZE (ab8540_cut2_devs), +NULL ,0 , ab8500->domain); }else if (is_ab8505 (ab8500)) - ret =mfd_add_devices (ab8500->dev,0 , ab8505_devs, -ARRAY_SIZE (ab8505_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8505_devs, +ARRAY_SIZE (ab8505_devs),NULL , +0 , ab8500->domain);else - ret =mfd_add_devices (ab8500->dev,0 , ab8500_devs, -ARRAY_SIZE (ab8500_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8500_devs, +ARRAY_SIZE (ab8500_devs),NULL , +0 , ab8500->domain);if (ret)return ret;/* Add battery management devices */ - ret =mfd_add_devices (ab8500->dev,0 , ab8500_bm_devs, -ARRAY_SIZE (ab8500_bm_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8500_bm_devs, +ARRAY_SIZE (ab8500_bm_devs),NULL , +0 , ab8500->domain);if (ret)dev_err (ab8500->dev,"error adding bm devices\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 163/686 Bluetooth: selftest: Pin module for selftest debugfs file operations
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bui Viet Dung <[email protected]>
[ Upstream commit 64aabf94ecccb1120a63b4ee5a6761871a181a41 ]
An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, test_smp_fops in net/bluetooth/smp.c and test_ecdh_fops in net/bluetooth/selftest.c have no .owner set to THIS_MODULE.
As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth module. When CONFIG_BT=m and selftests are enabled, a userspace process can open either /sys/kernel/debug/bluetooth/selftest_smp or /sys/kernel/debug/bluetooth/selftest_ecdh and keep the file descriptor open while the module is unloaded (rmmod bluetooth).
When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release():
BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: <TASK> __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
The issue was discovered via manual code audit of net/bluetooth/smp.c and net/bluetooth/selftest.c.
Set .owner = THIS_MODULE on test_smp_fops and test_ecdh_fops so that debugfs keeps the module pinned until the file descriptors are closed.
--- net/bluetooth/selftest.c | 1 + net/bluetooth/smp.c | 1 + 2 files changed, 2 insertions(+)
net/bluetooth/selftest.c +1 -0
@@ -191,6 +191,7 @@ static ssize_t test_ecdh_read(struct file *file, char __user *user_buf, }static const struct file_operations test_ecdh_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = test_ecdh_read, .llseek = default_llseek,
net/bluetooth/smp.c +1 -0
@@ -3735,6 +3735,7 @@ static ssize_t test_smp_read(struct file *file, char __user *user_buf, }static const struct file_operations test_smp_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = test_smp_read, .llseek = default_llseek,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 164/686 cxl/events: Test CME counter expiry with equality, not bitwise AND
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit b94ba9a1f2d5c57f2eec67d502bb8fdd1e53c87a ]
The Memory Event Type field in the General Media and DRAM event records is an enumeration, not a bitmask. The validity checks for the advanced programmable CME counter expiration event (05h) test the field with a bitwise AND, so types 01h, 03h, 04h and 06h match it as well.
A device reporting one of those types trips WARN_ON_ONCE once the general media or DRAM tracepoint is enabled, which is the case anywhere rasdaemon collects CXL events. Under panic_on_warn=1 that kills the machine.
Compare the type field for equality instead. Type 05h records that do violate the spec conditions still warn.
--- drivers/cxl/core/mbox.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/core/mbox.c +4 -4
@@ -934,11 +934,11 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,if (evt->gen_media.media_hdr.descriptor &CXL_GMER_EVT_DESC_THRESHOLD_EVENT ) -WARN_ON_ONCE ((evt->gen_media.media_hdr.type & +WARN_ON_ONCE ((evt->gen_media.media_hdr.type ==CXL_GMER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ) && !get_unaligned_le24 (evt->gen_media.cme_count));else -WARN_ON_ONCE (evt->gen_media.media_hdr.type & +WARN_ON_ONCE (evt->gen_media.media_hdr.type ==CXL_GMER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ); trace_cxl_general_media(cxlmd, type, cxlr, hpa,
@@ -949,11 +949,11 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,if (evt->dram.media_hdr.descriptor &CXL_GMER_EVT_DESC_THRESHOLD_EVENT ) -WARN_ON_ONCE ((evt->dram.media_hdr.type & +WARN_ON_ONCE ((evt->dram.media_hdr.type ==CXL_DER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ) && !get_unaligned_le24 (evt->dram.cvme_count));else -WARN_ON_ONCE (evt->dram.media_hdr.type & +WARN_ON_ONCE (evt->dram.media_hdr.type ==CXL_DER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ); trace_cxl_dram(cxlmd, type, cxlr, hpa, hpa_alias,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 165/686 tracing: Add the bucket size to expr_field_str()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit c027ed03bc03a0e82fc368eaad657584a4480c7a ]
expr_field_str() renders a HIST_FIELD_FL_BUCKET field as "pid.buckets", dropping the count, and parse_field() rejects that spelling.
get_hist_field_flags() returns the bare string "buckets" and keeps the count in hist_field->buckets. hist_field_print() appends it, expr_field_str() never did. Nothing reaches it today, since .buckets is refused on a value and no expression can carry one, but the next patch renders histogram keys with expr_field_str(), where a .buckets key is legal.
Append the count, as hist_field_print() does.
--- kernel/trace/trace_events_hist.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_events_hist.c +3 -0
@@ -1757,6 +1757,9 @@ static bool expr_field_str(struct hist_field *field, struct seq_buf *s)seq_buf_printf (s,".%s" , flags_str); } +if (field->buckets) +seq_buf_printf (s,"=%lu" , field->buckets); +return !seq_buf_has_overflowed (s); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 166/686 net: erspan: set lltx to avoid sch_direct_xmit deadlock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Zhou <[email protected]>
[ Upstream commit 2d36ec73836e83175deb467fd494c61006107e5d ]
The ERSPAN xmit path re-enters the network stack, causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock, creating an ABBA deadlock. This happens for both IPv4 ERSPAN (erspan_xmit() -> ip_tunnel_xmit()) and IPv6 ERSPAN (ip6erspan_tunnel_xmit() -> ip6_tnl_xmit()):
sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit -> ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]
sch_direct_xmit [lock erspan] -> ip6erspan_tunnel_xmit -> ip6_tnl_xmit -> ip6_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]
Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as the ERSPAN xmit path has no shared mutable state: o_seqno is atomic, TX stats are per-CPU u64_stats, dst_cache is per-CPU, and o_flags is no longer modified in the xmit path since commit 9958e69b9893 ("gre: fix ERSPAN o_flags race/corruption in xmit and fill_info"). GRETAP, the sibling device with identical xmit structure, already sets lltx.
--- net/ipv4/ip_gre.c | 1 + net/ipv6/ip6_gre.c | 1 + 2 files changed, 2 insertions(+)
net/ipv4/ip_gre.c +1 -0
@@ -1366,6 +1366,7 @@ static int erspan_tunnel_init(struct net_device *dev) dev->features |=GRE_FEATURES ; dev->hw_features |=GRE_FEATURES ; dev->priv_flags |=IFF_LIVE_ADDR_CHANGE ; + dev->lltx = true;netif_keep_dst (dev);return ip_tunnel_init (dev);
net/ipv6/ip6_gre.c +1 -0
@@ -1863,6 +1863,7 @@ static int ip6erspan_tap_init(struct net_device *dev) dev->mtu -=8 ; dev->priv_flags |=IFF_LIVE_ADDR_CHANGE ; + dev->lltx = true;ip6erspan_tnl_link_config (tunnel,1 );netdev_hold (dev, &tunnel->dev_tracker,GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 167/686 rds: fix out-of-bounds conn_path walks via handshake exthdrs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Martin <[email protected]>
[ Upstream commit 50f2103fce43922b6e562937b2d2fc62089ff7ec ]
Both the lane and the connection-generation negotiation are driven by extension headers in handshake packets, and both are processed unconditionally, even on transports that are not multipath capable. A non-MP connection (t_mp_capable unset) owns exactly one rds_conn_path slot, so a peer claiming up to RDS_MPATH_WORKERS lanes makes every subsequent fan-out walk conn->c_path[0..7] at 504-byte strides past the single allocated slot (KASAN: "Read of size 8 in rds_conn_path_connect_if_down"); the generation negotiation opens a similar out-of-bounds walk on the same array.
Only process handshake extension headers when the connection's transport is multipath capable, so a peer can never make us walk lanes that do not exist. Both call sites in rds_recv_incoming() are gated.
This is a port of the Oracle UEK fix for the same issue, picked up where Paula's series of the same change left off.
This issue was discovered by Tencent CodeBuddy Security.
--- net/rds/recv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/rds/recv.c +4 -2
@@ -343,7 +343,8 @@ void rds_recv_incoming(struct rds_connection *conn, struct in6_addr *saddr,rds_stats_inc (s_recv_ping);rds_send_pong (cp, inc->i_hdr.h_sport);/* if this is a handshake ping, start multipath if necessary */ -if (RDS_HS_PROBE (be16_to_cpu (inc->i_hdr.h_sport), +if (conn->c_trans->t_mp_capable && +RDS_HS_PROBE (be16_to_cpu (inc->i_hdr.h_sport),be16_to_cpu (inc->i_hdr.h_dport))) {rds_recv_hs_exthdrs (&inc->i_hdr, cp->cp_conn);rds_start_mprds (cp->cp_conn);
@@ -351,7 +352,8 @@ void rds_recv_incoming(struct rds_connection *conn, struct in6_addr *saddr, goto out; } -if (be16_to_cpu (inc->i_hdr.h_dport) ==RDS_FLAG_PROBE_PORT && +if (conn->c_trans->t_mp_capable && +be16_to_cpu (inc->i_hdr.h_dport) ==RDS_FLAG_PROBE_PORT && inc->i_hdr.h_sport ==0 ) {rds_recv_hs_exthdrs (&inc->i_hdr, cp->cp_conn);/* if this is a handshake pong, start multipath if necessary */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 168/686 gpio: pca953x: Preserve wakeup accounting on parent IRQ failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sahaj Chaudhari <[email protected]>
[ Upstream commit a38bf551726a21c9bcc001b02164f30378b64b64 ]
pca953x_irq_set_wake() updates wakeup_path before asking the parent IRQ controller to change its wake state. If irq_set_irq_wake() fails, the IRQ core rolls back its wake state but the driver's counter remains changed.
A failed enable can therefore leave the expander marked as part of the wakeup path when no child IRQ has successfully enabled wakeup. A failed disable can make the driver stop retaining power even though wakeup is still enabled. The suspend and resume paths use this counter to decide whether to disable or enable the regulator.
Update wakeup_path only after the parent operation succeeds, leaving it unchanged on error.
--- drivers/gpio/gpio-pca953x.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpio/gpio-pca953x.c +6 -1
@@ -839,13 +839,18 @@ static int pca953x_irq_set_wake(struct irq_data *d, unsigned int on) {struct gpio_chip *gc =irq_data_get_irq_chip_data (d);struct pca953x_chip *chip =gpiochip_get_data (gc); +int ret; + + ret =irq_set_irq_wake (chip->client->irq, on); +if (ret) +return ret;if (on)atomic_inc (&chip->wakeup_path);else atomic_dec (&chip->wakeup_path); -return irq_set_irq_wake (chip->client->irq, on); +return 0 ; }static void pca953x_irq_bus_lock (struct irq_data *d)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 169/686 f2fs: dont use truncate_inode_pages_final() on live inodes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daeho Jeong <[email protected]>
[ Upstream commit 74bbd6ada01f91fcad60608e0417bf45a9fa99e6 ]
truncate_inode_pages_final() is meant to be called from ->evict_inode. It sets AS_EXITING on the mapping, and nothing ever clears it, to tell the VM that the inode is going away.
f2fs calls it in two places where the inode stays live:
- F2FS_IOC_START_ATOMIC_REPLACE uses it to drop the page cache of the original inode before setting i_size to 0. The atomic write then goes on through this inode.
- f2fs_abort_atomic_write() uses it to drop the uncommitted data. It is called on eviction, but also on the last writer's close in f2fs_release_file(), from f2fs_file_flush() when the atomic writer exits, from F2FS_IOC_ABORT_ATOMIC_WRITE and when F2FS_IOC_COMMIT_ATOMIC_WRITE fails.
Other processes may still have the file open or mapped in all of these cases. The mapping then stays marked as exiting for as long as the inode is in memory. This stops reclaim from storing workingset shadow entries for it and breaks any code that assumes an exiting mapping has no users left.
All we need in both places is to drop the page cache, so use truncate_inode_pages(mapping, 0) instead. The eviction path is not affected, because f2fs_pre_evict_inode() still calls truncate_inode_pages_final() after f2fs_abort_atomic_write().
--- fs/f2fs/file.c | 2 +- fs/f2fs/segment.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/file.c +1 -1
@@ -2431,7 +2431,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) fi->original_i_size = isize;if (truncate) {set_inode_flag (inode,FI_ATOMIC_REPLACE ); -truncate_inode_pages_final (inode->i_mapping); +truncate_inode_pages (inode->i_mapping,0 );f2fs_i_size_write (inode,0 ); isize =0 ; }
fs/f2fs/segment.c +1 -1
@@ -193,7 +193,7 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean)return ;if (clean) -truncate_inode_pages_final (inode->i_mapping); +truncate_inode_pages (inode->i_mapping,0 );release_atomic_write_cnt (inode);clear_inode_flag (inode,FI_ATOMIC_COMMITTED );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 170/686 scsi: ufs: bsg: Validate request_len before accessing request
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Jhu <[email protected]>
[ Upstream commit 42aa443718104d10dbdb6f258810b425eb2451f8 ]
ufs_bsg_request() and ufs_bsg_exec_advanced_rpmb_req() read the request buffer without checking job->request_len, which userspace controls. A short request causes an out-of-bounds read. Found by syzkaller.
Reject requests shorter than the structure each path reads.
--- drivers/ufs/core/ufs_bsg.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/ufs/core/ufs_bsg.c +9 -0
@@ -79,6 +79,9 @@ static int ufs_bsg_exec_advanced_rpmb_req(struct ufs_hba *hba, struct bsg_job *jif (hba->ufs_version <ufshci_version (4 ,0 ) || !hba->dev_info.b_advanced_rpmb_en)return -EINVAL ; +if (job->request_len <sizeof (*rpmb_request)) +return -EINVAL ; +if (rpmb_request->ehs_req.length !=2 || rpmb_request->ehs_req.ehs_type !=1 )return -EINVAL ;
@@ -144,6 +147,11 @@ static int ufs_bsg_request(struct bsg_job *job)memset (job->reply,0 , job->reply_len); +if (job->request_len <sizeof (*bsg_request)) { + ret = -EINVAL ; + goto out_complete; + } +ufshcd_rpm_get_sync (hba); msgcode = bsg_request->msgcode;
@@ -193,6 +201,7 @@ static int ufs_bsg_request(struct bsg_job *job) out:ufshcd_rpm_put_sync (hba);kfree (buff); +out_complete: bsg_reply->result = ret;if (ret ==0 ) job->reply_len = rpmb ? sizeof(struct ufs_rpmb_reply) :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 171/686 scsi: ufs: bsg: Reject UIC commands with a non-zero result byte
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Jhu <[email protected]>
[ Upstream commit 1ae42513205a38b811afedb6797f9f9c4de37b90 ]
ufs_bsg_request() passes the user-supplied UIC argument2 unchanged, including the result byte (bits 7:0) that only the host controller writes. A non-zero value triggers the WARN_ON_ONCE() in ufshcd_dispatch_uic_cmd() and corrupts the reported result. Found by syzkaller.
Reject UIC commands that have the result byte set with -EINVAL.
--- drivers/ufs/core/ufs_bsg.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/ufs/core/ufs_bsg.c +4 -0
@@ -178,6 +178,10 @@ static int ufs_bsg_request(struct bsg_job *job)break ;case UPIU_TRANSACTION_UIC_CMD :memcpy (&uc, &bsg_request->upiu_req.uc,UIC_CMD_SIZE ); +if (uc.argument2 &MASK_UIC_COMMAND_RESULT ) { + ret = -EINVAL ; +break ; + } ret =ufshcd_send_bsg_uic_cmd (hba, &uc);if (ret)dev_err (hba->dev,"send uic cmd: error code %d\n" , ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 172/686 scsi: handle out-of-range SG_SET_TIMEOUT values
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingjie Wang <[email protected]>
[ Upstream commit 9a6cb1da4f3bc4633bf6669faed25a361834b1b9 ]
SG_SET_TIMEOUT accepts a signed int in USER_HZ units. The sg character device rejects negative values and limits positive values so the converted timeout fits its destination field. The block SCSI and BSG paths instead pass the value to clock_t_to_jiffies(), which accepts an unsigned long, and store the result in an unsigned int.
Negative values are converted into large unsigned timeouts. On 64-bit systems, large positive values can also exceed UINT_MAX after conversion and are truncated on assignment. With HZ=1000 and USER_HZ=100, for example, 429496730 clock ticks become 4294967300 jiffies and are stored as 4 jiffies. On 32-bit systems, an overflowing conversion becomes ULONG_MAX, which is an unsafe relative interval for the block timer comparisons.
Reject negative values with -EIO, matching drivers/scsi/sg.c. Saturate the converted value at the smaller of the destination field limit and MAX_JIFFY_OFFSET. This preserves successful ioctl behavior while avoiding both narrowing wraparound and an unsafe 32-bit timer interval.
The block SCSI behavior predates Git history. BSG has exposed the same behavior since it was introduced.
--- block/bsg.c | 5 ++++- drivers/scsi/scsi_ioctl.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-)
block/bsg.c +4 -1
@@ -130,7 +130,10 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case SG_SET_TIMEOUT :if (get_user (val, intp))return -EFAULT ; - bd->timeout =clock_t_to_jiffies (val); +if (val <0 ) +return -EIO ; + bd->timeout =min (clock_t_to_jiffies (val), +min (UINT_MAX ,MAX_JIFFY_OFFSET ));return 0 ;case SG_GET_TIMEOUT :return jiffies_to_clock_t (bd->timeout);
drivers/scsi/scsi_ioctl.c +8 -3
@@ -9,6 +9,7 @@#include <linux/blkdev.h> #include <linux/interrupt.h> #include <linux/errno.h> +#include <linux/jiffies.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/mm.h>
@@ -192,10 +193,14 @@ static int sg_set_timeout(struct scsi_device *sdev, int __user *p) {int timeout, err =get_user (timeout, p); -if (!err) - sdev->sg_timeout =clock_t_to_jiffies (timeout); +if (err) +return err; +if (timeout <0 ) +return -EIO ; -return err; + sdev->sg_timeout =min (clock_t_to_jiffies (timeout), +min (UINT_MAX ,MAX_JIFFY_OFFSET )); +return 0 ; }static int sg_get_reserved_size (struct scsi_device *sdev,int __user *p)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 173/686 posix-timers: Accept NULL clock_getres() output in stubs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 5b819071e4346256c4edbae5cc2095dff25694fc ]
With CONFIG_POSIX_TIMERS disabled, clock_getres() returns -EFAULT for a supported clock when the result pointer is NULL. POSIX permits a NULL result pointer to suppress returning the clock resolution.
Only copy the result when a destination is provided, in both the native and time32 stubs. This matches the full POSIX timer implementation and preserves clock ID validation.
--- kernel/time/posix-stubs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/posix-stubs.c +2 -2
@@ -83,7 +83,7 @@ SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct __kernel_timecase CLOCK_REALTIME :case CLOCK_MONOTONIC :case CLOCK_BOOTTIME : -if (put_timespec64 (&rtn_tp, tp)) +if (tp &&put_timespec64 (&rtn_tp, tp))return -EFAULT ;return 0 ;default :
@@ -166,7 +166,7 @@ SYSCALL_DEFINE2(clock_getres_time32, clockid_t, which_clock,case CLOCK_REALTIME :case CLOCK_MONOTONIC :case CLOCK_BOOTTIME : -if (put_old_timespec32 (&rtn_tp, tp)) +if (tp &&put_old_timespec32 (&rtn_tp, tp))return -EFAULT ;return 0 ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 174/686 tick/nohz: Reevaluate the tick for kicks flushed outside hardirq
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peng Wang <[email protected]>
[ Upstream commit e389ae428847a2e6a3b698b5967df68ccf90361c ]
The nohz full kick relies on interrupt exit to reevaluate the tick. However, a remote kick can also be flushed from task context without an interrupt exit guaranteed to follow. If a tick dependency is set or an earlier timer is queued after the idle-exit reevaluation, the required tick update can be delayed until another interrupt.
Reevaluate the tick directly from the callback outside hardirq context. Keep the existing interrupt exit handling for hardirq callbacks. The offline flush remains harmless because tick_sched_timer_dying() has already cleared TS_FLAG_NOHZ.
--- kernel/time/tick-sched.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/time/tick-sched.c +13 -1
@@ -377,9 +377,21 @@ static bool can_stop_full_tick(int cpu, struct tick_sched *ts)return true; } +static void tick_nohz_full_update_tick (struct tick_sched *ts); +static void nohz_full_kick_func (struct irq_work *work) { -/* Empty, the tick restart happens on tick_nohz_irq_exit() */ +struct tick_sched *ts =this_cpu_ptr (&tick_cpu_sched); + +if (WARN_ON_ONCE (!tick_nohz_full_cpu (smp_processor_id ()))) +return ; + +/* Task-context flushes may not be followed by an IRQ exit. */ +if (!in_hardirq ()) { +if (WARN_ON_ONCE (tick_sched_flag_test (ts,TS_FLAG_INIDLE ))) +return ; +tick_nohz_full_update_tick (ts); + } } static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 175/686 ipmr, ip6mr: validate packets injected into the register vif on xmit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit aa1799e93f5ebb973252aec649d84d12d9c7fd1c ]
reg_vif_xmit() passes the packet to ipmr_cache_report() which copies its IP header into the IGMPMSG_WHOLEPKT report that is queued to the mroute socket. Nothing guarantees that the packet contains a full IP header, so when a short packet is injected on the register device (e.g., using AF_PACKET), the copy reads past the end of the packet and a recvmsg() on the mroute socket leaks the uninitialized bytes to user space [1].
IPv6 has the same problem [2]. Its reg_vif_xmit() does call pskb_inet_may_pull(), but the helper keys off skb->protocol and does not pull anything when the protocol is neither IPv4 nor IPv6.
Fix by dropping packets whose protocol does not match the address family of the register device or that do not contain a full network header.
[1]
BUG: KMSAN: kernel-infoleak in _copy_to_iter raw_recvmsg
Uninit was stored to memory at:
ipmr_cache_report
reg_vif_xmit
packet_sendmsg
Uninit was created at:
__alloc_skb
sock_alloc_send_pskb
packet_sendmsg
Bytes 1-3 of 21 are uninitialized
[2]
BUG: KMSAN: kernel-infoleak in _copy_to_iter rawv6_recvmsg
Uninit was stored to memory at:
ip6mr_cache_report
reg_vif_xmit
packet_sendmsg
Uninit was created at:
__alloc_skb
sock_alloc_send_pskb
packet_sendmsg
Bytes 8-23 of 41 are uninitialized
--- net/ipv4/ipmr.c | 6 ++++++ net/ipv6/ip6mr.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
net/ipv4/ipmr.c +6 -0
@@ -530,6 +530,12 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) };int err; +if (skb->protocol !=htons (ETH_P_IP ) || !pskb_inet_may_pull (skb)) { +DEV_STATS_INC (dev, tx_errors); +kfree_skb (skb); +return NETDEV_TX_OK ; + } +rcu_read_lock (); err =ipmr_fib_lookup (net, &fl4, &mrt);if (err <0 ) {
net/ipv6/ip6mr.c +1 -1
@@ -620,7 +620,7 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, .flowi6_mark = skb->mark, }; -if (!pskb_inet_may_pull (skb)) +if (skb->protocol !=htons (ETH_P_IPV6 ) || !pskb_inet_may_pull (skb)) goto tx_err;if (ip6mr_fib_lookup (net, &fl6, &mrt) <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 176/686 ipmr: drop packets with unknown ingress VIF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 09280680f2ea060514be2a39ea84209fb6d721d4 ]
A packet can race with VIF publication and make ipmr_find_vif() return -1 even though the VIF device pointer is already visible. The parent VIF device check can then pass with an invalid ingress VIF. For (*,G) entries, this can also let the packet be forwarded back out its ingress VIF.
Drop packets whose ingress VIF lookup fails in both IPv4 and IPv6 forwarding, before checking the MFC parent device. This prevents forwarding with an unknown ingress VIF and avoids the (*,G) hairpin.
Without the early check, the negative index can reach the IPv4 offload lookup only for an skb marked for L3 forwarding offload, currently done by mlxsw. The race is rare; the supplied PoC reports only the UBSAN negative-index diagnostic.
--- net/ipv4/ipmr.c | 3 ++- net/ipv6/ip6mr.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/ipmr.c +2 -1
@@ -2052,7 +2052,8 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, }/* Wrong interface: drop packet and (maybe) send PIM assert. */ -if (rcu_access_pointer (mrt->vif_table[vif].dev) != dev) { +if (true_vifi <0 || +rcu_access_pointer (mrt->vif_table[vif].dev) != dev) {if (rt_is_output_route (skb_rtable (skb))) {/* It is our own packet, looped back. * Very complicated situation...
net/ipv6/ip6mr.c +2 -1
@@ -2173,7 +2173,8 @@ static void ip6_mr_forward(struct net *net, struct mr_table *mrt,/* * Wrong interface: drop packet and (maybe) send PIM assert. */ -if (rcu_access_pointer (mrt->vif_table[vif].dev) != dev) { +if (true_vifi <0 || +rcu_access_pointer (mrt->vif_table[vif].dev) != dev) {atomic_long_inc (&c->_c.mfc_un.res.wrong_if); if (true_vifi >= 0 && mrt->mroute_do_assert &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 177/686 tg3: Invert restart quirk logic to restrict SNP power-down bypass
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Noam D. Eliyahu <[email protected]>
[ Upstream commit d7314b51341c037973ce022f12c6009fd07b021e ]
Commit 9fc3bc764334 ("tg3: power down device only on SYSTEM_POWER_OFF") bypassed tg3_power_down() on system restarts to prevent reboot hangs and NMIs on servers where NICs were initialized via SNP (such as Dell PowerEdge R650 and R750).
However, skipping the power-down flow globally causes the ACPI _PTS method to trigger fatal PCIe AER events and hangs on other models. Commit e0efe83ed325 ("tg3: Disable tg3 PCIe AER on system reboot") attempted to mitigate this by adding an AER-disable DMI quirk table. Maintaining a growing list of models for a secondary symptom misses the root cause, leaving systems like the PowerEdge T440 (sharing the BCM5720 NIC) exposed.
Fix this by inverting the quirk logic:
1. Restrict SNP power-down avoidance strictly to tg3_restart_snp_quirk_table for the specific systems requiring it (Dell PowerEdge R650 and R750).
2. Restore standard power-down behavior for all other systems, eliminating the separate AER-disable quirk table.
For systems affected by the original SNP restart issue, their shutdown flow remains completely untouched.
--- drivers/net/ethernet/broadcom/tg3.c | 42 ++++++++--------------------- 1 file changed, 11 insertions(+), 31 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +11 -31
@@ -18201,41 +18201,17 @@ static int tg3_resume(struct device *device) static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); -/* Systems where ACPI _PTS (Prepare To Sleep) S5 will result in a fatal -* PCIe AER event on the tg3 device if the tg3 device is not, or cannot -* be, powered down. +/* Systems where powering down a tg3 device on restarts triggers +* NMIs and fatal hangs during reboot if the network adapters were +* initialized under SNP. */ -static const struct dmi_system_id tg3_restart_aer_quirk_table[] = { - { - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Dell Inc." ), -DMI_MATCH (DMI_PRODUCT_NAME ,"PowerEdge R440" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Dell Inc." ), -DMI_MATCH (DMI_PRODUCT_NAME ,"PowerEdge R540" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Dell Inc." ), -DMI_MATCH (DMI_PRODUCT_NAME ,"PowerEdge R640" ), - }, - }, +static const struct dmi_system_id tg3_restart_snp_quirk_table[] = { { .matches = {DMI_MATCH (DMI_SYS_VENDOR ,"Dell Inc." ),DMI_MATCH (DMI_PRODUCT_NAME ,"PowerEdge R650" ), }, }, - { - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Dell Inc." ), -DMI_MATCH (DMI_PRODUCT_NAME ,"PowerEdge R740" ), - }, - }, { .matches = {DMI_MATCH (DMI_SYS_VENDOR ,"Dell Inc." ),
@@ -18259,14 +18235,18 @@ static void tg3_shutdown(struct pci_dev *pdev)if (netif_running (dev))dev_close (dev); -if (system_state ==SYSTEM_POWER_OFF ) +if (!dmi_first_match (tg3_restart_snp_quirk_table) || + system_state ==SYSTEM_POWER_OFF ) {tg3_power_down (tp); -else if (system_state ==SYSTEM_RESTART && -dmi_first_match (tg3_restart_aer_quirk_table) && + }else if (system_state ==SYSTEM_RESTART && pdev->current_state != PCI_D3cold && pdev->current_state !=PCI_UNKNOWN ) {/* Disable PCIe AER on the tg3 to avoid a fatal * error during this system restart. +* Needed since on restarts for systems in +* tg3_restart_snp_quirk_table skipping on powering down the +* tg3 device causes a fatal AER error during ACPI _PTS +* (Prepare To Sleep). */ pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_CERE |
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 178/686 ns: dont add init_ipc_ns and init_net without namespace support
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 82f1c815aaef1905c5c6c386c8a0d74f6ff70a54 ]
When CONFIG_IPC_NS or CONFIG_NET_NS are turned off we still add the initial ipc and network namespace to the namespace trees. ipc_ns_init() calls ns_tree_add(&init_ipc_ns) whenever CONFIG_SYSVIPC is set and setup_net() calls ns_tree_add_raw() on init_net whenever CONFIG_NET is set.
But without CONFIG_IPC_NS and CONFIG_NET_NS these aren't namespaces userspace can do anything with. They don't have proc_ns_operations so there's no /proc/<pid>/ns/{ipc,net} for them, nsfs_fh_to_dentry() refuses them with -EOPNOTSUPP, and since ns->ops is NULL __ns_tree_add_raw() doesn't add them to the owner list of init_user_ns either. So they end up half registered. That's also not how we treat any of the other namespace types. Without CONFIG_UTS_NS, CONFIG_PID_NS, CONFIG_TIME_NS or CONFIG_USER_NS the initial namespace is never added to the tree.
listns() walks the unified tree and calls is_current_namespace() for every namespace it finds via may_list_ns(). But is_current_namespace() only knows about CLONE_NEWIPC and CLONE_NEWNET if CONFIG_IPC_NS and CONFIG_NET_NS are set. Otherwise we end up in the default case and its VFS_WARN_ON_ONCE(). Any unprivileged caller can trigger that with a plain listns() call:
WARNING: CPU: 0 PID: 526 at fs/nsfs.c:508 is_current_namespace+0x12f/0x440 Call Trace: legitimize_ns+0x25f/0x4c0 do_listns+0x185/0x5c0 __do_sys_listns+0x13b/0x300
Instead of teaching is_current_namespace() about namespaces that can't be opened, only add the initial namespaces to the tree if their namespace type is enabled. Move the registration of init_ipc_ns into ipc/namespace.c which is only built with CONFIG_IPC_NS. That also fixes CONFIG_SYSVIPC=n, CONFIG_POSIX_MQUEUE=y, CONFIG_IPC_NS=y where ipc/shm.c isn't built and init_ipc_ns was never added at all. For the network namespace only call ns_tree_add_raw() if CONFIG_NET_NS is set. Without CONFIG_NET_NS cleanup_net() isn't built and init_net is never removed so there's nothing to balance.
--- ipc/namespace.c | 7 +++++++ ipc/shm.c | 2 -- net/core/net_namespace.c | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-)
ipc/namespace.c +7 -0
@@ -254,3 +254,10 @@ const struct proc_ns_operations ipcns_operations = { .install = ipcns_install, .owner = ipcns_owner, }; + +static int __init ipc_ns_tree_init (void ) +{ +ns_tree_add (&init_ipc_ns); +return 0 ; +} +pure_initcall (ipc_ns_tree_init);
ipc/shm.c +0 -2
@@ -45,7 +45,6 @@#include <linux/mount.h> #include <linux/ipc_namespace.h> #include <linux/rhashtable.h> -#include <linux/nstree.h> #include <linux/uaccess.h>
@@ -149,7 +148,6 @@ void shm_exit_ns(struct ipc_namespace *ns)static int __init ipc_ns_init (void ) {shm_init_ns (&init_ipc_ns); -ns_tree_add (&init_ipc_ns);return 0 ; }
net/core/net_namespace.c +3 -1
@@ -442,7 +442,9 @@ static __net_init int setup_net(struct net *net)down_write (&net_rwsem);list_add_tail_rcu (&net->list, &net_namespace_list);up_write (&net_rwsem); -ns_tree_add_raw (net); +/* Without CONFIG_NET_NS init_net isn't exposed as a namespace. */ +if (IS_ENABLED (CONFIG_NET_NS )) +ns_tree_add_raw (net); out:return error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 179/686 net/9p/usbg: fix prefix matching in device lookup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
[ Upstream commit 9ee83ef8d24f11feb55fd0d222c0ec19f09dbd3f ]
p9_usbg_create() matches the mount source against registered usb9pfs instance tags with strncmp() and the length of the caller supplied source. That accepts any prefix of the registered tag.
For example, a gadget instance tagged "secret_channel" can be selected with "s", "sec", or any other non-empty prefix. Once selected, the instance is marked in use and the client is attached to that transport. This differs from the configfs tag lookup path, which uses strcmp() and therefore requires an exact tag match.
Require an exact tag match in p9_usbg_create() as well.
Message-ID: <[email protected]>
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/9p/trans_usbg.c +1 -1
@@ -389,7 +389,7 @@ static int p9_usbg_create(struct p9_client *client, const char *devname, char *aguard (mutex)(&usb9pfs_lock);list_for_each_entry (dev, &usbg_instance_list, usb9pfs_instance) { -if (!strncmp (devname, dev->tag,strlen (devname))) { +if (!strcmp (devname, dev->tag)) {if (!dev->inuse) { dev->inuse = true; found =1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 180/686 xfrm: retry inexact policy lookup after node reinsertion
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit 868f63c8bfafa9b827168c9126f85264c39c02ec ]
An inexact policy lookup first records pointers to candidate hlist heads and then traverses the lists. A concurrent policy insertion can merge inexact tree nodes between those operations:
lookup policy insertion
------ ----------------
find inexact candidates
save obsolete hlist head
write_seqcount_begin(&bin->count)
merge inexact tree nodes
hlist_del_rcu(&policy->bydst)
reinsert policy->bydst in survivor
write_seqcount_end(&bin->count) evaluate saved candidate list
miss the moved policy
The merge immediately reinserts the same hlist node into the surviving tree node. RCU keeps the policy alive, but it does not provide a consistent view while its list node is moved. A lookup that selected the obsolete list can observe it empty. A lookup already traversing a moved policy can instead follow the next pointer rewritten by the reinsertion. Either case can return an incorrect IPsec policy result.
The per-bin sequence counter already brackets calls to xfrm_policy_inexact_insert_node(), including node merges. The read side, however, currently validates the counter only while searching an individual rb-tree. A successful search returns without validation, and the later candidate-list traversal is outside that read-side section.
Snapshot the per-bin sequence before discovering candidate heads and
validate it after evaluating all candidate lists. Retry the lookup if
the inexact policy tree changes while it is being searched.
--- net/xfrm/xfrm_policy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/xfrm/xfrm_policy.c +9 -2
@@ -2157,6 +2157,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,struct xfrm_pol_inexact_bin *bin;struct xfrm_policy *pol, *ret;struct hlist_head *chain; +unsigned int inexact_sequence;unsigned int sequence;int err;
@@ -2191,12 +2192,18 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, goto skip_inexact; bin =xfrm_policy_inexact_lookup_rcu (net, type, family, dir, if_id); -if (!bin || !xfrm_policy_find_inexact_candidates (&cand, bin, saddr, - daddr)) +if (!bin) + goto skip_inexact; + + inexact_sequence =read_seqcount_begin (&bin->count); +if (!xfrm_policy_find_inexact_candidates (&cand, bin, saddr, daddr)) goto skip_inexact; pol =xfrm_policy_eval_candidates (&cand, ret, fl, type, family, if_id); +if (read_seqcount_retry (&bin->count, inexact_sequence)) + goto retry; +if (pol) { ret = pol;if (IS_ERR (pol))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 181/686 net/9p/usbg: clear stale request context after abort
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit b58943dd690eb9b76c652e735789937a03f3d30c ]
usb9pfs_clear_tx() serializes access to the active TX request with usb9pfs->lock, but leaves in_req->context pointing at the request after p9_client_cb() drops the transport reference. A later teardown path can therefore retrieve the same request after it has been freed:
CPU 0 (p9_usbg_close) CPU 1 (usb9pfs_disable)
lock(usb9pfs->lock)
req = in_req->context
p9_client_cb(client, req)
p9_req_put(client, req)
unlock(usb9pfs->lock)
request reaches zero refs
kmem_cache_free(req)
lock(usb9pfs->lock)
req = in_req->context
read req->t_errThe lock orders the two callbacks, but cannot protect a pointer that remains published after its reference has been released. KASAN reported:
BUG: KASAN: slab-use-after-free in usb9pfs_clear_tx+0x166/0x1b0 Read of size 4 at addr ffff88810e7420f4 by task poc/94 Call Trace: usb9pfs_clear_tx+0x166/0x1b0 usb9pfs_disable+0x1d/0x30 reset_config+0x9d/0x200 __composite_disconnect+0xa7/0x140 Allocated by task 93: kmem_cache_alloc_noprof+0x141/0x370 p9_tag_alloc+0x8f/0x5b0 p9_client_prepare_req+0xff/0x350 p9_client_rpc+0x1a5/0xac0 Freed by task 0: slab_free_after_rcu_debug+0xa6/0x1e0 rcu_core+0x50a/0x1850 Last potentially related work creation: kmem_cache_free+0x1db/0x3d0 p9_req_put+0x164/0x1f0 usb9pfs_clear_tx+0x120/0x1b0 p9_usbg_close+0x7e/0x150
Clear in_req->context after the callback while still holding the lock. This matches the consume-and-clear pattern in usb9pfs_tx_complete(), so subsequent teardown calls return without touching the released request. The existing callback and error ordering remain unchanged.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 1 + 1 file changed, 1 insertion(+)
net/9p/trans_usbg.c +1 -0
@@ -437,6 +437,7 @@ static void usb9pfs_clear_tx(struct f_usb9pfs *usb9pfs) req->t_err = -ECONNRESET ;p9_client_cb (usb9pfs->client, req,REQ_STATUS_ERROR ); + usb9pfs->in_req->context =NULL ; }static void p9_usbg_close (struct p9_client *client)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 182/686 9p/trans_virtio: reject mount tags longer than NAME_MAX at probe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 5bfef2b6dafe83fe2d8d210d54093a8f48cfc97e ]
p9_virtio_probe() reads a 16-bit mount tag length (tag_len) from the device config and kzalloc()s tag_len + 1 bytes for chan->tag with no upper bound. A malicious or compromised host can present a tag of up to 65535 bytes; that tag is later copied into the single-page sysfs buffer by p9_mount_tag_show() (memcpy(buf, chan->tag, tag_len + 1)), a host-controlled out-of-bounds write of up to ~64 KiB past the PAGE_SIZE attribute buffer.
Reject an overlong tag at probe time. A 9p mount tag is a name-like identifier, so bound it by NAME_MAX (255): that limit is independent of the sysfs/seq_file page size and is far above any legitimate mount tag, which keeps p9_mount_tag_show() safe at the root without hard-coding a seq_file implementation detail.
Message-ID: <[email protected]>
--- net/9p/trans_virtio.c | 5 +++++ 1 file changed, 5 insertions(+)
net/9p/trans_virtio.c +5 -0
@@ -629,6 +629,11 @@ static int p9_virtio_probe(struct virtio_device *vdev) err = -EINVAL ; goto out_free_vq; } +if (tag_len >NAME_MAX ) { +dev_err (&vdev->dev,"mount tag too long (%u bytes)\n" , tag_len); + err = -EINVAL ; + goto out_free_vq; + } tag =kzalloc (tag_len +1 ,GFP_KERNEL );if (!tag) { err = -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 183/686 9p/xen: fix refcount leak in p9_xen_response() on wrong tag
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifei Gao <[email protected]>
[ Upstream commit 4d183e6f153245aca2534e372152583b868dd925 ]
p9_xen_response() looks up the request for an incoming reply with p9_tag_lookup(), which takes a reference on the returned p9_req_t. When the tag does not resolve to a request in REQ_STATUS_SENT, the function warns and continues the loop without dropping that reference, permanently leaking the p9_req_t and its msize buffers. The reply header, including the tag, is supplied by the backend, so a malicious or buggy 9P backend can leak kernel memory on every crafted response.
Drop the reference before continuing.
Message-ID: <[email protected]>
--- net/9p/trans_xen.c | 2 ++ 1 file changed, 2 insertions(+)
net/9p/trans_xen.c +2 -0
@@ -201,6 +201,8 @@ static void p9_xen_response(struct work_struct *work) req =p9_tag_lookup (priv->client, h.tag);if (!req || req->status !=REQ_STATUS_SENT ) {dev_warn (&priv->dev->dev,"Wrong req tag=%x\n" , h.tag); +if (req) +p9_req_put (priv->client, req); cons += h.size;virt_mb (); ring->intf->in_cons = cons;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 184/686 9p: fix caches_show() out-of-bounds write
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Zhang <[email protected]>
[ Upstream commit 2acd800de8827b7cdce8cb5c2c63b8e8608ec8e3 ]
The sysfs show handler for /sys/fs/9p/caches appends cache tags with snprintf(buf + count, limit, ...) and then advances count and limit by the return value. This is incorrect for truncation because snprintf() returns the full would-have-been length, not the number of bytes stored.
Once the accumulated output exceeds PAGE_SIZE, count can advance past the sysfs buffer and limit can become negative. A later iteration then passes an out-of-bounds destination pointer and an oversized size_t into snprintf(), leading to an out-of-bounds write.
Use sysfs_emit_at() for the append instead. It follows the sysfs buffer contract and returns the number of bytes actually stored, so the offset remains bounded even when the output is truncated.
Message-ID: <abfb65f4800634dafb08238bba20cb48797e796f.1781908090.git.zzhan461@ucr.edu>
--- fs/9p/v9fs.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
fs/9p/v9fs.c +5 -11
@@ -16,6 +16,7 @@#include <linux/parser.h> #include <linux/slab.h> #include <linux/seq_file.h> +#include <linux/sysfs.h> #include <net/9p/9p.h> #include <net/9p/client.h> #include <net/9p/transport.h>
@@ -554,21 +555,14 @@ static ssize_t caches_show(struct kobject *kobj,struct kobj_attribute *attr, char *buf) { - ssize_t n = 0, count = 0, limit = PAGE_SIZE; + ssize_t count = 0;struct v9fs_session_info *v9ses;spin_lock (&v9fs_sessionlist_lock);list_for_each_entry (v9ses, &v9fs_sessionlist, slist) { -if (v9ses->cachetag) { - n =snprintf (buf + count, limit,"%s\n" , v9ses->cachetag); -if (n <0 ) { - count = n; -break ; - } - - count += n; - limit -= n; - } +if (v9ses->cachetag) + count +=sysfs_emit_at (buf, count,"%s\n" , + v9ses->cachetag); }spin_unlock (&v9fs_sessionlist_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 185/686 net/9p/usbg: Fix use-after-free in disable_usb9pfs()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
[ Upstream commit 6f401e350939442b2ac905f7e5ac952e3802a5d8 ]
disable_usb9pfs() frees the IN and OUT usb_request objects before it disables the corresponding endpoints. If either request is still queued, the later usb_ep_disable() call cancels the endpoint queue and the UDC driver can still access the already freed request.
With dummy_hcd and KASAN, this is reproducible by queueing the OUT request and then disconnecting the configfs gadget:
BUG: KASAN: slab-use-after-free in dummy_disable+0x2b4/0x300 Read of size 8 at addr ffff888009702400 by task sh/1 usb_ep_disable+0x8e/0x1f0 usb9pfs_func_unbind+0x193/0x350 gadget_dev_desc_UDC_store+0x135/0x280
dummy_free_request() also warns because the request is freed while its queue entry is still linked.
Disable both endpoints before freeing the request objects. This lets usb_ep_disable() cancel any queued transfers and invoke the completion callback while the request storage is still valid. The request objects are then freed only after they have been removed from the endpoint queues.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/9p/trans_usbg.c +3 -3
@@ -277,6 +277,9 @@ static void disable_usb9pfs(struct f_usb9pfs *usb9pfs)struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; +disable_ep (cdev, usb9pfs->in_ep); +disable_ep (cdev, usb9pfs->out_ep); +if (usb9pfs->in_req) {usb_ep_free_request (usb9pfs->in_ep, usb9pfs->in_req); usb9pfs->in_req =NULL ;
@@ -286,9 +289,6 @@ static void disable_usb9pfs(struct f_usb9pfs *usb9pfs)usb_ep_free_request (usb9pfs->out_ep, usb9pfs->out_req); usb9pfs->out_req =NULL ; } - -disable_ep (cdev, usb9pfs->in_ep); -disable_ep (cdev, usb9pfs->out_ep);dev_dbg (&cdev->gadget->dev,"%s disabled\n" , usb9pfs->function.name); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 186/686 net/9p/usbg: also disable endpoints on p9_usbg_close
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Grzeschik <[email protected]>
[ Upstream commit f81cdb9164806eb2df1e1c6df402e03bff7dde31 ]
The close function has to fully reverse the state change of 9p_create (mount) and the potential call of set_alt(1). This includes to ensure that the usage of the endpoints is not active any more.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 2 ++ 1 file changed, 2 insertions(+)
net/9p/trans_usbg.c +2 -0
@@ -465,6 +465,8 @@ static void p9_usbg_close(struct p9_client *client)mutex_lock (&usb9pfs_lock); dev->inuse = false;mutex_unlock (&usb9pfs_lock); + +disable_usb9pfs (usb9pfs); }static int p9_usbg_request (struct p9_client *client,struct p9_req_t *p9_req)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 187/686 net/9p/usbg: set client to Disconnected on usb9pfs_disable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Grzeschik <[email protected]>
[ Upstream commit 795f8eeca01d1c9ca3d9a450385b7745ace4e53a ]
This patch is setting the client status to Disconnected, when the client is still in use. Otherwise a disconnected usb cable would run any use of the mount to faults.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 5 +++++ 1 file changed, 5 insertions(+)
net/9p/trans_usbg.c +5 -0
@@ -748,7 +748,12 @@ static int usb9pfs_set_alt(struct usb_function *f,static void usb9pfs_disable (struct usb_function *f) {struct f_usb9pfs *usb9pfs =func_to_usb9pfs (f); +unsigned long flags; +spin_lock_irqsave (&usb9pfs->lock, flags); +if (usb9pfs->client) + usb9pfs->client->status = Disconnected; +spin_unlock_irqrestore (&usb9pfs->lock, flags);usb9pfs_clear_tx (usb9pfs); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 188/686 net/9p/usbg: always reset completion when disconnecting
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Grzeschik <[email protected]>
[ Upstream commit 08c6b9f484a406d9d87c5b2580725d2e0597f3b9 ]
When some tx or rx transfers were pending while closing the connection, the completion handler could catch one pending completion call. To ensure a normal start when mounting again, we have to reset the completion and flush any pending completions.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 2 ++ 1 file changed, 2 insertions(+)
net/9p/trans_usbg.c +2 -0
@@ -467,6 +467,7 @@ static void p9_usbg_close(struct p9_client *client)mutex_unlock (&usb9pfs_lock);disable_usb9pfs (usb9pfs); +reinit_completion (&usb9pfs->send); }static int p9_usbg_request (struct p9_client *client,struct p9_req_t *p9_req)
@@ -755,6 +756,7 @@ static void usb9pfs_disable(struct usb_function *f) usb9pfs->client->status = Disconnected;spin_unlock_irqrestore (&usb9pfs->lock, flags);usb9pfs_clear_tx (usb9pfs); +reinit_completion (&usb9pfs->send); }static struct usb_function *usb9pfs_alloc (struct usb_function_instance *fi)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 189/686 net/9p/usbg: call disable_usb9pfs() from usb9pfs_disable()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Grzeschik <[email protected]>
[ Upstream commit cd1988cf723c2eae87112b198bf90b0aebfeaf31 ]
usb9pfs_disable() is the usb_function ->disable callback, invoked by the composite gadget core whenever the host resets or unconfigures the gadget. The gadget function API requires this callback to disable its endpoints; every other in-tree function driver does so from its ->disable hook.
usb9pfs_disable() never called disable_usb9pfs(), so the IN/OUT endpoints and their usb_request objects were left active and allocated across a host-driven disable. When the host later reconfigures the device, enable_usb9pfs() calls alloc_requests() again and unconditionally overwrites usb9pfs->in_req/out_req, permanently leaking the previous allocations, while the endpoints themselves are left enabled underneath the function's own idea of being disabled.
Call disable_usb9pfs() before reinit_completion(&usb9pfs->send), mirroring the same sequence already used in p9_usbg_close(). Placing it before the reinit_completion() also ensures usb_ep_disable() has synchronously flushed any requests still queued in hardware before the completion is reset, closing the same race that motivated resetting the completion here in the first place.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/9p/trans_usbg.c +4 -0
@@ -756,6 +756,10 @@ static void usb9pfs_disable(struct usb_function *f) usb9pfs->client->status = Disconnected;spin_unlock_irqrestore (&usb9pfs->lock, flags);usb9pfs_clear_tx (usb9pfs); + +if (usb9pfs->in_ep->enabled) +disable_usb9pfs (usb9pfs); +reinit_completion (&usb9pfs->send); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 190/686 net/9p/usbg: fix out_req buffer leak in disable_usb9pfs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Grzeschik <[email protected]>
[ Upstream commit 5f9807270c7bda8f86b312ed1a8acd7716600555 ]
usb9pfs->out_req is allocated with alloc_ep_req(), which also allocates the request's data buffer (req->buf). disable_usb9pfs() frees it with plain usb_ep_free_request(), which only frees the usb_request structure itself and leaks req->buf on every close.
Use free_ep_req() instead, matching the allocator, as documented by its own comment ("Requests allocated via alloc_ep_req() *must* be freed by free_ep_req()").
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/9p/trans_usbg.c +1 -1
@@ -286,7 +286,7 @@ static void disable_usb9pfs(struct f_usb9pfs *usb9pfs) }if (usb9pfs->out_req) { -usb_ep_free_request (usb9pfs->out_ep, usb9pfs->out_req); +free_ep_req (usb9pfs->out_ep, usb9pfs->out_req); usb9pfs->out_req =NULL ; } dev_dbg(&cdev->gadget->dev, "%s disabled\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 191/686 net/9p/usbg: remove bogus context initialization in alloc_requests
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Grzeschik <[email protected]>
[ Upstream commit bbdb38b2e543ffa72dca5450f2535cf998ef1cdd ]
alloc_requests() initializes usb9pfs->in_req->context to point at the struct f_usb9pfs instance itself. usb9pfs_queue_tx() later overwrites this with the real struct p9_req_t pointer before every transmit, and usb9pfs_tx_complete() clears it back to NULL after each completion, so in_req->context only ever holds a valid p9_req_t once a request has actually been queued.
usb9pfs_clear_tx(), however, can run at any time (mount close, gadget disable) independent of whether a request was ever queued. If it runs before the first usb9pfs_transmit(), it reads the leftover sentinel value, type-confuses the struct f_usb9pfs pointer as a struct p9_req_t, and both writes through it (req->t_err = -ECONNRESET) and hands it to p9_client_cb(), which manipulates req->wq and req->refcount at bogus offsets inside f_usb9pfs. This reliably corrupts memory or panics whenever the transport is torn down before any 9p request has been transmitted, e.g. mounting and immediately unmounting, or a cable disconnect racing the very first request.
usb9pfs->out_req->context is set the same way but is never read by this transport (usb9pfs_rx_complete() identifies the instance via ep->driver_data instead), so it serves no purpose either.
Both endpoints' ->driver_data are already set to usb9pfs in enable_endpoint(), which is what the completion handlers actually use to recover the f_usb9pfs instance. Just drop the leftover ->context assignments; usb_ep_alloc_request()/alloc_ep_req() already return zeroed requests, so in_req->context correctly starts out NULL.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 4 ---- 1 file changed, 4 deletions(-)
net/9p/trans_usbg.c +0 -4
@@ -313,10 +313,6 @@ static int alloc_requests(struct usb_composite_dev *cdev, usb9pfs->in_req->complete = usb9pfs_tx_complete; usb9pfs->out_req->complete = usb9pfs_rx_complete; -/* length will be set in complete routine */ - usb9pfs->in_req->context = usb9pfs; - usb9pfs->out_req->context = usb9pfs; -return 0 ; fail_in:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 192/686 net/9p/usbg: clear stale client pointer on close
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyungjung Joo <[email protected]>
[ Upstream commit a478958f4c1181ff3362f8857b489c2d069f9c7d ]
p9_usbg_close() tears down the client transport, but usb9pfs keeps using usb9pfs->client from asynchronous TX and RX completion handlers. A late completion can therefore dereference a client that has already been freed during mount teardown.
Clear usb9pfs->client under usb9pfs->lock when closing the transport, detach any pending TX request from in_req->context, and make the TX/RX completion handlers bail out once the transport has been detached. This keeps late completions from touching a freed or rebound p9_client.
Message-ID: <[email protected]>
--- net/9p/trans_usbg.c | 61 +++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 16 deletions(-)
net/9p/trans_usbg.c +45 -16
@@ -148,7 +148,8 @@ static void usb9pfs_tx_complete(struct usb_ep *ep, struct usb_request *req) {struct f_usb9pfs *usb9pfs = ep->driver_data;struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; -struct p9_req_t *p9_tx_req = req->context; +struct p9_client *client; +struct p9_req_t *p9_tx_req;unsigned long flags;/* reset zero packages */
@@ -164,18 +165,25 @@ static void usb9pfs_tx_complete(struct usb_ep *ep, struct usb_request *req) ep->name, req->status, req->actual, req->length);spin_lock_irqsave (&usb9pfs->lock, flags); -WRITE_ONCE (p9_tx_req->status,REQ_STATUS_SENT ); + client = usb9pfs->client; + p9_tx_req = req->context; + req->context =NULL ; -p9_req_put (usb9pfs->client, p9_tx_req); +if (!client || !p9_tx_req) + goto unlock_complete; - req->context =NULL ; +WRITE_ONCE (p9_tx_req->status,REQ_STATUS_SENT ); +p9_req_put (client, p9_tx_req); + +unlock_complete:spin_unlock_irqrestore (&usb9pfs->lock, flags);complete (&usb9pfs->send); } -static struct p9_req_t *usb9pfs_rx_header (struct f_usb9pfs *usb9pfs,void *buf) +static struct p9_req_t *usb9pfs_rx_header (struct f_usb9pfs *usb9pfs, +struct p9_client *client,void *buf) {struct p9_req_t *p9_rx_req;struct p9_fcall rc;
@@ -201,7 +209,7 @@ static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf)"mux %p pkt: size: %d bytes tag: %d\n" , usb9pfs, rc.size, rc.tag); - p9_rx_req =p9_tag_lookup (usb9pfs->client, rc.tag); + p9_rx_req =p9_tag_lookup (client, rc.tag);if (!p9_rx_req || p9_rx_req->status !=REQ_STATUS_SENT ) {p9_debug (P9_DEBUG_ERROR ,"Unexpected packet tag %d\n" , rc.tag);return NULL ;
@@ -211,7 +219,7 @@ static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf)p9_debug (P9_DEBUG_ERROR ,"requested packet size too big: %d for tag %d with capacity %zd\n" , rc.size, rc.tag, p9_rx_req->rc.capacity); -p9_req_put (usb9pfs->client, p9_rx_req); +p9_req_put (client, p9_rx_req);return NULL ; }
@@ -219,7 +227,7 @@ static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf)p9_debug (P9_DEBUG_ERROR ,"No recv fcall for tag %d (req %p), disconnecting!\n" , rc.tag, p9_rx_req); -p9_req_put (usb9pfs->client, p9_rx_req); +p9_req_put (client, p9_rx_req);return NULL ; }
@@ -230,8 +238,10 @@ static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req) {struct f_usb9pfs *usb9pfs = ep->driver_data;struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; +struct p9_client *client;struct p9_req_t *p9_rx_req;unsigned int req_size = req->actual; +unsigned long flags;int status =REQ_STATUS_RCVD ;if (req->status) {
@@ -240,9 +250,16 @@ static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req)return ; } - p9_rx_req =usb9pfs_rx_header (usb9pfs, req->buf); -if (!p9_rx_req) +spin_lock_irqsave (&usb9pfs->lock, flags); + client = usb9pfs->client; +if (!client) { +spin_unlock_irqrestore (&usb9pfs->lock, flags);return ; + } + + p9_rx_req =usb9pfs_rx_header (usb9pfs, client, req->buf); +if (!p9_rx_req) + goto out_unlock;if (req_size > p9_rx_req->rc.capacity) { dev_err(&cdev->gadget->dev,
@@ -256,8 +273,11 @@ static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req) p9_rx_req->rc.size = req_size; -p9_client_cb (usb9pfs->client, p9_rx_req, status); -p9_req_put (usb9pfs->client, p9_rx_req); +p9_client_cb (client, p9_rx_req, status); +p9_req_put (client, p9_rx_req); + +out_unlock: +spin_unlock_irqrestore (&usb9pfs->lock, flags);complete (&usb9pfs->received); }
@@ -410,7 +430,9 @@ static int p9_usbg_create(struct p9_client *client, const char *devname, char *a client->status = Disconnected; else client->status = Connected; +spin_lock_irq (&usb9pfs->lock); usb9pfs->client = client; +spin_unlock_irq (&usb9pfs->lock); client->trans_mod->maxsize = usb9pfs->buflen;
@@ -421,18 +443,25 @@ static int p9_usbg_create(struct p9_client *client, const char *devname, char *astatic void usb9pfs_clear_tx (struct f_usb9pfs *usb9pfs) { +struct p9_client *client;struct p9_req_t *req; +unsigned long flags; -guard (spinlock_irqsave)(&usb9pfs->lock); +spin_lock_irqsave (&usb9pfs->lock, flags); + client = usb9pfs->client; + usb9pfs->client =NULL ; + req = usb9pfs->in_req ? usb9pfs->in_req->context :NULL ; +if (usb9pfs->in_req) + usb9pfs->in_req->context =NULL ; +spin_unlock_irqrestore (&usb9pfs->lock, flags); - req = usb9pfs->in_req->context; -if (!req) +if (!req || !client)return ;if (!req->t_err) req->t_err = -ECONNRESET ; -p9_client_cb (usb9pfs->client, req,REQ_STATUS_ERROR ); +p9_client_cb (client, req,REQ_STATUS_ERROR ); usb9pfs->in_req->context =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 193/686 xfrm: interface: validate the IP header on xmit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qihang <[email protected]>
[ Upstream commit 86de3a1118a16dbbbe5fabe9aa20ffb93c072ed5 ]
Packets injected into an xfrm interface (e.g. AF_PACKET on an xfrmi device) reach the xfrm output path without IP header validation, but xfrm4_transport_output() uses iph->ihl for __skb_pull() and memmove() and expects the header to be valid.
vti_tunnel_xmit() already calls pskb_inet_may_pull() before handing packets to the xfrm output path. Do the same in xfrmi_xmit() and perform the header checks ip_rcv_core()/ip6_rcv_core() do on entry to the IP stack: reject wrong IP versions and malformed IPv4 header lengths.
--- net/xfrm/xfrm_interface_core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/xfrm/xfrm_interface_core.c +8 -0
@@ -531,8 +531,13 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)memset (&fl,0 ,sizeof (fl)); +if (!pskb_inet_may_pull (skb)) + goto tx_err; +switch (skb->protocol) {case htons (ETH_P_IPV6 ): +if (ipv6_hdr (skb)->version !=6 ) + goto tx_err;memset (IP6CB (skb),0 ,sizeof (*IP6CB (skb)));xfrm_decode_session (dev_net (dev), skb, &fl,AF_INET6 );if (!dst) {
@@ -548,6 +553,9 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev) }break ;case htons (ETH_P_IP ): +if (ip_hdr (skb)->version !=4 ||ip_hdr (skb)->ihl <5 || + !pskb_network_may_pull (skb,ip_hdr (skb)->ihl *4 )) + goto tx_err;memset (IPCB (skb),0 ,sizeof (*IPCB (skb)));xfrm_decode_session (dev_net (dev), skb, &fl,AF_INET );if (!dst) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 194/686 xfrm: espintcp: reorder operations within espintcp_init_sk
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sabrina Dubroca <[email protected]>
[ Upstream commit f9a11716c8445b496e9fafeec7e8412d384d02e2 ]
When enabled on a socket, espintcp sets the socket callbacks to its own before it has finished setting up its context and published it as icsk_ulp_data. Any one of those callbacks that gets called before will dereference a NULL icsk_ulp_data.
Fix this by reording the operations, and add memory barriers to ensure callers will have a struct espintcp_ctx available. Add a few WRITE_ONCE/READ_ONCE too while we're there.
--- include/net/espintcp.h | 5 +++-- net/xfrm/espintcp.c | 43 +++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 19 deletions(-)
include/net/espintcp.h +3 -2
@@ -34,7 +34,8 @@ static inline struct espintcp_ctx *espintcp_getctx(const struct sock *sk) {const struct inet_connection_sock *icsk =inet_csk (sk); -/* RCU is only needed for diag */ -return (__force void *)icsk->icsk_ulp_data; +/* pairs with smp_wmb() in espintcp_init_sk() */ +smp_rmb (); +return (__force void *)READ_ONCE (icsk->icsk_ulp_data); }#endif
net/xfrm/espintcp.c +26 -17
67 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 195/686 drm/panic: Fix kmsg screen hang on a long log line
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 1ba6405638439a4214783965538b0196c8de8a5b ]
The kmsg panic screen reads the log back one chunk at a time. A record that does not fit in a chunk comes back empty without moving on, so the screen asks for it again forever and the panic never finishes. Every oops logs the list of loaded modules, and on my machine that list does not fit.
Read into a buffer the size printk formats one record into, and stop if a read still comes back empty.
--- drivers/gpu/drm/drm_panic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_panic.c +6 -1
@@ -562,7 +562,8 @@ static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);struct kmsg_dump_iter iter; -char kmsg_buf[512 ]; +/* the size printk formats one record into, too big for the stack */ +static char kmsg_buf[2048 ];size_t kmsg_len;struct drm_panic_line line;int yoffset;
@@ -580,6 +581,10 @@ static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)char *start;char *end; +/* a record that does not fit comes back empty, every time */ +if (!kmsg_len) +break ; +/* ignore terminating NUL and newline */ start = kmsg_buf + kmsg_len -2 ; end = kmsg_buf + kmsg_len -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 196/686 drm/drm_crtc: ensure dma_fence_ops remain valid during device unbind
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: André Draszik <[email protected]>
[ Upstream commit 3be436cbd3d265fe4fcfbb5b650edad7b2108443 ]
In [1], sashiko reported the following issue:
=== snip ===
Looking at how these fences are managed, drm_crtc_create_fence() creates a dma_fence without taking a reference to the drm_device or drm_crtc. Because the sync_file framework exposes this fence to userspace, the fence can outlive the CRTC.
The dma_fence contract requires that data accessed by dma_fence_ops (like get_driver_name) must remain valid for an RCU grace period after the fence is signaled. However, drm_crtc_cleanup() and the subsequent freeing of the device do not wait for an RCU grace period via synchronize_rcu().
If userspace calls ioctl(SYNC_IOC_FILE_INFO) concurrently with a device hot-unplug:
CPU1 (Userspace)sync_file_get_name()
ops = rcu_dereference(fence->ops);
if (!dma_fence_test_signaled_flag())
// Preempted or delayed here
CPU2 (Driver Teardown)
Signals the fence (setting fence->ops = NULL)
Destroys and frees the CRTC without waiting for an RCU grace period
CPU1 (Resumes)
ops->get_driver_name(fence) -> drm_crtc_fence_get_driver_name() crtc = fence_to_crtc(fence); // Casts to the freed CRTC return crtc->dev->driver->name; // Use-after-free
...
Does the CRTC or DRM device need to be kept alive for the RCU grace period, or should the fence hold a proper reference to prevent the use-after-free when get_driver_name() and get_timeline_name() access the freed CRTC structure?
=== snap ===
I believe this to be a correct observation and this patch implements the suggestion of waiting for an RCU grace period before proceeding with destruction of the drm_crtc, so that get_driver_name() and get_timeline_name() can still work.
--- drivers/gpu/drm/drm_crtc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_crtc.c +12 -3
@@ -476,14 +476,23 @@ EXPORT_SYMBOL(__drmm_crtc_alloc_with_planes);* drm_crtc_cleanup - Clean up the core crtc usage * @crtc: CRTC to cleanup * -* This function cleans up @crtc and removes it from the DRM mode setting -* core. Note that the function does *not* free the crtc structure itself, -* this is the responsibility of the caller. +* This function cleans up @crtc and removes it from the DRM mode setting core, +* after first waiting an RCU grace period to ensure @crtc->dev can safely be +* dereferenced by our dma_fence_ops. +* +* Note that the function does *not* free the crtc structure itself, this is the +* responsibility of the caller. */ void drm_crtc_cleanup (struct drm_crtc *crtc) {struct drm_device *dev = crtc->dev; +/* Ensure our dma_fence_ops remain valid for an RCU grace period after +* the fence is signaled. This is necessary because our dma_fence_ops +* dereference crtc->dev. +*/ +synchronize_rcu (); +/* Note that the crtc_list is considered to be static; should we * remove the drm_crtc at runtime we would have to decrement all * the indices on the drm_crtc after us in the crtc_list.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 197/686 wifi: mac80211: reload TDLS header pointer after skb_linearize()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weigang He <[email protected]>
[ Upstream commit 35c5a5ea4418571997a7e7af3e7e8922b136f6e6 ]
ieee80211_process_tdls_channel_switch() sets tf = skb->data before it calls skb_linearize(), and reads tf->action_code afterwards.
ieee80211_rx_h_data() queues TDLS channel switch requests and responses to the interface after pulling only offsetof(struct ieee80211_tdls_data, u) bytes, so the skb can still be non-linear when the interface work handles it. Drivers that build paged RX skbs do this for every frame that does not fit into the skb head, e.g. iwlwifi (mvm), which is also the only mac80211 driver that sets NL80211_FEATURE_TDLS_CHANNEL_SWITCH. If the remaining data does not fit into the tailroom, skb_linearize() moves the data to a new head and frees the old one, and the action code is then read from freed memory. Depending on what that memory holds by then, the frame is handled as before or ends in the WARN_ON_ONCE() of the default case.
The frame only has to be a data frame with the TDLS ethertype from an authorized peer, e.g. relayed by the AP from another station in the BSS; the read happens before the sender is checked to be a TDLS peer.
Load tf after skb_linearize(), as the request and response handlers already do.
Found by static analysis tool CodeQL.
--- net/mac80211/tdls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mac80211/tdls.c +2 -1
@@ -2017,7 +2017,7 @@ void ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) { - struct ieee80211_tdls_data *tf = (void *)skb->data; + struct ieee80211_tdls_data *tf;struct wiphy *wiphy = sdata->local->hw.wiphy;lockdep_assert_wiphy (wiphy);
@@ -2033,6 +2033,7 @@ ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata,* The packet/size was already validated by mac80211 Rx path, only look * at the action type. */ + tf = (void *)skb->data;switch (tf->action_code) {case WLAN_TDLS_CHANNEL_SWITCH_REQUEST :ieee80211_process_tdls_channel_switch_req (sdata, skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 198/686 wifi: brcmfmac: map msgbuf RX packet IDs bidirectional
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Perlow <[email protected]>
[ Upstream commit 7ed5dce55fa8393972b1bf2bf5af1c818c5e7dc2 ]
Commit f0ba5fd51ff2 ("wifi: brcmfmac: Set DMA direction for msgbuf packet IDs") maps the RX packet ID buffers DMA_FROM_DEVICE. The BCM4364 firmware also reads posted RX buffers, so with VT-d translation enabled every such read faults ("PTE Read access is not set") and the firmware crashes and resets in a loop.
Map the RX pool DMA_BIDIRECTIONAL again, as before that commit. TX keeps DMA_TO_DEVICE.
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +1 -1
@@ -1639,7 +1639,7 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr)if (!msgbuf->tx_pktids) goto fail; msgbuf->rx_pktids =brcmf_msgbuf_init_pktids (NR_RX_PKTIDS , -DMA_FROM_DEVICE ); +DMA_BIDIRECTIONAL );if (!msgbuf->rx_pktids) goto fail;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 199/686 wifi: rsi: Skip TX aggregation setup for non-QoS frames
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Kazinsky <[email protected]>
[ Upstream commit 71f756a4c064b0312f46617c20893ecc17c332e4 ]
When transmitting a non-QoS unicast frame to a station in AP mode, rsi_core_xmit() assigns IEEE80211_NONQOS_TID (16) to tid. The station lookup succeeds, allowing tid to index start_tx_aggr[], which has only IEEE80211_NUM_TIDS (16) elements. This causes an out-of-bounds read and, if the value read is zero, an out-of-bounds write.
Only access the aggregation state for tids below IEEE80211_NUM_TIDS, excluding the non-QoS sentinel from TX aggregation setup.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/net/wireless/rsi/rsi_91x_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/rsi/rsi_91x_core.c +1 -1
@@ -458,7 +458,7 @@ void rsi_core_xmit(struct rsi_common *common, struct sk_buff *skb) tx_params->sta_id =0 ; } -if (rsta) { +if (rsta && tid <IEEE80211_NUM_TIDS ) {/* Start aggregation if not done for this tid */ if (!rsta->start_tx_aggr[tid]) { rsta->start_tx_aggr[tid] = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 200/686 wifi: cfg80211: fix out-of-bounds read in valid_rule()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijing Yin <[email protected]>
[ Upstream commit 9d8ec0b5b5295bd23d979d1b2b905de25c36fff2 ]
valid_rule() validates a struct fwdb_rule from the regulatory database firmware file, but bounds checks only the first byte of the structure, the length field itself.
It then uses that length, which comes straight out of the file, to decide whether the optional fields are present, and reads rule->wmm_ptr at offset 18 of the 20-byte structure once the length claims 20 bytes or more.
A rule placed in the last bytes of the file therefore makes the parser read up to 19 bytes past the end of the firmware image. The image comes from vmalloc() in kernel_read_file(), so with the rule at the end of a page the read falls into the guard page and oopses, with no memory debugging enabled.
A length of at least offsetofend(max_bw) but below offsetofend(wmm_ptr) takes the other branch, so valid_rule() returns true having read nothing out of bounds, and the database is accepted. regdb_query_country() does not re-check the rule, and reads rule->start, rule->end, rule->max_bw and rule->cac_timeout off the end of the kmemdup()ed copy.
A malformed regulatory.db is parsed by cfg80211's own request_firmware_nowait() at init time, and on demand from user space through NL80211_CMD_RELOAD_REGDB, which needs CAP_NET_ADMIN but no wireless hardware. Both paths require write access to the firmware search path and CONFIG_CFG80211_REQUIRE_SIGNED_REGDB=n.
Bound the whole declared rule, not just its length field. The existing check on sizeof(rule->len) is still needed, since rule->len has to be shown to be inside the file before it can be read, so the new test goes after it. A rule reaching past the end of the file is now rejected, which fails the database rather than reading out of bounds. That also gives regdb_query_country() the bound it already assumes.
--- net/wireless/reg.c | 3 +++ 1 file changed, 3 insertions(+)
net/wireless/reg.c +3 -0
@@ -691,6 +691,9 @@ static bool valid_rule(const u8 *data, unsigned int size, u16 rule_ptr)/* mandatory fields */ if (rule->len < offsetofend(struct fwdb_rule, max_bw))return false; +/* the rule must lie entirely within the database */ +if ((u8 *)rule + rule->len > data + size) +return false; if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) {u32 wmm_ptr =be16_to_cpu (rule->wmm_ptr) <<2 ;struct fwdb_wmm_rule *wmm;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 201/686 drm/vc4: Publish the output fence outside of job_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maíra Canal <[email protected]>
[ Upstream commit 9ee552a42c3905b4547e83173d46413137ec329a ]
job_lock is taken by the V3D interrupt handler, so nesting an IRQ-unsafe lock under it creates an inversion. drm_syncobj_replace_fence() takes drm_syncobj::lock, which other paths acquire with interrupts enabled. For example, a thread interrupted while holding it blocks the handler on job_lock, and the handler can only make progress once the submit path releases job_lock, which it cannot do while waiting for drm_syncobj::lock.
This is reported by lockdep:
[ 188.139076] ========================================================
[ 188.139086] WARNING: possible irq lock inversion dependency detected
[ 188.139096] 7.3.0-rc3-00067-gc4f3feeaf60f #67 Tainted: G C
[ 188.139108] --------------------------------------------------------
[ 188.139116] swapper/0/0 just changed the state of lock:
[ 188.139125] ffff0000054f8ff8 (&vc4->job_lock){-...}-{3:3}, at: vc4_irq+0xa8/0x28c [vc4]
[ 188.139234] but this lock took another, HARDIRQ-unsafe lock in the past:
[ 188.139242] (&syncobj->lock){+.+.}-{3:3}
[ 188.139256] and interrupts could create inverse lock ordering between them.
[ 188.139267] other info that might help us debug this:
[ 188.139275] Possible interrupt unsafe locking scenario:
[ 188.139284] CPU0 CPU1
[ 188.139291] ---- ----
[ 188.139299] lock(&syncobj->lock);
[ 188.139312] local_irq_disable();
[ 188.139320] lock(&vc4->job_lock);
[ 188.139335] lock(&syncobj->lock);
[ 188.139350] <Interrupt>
[ 188.139358] lock(&vc4->job_lock);
[ 188.139372] *** DEADLOCK ***Hand the fence over after job_lock is dropped. The job can complete and drop exec->fence in that window, so take a reference first and publish through the local pointer, as exec may already be gone.
--- drivers/gpu/drm/vc4/vc4_gem.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_gem.c +9 -1
@@ -639,8 +639,11 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec, fence->seqno = exec->seqno; exec->fence = &fence->base; +/* The job can complete and drop exec->fence as soon as job_lock is +* released, so hold our own reference. +*/ if (out_sync) -drm_syncobj_replace_fence (out_sync, exec->fence); +dma_fence_get (&fence->base);vc4_attach_fences (exec);
@@ -662,6 +665,11 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec,spin_unlock_irqrestore (&vc4->job_lock, irqflags); +if (out_sync) { +drm_syncobj_replace_fence (out_sync, &fence->base); +dma_fence_put (&fence->base); + } +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 202/686 drm/vc4: Drop the BO reservations outside of job_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maíra Canal <[email protected]>
[ Upstream commit 8ef66514d7b993c9fb96a5886f001e3556610c1c ]
vc4_queue_submit() calls drm_exec_fini() with job_lock held and interrupts disabled. Besides unlocking the reservations, drm_exec_fini() frees the object array with kvfree(), which asks for preemptible task context or a non-NMI interrupt, and may reach might_sleep() through vfree().
Considering that an array that exceeds a page can take the vmalloc fallback, call drm_exec_fini() once job_lock is dropped. The reservations are then held across the job kick, which is harmless as nothing in the completion path takes a BO reservation.
Note that vc4_attach_fences() has to stay inside the critical section, as it walks exec, which the job done worker is free to release as soon as job_lock is dropped.
--- drivers/gpu/drm/vc4/vc4_gem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_gem.c +2 -2
@@ -647,8 +647,6 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec,vc4_attach_fences (exec); -drm_exec_fini (exec_ctx); -list_add_tail (&exec->head, &vc4->bin_job_list);/* If no bin job was executing and if the render job (if any) has the
@@ -665,6 +663,8 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec,spin_unlock_irqrestore (&vc4->job_lock, irqflags); +drm_exec_fini (exec_ctx); +if (out_sync) {drm_syncobj_replace_fence (out_sync, &fence->base);dma_fence_put (&fence->base);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 203/686 wifi: mac80211: reinstate IEEE80211_TX_CTL_AMPDU flag in ieee80211_tx_prep_agg()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Toke Høiland-Jørgensen <[email protected]>
[ Upstream commit 25e73f1d6868c759c8eb56cad4e411692c5341b4 ]
The commit 592234e941f1 ("wifi: mac80211: Fix iTXQ AMPDU fragmentation handling") changed the way handling of the IEEE80211_TX_CTL_AMPDU flag is done in mac80211, so the only place it is set is in ieee80211_tx_dequeue().
This means that any frames that are sent to the driver via drv_tx() will no longer have the flag set. In particular, this affects packets going through ieee80211_tx_pending(). Evan reported that this can result in the ath9k driver failing to account such packets in its block ack window, eventually overrunning the window and stalling TX.
Fix this by reinstating the flag in ieee80211_tx_prep_agg() when inside a valid block ack window. This should be harmless for the TXQ path, and will reinstate the previous behaviour for drivers that use the flag as a signal to track the packet in the window.
--- net/mac80211/tx.c | 2 ++ 1 file changed, 2 insertions(+)
net/mac80211/tx.c +2 -0
@@ -1124,6 +1124,7 @@ static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,struct sk_buff *purge_skb =NULL ;if (test_bit (HT_AGG_STATE_OPERATIONAL , &tid_tx->state)) { + info->flags |=IEEE80211_TX_CTL_AMPDU ; reset_agg_timer = true; }else if (test_bit (HT_AGG_STATE_WANT_START , &tid_tx->state)) {/*
@@ -1155,6 +1156,7 @@ static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,if (!tid_tx) {/* do nothing, let packet pass through */ }else if (test_bit (HT_AGG_STATE_OPERATIONAL , &tid_tx->state)) { + info->flags |=IEEE80211_TX_CTL_AMPDU ; reset_agg_timer = true; }else { queued = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 204/686 xfrm4: use a full socket for local errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fourie Zhang <[email protected]>
[ Upstream commit 5def91015ba7b59de62a81384572da7281b8a033 ]
xfrm4_local_error() passes skb->sk to inet_sk() and ip_local_error() without ensuring it points to a full socket. TCP SYN-ACK skbs can be owned by TCP_NEW_SYN_RECV request sockets.
xfrm4_tunnel_check_size() already checks sk_fullsock() since commit 1620c88887b1 ("xfrm: Fix the usage of skb->sk"), so iptfs_is_too_big() is the only remaining IPv4 caller passing a request socket here: the sk it tests is the listener, while skb->sk is the request socket.
When IP-TFS rejects such an skb because it exceeds its payload MTU, the local error path treats the request socket as a struct inet_sock. KASAN reports a slab-out-of-bounds read in ip_local_error() beyond the request_sock_TCP allocation.
Resolve the skb owner with skb_to_full_sk() before accessing inet_sock state or reporting the error. This maps a request socket to its listener and rejects sockets that cannot be used as full sockets, matching what commit 6973a21ee73c ("ipv6: xfrm: use full sockets in local error paths") did for xfrm6_local_error().
--- net/ipv4/xfrm4_output.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv4/xfrm4_output.c +5 -2
@@ -38,9 +38,12 @@ int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)void xfrm4_local_error (struct sk_buff *skb,u32 mtu) { +struct sock *sk =skb_to_full_sk (skb);struct iphdr *hdr; +if (!sk) +return ; + hdr = skb->encapsulation ?inner_ip_hdr (skb) :ip_hdr (skb); -ip_local_error (skb->sk,EMSGSIZE , hdr->daddr, -inet_sk (skb->sk)->inet_dport, mtu); +ip_local_error (sk,EMSGSIZE , hdr->daddr,inet_sk (sk)->inet_dport, mtu); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 205/686 scsi: aic7xxx: Use default settings on the SGI O2 onboard controllers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit 696bdfc58975fbc70d2e2347a74e0b562e7e2494 ]
The SGI O2 firmware runs its onboard aic7880s without the Adaptec BIOS, so scratch RAM holds no settings. The left over BIOS path reads uninitialised bytes, and bad parity panics the boot.
Use the defaults there with host ID 0. ahc_init() keeps the default host ID ahc_pci_config() chose, 7 on other PCI controllers, so only the O2 changes.
--- drivers/scsi/aic7xxx/aic7xxx_core.c | 8 ++++++-- drivers/scsi/aic7xxx/aic7xxx_pci.c | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-)
drivers/scsi/aic7xxx/aic7xxx_core.c +6 -2
@@ -5266,9 +5266,13 @@ ahc_init(struct ahc_softc *ahc)/* * Assume we have a board at this stage and it has been reset. +* PCI controllers keep the host ID ahc_pci_config() chose. */ -if ((ahc->flags &AHC_USEDEFAULTS ) !=0 ) - ahc->our_id = ahc->our_id_b =7 ; +if ((ahc->flags &AHC_USEDEFAULTS ) !=0 ) { +if ((ahc->chip &AHC_PCI ) ==0 ) + ahc->our_id =7 ; + ahc->our_id_b =7 ; + }/* * Default to allowing initiator operations.
drivers/scsi/aic7xxx/aic7xxx_pci.c +19 -1
@@ -701,6 +701,21 @@ ahc_find_pci_device(ahc_dev_softc_t pci)return (NULL ); } +/* +* The SGI O2 firmware runs its onboard controllers, in slots 1 and 2 of the +* root bus, without the Adaptec BIOS and at host ID 0. It leaves no settings +* in scratch RAM, which may still hold power-on contents with bad parity. +*/ +static bool +ahc_pci_sgi_o2_onboard (struct ahc_softc *ahc) +{ +int slot =ahc_get_pci_slot (ahc->dev_softc); + +return IS_ENABLED (CONFIG_SGI_IP32 ) && +ahc_get_pci_bus (ahc->dev_softc) ==0 && + (slot ==1 || slot ==2 ); +} +int ahc_pci_config (struct ahc_softc *ahc,const struct ahc_pci_identity *entry) {
@@ -782,6 +797,9 @@ ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry) ahc->bus_intr = ahc_pci_intr; ahc->bus_chip_init = ahc_pci_chip_init; +if (ahc_pci_sgi_o2_onboard (ahc)) + ahc->flags |=AHC_NO_BIOS_INIT ; +/* Remember how the card was setup in case there is no SEEPROM */ if ((ahc_inb (ahc,HCNTRL ) &POWRDN ) ==0 ) {ahc_pause (ahc);
@@ -898,7 +916,7 @@ ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry)* Assume only one connector and always turn * on termination. */ - our_id =0x07 ; + our_id =ahc_pci_sgi_o2_onboard (ahc) ?0 :0x07 ; sxfrctl1 =STPWEN ; }ahc_outb (ahc,SCSICONF , our_id|ENSPCHK |RESET_SCSI );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 206/686 scsi: aic79xx: Fix NULL pointer dereference in device reset
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Luebke <[email protected]>
[ Upstream commit f057a8bfeb6ff89c65e95540b8700a53c66d4a31 ]
Since commit c67e63800446 ("scsi: aic79xx: Do not reference SCSI command when resetting device") the device reset SCB has no SCSI command, but ahd_linux_dev_reset() still sets its residual, and ahd_abort_scbs(), which completes it, sets its status. Seen on an AIC-7902 when a failing disk triggered a device reset, which killed the SCSI error handler:
BUG: kernel NULL pointer dereference, address: 0000009c EIP: ahd_linux_dev_reset.cold+0xee/0x26e
Add NULL command checks to the accessors in aic79xx_osm.h. Also skip autosense for an SCB without a command and complete it with ahd_done() right away: the REQUEST SENSE path can clear SCB_DEVICE_RESET, after which ahd_done() would dereference the missing command.
--- drivers/scsi/aic7xxx/aic79xx_core.c | 4 +++- drivers/scsi/aic7xxx/aic79xx_osm.h | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-)
drivers/scsi/aic7xxx/aic79xx_core.c +3 -1
@@ -8942,8 +8942,10 @@ ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb) }#endif -if (ahd_perform_autosense (scb) ==0 ) +if (ahd_perform_autosense (scb) ==0 ) { +ahd_done (ahd, scb);break ; + } ahd_compile_devinfo(&devinfo, SCB_GET_OUR_ID(scb), SCB_GET_TARGET(ahd, scb),
drivers/scsi/aic7xxx/aic79xx_osm.h +21 -5
@@ -499,6 +499,8 @@ int ahd_linux_show_info(struct seq_file *,struct Scsi_Host *);static inline void ahd_cmd_set_transaction_status (struct scsi_cmnd *cmd,uint32_t status) { +if (!cmd) +return ; cmd->result &= ~(CAM_STATUS_MASK <<16 ); cmd->result |= status <<16 ; }
@@ -512,6 +514,8 @@ void ahd_set_transaction_status(struct scb *scb, uint32_t status)static inline void ahd_cmd_set_scsi_status (struct scsi_cmnd *cmd,uint32_t status) { +if (!cmd) +return ; cmd->result &= ~0xFFFF ; cmd->result |= status; }
@@ -525,6 +529,8 @@ void ahd_set_scsi_status(struct scb *scb, uint32_t status)static inline uint32_t ahd_cmd_get_transaction_status (struct scsi_cmnd *cmd) { +if (!cmd) +return CAM_REQ_INPROG ;return ((cmd->result >>16 ) &CAM_STATUS_MASK ); }
@@ -537,6 +543,8 @@ uint32_t ahd_get_transaction_status(struct scb *scb)static inline uint32_t ahd_cmd_get_scsi_status (struct scsi_cmnd *cmd) { +if (!cmd) +return SAM_STAT_GOOD ;return (cmd->result &0xFFFF ); }
@@ -564,13 +572,16 @@ u_long ahd_get_transfer_length(struct scb *scb)static inline int ahd_get_transfer_dir (struct scb *scb) { +if (!scb->io_ctx) +return DMA_NONE ;return (scb->io_ctx->sc_data_direction); }static inline void ahd_set_residual (struct scb *scb,u_long resid) { -scsi_set_resid (scb->io_ctx, resid); +if (scb->io_ctx) +scsi_set_resid (scb->io_ctx, resid); } static inline
@@ -582,6 +593,8 @@ void ahd_set_sense_residual(struct scb *scb, u_long resid)static inline u_long ahd_get_residual (struct scb *scb) { +if (!scb->io_ctx) +return 0 ;return scsi_get_resid (scb->io_ctx); }
@@ -595,11 +608,12 @@ static inlineint ahd_perform_autosense (struct scb *scb) {/* -* We always perform autosense in Linux. -* On other platforms this is set on a -* per-transaction basis. +* We always perform autosense in Linux, except for the device +* reset SCB, which has no command to return sense data to. */ -return (1 ); +if (!scb->io_ctx) +return 0 ; +return 1 ; } static inline uint32_t
@@ -629,6 +643,8 @@ void ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);static inline void ahd_freeze_scb (struct scb *scb) { +if (!scb->io_ctx) +return ;if ((scb->io_ctx->result & (CAM_DEV_QFRZN <<16 )) ==0 ) { scb->io_ctx->result |=CAM_DEV_QFRZN <<16 ; scb->platform_data->dev->qfrozen++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 207/686 scsi: target: Fix demo-mode dynamic ACL dev-entry UAF vs LUN teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Zhang <[email protected]>
[ Upstream commit 6a6e7d7230cd4e0a6c003bae5b85bf37a1e77b94 ]
A demo-mode (generate_node_acls=1) login that allocates a dynamic NodeACL populates that ACL's per-LUN dev entries in core_tpg_add_node_to_devs() *before* the ACL is linked onto tpg->acl_node_list by target_add_node_acl():
core_tpg_check_initiator_node_acl():
...
core_tpg_add_node_to_devs(acl, tpg, NULL); /* builds deves */
target_add_node_acl(acl); /* only now listed */
The LUN teardown sweep, core_clear_lun_from_tpg(), enumerates only tpg->acl_node_list, so a dev entry whose ACL is still in the window above is invisible to the sweep and is never disabled. It is left on the se_lun->lun_deve_list after core_tpg_remove_lun() frees the se_lun; when the same unpacked_lun is later re-added and the se_lun is reallocated at the same address, the stale dev entry is rediscovered by target_nacl_find_deve() and core_enable_device_list_for_node() corrupts lun_deve_list:
BUG: KASAN: slab-use-after-free ... core_enable_device_list_for_node+0x5ce/0x880 core_tpg_add_node_to_devs+0x169/0x190 core_dev_add_lun+0x146/0x190 target_fabric_port_link+0xe9/0x1b0 configfs_symlink+0x381/0xae0 __x64_sys_symlink+0x55/0x80
The demo-mode login path that drives the ACL/dev-entry creation is reachable by an unauthenticated initiator; the colliding LUN add/remove is a local configfs operation.
Commit 49cb77e297dc ("target: Avoid mappedlun symlink creation during lun shutdown") introduced se_lun->lun_shutdown and guarded the *explicit* ACL MappedLUN path (target_fabric_mappedlun_link()), but the demo-mode automatic path, core_tpg_add_node_to_devs() -> core_enable_device_list_for_node(), was never given the equivalent guard, and the publish-after-populate ordering in core_tpg_check_initiator_node_acl() was left unchanged.
Fix it in three cooperating parts:
1) Publish the dynamic NodeACL onto acl_node_list *before* creating its dev entries, so the teardown sweep can observe them.
2) Refuse to attach a dev entry to an se_lun that is shutting down, checked under nacl->lun_entry_mutex -- the same lock the sweep takes -- so once the sweep has passed an ACL any later enable for that LUN observes lun_shutdown and skips it.
3) In core_enable_device_list_for_node(), insert the new dev entry onto lun->lun_deve_list while still holding nacl->lun_entry_mutex, in both the replace and the new-entry branch. Previously the entry was added to nacl->lun_entry_hlist under the mutex but to lun->lun_deve_list only after dropping it; with the ACL now published early, the sweep could take the mutex in that gap, find the entry on the hlist, core_disable_device_list_for_node() it (list_del() on the not-yet- linked lun_link succeeds and the entry is freed), and then the enable would list_add_tail() the freed entry back onto lun_deve_list. Linking both lists under the mutex makes enable and the sweep mutually exclusive, closing that window.
core_tpg_add_node_to_devs() already ignores the return value of core_enable_device_list_for_node(), so a shutting-down LUN is simply skipped.
--- drivers/target/target_core_device.c | 18 +++++++++++++++--- drivers/target/target_core_tpg.c | 10 +++++++++- 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/target/target_core_device.c +15 -3
@@ -349,6 +349,19 @@ int core_enable_device_list_for_node( new->attach_count++;mutex_lock (&nacl->lun_entry_mutex); +/* +* Do not attach a new dev entry to an se_lun that is being torn down. +* lun_shutdown is set by core_tpg_remove_lun() before its +* core_clear_lun_from_tpg() sweep; checking it here under the same +* nacl->lun_entry_mutex the sweep takes guarantees that once the sweep +* has passed this ACL no dev entry can be left dangling on the +* se_lun->lun_deve_list that is about to be freed. +*/ +if (lun->lun_shutdown) { +mutex_unlock (&nacl->lun_entry_mutex); + ret = -ENODEV ; + goto free_stats; + } orig =target_nacl_find_deve (nacl, mapped_lun);if (orig && orig->se_lun) {struct se_lun *orig_lun = orig->se_lun;
@@ -375,12 +388,12 @@ int core_enable_device_list_for_node( new->se_lun_acl = lun_acl;hlist_del_rcu (&orig->link);hlist_add_head_rcu (&new->link, &nacl->lun_entry_hlist); -mutex_unlock (&nacl->lun_entry_mutex);spin_lock (&lun->lun_deve_lock);list_del (&orig->lun_link);list_add_tail (&new->lun_link, &lun->lun_deve_list);spin_unlock (&lun->lun_deve_lock); +mutex_unlock (&nacl->lun_entry_mutex);kref_put (&orig->pr_kref, target_pr_kref_release);wait_for_completion (&orig->pr_comp);
@@ -393,11 +406,10 @@ int core_enable_device_list_for_node( new->se_lun = lun; new->se_lun_acl = lun_acl;hlist_add_head_rcu (&new->link, &nacl->lun_entry_hlist); -mutex_unlock (&nacl->lun_entry_mutex); -spin_lock (&lun->lun_deve_lock);list_add_tail (&new->lun_link, &lun->lun_deve_list);spin_unlock (&lun->lun_deve_lock); +mutex_unlock (&nacl->lun_entry_mutex);target_luns_data_has_changed (nacl, new, true);return 0 ;
drivers/target/target_core_tpg.c +9 -1
@@ -266,6 +266,15 @@ struct se_node_acl *core_tpg_check_initiator_node_acl(kref_get (&acl->acl_kref); acl->dynamic_node_acl =1 ; +/* +* Publish the dynamic NodeACL on tpg->acl_node_list before creating +* its demo-mode MappedLUN dev entries below, so that a concurrent LUN +* teardown sweep (core_clear_lun_from_tpg(), which walks acl_node_list) +* can observe and disable those dev entries. Otherwise a dev entry can +* be left on an se_lun->lun_deve_list that is about to be freed. +*/ +target_add_node_acl (acl); +/* * Here we only create demo-mode MappedLUNs from the active * TPG LUNs if the fabric is not explicitly asking for
@@ -275,7 +284,6 @@ struct se_node_acl *core_tpg_check_initiator_node_acl( (tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg) != 1))core_tpg_add_node_to_devs (acl, tpg,NULL ); -target_add_node_acl (acl);return acl; }EXPORT_SYMBOL (core_tpg_check_initiator_node_acl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 208/686 9p/xen: validate the response size from the backend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit 9b4cf60c6b739461c5b4ec9c52587da6b2608786 ]
p9_xen_response() takes the length of an incoming response from the ring -- the first field of the 9p header, which the Xen transport reuses as its framing header -- and uses it to advance the consumer index, but never checks that it is at least the header size or no larger than the number of bytes the backend has actually produced.
A malicious or buggy backend can post a response whose size is smaller than the header (for example 0). The consumer index then never advances, so the response work re-reads the same ring contents instead of making progress. In testing this raced with the teardown that the malformed reply triggers and dereferenced a freed p9_client:
9pfs 9pfs-0: Wrong req tag=ffff
BUG: kernel NULL pointer dereference, address: 0000000000000060 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: Oops: 0000 [#1] SMP NOPTI CPU: 0 UID: 0 PID: 11 Comm: kworker/0:1 Not tainted 7.2.0-rc5 #6 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.17.0-0-gb52ca86e094d-prebuilt.qemu.org 04/01/2014 Workqueue: events p9_xen_response RIP: 0010:idr_find+0x4/0x10 RSP: 0018:ffffbf5d80063de8 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffffa229c21195a0 RCX: ffffa229c2400000 RDX: ffffa229c11c2200 RSI: 000000000000ffff RDI: 0000000000000050 RBP: 000000000000ffff R08: 3fffffffffffdfff R09: ffffffffffffffff R10: 3fffffffffffdfff R11: ffffffff87a60e80 R12: 0000000000000050 R13: 0000000000000000 R14: 000000000000ffff R15: 0000000000100000 FS: 0000000000000000(0000) GS:ffffa22a7661c000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000060 CR3: 000000003ac34002 CR4: 0000000000770ef0 PKRU: 55555554 Call Trace: <TASK> p9_tag_lookup+0x2b/0x90 p9_xen_response+0x17c/0x2e0 process_one_work+0x16a/0x3a0 worker_thread+0x172/0x2e0 kthread+0xdd/0x110 ret_from_fork+0x18b/0x240 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: CR2: 0000000000000060 ---[ end trace 0000000000000000 ]---
Reject a response whose size is outside [sizeof(header), queued] before using it, matching the validation the backend already applies to incoming requests.
Message-ID: <[email protected]>
--- net/9p/trans_xen.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/9p/trans_xen.c +8 -0
@@ -198,6 +198,14 @@ static void p9_xen_response(struct work_struct *work) masked_prod, &masked_cons, XEN_9PFS_RING_SIZE(ring)); +if (h.size <sizeof (h) || + h.size >xen_9pfs_queued (prod, cons, +XEN_9PFS_RING_SIZE (ring))) { +dev_warn_ratelimited (&priv->dev->dev, +"bad response size %u from backend\n" , h.size); +break ; + } + req =p9_tag_lookup (priv->client, h.tag);if (!req || req->status !=REQ_STATUS_SENT ) {dev_warn (&priv->dev->dev,"Wrong req tag=%x\n" , h.tag);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 209/686 9p: dont decrement a server-owned zero nlink
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuanfu Xie <[email protected]>
[ Upstream commit 4e915aa8566173b44146bc46177c85afbe6bdf96 ]
A 9P2000.L server can report nlink=0 for a regular file that still exists. On a cache=loose or cache=fscache mount, lookup stores that value with set_nlink(). A later successful unlink calls v9fs_dec_count(), which still calls drop_nlink() for a non-directory. drop_nlink() warns, and the unsigned link count wraps to 4294967295. fstat() on a descriptor opened before the unlink shows 0 before and 4294967295 after.
The warning on the unpatched kernel, trimmed:
WARNING: fs/inode.c:408 at drop_nlink+0xac/0xd0, CPU#1: trigger/188 CPU: 1 UID: 0 PID: 188 Comm: trigger Tainted: G N 7.3.0-rc4-00537-ga3ff15db6820 #1 PREEMPT(lazy) RIP: 0010:drop_nlink+0xac/0xd0 Call Trace: <TASK> v9fs_remove+0x529/0x750 vfs_unlink+0x2f0/0xbd0 filename_unlinkat+0x340/0x6c0 __x64_sys_unlink+0x46/0x70 do_syscall_64+0xe8/0x4f0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> ---[ end trace 0000000000000000 ]---
Directories whose cached nlink is at most 2 already skip this decrement, because the exported filesystem may not maintain nlink (commit ac89b2ef9b559). cache=none skips it as well (commit 574aa0b479947). cache=mmap does not take this path: it sets neither CACHE_META nor CACHE_LOOSE. A regular file on cache=loose or cache=fscache still does. Its count came from GETATTR and may already be zero, so skip the decrement when i_nlink is already 0.
Verified on 7.3-rc4-00537-ga3ff15db6820 with only this change. A server that advertises nlink=0 and accepts the unlink no longer warns, and the open descriptor stays at nlink 0. An honest server on the same mount still goes from 1 to 0. A rejected unlink leaves the count unchanged. cache=none is unchanged. With panic_on_warn the unpatched kernel panics on the warning; the patched kernel does not.
Message-ID: <[email protected]>
--- fs/9p/vfs_inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/9p/vfs_inode.c +8 -0
@@ -493,6 +493,12 @@ static int v9fs_at_to_dotl_flags(int flags)* nothing and races with concurrent metadata fetches that may already * have observed the post-unlink value (nlink == 0). * +* The same applies to a regular file whose cached nlink has already been +* driven to zero by the server: in the cached modes the attributes come +* from GETATTR and are applied verbatim, so decrementing a link count the +* server does not maintain only trips the drop_nlink() WARN_ON and +* underflows i_nlink. +* * @inode: inode whose nlink is being dropped */ static void v9fs_dec_count (struct inode *inode)
@@ -501,6 +507,8 @@ static void v9fs_dec_count(struct inode *inode)if (!(v9ses->cache & (CACHE_META |CACHE_LOOSE )))return ; +if (inode->i_nlink ==0 ) +return ;if (!S_ISDIR (inode->i_mode) || inode->i_nlink >2 )drop_nlink (inode); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 210/686 batman-adv: Close OGM aggregation before transmission
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit f91f64a91682c07e6c5f059804e709656364e8a6 ]
The OGM send worker leaves its forwarding packet on forw_bat_list until after batadv_iv_ogm_emit() returns. Aggregation holds forw_bat_list_lock, but emission reads and clones the packet without that lock.
CPU 0 can therefore start emitting a queued packet while CPU 1 takes the list lock, finds the same packet and appends another OGM. The sender can observe the new packet length before the corresponding direct-link flag is set, or clone the skb while its length and payload are being updated. This can transmit an OGM with incorrect flags or inconsistent data.
KCSAN reported:
BUG: KCSAN: data-race in batadv_iv_ogm_queue_add / batadv_iv_send_outstanding_bat_ogm_packet write to 0xffff888100fedcf8 of 2 bytes by interrupt on cpu 1: read to 0xffff888100fedcf8 of 2 bytes by task 70 on cpu 2: value changed: 0x00c0 -> 0x00d8
Mark the aggregate as full under forw_bat_list_lock before emission. This waits for any ongoing append and prevents further aggregation. Emission uses packet_len to walk the OGMs, so all queued packets are still sent. Keep the packet on the list so interface purging can find the worker, wait for it to finish and free the packet.
--- net/batman-adv/bat_iv_ogm.c | 5 +++++ net/batman-adv/types.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +5 -0
@@ -1787,6 +1787,11 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) goto out; } +/* Mark aggregate as full before forcing emit. */ +spin_lock_bh (&bat_priv->forw_bat_list_lock); + forw_packet->num_packets =BATADV_MAX_AGGREGATION_PACKETS ; +spin_unlock_bh (&bat_priv->forw_bat_list_lock); +batadv_iv_ogm_emit (forw_packet);/* we have to have at least one packet in the queue to determine the
net/batman-adv/types.h +7 -1
@@ -1970,7 +1970,13 @@ struct batadv_forw_packet {/** @direct_link_flags: direct link flags for aggregated OGM packets */ DECLARE_BITMAP (direct_link_flags,BATADV_MAX_AGGREGATION_PACKETS ); -/** @num_packets: counter for aggregated OGMv1 packets */ +/** +* @num_packets: counter for aggregated OGMv1 packets. Set to +* BATADV_MAX_AGGREGATION_PACKETS (independent of the real number of +* aggregated packets) by the send worker to prevent further +* aggregation while the packet is emitted. It must therefore not be +* used to iterate over the aggregated packets +*/ u8 num_packets;/** @delayed_work: work queue callback item for packet sending */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 211/686 batman-adv: mcast: validate tracker padding before forwarding
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit ea01fff30f631e67ee5f0a2b97855d772b3a35fc ]
A multicast tracker with an even number of destinations needs two padding bytes after its destination list. batadv_mcast_forw_packet() currently only checks that the count field and the addresses fit in the tracker TVLV.
If an unpadded even tracker is compacted to an odd number of destinations, batadv_mcast_forw_shrink_update_headers() includes those missing padding bytes in the amount to remove. The subsequent memmove can then write two bytes past the old packet tail. With no tailroom, this corrupts skb_shared_info.
Include the required padding in the existing tracker length check. This rejects the malformed tracker before either received or locally generated packets can reach the compactor.
--- net/batman-adv/multicast_forw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/batman-adv/multicast_forw.c +4 -1
@@ -950,8 +950,11 @@ static int batadv_mcast_forw_packet(struct batadv_priv *bat_priv, dest = (u8 *)mcast_tracker +sizeof (*mcast_tracker); -/* check if full tracker tvlv is within skb length */ +/* check if full tracker tvlv, including padding, is within skb length */ tvlv_len =sizeof (*mcast_tracker) +ETH_ALEN * num_dests; +if (!(num_dests %2 )) + tvlv_len +=2 ; +if (tvlv_len >skb_network_header_len (skb))return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 212/686 batman-adv: dat: initialize orig_node of unfilled candidate slots
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
[ Upstream commit 4eb19a389d74f06901b4cd6f24b996b2e84eaefc ]
batadv_dat_select_candidates() allocates the candidate array without zeroing it. batadv_choose_next_candidate() marks each slot as BATADV_DAT_CANDIDATE_NOT_FOUND but only sets orig_node when an eligible originator was found. In the following rounds, batadv_is_orig_node_eligible() compares res[j].orig_node of all previous slots against the evaluated originator. For slots without candidates, it reads uninitialized memory.
The orig_node has to be cleared together with theBATADV_DAT_CANDIDATE_NOT_FOUND type.
--- net/batman-adv/distributed-arp-table.c | 1 + 1 file changed, 1 insertion(+)
net/batman-adv/distributed-arp-table.c +1 -0
@@ -582,6 +582,7 @@ static void batadv_choose_next_candidate(struct batadv_priv *bat_priv,* NOT_FOUND */ cands[select].type =BATADV_DAT_CANDIDATE_NOT_FOUND ; + cands[select].orig_node =NULL ;/* iterate over the originator list and find the node with the closest * dat_address which has not been selected yet
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 213/686 batman-adv: fix skb leak when hard_iface is being released
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
[ Upstream commit 522e4aece2e96cacbb8a6ae1eec0d4c0dd6f4fed ]
batadv_batman_skb_recv() owns the skb it is given. When the hard_iface refcount already dropped to zero, the function jumped to err_out, which only returned NET_RX_DROP and skipped the kfree_skb() under err_free.
To avoid a leak, free the skb before returning in this case.
--- net/batman-adv/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/batman-adv/main.c +4 -3
@@ -427,8 +427,10 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,* shut down otherwise the packet may trigger de-reference errors * further down in the receive path. */ -if (!kref_get_unless_zero (&hard_iface->refcount)) - goto err_out; +if (!kref_get_unless_zero (&hard_iface->refcount)) { +kfree_skb (skb); +return NET_RX_DROP ; + } skb =skb_share_check (skb,GFP_ATOMIC );
@@ -487,7 +489,6 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,kfree_skb (skb); err_put:batadv_hardif_put (hard_iface); -err_out:return NET_RX_DROP ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 214/686 batman-adv: stop originator purge worker before freeing TT
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
[ Upstream commit f89eda5a9ccf82cba06b085b42ebc4886b8dfe9e ]
batadv_mesh_free() releases the translation tables via batadv_tt_free() before batadv_originator_free() stops orig_work. The purge worker can therefore still run while the TT is torn down. When an originator times out, batadv_purge_orig_ref() calls batadv_tt_global_del_orig(), which loads tt.global_hash and walks all buckets while taking their locks:
CPU0 CPU1
batadv_tt_free() batadv_purge_orig()
batadv_tt_global_del_orig()
hash = ...tt.global_hash;
batadv_tt_global_table_free()
batadv_hash_destroy(hash);
spin_lock_bh(&hash->list_locks[i]);Disable orig_work at the beginning of batadv_mesh_free(), directly after the mesh was marked as deactivating. The second disable_delayed_work_sync() in batadv_originator_free() is harmless because it is free'd anyway.
--- net/batman-adv/main.c | 5 +++++ 1 file changed, 5 insertions(+)
net/batman-adv/main.c +5 -0
@@ -249,6 +249,11 @@ void batadv_mesh_free(struct net_device *mesh_iface)atomic_set (&bat_priv->mesh_state,BATADV_MESH_DEACTIVATING ); +/* the originator purge worker accesses (among others) the TT tables +* and must therefore be stopped before any of them are freed +*/ +disable_delayed_work_sync (&bat_priv->orig_work); +batadv_purge_outstanding_packets (bat_priv,NULL );batadv_tp_stop_all (bat_priv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 215/686 net: jme: keep RX MAC clock enabled for WoL
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Franck Baur <[email protected]>
[ Upstream commit ed9179fc7228315fb745dc3b111bae446e6894d2 ]
On the JMicron JMC250 revision 03, the MAC reset performed during suspend leaves GPREG1_RXCLKOFF set. Although the driver enables Magic Packet detection, the gated RX MAC clock prevents wake-up from ACPI S3.
Keep the RX MAC clock enabled while WoL is armed. Restore the gated clock state immediately after disabling WoL during resume, preserving the RX engine initialization ordering.
Prevent concurrent link-change work from gating the clock again after WoL has been armed. Quiesce interrupt-driven link-change scheduling, synchronize pending interrupts, and cancel outstanding link-change work before programming WoL in suspend and shutdown paths.
Restore the deferred processing state before requesting link reinitialization on resume.
Tested on an ASUS K42JE with JMC250 [197b:0250] rev 03 using a Debian 6.12.111 kernel and an externally built module. ACPI S3 wake with a Magic Packet completed in 19 seconds, while a control without a Magic Packet resumed through the RTC alarm after 123 seconds. Ethernet and SSH recovered after resume.
S4 and S5 wake behaviour has not been validated with this revision.
--- drivers/net/ethernet/jme.c | 37 ++++++++++++++++++++++++++++++++----- drivers/net/ethernet/jme.h | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)
drivers/net/ethernet/jme.c +32 -5
@@ -1502,7 +1502,8 @@ jme_intr_msi(struct jme_adapter *jme, u32 intrstat)* all other events are ignored */ jwrite32 (jme,JME_IEVE , intrstat); -schedule_work (&jme->linkch_task); +if (!test_bit (JME_FLAG_WOL_QUIESCE , &jme->flags)) +schedule_work (&jme->linkch_task); goto out_reenable; }
@@ -1546,7 +1547,8 @@ jme_intr_msi(struct jme_adapter *jme, u32 intrstat)/* * Re-enable interrupt */ -jwrite32f (jme,JME_IENS ,INTR_ENABLE ); +if (!test_bit (JME_FLAG_WOL_QUIESCE , &jme->flags)) +jwrite32f (jme,JME_IENS ,INTR_ENABLE ); } static irqreturn_t
@@ -1892,6 +1894,7 @@ jme_powersave_phy(struct jme_adapter *jme)jme_set_100m_half (jme);if (jme->reg_pmcs & (PMCS_LFEN |PMCS_LREN ))jme_wait_link (jme); +jme_mac_rxclk_on (jme);jme_clear_pm_enable_wol (jme); }else {jme_phy_off (jme);
@@ -3158,6 +3161,21 @@ jme_shutdown(struct pci_dev *pdev)struct net_device *netdev =pci_get_drvdata (pdev);struct jme_adapter *jme =netdev_priv (netdev); +if (netif_running (netdev)) { +set_bit (JME_FLAG_WOL_QUIESCE , &jme->flags); +netif_device_detach (netdev); +netif_stop_queue (netdev); +jme_stop_irq (jme); +synchronize_irq (pdev->irq); +jme_stop_irq (jme); +cancel_work_sync (&jme->linkch_task); +tasklet_disable (&jme->pcc_task); +napi_disable (&jme->napi); +tasklet_disable (&jme->txclean_task); +tasklet_disable (&jme->rxclean_task); +tasklet_disable (&jme->rxempty_task); + } +jme_powersave_phy (jme);pci_pme_active (pdev, true); }
@@ -3172,11 +3190,16 @@ jme_suspend(struct device *dev)if (!netif_running (netdev))return 0 ; -atomic_dec (&jme->link_changing); - +set_bit (JME_FLAG_WOL_QUIESCE , &jme->flags);netif_device_detach (netdev);netif_stop_queue (netdev);jme_stop_irq (jme); +synchronize_irq (jme->pdev->irq); +jme_stop_irq (jme); +cancel_work_sync (&jme->linkch_task); +tasklet_disable (&jme->pcc_task); +napi_disable (&jme->napi); +atomic_dec (&jme->link_changing);tasklet_disable (&jme->txclean_task);tasklet_disable (&jme->rxclean_task);
@@ -3215,6 +3238,7 @@ jme_resume(struct device *dev)return 0 ;jme_clear_pm_disable_wol (jme); +jme_mac_rxclk_off (jme);jme_phy_on (jme);if (test_bit (JME_FLAG_SSET , &jme->flags))jme_set_link_ksettings (netdev, &jme->old_cmd);
@@ -3226,8 +3250,11 @@ jme_resume(struct device *dev)atomic_inc (&jme->link_changing); -jme_reset_link (jme); +napi_enable (&jme->napi); +tasklet_enable (&jme->pcc_task); +clear_bit (JME_FLAG_WOL_QUIESCE , &jme->flags); +jme_reset_link (jme);jme_start_irq (jme);return 0 ;
drivers/net/ethernet/jme.h +1 -0
@@ -450,6 +450,7 @@ enum jme_flags_bits {JME_FLAG_SSET =2 ,JME_FLAG_POLL =5 ,JME_FLAG_SHUTDOWN =6 , + JME_FLAG_WOL_QUIESCE = 7, };#define TX_TIMEOUT (5 * HZ)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 216/686 ipv6: raw: fix use-after-free in rawv6_send_hdrinc()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhou Qiuyue <[email protected]>
[ Upstream commit 66dfb2cacda7faae614d688943d85e75abf7f586 ]
rawv6_send_hdrinc() caches the route before handing the skb to l3mdev_ip6_out(). The VRF output path may replace skb->dst and release the original route, leaving the cached pointer stale.
The function later dereferences that pointer for statistics accounting and as the output device passed to NF_HOOK(). Its RCU read-side critical section starts after l3mdev_ip6_out(), so it cannot prevent the old route from being reclaimed in between.
Reload the route from the current skb destination after l3mdev_ip6_out() returns.
KASAN reports a slab-use-after-free in rawv6_sendmsg(), with the route allocated by ip6_dst_alloc(), freed by dst_destroy() from rcu_core(), and the related RCU callback queued from vrf_l3_out().
--- net/ipv6/raw.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/raw.c +3 -0
@@ -653,6 +653,9 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,if (unlikely (!skb))return 0 ; +/* l3mdev_ip6_out() may have replaced the skb dst. */ + rt =dst_rt6_info (skb_dst (skb)); +/* Acquire rcu_read_lock() in case we need to use rt->rt6i_idev * in the error path. Since skb has been freed, the dst could * have been queued for deletion.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 217/686 drm/vc4: hdmi: power down the BCM2712 PHY when the output is disabled
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dom Cobley <[email protected]>
[ Upstream commit a59a60e6e9e3a1d5177b28577d935d5ee37ace66 ]
vc6_hdmi_phy_disable() is empty, so on BCM2712 the PHY keeps its PLL and TMDS drivers running after the HDMI output is disabled, until the next vc6_hdmi_phy_init(). The TMDS clock is therefore not stopped between two mode sets, which the SCDC clock ratio change requires, and the idle PHY wastes power.
Reset and power down the PHY on disable, as the BCM2711 variant does.
--- drivers/gpu/drm/vc4/vc4_hdmi_phy.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/vc4/vc4_hdmi_phy.c +5 -0
@@ -1197,4 +1197,9 @@ void vc6_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,void vc6_hdmi_phy_disable (struct vc4_hdmi *vc4_hdmi) { +unsigned long flags; + +spin_lock_irqsave (&vc4_hdmi->hw_lock, flags); +vc6_hdmi_reset_phy (vc4_hdmi); +spin_unlock_irqrestore (&vc4_hdmi->hw_lock, flags); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 218/686 drm/vc4: hdmi: always cancel the scrambling work synchronously
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lucas Tanure <[email protected]>
[ Upstream commit 2e47848f0d076dec66df3bc403214073cd2214ac ]
The scrambling work re-arms itself every second while a scrambled mode is active. When the output is disabled, the work may be executing at that moment rather than pending, and delayed_work_pending() is then false, so the cancel is skipped. The running instance finishes after the disable, sees the sink report scrambling off, writes the SCDC scrambling and clock ratio bits back on, and queues itself again. The sink is left configured for a scrambled 1/40 link that no longer exists and the work keeps running until the next enable.
cancel_delayed_work_sync() handles both states: it waits for a running instance and blocks it from queueing itself again.
--- drivers/gpu/drm/vc4/vc4_hdmi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -2
@@ -764,8 +764,7 @@ static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder) vc4_hdmi->scdc_enabled = false; -if (delayed_work_pending (&vc4_hdmi->scrambling_work)) -cancel_delayed_work_sync (&vc4_hdmi->scrambling_work); +cancel_delayed_work_sync (&vc4_hdmi->scrambling_work);if (!drm_dev_enter (drm, &idx))return ;
Signature · 1 line
2.53.0