4.19.270-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 292/521 powerpc/pseries: PCIE PHB reset
In reply to Greg Kroah-HartmanFrom: Wen Xiong <[email protected]>
[ Upstream commit 5a090f7c363fdc09b99222eae679506a58e7cc68 ]
Several device drivers hit EEH(Extended Error handling) when triggering kdump on Pseries PowerVM. This patch implemented a reset of the PHBs in pci general code when triggering kdump. PHB reset stop all PCI transactions from normal kernel. We have tested the patch in several enviroments:
- direct slot adapters
- adapters under the switch
- a VF adapter in PowerVM
- a VF adapter/adapter in KVM guest.
Stable-dep-of: 9aafbfa5f57a ("powerpc/pseries/eeh: use correct API for error log size")
--- arch/powerpc/platforms/pseries/eeh_pseries.c | 232 ++++++++++++++----- 1 file changed, 169 insertions(+), 63 deletions(-)
arch/powerpc/platforms/pseries/eeh_pseries.c +169 -63
@@ -37,6 +37,7 @@#include <linux/sched.h> #include <linux/seq_file.h> #include <linux/spinlock.h> +#include <linux/crash_dump.h> #include <asm/eeh.h> #include <asm/eeh_event.h>
@@ -94,6 +95,152 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)eeh_sysfs_add_device (pdev); } + +/** +* pseries_eeh_get_config_addr - Retrieve config address +* +* Retrieve the assocated config address. Actually, there're 2 RTAS +* function calls dedicated for the purpose. We need implement +* it through the new function and then the old one. Besides, +* you should make sure the config address is figured out from +* FDT node before calling the function. +* +* It's notable that zero'ed return value means invalid PE config +* address. +*/ +static int pseries_eeh_get_config_addr (struct pci_controller *phb,int config_addr) +{ +int ret =0 ; +int rets[3 ]; + +if (ibm_get_config_addr_info2 !=RTAS_UNKNOWN_SERVICE ) { +/* +* First of all, we need to make sure there has one PE +* associated with the device. Otherwise, PE address is +* meaningless. +*/ + ret =rtas_call (ibm_get_config_addr_info2,4 ,2 , rets, + config_addr,BUID_HI (phb->buid), +BUID_LO (phb->buid),1 ); +if (ret || (rets[0 ] ==0 )) +return 0 ; + +/* Retrieve the associated PE config address */ + ret =rtas_call (ibm_get_config_addr_info2,4 ,2 , rets, + config_addr,BUID_HI (phb->buid), +BUID_LO (phb->buid),0 ); +if (ret) { +pr_warn ("%s: Failed to get address for PHB#%x-PE#%x\n" , + __func__, phb->global_number, config_addr); +return 0 ; + } + +return rets[0 ]; + } + +if (ibm_get_config_addr_info !=RTAS_UNKNOWN_SERVICE ) { + ret =rtas_call (ibm_get_config_addr_info,4 ,2 , rets, + config_addr,BUID_HI (phb->buid), +BUID_LO (phb->buid),0 ); +if (ret) { +pr_warn ("%s: Failed to get address for PHB#%x-PE#%x\n" , + __func__, phb->global_number, config_addr); +return 0 ; + } + +return rets[0 ]; + } + +return ret; +} + +/** +* pseries_eeh_phb_reset - Reset the specified PHB +* @phb: PCI controller +* @config_adddr: the associated config address +* @option: reset option +* +* Reset the specified PHB/PE +*/ +static int pseries_eeh_phb_reset (struct pci_controller *phb,int config_addr,int option) +{ +int ret; + +/* Reset PE through RTAS call */ + ret =rtas_call (ibm_set_slot_reset,4 ,1 ,NULL , + config_addr,BUID_HI (phb->buid), +BUID_LO (phb->buid), option); + +/* If fundamental-reset not supported, try hot-reset */ +if (option ==EEH_RESET_FUNDAMENTAL && + ret ==-8 ) { + option =EEH_RESET_HOT ; + ret =rtas_call (ibm_set_slot_reset,4 ,1 ,NULL , + config_addr,BUID_HI (phb->buid), +BUID_LO (phb->buid), option); + } + +/* We need reset hold or settlement delay */ +if (option ==EEH_RESET_FUNDAMENTAL || + option ==EEH_RESET_HOT ) +msleep (EEH_PE_RST_HOLD_TIME ); +else +msleep (EEH_PE_RST_SETTLE_TIME ); + +return ret; +} + +/** +* pseries_eeh_phb_configure_bridge - Configure PCI bridges in the indicated PE +* @phb: PCI controller +* @config_adddr: the associated config address +* +* The function will be called to reconfigure the bridges included +* in the specified PE so that the mulfunctional PE would be recovered +* again. +*/ +static int pseries_eeh_phb_configure_bridge (struct pci_controller *phb,int config_addr) +{ +int ret; +/* Waiting 0.2s maximum before skipping configuration */ +int max_wait =200 ; + +while (max_wait >0 ) { + ret =rtas_call (ibm_configure_pe,3 ,1 ,NULL , + config_addr,BUID_HI (phb->buid), +BUID_LO (phb->buid)); + +if (!ret) +return ret; +if (ret <0 ) +break ; + +/* +* If RTAS returns a delay value that's above 100ms, cut it +* down to 100ms in case firmware made a mistake. For more +* on how these delay values work see rtas_busy_delay_time +*/ +if (ret >RTAS_EXTENDED_DELAY_MIN +2 && + ret <=RTAS_EXTENDED_DELAY_MAX ) + ret =RTAS_EXTENDED_DELAY_MIN +2 ; + + max_wait -=rtas_busy_delay_time (ret); + +if (max_wait <0 ) +break ; + +rtas_busy_delay (ret); + } + +pr_warn ("%s: Unable to configure bridge PHB#%x-PE#%x (%d)\n" , + __func__, phb->global_number, config_addr, ret); +/* PAPR defines -3 as "Parameter Error" for this function: */ +if (ret ==-3 ) +return -EINVAL ; +else +return -EIO ; +} +/* * Buffer for reporting slot-error-detail rtas calls. Its here * in BSS, and not dynamically alloced, so that it ends up in
@@ -110,6 +257,10 @@ static int eeh_error_buf_size;*/ static int pseries_eeh_init (void ) { +struct pci_controller *phb; +struct pci_dn *pdn; +int addr, config_addr; +/* figure out EEH RTAS function call tokens */ ibm_set_eeh_option =rtas_token ("ibm,set-eeh-option" ); ibm_set_slot_reset =rtas_token ("ibm,set-slot-reset" );
@@ -162,6 +313,22 @@ static int pseries_eeh_init(void)/* Set EEH machine dependent code */ ppc_md.pcibios_bus_add_device = pseries_pcibios_bus_add_device; +if (is_kdump_kernel () || reset_devices) { +pr_info ("Issue PHB reset ...\n" ); +list_for_each_entry (phb, &hose_list, list_node) { + pdn = list_first_entry(&PCI_DN(phb->dn)->child_list, struct pci_dn, list); + addr = (pdn->busno <<16 ) | (pdn->devfn <<8 ); + config_addr =pseries_eeh_get_config_addr (phb, addr); +/* invalid PE config addr */ +if (config_addr ==0 ) +continue ; + +pseries_eeh_phb_reset (phb, config_addr,EEH_RESET_FUNDAMENTAL ); +pseries_eeh_phb_reset (phb, config_addr,EEH_RESET_DEACTIVATE ); +pseries_eeh_phb_configure_bridge (phb, config_addr); + } + } +return 0 ; }
@@ -531,35 +698,13 @@ static int pseries_eeh_get_state(struct eeh_pe *pe, int *state)static int pseries_eeh_reset (struct eeh_pe *pe,int option) {int config_addr; -int ret;/* Figure out PE address */ config_addr = pe->config_addr;if (pe->addr) config_addr = pe->addr; -/* Reset PE through RTAS call */ - ret =rtas_call (ibm_set_slot_reset,4 ,1 ,NULL , - config_addr,BUID_HI (pe->phb->buid), -BUID_LO (pe->phb->buid), option); - -/* If fundamental-reset not supported, try hot-reset */ -if (option ==EEH_RESET_FUNDAMENTAL && - ret ==-8 ) { - option =EEH_RESET_HOT ; - ret =rtas_call (ibm_set_slot_reset,4 ,1 ,NULL , - config_addr,BUID_HI (pe->phb->buid), -BUID_LO (pe->phb->buid), option); - } - -/* We need reset hold or settlement delay */ -if (option ==EEH_RESET_FUNDAMENTAL || - option ==EEH_RESET_HOT ) -msleep (EEH_PE_RST_HOLD_TIME ); -else -msleep (EEH_PE_RST_SETTLE_TIME ); - -return ret; +return pseries_eeh_phb_reset (pe->phb, config_addr, option); }/**
@@ -661,56 +806,17 @@ static int pseries_eeh_get_log(struct eeh_pe *pe, int severity, char *drv_log, u* pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE * @pe: EEH PE * -* The function will be called to reconfigure the bridges included -* in the specified PE so that the mulfunctional PE would be recovered -* again. */ static int pseries_eeh_configure_bridge (struct eeh_pe *pe) {int config_addr; -int ret; -/* Waiting 0.2s maximum before skipping configuration */ -int max_wait =200 ;/* Figure out the PE address */ config_addr = pe->config_addr;if (pe->addr) config_addr = pe->addr; -while (max_wait >0 ) { - ret =rtas_call (ibm_configure_pe,3 ,1 ,NULL , - config_addr,BUID_HI (pe->phb->buid), -BUID_LO (pe->phb->buid)); - -if (!ret) -return ret; -if (ret <0 ) -break ; - -/* -* If RTAS returns a delay value that's above 100ms, cut it -* down to 100ms in case firmware made a mistake. For more -* on how these delay values work see rtas_busy_delay_time -*/ -if (ret >RTAS_EXTENDED_DELAY_MIN +2 && - ret <=RTAS_EXTENDED_DELAY_MAX ) - ret =RTAS_EXTENDED_DELAY_MIN +2 ; - - max_wait -=rtas_busy_delay_time (ret); - -if (max_wait <0 ) -break ; - -rtas_busy_delay (ret); - } - -pr_warn ("%s: Unable to configure bridge PHB#%x-PE#%x (%d)\n" , - __func__, pe->phb->global_number, pe->addr, ret); -/* PAPR defines -3 as "Parameter Error" for this function: */ -if (ret ==-3 ) -return -EINVAL ; -else -return -EIO ; +return pseries_eeh_phb_configure_bridge (pe->phb, config_addr); }/**
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 293/521 powerpc/pseries: Stop using eeh_ops->init()
In reply to Greg Kroah-HartmanFrom: Oliver O'Halloran <[email protected]>
[ Upstream commit 1f8fa0cd6a848ff072bffe0ee776554387128f60 ]
Fold pseries_eeh_init() into eeh_pseries_init() rather than having eeh_init() call it via eeh_ops->init(). It's simpler and it'll let us delete eeh_ops.init.
Stable-dep-of: 9aafbfa5f57a ("powerpc/pseries/eeh: use correct API for error log size")
--- arch/powerpc/platforms/pseries/eeh_pseries.c | 155 +++++++++---------- 1 file changed, 71 insertions(+), 84 deletions(-)
arch/powerpc/platforms/pseries/eeh_pseries.c +71 -84
@@ -250,88 +250,6 @@ static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];static DEFINE_SPINLOCK (slot_errbuf_lock);static int eeh_error_buf_size; -/** -* pseries_eeh_init - EEH platform dependent initialization -* -* EEH platform dependent initialization on pseries. -*/ -static int pseries_eeh_init (void ) -{ -struct pci_controller *phb; -struct pci_dn *pdn; -int addr, config_addr; - -/* figure out EEH RTAS function call tokens */ - ibm_set_eeh_option =rtas_token ("ibm,set-eeh-option" ); - ibm_set_slot_reset =rtas_token ("ibm,set-slot-reset" ); - ibm_read_slot_reset_state2 =rtas_token ("ibm,read-slot-reset-state2" ); - ibm_read_slot_reset_state =rtas_token ("ibm,read-slot-reset-state" ); - ibm_slot_error_detail =rtas_token ("ibm,slot-error-detail" ); - ibm_get_config_addr_info2 =rtas_token ("ibm,get-config-addr-info2" ); - ibm_get_config_addr_info =rtas_token ("ibm,get-config-addr-info" ); - ibm_configure_pe =rtas_token ("ibm,configure-pe" ); - -/* -* ibm,configure-pe and ibm,configure-bridge have the same semantics, -* however ibm,configure-pe can be faster. If we can't find -* ibm,configure-pe then fall back to using ibm,configure-bridge. -*/ -if (ibm_configure_pe ==RTAS_UNKNOWN_SERVICE ) - ibm_configure_pe =rtas_token ("ibm,configure-bridge" ); - -/* -* Necessary sanity check. We needn't check "get-config-addr-info" -* and its variant since the old firmware probably support address -* of domain/bus/slot/function for EEH RTAS operations. -*/ -if (ibm_set_eeh_option ==RTAS_UNKNOWN_SERVICE || - ibm_set_slot_reset ==RTAS_UNKNOWN_SERVICE || - (ibm_read_slot_reset_state2 ==RTAS_UNKNOWN_SERVICE && - ibm_read_slot_reset_state ==RTAS_UNKNOWN_SERVICE ) || - ibm_slot_error_detail ==RTAS_UNKNOWN_SERVICE || - ibm_configure_pe ==RTAS_UNKNOWN_SERVICE ) { -pr_info ("EEH functionality not supported\n" ); -return -EINVAL ; - } - -/* Initialize error log lock and size */ -spin_lock_init (&slot_errbuf_lock); - eeh_error_buf_size =rtas_token ("rtas-error-log-max" ); -if (eeh_error_buf_size ==RTAS_UNKNOWN_SERVICE ) { -pr_info ("%s: unknown EEH error log size\n" , - __func__); - eeh_error_buf_size =1024 ; - }else if (eeh_error_buf_size >RTAS_ERROR_LOG_MAX ) { -pr_info ("%s: EEH error log size %d exceeds the maximal %d\n" , - __func__, eeh_error_buf_size,RTAS_ERROR_LOG_MAX ); - eeh_error_buf_size =RTAS_ERROR_LOG_MAX ; - } - -/* Set EEH probe mode */ -eeh_add_flag (EEH_PROBE_MODE_DEVTREE |EEH_ENABLE_IO_FOR_LOG ); - -/* Set EEH machine dependent code */ - ppc_md.pcibios_bus_add_device = pseries_pcibios_bus_add_device; - -if (is_kdump_kernel () || reset_devices) { -pr_info ("Issue PHB reset ...\n" ); -list_for_each_entry (phb, &hose_list, list_node) { - pdn = list_first_entry(&PCI_DN(phb->dn)->child_list, struct pci_dn, list); - addr = (pdn->busno <<16 ) | (pdn->devfn <<8 ); - config_addr =pseries_eeh_get_config_addr (phb, addr); -/* invalid PE config addr */ -if (config_addr ==0 ) -continue ; - -pseries_eeh_phb_reset (phb, config_addr,EEH_RESET_FUNDAMENTAL ); -pseries_eeh_phb_reset (phb, config_addr,EEH_RESET_DEACTIVATE ); -pseries_eeh_phb_configure_bridge (phb, config_addr); - } - } - -return 0 ; -} -static int pseries_eeh_cap_start (struct pci_dn *pdn) {u32 status;
@@ -964,7 +882,6 @@ static int pseries_notify_resume(struct pci_dn *pdn)static struct eeh_ops pseries_eeh_ops = { .name ="pseries" , - .init = pseries_eeh_init, .probe = pseries_eeh_probe, .set_option = pseries_eeh_set_option, .get_pe_addr = pseries_eeh_get_pe_addr,
@@ -991,7 +908,77 @@ static struct eeh_ops pseries_eeh_ops = {*/ static int __init eeh_pseries_init (void ) { -int ret; +struct pci_controller *phb; +struct pci_dn *pdn; +int ret, addr, config_addr; + +/* figure out EEH RTAS function call tokens */ + ibm_set_eeh_option =rtas_token ("ibm,set-eeh-option" ); + ibm_set_slot_reset =rtas_token ("ibm,set-slot-reset" ); + ibm_read_slot_reset_state2 =rtas_token ("ibm,read-slot-reset-state2" ); + ibm_read_slot_reset_state =rtas_token ("ibm,read-slot-reset-state" ); + ibm_slot_error_detail =rtas_token ("ibm,slot-error-detail" ); + ibm_get_config_addr_info2 =rtas_token ("ibm,get-config-addr-info2" ); + ibm_get_config_addr_info =rtas_token ("ibm,get-config-addr-info" ); + ibm_configure_pe =rtas_token ("ibm,configure-pe" ); + +/* +* ibm,configure-pe and ibm,configure-bridge have the same semantics, +* however ibm,configure-pe can be faster. If we can't find +* ibm,configure-pe then fall back to using ibm,configure-bridge. +*/ +if (ibm_configure_pe ==RTAS_UNKNOWN_SERVICE ) + ibm_configure_pe =rtas_token ("ibm,configure-bridge" ); + +/* +* Necessary sanity check. We needn't check "get-config-addr-info" +* and its variant since the old firmware probably support address +* of domain/bus/slot/function for EEH RTAS operations. +*/ +if (ibm_set_eeh_option ==RTAS_UNKNOWN_SERVICE || + ibm_set_slot_reset ==RTAS_UNKNOWN_SERVICE || + (ibm_read_slot_reset_state2 ==RTAS_UNKNOWN_SERVICE && + ibm_read_slot_reset_state ==RTAS_UNKNOWN_SERVICE ) || + ibm_slot_error_detail ==RTAS_UNKNOWN_SERVICE || + ibm_configure_pe ==RTAS_UNKNOWN_SERVICE ) { +pr_info ("EEH functionality not supported\n" ); +return -EINVAL ; + } + +/* Initialize error log lock and size */ +spin_lock_init (&slot_errbuf_lock); + eeh_error_buf_size =rtas_token ("rtas-error-log-max" ); +if (eeh_error_buf_size ==RTAS_UNKNOWN_SERVICE ) { +pr_info ("%s: unknown EEH error log size\n" , + __func__); + eeh_error_buf_size =1024 ; + }else if (eeh_error_buf_size >RTAS_ERROR_LOG_MAX ) { +pr_info ("%s: EEH error log size %d exceeds the maximal %d\n" , + __func__, eeh_error_buf_size,RTAS_ERROR_LOG_MAX ); + eeh_error_buf_size =RTAS_ERROR_LOG_MAX ; + } + +/* Set EEH probe mode */ +eeh_add_flag (EEH_PROBE_MODE_DEVTREE |EEH_ENABLE_IO_FOR_LOG ); + +/* Set EEH machine dependent code */ + ppc_md.pcibios_bus_add_device = pseries_pcibios_bus_add_device; + +if (is_kdump_kernel () || reset_devices) { +pr_info ("Issue PHB reset ...\n" ); +list_for_each_entry (phb, &hose_list, list_node) { + pdn = list_first_entry(&PCI_DN(phb->dn)->child_list, struct pci_dn, list); + addr = (pdn->busno <<16 ) | (pdn->devfn <<8 ); + config_addr =pseries_eeh_get_config_addr (phb, addr); +/* invalid PE config addr */ +if (config_addr ==0 ) +continue ; + +pseries_eeh_phb_reset (phb, config_addr,EEH_RESET_FUNDAMENTAL ); +pseries_eeh_phb_reset (phb, config_addr,EEH_RESET_DEACTIVATE ); +pseries_eeh_phb_configure_bridge (phb, config_addr); + } + } ret =eeh_ops_register (&pseries_eeh_ops);if (!ret)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 294/521 powerpc/eeh: Drop redundant spinlock initialization
In reply to Greg Kroah-HartmanFrom: Haowen Bai <[email protected]>
[ Upstream commit 3def164a5cedad9117859dd4610cae2cc59cb6d2 ]
slot_errbuf_lock has declared and initialized by DEFINE_SPINLOCK, so we don't need to spin_lock_init again, drop it.
Stable-dep-of: 9aafbfa5f57a ("powerpc/pseries/eeh: use correct API for error log size")
--- arch/powerpc/platforms/pseries/eeh_pseries.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -2
@@ -945,8 +945,7 @@ static int __init eeh_pseries_init(void)return -EINVAL ; } -/* Initialize error log lock and size */ -spin_lock_init (&slot_errbuf_lock); +/* Initialize error log size */ eeh_error_buf_size =rtas_token ("rtas-error-log-max" );if (eeh_error_buf_size ==RTAS_UNKNOWN_SERVICE ) { pr_info("%s: unknown EEH error log size\n",
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 295/521 powerpc/pseries/eeh: use correct API for error log size
In reply to Greg Kroah-HartmanFrom: Nathan Lynch <[email protected]>
[ Upstream commit 9aafbfa5f57a4b75bafd3bed0191e8429c5fa618 ]
rtas-error-log-max is not the name of an RTAS function, so rtas_token() is not the appropriate API for retrieving its value. We already have rtas_get_error_log_max() which returns a sensible value if the property is absent for any reason, so use that instead.
--- arch/powerpc/platforms/pseries/eeh_pseries.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -10
@@ -946,16 +946,7 @@ static int __init eeh_pseries_init(void) }/* Initialize error log size */ - eeh_error_buf_size =rtas_token ("rtas-error-log-max" ); -if (eeh_error_buf_size ==RTAS_UNKNOWN_SERVICE ) { -pr_info ("%s: unknown EEH error log size\n" , - __func__); - eeh_error_buf_size =1024 ; - }else if (eeh_error_buf_size >RTAS_ERROR_LOG_MAX ) { -pr_info ("%s: EEH error log size %d exceeds the maximal %d\n" , - __func__, eeh_error_buf_size,RTAS_ERROR_LOG_MAX ); - eeh_error_buf_size =RTAS_ERROR_LOG_MAX ; - } + eeh_error_buf_size =rtas_get_error_log_max ();/* Set EEH probe mode */ eeh_add_flag (EEH_PROBE_MODE_DEVTREE |EEH_ENABLE_IO_FOR_LOG );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 296/521 rtc: st-lpc: Add missing clk_disable_unprepare in st_rtc_probe()
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
[ Upstream commit 5fb733d7bd6949e90028efdce8bd528c6ab7cf1e ]
The clk_disable_unprepare() should be called in the error handling of clk_get_rate(), fix it.
--- drivers/rtc/rtc-st-lpc.c | 1 + 1 file changed, 1 insertion(+)
drivers/rtc/rtc-st-lpc.c +1 -0
@@ -249,6 +249,7 @@ static int st_rtc_probe(struct platform_device *pdev) rtc->clkrate =clk_get_rate (rtc->clk);if (!rtc->clkrate) { +clk_disable_unprepare (rtc->clk);dev_err (&pdev->dev,"Unable to fetch clock rate\n" );return -EINVAL ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 297/521 nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure
In reply to Greg Kroah-HartmanFrom: Dan Aloni <[email protected]>
[ Upstream commit 3bc8edc98bd43540dbe648e4ef91f443d6d20a24 ]
On error situation clp->cl_cb_conn.cb_xprt should not be given a reference to the xprt otherwise both client cleanup and the error handling path of the caller call to put it. Better to delay handing over the reference to a later branch.
[ 72.530665] refcount_t: underflow; use-after-free. [ 72.531933] WARNING: CPU: 0 PID: 173 at lib/refcount.c:28 refcount_warn_saturate+0xcf/0x120 [ 72.533075] Modules linked in: nfsd(OE) nfsv4(OE) nfsv3(OE) nfs(OE) lockd(OE) compat_nfs_ssc(OE) nfs_acl(OE) rpcsec_gss_krb5(OE) auth_rpcgss(OE) rpcrdma(OE) dns_resolver fscache netfs grace rdma_cm iw_cm ib_cm sunrpc(OE) mlx5_ib mlx5_core mlxfw pci_hyperv_intf ib_uverbs ib_core xt_MASQUERADE nf_conntrack_netlink nft_counter xt_addrtype nft_compat br_netfilter bridge stp llc nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_set overlay nf_tables nfnetlink crct10dif_pclmul crc32_pclmul ghash_clmulni_intel xfs serio_raw virtio_net virtio_blk net_failover failover fuse [last unloaded: sunrpc] [ 72.540389] CPU: 0 PID: 173 Comm: kworker/u16:5 Tainted: G OE 5.15.82-dan #1 [ 72.541511] Hardware name: Red Hat KVM/RHEL-AV, BIOS 1.16.0-3.module+el8.7.0+1084+97b81f61 04/01/2014 [ 72.542717] Workqueue: nfsd4_callbacks nfsd4_run_cb_work [nfsd] [ 72.543575] RIP: 0010:refcount_warn_saturate+0xcf/0x120 [ 72.544299] Code: 55 00 0f 0b 5d e9 01 50 98 00 80 3d 75 9e 39 08 00 0f 85 74 ff ff ff 48 c7 c7 e8 d1 60 8e c6 05 61 9e 39 08 01 e8 f6 51 55 00 <0f> 0b 5d e9 d9 4f 98 00 80 3d 4b 9e 39 08 00 0f 85 4c ff ff ff 48 [ 72.546666] RSP: 0018:ffffb3f841157cf0 EFLAGS: 00010286 [ 72.547393] RAX: 0000000000000026 RBX: ffff89ac6231d478 RCX: 0000000000000000 [ 72.548324] RDX: ffff89adb7c2c2c0 RSI: ffff89adb7c205c0 RDI: ffff89adb7c205c0 [ 72.549271] RBP: ffffb3f841157cf0 R08: 0000000000000000 R09: c0000000ffefffff [ 72.550209] R10: 0000000000000001 R11: ffffb3f841157ad0 R12: ffff89ac6231d180 [ 72.551142] R13: ffff89ac6231d478 R14: ffff89ac40c06180 R15: ffff89ac6231d4b0 [ 72.552089] FS: 0000000000000000(0000) GS:ffff89adb7c00000(0000) knlGS:0000000000000000 [ 72.553175] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 72.553934] CR2: 0000563a310506a8 CR3: 0000000109a66000 CR4: 0000000000350ef0 [ 72.554874] Call Trace: [ 72.555278] <TASK> [ 72.555614] svc_xprt_put+0xaf/0xe0 [sunrpc] [ 72.556276] nfsd4_process_cb_update.isra.11+0xb7/0x410 [nfsd] [ 72.557087] ? update_load_avg+0x82/0x610 [ 72.557652] ? cpuacct_charge+0x60/0x70 [ 72.558212] ? dequeue_entity+0xdb/0x3e0 [ 72.558765] ? queued_spin_unlock+0x9/0x20 [ 72.559358] nfsd4_run_cb_work+0xfc/0x270 [nfsd] [ 72.560031] process_one_work+0x1df/0x390 [ 72.560600] worker_thread+0x37/0x3b0 [ 72.561644] ? process_one_work+0x390/0x390 [ 72.562247] kthread+0x12f/0x150 [ 72.562710] ? set_kthread_struct+0x50/0x50 [ 72.563309] ret_from_fork+0x22/0x30 [ 72.563818] </TASK> [ 72.564189] ---[ end trace 031117b1c72ec616 ]--- [ 72.566019] list_add corruption. next->prev should be prev (ffff89ac4977e538), but was ffff89ac4763e018. (next=ffff89ac4763e018). [ 72.567647] ------------[ cut here ]------------
--- fs/nfsd/nfs4callback.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfsd/nfs4callback.c +3 -1
@@ -800,7 +800,6 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c }else {if (!conn->cb_xprt)return -EINVAL ; - clp->cl_cb_conn.cb_xprt = conn->cb_xprt; clp->cl_cb_session = ses; args.bc_xprt = conn->cb_xprt; args.prognumber = clp->cl_cb_session->se_cb_prog;
@@ -820,6 +819,9 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *crpc_shutdown_client (client);return PTR_ERR (cred); } + +if (clp->cl_minorversion !=0 ) + clp->cl_cb_conn.cb_xprt = conn->cb_xprt; clp->cl_cb_client = client; clp->cl_cb_cred = cred;return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 298/521 mISDN: hfcsusb: dont call dev_kfree_skb/kfree_skb() under spin_lock_irqsave()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit ddc9648db162eee556edd5222d2808fe33730203 ]
It is not allowed to call kfree_skb() or consume_skb() from hardware interrupt context or with hardware interrupts being disabled.
It should use dev_kfree_skb_irq() or dev_consume_skb_irq() instead. The difference between them is free reason, dev_kfree_skb_irq() means the SKB is dropped in error and dev_consume_skb_irq() means the SKB is consumed in normal.
skb_queue_purge() is called under spin_lock_irqsave() in hfcusb_l2l1D(), kfree_skb() is called in it, to fix this, use skb_queue_splice_init() to move the dch->squeue to a free queue, also enqueue the tx_skb and rx_skb, at last calling __skb_queue_purge() to free the SKBs afer unlock.
In tx_iso_complete(), dev_kfree_skb() is called to consume the transmitted SKB, so replace it with dev_consume_skb_irq().
--- drivers/isdn/hardware/mISDN/hfcsusb.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/isdn/hardware/mISDN/hfcsusb.c +8 -4
@@ -337,20 +337,24 @@ hfcusb_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb)test_and_clear_bit (FLG_L2_ACTIVATED , &dch->Flags);if (hw->protocol ==ISDN_P_NT_S0 ) { +struct sk_buff_head free_queue; + +__skb_queue_head_init (&free_queue);hfcsusb_ph_command (hw,HFC_L1_DEACTIVATE_NT );spin_lock_irqsave (&hw->lock, flags); -skb_queue_purge (&dch->squeue); +skb_queue_splice_init (&dch->squeue, &free_queue);if (dch->tx_skb) { -dev_kfree_skb (dch->tx_skb); +__skb_queue_tail (&free_queue, dch->tx_skb); dch->tx_skb =NULL ; } dch->tx_idx =0 ;if (dch->rx_skb) { -dev_kfree_skb (dch->rx_skb); +__skb_queue_tail (&free_queue, dch->rx_skb); dch->rx_skb =NULL ; }test_and_clear_bit (FLG_TX_BUSY , &dch->Flags);spin_unlock_irqrestore (&hw->lock, flags); +__skb_queue_purge (&free_queue);#ifdef FIXME if (test_and_clear_bit (FLG_L1_BUSY , &dch->Flags))dchannel_sched_event (&hc->dch,D_CLEARBUSY );
@@ -1344,7 +1348,7 @@ tx_iso_complete(struct urb *urb)printk ("\n" ); } -dev_kfree_skb (tx_skb); +dev_consume_skb_irq (tx_skb); tx_skb =NULL ;if (fifo->dch &&get_next_dframe (fifo->dch)) tx_skb = fifo->dch->tx_skb;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 299/521 mISDN: hfcpci: dont call dev_kfree_skb/kfree_skb() under spin_lock_irqsave()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit f0f596bd75a9d573ca9b587abb39cee0b916bb82 ]
It is not allowed to call kfree_skb() or consume_skb() from hardware interrupt context or with hardware interrupts being disabled.
skb_queue_purge() is called under spin_lock_irqsave() in hfcpci_l2l1D(), kfree_skb() is called in it, to fix this, use skb_queue_splice_init() to move the dch->squeue to a free queue, also enqueue the tx_skb and rx_skb, at last calling __skb_queue_purge() to free the SKBs afer unlock.
--- drivers/isdn/hardware/mISDN/hfcpci.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/isdn/hardware/mISDN/hfcpci.c +9 -4
@@ -1633,16 +1633,19 @@ hfcpci_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb)test_and_clear_bit (FLG_L2_ACTIVATED , &dch->Flags);spin_lock_irqsave (&hc->lock, flags);if (hc->hw.protocol ==ISDN_P_NT_S0 ) { +struct sk_buff_head free_queue; + +__skb_queue_head_init (&free_queue);/* prepare deactivation */ Write_hfc (hc,HFCPCI_STATES ,0x40 ); -skb_queue_purge (&dch->squeue); +skb_queue_splice_init (&dch->squeue, &free_queue);if (dch->tx_skb) { -dev_kfree_skb (dch->tx_skb); +__skb_queue_tail (&free_queue, dch->tx_skb); dch->tx_skb =NULL ; } dch->tx_idx =0 ;if (dch->rx_skb) { -dev_kfree_skb (dch->rx_skb); +__skb_queue_tail (&free_queue, dch->rx_skb); dch->rx_skb =NULL ; }test_and_clear_bit (FLG_TX_BUSY , &dch->Flags);
@@ -1655,10 +1658,12 @@ hfcpci_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb) hc->hw.mst_m &= ~HFCPCI_MASTER ;Write_hfc (hc,HFCPCI_MST_MODE , hc->hw.mst_m); ret =0 ; +spin_unlock_irqrestore (&hc->lock, flags); +__skb_queue_purge (&free_queue); }else { ret =l1_event (dch->l1, hh->prim); +spin_unlock_irqrestore (&hc->lock, flags); } -spin_unlock_irqrestore (&hc->lock, flags);break ; }if (!ret)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 300/521 mISDN: hfcmulti: dont call dev_kfree_skb/kfree_skb() under spin_lock_irqsave()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 1232946cf522b8de9e398828bde325d7c41f29dd ]
It is not allowed to call kfree_skb() or consume_skb() from hardware interrupt context or with hardware interrupts being disabled.
skb_queue_purge() is called under spin_lock_irqsave() in handle_dmsg() and hfcm_l1callback(), kfree_skb() is called in them, to fix this, use skb_queue_splice_init() to move the dch->squeue to a free queue, also enqueue the tx_skb and rx_skb, at last calling __skb_queue_purge() to free the SKBs afer unlock.
--- drivers/isdn/hardware/mISDN/hfcmulti.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/isdn/hardware/mISDN/hfcmulti.c +13 -6
@@ -3233,6 +3233,7 @@ static int hfcm_l1callback(struct dchannel *dch, u_int cmd) {struct hfc_multi *hc = dch->hw; +struct sk_buff_head free_queue;u_long flags;switch (cmd) {
@@ -3261,6 +3262,7 @@ hfcm_l1callback(struct dchannel *dch, u_int cmd)l1_event (dch->l1,HW_POWERUP_IND );break ;case HW_DEACT_REQ : +__skb_queue_head_init (&free_queue);/* start deactivation */ spin_lock_irqsave (&hc->lock, flags);if (hc->ctype ==HFC_TYPE_E1 ) {
@@ -3280,20 +3282,21 @@ hfcm_l1callback(struct dchannel *dch, u_int cmd)plxsd_checksync (hc,0 ); } } -skb_queue_purge (&dch->squeue); +skb_queue_splice_init (&dch->squeue, &free_queue);if (dch->tx_skb) { -dev_kfree_skb (dch->tx_skb); +__skb_queue_tail (&free_queue, dch->tx_skb); dch->tx_skb =NULL ; } dch->tx_idx =0 ;if (dch->rx_skb) { -dev_kfree_skb (dch->rx_skb); +__skb_queue_tail (&free_queue, dch->rx_skb); dch->rx_skb =NULL ; }test_and_clear_bit (FLG_TX_BUSY , &dch->Flags);if (test_and_clear_bit (FLG_BUSY_TIMER , &dch->Flags))del_timer (&dch->timer);spin_unlock_irqrestore (&hc->lock, flags); +__skb_queue_purge (&free_queue);break ;case HW_POWERUP_REQ :spin_lock_irqsave (&hc->lock, flags);
@@ -3400,6 +3403,9 @@ handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)case PH_DEACTIVATE_REQ :test_and_clear_bit (FLG_L2_ACTIVATED , &dch->Flags);if (dch->dev.D.protocol !=ISDN_P_TE_S0 ) { +struct sk_buff_head free_queue; + +__skb_queue_head_init (&free_queue);spin_lock_irqsave (&hc->lock, flags);if (debug &DEBUG_HFCMULTI_MSG ) printk(KERN_DEBUG
@@ -3421,14 +3427,14 @@ handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)/* deactivate */ dch->state =1 ; } -skb_queue_purge (&dch->squeue); +skb_queue_splice_init (&dch->squeue, &free_queue);if (dch->tx_skb) { -dev_kfree_skb (dch->tx_skb); +__skb_queue_tail (&free_queue, dch->tx_skb); dch->tx_skb =NULL ; } dch->tx_idx =0 ;if (dch->rx_skb) { -dev_kfree_skb (dch->rx_skb); +__skb_queue_tail (&free_queue, dch->rx_skb); dch->rx_skb =NULL ; }test_and_clear_bit (FLG_TX_BUSY , &dch->Flags);
@@ -3440,6 +3446,7 @@ handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)#endif ret =0 ;spin_unlock_irqrestore (&hc->lock, flags); +__skb_queue_purge (&free_queue); }else ret =l1_event (dch->l1, hh->prim);break ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 301/521 nfc: pn533: Clear nfc_target before being used
In reply to Greg Kroah-HartmanFrom: Minsuk Kang <[email protected]>
[ Upstream commit 9f28157778ede0d4f183f7ab3b46995bb400abbe ]
Fix a slab-out-of-bounds read that occurs in nla_put() called from nfc_genl_send_target() when target->sensb_res_len, which is duplicated from an nfc_target in pn533, is too large as the nfc_target is not properly initialized and retains garbage values. Clear nfc_targets with memset() before they are used.
Found by a modified version of syzkaller.
BUG: KASAN: slab-out-of-bounds in nla_put Call Trace: memcpy nla_put nfc_genl_dump_targets genl_lock_dumpit netlink_dump __netlink_dump_start genl_family_rcv_msg_dumpit genl_rcv_msg netlink_rcv_skb genl_rcv netlink_unicast netlink_sendmsg sock_sendmsg ____sys_sendmsg ___sys_sendmsg __sys_sendmsg do_syscall_64
--- drivers/nfc/pn533/pn533.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nfc/pn533/pn533.c +4 -0
@@ -1305,6 +1305,8 @@ static int pn533_poll_dep_complete(struct pn533 *dev, void *arg,if (IS_ERR (resp))return PTR_ERR (resp); +memset (&nfc_target,0 ,sizeof (struct nfc_target )); + rsp = (struct pn533_cmd_jump_dep_response *)resp->data; rc = rsp->status &PN533_CMD_RET_MASK ;
@@ -1786,6 +1788,8 @@ static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,dev_dbg (dev->dev,"Creating new target\n" ); +memset (&nfc_target,0 ,sizeof (struct nfc_target )); + nfc_target.supported_protocols =NFC_PROTO_NFC_DEP_MASK ; nfc_target.nfcid1_len =10 ;memcpy (nfc_target.nfcid1, rsp->nfcid3t, nfc_target.nfcid1_len);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 302/521 r6040: Fix kmemleak in probe and remove
In reply to Greg Kroah-HartmanFrom: Li Zetao <[email protected]>
[ Upstream commit 7e43039a49c2da45edc1d9d7c9ede4003ab45a5f ]
There is a memory leaks reported by kmemleak:
unreferenced object 0xffff888116111000 (size 2048):
comm "modprobe", pid 817, jiffies 4294759745 (age 76.502s)
hex dump (first 32 bytes):
00 c4 0a 04 81 88 ff ff 08 10 11 16 81 88 ff ff ................
08 10 11 16 81 88 ff ff 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff815bcd82>] kmalloc_trace+0x22/0x60
[<ffffffff827e20ee>] phy_device_create+0x4e/0x90
[<ffffffff827e6072>] get_phy_device+0xd2/0x220
[<ffffffff827e7844>] mdiobus_scan+0xa4/0x2e0
[<ffffffff827e8be2>] __mdiobus_register+0x482/0x8b0
[<ffffffffa01f5d24>] r6040_init_one+0x714/0xd2c [r6040]
...The problem occurs in probe process as follows:
r6040_init_one:
mdiobus_register
mdiobus_scan <- alloc and register phy_device,
the reference count of phy_device is 3
r6040_mii_probe
phy_connect <- connect to the first phy_device,
so the reference count of the first phy_device is 4, others are 3
register_netdev <- fault inject succeeded, goto error handling path
// error handling path
err_out_mdio_unregister:
mdiobus_unregister(lp->mii_bus);
err_out_mdio:
mdiobus_free(lp->mii_bus); <- the reference count of the first
phy_device is 1, it is not released and other phy_devices are released
// similarly, the remove process also has the same problem
The root cause is traced to the phy_device is not disconnected when removes one r6040 device in r6040_remove_one() or on error handling path after r6040_mii probed successfully. In r6040_mii_probe(), a net ethernet device is connected to the first PHY device of mii_bus, in order to notify the connected driver when the link status changes, which is the default behavior of the PHY infrastructure to handle everything. Therefore the phy_device should be disconnected when removes one r6040 device or on error handling path.
Fix it by adding phy_disconnect() when removes one r6040 device or on error handling path after r6040_mii probed successfully.
--- drivers/net/ethernet/rdc/r6040.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/rdc/r6040.c +4 -1
@@ -1184,10 +1184,12 @@ static int r6040_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) err =register_netdev (dev);if (err) {dev_err (&pdev->dev,"Failed to register net device\n" ); - goto err_out_mdio_unregister; + goto err_out_phy_disconnect; }return 0 ; +err_out_phy_disconnect: +phy_disconnect (dev->phydev); err_out_mdio_unregister:mdiobus_unregister (lp->mii_bus); err_out_mdio:
@@ -1211,6 +1213,7 @@ static void r6040_remove_one(struct pci_dev *pdev)struct r6040_private *lp =netdev_priv (dev);unregister_netdev (dev); +phy_disconnect (dev->phydev);mdiobus_unregister (lp->mii_bus);mdiobus_free (lp->mii_bus);netif_napi_del (&lp->napi);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 303/521 rtc: mxc_v2: Add missing clk_disable_unprepare()
In reply to Greg Kroah-HartmanFrom: GUO Zihua <[email protected]>
[ Upstream commit 55d5a86618d3b1a768bce01882b74cbbd2651975 ]
The call to clk_disable_unprepare() is left out in the error handling of devm_rtc_allocate_device. Add it back.
--- drivers/rtc/rtc-mxc_v2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/rtc/rtc-mxc_v2.c +3 -1
@@ -335,8 +335,10 @@ static int mxc_rtc_probe(struct platform_device *pdev) } pdata->rtc =devm_rtc_allocate_device (&pdev->dev); -if (IS_ERR (pdata->rtc)) +if (IS_ERR (pdata->rtc)) { +clk_disable_unprepare (pdata->clk);return PTR_ERR (pdata->rtc); + } pdata->rtc->ops = &mxc_rtc_ops; pdata->rtc->range_max =U32_MAX ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 304/521 openvswitch: Fix flow lookup to use unmasked key
In reply to Greg Kroah-HartmanFrom: Eelco Chaudron <[email protected]>
[ Upstream commit 68bb10101e6b0a6bb44e9c908ef795fc4af99eae ]
The commit mentioned below causes the ovs_flow_tbl_lookup() function to be called with the masked key. However, it's supposed to be called with the unmasked key. This due to the fact that the datapath supports installing wider flows, and OVS relies on this behavior. For example if ipv4(src=1.1.1.1/192.0.0.0, dst=1.1.1.2/192.0.0.0) exists, a wider flow (smaller mask) of ipv4(src=192.1.1.1/128.0.0.0,dst=192.1.1.2/ 128.0.0.0) is allowed to be added.
However, if we try to add a wildcard rule, the installation fails:
$ ovs-appctl dpctl/add-flow system@myDP "in_port(1),eth_type(0x0800), \ ipv4(src=1.1.1.1/192.0.0.0,dst=1.1.1.2/192.0.0.0,frag=no)" 2 $ ovs-appctl dpctl/add-flow system@myDP "in_port(1),eth_type(0x0800), \ ipv4(src=192.1.1.1/0.0.0.0,dst=49.1.1.2/0.0.0.0,frag=no)" 2 ovs-vswitchd: updating flow table (File exists)
The reason is that the key used to determine if the flow is already present in the system uses the original key ANDed with the mask. This results in the IP address not being part of the (miniflow) key, i.e., being substituted with an all-zero value. When doing the actual lookup, this results in the key wrongfully matching the first flow, and therefore the flow does not get installed.
This change reverses the commit below, but rather than having the key on the stack, it's allocated.
--- net/openvswitch/datapath.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
net/openvswitch/datapath.c +16 -9
@@ -903,6 +903,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)struct sw_flow_mask mask;struct sk_buff *reply;struct datapath *dp; +struct sw_flow_key *key;struct sw_flow_actions *acts;struct sw_flow_match match;u32 ufid_flags =ovs_nla_get_ufid_flags (a[OVS_FLOW_ATTR_UFID_FLAGS ]);
@@ -930,24 +931,26 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info) }/* Extract key. */ -ovs_match_init (&match, &new_flow->key, false, &mask); + key =kzalloc (sizeof (*key),GFP_KERNEL ); +if (!key) { + error = -ENOMEM ; + goto err_kfree_key; + } + +ovs_match_init (&match, key, false, &mask); error =ovs_nla_get_match (net, &match, a[OVS_FLOW_ATTR_KEY ], a[OVS_FLOW_ATTR_MASK ], log);if (error) goto err_kfree_flow; +ovs_flow_mask_key (&new_flow->key, key, true, &mask); +/* Extract flow identifier. */ error =ovs_nla_get_identifier (&new_flow->id, a[OVS_FLOW_ATTR_UFID ], - &new_flow->key, log); + key, log);if (error) goto err_kfree_flow; -/* unmasked key is needed to match when ufid is not used. */ -if (ovs_identifier_is_key (&new_flow->id)) - match.key = new_flow->id.unmasked_key; - -ovs_flow_mask_key (&new_flow->key, &new_flow->key, true, &mask); -/* Validate actions. */ error =ovs_nla_copy_actions (net, a[OVS_FLOW_ATTR_ACTIONS ], &new_flow->key, &acts, log);
@@ -974,7 +977,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)if (ovs_identifier_is_ufid (&new_flow->id)) flow =ovs_flow_tbl_lookup_ufid (&dp->table, &new_flow->id);if (!flow) - flow =ovs_flow_tbl_lookup (&dp->table, &new_flow->key); + flow =ovs_flow_tbl_lookup (&dp->table, key);if (likely (!flow)) {rcu_assign_pointer (new_flow->sf_acts, acts);
@@ -1044,6 +1047,8 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)if (reply)ovs_notify (&dp_flow_genl_family, reply, info); + +kfree (key);return 0 ; err_unlock_ovs:
@@ -1053,6 +1058,8 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)ovs_nla_free_flow_actions (acts); err_kfree_flow:ovs_flow_free (new_flow, false); +err_kfree_key: +kfree (key); error:return error; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 305/521 skbuff: Account for tail adjustment during pull operations
In reply to Greg Kroah-HartmanFrom: Subash Abhinov Kasiviswanathan <[email protected]>
[ Upstream commit 2d7afdcbc9d32423f177ee12b7c93783aea338fb ]
Extending the tail can have some unexpected side effects if a program uses a helper like BPF_FUNC_skb_pull_data to read partial content beyond the head skb headlen when all the skbs in the gso frag_list are linear with no head_frag -
kernel BUG at net/core/skbuff.c:4219!
pc : skb_segment+0xcf4/0xd2c lr : skb_segment+0x63c/0xd2c Call trace: skb_segment+0xcf4/0xd2c __udp_gso_segment+0xa4/0x544 udp4_ufo_fragment+0x184/0x1c0 inet_gso_segment+0x16c/0x3a4 skb_mac_gso_segment+0xd4/0x1b0 __skb_gso_segment+0xcc/0x12c udp_rcv_segment+0x54/0x16c udp_queue_rcv_skb+0x78/0x144 udp_unicast_rcv_skb+0x8c/0xa4 __udp4_lib_rcv+0x490/0x68c udp_rcv+0x20/0x30 ip_protocol_deliver_rcu+0x1b0/0x33c ip_local_deliver+0xd8/0x1f0 ip_rcv+0x98/0x1a4 deliver_ptype_list_skb+0x98/0x1ec __netif_receive_skb_core+0x978/0xc60
Fix this by marking these skbs as GSO_DODGY so segmentation can handle the tail updates accordingly.
--- net/core/skbuff.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/skbuff.c +3 -0
@@ -1953,6 +1953,9 @@ void *__pskb_pull_tail(struct sk_buff *skb, int delta) insp = list; }else {/* Eaten partially. */ +if (skb_is_gso (skb) && !list->head_frag && +skb_headlen (list)) +skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;if (skb_shared (list)) {/* Sucks! We need to fork list. :-( */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 306/521 net_sched: reject TCF_EM_SIMPLE case for complex ematch module
In reply to Greg Kroah-HartmanFrom: Cong Wang <[email protected]>
[ Upstream commit 9cd3fd2054c3b3055163accbf2f31a4426f10317 ]
When TCF_EM_SIMPLE was introduced, it is supposed to be convenient for ematch implementation:
https://lore.kernel.org/all/[email protected]/
"You don't have to, providing a 32bit data chunk without TCF_EM_SIMPLE set will simply result in allocating & copy. It's an optimization, nothing more."
So if an ematch module provides ops->datalen that means it wants a complex data structure (saved in its em->data) instead of a simple u32 value. We should simply reject such a combination, otherwise this u32 could be misinterpreted as a pointer.
--- net/sched/ematch.c | 2 ++ 1 file changed, 2 insertions(+)
net/sched/ematch.c +2 -0
@@ -259,6 +259,8 @@ static int tcf_em_validate(struct tcf_proto *tp,* the value carried. */ if (em_hdr->flags &TCF_EM_SIMPLE ) { +if (em->ops->datalen >0 ) + goto errout;if (data_len <sizeof (u32)) goto errout; em->data = *(u32 *) data;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 307/521 rxrpc: Fix missing unlock in rxrpc_do_sendmsg()
In reply to Greg Kroah-HartmanFrom: David Howells <[email protected]>
[ Upstream commit 4feb2c44629e6f9b459b41a5a60491069d346a95 ]
One of the error paths in rxrpc_do_sendmsg() doesn't unlock the call mutex before returning. Fix it to do this.
Note that this still doesn't get rid of the checker warning:
../net/rxrpc/sendmsg.c:617:5: warning: context imbalance in 'rxrpc_do_sendmsg' - wrong count at exit
I think the interplay between the socket lock and the call's user_mutex may be too complicated for checker to analyse, especially as rxrpc_new_client_call_for_sendmsg(), which it calls, returns with the call's user_mutex if successful but unconditionally drops the socket lock.
--- net/rxrpc/sendmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/sendmsg.c +1 -1
@@ -689,7 +689,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)if (call->tx_total_len !=-1 || call->tx_pending || call->tx_top !=0 ) - goto error_put; + goto out_put_unlock; call->tx_total_len = p.call.tx_total_len; } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 308/521 myri10ge: Fix an error handling path in myri10ge_probe()
In reply to Greg Kroah-HartmanFrom: Christophe JAILLET <[email protected]>
[ Upstream commit d83b950d44d2982c0e62e3d81b0f35ab09431008 ]
Some memory allocated in myri10ge_probe_slices() is not released in the error handling path of myri10ge_probe().
Add the corresponding kfree(), as already done in the remove function.
--- drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/myricom/myri10ge/myri10ge.c +1 -0
@@ -3960,6 +3960,7 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)myri10ge_free_slices (mgp); abort_with_firmware: +kfree (mgp->msix_vectors);myri10ge_dummy_rdma (mgp,0 ); abort_with_ioremap:
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 309/521 net: stream: purge sk_error_queue in sk_stream_kill_queues()
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
[ Upstream commit e0c8bccd40fc1c19e1d246c39bcf79e357e1ada3 ]
Changheon Lee reported TCP socket leaks, with a nice repro.
It seems we leak TCP sockets with the following sequence:
1) SOF_TIMESTAMPING_TX_ACK is enabled on the socket.
Each ACK will cook an skb put in error queue, from __skb_tstamp_tx(). __skb_tstamp_tx() is using skb_clone(), unless SOF_TIMESTAMPING_OPT_TSONLY was also requested.
2) If the application is also using MSG_ZEROCOPY, then we put in the error queue cloned skbs that had a struct ubuf_info attached to them.
Whenever an struct ubuf_info is allocated, sock_zerocopy_alloc() does a sock_hold().
As long as the cloned skbs are still in sk_error_queue, socket refcount is kept elevated.
3) Application closes the socket, while error queue is not empty.
Since tcp_close() no longer purges the socket error queue, we might end up with a TCP socket with at least one skb in error queue keeping the socket alive forever.
This bug can be (ab)used to consume all kernel memory and freeze the host.
We need to purge the error queue, with proper synchronization against concurrent writers.
--- net/core/stream.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/core/stream.c +6 -0
@@ -196,6 +196,12 @@ void sk_stream_kill_queues(struct sock *sk)/* First the read buffer. */ __skb_queue_purge (&sk->sk_receive_queue); +/* Next, the error queue. +* We need to use queue lock, because other threads might +* add packets to the queue without socket lock being held. +*/ +skb_queue_purge (&sk->sk_error_queue); +/* Next, the write queue. */ WARN_ON (!skb_queue_empty (&sk->sk_write_queue));
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 310/521 binfmt_misc: fix shift-out-of-bounds in check_special_flags
In reply to Greg Kroah-HartmanFrom: Liu Shixin <[email protected]>
[ Upstream commit 6a46bf558803dd2b959ca7435a5c143efe837217 ]
UBSAN reported a shift-out-of-bounds warning:
left shift of 1 by 31 places cannot be represented in type 'int'
Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x8d/0xcf lib/dump_stack.c:106 ubsan_epilogue+0xa/0x44 lib/ubsan.c:151 __ubsan_handle_shift_out_of_bounds+0x1e7/0x208 lib/ubsan.c:322 check_special_flags fs/binfmt_misc.c:241 [inline] create_entry fs/binfmt_misc.c:456 [inline] bm_register_write+0x9d3/0xa20 fs/binfmt_misc.c:654 vfs_write+0x11e/0x580 fs/read_write.c:582 ksys_write+0xcf/0x120 fs/read_write.c:637 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x34/0x80 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x4194e1
Since the type of Node's flags is unsigned long, we should define these macros with same type too.
--- fs/binfmt_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/binfmt_misc.c +4 -4
@@ -42,10 +42,10 @@ static LIST_HEAD(entries);static int enabled =1 ;enum {Enabled, Magic}; -#define MISC_FMT_PRESERVE_ARGV0 (1 << 31) -#define MISC_FMT_OPEN_BINARY (1 << 30) -#define MISC_FMT_CREDENTIALS (1 << 29) -#define MISC_FMT_OPEN_FILE (1 << 28) +#define MISC_FMT_PRESERVE_ARGV0 (1UL << 31) +#define MISC_FMT_OPEN_BINARY (1UL << 30) +#define MISC_FMT_CREDENTIALS (1UL << 29) +#define MISC_FMT_OPEN_FILE (1UL << 28) typedef struct { struct list_head list;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 311/521 fs: jfs: fix shift-out-of-bounds in dbAllocAG
In reply to Greg Kroah-HartmanFrom: Dongliang Mu <[email protected]>
[ Upstream commit 898f706695682b9954f280d95e49fa86ffa55d08 ]
Syzbot found a crash : UBSAN: shift-out-of-bounds in dbAllocAG. The underlying bug is the missing check of bmp->db_agl2size. The field can be greater than 64 and trigger the shift-out-of-bounds.
Fix this bug by adding a check of bmp->db_agl2size in dbMount since this field is used in many following functions. The upper bound for this field is L2MAXL2SIZE - L2MAXAG, thanks for the help of Dave Kleikamp. Note that, for maintenance, I reorganized error handling code of dbMount.
--- fs/jfs/jfs_dmap.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
fs/jfs/jfs_dmap.c +16 -6
@@ -168,7 +168,7 @@ int dbMount(struct inode *ipbmap)struct bmap *bmp;struct dbmap_disk *dbmp_le;struct metapage *mp; -int i; +int i, err;/* * allocate/initialize the in-memory bmap descriptor
@@ -183,8 +183,8 @@ int dbMount(struct inode *ipbmap)BMAPBLKNO <<JFS_SBI (ipbmap->i_sb)->l2nbperpage, PSIZE, 0);if (mp ==NULL ) { -kfree (bmp); -return -EIO ; + err = -EIO ; + goto err_kfree_bmp; }/* copy the on-disk bmap descriptor to its in-memory version. */
@@ -194,9 +194,8 @@ int dbMount(struct inode *ipbmap) bmp->db_l2nbperpage =le32_to_cpu (dbmp_le->dn_l2nbperpage); bmp->db_numag =le32_to_cpu (dbmp_le->dn_numag);if (!bmp->db_numag) { -release_metapage (mp); -kfree (bmp); -return -EINVAL ; + err = -EINVAL ; + goto err_release_metapage; } bmp->db_maxlevel =le32_to_cpu (dbmp_le->dn_maxlevel);
@@ -207,6 +206,11 @@ int dbMount(struct inode *ipbmap) bmp->db_agwidth =le32_to_cpu (dbmp_le->dn_agwidth); bmp->db_agstart =le32_to_cpu (dbmp_le->dn_agstart); bmp->db_agl2size =le32_to_cpu (dbmp_le->dn_agl2size); +if (bmp->db_agl2size >L2MAXL2SIZE -L2MAXAG ) { + err = -EINVAL ; + goto err_release_metapage; + } +for (i =0 ; i <MAXAG ; i++) bmp->db_agfree[i] =le64_to_cpu (dbmp_le->dn_agfree[i]); bmp->db_agsize =le64_to_cpu (dbmp_le->dn_agsize);
@@ -227,6 +231,12 @@ int dbMount(struct inode *ipbmap)BMAP_LOCK_INIT (bmp);return (0 ); + +err_release_metapage: +release_metapage (mp); +err_kfree_bmp: +kfree (bmp); +return err; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 312/521 udf: Avoid double brelse() in udf_rename()
In reply to Greg Kroah-HartmanFrom: Shigeru Yoshida <[email protected]>
[ Upstream commit c791730f2554a9ebb8f18df9368dc27d4ebc38c2 ]
syzbot reported a warning like below [1]:
VFS: brelse: Trying to free free buffer
WARNING: CPU: 2 PID: 7301 at fs/buffer.c:1145 __brelse+0x67/0xa0 ... Call Trace: <TASK> invalidate_bh_lru+0x99/0x150 smp_call_function_many_cond+0xe2a/0x10c0 ? generic_remap_file_range_prep+0x50/0x50 ? __brelse+0xa0/0xa0 ? __mutex_lock+0x21c/0x12d0 ? smp_call_on_cpu+0x250/0x250 ? rcu_read_lock_sched_held+0xb/0x60 ? lock_release+0x587/0x810 ? __brelse+0xa0/0xa0 ? generic_remap_file_range_prep+0x50/0x50 on_each_cpu_cond_mask+0x3c/0x80 blkdev_flush_mapping+0x13a/0x2f0 blkdev_put_whole+0xd3/0xf0 blkdev_put+0x222/0x760 deactivate_locked_super+0x96/0x160 deactivate_super+0xda/0x100 cleanup_mnt+0x222/0x3d0 task_work_run+0x149/0x240 ? task_work_cancel+0x30/0x30 do_exit+0xb29/0x2a40 ? reacquire_held_locks+0x4a0/0x4a0 ? do_raw_spin_lock+0x12a/0x2b0 ? mm_update_next_owner+0x7c0/0x7c0 ? rwlock_bug.part.0+0x90/0x90 ? zap_other_threads+0x234/0x2d0 do_group_exit+0xd0/0x2a0 __x64_sys_exit_group+0x3a/0x50 do_syscall_64+0x34/0xb0 entry_SYSCALL_64_after_hwframe+0x63/0xcd
The cause of the issue is that brelse() is called on both ofibh.sbh and ofibh.ebh by udf_find_entry() when it returns NULL. However, brelse() is called by udf_rename(), too. So, b_count on buffer_head becomes unbalanced.
This patch fixes the issue by not calling brelse() by udf_rename() when udf_find_entry() returns NULL.
--- fs/udf/namei.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/udf/namei.c +4 -4
@@ -1106,8 +1106,9 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,return -EINVAL ; ofi =udf_find_entry (old_dir, &old_dentry->d_name, &ofibh, &ocfi); -if (IS_ERR (ofi)) { - retval =PTR_ERR (ofi); +if (!ofi ||IS_ERR (ofi)) { +if (IS_ERR (ofi)) + retval =PTR_ERR (ofi); goto end_rename; }
@@ -1116,8 +1117,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,brelse (ofibh.sbh); tloc =lelb_to_cpu (ocfi.icb.extLocation); -if (!ofi ||udf_get_lb_pblock (old_dir->i_sb, &tloc,0 ) - != old_inode->i_ino) +if (udf_get_lb_pblock (old_dir->i_sb, &tloc,0 ) != old_inode->i_ino) goto end_rename; nfi =udf_find_entry (new_dir, &new_dentry->d_name, &nfibh, &ncfi);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 313/521 fs: jfs: fix shift-out-of-bounds in dbDiscardAG
In reply to Greg Kroah-HartmanFrom: Hoi Pok Wu <[email protected]>
[ Upstream commit 25e70c6162f207828dd405b432d8f2a98dbf7082 ]
This should be applied to most URSAN bugs found recently by syzbot, by guarding the dbMount. As syzbot feeding rubbish into the bmap descriptor.
--- fs/jfs/jfs_dmap.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/jfs/jfs_dmap.c +5 -0
@@ -211,6 +211,11 @@ int dbMount(struct inode *ipbmap) goto err_release_metapage; } +if (((bmp->db_mapsize -1 ) >> bmp->db_agl2size) >MAXAG ) { + err = -EINVAL ; + goto err_release_metapage; + } +for (i =0 ; i <MAXAG ; i++) bmp->db_agfree[i] =le64_to_cpu (dbmp_le->dn_agfree[i]); bmp->db_agsize =le64_to_cpu (dbmp_le->dn_agsize);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 314/521 ACPICA: Fix error code path in acpi_ds_call_control_method()
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 404ec60438add1afadaffaed34bb5fe4ddcadd40 ]
A use-after-free in acpi_ps_parse_aml() after a failing invocaion of acpi_ds_call_control_method() is reported by KASAN [1] and code inspection reveals that next_walk_state pushed to the thread by acpi_ds_create_walk_state() is freed on errors, but it is not popped from the thread beforehand. Thus acpi_ds_get_current_walk_state() called by acpi_ps_parse_aml() subsequently returns it as the new walk state which is incorrect.
To address this, make acpi_ds_call_control_method() call acpi_ds_pop_walk_state() to pop next_walk_state from the thread before returning an error.
--- drivers/acpi/acpica/dsmethod.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/acpi/acpica/dsmethod.c +8 -2
@@ -517,7 +517,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread, info =ACPI_ALLOCATE_ZEROED (sizeof (struct acpi_evaluate_info ));if (!info) { status =AE_NO_MEMORY ; - goto cleanup; + goto pop_walk_state; } info->parameters = &this_walk_state->operands[0 ];
@@ -529,7 +529,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,ACPI_FREE (info);if (ACPI_FAILURE (status)) { - goto cleanup; + goto pop_walk_state; }/*
@@ -561,6 +561,12 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,return_ACPI_STATUS (status); +pop_walk_state: + +/* On error, pop the walk state to be deleted from thread */ + +acpi_ds_pop_walk_state (thread); + cleanup:/* On error, we must terminate the method properly */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 315/521 nilfs2: fix shift-out-of-bounds/overflow in nilfs_sb2_bad_offset()
In reply to Greg Kroah-HartmanFrom: Ryusuke Konishi <[email protected]>
[ Upstream commit 610a2a3d7d8be3537458a378ec69396a76c385b6 ]
Patch series "nilfs2: fix UBSAN shift-out-of-bounds warnings on mount time".
The first patch fixes a bug reported by syzbot, and the second one fixes the remaining bug of the same kind. Although they are triggered by the same super block data anomaly, I divided it into the above two because the details of the issues and how to fix it are different.
Both are required to eliminate the shift-out-of-bounds issues at mount time.
This patch (of 2):
If the block size exponent information written in an on-disk superblock is corrupted, nilfs_sb2_bad_offset helper function can trigger shift-out-of-bounds warning followed by a kernel panic (if panic_on_warn is set):
shift exponent 38983 is too large for 64-bit type 'unsigned long long'
Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106 ubsan_epilogue lib/ubsan.c:151 [inline] __ubsan_handle_shift_out_of_bounds+0x33d/0x3b0 lib/ubsan.c:322 nilfs_sb2_bad_offset fs/nilfs2/the_nilfs.c:449 [inline] nilfs_load_super_block+0xdf5/0xe00 fs/nilfs2/the_nilfs.c:523 init_nilfs+0xb7/0x7d0 fs/nilfs2/the_nilfs.c:577 nilfs_fill_super+0xb1/0x5d0 fs/nilfs2/super.c:1047 nilfs_mount+0x613/0x9b0 fs/nilfs2/super.c:1317 ...
In addition, since nilfs_sb2_bad_offset() performs multiplication without considering the upper bound, the computation may overflow if the disk layout parameters are not normal.
This fixes these issues by inserting preliminary sanity checks for those parameters and by converting the comparison from one involving multiplication and left bit-shifting to one using division and right bit-shifting.
--- fs/nilfs2/the_nilfs.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
fs/nilfs2/the_nilfs.c +27 -4
@@ -13,6 +13,7 @@#include <linux/blkdev.h> #include <linux/backing-dev.h> #include <linux/random.h> +#include <linux/log2.h> #include <linux/crc32.h> #include "nilfs.h" #include "segment.h"
@@ -448,11 +449,33 @@ static int nilfs_valid_sb(struct nilfs_super_block *sbp)return crc ==le32_to_cpu (sbp->s_sum); } -static int nilfs_sb2_bad_offset (struct nilfs_super_block *sbp,u64 offset) +/** +* nilfs_sb2_bad_offset - check the location of the second superblock +* @sbp: superblock raw data buffer +* @offset: byte offset of second superblock calculated from device size +* +* nilfs_sb2_bad_offset() checks if the position on the second +* superblock is valid or not based on the filesystem parameters +* stored in @sbp. If @offset points to a location within the segment +* area, or if the parameters themselves are not normal, it is +* determined to be invalid. +* +* Return Value: true if invalid, false if valid. +*/ +static bool nilfs_sb2_bad_offset (struct nilfs_super_block *sbp,u64 offset) { -return offset < ((le64_to_cpu (sbp->s_nsegments) * -le32_to_cpu (sbp->s_blocks_per_segment)) << - (le32_to_cpu (sbp->s_log_block_size) +10 )); +unsigned int shift_bits =le32_to_cpu (sbp->s_log_block_size); +u32 blocks_per_segment =le32_to_cpu (sbp->s_blocks_per_segment); +u64 nsegments =le64_to_cpu (sbp->s_nsegments); +u64 index; + +if (blocks_per_segment <NILFS_SEG_MIN_BLOCKS || + shift_bits >ilog2 (NILFS_MAX_BLOCK_SIZE ) -BLOCK_SIZE_BITS ) +return true; + + index = offset >> (shift_bits +BLOCK_SIZE_BITS ); +do_div (index, blocks_per_segment); +return index < nsegments; }static void nilfs_release_super_block (struct the_nilfs *nilfs)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 316/521 acct: fix potential integer overflow in encode_comp_t()
In reply to Greg Kroah-HartmanFrom: Zheng Yejian <[email protected]>
[ Upstream commit c5f31c655bcc01b6da53b836ac951c1556245305 ]
The integer overflow is descripted with following codes:
Quoted 3 lines
317 static
comp_tencode_comp_t(u64 value)
318 {
319 int exp, rnd;
......
Quoted 4 lines
341 exp <<= MANTSIZE; 342 exp += value; 343 return exp;344 }
Currently comp_t is defined as type of '__u16', but the variable 'exp' is type of 'int', so overflow would happen when variable 'exp' in line 343 is greater than 65535.
--- kernel/acct.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/acct.c +2 -0
@@ -331,6 +331,8 @@ static comp_t encode_comp_t(unsigned long value) exp++; } +if (exp > (((comp_t ) ~0U ) >>MANTSIZE )) +return (comp_t ) ~0U ;/* * Clean it up and polish it off. */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 317/521 hfs: fix OOB Read in __hfs_brec_find
In reply to Greg Kroah-HartmanFrom: ZhangPeng <[email protected]>
[ Upstream commit 8d824e69d9f3fa3121b2dda25053bae71e2460d2 ]
Syzbot reported a OOB read bug:
==================================================================
BUG: KASAN: slab-out-of-bounds in hfs_strcmp+0x117/0x190 fs/hfs/string.c:84 Read of size 1 at addr ffff88807eb62c4e by task kworker/u4:1/11 CPU: 1 PID: 11 Comm: kworker/u4:1 Not tainted 6.1.0-rc6-syzkaller-00308-g644e9524388a #0 Workqueue: writeback wb_workfn (flush-7:0) Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106 print_address_description+0x74/0x340 mm/kasan/report.c:284 print_report+0x107/0x1f0 mm/kasan/report.c:395 kasan_report+0xcd/0x100 mm/kasan/report.c:495 hfs_strcmp+0x117/0x190 fs/hfs/string.c:84 __hfs_brec_find+0x213/0x5c0 fs/hfs/bfind.c:75 hfs_brec_find+0x276/0x520 fs/hfs/bfind.c:138 hfs_write_inode+0x34c/0xb40 fs/hfs/inode.c:462 write_inode fs/fs-writeback.c:1440 [inline]
If the input inode of hfs_write_inode() is incorrect:
struct inode
struct hfs_inode_info
struct hfs_cat_key
struct hfs_name
u8 len # len is greater than HFS_NAMELEN(31) which is the
maximum length of an HFS filename
OOB read occurred:hfs_write_inode()
hfs_brec_find()
__hfs_brec_find()
hfs_cat_keycmp()
hfs_strcmp() # OOB read occurred due to len is too large
Fix this by adding a Check on len in hfs_write_inode() before calling hfs_brec_find().
--- fs/hfs/inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/hfs/inode.c +2 -0
@@ -453,6 +453,8 @@ int hfs_write_inode(struct inode *inode, struct writeback_control *wbc)/* panic? */ return -EIO ; +if (HFS_I (main_inode)->cat_key.CName.len >HFS_NAMELEN ) +return -EIO ; fd.search_key->cat =HFS_I (main_inode)->cat_key;if (hfs_brec_find (&fd))/* panic? */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 318/521 wifi: ath9k: verify the expected usb_endpoints are present
In reply to Greg Kroah-HartmanFrom: Fedor Pchelkin <[email protected]>
[ Upstream commit 16ef02bad239f11f322df8425d302be62f0443ce ]
The bug arises when a USB device claims to be an ATH9K but doesn't have the expected endpoints. (In this case there was an interrupt endpoint where the driver expected a bulk endpoint.) The kernel needs to be able to handle such devices without getting an internal error.
usb 1-1: BOGUS urb xfer, pipe 3 != type 1
WARNING: CPU: 3 PID: 500 at drivers/usb/core/urb.c:493 usb_submit_urb+0xce2/0x1430 drivers/usb/core/urb.c:493 Modules linked in: CPU: 3 PID: 500 Comm: kworker/3:2 Not tainted 5.10.135-syzkaller #0 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 Workqueue: events request_firmware_work_func RIP: 0010:usb_submit_urb+0xce2/0x1430 drivers/usb/core/urb.c:493 Call Trace: ath9k_hif_usb_alloc_rx_urbs drivers/net/wireless/ath/ath9k/hif_usb.c:908 [inline] ath9k_hif_usb_alloc_urbs+0x75e/0x1010 drivers/net/wireless/ath/ath9k/hif_usb.c:1019 ath9k_hif_usb_dev_init drivers/net/wireless/ath/ath9k/hif_usb.c:1109 [inline] ath9k_hif_usb_firmware_cb+0x142/0x530 drivers/net/wireless/ath/ath9k/hif_usb.c:1242 request_firmware_work_func+0x12e/0x240 drivers/base/firmware_loader/main.c:1097 process_one_work+0x9af/0x1600 kernel/workqueue.c:2279 worker_thread+0x61d/0x12f0 kernel/workqueue.c:2425 kthread+0x3b4/0x4a0 kernel/kthread.c:313 ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:299
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- drivers/net/wireless/ath/ath9k/hif_usb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/wireless/ath/ath9k/hif_usb.c +14 -0
@@ -1328,10 +1328,24 @@ static int send_eject_command(struct usb_interface *interface)static int ath9k_hif_usb_probe (struct usb_interface *interface,const struct usb_device_id *id) { +struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in, *int_out;struct usb_device *udev =interface_to_usbdev (interface); +struct usb_host_interface *alt;struct hif_device_usb *hif_dev;int ret =0 ; +/* Verify the expected endpoints are present */ + alt = interface->cur_altsetting; +if (usb_find_common_endpoints (alt, &bulk_in, &bulk_out, &int_in, &int_out) <0 || +usb_endpoint_num (bulk_in) !=USB_WLAN_RX_PIPE || +usb_endpoint_num (bulk_out) !=USB_WLAN_TX_PIPE || +usb_endpoint_num (int_in) !=USB_REG_IN_PIPE || +usb_endpoint_num (int_out) !=USB_REG_OUT_PIPE ) { +dev_err (&udev->dev, +"ath9k_htc: Device endpoint numbers are not the expected ones\n" ); +return -ENODEV ; + } +if (id->driver_info ==STORAGE_DEVICE )return send_eject_command (interface);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 319/521 wifi: ar5523: Fix use-after-free on ar5523_cmd() timed out
In reply to Greg Kroah-HartmanFrom: Shigeru Yoshida <[email protected]>
[ Upstream commit b6702a942a069c2a975478d719e98d83cdae1797 ]
syzkaller reported use-after-free with the stack trace like below [1]:
[ 38.960489][ C3] ================================================================== [ 38.963216][ C3] BUG: KASAN: use-after-free in ar5523_cmd_tx_cb+0x220/0x240 [ 38.964950][ C3] Read of size 8 at addr ffff888048e03450 by task swapper/3/0 [ 38.966363][ C3] [ 38.967053][ C3] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 6.0.0-09039-ga6afa4199d3d-dirty #18 [ 38.968464][ C3] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.0-1.fc36 04/01/2014 [ 38.969959][ C3] Call Trace: [ 38.970841][ C3] <IRQ> [ 38.971663][ C3] dump_stack_lvl+0xfc/0x174 [ 38.972620][ C3] print_report.cold+0x2c3/0x752 [ 38.973626][ C3] ? ar5523_cmd_tx_cb+0x220/0x240 [ 38.974644][ C3] kasan_report+0xb1/0x1d0 [ 38.975720][ C3] ? ar5523_cmd_tx_cb+0x220/0x240 [ 38.976831][ C3] ar5523_cmd_tx_cb+0x220/0x240 [ 38.978412][ C3] __usb_hcd_giveback_urb+0x353/0x5b0 [ 38.979755][ C3] usb_hcd_giveback_urb+0x385/0x430 [ 38.981266][ C3] dummy_timer+0x140c/0x34e0 [ 38.982925][ C3] ? notifier_call_chain+0xb5/0x1e0 [ 38.984761][ C3] ? rcu_read_lock_sched_held+0xb/0x60 [ 38.986242][ C3] ? lock_release+0x51c/0x790 [ 38.987323][ C3] ? _raw_read_unlock_irqrestore+0x37/0x70 [ 38.988483][ C3] ? __wake_up_common_lock+0xde/0x130 [ 38.989621][ C3] ? reacquire_held_locks+0x4a0/0x4a0 [ 38.990777][ C3] ? lock_acquire+0x472/0x550 [ 38.991919][ C3] ? rcu_read_lock_sched_held+0xb/0x60 [ 38.993138][ C3] ? lock_acquire+0x472/0x550 [ 38.994890][ C3] ? dummy_urb_enqueue+0x860/0x860 [ 38.996266][ C3] ? do_raw_spin_unlock+0x16f/0x230 [ 38.997670][ C3] ? dummy_urb_enqueue+0x860/0x860 [ 38.999116][ C3] call_timer_fn+0x1a0/0x6a0 [ 39.000668][ C3] ? add_timer_on+0x4a0/0x4a0 [ 39.002137][ C3] ? reacquire_held_locks+0x4a0/0x4a0 [ 39.003809][ C3] ? __next_timer_interrupt+0x226/0x2a0 [ 39.005509][ C3] __run_timers.part.0+0x69a/0xac0 [ 39.007025][ C3] ? dummy_urb_enqueue+0x860/0x860 [ 39.008716][ C3] ? call_timer_fn+0x6a0/0x6a0 [ 39.010254][ C3] ? cpuacct_percpu_seq_show+0x10/0x10 [ 39.011795][ C3] ? kvm_sched_clock_read+0x14/0x40 [ 39.013277][ C3] ? sched_clock_cpu+0x69/0x2b0 [ 39.014724][ C3] run_timer_softirq+0xb6/0x1d0 [ 39.016196][ C3] __do_softirq+0x1d2/0x9be [ 39.017616][ C3] __irq_exit_rcu+0xeb/0x190 [ 39.019004][ C3] irq_exit_rcu+0x5/0x20 [ 39.020361][ C3] sysvec_apic_timer_interrupt+0x8f/0xb0 [ 39.021965][ C3] </IRQ> [ 39.023237][ C3] <TASK>
In ar5523_probe(), ar5523_host_available() calls ar5523_cmd() as below (there are other functions which finally call ar5523_cmd()):
ar5523_probe()
-> ar5523_host_available()
-> ar5523_cmd_read()
-> ar5523_cmd()
If ar5523_cmd() timed out, then ar5523_host_available() failed and ar5523_probe() freed the device structure. So, ar5523_cmd_tx_cb() might touch the freed structure.
This patch fixes this issue by canceling in-flight tx cmd if submitted urb timed out.
--- drivers/net/wireless/ath/ar5523/ar5523.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/ath/ar5523/ar5523.c +6 -0
@@ -241,6 +241,11 @@ static void ar5523_cmd_tx_cb(struct urb *urb) } } +static void ar5523_cancel_tx_cmd (struct ar5523 *ar) +{ +usb_kill_urb (ar->tx_cmd.urb_tx); +} +static int ar5523_cmd (struct ar5523 *ar,u32 code,const void *idata,int ilen,void *odata,int olen,int flags) {
@@ -280,6 +285,7 @@ static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata, }if (!wait_for_completion_timeout (&cmd->done,2 *HZ )) { +ar5523_cancel_tx_cmd (ar); cmd->odata =NULL ;ar5523_err (ar,"timeout waiting for command %02x reply\n" , code);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 320/521 ASoC: codecs: rt298: Add quirk for KBL-R RVP platform
In reply to Greg Kroah-HartmanFrom: Amadeusz Sławiński <[email protected]>
[ Upstream commit 953dbd1cef18ce9ac0d69c1bd735b929fe52a17e ]
KBL-R RVP platforms also use combojack, so we need to enable that configuration for them.
--- sound/soc/codecs/rt298.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/soc/codecs/rt298.c +7 -0
@@ -1169,6 +1169,13 @@ static const struct dmi_system_id force_combo_jack_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Geminilake") } }, + { + .ident = "Intel Kabylake R RVP", + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Intel Corporation" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Kabylake Client platform") + } + }, { } };
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 321/521 ipmi: fix memleak when unload ipmi driver
In reply to Greg Kroah-HartmanFrom: Zhang Yuchen <[email protected]>
[ Upstream commit 36992eb6b9b83f7f9cdc8e74fb5799d7b52e83e9 ]
After the IPMI disconnect problem, the memory kept rising and we tried to unload the driver to free the memory. However, only part of the free memory is recovered after the driver is uninstalled. Using ebpf to hook free functions, we find that neither ipmi_user nor ipmi_smi_msg is free, only ipmi_recv_msg is free.
We find that the deliver_smi_err_response call in clean_smi_msgs does the destroy processing on each message from the xmit_msg queue without checking the return value and free ipmi_smi_msg.
deliver_smi_err_response is called only at this location. Adding the free handling has no effect.
To verify, try using ebpf to trace the free function.
$ bpftrace -e 'kretprobe:ipmi_alloc_recv_msg {printf("alloc rcv
%p\n",retval);} kprobe:free_recv_msg {printf("free recv %p\n",
arg0)} kretprobe:ipmi_alloc_smi_msg {printf("alloc smi %p\n",
retval);} kprobe:free_smi_msg {printf("free smi %p\n",arg0)}'Message-Id: <[email protected]>
--- drivers/char/ipmi/ipmi_msghandler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/char/ipmi/ipmi_msghandler.c +6 -2
@@ -3461,12 +3461,16 @@ static void deliver_smi_err_response(struct ipmi_smi *intf,struct ipmi_smi_msg *msg, unsigned char err) { + int rv; msg->rsp[0 ] = msg->data[0 ] |4 ; msg->rsp[1 ] = msg->data[1 ]; msg->rsp[2 ] = err; msg->rsp_size =3 ; -/* It's an error, so it will never requeue, no need to check return. */ -handle_one_recv_msg (intf, msg); + +/* This will never requeue, but it may ask us to free the message. */ + rv =handle_one_recv_msg (intf, msg); +if (rv ==0 ) +ipmi_free_smi_msg (msg); }static void cleanup_smi_msgs (struct ipmi_smi *intf)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 322/521 bpf: make sure skb->len != 0 when redirecting to a tunneling device
In reply to Greg Kroah-HartmanFrom: Stanislav Fomichev <[email protected]>
[ Upstream commit 07ec7b502800ba9f7b8b15cb01dd6556bb41aaca ]
syzkaller managed to trigger another case where skb->len == 0 when we enter __dev_queue_xmit:
WARNING: CPU: 0 PID: 2470 at include/linux/skbuff.h:2576 skb_assert_len include/linux/skbuff.h:2576 [inline] WARNING: CPU: 0 PID: 2470 at include/linux/skbuff.h:2576 __dev_queue_xmit+0x2069/0x35e0 net/core/dev.c:4295 Call Trace: dev_queue_xmit+0x17/0x20 net/core/dev.c:4406 __bpf_tx_skb net/core/filter.c:2115 [inline] __bpf_redirect_no_mac net/core/filter.c:2140 [inline] __bpf_redirect+0x5fb/0xda0 net/core/filter.c:2163 ____bpf_clone_redirect net/core/filter.c:2447 [inline] bpf_clone_redirect+0x247/0x390 net/core/filter.c:2419 bpf_prog_48159a89cb4a9a16+0x59/0x5e bpf_dispatcher_nop_func include/linux/bpf.h:897 [inline] __bpf_prog_run include/linux/filter.h:596 [inline] bpf_prog_run include/linux/filter.h:603 [inline] bpf_test_run+0x46c/0x890 net/bpf/test_run.c:402 bpf_prog_test_run_skb+0xbdc/0x14c0 net/bpf/test_run.c:1170 bpf_prog_test_run+0x345/0x3c0 kernel/bpf/syscall.c:3648 __sys_bpf+0x43a/0x6c0 kernel/bpf/syscall.c:5005 __do_sys_bpf kernel/bpf/syscall.c:5091 [inline] __se_sys_bpf kernel/bpf/syscall.c:5089 [inline] __x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:5089 do_syscall_64+0x54/0x70 arch/x86/entry/common.c:48 entry_SYSCALL_64_after_hwframe+0x61/0xc6
The reproducer doesn't really reproduce outside of syzkaller environment, so I'm taking a guess here. It looks like we do generate correct ETH_HLEN-sized packet, but we redirect the packet to the tunneling device. Before we do so, we __skb_pull l2 header and arrive again at skb->len == 0. Doesn't seem like we can do anything better than having an explicit check after __skb_pull?
--- net/core/filter.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/filter.c +4 -0
@@ -2025,6 +2025,10 @@ static int __bpf_redirect_no_mac(struct sk_buff *skb, struct net_device *dev,if (mlen) {__skb_pull (skb, mlen); +if (unlikely (!skb->len)) { +kfree_skb (skb); +return -ERANGE ; + }/* At ingress, the mac header has already been pulled once. * At egress, skb_pospull_rcsum has to be done in case that
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 323/521 net: ethernet: ti: Fix return type of netcp_ndo_start_xmit()
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit 63fe6ff674a96cfcfc0fa8df1051a27aa31c70b4 ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/net/ethernet/ti/netcp_core.c:1944:21: error: incompatible function pointer types initializing 'netdev_tx_t (*)(struct sk_buff *, struct net_device *)' (aka 'enum netdev_tx (*)(struct sk_buff *, struct net_device *)') with an expression of type 'int (struct sk_buff *, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.ndo_start_xmit = netcp_ndo_start_xmit,
^~~~~~~~~~~~~~~~~~~~
1 error generated.
->ndo_start_xmit() in 'struct net_device_ops' expects a return type of 'netdev_tx_t', not 'int'. Adjust the return type of netcp_ndo_start_xmit() to match the prototype's to resolve the warning and CFI failure.
--- drivers/net/ethernet/ti/netcp_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ti/netcp_core.c +1 -1
@@ -1276,7 +1276,7 @@ static int netcp_tx_submit_skb(struct netcp_intf *netcp, }/* Submit the packet */ -static int netcp_ndo_start_xmit (struct sk_buff *skb,struct net_device *ndev) +static netdev_tx_t netcp_ndo_start_xmit (struct sk_buff *skb,struct net_device *ndev) {struct netcp_intf *netcp =netdev_priv (ndev);struct netcp_stats *tx_stats = &netcp->stats;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 324/521 hamradio: baycom_epp: Fix return type of baycom_send_packet()
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit c5733e5b15d91ab679646ec3149e192996a27d5d ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/net/hamradio/baycom_epp.c:1119:25: error: incompatible function pointer types initializing 'netdev_tx_t (*)(struct sk_buff *, struct net_device *)' (aka 'enum netdev_tx (*)(struct sk_buff *, struct net_device *)') with an expression of type 'int (struct sk_buff *, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.ndo_start_xmit = baycom_send_packet,
^~~~~~~~~~~~~~~~~~
1 error generated.
->ndo_start_xmit() in 'struct net_device_ops' expects a return type of 'netdev_tx_t', not 'int'. Adjust the return type of baycom_send_packet() to match the prototype's to resolve the warning and CFI failure.
--- drivers/net/hamradio/baycom_epp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/hamradio/baycom_epp.c +1 -1
@@ -772,7 +772,7 @@ static void epp_bh(struct work_struct *work)* ===================== network driver interface ========================= */ -static int baycom_send_packet (struct sk_buff *skb,struct net_device *dev) +static netdev_tx_t baycom_send_packet (struct sk_buff *skb,struct net_device *dev) {struct baycom_state *bc =netdev_priv (dev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 325/521 wifi: brcmfmac: Fix potential shift-out-of-bounds in brcmf_fw_alloc_request()
In reply to Greg Kroah-HartmanFrom: Minsuk Kang <[email protected]>
[ Upstream commit 81d17f6f3331f03c8eafdacea68ab773426c1e3c ]
This patch fixes a shift-out-of-bounds in brcmfmac that occurs in BIT(chiprev) when a 'chiprev' provided by the device is too large. It should also not be equal to or greater than BITS_PER_TYPE(u32) as we do bitwise AND with a u32 variable and BIT(chiprev). The patch adds a check that makes the function return NULL if that is the case. Note that the NULL case is later handled by the bus-specific caller, brcmf_usb_probe_cb() or brcmf_usb_reset_resume(), for example.
Found by a modified version of syzkaller.
UBSAN: shift-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c shift exponent 151055786 is too large for 64-bit type 'long unsigned int' CPU: 0 PID: 1885 Comm: kworker/0:2 Tainted: G O 5.14.0+ #132 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014 Workqueue: usb_hub_wq hub_event Call Trace: dump_stack_lvl+0x57/0x7d ubsan_epilogue+0x5/0x40 __ubsan_handle_shift_out_of_bounds.cold+0x53/0xdb ? lock_chain_count+0x20/0x20 brcmf_fw_alloc_request.cold+0x19/0x3ea ? brcmf_fw_get_firmwares+0x250/0x250 ? brcmf_usb_ioctl_resp_wait+0x1a7/0x1f0 brcmf_usb_get_fwname+0x114/0x1a0 ? brcmf_usb_reset_resume+0x120/0x120 ? number+0x6c4/0x9a0 brcmf_c_process_clm_blob+0x168/0x590 ? put_dec+0x90/0x90 ? enable_ptr_key_workfn+0x20/0x20 ? brcmf_common_pd_remove+0x50/0x50 ? rcu_read_lock_sched_held+0xa1/0xd0 brcmf_c_preinit_dcmds+0x673/0xc40 ? brcmf_c_set_joinpref_default+0x100/0x100 ? rcu_read_lock_sched_held+0xa1/0xd0 ? rcu_read_lock_bh_held+0xb0/0xb0 ? lock_acquire+0x19d/0x4e0 ? find_held_lock+0x2d/0x110 ? brcmf_usb_deq+0x1cc/0x260 ? mark_held_locks+0x9f/0xe0 ? lockdep_hardirqs_on_prepare+0x273/0x3e0 ? _raw_spin_unlock_irqrestore+0x47/0x50 ? trace_hardirqs_on+0x1c/0x120 ? brcmf_usb_deq+0x1a7/0x260 ? brcmf_usb_rx_fill_all+0x5a/0xf0 brcmf_attach+0x246/0xd40 ? wiphy_new_nm+0x1476/0x1d50 ? kmemdup+0x30/0x40 brcmf_usb_probe+0x12de/0x1690 ? brcmf_usbdev_qinit.constprop.0+0x470/0x470 usb_probe_interface+0x25f/0x710 really_probe+0x1be/0xa90 __driver_probe_device+0x2ab/0x460 ? usb_match_id.part.0+0x88/0xc0 driver_probe_device+0x49/0x120 __device_attach_driver+0x18a/0x250 ? driver_allows_async_probing+0x120/0x120 bus_for_each_drv+0x123/0x1a0 ? bus_rescan_devices+0x20/0x20 ? lockdep_hardirqs_on_prepare+0x273/0x3e0 ? trace_hardirqs_on+0x1c/0x120 __device_attach+0x207/0x330 ? device_bind_driver+0xb0/0xb0 ? kobject_uevent_env+0x230/0x12c0 bus_probe_device+0x1a2/0x260 device_add+0xa61/0x1ce0 ? __mutex_unlock_slowpath+0xe7/0x660 ? __fw_devlink_link_to_suppliers+0x550/0x550 usb_set_configuration+0x984/0x1770 ? kernfs_create_link+0x175/0x230 usb_generic_driver_probe+0x69/0x90 usb_probe_device+0x9c/0x220 really_probe+0x1be/0xa90 __driver_probe_device+0x2ab/0x460 driver_probe_device+0x49/0x120 __device_attach_driver+0x18a/0x250 ? driver_allows_async_probing+0x120/0x120 bus_for_each_drv+0x123/0x1a0 ? bus_rescan_devices+0x20/0x20 ? lockdep_hardirqs_on_prepare+0x273/0x3e0 ? trace_hardirqs_on+0x1c/0x120 __device_attach+0x207/0x330 ? device_bind_driver+0xb0/0xb0 ? kobject_uevent_env+0x230/0x12c0 bus_probe_device+0x1a2/0x260 device_add+0xa61/0x1ce0 ? __fw_devlink_link_to_suppliers+0x550/0x550 usb_new_device.cold+0x463/0xf66 ? hub_disconnect+0x400/0x400 ? _raw_spin_unlock_irq+0x24/0x30 hub_event+0x10d5/0x3330 ? hub_port_debounce+0x280/0x280 ? __lock_acquire+0x1671/0x5790 ? wq_calc_node_cpumask+0x170/0x2a0 ? lock_release+0x640/0x640 ? rcu_read_lock_sched_held+0xa1/0xd0 ? rcu_read_lock_bh_held+0xb0/0xb0 ? lockdep_hardirqs_on_prepare+0x273/0x3e0 process_one_work+0x873/0x13e0 ? lock_release+0x640/0x640 ? pwq_dec_nr_in_flight+0x320/0x320 ? rwlock_bug.part.0+0x90/0x90 worker_thread+0x8b/0xd10 ? __kthread_parkme+0xd9/0x1d0 ? process_one_work+0x13e0/0x13e0 kthread+0x379/0x450 ? _raw_spin_unlock_irq+0x24/0x30 ? set_kthread_struct+0x100/0x100 ret_from_fork+0x1f/0x30
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c +5 -0
@@ -648,6 +648,11 @@ brcmf_fw_alloc_request(u32 chip, u32 chiprev,char end ='\0' ;size_t reqsz; +if (chiprev >=BITS_PER_TYPE (u32)) { +brcmf_err ("Invalid chip revision %u\n" , chiprev); +return NULL ; + } +for (i =0 ; i < table_size; i++) {if (mapping_table[i].chipid == chip && mapping_table[i].revmask &BIT (chiprev))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 326/521 igb: Do not free q_vector unless new one was allocated
In reply to Greg Kroah-HartmanFrom: Kees Cook <[email protected]>
[ Upstream commit 0668716506ca66f90d395f36ccdaebc3e0e84801 ]
Avoid potential use-after-free condition under memory pressure. If the kzalloc() fails, q_vector will be freed but left in the original adapter->q_vector[v_idx] array position.
--- drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +6 -2
@@ -1211,8 +1211,12 @@ static int igb_alloc_q_vector(struct igb_adapter *adapter,if (!q_vector) { q_vector =kzalloc (size,GFP_KERNEL ); }else if (size >ksize (q_vector)) { -kfree_rcu (q_vector, rcu); - q_vector =kzalloc (size,GFP_KERNEL ); +struct igb_q_vector *new_q_vector; + + new_q_vector =kzalloc (size,GFP_KERNEL ); +if (new_q_vector) +kfree_rcu (q_vector, rcu); + q_vector = new_q_vector; }else {memset (q_vector,0 , size); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 327/521 drm/amdgpu: Fix type of second parameter in trans_msg() callback
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit f0d0f1087333714ee683cc134a95afe331d7ddd9 ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c:412:15: error: incompatible function pointer types initializing 'void (*)(struct amdgpu_device *, u32, u32, u32, u32)' (aka 'void (*)(struct amdgpu_device *, unsigned int, unsigned int, unsigned int, unsigned int)') with an expression of type 'void (struct amdgpu_device *, enum idh_request, u32, u32, u32)' (aka 'void (struct amdgpu_device *, enum idh_request, unsigned int, unsigned int, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
.trans_msg = xgpu_ai_mailbox_trans_msg,
^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c:435:15: error: incompatible function pointer types initializing 'void (*)(struct amdgpu_device *, u32, u32, u32, u32)' (aka 'void (*)(struct amdgpu_device *, unsigned int, unsigned int, unsigned int, unsigned int)') with an expression of type 'void (struct amdgpu_device *, enum idh_request, u32, u32, u32)' (aka 'void (struct amdgpu_device *, enum idh_request, unsigned int, unsigned int, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
.trans_msg = xgpu_nv_mailbox_trans_msg,
^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
The type of the second parameter in the prototype should be 'enum idh_request' instead of 'u32'. Update it to clear up the warnings.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +4 -1
@@ -48,6 +48,8 @@ struct amdgpu_vf_error_buffer {uint64_t data[AMDGPU_VF_ERROR_ENTRY_SIZE ]; }; +enum idh_request ; +/** * struct amdgpu_virt_ops - amdgpu device virt operations */
@@ -56,7 +58,8 @@ struct amdgpu_virt_ops {int (*rel_full_gpu)(struct amdgpu_device *adev,bool init);int (*reset_gpu)(struct amdgpu_device *adev);int (*wait_reset)(struct amdgpu_device *adev); -void (*trans_msg)(struct amdgpu_device *adev,u32 req,u32 data1,u32 data2,u32 data3); +void (*trans_msg)(struct amdgpu_device *adev,enum idh_request req, +u32 data1,u32 data2,u32 data3); };/*
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 328/521 s390/ctcm: Fix return type of ctc{mp,}m_tx()
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit aa5bf80c3c067b82b4362cd6e8e2194623bcaca6 ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/s390/net/ctcm_main.c:1064:21: error: incompatible function pointer types initializing 'netdev_tx_t (*)(struct sk_buff *, struct net_device *)' (aka 'enum netdev_tx (*)(struct sk_buff *, struct net_device *)') with an expression of type 'int (struct sk_buff *, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.ndo_start_xmit = ctcm_tx,
^~~~~~~
drivers/s390/net/ctcm_main.c:1072:21: error: incompatible function pointer types initializing 'netdev_tx_t (*)(struct sk_buff *, struct net_device *)' (aka 'enum netdev_tx (*)(struct sk_buff *, struct net_device *)') with an expression of type 'int (struct sk_buff *, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.ndo_start_xmit = ctcmpc_tx,
^~~~~~~~~
->ndo_start_xmit() in 'struct net_device_ops' expects a return type of 'netdev_tx_t', not 'int'. Adjust the return type of ctc{mp,}m_tx() to match the prototype's to resolve the warning and potential CFI failure, should s390 select ARCH_SUPPORTS_CFI_CLANG in the future.
Additionally, while in the area, remove a comment block that is no longer relevant.
--- drivers/s390/net/ctcm_main.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/s390/net/ctcm_main.c +2 -9
@@ -867,16 +867,9 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)/** * Start transmission of a packet. * Called from generic network device layer. -* -* skb Pointer to buffer containing the packet. -* dev Pointer to interface struct. -* -* returns 0 if packet consumed, !0 if packet rejected. -* Note: If we return !0, then the packet is free'd by -* the generic network layer. */ /* first merge version - leaving both functions separated */ -static int ctcm_tx (struct sk_buff *skb,struct net_device *dev) +static netdev_tx_t ctcm_tx (struct sk_buff *skb,struct net_device *dev) {struct ctcm_priv *priv = dev->ml_priv;
@@ -919,7 +912,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev) }/* unmerged MPC variant of ctcm_tx */ -static int ctcmpc_tx (struct sk_buff *skb,struct net_device *dev) +static netdev_tx_t ctcmpc_tx (struct sk_buff *skb,struct net_device *dev) {int len =0 ;struct ctcm_priv *priv = dev->ml_priv;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 329/521 s390/netiucv: Fix return type of netiucv_tx()
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit 88d86d18d7cf7e9137c95f9d212bb9fff8a1b4be ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/s390/net/netiucv.c:1854:21: error: incompatible function pointer types initializing 'netdev_tx_t (*)(struct sk_buff *, struct net_device *)' (aka 'enum netdev_tx (*)(struct sk_buff *, struct net_device *)') with an expression of type 'int (struct sk_buff *, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.ndo_start_xmit = netiucv_tx,
^~~~~~~~~~
->ndo_start_xmit() in 'struct net_device_ops' expects a return type of 'netdev_tx_t', not 'int'. Adjust the return type of netiucv_tx() to match the prototype's to resolve the warning and potential CFI failure, should s390 select ARCH_SUPPORTS_CFI_CLANG in the future.
Additionally, while in the area, remove a comment block that is no longer relevant.
--- drivers/s390/net/netiucv.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/s390/net/netiucv.c +1 -8
@@ -1344,15 +1344,8 @@ static int netiucv_pm_restore_thaw(struct device *dev)/** * Start transmission of a packet. * Called from generic network device layer. -* -* @param skb Pointer to buffer containing the packet. -* @param dev Pointer to interface struct. -* -* @return 0 if packet consumed, !0 if packet rejected. -* Note: If we return !0, then the packet is free'd by -* the generic network layer. */ -static int netiucv_tx (struct sk_buff *skb,struct net_device *dev) +static netdev_tx_t netiucv_tx (struct sk_buff *skb,struct net_device *dev) {struct netiucv_priv *privptr =netdev_priv (dev);int rc;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 330/521 s390/lcs: Fix return type of lcs_start_xmit()
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit bb16db8393658e0978c3f0d30ae069e878264fa3 ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/s390/net/lcs.c:2090:21: error: incompatible function pointer types initializing 'netdev_tx_t (*)(struct sk_buff *, struct net_device *)' (aka 'enum netdev_tx (*)(struct sk_buff *, struct net_device *)') with an expression of type 'int (struct sk_buff *, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.ndo_start_xmit = lcs_start_xmit,
^~~~~~~~~~~~~~
drivers/s390/net/lcs.c:2097:21: error: incompatible function pointer types initializing 'netdev_tx_t (*)(struct sk_buff *, struct net_device *)' (aka 'enum netdev_tx (*)(struct sk_buff *, struct net_device *)') with an expression of type 'int (struct sk_buff *, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.ndo_start_xmit = lcs_start_xmit,
^~~~~~~~~~~~~~
->ndo_start_xmit() in 'struct net_device_ops' expects a return type of 'netdev_tx_t', not 'int'. Adjust the return type of lcs_start_xmit() to match the prototype's to resolve the warning and potential CFI failure, should s390 select ARCH_SUPPORTS_CFI_CLANG in the future.
--- drivers/s390/net/lcs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/s390/net/lcs.c +3 -5
@@ -1518,9 +1518,8 @@ lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)/** * Packet transmit function called by network stack */ -static int -__lcs_start_xmit (struct lcs_card *card,struct sk_buff *skb, -struct net_device *dev) +static netdev_tx_t __lcs_start_xmit (struct lcs_card *card,struct sk_buff *skb, +struct net_device *dev) {struct lcs_header *header;int rc =NETDEV_TX_OK ;
@@ -1581,8 +1580,7 @@ __lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb,return rc; } -static int -lcs_start_xmit (struct sk_buff *skb,struct net_device *dev) +static netdev_tx_t lcs_start_xmit (struct sk_buff *skb,struct net_device *dev) {struct lcs_card *card;int rc;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 331/521 drm/sti: Use drm_mode_copy()
In reply to Greg Kroah-HartmanFrom: Ville Syrjälä <[email protected]>
[ Upstream commit 442cf8e22ba25a77cb9092d78733fdbac9844e50 ]
struct drm_display_mode embeds a list head, so overwriting the full struct with another one will corrupt the list (if the destination mode is on a list). Use drm_mode_copy() instead which explicitly preserves the list head of the destination mode.
Even if we know the destination mode is not on any list using drm_mode_copy() seems decent as it sets a good example. Bad examples of not using it might eventually get copied into code where preserving the list head actually matters.
Obviously one case not covered here is when the mode itself is embedded in a larger structure and the whole structure is copied. But if we are careful when copying into modes embedded in structures I think we can be a little more reassured that bogus list heads haven't been propagated in.
@is_mode_copy@
@@drm_mode_copy(...)
{
...
}
@depends on !is_mode_copy@
struct drm_display_mode *mode;
expression E, S;
@@
(
- *mode = E
+ drm_mode_copy(mode, &E)
|
- memcpy(mode, E, S)
+ drm_mode_copy(mode, E)
)
@depends on !is_mode_copy@
struct drm_display_mode mode;
expression E;
@@
(
- mode = E
+ drm_mode_copy(&mode, &E)
|
- memcpy(&mode, E, S)
+ drm_mode_copy(&mode, E)
)
@@
struct drm_display_mode *mode;
@@
- &*mode
+ mode
--- drivers/gpu/drm/sti/sti_dvo.c | 2 +- drivers/gpu/drm/sti/sti_hda.c | 2 +- drivers/gpu/drm/sti/sti_hdmi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/sti/sti_dvo.c +1 -1
@@ -288,7 +288,7 @@ static void sti_dvo_set_mode(struct drm_bridge *bridge,DRM_DEBUG_DRIVER ("\n" ); -memcpy (&dvo->mode, mode,sizeof (struct drm_display_mode )); +drm_mode_copy (&dvo->mode, mode);/* According to the path used (main or aux), the dvo clocks should * have a different parent clock. */
drivers/gpu/drm/sti/sti_hda.c +1 -1
@@ -518,7 +518,7 @@ static void sti_hda_set_mode(struct drm_bridge *bridge,DRM_DEBUG_DRIVER ("\n" ); -memcpy (&hda->mode, mode,sizeof (struct drm_display_mode )); +drm_mode_copy (&hda->mode, mode);if (!hda_get_mode_idx (hda->mode, &mode_idx)) {DRM_ERROR ("Undefined mode\n" );
drivers/gpu/drm/sti/sti_hdmi.c +1 -1
@@ -926,7 +926,7 @@ static void sti_hdmi_set_mode(struct drm_bridge *bridge,DRM_DEBUG_DRIVER ("\n" );/* Copy the drm display mode in the connector local structure */ -memcpy (&hdmi->mode, mode,sizeof (struct drm_display_mode )); +drm_mode_copy (&hdmi->mode, mode);/* Update clock framerate according to the selected mode */ ret =clk_set_rate (hdmi->clk_pix, mode->clock *1000 );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 332/521 drivers/md/md-bitmap: check the return value of md_bitmap_get_counter()
In reply to Greg Kroah-HartmanFrom: Li Zhong <[email protected]>
[ Upstream commit 3bd548e5b819b8c0f2c9085de775c5c7bff9052f ]
Check the return value of md_bitmap_get_counter() in case it returns NULL pointer, which will result in a null pointer dereference.
v2: update the check to include other dereference
--- drivers/md/md-bitmap.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/md/md-bitmap.c +15 -12
@@ -2191,20 +2191,23 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,if (set) { bmc_new =md_bitmap_get_counter (&bitmap->counts, block, &new_blocks,1 ); -if (*bmc_new ==0 ) { -/* need to set on-disk bits too. */ -sector_t end = block + new_blocks; -sector_t start = block >> chunkshift; - start <<= chunkshift; -while (start < end) { -md_bitmap_file_set_bit (bitmap, block); - start +=1 << chunkshift; +if (bmc_new) { +if (*bmc_new ==0 ) { +/* need to set on-disk bits too. */ +sector_t end = block + new_blocks; +sector_t start = block >> chunkshift; + + start <<= chunkshift; +while (start < end) { +md_bitmap_file_set_bit (bitmap, block); + start +=1 << chunkshift; + } + *bmc_new =2 ; +md_bitmap_count_page (&bitmap->counts, block,1 ); +md_bitmap_set_pending (&bitmap->counts, block); } - *bmc_new =2 ; -md_bitmap_count_page (&bitmap->counts, block,1 ); -md_bitmap_set_pending (&bitmap->counts, block); + *bmc_new |=NEEDED_MASK ; } - *bmc_new |=NEEDED_MASK ;if (new_blocks < old_blocks) old_blocks = new_blocks; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 333/521 md/raid1: stop mdx_raid1 thread when raid1 array run failed
In reply to Greg Kroah-HartmanFrom: Jiang Li <[email protected]>
[ Upstream commit b611ad14006e5be2170d9e8e611bf49dff288911 ]
fail run raid1 array when we assemble array with the inactive disk only, but the mdx_raid1 thread were not stop, Even if the associated resources have been released. it will caused a NULL dereference when we do poweroff.
This causes the following Oops:
[ 287.587787] BUG: kernel NULL pointer dereference, address: 0000000000000070
[ 287.594762] #PF: supervisor read access in kernel mode
[ 287.599912] #PF: error_code(0x0000) - not-present page
[ 287.605061] PGD 0 P4D 0
[ 287.607612] Oops: 0000 [#1] SMP NOPTI
[ 287.611287] CPU: 3 PID: 5265 Comm: md0_raid1 Tainted: G U 5.10.146 #0
[ 287.619029] Hardware name: xxxxxxx/To be filled by O.E.M, BIOS 5.19 06/16/2022
[ 287.626775] RIP: 0010:md_check_recovery+0x57/0x500 [md_mod]
[ 287.632357] Code: fe 01 00 00 48 83 bb 10 03 00 00 00 74 08 48 89 ......
[ 287.651118] RSP: 0018:ffffc90000433d78 EFLAGS: 00010202
[ 287.656347] RAX: 0000000000000000 RBX: ffff888105986800 RCX: 0000000000000000
[ 287.663491] RDX: ffffc90000433bb0 RSI: 00000000ffffefff RDI: ffff888105986800
[ 287.670634] RBP: ffffc90000433da0 R08: 0000000000000000 R09: c0000000ffffefff
[ 287.677771] R10: 0000000000000001 R11: ffffc90000433ba8 R12: ffff888105986800
[ 287.684907] R13: 0000000000000000 R14: fffffffffffffe00 R15: ffff888100b6b500
[ 287.692052] FS: 0000000000000000(0000) GS:ffff888277f80000(0000) knlGS:0000000000000000
[ 287.700149] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 287.705897] CR2: 0000000000000070 CR3: 000000000320a000 CR4: 0000000000350ee0
[ 287.713033] Call Trace:
[ 287.715498] raid1d+0x6c/0xbbb [raid1]
[ 287.719256] ? __schedule+0x1ff/0x760
[ 287.722930] ? schedule+0x3b/0xb0
[ 287.726260] ? schedule_timeout+0x1ed/0x290
[ 287.730456] ? __switch_to+0x11f/0x400
[ 287.734219] md_thread+0xe9/0x140 [md_mod]
[ 287.738328] ? md_thread+0xe9/0x140 [md_mod]
[ 287.742601] ? wait_woken+0x80/0x80
[ 287.746097] ? md_register_thread+0xe0/0xe0 [md_mod]
[ 287.751064] kthread+0x11a/0x140
[ 287.754300] ? kthread_park+0x90/0x90
[ 287.757974] ret_from_fork+0x1f/0x30In fact, when raid1 array run fail, we need to domd_unregister_thread() before raid1_free().
--- drivers/md/raid1.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/raid1.c +1 -0
@@ -3110,6 +3110,7 @@ static int raid1_run(struct mddev *mddev)* RAID1 needs at least one disk in active */ if (conf->raid_disks - mddev->degraded <1 ) { +md_unregister_thread (&conf->thread); ret = -EINVAL ; goto abort; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 334/521 mrp: introduce active flags to prevent UAF when applicant uninit
In reply to Greg Kroah-HartmanFrom: Schspa Shi <[email protected]>
[ Upstream commit ab0377803dafc58f1e22296708c1c28e309414d6 ]
The caller of del_timer_sync must prevent restarting of the timer, If we have no this synchronization, there is a small probability that the cancellation will not be successful.
And syzbot report the fellowing crash:
==================================================================
BUG: KASAN: use-after-free in hlist_add_head include/linux/list.h:929 [inline] BUG: KASAN: use-after-free in enqueue_timer+0x18/0xa4 kernel/time/timer.c:605
Write at addr f9ff000024df6058 by task syz-fuzzer/2256 Pointer tag: [f9], memory tag: [fe]
CPU: 1 PID: 2256 Comm: syz-fuzzer Not tainted 6.1.0-rc5-syzkaller-00008- ge01d50cbd6ee #0 Hardware name: linux,dummy-virt (DT) Call trace: dump_backtrace.part.0+0xe0/0xf0 arch/arm64/kernel/stacktrace.c:156 dump_backtrace arch/arm64/kernel/stacktrace.c:162 [inline] show_stack+0x18/0x40 arch/arm64/kernel/stacktrace.c:163 __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x68/0x84 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:284 [inline] print_report+0x1a8/0x4a0 mm/kasan/report.c:395 kasan_report+0x94/0xb4 mm/kasan/report.c:495 __do_kernel_fault+0x164/0x1e0 arch/arm64/mm/fault.c:320 do_bad_area arch/arm64/mm/fault.c:473 [inline] do_tag_check_fault+0x78/0x8c arch/arm64/mm/fault.c:749 do_mem_abort+0x44/0x94 arch/arm64/mm/fault.c:825 el1_abort+0x40/0x60 arch/arm64/kernel/entry-common.c:367 el1h_64_sync_handler+0xd8/0xe4 arch/arm64/kernel/entry-common.c:427 el1h_64_sync+0x64/0x68 arch/arm64/kernel/entry.S:576 hlist_add_head include/linux/list.h:929 [inline] enqueue_timer+0x18/0xa4 kernel/time/timer.c:605 mod_timer+0x14/0x20 kernel/time/timer.c:1161 mrp_periodic_timer_arm net/802/mrp.c:614 [inline] mrp_periodic_timer+0xa0/0xc0 net/802/mrp.c:627 call_timer_fn.constprop.0+0x24/0x80 kernel/time/timer.c:1474 expire_timers+0x98/0xc4 kernel/time/timer.c:1519
To fix it, we can introduce a new active flags to make sure the timer will not restart.
--- include/net/mrp.h | 1 + net/802/mrp.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-)
include/net/mrp.h +1 -0
@@ -120,6 +120,7 @@ struct mrp_applicant {struct sk_buff *pdu;struct rb_root mad;struct rcu_head rcu; +bool active; };struct mrp_port {
net/802/mrp.c +13 -5
@@ -609,7 +609,10 @@ static void mrp_join_timer(struct timer_list *t)spin_unlock (&app->lock);mrp_queue_xmit (app); -mrp_join_timer_arm (app); +spin_lock (&app->lock); +if (likely (app->active)) +mrp_join_timer_arm (app); +spin_unlock (&app->lock); }static void mrp_periodic_timer_arm (struct mrp_applicant *app)
@@ -623,11 +626,12 @@ static void mrp_periodic_timer(struct timer_list *t)struct mrp_applicant *app =from_timer (app, t, periodic_timer);spin_lock (&app->lock); -mrp_mad_event (app,MRP_EVENT_PERIODIC ); -mrp_pdu_queue (app); +if (likely (app->active)) { +mrp_mad_event (app,MRP_EVENT_PERIODIC ); +mrp_pdu_queue (app); +mrp_periodic_timer_arm (app); + }spin_unlock (&app->lock); - -mrp_periodic_timer_arm (app); }static int mrp_pdu_parse_end_mark (struct sk_buff *skb,int *offset)
@@ -875,6 +879,7 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl) app->dev = dev; app->app = appl; app->mad =RB_ROOT ; + app->active = true;spin_lock_init (&app->lock);skb_queue_head_init (&app->queue);rcu_assign_pointer (dev->mrp_port->applicants[appl->type], app);
@@ -903,6 +908,9 @@ void mrp_uninit_applicant(struct net_device *dev, struct mrp_application *appl)RCU_INIT_POINTER (port->applicants[appl->type],NULL ); +spin_lock_bh (&app->lock); + app->active = false; +spin_unlock_bh (&app->lock);/* Delete timer and generate a final TX event to flush out * all pending messages before the applicant is gone. */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 335/521 ppp: associate skb with a device at tx
In reply to Greg Kroah-HartmanFrom: Stanislav Fomichev <[email protected]>
[ Upstream commit 9f225444467b98579cf28d94f4ad053460dfdb84 ]
Syzkaller triggered flow dissector warning with the following:
r0 = openat$ppp(0xffffffffffffff9c, &(0x7f0000000000), 0xc0802, 0x0)
ioctl$PPPIOCNEWUNIT(r0, 0xc004743e, &(0x7f00000000c0))
ioctl$PPPIOCSACTIVE(r0, 0x40107446, &(0x7f0000000240)={0x2, &(0x7f0000000180)=[{0x20, 0x0, 0x0, 0xfffff034}, {0x6}]}) pwritev(r0, &(0x7f0000000040)=[{&(0x7f0000000140)='\x00!', 0x2}], 0x1, 0x0, 0x0)
[ 9.485814] WARNING: CPU: 3 PID: 329 at net/core/flow_dissector.c:1016 __skb_flow_dissect+0x1ee0/0x1fa0 [ 9.485929] skb_get_poff+0x53/0xa0 [ 9.485937] bpf_skb_get_pay_offset+0xe/0x20 [ 9.485944] ? ppp_send_frame+0xc2/0x5b0 [ 9.485949] ? _raw_spin_unlock_irqrestore+0x40/0x60 [ 9.485958] ? __ppp_xmit_process+0x7a/0xe0 [ 9.485968] ? ppp_xmit_process+0x5b/0xb0 [ 9.485974] ? ppp_write+0x12a/0x190 [ 9.485981] ? do_iter_write+0x18e/0x2d0 [ 9.485987] ? __import_iovec+0x30/0x130 [ 9.485997] ? do_pwritev+0x1b6/0x240 [ 9.486016] ? trace_hardirqs_on+0x47/0x50 [ 9.486023] ? __x64_sys_pwritev+0x24/0x30 [ 9.486026] ? do_syscall_64+0x3d/0x80 [ 9.486031] ? entry_SYSCALL_64_after_hwframe+0x63/0xcd
Flow dissector tries to find skb net namespace either via device or via socket. Neigher is set in ppp_send_frame, so let's manually use ppp->dev.
--- drivers/net/ppp/ppp_generic.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ppp/ppp_generic.c +2 -0
@@ -1528,6 +1528,8 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)int len;unsigned char *cp; + skb->dev = ppp->dev; +if (proto <0x8000 ) {#ifdef CONFIG_PPP_FILTER /* check if we should pass this packet */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 336/521 media: dvb-frontends: fix leak of memory fw
In reply to Greg Kroah-HartmanFrom: Yan Lei <[email protected]>
[ Upstream commit a15fe8d9f1bf460a804bcf18a890bfd2cf0d5caa ]
--- drivers/media/dvb-frontends/bcm3510.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/dvb-frontends/bcm3510.c +1 -0
@@ -649,6 +649,7 @@ static int bcm3510_download_firmware(struct dvb_frontend* fe)deb_info ("firmware chunk, addr: 0x%04x, len: 0x%04x, total length: 0x%04zx\n" ,addr,len,fw->size);if ((ret =bcm3510_write_ram (st,addr,&b[i+4 ],len)) <0 ) {err ("firmware download failed: %d\n" ,ret); +release_firmware (fw);return ret; } i +=4 + len;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 337/521 media: dvbdev: adopts refcnt to avoid UAF
In reply to Greg Kroah-HartmanFrom: Lin Ma <[email protected]>
[ Upstream commit 0fc044b2b5e2d05a1fa1fb0d7f270367a7855d79 ]
dvb_unregister_device() is known that prone to use-after-free. That is, the cleanup from dvb_unregister_device() releases the dvb_device even if there are pointers stored in file->private_data still refer to it.
This patch adds a reference counter into struct dvb_device and delays its deallocation until no pointer refers to the object.
--- drivers/media/dvb-core/dvb_ca_en50221.c | 2 +- drivers/media/dvb-core/dvb_frontend.c | 2 +- drivers/media/dvb-core/dvbdev.c | 32 +++++++++++++++++++------ include/media/dvbdev.h | 31 +++++++++++++----------- 4 files changed, 44 insertions(+), 23 deletions(-)
drivers/media/dvb-core/dvb_ca_en50221.c +1 -1
@@ -168,7 +168,7 @@ static void dvb_ca_private_free(struct dvb_ca_private *ca) {unsigned int i; -dvb_free_device (ca->dvbdev); +dvb_device_put (ca->dvbdev);for (i =0 ; i < ca->slot_count; i++)vfree (ca->slot_info[i].rx_buffer.data);
drivers/media/dvb-core/dvb_frontend.c +1 -1
@@ -147,7 +147,7 @@ static void __dvb_frontend_free(struct dvb_frontend *fe)struct dvb_frontend_private *fepriv = fe->frontend_priv;if (fepriv) -dvb_free_device (fepriv->dvbdev); +dvb_device_put (fepriv->dvbdev);dvb_frontend_invoke_release (fe, fe->ops.release);
drivers/media/dvb-core/dvbdev.c +25 -7
@@ -107,7 +107,7 @@ static int dvb_device_open(struct inode *inode, struct file *file) new_fops =fops_get (dvbdev->fops);if (!new_fops) goto fail; - file->private_data = dvbdev; + file->private_data =dvb_device_get (dvbdev);replace_fops (file, new_fops);if (file->f_op->open) err = file->f_op->open (inode, file);
@@ -171,6 +171,9 @@ int dvb_generic_release(struct inode *inode, struct file *file) } dvbdev->users++; + +dvb_device_put (dvbdev); +return 0 ; }EXPORT_SYMBOL (dvb_generic_release);
@@ -487,6 +490,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,return -ENOMEM ; } +kref_init (&dvbdev->ref);memcpy (dvbdev, template,sizeof (struct dvb_device )); dvbdev->type = type; dvbdev->id = id;
@@ -518,7 +522,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,#endif dvbdev->minor = minor; - dvb_minors[minor] = dvbdev; + dvb_minors[minor] =dvb_device_get (dvbdev);up_write (&minor_rwsem); ret =dvb_register_media_device (dvbdev, type, minor, demux_sink_pads);
@@ -559,6 +563,7 @@ void dvb_remove_device(struct dvb_device *dvbdev)down_write (&minor_rwsem); dvb_minors[dvbdev->minor] =NULL ; +dvb_device_put (dvbdev);up_write (&minor_rwsem);dvb_media_device_free (dvbdev);
@@ -570,21 +575,34 @@ void dvb_remove_device(struct dvb_device *dvbdev)EXPORT_SYMBOL (dvb_remove_device); -void dvb_free_device (struct dvb_device *dvbdev) +static void dvb_free_device (struct kref *ref) { -if (!dvbdev) -return ; + struct dvb_device *dvbdev = container_of(ref, struct dvb_device, ref);kfree (dvbdev->fops);kfree (dvbdev); } -EXPORT_SYMBOL (dvb_free_device); + + +struct dvb_device *dvb_device_get (struct dvb_device *dvbdev) +{ +kref_get (&dvbdev->ref); +return dvbdev; +} +EXPORT_SYMBOL (dvb_device_get); + + +void dvb_device_put (struct dvb_device *dvbdev) +{ +if (dvbdev) +kref_put (&dvbdev->ref, dvb_free_device); +}void dvb_unregister_device (struct dvb_device *dvbdev) {dvb_remove_device (dvbdev); -dvb_free_device (dvbdev); +dvb_device_put (dvbdev); }EXPORT_SYMBOL (dvb_unregister_device);
include/media/dvbdev.h +17 -14
@@ -156,6 +156,7 @@ struct dvb_adapter {*/ struct dvb_device {struct list_head list_head; +struct kref ref;const struct file_operations *fops;struct dvb_adapter *adapter;enum dvb_device_type type;
@@ -187,6 +188,20 @@ struct dvb_device {void *priv; }; +/** +* dvb_device_get - Increase dvb_device reference +* +* @dvbdev: pointer to struct dvb_device +*/ +struct dvb_device *dvb_device_get (struct dvb_device *dvbdev); + +/** +* dvb_device_get - Decrease dvb_device reference +* +* @dvbdev: pointer to struct dvb_device +*/ +void dvb_device_put (struct dvb_device *dvbdev); +/** * dvb_register_adapter - Registers a new DVB adapter *
@@ -231,29 +246,17 @@ int dvb_register_device(struct dvb_adapter *adap,/** * dvb_remove_device - Remove a registered DVB device * -* This does not free memory. To do that, call dvb_free_device(). +* This does not free memory. dvb_free_device() will do that when +* reference counter is empty * * @dvbdev: pointer to struct dvb_device */ void dvb_remove_device (struct dvb_device *dvbdev); -/** -* dvb_free_device - Free memory occupied by a DVB device. -* -* Call dvb_unregister_device() before calling this function. -* -* @dvbdev: pointer to struct dvb_device -*/ -void dvb_free_device (struct dvb_device *dvbdev);/** * dvb_unregister_device - Unregisters a DVB device * -* This is a combination of dvb_remove_device() and dvb_free_device(). -* Using this function is usually a mistake, and is often an indicator -* for a use-after-free bug (when a userspace process keeps a file -* handle to a detached device). -* * @dvbdev: pointer to struct dvb_device */ void dvb_unregister_device (struct dvb_device *dvbdev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 338/521 media: dvb-usb: fix memory leak in dvb_usb_adapter_init()
In reply to Greg Kroah-HartmanFrom: Mazin Al Haddad <[email protected]>
[ Upstream commit 94d90fb06b94a90c176270d38861bcba34ce377d ]
Syzbot reports a memory leak in "dvb_usb_adapter_init()". The leak is due to not accounting for and freeing current iteration's adapter->priv in case of an error. Currently if an error occurs, it will exit before incrementing "num_adapters_initalized", which is used as a reference counter to free all adap->priv in "dvb_usb_adapter_exit()". There are multiple error paths that can exit from before incrementing the counter. Including the error handling paths for "dvb_usb_adapter_stream_init()", "dvb_usb_adapter_dvb_init()" and "dvb_usb_adapter_frontend_init()" within "dvb_usb_adapter_init()".
This means that in case of an error in any of these functions the current iteration is not accounted for and the current iteration's adap->priv is not freed.
Fix this by freeing the current iteration's adap->priv in the "stream_init_err:" label in the error path. The rest of the (accounted for) adap->priv objects are freed in dvb_usb_adapter_exit() as expected using the num_adapters_initalized variable.
Syzbot report:
BUG: memory leak
unreferenced object 0xffff8881172f1a00 (size 512):
comm "kworker/0:2", pid 139, jiffies 4294994873 (age 10.960s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff844af012>] dvb_usb_adapter_init drivers/media/usb/dvb-usb/dvb-usb-init.c:75 [inline]
[<ffffffff844af012>] dvb_usb_init drivers/media/usb/dvb-usb/dvb-usb-init.c:184 [inline]
[<ffffffff844af012>] dvb_usb_device_init.cold+0x4e5/0x79e drivers/media/usb/dvb-usb/dvb-usb-init.c:308
[<ffffffff830db21d>] dib0700_probe+0x8d/0x1b0 drivers/media/usb/dvb-usb/dib0700_core.c:883
[<ffffffff82d3fdc7>] usb_probe_interface+0x177/0x370 drivers/usb/core/driver.c:396
[<ffffffff8274ab37>] call_driver_probe drivers/base/dd.c:542 [inline]
[<ffffffff8274ab37>] really_probe.part.0+0xe7/0x310 drivers/base/dd.c:621
[<ffffffff8274ae6c>] really_probe drivers/base/dd.c:583 [inline]
[<ffffffff8274ae6c>] __driver_probe_device+0x10c/0x1e0 drivers/base/dd.c:752
[<ffffffff8274af6a>] driver_probe_device+0x2a/0x120 drivers/base/dd.c:782
[<ffffffff8274b786>] __device_attach_driver+0xf6/0x140 drivers/base/dd.c:899
[<ffffffff82747c87>] bus_for_each_drv+0xb7/0x100 drivers/base/bus.c:427
[<ffffffff8274b352>] __device_attach+0x122/0x260 drivers/base/dd.c:970
[<ffffffff827498f6>] bus_probe_device+0xc6/0xe0 drivers/base/bus.c:487
[<ffffffff82745cdb>] device_add+0x5fb/0xdf0 drivers/base/core.c:3405
[<ffffffff82d3d202>] usb_set_configuration+0x8f2/0xb80 drivers/usb/core/message.c:2170
[<ffffffff82d4dbfc>] usb_generic_driver_probe+0x8c/0xc0 drivers/usb/core/generic.c:238
[<ffffffff82d3f49c>] usb_probe_device+0x5c/0x140 drivers/usb/core/driver.c:293
[<ffffffff8274ab37>] call_driver_probe drivers/base/dd.c:542 [inline]
[<ffffffff8274ab37>] really_probe.part.0+0xe7/0x310 drivers/base/dd.c:621
[<ffffffff8274ae6c>] really_probe drivers/base/dd.c:583 [inline]
[<ffffffff8274ae6c>] __driver_probe_device+0x10c/0x1e0 drivers/base/dd.c:752--- drivers/media/usb/dvb-usb/dvb-usb-init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/usb/dvb-usb/dvb-usb-init.c +3 -1
@@ -84,7 +84,7 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs) ret =dvb_usb_adapter_stream_init (adap);if (ret) -return ret; + goto stream_init_err; ret =dvb_usb_adapter_dvb_init (adap, adapter_nrs);if (ret)
@@ -117,6 +117,8 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)dvb_usb_adapter_dvb_exit (adap); dvb_init_err:dvb_usb_adapter_stream_exit (adap); +stream_init_err: +kfree (adap->priv);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 339/521 blk-mq: fix possible memleak when register hctx failed
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
[ Upstream commit 4b7a21c57b14fbcd0e1729150189e5933f5088e9 ]
There's issue as follows when do fault injection test:
unreferenced object 0xffff888132a9f400 (size 512):
comm "insmod", pid 308021, jiffies 4324277909 (age 509.733s) hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 08 f4 a9 32 81 88 ff ff ...........2....
08 f4 a9 32 81 88 ff ff 00 00 00 00 00 00 00 00 ...2............
backtrace:
[<00000000e8952bb4>] kmalloc_node_trace+0x22/0xa0
[<00000000f9980e0f>] blk_mq_alloc_and_init_hctx+0x3f1/0x7e0
[<000000002e719efa>] blk_mq_realloc_hw_ctxs+0x1e6/0x230
[<000000004f1fda40>] blk_mq_init_allocated_queue+0x27e/0x910
[<00000000287123ec>] __blk_mq_alloc_disk+0x67/0xf0
[<00000000a2a34657>] 0xffffffffa2ad310f
[<00000000b173f718>] 0xffffffffa2af824a
[<0000000095a1dabb>] do_one_initcall+0x87/0x2a0
[<00000000f32fdf93>] do_init_module+0xdf/0x320
[<00000000cbe8541e>] load_module+0x3006/0x3390
[<0000000069ed1bdb>] __do_sys_finit_module+0x113/0x1b0
[<00000000a1a29ae8>] do_syscall_64+0x35/0x80
[<000000009cd878b0>] entry_SYSCALL_64_after_hwframe+0x46/0xb0Fault injection context as follows:
kobject_add
blk_mq_register_hctx
blk_mq_sysfs_register
blk_register_queue
device_add_disk
null_add_dev.part.0 [null_blk]
As 'blk_mq_register_hctx' may already add some objects when failed halfway, but there isn't do fallback, caller don't know which objects add failed. To solve above issue just do fallback when add objects failed halfway in 'blk_mq_register_hctx'.
--- block/blk-mq-sysfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
block/blk-mq-sysfs.c +9 -2
@@ -241,7 +241,7 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) {struct request_queue *q = hctx->queue;struct blk_mq_ctx *ctx; -int i, ret; +int i, j, ret;if (!hctx->nr_ctx)return 0 ;
@@ -253,9 +253,16 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)hctx_for_each_ctx (hctx, ctx, i) { ret =kobject_add (&ctx->kobj, &hctx->kobj,"cpu%u" , ctx->cpu);if (ret) -break ; + goto out; } +return 0 ; +out: +hctx_for_each_ctx (hctx, ctx, j) { +if (j < i) +kobject_del (&ctx->kobj); + } +kobject_del (&hctx->kobj);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 340/521 regulator: core: fix use_count leakage when handling boot-on
In reply to Greg Kroah-HartmanFrom: Rui Zhang <[email protected]>
[ Upstream commit 0591b14ce0398125439c759f889647369aa616a0 ]
I found a use_count leakage towards supply regulator of rdev with boot-on option.
┌───────────────────┐ ┌───────────────────┐ │ regulator_dev A │ │ regulator_dev B │ │ (boot-on) │ │ (boot-on) │ │ use_count=0 │◀──supply──│ use_count=1 │ │ │ │ │ └───────────────────┘ └───────────────────┘
In case of rdev(A) configured with `regulator-boot-on', the use_count of supplying regulator(B) will increment inside regulator_enable(rdev->supply).
Thus, B will acts like always-on, and further balanced regulator_enable/disable cannot actually disable it anymore.
However, B was also configured with `regulator-boot-on', we wish it could be disabled afterwards.
--- drivers/regulator/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/regulator/core.c +7 -1
@@ -1197,7 +1197,13 @@ static int set_machine_constraints(struct regulator_dev *rdev)if (rdev->supply_name && !rdev->supply)return -EPROBE_DEFER ; -if (rdev->supply) { +/* If supplying regulator has already been enabled, +* it's not intended to have use_count increment +* when rdev is only boot-on. +*/ +if (rdev->supply && + (rdev->constraints->always_on || + !regulator_is_enabled (rdev->supply))) { ret =regulator_enable (rdev->supply);if (ret <0 ) {_regulator_put (rdev->supply);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 341/521 mmc: f-sdh30: Add quirks for broken timeout clock capability
In reply to Greg Kroah-HartmanFrom: Kunihiko Hayashi <[email protected]>
[ Upstream commit aae9d3a440736691b3c1cb09ae2c32c4f1ee2e67 ]
There is a case where the timeout clock is not supplied to the capability. Add a quirk for that.
--- drivers/mmc/host/sdhci_f_sdh30.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/host/sdhci_f_sdh30.c +3 -0
@@ -199,6 +199,9 @@ static int sdhci_f_sdh30_probe(struct platform_device *pdev)if (reg &SDHCI_CAN_DO_8BIT ) priv->vendor_hs200 =F_SDH30_EMMC_HS200 ; +if (!(reg &SDHCI_TIMEOUT_CLK_MASK )) + host->quirks |=SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK ; + ret =sdhci_add_host (host);if (ret) goto err_add_host;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 342/521 media: si470x: Fix use-after-free in si470x_int_in_callback()
In reply to Greg Kroah-HartmanFrom: Shigeru Yoshida <[email protected]>
[ Upstream commit 7d21e0b1b41b21d628bf2afce777727bd4479aa5 ]
syzbot reported use-after-free in si470x_int_in_callback() [1]. This indicates that urb->context, which contains struct si470x_device object, is freed when si470x_int_in_callback() is called.
The cause of this issue is that si470x_int_in_callback() is called for freed urb.
si470x_usb_driver_probe() calls si470x_start_usb(), which then calls usb_submit_urb() and si470x_start(). If si470x_start_usb() fails, si470x_usb_driver_probe() doesn't kill urb, but it just frees struct si470x_device object, as depicted below:
si470x_usb_driver_probe()
...
si470x_start_usb()
...
usb_submit_urb()
retval = si470x_start()
return retval
if (retval < 0)
free struct si470x_device object, but don't kill urbThis patch fixes this issue by killing urb when si470x_start_usb() fails and urb is submitted. If si470x_start_usb() fails and urb is not submitted, i.e. submitting usb fails, it just frees struct si470x_device object.
--- drivers/media/radio/si470x/radio-si470x-usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/radio/si470x/radio-si470x-usb.c +3 -1
@@ -742,8 +742,10 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,/* start radio */ retval =si470x_start_usb (radio); -if (retval <0 ) +if (retval <0 && !radio->int_in_running) goto err_buf; +else if (retval <0 )/* in case of radio->int_in_running == 1 */ + goto err_all;/* set initial frequency */ si470x_set_freq (radio,87.5 *FREQ_MUL );/* available in all regions */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 343/521 clk: st: Fix memory leak in st_of_quadfs_setup()
In reply to Greg Kroah-HartmanFrom: Xiu Jianfeng <[email protected]>
[ Upstream commit cfd3ffb36f0d566846163118651d868e607300ba ]
If st_clk_register_quadfs_pll() fails, @lock should be freed before goto @err_exit, otherwise will cause meory leak issue, fix it.
--- drivers/clk/st/clkgen-fsyn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/st/clkgen-fsyn.c +3 -2
@@ -948,9 +948,10 @@ static void __init st_of_quadfs_setup(struct device_node *np, clk =st_clk_register_quadfs_pll (pll_name, clk_parent_name, data, reg, lock); -if (IS_ERR (clk)) +if (IS_ERR (clk)) { +kfree (lock); goto err_exit; -else + }else pr_debug("%s: parent %s rate %u\n", __clk_get_name(clk), __clk_get_name(clk_get_parent(clk)),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 344/521 drm/fsl-dcu: Fix return type of fsl_dcu_drm_connector_mode_valid()
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit 96d845a67b7e406cfed7880a724c8ca6121e022e ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c:74:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = fsl_dcu_drm_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
->mode_valid() in 'struct drm_connector_helper_funcs' expects a return type of 'enum drm_mode_status', not 'int'. Adjust the return type of fsl_dcu_drm_connector_mode_valid() to match the prototype's to resolve the warning and CFI failure.
--- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c +3 -2
@@ -83,8 +83,9 @@ static int fsl_dcu_drm_connector_get_modes(struct drm_connector *connector)return num_modes; } -static int fsl_dcu_drm_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +fsl_dcu_drm_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {if (mode->hdisplay &0xf )return MODE_ERROR ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 345/521 drm/sti: Fix return type of sti_{dvo,hda,hdmi}_connector_mode_valid()
In reply to Greg Kroah-HartmanFrom: Nathan Chancellor <[email protected]>
[ Upstream commit 0ad811cc08a937d875cbad0149c1bab17f84ba05 ]
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals:
drivers/gpu/drm/sti/sti_hda.c:637:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = sti_hda_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/sti/sti_dvo.c:376:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = sti_dvo_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/sti/sti_hdmi.c:1035:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict]
.mode_valid = sti_hdmi_connector_mode_valid,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
->mode_valid() in 'struct drm_connector_helper_funcs' expects a return type of 'enum drm_mode_status', not 'int'. Adjust the return type of sti_{dvo,hda,hdmi}_connector_mode_valid() to match the prototype's to resolve the warning and CFI failure.
--- drivers/gpu/drm/sti/sti_dvo.c | 5 +++-- drivers/gpu/drm/sti/sti_hda.c | 5 +++-- drivers/gpu/drm/sti/sti_hdmi.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/sti/sti_dvo.c +3 -2
@@ -346,8 +346,9 @@ static int sti_dvo_connector_get_modes(struct drm_connector *connector)#define CLK_TOLERANCE_HZ 50 -static int sti_dvo_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +sti_dvo_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {int target = mode->clock *1000 ;int target_min = target -CLK_TOLERANCE_HZ ;
drivers/gpu/drm/sti/sti_hda.c +3 -2
@@ -596,8 +596,9 @@ static int sti_hda_connector_get_modes(struct drm_connector *connector)#define CLK_TOLERANCE_HZ 50 -static int sti_hda_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +sti_hda_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {int target = mode->clock *1000 ;int target_min = target -CLK_TOLERANCE_HZ ;
drivers/gpu/drm/sti/sti_hdmi.c +3 -2
@@ -989,8 +989,9 @@ static int sti_hdmi_connector_get_modes(struct drm_connector *connector)#define CLK_TOLERANCE_HZ 50 -static int sti_hdmi_connector_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) +static enum drm_mode_status +sti_hdmi_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) {int target = mode->clock *1000 ;int target_min = target -CLK_TOLERANCE_HZ ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 346/521 orangefs: Fix kmemleak in orangefs_prepare_debugfs_help_string()
In reply to Greg Kroah-HartmanFrom: Zhang Xiaoxu <[email protected]>
[ Upstream commit d23417a5bf3a3afc55de5442eb46e1e60458b0a1 ]
When insert and remove the orangefs module, then debug_help_string will be leaked:
unreferenced object 0xffff8881652ba000 (size 4096):
comm "insmod", pid 1701, jiffies 4294893639 (age 13218.530s)
hex dump (first 32 bytes):
43 6c 69 65 6e 74 20 44 65 62 75 67 20 4b 65 79 Client Debug Key
77 6f 72 64 73 20 61 72 65 20 75 6e 6b 6e 6f 77 words are unknow
backtrace:
[<0000000004e6f8e3>] kmalloc_trace+0x27/0xa0
[<0000000006f75d85>] orangefs_prepare_debugfs_help_string+0x5e/0x480 [orangefs]
[<0000000091270a2a>] _sub_I_65535_1+0x57/0xf70 [crc_itu_t]
[<000000004b1ee1a3>] do_one_initcall+0x87/0x2a0
[<000000001d0614ae>] do_init_module+0xdf/0x320
[<00000000efef068c>] load_module+0x2f98/0x3330
[<000000006533b44d>] __do_sys_finit_module+0x113/0x1b0
[<00000000a0da6f99>] do_syscall_64+0x35/0x80
[<000000007790b19b>] entry_SYSCALL_64_after_hwframe+0x46/0xb0When remove the module, should always free debug_help_string. Should always free the allocated buffer when change the free_debug_help_string.
--- fs/orangefs/orangefs-debugfs.c | 3 +++ 1 file changed, 3 insertions(+)
fs/orangefs/orangefs-debugfs.c +3 -0
@@ -254,6 +254,8 @@ static int orangefs_kernel_debug_init(void)void orangefs_debugfs_cleanup (void ) {debugfs_remove_recursive (debug_dir); +kfree (debug_help_string); + debug_help_string =NULL ; }/* open ORANGEFS_KMOD_DEBUG_HELP_FILE */
@@ -709,6 +711,7 @@ int orangefs_prepare_debugfs_help_string(int at_boot)memset (debug_help_string,0 ,DEBUG_HELP_STRING_SIZE );strlcat (debug_help_string, new, string_size);mutex_unlock (&orangefs_help_file_lock); +kfree (new); } rc =0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 347/521 ASoC: mediatek: mt8173-rt5650-rt5514: fix refcount leak in mt8173_rt5650_rt5514_dev_probe()
In reply to Greg Kroah-HartmanFrom: Wang Yufen <[email protected]>
[ Upstream commit 3327d721114c109ba0575f86f8fda3b525404054 ]
The node returned by of_parse_phandle() with refcount incremented, of_node_put() needs be called when finish using it. So add it in the error path in mt8173_rt5650_rt5514_dev_probe().
--- sound/soc/mediatek/mt8173/mt8173-rt5650-rt5514.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
sound/soc/mediatek/mt8173/mt8173-rt5650-rt5514.c +5 -2
@@ -199,14 +199,16 @@ static int mt8173_rt5650_rt5514_dev_probe(struct platform_device *pdev)if (!mt8173_rt5650_rt5514_codecs[0 ].of_node) {dev_err (&pdev->dev,"Property 'audio-codec' missing or invalid\n" ); -return -EINVAL ; + ret = -EINVAL ; + goto out; } mt8173_rt5650_rt5514_codecs[1 ].of_node =of_parse_phandle (pdev->dev.of_node,"mediatek,audio-codec" ,1 );if (!mt8173_rt5650_rt5514_codecs[1 ].of_node) {dev_err (&pdev->dev,"Property 'audio-codec' missing or invalid\n" ); -return -EINVAL ; + ret = -EINVAL ; + goto out; } mt8173_rt5650_rt5514_codec_conf[0 ].of_node = mt8173_rt5650_rt5514_codecs[1 ].of_node;
@@ -218,6 +220,7 @@ static int mt8173_rt5650_rt5514_dev_probe(struct platform_device *pdev)dev_err (&pdev->dev,"%s snd_soc_register_card fail %d\n" , __func__, ret); +out:of_node_put (platform_node);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 348/521 ASoC: rockchip: pdm: Add missing clk_disable_unprepare() in rockchip_pdm_runtime_resume()
In reply to Greg Kroah-HartmanFrom: Wang Jingjin <[email protected]>
[ Upstream commit ef0a098efb36660326c133af9b5a04a96a00e3ca ]
The clk_disable_unprepare() should be called in the error handling of rockchip_pdm_runtime_resume().
--- sound/soc/rockchip/rockchip_pdm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/rockchip/rockchip_pdm.c +1 -0
@@ -303,6 +303,7 @@ static int rockchip_pdm_runtime_resume(struct device *dev) ret =clk_prepare_enable (pdm->hclk);if (ret) { +clk_disable_unprepare (pdm->clk);dev_err (pdm->dev,"hclock enable failed %d\n" , ret);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 349/521 ASoC: wm8994: Fix potential deadlock
In reply to Greg Kroah-HartmanFrom: Marek Szyprowski <[email protected]>
[ Upstream commit 9529dc167ffcdfd201b9f0eda71015f174095f7e ]
Fix this by dropping wm8994->accdet_lock while calling cancel_delayed_work_sync(&wm8994->mic_work) in wm1811_jackdet_irq().
--- sound/soc/codecs/wm8994.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/soc/codecs/wm8994.c +5 -0
@@ -3715,7 +3715,12 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data) }else {dev_dbg (component->dev,"Jack not detected\n" ); +/* Release wm8994->accdet_lock to avoid deadlock: +* cancel_delayed_work_sync() takes wm8994->mic_work internal +* lock and wm1811_mic_work takes wm8994->accdet_lock */ +mutex_unlock (&wm8994->accdet_lock);cancel_delayed_work_sync (&wm8994->mic_work); +mutex_lock (&wm8994->accdet_lock);snd_soc_component_update_bits (component,WM8958_MICBIAS2 ,WM8958_MICB2_DISCH ,WM8958_MICB2_DISCH );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 350/521 ASoC: rockchip: spdif: Add missing clk_disable_unprepare() in rk_spdif_runtime_resume()
In reply to Greg Kroah-HartmanFrom: Wang Jingjin <[email protected]>
[ Upstream commit 6d94d0090527b1763872275a7ccd44df7219b31e ]
rk_spdif_runtime_resume() may have called clk_prepare_enable() before return from failed branches, add missing clk_disable_unprepare() in this case.
--- sound/soc/rockchip/rockchip_spdif.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/rockchip/rockchip_spdif.c +1 -0
@@ -89,6 +89,7 @@ static int __maybe_unused rk_spdif_runtime_resume(struct device *dev) ret =clk_prepare_enable (spdif->hclk);if (ret) { +clk_disable_unprepare (spdif->mclk);dev_err (spdif->dev,"hclk clock enable failed %d\n" , ret);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 351/521 ASoC: rt5670: Remove unbalanced pm_runtime_put()
In reply to Greg Kroah-HartmanFrom: Hans de Goede <[email protected]>
[ Upstream commit 6c900dcc3f7331a67ed29739d74524e428d137fb ]
For some reason rt5670_i2c_probe() does a pm_runtime_put() at the end of a successful probe. But it has never done a pm_runtime_get() leading to the following error being logged into dmesg:
rt5670 i2c-10EC5640:00: Runtime PM usage count underflow!
Fix this by removing the unnecessary pm_runtime_put().
--- sound/soc/codecs/rt5670.c | 2 -- 1 file changed, 2 deletions(-)
sound/soc/codecs/rt5670.c +0 -2
@@ -3217,8 +3217,6 @@ static int rt5670_i2c_probe(struct i2c_client *i2c,if (ret <0 ) goto err; -pm_runtime_put (&i2c->dev); -return 0 ; err:pm_runtime_disable (&i2c->dev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 352/521 pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion
In reply to Greg Kroah-HartmanFrom: John Stultz <[email protected]>
[ Upstream commit 76d62f24db07f22ccf9bc18ca793c27d4ebef721 ]
Wei Wang reported seeing priority inversion caused latencies caused by contention on pmsg_lock, and suggested it be switched to a rt_mutex.
I was initially hesitant this would help, as the tasks in that trace all seemed to be SCHED_NORMAL, so the benefit would be limited to only nice boosting.
However, another similar issue was raised where the priority inversion was seen did involve a blocked RT task so it is clear this would be helpful in that case.
--- fs/pstore/pmsg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/pstore/pmsg.c +4 -3
@@ -15,9 +15,10 @@#include <linux/device.h> #include <linux/fs.h> #include <linux/uaccess.h> +#include <linux/rtmutex.h> #include "internal.h" -static DEFINE_MUTEX (pmsg_lock); +static DEFINE_RT_MUTEX (pmsg_lock);static ssize_t write_pmsg (struct file *file,const char __user *buf,size_t count,loff_t *ppos)
@@ -36,9 +37,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,if (!access_ok (VERIFY_READ , buf, count))return -EFAULT ; -mutex_lock (&pmsg_lock); +rt_mutex_lock (&pmsg_lock); ret = psinfo->write_user (&record, buf); -mutex_unlock (&pmsg_lock); +rt_mutex_unlock (&pmsg_lock);return ret ? ret : count; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 353/521 perf debug: Set debug_peo_args and redirect_to_stderr variable to correct values in perf_quiet_option()
In reply to Greg Kroah-HartmanFrom: Yang Jihong <[email protected]>
[ Upstream commit 188ac720d364035008a54d249cf47b4cc100f819 ]
When perf uses quiet mode, perf_quiet_option() sets the 'debug_peo_args' variable to -1, and display_attr() incorrectly determines the value of 'debug_peo_args'. As a result, unexpected information is displayed.
Before:
# perf record --quiet -- ls > /dev/null
------------------------------------------------------------
perf_event_attr:
size 128
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|PERIOD
read_format ID|LOST
disabled 1
inherit 1
mmap 1
comm 1
freq 1
enable_on_exec 1
task 1
precise_ip 3
sample_id_all 1
exclude_guest 1
mmap2 1
comm_exec 1
ksymbol 1
bpf_event 1
------------------------------------------------------------
...After:
# perf record --quiet -- ls > /dev/null #
redirect_to_stderr is a similar problem.
--- tools/perf/util/debug.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/util/debug.c +4 -0
@@ -232,6 +232,10 @@ int perf_quiet_option(void) var++; } +/* For debug variables that are used as bool types, set to 0. */ + redirect_to_stderr =0 ; + debug_peo_args =0 ; +return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 354/521 pstore: Make sure CONFIG_PSTORE_PMSG selects CONFIG_RT_MUTEXES
In reply to Greg Kroah-HartmanFrom: John Stultz <[email protected]>
[ Upstream commit 2f4fec5943407318b9523f01ce1f5d668c028332 ]
In commit 76d62f24db07 ("pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion") I changed a lock to an rt_mutex.
However, its possible that CONFIG_RT_MUTEXES is not enabled, which then results in a build failure, as the 0day bot detected:
https://lore.kernel.org/linux-mm/[email protected]/
Thus this patch changes CONFIG_PSTORE_PMSG to select CONFIG_RT_MUTEXES, which ensures the build will not fail.
--- fs/pstore/Kconfig | 1 + 1 file changed, 1 insertion(+)
fs/pstore/Kconfig +1 -0
@@ -117,6 +117,7 @@ config PSTORE_CONSOLE config PSTORE_PMSG bool "Log user space messages" depends on PSTORE + select RT_MUTEXES help When the option is enabled, pstore will export a character interface /dev/pmsg0 to log user space messages. On reboot
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 355/521 usb: dwc3: core: defer probe on ulpi_read_id timeout
In reply to Greg Kroah-HartmanFrom: Ferry Toth <[email protected]>
commit 63130462c919ece0ad0d9bb5a1f795ef8d79687e upstream.
Since commit 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present"), Dual Role support on Intel Merrifield platform broke due to rearranging the call to dwc3_get_extcon().
It appears to be caused by ulpi_read_id() masking the timeout on the first test write. In the past dwc3 probe continued by calling dwc3_core_soft_reset() followed by dwc3_get_extcon() which happend to return -EPROBE_DEFER. On deferred probe ulpi_read_id() finally succeeded. Due to above mentioned rearranging -EPROBE_DEFER is not returned and probe completes without phy.
On Intel Merrifield the timeout on the first test write issue is reproducible but it is difficult to find the root cause. Using a mainline kernel and rootfs with buildroot ulpi_read_id() succeeds. As soon as adding ftrace / bootconfig to find out why, ulpi_read_id() fails and we can't analyze the flow. Using another rootfs ulpi_read_id() fails even without adding ftrace. We suspect the issue is some kind of timing / race, but merely retrying ulpi_read_id() does not resolve the issue.
As we now changed ulpi_read_id() to return -ETIMEDOUT in this case, we need to handle the error by calling dwc3_core_soft_reset() and request -EPROBE_DEFER. On deferred probe ulpi_read_id() is retried and succeeds.
--- drivers/usb/dwc3/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/usb/dwc3/core.c +6 -1
@@ -914,8 +914,13 @@ static int dwc3_core_init(struct dwc3 *dif (!dwc->ulpi_ready) { ret =dwc3_core_ulpi_init (dwc); -if (ret) +if (ret) { +if (ret == -ETIMEDOUT ) { +dwc3_core_soft_reset (dwc); + ret = -EPROBE_DEFER ; + } goto err0; + } dwc->ulpi_ready = true; }
Greg Kroah-Hartman
maintainerPATCH 356/521 HID: wacom: Ensure bootloader PID is usable in hidraw mode
In reply to Greg Kroah-HartmanFrom: Jason Gerecke <[email protected]>
commit 1db1f392591aff13fd643f0ec7c1d5e27391d700 upstream.
Some Wacom devices have a special "bootloader" mode that is used for firmware flashing. When operating in this mode, the device cannot be used for input, and the HID descriptor is not able to be processed by the driver. The driver generates an "Unknown device_type" warning and then returns an error code from wacom_probe(). This is a problem because userspace still needs to be able to interact with the device via hidraw to perform the firmware flash.
This commit adds a non-generic device definition for 056a:0094 which is used when devices are in "bootloader" mode. It marks the devices with a special BOOTLOADER type that is recognized by wacom_probe() and wacom_raw_event(). When we see this type we ensure a hidraw device is created and otherwise keep our hands off so that userspace is in full control.
--- drivers/hid/wacom_sys.c | 8 ++++++++ drivers/hid/wacom_wac.c | 4 ++++ drivers/hid/wacom_wac.h | 1 + 3 files changed, 13 insertions(+)
drivers/hid/wacom_sys.c +8 -0
@@ -163,6 +163,9 @@ static int wacom_raw_event(struct hid_de {struct wacom *wacom =hid_get_drvdata (hdev); +if (wacom->wacom_wac.features.type ==BOOTLOADER ) +return 0 ; +if (size >WACOM_PKGLEN_MAX )return 1 ;
@@ -2759,6 +2762,11 @@ static int wacom_probe(struct hid_device goto fail; } +if (features->type ==BOOTLOADER ) { +hid_warn (hdev,"Using device in hidraw-only mode" ); +return hid_hw_start (hdev,HID_CONNECT_HIDRAW ); + } + error =wacom_parse_and_register (wacom, false);if (error) goto fail;
drivers/hid/wacom_wac.c +4 -0
@@ -4680,6 +4680,9 @@ static const struct wacom_features wacomstatic const struct wacom_features wacom_features_HID_ANY_ID = {"Wacom HID" , .type =HID_GENERIC , .oVid =HID_ANY_ID , .oPid =HID_ANY_ID }; +static const struct wacom_features wacom_features_0x94 = + {"Wacom Bootloader" , .type =BOOTLOADER }; +#define USB_DEVICE_WACOM (prod) \ HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\ .driver_data = (kernel_ulong_t)&wacom_features_##prod
@@ -4753,6 +4756,7 @@ const struct hid_device_id wacom_ids[] = { USB_DEVICE_WACOM(0x84) }, { USB_DEVICE_WACOM(0x90) }, { USB_DEVICE_WACOM(0x93) }, + { USB_DEVICE_WACOM(0x94) }, { USB_DEVICE_WACOM(0x97) }, { USB_DEVICE_WACOM(0x9A) }, { USB_DEVICE_WACOM(0x9F) },
drivers/hid/wacom_wac.h +1 -0
@@ -244,6 +244,7 @@ enum {MTTPC ,MTTPC_B ,HID_GENERIC , +BOOTLOADER , MAX_TYPE };
Greg Kroah-Hartman
maintainerPATCH 357/521 reiserfs: Add missing calls to reiserfs_security_free()
In reply to Greg Kroah-HartmanFrom: Roberto Sassu <[email protected]>
commit 572302af1258459e124437b8f3369357447afac7 upstream.
Commit 57fe60df6241 ("reiserfs: add atomic addition of selinux attributes during inode creation") defined reiserfs_security_free() to free the name and value of a security xattr allocated by the active LSM through security_old_inode_init_security(). However, this function is not called in the reiserfs code.
Thus, add a call to reiserfs_security_free() whenever reiserfs_security_init() is called, and initialize value to NULL, to avoid to call kfree() on an uninitialized pointer.
Finally, remove the kfree() for the xattr name, as it is not allocated anymore.
--- fs/reiserfs/namei.c | 4 ++++ fs/reiserfs/xattr_security.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
fs/reiserfs/namei.c +4 -0
@@ -695,6 +695,7 @@ static int reiserfs_create(struct inode out_failed:reiserfs_write_unlock (dir->i_sb); +reiserfs_security_free (&security);return retval; }
@@ -778,6 +779,7 @@ static int reiserfs_mknod(struct inode * out_failed:reiserfs_write_unlock (dir->i_sb); +reiserfs_security_free (&security);return retval; }
@@ -876,6 +878,7 @@ static int reiserfs_mkdir(struct inode * retval =journal_end (&th); out_failed:reiserfs_write_unlock (dir->i_sb); +reiserfs_security_free (&security);return retval; }
@@ -1191,6 +1194,7 @@ static int reiserfs_symlink(struct inode retval =journal_end (&th); out_failed:reiserfs_write_unlock (parent_dir->i_sb); +reiserfs_security_free (&security);return retval; }
fs/reiserfs/xattr_security.c +1 -1
@@ -49,6 +49,7 @@ int reiserfs_security_init(struct inodeint error; sec->name =NULL ; + sec->value =NULL ;/* Don't add selinux attributes on xattrs - they'll never get used */ if (IS_PRIVATE (dir))
@@ -94,7 +95,6 @@ int reiserfs_security_write(struct reisevoid reiserfs_security_free (struct reiserfs_security_handle *sec) { -kfree (sec->name);kfree (sec->value); sec->name =NULL ; sec->value =NULL ;
Greg Kroah-Hartman
maintainerPATCH 358/521 iio: adc: ad_sigma_delta: do not use internal iio_dev lock
In reply to Greg Kroah-HartmanFrom: Nuno Sá <[email protected]>
commit 20228a1d5a55e7db0c6720840f2c7d2b48c55f69 upstream.
Drop 'mlock' usage by making use of iio_device_claim_direct_mode(). This change actually makes sure we cannot do a single conversion while buffering is enable. Note there was a potential race in the previous code since we were only acquiring the lock after checking if the bus is enabled.
--- drivers/iio/adc/ad_sigma_delta.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +4 -4
@@ -283,10 +283,10 @@ int ad_sigma_delta_single_conversion(strunsigned int sample, raw_sample;int ret =0 ; -if (iio_buffer_enabled (indio_dev)) -return -EBUSY ; + ret =iio_device_claim_direct_mode (indio_dev); +if (ret) +return ret; -mutex_lock (&indio_dev->mlock);ad_sigma_delta_set_channel (sigma_delta, chan->address);spi_bus_lock (sigma_delta->spi->master);
@@ -320,7 +320,7 @@ out:ad_sigma_delta_set_mode (sigma_delta,AD_SD_MODE_IDLE ); sigma_delta->bus_locked = false;spi_bus_unlock (sigma_delta->spi->master); -mutex_unlock (&indio_dev->mlock); +iio_device_release_direct_mode (indio_dev);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 359/521 gcov: add support for checksum field
In reply to Greg Kroah-HartmanFrom: Rickard x Andersson <[email protected]>
commit e96b95c2b7a63a454b6498e2df67aac14d046d13 upstream.
In GCC version 12.1 a checksum field was added.
This patch fixes a kernel crash occurring during boot when using gcov-kernel with GCC version 12.2. The crash occurred on a system running on i.MX6SX.
--- kernel/gcov/gcc_4_7.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/gcov/gcc_4_7.c +5 -0
@@ -85,6 +85,7 @@ struct gcov_fn_info {* @version: gcov version magic indicating the gcc version used for compilation * @next: list head for a singly-linked list * @stamp: uniquifying time stamp +* @checksum: unique object checksum * @filename: name of the associated gcov data file * @merge: merge functions (null for unused counter type) * @n_functions: number of instrumented functions
@@ -97,6 +98,10 @@ struct gcov_info {unsigned int version;struct gcov_info *next;unsigned int stamp; +/* Since GCC 12.1 a checksum field is added. */ +#if (__GNUC__ >=12 ) +unsigned int checksum; +#endif const char *filename;void (*merge[GCOV_COUNTERS ])(gcov_type *,unsigned int );unsigned int n_functions;
Greg Kroah-Hartman
maintainerPATCH 360/521 media: dvbdev: fix build warning due to comments
In reply to Greg Kroah-HartmanFrom: Lin Ma <[email protected]>
commit 3edfd14bb50fa6f94ed1a37bbb17d9f1c2793b57 upstream.
Previous commit that introduces reference counter does not add proper comments, which will lead to warning when building htmldocs. Fix them.
--- include/media/dvbdev.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/media/dvbdev.h +2 -1
@@ -126,6 +126,7 @@ struct dvb_adapter {* struct dvb_device - represents a DVB device node * * @list_head: List head with all DVB devices +* @ref: reference counter * @fops: pointer to struct file_operations * @adapter: pointer to the adapter that holds this device node * @type: type of the device, as defined by &enum dvb_device_type.
@@ -196,7 +197,7 @@ struct dvb_device {struct dvb_device *dvb_device_get (struct dvb_device *dvbdev);/** -* dvb_device_get - Decrease dvb_device reference +* dvb_device_put - Decrease dvb_device reference * * @dvbdev: pointer to struct dvb_device */
Greg Kroah-Hartman
maintainerPATCH 361/521 media: dvbdev: fix refcnt bug
In reply to Greg Kroah-HartmanFrom: Lin Ma <[email protected]>
commit 3a664569b71b0a52be5ffb9fb87cc4f83d29bd71 upstream.
Previous commit initialize the dvbdev->ref before the template copy, which will overwrite the reference and cause refcnt bug.
refcount_t: addition on 0; use-after-free.
WARNING: CPU: 0 PID: 1 at lib/refcount.c:25 refcount_warn_saturate+0x17c/0x1f0 lib/refcount.c:25 Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.1.0-rc6-next-20221128-syzkaller #0 ... RIP: 0010:refcount_warn_saturate+0x17c/0x1f0 lib/refcount.c:25 RSP: 0000:ffffc900000678d0 EFLAGS: 00010282 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: ffff88813ff58000 RSI: ffffffff81660e7c RDI: fffff5200000cf0c RBP: ffff888022a45010 R08: 0000000000000005 R09: 0000000000000000 R10: 0000000080000000 R11: 0000000000000000 R12: 0000000000000001 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000001 FS: 0000000000000000(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff88823ffff000 CR3: 000000000c48e000 CR4: 00000000003506f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> __refcount_add include/linux/refcount.h:199 [inline] __refcount_inc include/linux/refcount.h:250 [inline] refcount_inc include/linux/refcount.h:267 [inline] kref_get include/linux/kref.h:45 [inline] dvb_device_get drivers/media/dvb-core/dvbdev.c:585 [inline] dvb_register_device+0xe83/0x16e0 drivers/media/dvb-core/dvbdev.c:517
...
Just place the kref_init at correct position.
--- drivers/media/dvb-core/dvbdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-core/dvbdev.c +1 -1
@@ -490,8 +490,8 @@ int dvb_register_device(struct dvb_adaptreturn -ENOMEM ; } -kref_init (&dvbdev->ref);memcpy (dvbdev, template,sizeof (struct dvb_device )); +kref_init (&dvbdev->ref); dvbdev->type = type; dvbdev->id = id; dvbdev->adapter = adap;
Greg Kroah-Hartman
maintainerPATCH 362/521 ata: ahci: Fix PCS quirk application for suspend
In reply to Greg Kroah-HartmanFrom: Adam Vodopjan <[email protected]>
[ Upstream commit 37e14e4f3715428b809e4df9a9958baa64c77d51 ]
Since kernel 5.3.4 my laptop (ICH8M controller) does not see Kingston SV300S37A60G SSD disk connected into a SATA connector on wake from suspend. The problem was introduced in c312ef176399 ("libata/ahci: Drop PCS quirk for Denverton and beyond"): the quirk is not applied on wake from suspend as it originally was.
It is worth to mention the commit contained another bug: the quirk is not applied at all to controllers which require it. The fix commit 09d6ac8dc51a ("libata/ahci: Fix PCS quirk application") landed in 5.3.8. So testing my patch anywhere between commits c312ef176399 and 09d6ac8dc51a is pointless.
Not all disks trigger the problem. For example nothing bad happens with Western Digital WD5000LPCX HDD.
Test hardware:
- Acer 5920G with ICH8M SATA controller
- sda: some SATA HDD connnected into the DVD drive IDE port with a SATA-IDE caddy. It is a boot disk
- sdb: Kingston SV300S37A60G SSD connected into the only SATA port
Sample "dmesg --notime | grep -E '^(sd |ata)'" output on wake:
sd 0:0:0:0: [sda] Starting disk
sd 2:0:0:0: [sdb] Starting disk
ata4: SATA link down (SStatus 4 SControl 300)
ata3: SATA link down (SStatus 4 SControl 300)
ata1.00: ACPI cmd ef/03:0c:00:00:00:a0 (SET FEATURES) filtered out ata1.00: ACPI cmd ef/03:42:00:00:00:a0 (SET FEATURES) filtered out
ata1: FORCE: cable set to 80c
ata5: SATA link down (SStatus 0 SControl 300)
ata3: SATA link down (SStatus 4 SControl 300)
ata3: SATA link down (SStatus 4 SControl 300)
ata3.00: disabled
sd 2:0:0:0: rejecting I/O to offline device
ata3.00: detaching (SCSI 2:0:0:0)
sd 2:0:0:0: [sdb] Start/Stop Unit failed: Result: hostbyte=DID_NO_CONNECT
driverbyte=DRIVER_OK
sd 2:0:0:0: [sdb] Synchronizing SCSI cache
sd 2:0:0:0: [sdb] Synchronize Cache(10) failed: Result:
hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
sd 2:0:0:0: [sdb] Stopping disk
sd 2:0:0:0: [sdb] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET
driverbyte=DRIVER_OK
Commit c312ef176399 dropped ahci_pci_reset_controller() which internally calls ahci_reset_controller() and applies the PCS quirk if needed after that. It was called each time a reset was required instead of just ahci_reset_controller(). This patch puts the function back in place.
--- drivers/ata/ahci.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)
drivers/ata/ahci.c +23 -9
@@ -97,6 +97,7 @@ enum board_ids {static int ahci_init_one (struct pci_dev *pdev,const struct pci_device_id *ent);static void ahci_remove_one (struct pci_dev *dev);static void ahci_shutdown_one (struct pci_dev *dev); +static void ahci_intel_pcs_quirk (struct pci_dev *pdev,struct ahci_host_priv *hpriv);static int ahci_vt8251_hardreset (struct ata_link *link,unsigned int *class,unsigned long deadline); static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
@@ -655,6 +656,25 @@ static void ahci_pci_save_initial_config(struct pci_dev *pdev,ahci_save_initial_config (&pdev->dev, hpriv); } +static int ahci_pci_reset_controller (struct ata_host *host) +{ +struct pci_dev *pdev =to_pci_dev (host->dev); +struct ahci_host_priv *hpriv = host->private_data; +int rc; + + rc =ahci_reset_controller (host); +if (rc) +return rc; + +/* +* If platform firmware failed to enable ports, try to enable +* them here. +*/ +ahci_intel_pcs_quirk (pdev, hpriv); + +return 0 ; +} +static void ahci_pci_init_controller (struct ata_host *host) {struct ahci_host_priv *hpriv = host->private_data;
@@ -857,7 +877,7 @@ static int ahci_pci_device_runtime_resume(struct device *dev)struct ata_host *host =pci_get_drvdata (pdev);int rc; - rc =ahci_reset_controller (host); + rc =ahci_pci_reset_controller (host);if (rc)return rc;ahci_pci_init_controller (host);
@@ -892,7 +912,7 @@ static int ahci_pci_device_resume(struct device *dev)ahci_mcp89_apple_enable (pdev);if (pdev->dev.power.power_state.event ==PM_EVENT_SUSPEND ) { - rc =ahci_reset_controller (host); + rc =ahci_pci_reset_controller (host);if (rc)return rc;
@@ -1769,12 +1789,6 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)/* save initial config */ ahci_pci_save_initial_config (pdev, hpriv); -/* -* If platform firmware failed to enable ports, try to enable -* them here. -*/ -ahci_intel_pcs_quirk (pdev, hpriv); -/* prepare host */ if (hpriv->cap &HOST_CAP_NCQ ) { pi.flags |=ATA_FLAG_NCQ ;
@@ -1884,7 +1898,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)if (rc)return rc; - rc =ahci_reset_controller (host); + rc =ahci_pci_reset_controller (host);if (rc)return rc;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 363/521 powerpc/rtas: avoid device tree lookups in rtas_os_term()
In reply to Greg Kroah-HartmanFrom: Nathan Lynch <[email protected]>
[ Upstream commit ed2213bfb192ab51f09f12e9b49b5d482c6493f3 ]
rtas_os_term() is called during panic. Its behavior depends on a couple of conditions in the /rtas node of the device tree, the traversal of which entails locking and local IRQ state changes. If the kernel panics while devtree_lock is held, rtas_os_term() as currently written could hang.
Instead of discovering the relevant characteristics at panic time, cache them in file-static variables at boot. Note the lookup for "ibm,extended-os-term" is converted to of_property_read_bool() since it is a boolean property, not an RTAS function token.
--- arch/powerpc/kernel/rtas.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
arch/powerpc/kernel/rtas.c +10 -3
@@ -717,6 +717,7 @@ void __noreturn rtas_halt(void)/* Must be in the RMO region, so we place it here */ static char rtas_os_term_buf[2048 ]; +static s32 ibm_os_term_token =RTAS_UNKNOWN_SERVICE ;void rtas_os_term (char *str) {
@@ -728,14 +729,13 @@ void rtas_os_term(char *str)* this property may terminate the partition which we want to avoid * since it interferes with panic_timeout. */ -if (RTAS_UNKNOWN_SERVICE ==rtas_token ("ibm,os-term" ) || -RTAS_UNKNOWN_SERVICE ==rtas_token ("ibm,extended-os-term" )) +if (ibm_os_term_token ==RTAS_UNKNOWN_SERVICE )return ;snprintf (rtas_os_term_buf,2048 ,"OS panic: %s" , str);do { - status =rtas_call (rtas_token ("ibm,os-term" ),1 ,1 ,NULL , + status =rtas_call (ibm_os_term_token,1 ,1 ,NULL ,__pa (rtas_os_term_buf)); }while (rtas_busy_delay (status));
@@ -1332,6 +1332,13 @@ void __init rtas_initialize(void) no_entry =of_property_read_u32 (rtas.dev,"linux,rtas-entry" , &entry); rtas.entry = no_entry ? rtas.base : entry; +/* +* Discover these now to avoid device tree lookups in the +* panic path. +*/ +if (of_property_read_bool (rtas.dev,"ibm,extended-os-term" )) + ibm_os_term_token =rtas_token ("ibm,os-term" ); +/* If RTAS was found, allocate the RMO buffer for it and look for * the stop-self token if any */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 364/521 powerpc/rtas: avoid scheduling in rtas_os_term()
In reply to Greg Kroah-HartmanFrom: Nathan Lynch <[email protected]>
[ Upstream commit 6c606e57eecc37d6b36d732b1ff7e55b7dc32dd4 ]
It's unsafe to use rtas_busy_delay() to handle a busy status from the ibm,os-term RTAS function in rtas_os_term():
Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b BUG: sleeping function called from invalid context at arch/powerpc/kernel/rtas.c:618 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: swapper/0 preempt_count: 2, expected: 0 CPU: 7 PID: 1 Comm: swapper/0 Tainted: G D 6.0.0-rc5-02182-gf8553a572277-dirty #9 Call Trace: [c000000007b8f000] [c000000001337110] dump_stack_lvl+0xb4/0x110 (unreliable) [c000000007b8f040] [c0000000002440e4] __might_resched+0x394/0x3c0 [c000000007b8f0e0] [c00000000004f680] rtas_busy_delay+0x120/0x1b0 [c000000007b8f100] [c000000000052d04] rtas_os_term+0xb8/0xf4 [c000000007b8f180] [c0000000001150fc] pseries_panic+0x50/0x68 [c000000007b8f1f0] [c000000000036354] ppc_panic_platform_handler+0x34/0x50 [c000000007b8f210] [c0000000002303c4] notifier_call_chain+0xd4/0x1c0 [c000000007b8f2b0] [c0000000002306cc] atomic_notifier_call_chain+0xac/0x1c0 [c000000007b8f2f0] [c0000000001d62b8] panic+0x228/0x4d0 [c000000007b8f390] [c0000000001e573c] do_exit+0x140c/0x1420 [c000000007b8f480] [c0000000001e586c] make_task_dead+0xdc/0x200
Use rtas_busy_delay_time() instead, which signals without side effects whether to attempt the ibm,os-term RTAS call again.
--- arch/powerpc/kernel/rtas.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/kernel/rtas.c +6 -1
@@ -734,10 +734,15 @@ void rtas_os_term(char *str)snprintf (rtas_os_term_buf,2048 ,"OS panic: %s" , str); +/* +* Keep calling as long as RTAS returns a "try again" status, +* but don't use rtas_busy_delay(), which potentially +* schedules. +*/ do { status =rtas_call (ibm_os_term_token,1 ,1 ,NULL ,__pa (rtas_os_term_buf)); - }while (rtas_busy_delay (status)); + }while (rtas_busy_delay_time (status));if (status !=0 )printk (KERN_EMERG "ibm,os-term call failed %d\n" , status);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 365/521 HID: plantronics: Additional PIDs for double volume key presses quirk
In reply to Greg Kroah-HartmanFrom: Terry Junge <[email protected]>
[ Upstream commit 3d57f36c89d8ba32b2c312f397a37fd1a2dc7cfc ]
I no longer work for Plantronics (aka Poly, aka HP) and do not have access to the headsets in order to test. However, as noted by Maxim, the other 32xx models that share the same base code set as the 3220 would need the same quirk. This patch adds the PIDs for the rest of the Blackwire 32XX product family that require the quirk.
Plantronics Blackwire 3210 Series (047f:c055)
Plantronics Blackwire 3215 Series (047f:c057)
Plantronics Blackwire 3225 Series (047f:c058)
Quote from previous patch by Maxim Mikityanskiy Plantronics Blackwire 3220 Series (047f:c056) sends HID reports twice for each volume key press. This patch adds a quirk to hid-plantronics for this product ID, which will ignore the second volume key press if it happens within 5 ms from the last one that was handled.
The patch was tested on the mentioned model only, it shouldn't affect other models, however, this quirk might be needed for them too. Auto-repeat (when a key is held pressed) is not affected, because the rate is about 3 times per second, which is far less frequent than once in 5 ms.
End quote
--- drivers/hid/hid-ids.h | 3 +++ drivers/hid/hid-plantronics.c | 9 +++++++++ 2 files changed, 12 insertions(+)
drivers/hid/hid-ids.h +3 -0
@@ -908,7 +908,10 @@#define USB_DEVICE_ID_ORTEK_IHOME_IMAC_A210S 0x8003#define USB_VENDOR_ID_PLANTRONICS 0x047f +#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3210_SERIES 0xc055#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3220_SERIES 0xc056 +#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3215_SERIES 0xc057 +#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3225_SERIES 0xc058#define USB_VENDOR_ID_PANASONIC 0x04da#define USB_DEVICE_ID_PANABOARD_UBT780 0x1044
drivers/hid/hid-plantronics.c +9 -0
@@ -201,9 +201,18 @@ static int plantronics_probe(struct hid_device *hdev, }static const struct hid_device_id plantronics_devices[] = { + {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS , +USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3210_SERIES ), + .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS ,USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3220_SERIES ), .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, + {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS , +USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3215_SERIES ), + .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, + {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS , +USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3225_SERIES ), + .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS ,HID_ANY_ID ) }, { } };
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 366/521 hfsplus: fix bug causing custom uid and gid being unable to be assigned with mount
In reply to Greg Kroah-HartmanFrom: Aditya Garg <[email protected]>
commit 9f2b5debc07073e6dfdd774e3594d0224b991927 upstream.
Despite specifying UID and GID in mount command, the specified UID and GID were not being assigned. This patch fixes this issue.
--- fs/hfsplus/hfsplus_fs.h | 2 ++ fs/hfsplus/inode.c | 4 ++-- fs/hfsplus/options.c | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-)
fs/hfsplus/hfsplus_fs.h +2 -0
@@ -198,6 +198,8 @@ struct hfsplus_sb_info {#define HFSPLUS_SB_HFSX 3#define HFSPLUS_SB_CASEFOLD 4#define HFSPLUS_SB_NOBARRIER 5 +#define HFSPLUS_SB_UID 6 +#define HFSPLUS_SB_GID 7static inline struct hfsplus_sb_info *HFSPLUS_SB (struct super_block *sb) {
fs/hfsplus/inode.c +2 -2
@@ -187,11 +187,11 @@ static void hfsplus_get_perms(struct ino mode =be16_to_cpu (perms->mode);i_uid_write (inode,be32_to_cpu (perms->owner)); -if (!i_uid_read (inode) && !mode) +if ((test_bit (HFSPLUS_SB_UID , &sbi->flags)) || (!i_uid_read (inode) && !mode)) inode->i_uid = sbi->uid;i_gid_write (inode,be32_to_cpu (perms->group)); -if (!i_gid_read (inode) && !mode) +if ((test_bit (HFSPLUS_SB_GID , &sbi->flags)) || (!i_gid_read (inode) && !mode)) inode->i_gid = sbi->gid;if (dir) {
fs/hfsplus/options.c +4 -0
@@ -140,6 +140,8 @@ int hfsplus_parse_options(char *input, sif (!uid_valid (sbi->uid)) {pr_err ("invalid uid specified\n" );return 0 ; + }else { +set_bit (HFSPLUS_SB_UID , &sbi->flags); }break ;case opt_gid:
@@ -151,6 +153,8 @@ int hfsplus_parse_options(char *input, sif (!gid_valid (sbi->gid)) {pr_err ("invalid gid specified\n" );return 0 ; + }else { +set_bit (HFSPLUS_SB_GID , &sbi->flags); }break ;case opt_part:
Greg Kroah-Hartman
maintainerPATCH 367/521 ovl: Use ovl mounters fsuid and fsgid in ovl_link()
In reply to Greg Kroah-HartmanFrom: Zhang Tianci <[email protected]>
commit 5b0db51215e895a361bc63132caa7cca36a53d6a upstream.
There is a wrong case of link() on overlay:
$ mkdir /lower /fuse /merge
$ mount -t fuse /fuse
$ mkdir /fuse/upper /fuse/work
$ mount -t overlay /merge -o lowerdir=/lower,upperdir=/fuse/upper,\
workdir=work
$ touch /merge/file
$ chown bin.bin /merge/file // the file's caller becomes "bin"
$ ln /merge/file /merge/lnkfileThen we will get an error(EACCES) because fuse daemon checks the link()'s caller is "bin", it denied this request.
In the changing history of ovl_link(), there are two key commits:
The first is commit bb0d2b8ad296 ("ovl: fix sgid on directory") which overrides the cred's fsuid/fsgid using the new inode. The new inode's owner is initialized by inode_init_owner(), and inode->fsuid is assigned to the current user. So the override fsuid becomes the current user. We know link() is actually modifying the directory, so the caller must have the MAY_WRITE permission on the directory. The current caller may should have this permission. This is acceptable to use the caller's fsuid.
The second is commit 51f7e52dc943 ("ovl: share inode for hard link") which removed the inode creation in ovl_link(). This commit move inode_init_owner() into ovl_create_object(), so the ovl_link() just give the old inode to ovl_create_or_link(). Then the override fsuid becomes the old inode's fsuid, neither the caller nor the overlay's mounter! So this is incorrect.
Fix this bug by using ovl mounter's fsuid/fsgid to do underlying fs's link().
--- fs/overlayfs/dir.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-)
fs/overlayfs/dir.c +30 -16
@@ -561,28 +561,42 @@ static int ovl_create_or_link(struct den goto out_revert_creds; } - err = -ENOMEM ; - override_cred =prepare_creds (); -if (override_cred) { +if (!attr->hardlink) { + err = -ENOMEM ; + override_cred =prepare_creds (); +if (!override_cred) + goto out_revert_creds; +/* +* In the creation cases(create, mkdir, mknod, symlink), +* ovl should transfer current's fs{u,g}id to underlying +* fs. Because underlying fs want to initialize its new +* inode owner using current's fs{u,g}id. And in this +* case, the @inode is a new inode that is initialized +* in inode_init_owner() to current's fs{u,g}id. So use +* the inode's i_{u,g}id to override the cred's fs{u,g}id. +* +* But in the other hardlink case, ovl_link() does not +* create a new inode, so just use the ovl mounter's +* fs{u,g}id. +*/ override_cred->fsuid = inode->i_uid; override_cred->fsgid = inode->i_gid; -if (!attr->hardlink) { - err =security_dentry_create_files_as (dentry, - attr->mode, &dentry->d_name, old_cred, - override_cred); -if (err) { -put_cred (override_cred); - goto out_revert_creds; - } + err =security_dentry_create_files_as (dentry, + attr->mode, &dentry->d_name, old_cred, + override_cred); +if (err) { +put_cred (override_cred); + goto out_revert_creds; }put_cred (override_creds (override_cred));put_cred (override_cred); - -if (!ovl_dentry_is_whiteout (dentry)) - err =ovl_create_upper (dentry, inode, attr); -else - err =ovl_create_over_whiteout (dentry, inode, attr); } + +if (!ovl_dentry_is_whiteout (dentry)) + err =ovl_create_upper (dentry, inode, attr); +else + err =ovl_create_over_whiteout (dentry, inode, attr); + out_revert_creds:revert_creds (old_cred);return err;
Greg Kroah-Hartman
maintainerPATCH 368/521 ALSA: line6: correct midi status byte when receiving data from podxt
In reply to Greg Kroah-HartmanFrom: Artem Egorkine <[email protected]>
commit 8508fa2e7472f673edbeedf1b1d2b7a6bb898ecc upstream.
A PODxt device sends 0xb2, 0xc2 or 0xf2 as a status byte for MIDI messages over USB that should otherwise have a 0xb0, 0xc0 or 0xf0 status byte. This is usually corrected by the driver on other OSes.
This fixes MIDI sysex messages sent by PODxt.
[ tiwai: fixed white spaces ]
--- sound/usb/line6/driver.c | 3 ++- sound/usb/line6/midi.c | 3 ++- sound/usb/line6/midibuf.c | 25 +++++++++++++++++-------- sound/usb/line6/midibuf.h | 5 ++++- sound/usb/line6/pod.c | 3 ++- 5 files changed, 27 insertions(+), 12 deletions(-)
sound/usb/line6/driver.c +2 -1
@@ -318,7 +318,8 @@ static void line6_data_received(struct ufor (;;) { done =line6_midibuf_read (mb, line6->buffer_message, -LINE6_MIDI_MESSAGE_MAXLEN ); +LINE6_MIDI_MESSAGE_MAXLEN , +LINE6_MIDIBUF_READ_RX );if (done <=0 )break ;
sound/usb/line6/midi.c +2 -1
@@ -60,7 +60,8 @@ static void line6_midi_transmit(struct sfor (;;) { done =line6_midibuf_read (mb, chunk, -LINE6_FALLBACK_MAXPACKETSIZE ); +LINE6_FALLBACK_MAXPACKETSIZE , +LINE6_MIDIBUF_READ_TX );if (done ==0 )break ;
sound/usb/line6/midibuf.c +17 -8
@@ -13,6 +13,7 @@#include "midibuf.h" +static int midibuf_message_length (unsigned char code) {int message_length;
@@ -24,12 +25,7 @@ static int midibuf_message_length(unsign message_length = length[(code >>4 ) -8 ]; }else { -/* -Note that according to the MIDI specification 0xf2 is -the "Song Position Pointer", but this is used by Line 6 -to send sysex messages to the host. -*/ -static const int length[] = {-1 ,2 ,-1 ,2 ,-1 ,-1 ,1 ,1 ,1 ,1 , +static const int length[] = {-1 ,2 ,2 ,2 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 }; message_length = length[code &0x0f ];
@@ -129,7 +125,7 @@ int line6_midibuf_write(struct midi_buff }int line6_midibuf_read (struct midi_buffer *this,unsigned char *data, -int length) +int length,int read_type) {int bytes_used;int length1, length2;
@@ -152,9 +148,22 @@ int line6_midibuf_read(struct midi_buffe length1 = this->size - this->pos_read; -/* check MIDI command length */ command = this->buf[this->pos_read]; +/* +PODxt always has status byte lower nibble set to 0010, +when it means to send 0000, so we correct if here so +that control/program changes come on channel 1 and +sysex message status byte is correct +*/ +if (read_type ==LINE6_MIDIBUF_READ_RX ) { +if (command ==0xb2 || command ==0xc2 || command ==0xf2 ) { +unsigned char fixed = command &0xf0 ; + this->buf[this->pos_read] = fixed; + command = fixed; + } + } +/* check MIDI command length */ if (command &0x80 ) { midi_length =midibuf_message_length (command); this->command_prev = command;
sound/usb/line6/midibuf.h +4 -1
@@ -12,6 +12,9 @@ #ifndef MIDIBUF_H #define MIDIBUF_H +#define LINE6_MIDIBUF_READ_TX 0 +#define LINE6_MIDIBUF_READ_RX 1 + struct midi_buffer { unsigned char *buf; int size;
@@ -27,7 +30,7 @@ extern void line6_midibuf_destroy(structextern int line6_midibuf_ignore (struct midi_buffer *mb,int length);extern int line6_midibuf_init (struct midi_buffer *mb,int size,int split);extern int line6_midibuf_read (struct midi_buffer *mb,unsigned char *data, -int length); +int length,int read_type);extern void line6_midibuf_reset (struct midi_buffer *mb);extern int line6_midibuf_write (struct midi_buffer *mb,unsigned char *data,int length);
sound/usb/line6/pod.c +2 -1
@@ -169,8 +169,9 @@ static struct line6_pcm_properties pod_p .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */ }; +static const char pod_version_header[] = { -0xf2 ,0x7e ,0x7f ,0x06 ,0x02 +0xf0 ,0x7e ,0x7f ,0x06 ,0x02 };/* forward declarations: */
Greg Kroah-Hartman
maintainerPATCH 369/521 ALSA: line6: fix stack overflow in line6_midi_transmit
In reply to Greg Kroah-HartmanFrom: Artem Egorkine <[email protected]>
commit b8800d324abb50160560c636bfafe2c81001b66c upstream.
Correctly calculate available space including the size of the chunk buffer. This fixes a buffer overflow when multiple MIDI sysex messages are sent to a PODxt device.
--- sound/usb/line6/midi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/usb/line6/midi.c +2 -1
@@ -48,7 +48,8 @@ static void line6_midi_transmit(struct sint req, done;for (;;) { - req =min (line6_midibuf_bytes_free (mb), line6->max_packet_size); + req =min3 (line6_midibuf_bytes_free (mb), line6->max_packet_size, +LINE6_FALLBACK_MAXPACKETSIZE ); done =snd_rawmidi_transmit_peek (substream, chunk, req);if (done ==0 )
Greg Kroah-Hartman
maintainerPATCH 370/521 pnode: terminate at peers of source
In reply to Greg Kroah-HartmanFrom: Christian Brauner <[email protected]>
commit 11933cf1d91d57da9e5c53822a540bbdc2656c16 upstream.
The propagate_mnt() function handles mount propagation when creating mounts and propagates the source mount tree @source_mnt to all applicable nodes of the destination propagation mount tree headed by @dest_mnt.
Unfortunately it contains a bug where it fails to terminate at peers of @source_mnt when looking up copies of the source mount that become masters for copies of the source mount tree mounted on top of slaves in the destination propagation tree causing a NULL dereference.
Once the mechanics of the bug are understood it's easy to trigger. Because of unprivileged user namespaces it is available to unprivileged users.
While fixing this bug we've gotten confused multiple times due to unclear terminology or missing concepts. So let's start this with some clarifications:
* The terms "master" or "peer" denote a shared mount. A shared mount belongs to a peer group.
* A peer group is a set of shared mounts that propagate to each other. They are identified by a peer group id. The peer group id is available in @shared_mnt->mnt_group_id.
Shared mounts within the same peer group have the same peer group id. The peers in a peer group can be reached via @shared_mnt->mnt_share.
* The terms "slave mount" or "dependent mount" denote a mount that receives propagation from a peer in a peer group. IOW, shared mounts may have slave mounts and slave mounts have shared mounts as their master. Slave mounts of a given peer in a peer group are listed on that peers slave list available at @shared_mnt->mnt_slave_list.
* The term "master mount" denotes a mount in a peer group. IOW, it denotes a shared mount or a peer mount in a peer group. The term "master mount" - or "master" for short - is mostly used when talking in the context of slave mounts that receive propagation from a master mount. A master mount of a slave identifies the closest peer group a slave mount receives propagation from. The master mount of a slave can be identified via @slave_mount->mnt_master. Different slaves may point to different masters in the same peer group.
* Multiple peers in a peer group can have non-empty ->mnt_slave_lists. Non-empty ->mnt_slave_lists of peers don't intersect. Consequently, to ensure all slave mounts of a peer group are visited the ->mnt_slave_lists of all peers in a peer group have to be walked.
* Slave mounts point to a peer in the closest peer group they receive propagation from via @slave_mnt->mnt_master (see above). Together with these peers they form a propagation group (see below). The closest peer group can thus be identified through the peer group id @slave_mnt->mnt_master->mnt_group_id of the peer/master that a slave mount receives propagation from.
* A shared-slave mount is a slave mount to a peer group pg1 while also a peer in another peer group pg2. IOW, a peer group may receive propagation from another peer group.
If a peer group pg1 is a slave to another peer group pg2 then all peers in peer group pg1 point to the same peer in peer group pg2 via ->mnt_master. IOW, all peers in peer group pg1 appear on the same ->mnt_slave_list. IOW, they cannot be slaves to different peer groups.
* A pure slave mount is a slave mount that is a slave to a peer group but is not a peer in another peer group.
* A propagation group denotes the set of mounts consisting of a single peer group pg1 and all slave mounts and shared-slave mounts that point to a peer in that peer group via ->mnt_master. IOW, all slave mounts such that @slave_mnt->mnt_master->mnt_group_id is equal to @shared_mnt->mnt_group_id.
The concept of a propagation group makes it easier to talk about a single propagation level in a propagation tree.
For example, in propagate_mnt() the immediate peers of @dest_mnt and all slaves of @dest_mnt's peer group form a propagation group propg1. So a shared-slave mount that is a slave in propg1 and that is a peer in another peer group pg2 forms another propagation group propg2 together with all slaves that point to that shared-slave mount in their ->mnt_master.
* A propagation tree refers to all mounts that receive propagation starting from a specific shared mount.
For example, for propagate_mnt() @dest_mnt is the start of a propagation tree. The propagation tree ecompasses all mounts that receive propagation from @dest_mnt's peer group down to the leafs.
With that out of the way let's get to the actual algorithm.
We know that @dest_mnt is guaranteed to be a pure shared mount or a shared-slave mount. This is guaranteed by a check in attach_recursive_mnt(). So propagate_mnt() will first propagate the source mount tree to all peers in @dest_mnt's peer group:
for (n = next_peer(dest_mnt); n != dest_mnt; n = next_peer(n)) {
ret = propagate_one(n);
if (ret)
goto out;
}Notice, that the peer propagation loop of propagate_mnt() doesn't propagate @dest_mnt itself. @dest_mnt is mounted directly in attach_recursive_mnt() after we propagated to the destination propagation tree.
The mount that will be mounted on top of @dest_mnt is @source_mnt. This copy was created earlier even before we entered attach_recursive_mnt() and doesn't concern us a lot here.
It's just important to notice that when propagate_mnt() is called @source_mnt will not yet have been mounted on top of @dest_mnt. Thus, @source_mnt->mnt_parent will either still point to @source_mnt or - in the case @source_mnt is moved and thus already attached - still to its former parent.
For each peer @m in @dest_mnt's peer group propagate_one() will create a new copy of the source mount tree and mount that copy @child on @m such that @child->mnt_parent points to @m after propagate_one() returns.
propagate_one() will stash the last destination propagation node @m in @last_dest and the last copy it created for the source mount tree in @last_source.
Hence, if we call into propagate_one() again for the next destination propagation node @m, @last_dest will point to the previous destination propagation node and @last_source will point to the previous copy of the source mount tree and mounted on @last_dest.
Each new copy of the source mount tree is created from the previous copy of the source mount tree. This will become important later.
The peer loop in propagate_mnt() is straightforward. We iterate through the peers copying and updating @last_source and @last_dest as we go through them and mount each copy of the source mount tree @child on a peer @m in @dest_mnt's peer group.
After propagate_mnt() handled the peers in @dest_mnt's peer group propagate_mnt() will propagate the source mount tree down the propagation tree that @dest_mnt's peer group propagates to:
for (m = next_group(dest_mnt, dest_mnt); m;
m = next_group(m, dest_mnt)) {
/* everything in that slave group */
n = m;
do {
ret = propagate_one(n);
if (ret)
goto out;
n = next_peer(n);
} while (n != m);
}The next_group() helper will recursively walk the destination propagation tree, descending into each propagation group of the propagation tree.
The important part is that it takes care to propagate the source mount tree to all peers in the peer group of a propagation group before it propagates to the slaves to those peers in the propagation group. IOW, it creates and mounts copies of the source mount tree that become masters before it creates and mounts copies of the source mount tree that become slaves to these masters.
It is important to remember that propagating the source mount tree to each mount @m in the destination propagation tree simply means that we create and mount new copies @child of the source mount tree on @m such that @child->mnt_parent points to @m.
Since we know that each node @m in the destination propagation tree headed by @dest_mnt's peer group will be overmounted with a copy of the source mount tree and since we know that the propagation properties of each copy of the source mount tree we create and mount at @m will mostly mirror the propagation properties of @m. We can use that information to create and mount the copies of the source mount tree that become masters before their slaves.
The easy case is always when @m and @last_dest are peers in a peer group of a given propagation group. In that case we know that we can simply copy @last_source without having to figure out what the master for the new copy @child of the source mount tree needs to be as we've done that in a previous call to propagate_one().
The hard case is when we're dealing with a slave mount or a shared-slave mount @m in a destination propagation group that we need to create and mount a copy of the source mount tree on.
For each propagation group in the destination propagation tree we propagate the source mount tree to we want to make sure that the copies @child of the source mount tree we create and mount on slaves @m pick an ealier copy of the source mount tree that we mounted on a master @m of the destination propagation group as their master. This is a mouthful but as far as we can tell that's the core of it all.
But, if we keep track of the masters in the destination propagation tree @m we can use the information to find the correct master for each copy of the source mount tree we create and mount at the slaves in the destination propagation tree @m.
Let's walk through the base case as that's still fairly easy to grasp.
If we're dealing with the first slave in the propagation group that @dest_mnt is in then we don't yet have marked any masters in the destination propagation tree.
We know the master for the first slave to @dest_mnt's peer group is simple @dest_mnt. So we expect this algorithm to yield a copy of the source mount tree that was mounted on a peer in @dest_mnt's peer group as the master for the copy of the source mount tree we want to mount at the first slave @m:
for (n = m; ; n = p) {
p = n->mnt_master;
if (p == dest_master || IS_MNT_MARKED(p))
break;
}For the first slave we walk the destination propagation tree all the way up to a peer in @dest_mnt's peer group. IOW, the propagation hierarchy can be walked by walking up the @mnt->mnt_master hierarchy of the destination propagation tree @m. We will ultimately find a peer in @dest_mnt's peer group and thus ultimately @dest_mnt->mnt_master.
Btw, here the assumption we listed at the beginning becomes important. Namely, that peers in a peer group pg1 that are slaves in another peer group pg2 appear on the same ->mnt_slave_list. IOW, all slaves who are peers in peer group pg1 point to the same peer in peer group pg2 via their ->mnt_master. Otherwise the termination condition in the code above would be wrong and next_group() would be broken too.
So the first iteration sets:
n = m;
p = n->mnt_master;
such that @p now points to a peer or @dest_mnt itself. We walk up one more level since we don't have any marked mounts. So we end up with:
n = dest_mnt;
p = dest_mnt->mnt_master;
If @dest_mnt's peer group is not slave to another peer group then @p is now NULL. If @dest_mnt's peer group is a slave to another peer group then @p now points to @dest_mnt->mnt_master points which is a master outside the propagation tree we're dealing with.
Now we need to figure out the master for the copy of the source mount tree we're about to create and mount on the first slave of @dest_mnt's peer group:
do {
struct mount *parent = last_source->mnt_parent;
if (last_source == first_source)
break;
done = parent->mnt_master == p;
if (done && peers(n, parent))
break;
last_source = last_source->mnt_master;
} while (!done);We know that @last_source->mnt_parent points to @last_dest and @last_dest is the last peer in @dest_mnt's peer group we propagated to in the peer loop in propagate_mnt().
Consequently, @last_source is the last copy we created and mount on that last peer in @dest_mnt's peer group. So @last_source is the master we want to pick.
We know that @last_source->mnt_parent->mnt_master points to @last_dest->mnt_master. We also know that @last_dest->mnt_master is either NULL or points to a master outside of the destination propagation tree and so does @p. Hence:
done = parent->mnt_master == p;
is trivially true in the base condition.
We also know that for the first slave mount of @dest_mnt's peer group that @last_dest either points @dest_mnt itself because it was initialized to:
last_dest = dest_mnt;
at the beginning of propagate_mnt() or it will point to a peer of @dest_mnt in its peer group. In both cases it is guaranteed that on the first iteration @n and @parent are peers (Please note the check for peers here as that's important.):
if (done && peers(n, parent))
break;
So, as we expected, we select @last_source, which referes to the last copy of the source mount tree we mounted on the last peer in @dest_mnt's peer group, as the master of the first slave in @dest_mnt's peer group. The rest is taken care of by clone_mnt(last_source, ...). We'll skip over that part otherwise this becomes a blogpost.
At the end of propagate_mnt() we now mark @m->mnt_master as the first master in the destination propagation tree that is distinct from @dest_mnt->mnt_master. IOW, we mark @dest_mnt itself as a master.
By marking @dest_mnt or one of it's peers we are able to easily find it again when we later lookup masters for other copies of the source mount tree we mount copies of the source mount tree on slaves @m to @dest_mnt's peer group. This, in turn allows us to find the master we selected for the copies of the source mount tree we mounted on master in the destination propagation tree again.
The important part is to realize that the code makes use of the fact that the last copy of the source mount tree stashed in @last_source was mounted on top of the previous destination propagation node @last_dest. What this means is that @last_source allows us to walk the destination propagation hierarchy the same way each destination propagation node @m does.
If we take @last_source, which is the copy of @source_mnt we have mounted on @last_dest in the previous iteration of propagate_one(), then we know @last_source->mnt_parent points to @last_dest but we also know that as we walk through the destination propagation tree that @last_source->mnt_master will point to an earlier copy of the source mount tree we mounted one an earlier destination propagation node @m.
IOW, @last_source->mnt_parent will be our hook into the destination propagation tree and each consecutive @last_source->mnt_master will lead us to an earlier propagation node @m via @last_source->mnt_master->mnt_parent.
Hence, by walking up @last_source->mnt_master, each of which is mounted on a node that is a master @m in the destination propagation tree we can also walk up the destination propagation hierarchy.
So, for each new destination propagation node @m we use the previous copy of @last_source and the fact it's mounted on the previous propagation node @last_dest via @last_source->mnt_master->mnt_parent to determine what the master of the new copy of @last_source needs to be.
The goal is to find the _closest_ master that the new copy of the source mount tree we are about to create and mount on a slave @m in the destination propagation tree needs to pick. IOW, we want to find a suitable master in the propagation group.
As the propagation structure of the source mount propagation tree we create mirrors the propagation structure of the destination propagation tree we can find @m's closest master - i.e., a marked master - which is a peer in the closest peer group that @m receives propagation from. We store that closest master of @m in @p as before and record the slave to that master in @n
We then search for this master @p via @last_source by walking up the master hierarchy starting from the last copy of the source mount tree stored in @last_source that we created and mounted on the previous destination propagation node @m.
We will try to find the master by walking @last_source->mnt_master and by comparing @last_source->mnt_master->mnt_parent->mnt_master to @p. If we find @p then we can figure out what earlier copy of the source mount tree needs to be the master for the new copy of the source mount tree we're about to create and mount at the current destination propagation node @m.
If @last_source->mnt_master->mnt_parent and @n are peers then we know that the closest master they receive propagation from is @last_source->mnt_master->mnt_parent->mnt_master. If not then the closest immediate peer group that they receive propagation from must be one level higher up.
This builds on the earlier clarification at the beginning that all peers in a peer group which are slaves of other peer groups all point to the same ->mnt_master, i.e., appear on the same ->mnt_slave_list, of the closest peer group that they receive propagation from.
However, terminating the walk has corner cases.
If the closest marked master for a given destination node @m cannot be found by walking up the master hierarchy via @last_source->mnt_master then we need to terminate the walk when we encounter @source_mnt again.
This isn't an arbitrary termination. It simply means that the new copy of the source mount tree we're about to create has a copy of the source mount tree we created and mounted on a peer in @dest_mnt's peer group as its master. IOW, @source_mnt is the peer in the closest peer group that the new copy of the source mount tree receives propagation from.
We absolutely have to stop @source_mnt because @last_source->mnt_master either points outside the propagation hierarchy we're dealing with or it is NULL because @source_mnt isn't a shared-slave.
So continuing the walk past @source_mnt would cause a NULL dereference via @last_source->mnt_master->mnt_parent. And so we have to stop the walk when we encounter @source_mnt again.
One scenario where this can happen is when we first handled a series of slaves of @dest_mnt's peer group and then encounter peers in a new peer group that is a slave to @dest_mnt's peer group. We handle them and then we encounter another slave mount to @dest_mnt that is a pure slave to @dest_mnt's peer group. That pure slave will have a peer in @dest_mnt's peer group as its master. Consequently, the new copy of the source mount tree will need to have @source_mnt as it's master. So we walk the propagation hierarchy all the way up to @source_mnt based on @last_source->mnt_master.
So terminate on @source_mnt, easy peasy. Except, that the check misses something that the rest of the algorithm already handles.
If @dest_mnt has peers in it's peer group the peer loop in propagate_mnt():
for (n = next_peer(dest_mnt); n != dest_mnt; n = next_peer(n)) {
ret = propagate_one(n);
if (ret)
goto out;
}will consecutively update @last_source with each previous copy of the source mount tree we created and mounted at the previous peer in @dest_mnt's peer group. So after that loop terminates @last_source will point to whatever copy of the source mount tree was created and mounted on the last peer in @dest_mnt's peer group.
Furthermore, if there is even a single additional peer in @dest_mnt's peer group then @last_source will __not__ point to @source_mnt anymore. Because, as we mentioned above, @dest_mnt isn't even handled in this loop but directly in attach_recursive_mnt(). So it can't even accidently come last in that peer loop.
So the first time we handle a slave mount @m of @dest_mnt's peer group the copy of the source mount tree we create will make the __last copy of the source mount tree we created and mounted on the last peer in @dest_mnt's peer group the master of the new copy of the source mount tree we create and mount on the first slave of @dest_mnt's peer group__.
But this means that the termination condition that checks for @source_mnt is wrong. The @source_mnt cannot be found anymore by propagate_one(). Instead it will find the last copy of the source mount tree we created and mounted for the last peer of @dest_mnt's peer group again. And that is a peer of @source_mnt not @source_mnt itself.
IOW, we fail to terminate the loop correctly and ultimately dereference @last_source->mnt_master->mnt_parent. When @source_mnt's peer group isn't slave to another peer group then @last_source->mnt_master is NULL causing the splat below.
For example, assume @dest_mnt is a pure shared mount and has three peers in its peer group:
===================================================================================
mount-id mount-parent-id peer-group-id
===================================================================================
(@dest_mnt) mnt_master[216] 309 297 shared:216
\
(@source_mnt) mnt_master[218]: 609 609 shared:218(1) mnt_master[216]: 607 605 shared:216
\
(P1) mnt_master[218]: 624 607 shared:218(2) mnt_master[216]: 576 574 shared:216
\
(P2) mnt_master[218]: 625 576 shared:218(3) mnt_master[216]: 545 543 shared:216
\
(P3) mnt_master[218]: 626 545 shared:218After this sequence has been processed @last_source will point to (P3), the copy generated for the third peer in @dest_mnt's peer group we handled. So the copy of the source mount tree (P4) we create and mount on the first slave of @dest_mnt's peer group:
===================================================================================
mount-id mount-parent-id peer-group-id
===================================================================================
mnt_master[216] 309 297 shared:216
/
/
(S0) mnt_slave 483 481 master:216
\
\ (P3) mnt_master[218] 626 545 shared:218
\ /
\/
(P4) mnt_slave 627 483 master:218will pick the last copy of the source mount tree (P3) as master, not (S0).
When walking the propagation hierarchy via @last_source's master hierarchy we encounter (P3) but not (S0), i.e., @source_mnt.
We can fix this in multiple ways:
(1) By setting @last_source to @source_mnt after we processed the peers in @dest_mnt's peer group right after the peer loop in propagate_mnt().
(2) By changing the termination condition that relies on finding exactly @source_mnt to finding a peer of @source_mnt.
(3) By only moving @last_source when we actually venture into a new peer group or some clever variant thereof.
The first two options are minimally invasive and what we want as a fix. The third option is more intrusive but something we'd like to explore in the near future.
This passes all LTP tests and specifically the mount propagation testsuite part of it. It also holds up against all known reproducers of this issues.
Final words.
First, this is a clever but __worringly__ underdocumented algorithm. There isn't a single detailed comment to be found in next_group(), propagate_one() or anywhere else in that file for that matter. This has been a giant pain to understand and work through and a bug like this is insanely difficult to fix without a detailed understanding of what's happening. Let's not talk about the amount of time that was sunk into fixing this.
Second, all the cool kids with access to
unshare --mount --user --map-root --propagation=unchanged are going to have a lot of fun. IOW, triggerable by unprivileged users while namespace_lock() lock is held.
[ 115.848393] BUG: kernel NULL pointer dereference, address: 0000000000000010 [ 115.848967] #PF: supervisor read access in kernel mode [ 115.849386] #PF: error_code(0x0000) - not-present page [ 115.849803] PGD 0 P4D 0 [ 115.850012] Oops: 0000 [#1] PREEMPT SMP PTI [ 115.850354] CPU: 0 PID: 15591 Comm: mount Not tainted 6.1.0-rc7 #3 [ 115.850851] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 115.851510] RIP: 0010:propagate_one.part.0+0x7f/0x1a0 [ 115.851924] Code: 75 eb 4c 8b 05 c2 25 37 02 4c 89 ca 48 8b 4a 10 49 39 d0 74 1e 48 3b 81 e0 00 00 00 74 26 48 8b 92 e0 00 00 00 be 01 00 00 00 <48> 8b 4a 10 49 39 d0 75 e2 40 84 f6 74 38 4c 89 05 84 25 37 02 4d [ 115.853441] RSP: 0018:ffffb8d5443d7d50 EFLAGS: 00010282 [ 115.853865] RAX: ffff8e4d87c41c80 RBX: ffff8e4d88ded780 RCX: ffff8e4da4333a00 [ 115.854458] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff8e4d88ded780 [ 115.855044] RBP: ffff8e4d88ded780 R08: ffff8e4da4338000 R09: ffff8e4da43388c0 [ 115.855693] R10: 0000000000000002 R11: ffffb8d540158000 R12: ffffb8d5443d7da8 [ 115.856304] R13: ffff8e4d88ded780 R14: 0000000000000000 R15: 0000000000000000 [ 115.856859] FS: 00007f92c90c9800(0000) GS:ffff8e4dfdc00000(0000) knlGS:0000000000000000 [ 115.857531] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 115.858006] CR2: 0000000000000010 CR3: 0000000022f4c002 CR4: 00000000000706f0 [ 115.858598] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 115.859393] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 115.860099] Call Trace: [ 115.860358] <TASK> [ 115.860535] propagate_mnt+0x14d/0x190 [ 115.860848] attach_recursive_mnt+0x274/0x3e0 [ 115.861212] path_mount+0x8c8/0xa60 [ 115.861503] __x64_sys_mount+0xf6/0x140 [ 115.861819] do_syscall_64+0x5b/0x80 [ 115.862117] ? do_faccessat+0x123/0x250 [ 115.862435] ? syscall_exit_to_user_mode+0x17/0x40 [ 115.862826] ? do_syscall_64+0x67/0x80 [ 115.863133] ? syscall_exit_to_user_mode+0x17/0x40 [ 115.863527] ? do_syscall_64+0x67/0x80 [ 115.863835] ? do_syscall_64+0x67/0x80 [ 115.864144] ? do_syscall_64+0x67/0x80 [ 115.864452] ? exc_page_fault+0x70/0x170 [ 115.864775] entry_SYSCALL_64_after_hwframe+0x63/0xcd [ 115.865187] RIP: 0033:0x7f92c92b0ebe [ 115.865480] Code: 48 8b 0d 75 4f 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 42 4f 0c 00 f7 d8 64 89 01 48 [ 115.866984] RSP: 002b:00007fff000aa728 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5 [ 115.867607] RAX: ffffffffffffffda RBX: 000055a77888d6b0 RCX: 00007f92c92b0ebe [ 115.868240] RDX: 000055a77888d8e0 RSI: 000055a77888e6e0 RDI: 000055a77888e620 [ 115.868823] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000001 [ 115.869403] R10: 0000000000001000 R11: 0000000000000246 R12: 000055a77888e620 [ 115.869994] R13: 000055a77888d8e0 R14: 00000000ffffffff R15: 00007f92c93e4076 [ 115.870581] </TASK> [ 115.870763] Modules linked in: nft_fib_inet nft_fib_ipv4
nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_set rfkill nf_tables nfnetlink qrtr snd_intel8x0 sunrpc snd_ac97_codec ac97_bus snd_pcm snd_timer intel_rapl_msr intel_rapl_common snd vboxguest intel_powerclamp video rapl joydev soundcore i2c_piix4 wmi fuse zram xfs vmwgfx crct10dif_pclmul crc32_pclmul crc32c_intel polyval_clmulni polyval_generic drm_ttm_helper ttm e1000 ghash_clmulni_intel serio_raw ata_generic pata_acpi scsi_dh_rdac scsi_dh_emc scsi_dh_alua dm_multipath
[ 115.875288] CR2: 0000000000000010 [ 115.875641] ---[ end trace 0000000000000000 ]--- [ 115.876135] RIP: 0010:propagate_one.part.0+0x7f/0x1a0 [ 115.876551] Code: 75 eb 4c 8b 05 c2 25 37 02 4c 89 ca 48 8b 4a 10 49 39 d0 74 1e 48 3b 81 e0 00 00 00 74 26 48 8b 92 e0 00 00 00 be 01 00 00 00 <48> 8b 4a 10 49 39 d0 75 e2 40 84 f6 74 38 4c 89 05 84 25 37 02 4d [ 115.878086] RSP: 0018:ffffb8d5443d7d50 EFLAGS: 00010282 [ 115.878511] RAX: ffff8e4d87c41c80 RBX: ffff8e4d88ded780 RCX: ffff8e4da4333a00 [ 115.879128] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff8e4d88ded780 [ 115.879715] RBP: ffff8e4d88ded780 R08: ffff8e4da4338000 R09: ffff8e4da43388c0 [ 115.880359] R10: 0000000000000002 R11: ffffb8d540158000 R12: ffffb8d5443d7da8 [ 115.880962] R13: ffff8e4d88ded780 R14: 0000000000000000 R15: 0000000000000000 [ 115.881548] FS: 00007f92c90c9800(0000) GS:ffff8e4dfdc00000(0000) knlGS:0000000000000000 [ 115.882234] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 115.882713] CR2: 0000000000000010 CR3: 0000000022f4c002 CR4: 00000000000706f0 [ 115.883314] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 115.883966] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
---
If there are no big objections I'll get this to Linus rather sooner than later.
--- fs/pnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/pnode.c +1 -1
@@ -245,7 +245,7 @@ static int propagate_one(struct mount *m } do { struct mount *parent = last_source->mnt_parent; - if (last_source == first_source) + if (peers(last_source, first_source)) break; done = parent->mnt_master == p; if (done && peers(n, parent))
Greg Kroah-Hartman
maintainerPATCH 371/521 md: fix a crash in mempool_free
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit 341097ee53573e06ab9fc675d96a052385b851fa upstream.
There's a crash in mempool_free when running the lvm test shell/lvchange-rebuild-raid.sh.
The reason for the crash is this:
* super_written calls atomic_dec_and_test(&mddev->pending_writes) and wake_up(&mddev->sb_wait). Then it calls rdev_dec_pending(rdev, mddev) and bio_put(bio).
* so, the process that waited on sb_wait and that is woken up is racing with bio_put(bio).
* if the process wins the race, it calls bioset_exit before bio_put(bio) is executed.
* bio_put(bio) attempts to free a bio into a destroyed bio set - causing a crash in mempool_free.
We fix this bug by moving bio_put before atomic_dec_and_test.
We also move rdev_dec_pending before atomic_dec_and_test as suggested by Neil Brown.
The function md_end_flush has a similar bug - we must call bio_put before we decrement the number of in-progress bios.
BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 11557f0067 P4D 11557f0067 PUD 0 Oops: 0002 [#1] PREEMPT SMP CPU: 0 PID: 73 Comm: kworker/0:1 Not tainted 6.1.0-rc3 #5 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 Workqueue: kdelayd flush_expired_bios [dm_delay] RIP: 0010:mempool_free+0x47/0x80 Code: 48 89 ef 5b 5d ff e0 f3 c3 48 89 f7 e8 32 45 3f 00 48 63 53 08 48 89 c6 3b 53 04 7d 2d 48 8b 43 10 8d 4a 01 48 89 df 89 4b 08 <48> 89 2c d0 e8 b0 45 3f 00 48 8d 7b 30 5b 5d 31 c9 ba 01 00 00 00 RSP: 0018:ffff88910036bda8 EFLAGS: 00010093 RAX: 0000000000000000 RBX: ffff8891037b65d8 RCX: 0000000000000001 RDX: 0000000000000000 RSI: 0000000000000202 RDI: ffff8891037b65d8 RBP: ffff8891447ba240 R08: 0000000000012908 R09: 00000000003d0900 R10: 0000000000000000 R11: 0000000000173544 R12: ffff889101a14000 R13: ffff8891562ac300 R14: ffff889102b41440 R15: ffffe8ffffa00d05 FS: 0000000000000000(0000) GS:ffff88942fa00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000001102e99000 CR4: 00000000000006b0 Call Trace: <TASK> clone_endio+0xf4/0x1c0 [dm_mod] clone_endio+0xf4/0x1c0 [dm_mod] __submit_bio+0x76/0x120 submit_bio_noacct_nocheck+0xb6/0x2a0 flush_expired_bios+0x28/0x2f [dm_delay] process_one_work+0x1b4/0x300 worker_thread+0x45/0x3e0 ? rescuer_thread+0x380/0x380 kthread+0xc2/0x100 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x1f/0x30 </TASK> Modules linked in: brd dm_delay dm_raid dm_mod af_packet uvesafb cfbfillrect cfbimgblt cn cfbcopyarea fb font fbdev tun autofs4 binfmt_misc configfs ipv6 virtio_rng virtio_balloon rng_core virtio_net pcspkr net_failover failover qemu_fw_cfg button mousedev raid10 raid456 libcrc32c async_raid6_recov async_memcpy async_pq raid6_pq async_xor xor async_tx raid1 raid0 md_mod sd_mod t10_pi crc64_rocksoft crc64 virtio_scsi scsi_mod evdev psmouse bsg scsi_common [last unloaded: brd] CR2: 0000000000000000 ---[ end trace 0000000000000000 ]---
--- drivers/md/md.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/md/md.c +6 -3
@@ -417,13 +417,14 @@ static void md_end_flush(struct bio *biostruct md_rdev *rdev = bio->bi_private;struct mddev *mddev = rdev->mddev; +bio_put (bio); +rdev_dec_pending (rdev, mddev);if (atomic_dec_and_test (&mddev->flush_pending)) {/* The pre-request flush has finished */ queue_work (md_wq, &mddev->flush_work); } -bio_put (bio); }static void md_submit_flush_data (struct work_struct *ws);
@@ -821,10 +822,12 @@ static void super_written(struct bio *bi }else clear_bit (LastDev, &rdev->flags); +bio_put (bio); + +rdev_dec_pending (rdev, mddev); +if (atomic_dec_and_test (&mddev->pending_writes))wake_up (&mddev->sb_wait); -rdev_dec_pending (rdev, mddev); -bio_put (bio); } void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
Greg Kroah-Hartman
maintainerPATCH 372/521 mmc: vub300: fix warning - do not call blocking ops when !TASK_RUNNING
In reply to Greg Kroah-HartmanFrom: Deren Wu <[email protected]>
commit 4a44cd249604e29e7b90ae796d7692f5773dd348 upstream.
vub300_enable_sdio_irq() works with mutex and need TASK_RUNNING here. Ensure that we mark current as TASK_RUNNING for sleepable context.
[ 77.554641] do not call blocking ops when !TASK_RUNNING; state=1 set at [<ffffffff92a72c1d>] sdio_irq_thread+0x17d/0x5b0 [ 77.554652] WARNING: CPU: 2 PID: 1983 at kernel/sched/core.c:9813 __might_sleep+0x116/0x160 [ 77.554905] CPU: 2 PID: 1983 Comm: ksdioirqd/mmc1 Tainted: G OE 6.1.0-rc5 #1 [ 77.554910] Hardware name: Intel(R) Client Systems NUC8i7BEH/NUC8BEB, BIOS BECFL357.86A.0081.2020.0504.1834 05/04/2020 [ 77.554912] RIP: 0010:__might_sleep+0x116/0x160 [ 77.554920] RSP: 0018:ffff888107b7fdb8 EFLAGS: 00010282 [ 77.554923] RAX: 0000000000000000 RBX: ffff888118c1b740 RCX: 0000000000000000 [ 77.554926] RDX: 0000000000000001 RSI: 0000000000000004 RDI: ffffed1020f6ffa9 [ 77.554928] RBP: ffff888107b7fde0 R08: 0000000000000001 R09: ffffed1043ea60ba [ 77.554930] R10: ffff88821f5305cb R11: ffffed1043ea60b9 R12: ffffffff93aa3a60 [ 77.554932] R13: 000000000000011b R14: 7fffffffffffffff R15: ffffffffc0558660 [ 77.554934] FS: 0000000000000000(0000) GS:ffff88821f500000(0000) knlGS:0000000000000000 [ 77.554937] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 77.554939] CR2: 00007f8a44010d68 CR3: 000000024421a003 CR4: 00000000003706e0 [ 77.554942] Call Trace: [ 77.554944] <TASK> [ 77.554952] mutex_lock+0x78/0xf0 [ 77.554973] vub300_enable_sdio_irq+0x103/0x3c0 [vub300] [ 77.554981] sdio_irq_thread+0x25c/0x5b0 [ 77.555006] kthread+0x2b8/0x370 [ 77.555017] ret_from_fork+0x1f/0x30 [ 77.555023] </TASK> [ 77.555025] ---[ end trace 0000000000000000 ]---
--- drivers/mmc/host/vub300.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/host/vub300.c +2 -0
@@ -2052,6 +2052,7 @@ static void vub300_enable_sdio_irq(strucreturn ;kref_get (&vub300->kref);if (enable) { +set_current_state (TASK_RUNNING );mutex_lock (&vub300->irq_mutex);if (vub300->irqs_queued) { vub300->irqs_queued -=1 ;
@@ -2067,6 +2068,7 @@ static void vub300_enable_sdio_irq(strucvub300_queue_poll_work (vub300,0 ); }mutex_unlock (&vub300->irq_mutex); +set_current_state (TASK_INTERRUPTIBLE ); }else { vub300->irq_enabled =0 ; }
Greg Kroah-Hartman
maintainerPATCH 373/521 tpm: tpm_crb: Add the missed acpi_put_table() to fix memory leak
In reply to Greg Kroah-HartmanFrom: Hanjun Guo <[email protected]>
commit 37e90c374dd11cf4919c51e847c6d6ced0abc555 upstream.
In crb_acpi_add(), we get the TPM2 table to retrieve information like start method, and then assign them to the priv data, so the TPM2 table is not used after the init, should be freed, call acpi_put_table() to fix the memory leak.
--- drivers/char/tpm/tpm_crb.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/char/tpm/tpm_crb.c +20 -9
@@ -680,12 +680,16 @@ static int crb_acpi_add(struct acpi_devi/* Should the FIFO driver handle this? */ sm = buf->start_method; -if (sm ==ACPI_TPM2_MEMORY_MAPPED ) -return -ENODEV ; +if (sm ==ACPI_TPM2_MEMORY_MAPPED ) { + rc = -ENODEV ; + goto out; + } priv =devm_kzalloc (dev,sizeof (struct crb_priv ),GFP_KERNEL ); -if (!priv) -return -ENOMEM ; +if (!priv) { + rc = -ENOMEM ; + goto out; + }if (sm ==ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC ) {if (buf->header.length < (sizeof (*buf) +sizeof (*crb_smc))) {
@@ -693,7 +697,8 @@ static int crb_acpi_add(struct acpi_deviFW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n" , buf->header.length, ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC); -return -EINVAL ; + rc = -EINVAL ; + goto out; } crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf)); priv->smc_func_id = crb_smc->smc_func_id;
@@ -704,17 +709,23 @@ static int crb_acpi_add(struct acpi_devi rc =crb_map_io (device, priv, buf);if (rc) -return rc; + goto out; chip =tpmm_chip_alloc (dev, &tpm_crb); -if (IS_ERR (chip)) -return PTR_ERR (chip); +if (IS_ERR (chip)) { + rc =PTR_ERR (chip); + goto out; + }dev_set_drvdata (&chip->dev, priv); chip->acpi_dev_handle = device->handle; chip->flags =TPM_CHIP_FLAG_TPM2 ; -return tpm_chip_register (chip); + rc =tpm_chip_register (chip); + +out: +acpi_put_table ((struct acpi_table_header *)buf); +return rc; }static int crb_acpi_remove (struct acpi_device *device)
Greg Kroah-Hartman
maintainerPATCH 374/521 tpm: tpm_tis: Add the missed acpi_put_table() to fix memory leak
In reply to Greg Kroah-HartmanFrom: Hanjun Guo <[email protected]>
commit db9622f762104459ff87ecdf885cc42c18053fd9 upstream.
In check_acpi_tpm2(), we get the TPM2 table just to make sure the table is there, not used after the init, so the acpi_put_table() should be added to release the ACPI memory.
--- drivers/char/tpm/tpm_tis.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm_tis.c +5 -4
@@ -129,6 +129,7 @@ static int check_acpi_tpm2(struct deviceconst struct acpi_device_id *aid =acpi_match_device (tpm_acpi_tbl, dev);struct acpi_table_tpm2 *tbl;acpi_status st; +int ret =0 ;if (!aid || aid->driver_data !=DEVICE_IS_TPM2 )return 0 ;
@@ -136,8 +137,7 @@ static int check_acpi_tpm2(struct device/* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2 * table is mandatory */ - st = -acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl); + st =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl);if (ACPI_FAILURE (st) || tbl->header.length <sizeof (*tbl)) {dev_err (dev,FW_BUG "failed to get TPM2 ACPI table\n" );return -EINVAL ;
@@ -145,9 +145,10 @@ static int check_acpi_tpm2(struct device/* The tpm2_crb driver handles this device */ if (tbl->start_method !=ACPI_TPM2_MEMORY_MAPPED ) -return -ENODEV ; + ret = -ENODEV ; - return 0; +acpi_put_table ((struct acpi_table_header *)tbl); + return ret; }#else static int check_acpi_tpm2 (struct device *dev)
Greg Kroah-Hartman
maintainerPATCH 375/521 SUNRPC: Dont leak netobj memory when gss_read_proxy_verf() fails
In reply to Greg Kroah-HartmanFrom: Chuck Lever <[email protected]>
commit da522b5fe1a5f8b7c20a0023e87b52a150e53bf5 upstream.
--- net/sunrpc/auth_gss/svcauth_gss.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +7 -2
@@ -1088,18 +1088,23 @@ static int gss_read_proxy_verf(struct svreturn res; inlen =svc_getnl (argv); -if (inlen > (argv->iov_len + rqstp->rq_arg.page_len)) +if (inlen > (argv->iov_len + rqstp->rq_arg.page_len)) { +kfree (in_handle->data);return SVC_DENIED ; + } pages =DIV_ROUND_UP (inlen,PAGE_SIZE ); in_token->pages =kcalloc (pages,sizeof (struct page *),GFP_KERNEL ); -if (!in_token->pages) +if (!in_token->pages) { +kfree (in_handle->data);return SVC_DENIED ; + } in_token->page_base =0 ; in_token->page_len = inlen;for (i =0 ; i < pages; i++) { in_token->pages[i] =alloc_page (GFP_KERNEL );if (!in_token->pages[i]) { +kfree (in_handle->data);gss_free_in_token_pages (in_token);return SVC_DENIED ; }
Greg Kroah-Hartman
maintainerPATCH 376/521 media: stv0288: use explicitly signed char
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit 7392134428c92a4cb541bd5c8f4f5c8d2e88364d upstream.
With char becoming unsigned by default, and with char alone being ambiguous and based on architecture, signed chars need to be marked explicitly as such. Use s8 and u8 types here, since that's what surrounding code does. This fixes:
drivers/media/dvb-frontends/stv0288.c:471 stv0288_set_frontend() warn: assigning (-9) to unsigned variable 'tm' drivers/media/dvb-frontends/stv0288.c:471 stv0288_set_frontend() warn: we never enter this loop
--- drivers/media/dvb-frontends/stv0288.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/dvb-frontends/stv0288.c +2 -3
@@ -452,9 +452,8 @@ static int stv0288_set_frontend(struct dstruct stv0288_state *state = fe->demodulator_priv;struct dtv_frontend_properties *c = &fe->dtv_property_cache; -char tm; -unsigned char tda[3 ]; -u8 reg, time_out =0 ; +u8 tda[3 ], reg, time_out =0 ; +s8 tm;dprintk ("%s : FE_SET_FRONTEND\n" , __func__);
Greg Kroah-Hartman
maintainerPATCH 377/521 soc: qcom: Select REMAP_MMIO for LLCC driver
In reply to Greg Kroah-HartmanFrom: Manivannan Sadhasivam <[email protected]>
commit 5d2fe2d7b616b8baa18348ead857b504fc2de336 upstream.
LLCC driver uses REGMAP_MMIO for accessing the hardware registers. So select the dependency in Kconfig. Without this, there will be errors while building the driver with COMPILE_TEST only:
ERROR: modpost: "__devm_regmap_init_mmio_clk" [drivers/soc/qcom/llcc-qcom.ko] undefined! make[1]: *** [scripts/Makefile.modpost:126: Module.symvers] Error 1
make: *** [Makefile:1944: modpost] Error 2
--- drivers/soc/qcom/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/soc/qcom/Kconfig +1 -0
@@ -16,6 +16,7 @@ config QCOM_COMMAND_DB config QCOM_GENI_SE tristate "QCOM GENI Serial Engine Driver" depends on ARCH_QCOM || COMPILE_TEST + select REGMAP_MMIO help This driver is used to manage Generic Interface (GENI) firmware based Qualcomm Technologies, Inc. Universal Peripheral (QUP) Wrapper. This
Greg Kroah-Hartman
maintainerPATCH 378/521 ktest.pl minconfig: Unset configs instead of just removing them
In reply to Greg Kroah-HartmanFrom: Steven Rostedt <[email protected]>
commit ef784eebb56425eed6e9b16e7d47e5c00dcf9c38 upstream.
After a full run of a make_min_config test, I noticed there were a lot of CONFIGs still enabled that really should not be. Looking at them, I noticed they were all defined as "default y". The issue is that the test simple removes the config and re-runs make oldconfig, which enables it again because it is set to default 'y'. Instead, explicitly disable the config with writing "# CONFIG_FOO is not set" to the file to keep it from being set again.
With this change, one of my box's minconfigs went from 768 configs set, down to 521 configs set.
--- tools/testing/ktest/ktest.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/ktest/ktest.pl +2 -1
@@ -3706,9 +3706,10 @@ sub test_this_config { # .config to make sure it is missing the config that # we had before my %configs = %min_configs; - delete $configs{$config}; + $configs{$config} = "# $config is not set"; make_new_config ((values %configs), (values %keep_configs)); make_oldconfig; + delete $configs{$config}; undef %configs; assign_configs \%configs, $output_config;
Greg Kroah-Hartman
maintainerPATCH 379/521 ARM: ux500: do not directly dereference __iomem
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit 65b0e307a1a9193571db12910f382f84195a3d29 upstream.
Sparse reports that calling add_device_randomness() on uid is a violation of address spaces. And indeed the next usage uses readl() properly, but that was left out when passing it toadd_device_ randomness(). So instead copy the whole thing to the stack first.
--- drivers/soc/ux500/ux500-soc-id.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/soc/ux500/ux500-soc-id.c +4 -6
@@ -159,20 +159,18 @@ static ssize_t ux500_get_process(structstatic const char *db8500_read_soc_id (struct device_node *backupram) {void __iomem *base; -void __iomem *uid;const char *retstr; +u32 uid[5 ]; base =of_iomap (backupram,0 );if (!base)return NULL ; - uid = base +0x1fc0 ; +memcpy_fromio (uid, base +0x1fc0 ,sizeof (uid));/* Throw these device-specific numbers into the entropy pool */ -add_device_randomness (uid,0x14 ); +add_device_randomness (uid,sizeof (uid)); retstr =kasprintf (GFP_KERNEL ,"%08x%08x%08x%08x%08x" , -readl ((u32 *)uid+0 ), -readl ((u32 *)uid+1 ),readl ((u32 *)uid+2 ), -readl ((u32 *)uid+3 ),readl ((u32 *)uid+4 )); + uid[0 ], uid[1 ], uid[2 ], uid[3 ], uid[4 ]);iounmap (base);return retstr; }
Greg Kroah-Hartman
maintainerPATCH 380/521 selftests: Use optional USERCFLAGS and USERLDFLAGS
In reply to Greg Kroah-HartmanFrom: Mickaël Salaün <[email protected]>
commit de3ee3f63400a23954e7c1ad1cb8c20f29ab6fe3 upstream.
This change enables to extend CFLAGS and LDFLAGS from command line, e.g. to extend compiler checks: make USERCFLAGS=-Werror USERLDFLAGS=-static
USERCFLAGS and USERLDFLAGS are documented in Documentation/kbuild/makefiles.rst and Documentation/kbuild/kbuild.rst
This should be backported (down to 5.10) to improve previous kernel versions testing as well.
--- tools/testing/selftests/lib.mk | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/lib.mk +5 -0
@@ -144,6 +144,11 @@ endef clean: $(CLEAN) +# Enables to extend CFLAGS and LDFLAGS from command line, e.g. +# make USERCFLAGS=-Werror USERLDFLAGS=-static +CFLAGS += $(USERCFLAGS) +LDFLAGS += $(USERLDFLAGS) + # When make O= with kselftest target from main level # the following aren't defined. #
Greg Kroah-Hartman
maintainerPATCH 381/521 binfmt: Move install_exec_creds after setup_new_exec to match binfmt_elf
In reply to Greg Kroah-HartmanFrom: Eric W. Biederman <[email protected]>
[ Upstream commit e7f7785449a1f459a4a3ca92f82f56fb054dd2b9 ]
In 2016 Linus moved install_exec_creds immediately after setup_new_exec, in binfmt_elf as a cleanup and as part of closing a potential information leak.
Perform the same cleanup for the other binary formats.
Different binary formats doing the same things the same way makes exec easier to reason about and easier to maintain.
Greg Ungerer reports:
Quoted 3 lines
I tested the the whole series on non-MMU m68k and non-MMU arm (exercising
binfmt_flat) and it all tested out with no problems, so for thebinfmt_flatchanges:
Ref: 9f834ec18def ("binfmt_elf: switch to new creds when switching to new mm")
Stable-dep-of: e7f703ff2507 ("binfmt: Fix error return code in load_elf_fdpic_binary()")
--- arch/x86/ia32/ia32_aout.c | 3 +-- fs/binfmt_aout.c | 2 +- fs/binfmt_elf_fdpic.c | 2 +- fs/binfmt_flat.c | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-)
arch/x86/ia32/ia32_aout.c +1 -2
@@ -298,6 +298,7 @@ static int load_aout_binary(struct linux_binprm *bprm)set_personality_ia32 (false);setup_new_exec (bprm); +install_exec_creds (bprm); regs->cs = __USER32_CS; regs->r8 = regs->r9 = regs->r10 = regs->r11 = regs->r12 =
@@ -314,8 +315,6 @@ static int load_aout_binary(struct linux_binprm *bprm)if (retval <0 )return retval; -install_exec_creds (bprm); -if (N_MAGIC (ex) ==OMAGIC ) {unsigned long text_addr, map_size;
fs/binfmt_aout.c +1 -1
@@ -244,6 +244,7 @@ static int load_aout_binary(struct linux_binprm * bprm)set_personality (PER_LINUX );#endif setup_new_exec (bprm); +install_exec_creds (bprm); current->mm->end_code = ex.a_text + (current->mm->start_code =N_TXTADDR (ex));
@@ -256,7 +257,6 @@ static int load_aout_binary(struct linux_binprm * bprm)if (retval <0 )return retval; -install_exec_creds (bprm);if (N_MAGIC (ex) ==OMAGIC ) {unsigned long text_addr, map_size;
fs/binfmt_elf_fdpic.c +1 -1
@@ -357,6 +357,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) current->personality |=READ_IMPLIES_EXEC ;setup_new_exec (bprm); +install_exec_creds (bprm);set_binfmt (&elf_fdpic_format);
@@ -438,7 +439,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) current->mm->start_stack = current->mm->start_brk + stack_size;#endif -install_exec_creds (bprm);if (create_elf_fdpic_tables (bprm, current->mm, &exec_params, &interp_params) <0 ) goto error;
fs/binfmt_flat.c +1 -2
@@ -541,6 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm,/* OK, This is the point of no return */ set_personality (PER_LINUX_32BIT );setup_new_exec (bprm); +install_exec_creds (bprm); }/*
@@ -965,8 +966,6 @@ static int load_flat_binary(struct linux_binprm *bprm) } } -install_exec_creds (bprm); -set_binfmt (&flat_format);#ifdef CONFIG_MMU
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 382/521 binfmt: Fix error return code in load_elf_fdpic_binary()
In reply to Greg Kroah-HartmanFrom: Wang Yufen <[email protected]>
[ Upstream commit e7f703ff2507f4e9f496da96cd4b78fd3026120c ]
Fix to return a negative error code from create_elf_fdpic_tables() instead of 0.
--- fs/binfmt_elf_fdpic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/binfmt_elf_fdpic.c +3 -2
@@ -439,8 +439,9 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) current->mm->start_stack = current->mm->start_brk + stack_size;#endif -if (create_elf_fdpic_tables (bprm, current->mm, - &exec_params, &interp_params) <0 ) + retval =create_elf_fdpic_tables (bprm, current->mm, &exec_params, + &interp_params); +if (retval <0 ) goto error;kdebug ("- start_code %lx" , current->mm->start_code);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 383/521 dm cache: Fix ABBA deadlock between shrink_slab and dm_cache_metadata_abort
In reply to Greg Kroah-HartmanFrom: Mike Snitzer <[email protected]>
commit 352b837a5541690d4f843819028cf2b8be83d424 upstream.
Same ABBA deadlock pattern fixed in commit 4b60f452ec51 ("dm thin: Fix ABBA deadlock between shrink_slab and dm_pool_abort_metadata") to DM-cache's metadata.
--- drivers/md/dm-cache-metadata.c | 54 +++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-)
drivers/md/dm-cache-metadata.c +47 -7
@@ -551,11 +551,13 @@ static int __create_persistent_data_objereturn r; } -static void __destroy_persistent_data_objects (struct dm_cache_metadata *cmd) +static void __destroy_persistent_data_objects (struct dm_cache_metadata *cmd, +bool destroy_bm) {dm_sm_destroy (cmd->metadata_sm);dm_tm_destroy (cmd->tm); -dm_block_manager_destroy (cmd->bm); +if (destroy_bm) +dm_block_manager_destroy (cmd->bm); }typedef unsigned long (*flags_mutator )(unsigned long );
@@ -826,7 +828,7 @@ static struct dm_cache_metadata *lookup_ cmd2 =lookup (bdev);if (cmd2) {mutex_unlock (&table_lock); -__destroy_persistent_data_objects (cmd); +__destroy_persistent_data_objects (cmd, true);kfree (cmd);return cmd2; }
@@ -874,7 +876,7 @@ void dm_cache_metadata_close(struct dm_cmutex_unlock (&table_lock);if (!cmd->fail_io) -__destroy_persistent_data_objects (cmd); +__destroy_persistent_data_objects (cmd, true);kfree (cmd); } }
@@ -1808,14 +1810,52 @@ int dm_cache_metadata_needs_check(structint dm_cache_metadata_abort (struct dm_cache_metadata *cmd) { -int r; +int r = -EINVAL ; +struct dm_block_manager *old_bm =NULL , *new_bm =NULL ; + +/* fail_io is double-checked with cmd->root_lock held below */ +if (unlikely (cmd->fail_io)) +return r; + +/* +* Replacement block manager (new_bm) is created and old_bm destroyed outside of +* cmd root_lock to avoid ABBA deadlock that would result (due to life-cycle of +* shrinker associated with the block manager's bufio client vs cmd root_lock). +* - must take shrinker_rwsem without holding cmd->root_lock +*/ + new_bm =dm_block_manager_create (cmd->bdev,DM_CACHE_METADATA_BLOCK_SIZE <<SECTOR_SHIFT , +CACHE_MAX_CONCURRENT_LOCKS );WRITE_LOCK (cmd); -__destroy_persistent_data_objects (cmd); - r =__create_persistent_data_objects (cmd, false); +if (cmd->fail_io) { +WRITE_UNLOCK (cmd); + goto out; + } + +__destroy_persistent_data_objects (cmd, false); + old_bm = cmd->bm; +if (IS_ERR (new_bm)) { +DMERR ("could not create block manager during abort" ); + cmd->bm =NULL ; + r =PTR_ERR (new_bm); + goto out_unlock; + } + + cmd->bm = new_bm; + r =__open_or_format_metadata (cmd, false); +if (r) { + cmd->bm =NULL ; + goto out_unlock; + } + new_bm =NULL ; +out_unlock:if (r) cmd->fail_io = true;WRITE_UNLOCK (cmd); +dm_block_manager_destroy (old_bm); +out: +if (new_bm && !IS_ERR (new_bm)) +dm_block_manager_destroy (new_bm);return r; }
Greg Kroah-Hartman
maintainerPATCH 384/521 dm thin: Use last transactions pmd->root when commit failed
In reply to Greg Kroah-HartmanFrom: Zhihao Cheng <[email protected]>
commit 7991dbff6849f67e823b7cc0c15e5a90b0549b9f upstream.
Recently we found a softlock up problem in dm thin pool btree lookup code due to corrupted metadata:
Kernel panic - not syncing: softlockup: hung tasks CPU: 7 PID: 2669225 Comm: kworker/u16:3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) Workqueue: dm-thin do_worker [dm_thin_pool] Call Trace: <IRQ> dump_stack+0x9c/0xd3 panic+0x35d/0x6b9 watchdog_timer_fn.cold+0x16/0x25 __run_hrtimer+0xa2/0x2d0 </IRQ> RIP: 0010:__relink_lru+0x102/0x220 [dm_bufio] __bufio_new+0x11f/0x4f0 [dm_bufio] new_read+0xa3/0x1e0 [dm_bufio] dm_bm_read_lock+0x33/0xd0 [dm_persistent_data] ro_step+0x63/0x100 [dm_persistent_data] btree_lookup_raw.constprop.0+0x44/0x220 [dm_persistent_data] dm_btree_lookup+0x16f/0x210 [dm_persistent_data] dm_thin_find_block+0x12c/0x210 [dm_thin_pool] __process_bio_read_only+0xc5/0x400 [dm_thin_pool] process_thin_deferred_bios+0x1a4/0x4a0 [dm_thin_pool] process_one_work+0x3c5/0x730
Following process may generate a broken btree mixed with fresh and stale btree nodes, which could get dm thin trapped in an infinite loop while looking up data block:
Transaction 1: pmd->root = A, A->B->C // One path in btree
pmd->root = X, X->Y->Z // Copy-up
Transaction 2: X,Z is updated on disk, Y write failed.
// Commit failed, dm thin becomes read-only.
process_bio_read_only
dm_thin_find_block
__find_block
dm_btree_lookup(pmd->root)The pmd->root points to a broken btree, Y may contain stale node pointing to any block, for example X, which gets dm thin trapped into a dead loop while looking up Z.
Fix this by setting pmd->root in __open_metadata(), so that dm thin will use the last transaction's pmd->root if commit failed.
Fetch a reproducer in [Link].
Linke: https://bugzilla.kernel.org/show_bug.cgi?id=216790
--- drivers/md/dm-thin-metadata.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/md/dm-thin-metadata.c +9 -0
@@ -660,6 +660,15 @@ static int __open_metadata(struct dm_poo goto bad_cleanup_data_sm; } +/* +* For pool metadata opening process, root setting is redundant +* because it will be set again in __begin_transaction(). But dm +* pool aborting process really needs to get last transaction's +* root to avoid accessing broken btree. +*/ + pmd->root =le64_to_cpu (disk_super->data_mapping_root); + pmd->details_root =le64_to_cpu (disk_super->device_details_root); +__setup_btree_details (pmd);dm_bm_unlock (sblock);
Greg Kroah-Hartman
maintainerPATCH 385/521 dm thin: Fix UAF in run_timer_softirq()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit 88430ebcbc0ec637b710b947738839848c20feff upstream.
When dm_resume() and dm_destroy() are concurrent, it will lead to UAF, as follows:
BUG: KASAN: use-after-free in __run_timers+0x173/0x710 Write of size 8 at addr ffff88816d9490f0 by task swapper/0/0 <snip> Call Trace: <IRQ> dump_stack_lvl+0x73/0x9f print_report.cold+0x132/0xaa2 _raw_spin_lock_irqsave+0xcd/0x160 __run_timers+0x173/0x710 kasan_report+0xad/0x110 __run_timers+0x173/0x710 __asan_store8+0x9c/0x140 __run_timers+0x173/0x710 call_timer_fn+0x310/0x310 pvclock_clocksource_read+0xfa/0x250 kvm_clock_read+0x2c/0x70 kvm_clock_get_cycles+0xd/0x20 ktime_get+0x5c/0x110 lapic_next_event+0x38/0x50 clockevents_program_event+0xf1/0x1e0 run_timer_softirq+0x49/0x90 __do_softirq+0x16e/0x62c __irq_exit_rcu+0x1fa/0x270 irq_exit_rcu+0x12/0x20 sysvec_apic_timer_interrupt+0x8e/0xc0
One of the concurrency UAF can be shown as below:
use free
do_resume |
__find_device_hash_cell |
dm_get |
atomic_inc(&md->holders) |
| dm_destroy
| __dm_destroy
| if (!dm_suspended_md(md))
| atomic_read(&md->holders)
| msleep(1)
dm_resume |
__dm_resume |
dm_table_resume_targets |
pool_resume |
do_waker #add delay work |
dm_put |
atomic_dec(&md->holders) |
| dm_table_destroy
| pool_dtr
| __pool_dec
| __pool_destroy
| destroy_workqueue
| kfree(pool) # free pool time out__do_softirq
run_timer_softirq # pool has already been freed
This can be easily reproduced using:
1. create thin-pool
2. dmsetup suspend pool
3. dmsetup resume pool
4. dmsetup remove_all # Concurrent with 3
The root cause of this UAF bug is that dm_resume() adds timer after dm_destroy() skips cancelling the timer because of suspend status. After timeout, it will call run_timer_softirq(), however pool has already been freed. The concurrency UAF bug will happen.
Therefore, cancelling timer again in __pool_destroy().
--- drivers/md/dm-thin.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-thin.c +2 -0
@@ -2921,6 +2921,8 @@ static void __pool_destroy(struct pool *dm_bio_prison_destroy (pool->prison);dm_kcopyd_client_destroy (pool->copier); +cancel_delayed_work_sync (&pool->waker); +cancel_delayed_work_sync (&pool->no_space_timeout);if (pool->wq)destroy_workqueue (pool->wq);
Greg Kroah-Hartman
maintainerPATCH 386/521 dm cache: Fix UAF in destroy()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit 6a459d8edbdbe7b24db42a5a9f21e6aa9e00c2aa upstream.
Dm_cache also has the same UAF problem when dm_resume() and dm_destroy() are concurrent.
Therefore, cancelling timer again in destroy().
--- drivers/md/dm-cache-target.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/dm-cache-target.c +1 -0
@@ -1987,6 +1987,7 @@ static void destroy(struct cache *cache)if (cache->prison)dm_bio_prison_destroy_v2 (cache->prison); +cancel_delayed_work_sync (&cache->waker);if (cache->wq)destroy_workqueue (cache->wq);
Greg Kroah-Hartman
maintainerPATCH 387/521 dm cache: set needs_check flag after aborting metadata
In reply to Greg Kroah-HartmanFrom: Mike Snitzer <[email protected]>
commit 6b9973861cb2e96dcd0bb0f1baddc5c034207c5c upstream.
Otherwise the commit that will be aborted will be associated with the metadata objects that will be torn down. Must write needs_check flag to metadata with a reset block manager.
Found through code-inspection (and compared against dm-thin.c).
--- drivers/md/dm-cache-target.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-cache-target.c +5 -5
@@ -1010,16 +1010,16 @@ static void abort_transaction(struct cacif (get_cache_mode (cache) >=CM_READ_ONLY )return ; -if (dm_cache_metadata_set_needs_check (cache->cmd)) { -DMERR ("%s: failed to set 'needs_check' flag in metadata" , dev_name); -set_cache_mode (cache,CM_FAIL ); - } -DMERR_LIMIT ("%s: aborting current metadata transaction" , dev_name);if (dm_cache_metadata_abort (cache->cmd)) {DMERR ("%s: failed to abort metadata transaction" , dev_name);set_cache_mode (cache,CM_FAIL ); } + +if (dm_cache_metadata_set_needs_check (cache->cmd)) { +DMERR ("%s: failed to set 'needs_check' flag in metadata" , dev_name); +set_cache_mode (cache,CM_FAIL ); + } }static void metadata_operation_failed (struct cache *cache,const char *op,int r)
Greg Kroah-Hartman
maintainerPATCH 388/521 x86/microcode/intel: Do not retry microcode reloading on the APs
In reply to Greg Kroah-HartmanFrom: Ashok Raj <[email protected]>
commit be1b670f61443aa5d0d01782e9b8ea0ee825d018 upstream.
The retries in load_ucode_intel_ap() were in place to support systems with mixed steppings. Mixed steppings are no longer supported and there is only one microcode image at a time. Any retries will simply reattempt to apply the same image over and over without making progress.
[ bp: Zap the circumstantial reasoning from the commit message. ]
--- arch/x86/kernel/cpu/microcode/intel.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +1 -7
@@ -662,7 +662,6 @@ void load_ucode_intel_ap(void)else iup = &intel_ucode_patch; -reget:if (!*iup) { patch =__load_ucode_intel (&uci);if (!patch)
@@ -673,12 +672,7 @@ reget: uci.mc = *iup; -if (apply_microcode_early (&uci, true)) { -/* Mixed-silicon system? Try to refetch the proper patch: */ - *iup =NULL ; - - goto reget; - } +apply_microcode_early (&uci, true); }static struct microcode_intel *find_patch (struct ucode_cpu_info *uci)
Greg Kroah-Hartman
maintainerPATCH 389/521 tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line
In reply to Greg Kroah-HartmanFrom: Yang Jihong <[email protected]>
commit c1ac03af6ed45d05786c219d102f37eb44880f28 upstream.
print_trace_line may overflow seq_file buffer. If the event is not consumed, the while loop keeps peeking this event, causing a infinite loop.
--- kernel/trace/trace.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
kernel/trace/trace.c +14 -1
@@ -5803,7 +5803,20 @@ waitagain: ret =print_trace_line (iter);if (ret ==TRACE_TYPE_PARTIAL_LINE ) { -/* don't print partial lines */ +/* +* If one print_trace_line() fills entire trace_seq in one shot, +* trace_seq_to_user() will returns -EBUSY because save_len == 0, +* In this case, we need to consume it, otherwise, loop will peek +* this event next time, resulting in an infinite loop. +*/ +if (save_len ==0 ) { + iter->seq.full =0 ; +trace_seq_puts (&iter->seq,"[LINE TOO BIG]\n" ); +trace_consume (iter); +break ; + } + +/* In other cases, don't print partial lines */ iter->seq.seq.len = save_len;break ; }
Greg Kroah-Hartman
maintainerPATCH 390/521 ARM: 9256/1: NWFPE: avoid compiler-generated __aeabi_uldivmod
In reply to Greg Kroah-HartmanFrom: Nick Desaulniers <[email protected]>
commit 3220022038b9a3845eea762af85f1c5694b9f861 upstream.
clang-15's ability to elide loops completely became more aggressive when it can deduce how a variable is being updated in a loop. Counting down one variable by an increment of another can be replaced by a modulo operation.
For 64b variables on 32b ARM EABI targets, this can result in the compiler generating calls to __aeabi_uldivmod, which it does for a do while loop in float64_rem().
For the kernel, we'd generally prefer that developers not open code 64b division via binary / operators and instead use the more explicit helpers from div64.h. On arm-linux-gnuabi targets, failure to do so can result in linkage failures due to undefined references to __aeabi_uldivmod().
While developers can avoid open coding divisions on 64b variables, the compiler doesn't know that the Linux kernel has a partial implementation of a compiler runtime (--rtlib) to enforce this convention.
It's also undecidable for the compiler whether the code in question would be faster to execute the loop vs elide it and do the 64b division.
While I actively avoid using the internal -mllvm command line flags, I think we get better code than using barrier() here, which will force reloads+spills in the loop for all toolchains.
--- arch/arm/nwfpe/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/nwfpe/Makefile +6 -0
@@ -11,3 +11,9 @@ nwfpe-y += fpa11.o fpa11_cpdo.o fpa11 entry.o nwfpe-$(CONFIG_FPE_NWFPE_XP) += extended_cpdo.o + +# Try really hard to avoid generating calls to __aeabi_uldivmod() from +# float64_rem() due to loop elision. +ifdef CONFIG_CC_IS_CLANG +CFLAGS_softfloat.o += -mllvm -replexitval=never +endif
Greg Kroah-Hartman
maintainerPATCH 391/521 media: dvb-core: Fix double free in dvb_register_device()
In reply to Greg Kroah-HartmanFrom: Keita Suzuki <[email protected]>
commit 6b0d0477fce747d4137aa65856318b55fba72198 upstream.
In function dvb_register_device() -> dvb_register_media_device() -> dvb_create_media_entity(), dvb->entity is allocated and initialized. If the initialization fails, it frees the dvb->entity, and return an error code. The caller takes the error code and handles the error by calling dvb_media_device_free(), which unregisters the entity and frees the field again if it is not NULL. As dvb->entity may not NULLed in dvb_create_media_entity() when the allocation of dvbdev->pad fails, a double free may occur. This may also cause an Use After free in media_device_unregister_entity().
Fix this by storing NULL to dvb->entity when it is freed.
--- drivers/media/dvb-core/dvbdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/dvb-core/dvbdev.c +1 -0
@@ -345,6 +345,7 @@ static int dvb_create_media_entity(struc GFP_KERNEL);if (!dvbdev->pads) {kfree (dvbdev->entity); + dvbdev->entity =NULL ;return -ENOMEM ; } }
Greg Kroah-Hartman
maintainerPATCH 392/521 media: dvb-core: Fix UAF due to refcount races at releasing
In reply to Greg Kroah-HartmanFrom: Takashi Iwai <[email protected]>
commit fd3d91ab1c6ab0628fe642dd570b56302c30a792 upstream.
The dvb-core tries to sync the releases of opened files at dvb_dmxdev_release() with two refcounts: dvbdev->users and dvr_dvbdev->users. A problem is present in those two syncs: when yet another dvb_demux_open() is called during those sync waits, dvb_demux_open() continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount at dvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.
This patch addresses the problem by adding the check of dmxdev->exit flag at dvb_demux_open(), just like dvb_dvr_open() already does. With the exit flag check, the second call of dvb_demux_open() fails, hence the further corruption can be avoided.
Also for avoiding the races of the dmxdev->exit flag reference, this patch serializes the dmxdev->exit set up and the sync waits with the dmxdev->mutex lock at dvb_dmxdev_release(). Without the mutex lock, dvb_demux_open() (or dvb_dvr_open()) may run concurrently with dvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.
CVE-2022-41218 is assigned to those bugs above.
--- drivers/media/dvb-core/dmxdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/dvb-core/dmxdev.c +8 -0
@@ -800,6 +800,11 @@ static int dvb_demux_open(struct inode *if (mutex_lock_interruptible (&dmxdev->mutex))return -ERESTARTSYS ; +if (dmxdev->exit) { +mutex_unlock (&dmxdev->mutex); +return -ENODEV ; + } +for (i =0 ; i < dmxdev->filternum; i++)if (dmxdev->filter[i].state ==DMXDEV_STATE_FREE )break ;
@@ -1457,7 +1462,10 @@ EXPORT_SYMBOL(dvb_dmxdev_init);void dvb_dmxdev_release (struct dmxdev *dmxdev) { +mutex_lock (&dmxdev->mutex); dmxdev->exit =1 ; +mutex_unlock (&dmxdev->mutex); +if (dmxdev->dvbdev->users >1 ) {wait_event (dmxdev->dvbdev->wait_queue, dmxdev->dvbdev->users ==1 );
Greg Kroah-Hartman
maintainerPATCH 393/521 cifs: fix confusing debug message
In reply to Greg Kroah-HartmanFrom: Paulo Alcantara <[email protected]>
commit a85ceafd41927e41a4103d228a993df7edd8823b upstream.
Since rc was initialised to -ENOMEM in cifs_get_smb_ses(), when an existing smb session was found, free_xid() would be called and then print
CIFS: fs/cifs/connect.c: Existing tcp session with server found
CIFS: fs/cifs/connect.c: VFS: in cifs_get_smb_ses as Xid: 44 with uid: 0
CIFS: fs/cifs/connect.c: Existing smb sess found (status=1)
CIFS: fs/cifs/connect.c: VFS: leaving cifs_get_smb_ses (xid = 44) rc = -12
Fix this by initialising rc to 0 and then let free_xid() print this instead
CIFS: fs/cifs/connect.c: Existing tcp session with server found
CIFS: fs/cifs/connect.c: VFS: in cifs_get_smb_ses as Xid: 14 with uid: 0
CIFS: fs/cifs/connect.c: Existing smb sess found (status=1)
CIFS: fs/cifs/connect.c: VFS: leaving cifs_get_smb_ses (xid = 14) rc = 0
--- fs/cifs/connect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/cifs/connect.c +3 -1
@@ -2940,7 +2940,7 @@ cifs_set_cifscreds(struct smb_vol *vol _static struct cifs_ses *cifs_get_smb_ses (struct TCP_Server_Info *server,struct smb_vol *volume_info) { -int rc = -ENOMEM ; +int rc =0 ;unsigned int xid;struct cifs_ses *ses;struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
@@ -2982,6 +2982,8 @@ cifs_get_smb_ses(struct TCP_Server_Inforeturn ses; } + rc = -ENOMEM ; +cifs_dbg (FYI ,"Existing smb sess not found\n" ); ses =sesInfoAlloc ();if (ses ==NULL )
Greg Kroah-Hartman
maintainerPATCH 394/521 md/bitmap: Fix bitmap chunk size overflow issues
In reply to Greg Kroah-HartmanFrom: Florian-Ewald Mueller <[email protected]>
commit 4555211190798b6b6fa2c37667d175bf67945c78 upstream.
- limit bitmap chunk size internal u64 variable to values not overflowing the u32 bitmap superblock structure variable stored on persistent media
- assign bitmap chunk size internal u64 variable from unsigned values to avoid possible sign extension artifacts when assigning from a s32 value
The bug has been there since at least kernel 4.0.
Steps to reproduce it:
1: mdadm -C /dev/mdx -l 1 --bitmap=internal --bitmap-chunk=256M -e 1.2 -n2 /dev/rnbd1 /dev/rnbd2
2 resize member device rnbd1 and rnbd2 to 8 TB
3 mdadm --grow /dev/mdx --size=max
The bitmap_chunksize will overflow without patch.
--- drivers/md/md-bitmap.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/md/md-bitmap.c +12 -8
@@ -488,7 +488,7 @@ void md_bitmap_print_sb(struct bitmap *b sb =kmap_atomic (bitmap->storage.sb_page);pr_debug ("%s: bitmap file superblock:\n" ,bmname (bitmap));pr_debug (" magic: %08x\n" ,le32_to_cpu (sb->magic)); -pr_debug (" version: %d\n" ,le32_to_cpu (sb->version)); +pr_debug (" version: %u\n" ,le32_to_cpu (sb->version)); pr_debug(" uuid: %08x.%08x.%08x.%08x\n", le32_to_cpu(*(__u32 *)(sb->uuid+0)), le32_to_cpu(*(__u32 *)(sb->uuid+4)),
@@ -499,11 +499,11 @@ void md_bitmap_print_sb(struct bitmap *bpr_debug ("events cleared: %llu\n" , (unsigned long long )le64_to_cpu (sb->events_cleared));pr_debug (" state: %08x\n" ,le32_to_cpu (sb->state)); -pr_debug (" chunksize: %d B\n" ,le32_to_cpu (sb->chunksize)); -pr_debug (" daemon sleep: %ds\n" ,le32_to_cpu (sb->daemon_sleep)); +pr_debug (" chunksize: %u B\n" ,le32_to_cpu (sb->chunksize)); +pr_debug (" daemon sleep: %us\n" ,le32_to_cpu (sb->daemon_sleep));pr_debug (" sync size: %llu KB\n" , (unsigned long long )le64_to_cpu (sb->sync_size)/2 ); -pr_debug ("max write behind: %d\n" ,le32_to_cpu (sb->write_behind)); +pr_debug ("max write behind: %u\n" ,le32_to_cpu (sb->write_behind));kunmap_atomic (sb); }
@@ -2101,7 +2101,8 @@ int md_bitmap_resize(struct bitmap *bitm bytes =DIV_ROUND_UP (chunks,8 );if (!bitmap->mddev->bitmap_info.external) bytes +=sizeof (bitmap_super_t); - }while (bytes > (space <<9 )); + }while (bytes > (space <<9 ) && (chunkshift +BITMAP_BLOCK_SHIFT ) < + (BITS_PER_BYTE *sizeof (((bitmap_super_t *)0 )->chunksize) -1 )); }else chunkshift =ffz (~chunksize) -BITMAP_BLOCK_SHIFT ;
@@ -2146,7 +2147,7 @@ int md_bitmap_resize(struct bitmap *bitm bitmap->counts.missing_pages = pages; bitmap->counts.chunkshift = chunkshift; bitmap->counts.chunks = chunks; - bitmap->mddev->bitmap_info.chunksize =1 << (chunkshift + + bitmap->mddev->bitmap_info.chunksize =1UL << (chunkshift +BITMAP_BLOCK_SHIFT ); blocks = min(old_counts.chunks << old_counts.chunkshift,
@@ -2172,8 +2173,8 @@ int md_bitmap_resize(struct bitmap *bitm bitmap->counts.missing_pages = old_counts.pages; bitmap->counts.chunkshift = old_counts.chunkshift; bitmap->counts.chunks = old_counts.chunks; - bitmap->mddev->bitmap_info.chunksize =1 << (old_counts.chunkshift + -BITMAP_BLOCK_SHIFT ); + bitmap->mddev->bitmap_info.chunksize = +1UL << (old_counts.chunkshift +BITMAP_BLOCK_SHIFT ); blocks = old_counts.chunks << old_counts.chunkshift;pr_warn ("Could not pre-allocate in-memory bitmap for cluster raid\n" );break ;
@@ -2499,6 +2500,9 @@ chunksize_store(struct mddev *mddev, conif (csize <512 || !is_power_of_2 (csize))return -EINVAL ; +if (BITS_PER_LONG >32 && csize >= (1ULL << (BITS_PER_BYTE * +sizeof (((bitmap_super_t *)0 )->chunksize)))) +return -EOVERFLOW ; mddev->bitmap_info.chunksize = csize;return len; }
Greg Kroah-Hartman
maintainerPATCH 395/521 ipmi: fix long wait in unload when IPMI disconnect
In reply to Greg Kroah-HartmanFrom: Zhang Yuchen <[email protected]>
commit f6f1234d98cce69578bfac79df147a1f6660596c upstream.
When fixing the problem mentioned in PATCH1, we also found the following problem:
If the IPMI is disconnected and in the sending process, the uninstallation driver will be stuck for a long time.
The main problem is that uninstalling the driver waits for curr_msg to be sent or HOSED. After stopping tasklet, the only place to trigger the timeout mechanism is the circular poll in shutdown_smi.
The poll function delays 10us and calls smi_event_handler(smi_info,10). Smi_event_handler deducts 10us from kcs->ibf_timeout.
But the poll func is followed by schedule_timeout_uninterruptible(1). The time consumed here is not counted in kcs->ibf_timeout.
So when 10us is deducted from kcs->ibf_timeout, at least 1 jiffies has actually passed. The waiting time has increased by more than a hundredfold.
Now instead of calling poll(). call smi_event_handler() directly and calculate the elapsed time.
For verification, you can directly use ebpf to check the kcs-> ibf_timeout for each call to kcs_event() when IPMI is disconnected. Decrement at normal rate before unloading. The decrement rate becomes very slow after unloading.
$ bpftrace -e 'kprobe:kcs_event {printf("kcs->ibftimeout : %d\n",
*(arg0+584));}'Message-Id: <[email protected]>
--- drivers/char/ipmi/ipmi_si_intf.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/char/ipmi/ipmi_si_intf.c +19 -8
@@ -2187,6 +2187,20 @@ skip_fallback_noirq: }module_init (init_ipmi_si); +static void wait_msg_processed (struct smi_info *smi_info) +{ +unsigned long jiffies_now; +long time_diff; + +while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { + jiffies_now = jiffies; + time_diff = (((long )jiffies_now - (long )smi_info->last_timeout_jiffies) + *SI_USEC_PER_JIFFY ); +smi_event_handler (smi_info, time_diff); +schedule_timeout_uninterruptible (1 ); + } +} +static void shutdown_smi (void *send_info) {struct smi_info *smi_info = send_info;
@@ -2221,16 +2235,13 @@ static void shutdown_smi(void *send_info* in the BMC. Note that timers and CPU interrupts are off, * so no need for locks. */ -while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { -poll (smi_info); -schedule_timeout_uninterruptible (1 ); - } +wait_msg_processed (smi_info); +if (smi_info->handlers)disable_si_irq (smi_info); -while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { -poll (smi_info); -schedule_timeout_uninterruptible (1 ); - } + +wait_msg_processed (smi_info); +if (smi_info->handlers) smi_info->handlers->cleanup (smi_info->si_sm);
Greg Kroah-Hartman
maintainerPATCH 396/521 ima: Fix a potential NULL pointer access in ima_restore_measurement_list
In reply to Greg Kroah-HartmanFrom: Huaxin Lu <[email protected]>
commit 11220db412edae8dba58853238f53258268bdb88 upstream.
In restore_template_fmt, when kstrdup fails, a non-NULL value will still be returned, which causes a NULL pointer access in template_desc_init_fields.
--- security/integrity/ima/ima_template.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
security/integrity/ima/ima_template.c +4 -1
@@ -266,8 +266,11 @@ static struct ima_template_desc *restore template_desc->name ="" ; template_desc->fmt =kstrdup (template_name,GFP_KERNEL ); -if (!template_desc->fmt) +if (!template_desc->fmt) { +kfree (template_desc); + template_desc =NULL ; goto out; + }spin_lock (&template_list);list_add_tail_rcu (&template_desc->list, &defined_templates);
Greg Kroah-Hartman
maintainerPATCH 397/521 ipmi: fix use after free in _ipmi_destroy_user()
In reply to Greg Kroah-HartmanFrom: Dan Carpenter <[email protected]>
commit a92ce570c81dc0feaeb12a429b4bc65686d17967 upstream.
The intf_free() function frees the "intf" pointer so we cannot dereference it again on the next line.
Message-Id: <Y3M8xa1drZv4CToE@kili>
--- drivers/char/ipmi/ipmi_msghandler.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/ipmi/ipmi_msghandler.c +3 -1
@@ -1219,6 +1219,7 @@ static void _ipmi_destroy_user(struct ipunsigned long flags;struct cmd_rcvr *rcvr;struct cmd_rcvr *rcvrs =NULL ; +struct module *owner;if (!acquire_ipmi_user (user, &i)) {/*
@@ -1278,8 +1279,9 @@ static void _ipmi_destroy_user(struct ipkfree (rcvr); } + owner = intf->owner;kref_put (&intf->refcount, intf_free); -module_put (intf->owner); +module_put (owner); }int ipmi_destroy_user (struct ipmi_user *user)
Greg Kroah-Hartman
maintainerPATCH 398/521 PCI: Fix pci_device_is_present() for VFs by checking PF
In reply to Greg Kroah-HartmanFrom: Michael S. Tsirkin <[email protected]>
commit 98b04dd0b4577894520493d96bc4623387767445 upstream.
pci_device_is_present() previously didn't work for VFs because it reads the Vendor and Device ID, which are 0xffff for VFs, which looks like they aren't present. Check the PF instead.
Wei Gong reported that if virtio I/O is in progress when the driver is unbound or "0" is written to /sys/.../sriov_numvfs, the virtio I/O operation hangs, which may result in output like this:
task:bash state:D stack: 0 pid: 1773 ppid: 1241 flags:0x00004002
Call Trace: schedule+0x4f/0xc0 blk_mq_freeze_queue_wait+0x69/0xa0 blk_mq_freeze_queue+0x1b/0x20 blk_cleanup_queue+0x3d/0xd0 virtblk_remove+0x3c/0xb0 [virtio_blk] virtio_dev_remove+0x4b/0x80 ... device_unregister+0x1b/0x60 unregister_virtio_device+0x18/0x30 virtio_pci_remove+0x41/0x80 pci_device_remove+0x3e/0xb0
This happened because pci_device_is_present(VF) returned "false" in virtio_pci_remove(), so it called virtio_break_device(). The broken vq meant that vring_interrupt() skipped the vq.callback() that would have completed the virtio I/O operation via virtblk_done().
--- drivers/pci/pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/pci.c +2 -0
@@ -5815,6 +5815,8 @@ bool pci_device_is_present(struct pci_de {u32 v; +/* Check PF if pdev is a VF, since VF Vendor/Device IDs are 0xffff */ + pdev =pci_physfn (pdev);if (pci_dev_is_disconnected (pdev))return false;return pci_bus_read_dev_vendor_id (pdev->bus, pdev->devfn, &v,0 );
Greg Kroah-Hartman
maintainerPATCH 399/521 PCI/sysfs: Fix double free in error path
In reply to Greg Kroah-HartmanFrom: Sascha Hauer <[email protected]>
commit aa382ffa705bea9931ec92b6f3c70e1fdb372195 upstream.
When pci_create_attr() fails, pci_remove_resource_files() is called which will iterate over the res_attr[_wc] arrays and frees every non NULL entry. To avoid a double free here set the array entry only after it's clear we successfully initialized it.
--- drivers/pci/pci-sysfs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/pci/pci-sysfs.c +9 -4
@@ -1289,11 +1289,9 @@ static int pci_create_attr(struct pci_desysfs_bin_attr_init (res_attr);if (write_combine) { - pdev->res_attr_wc[num] = res_attr;sprintf (res_attr_name,"resource%d_wc" , num); res_attr->mmap = pci_mmap_resource_wc; }else { - pdev->res_attr[num] = res_attr;sprintf (res_attr_name,"resource%d" , num);if (pci_resource_flags (pdev, num) &IORESOURCE_IO ) { res_attr->read = pci_read_resource_io;
@@ -1309,10 +1307,17 @@ static int pci_create_attr(struct pci_de res_attr->size =pci_resource_len (pdev, num); res_attr->private = (void *)(unsigned long )num; retval =sysfs_create_bin_file (&pdev->dev.kobj, res_attr); -if (retval) +if (retval) {kfree (res_attr); +return retval; + } + +if (write_combine) + pdev->res_attr_wc[num] = res_attr; +else + pdev->res_attr[num] = res_attr; -return retval; +return 0 ; }/**
Greg Kroah-Hartman
maintainerPATCH 400/521 crypto: n2 - add missing hash statesize
In reply to Greg Kroah-HartmanFrom: Corentin Labbe <[email protected]>
commit 76a4e874593543a2dff91d249c95bac728df2774 upstream.
Add missing statesize to hash templates.
This is mandatory otherwise no algorithms can be registered as the core requires statesize to be set.
--- drivers/crypto/n2_core.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/crypto/n2_core.c +6 -0
@@ -1286,6 +1286,7 @@ struct n2_hash_tmpl {const u32 *hash_init;u8 hw_op_hashsz;u8 digest_size; +u8 statesize;u8 block_size;u8 auth_type;u8 hmac_type;
@@ -1317,6 +1318,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_MD5, .hw_op_hashsz = MD5_DIGEST_SIZE, .digest_size = MD5_DIGEST_SIZE, + .statesize = sizeof(struct md5_state), .block_size = MD5_HMAC_BLOCK_SIZE }, { .name = "sha1", .hash_zero = sha1_zero_message_hash,
@@ -1325,6 +1327,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_SHA1, .hw_op_hashsz = SHA1_DIGEST_SIZE, .digest_size = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct sha1_state), .block_size = SHA1_BLOCK_SIZE }, { .name = "sha256", .hash_zero = sha256_zero_message_hash,
@@ -1333,6 +1336,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_SHA256, .hw_op_hashsz = SHA256_DIGEST_SIZE, .digest_size = SHA256_DIGEST_SIZE, + .statesize = sizeof(struct sha256_state), .block_size = SHA256_BLOCK_SIZE }, { .name = "sha224", .hash_zero = sha224_zero_message_hash,
@@ -1341,6 +1345,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_RESERVED, .hw_op_hashsz = SHA256_DIGEST_SIZE, .digest_size = SHA224_DIGEST_SIZE, + .statesize = sizeof(struct sha256_state), .block_size = SHA224_BLOCK_SIZE }, };#define NUM_HASH_TMPLS ARRAY_SIZE(hash_tmpls)
@@ -1482,6 +1487,7 @@ static int __n2_register_one_ahash(const halg = &ahash->halg; halg->digestsize = tmpl->digest_size; + halg->statesize = tmpl->statesize; base = &halg->base;snprintf (base->cra_name,CRYPTO_MAX_ALG_NAME ,"%s" , tmpl->name);
Greg Kroah-Hartman
maintainerPATCH 401/521 iommu/amd: Fix ivrs_acpihid cmdline parsing code
In reply to Greg Kroah-HartmanFrom: Kim Phillips <[email protected]>
commit 5f18e9f8868c6d4eae71678e7ebd4977b7d8c8cf upstream.
The second (UID) strcmp in acpi_dev_hid_uid_match considers "0" and "00" different, which can prevent device registration.
Have the AMD IOMMU driver's ivrs_acpihid parsing code remove any leading zeroes to make the UID strcmp succeed. Now users can safely specify "AMDxxxxx:00" or "AMDxxxxx:0" and expect the same behaviour.
--- drivers/iommu/amd_iommu_init.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/iommu/amd_iommu_init.c +7 -0
@@ -2946,6 +2946,13 @@ static int __init parse_ivrs_acpihid(chareturn 1 ; } +/* +* Ignore leading zeroes after ':', so e.g., AMDI0095:00 +* will match AMDI0095:0 in the second strcmp in acpi_dev_hid_uid_match +*/ +while (*uid =='0' && *(uid +1 )) + uid++; + i = early_acpihid_map_size++;memcpy (early_acpihid_map[i].hid, hid,strlen (hid));memcpy (early_acpihid_map[i].uid, uid,strlen (uid));
Greg Kroah-Hartman
maintainerPATCH 402/521 parisc: led: Fix potential null-ptr-deref in start_task()
In reply to Greg Kroah-HartmanFrom: Shang XiaoJing <[email protected]>
commit 41f563ab3c33698bdfc3403c7c2e6c94e73681e4 upstream.
start_task() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:
start_task()
create_singlethread_workqueue() # failed, led_wq is NULL queue_delayed_work()
queue_delayed_work_on()
__queue_delayed_work() # warning here, but continue
__queue_work() # access wq->flags, null-ptr-deref
Check the ret value and return -ENOMEM if it is NULL.
--- drivers/parisc/led.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/parisc/led.c +3 -0
@@ -141,6 +141,9 @@ static int start_task(void)/* Create the work queue and queue the LED task */ led_wq =create_singlethread_workqueue ("led_wq" ); +if (!led_wq) +return -ENOMEM ; +queue_delayed_work (led_wq, &led_task,0 );return 0 ;
Greg Kroah-Hartman
maintainerPATCH 403/521 device_cgroup: Roll back to original exceptions after copy failure
In reply to Greg Kroah-HartmanFrom: Wang Weiyang <[email protected]>
commit e68bfbd3b3c3a0ec3cf8c230996ad8cabe90322f upstream.
When add the 'a *:* rwm' entry to devcgroup A's whitelist, at first A's exceptions will be cleaned and A's behavior is changed to DEVCG_DEFAULT_ALLOW. Then parent's exceptions will be copyed to A's whitelist. If copy failure occurs, just return leaving A to grant permissions to all devices. And A may grant more permissions than parent.
Backup A's whitelist and recover original exceptions after copy failure.
--- security/device_cgroup.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
security/device_cgroup.c +29 -4
@@ -79,6 +79,17 @@ free_and_exit:return -ENOMEM ; } +static void dev_exceptions_move (struct list_head *dest,struct list_head *orig) +{ +struct dev_exception_item *ex, *tmp; + +lockdep_assert_held (&devcgroup_mutex); + +list_for_each_entry_safe (ex, tmp, orig, list) { +list_move_tail (&ex->list, dest); + } +} +/* * called under devcgroup_mutex */
@@ -600,11 +611,13 @@ static int devcgroup_update_access(strucint count, rc =0 ;struct dev_exception_item ex;struct dev_cgroup *parent =css_to_devcgroup (devcgroup->css.parent); +struct dev_cgroup tmp_devcgrp;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;memset (&ex,0 ,sizeof (ex)); +memset (&tmp_devcgrp,0 ,sizeof (tmp_devcgrp)); b = buffer;switch (*b) {
@@ -616,15 +629,27 @@ static int devcgroup_update_access(strucif (!may_allow_all (parent))return -EPERM ; -dev_exception_clean (devcgroup); - devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; -if (!parent) +if (!parent) { + devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; +dev_exception_clean (devcgroup);break ; + } +INIT_LIST_HEAD (&tmp_devcgrp.exceptions); + rc =dev_exceptions_copy (&tmp_devcgrp.exceptions, + &devcgroup->exceptions); +if (rc) +return rc; +dev_exception_clean (devcgroup); rc =dev_exceptions_copy (&devcgroup->exceptions, &parent->exceptions); -if (rc) +if (rc) { +dev_exceptions_move (&devcgroup->exceptions, + &tmp_devcgrp.exceptions);return rc; + } + devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; +dev_exception_clean (&tmp_devcgrp);break ;case DEVCG_DENY :if (css_has_online_children (&devcgroup->css))
Greg Kroah-Hartman
maintainerPATCH 404/521 drm/connector: send hotplug uevent on connector cleanup
In reply to Greg Kroah-HartmanFrom: Simon Ser <[email protected]>
commit 6fdc2d490ea1369d17afd7e6eb66fecc5b7209bc upstream.
A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:
1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.
The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.
Fix this by sending a hotplug uevent from drm_connector_cleanup().
--- drivers/gpu/drm/drm_connector.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_connector.c +3 -0
@@ -413,6 +413,9 @@ void drm_connector_cleanup(struct drm_comutex_destroy (&connector->mutex);memset (connector,0 ,sizeof (*connector)); + +if (dev->registered) +drm_sysfs_hotplug_event (dev); }EXPORT_SYMBOL (drm_connector_cleanup);
Greg Kroah-Hartman
maintainerPATCH 405/521 drm/vmwgfx: Validate the box size for the snooped cursor
In reply to Greg Kroah-HartmanFrom: Zack Rusin <[email protected]>
commit 4cf949c7fafe21e085a4ee386bb2dade9067316e upstream.
Invalid userspace dma surface copies could potentially overflow the memcpy from the surface to the snooped image leading to crashes. To fix it the dimensions of the copybox have to be validated against the expected size of the snooped cursor.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +2 -1
@@ -179,7 +179,8 @@ void vmw_kms_cursor_snoop(struct vmw_surif (cmd->dma.guest.ptr.offset %PAGE_SIZE || box->x !=0 || box->y !=0 || box->z !=0 || box->srcx !=0 || box->srcy !=0 || box->srcz !=0 || - box->d !=1 || box_count !=1 ) { + box->d !=1 || box_count !=1 || + box->w >64 || box->h >64 ) {/* TODO handle none page aligned offsets */ /* TODO handle more dst & src != 0 */ /* TODO handle more then one copy */
Greg Kroah-Hartman
maintainerPATCH 406/521 ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit eee22187b53611e173161e38f61de1c7ecbeb876 upstream.
In do_writepages, if the value returned by ext4_writepages is "-ENOMEM" and "wbc->sync_mode == WB_SYNC_ALL", retry until the condition is not met.
In __ext4_get_inode_loc, if the bh returned by sb_getblk is NULL, the function returns -ENOMEM.
In __getblk_slow, if the return value of grow_buffers is less than 0, the function returns NULL.
When the three processes are connected in series like the following stack, an infinite loop may occur:
do_writepages <--- keep retrying
ext4_writepages
mpage_map_and_submit_extent
mpage_map_one_extent
ext4_map_blocks
ext4_ext_map_blocks
ext4_ext_handle_unwritten_extents
ext4_ext_convert_to_initialized
ext4_split_extent
ext4_split_extent_at
__ext4_ext_dirty
__ext4_mark_inode_dirty
ext4_reserve_inode_write
ext4_get_inode_loc
__ext4_get_inode_loc <--- return -ENOMEM
sb_getblk
__getblk_gfp
__getblk_slow <--- return NULL
grow_buffers
grow_dev_page <--- return -ENXIO
ret = (block < end_block) ? 1 : -ENXIO;In this issue, bg_inode_table_hi is overwritten as an incorrect value. As a result, block < end_block cannot be met in grow_dev_page. Therefore, __ext4_get_inode_loc always returns '-ENOMEM' and do_writepages keeps retrying. As a result, the writeback process is in the D state due to an infinite loop.
Add a check on inode table block in the __ext4_get_inode_loc function by referring to ext4_read_inode_bitmap to avoid this infinite loop.
--- fs/ext4/inode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/ext4/inode.c +9 -1
@@ -4663,9 +4663,17 @@ static int __ext4_get_inode_loc(struct i inodes_per_block =EXT4_SB (sb)->s_inodes_per_block; inode_offset = ((inode->i_ino -1 ) %EXT4_INODES_PER_GROUP (sb)); - block =ext4_inode_table (sb, gdp) + (inode_offset / inodes_per_block); iloc->offset = (inode_offset % inodes_per_block) *EXT4_INODE_SIZE (sb); + block =ext4_inode_table (sb, gdp); +if ((block <=le32_to_cpu (EXT4_SB (sb)->s_es->s_first_data_block)) || + (block >=ext4_blocks_count (EXT4_SB (sb)->s_es))) { +ext4_error (sb,"Invalid inode table block %llu in " +"block_group %u" , block, iloc->block_group); +return -EFSCORRUPTED ; + } + block += (inode_offset / inodes_per_block); + bh =sb_getblk (sb, block);if (unlikely (!bh))return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 407/521 ext4: fix undefined behavior in bit shift for ext4_check_flag_values
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
commit 3bf678a0f9c017c9ba7c581541dbc8453452a7ae upstream.
Shifting signed 32-bit value by 31 bits is undefined, so changing significant bit to unsigned. The UBSAN warning calltrace like below:
UBSAN: shift-out-of-bounds in fs/ext4/ext4.h:591:2 left shift of 1 by 31 places cannot be represented in type 'int' Call Trace: <TASK> dump_stack_lvl+0x7d/0xa5 dump_stack+0x15/0x1b ubsan_epilogue+0xe/0x4e __ubsan_handle_shift_out_of_bounds+0x1e7/0x20c ext4_init_fs+0x5a/0x277 do_one_initcall+0x76/0x430 kernel_init_freeable+0x3b3/0x422 kernel_init+0x24/0x1e0 ret_from_fork+0x1f/0x30 </TASK>
--- fs/ext4/ext4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4.h +1 -1
@@ -503,7 +503,7 @@ enum {* * It's not paranoia if the Murphy's Law really *is* out to get you. :-) */ -#define TEST_FLAG_VALUE (FLAG ) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) +#define TEST_FLAG_VALUE (FLAG ) (EXT4_##FLAG##_FL == (1U << EXT4_INODE_##FLAG))#define CHECK_FLAG_VALUE (FLAG ) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG))static inline void ext4_check_flag_values (void )
Greg Kroah-Hartman
maintainerPATCH 408/521 ext4: add helper to check quota inums
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 07342ec259df2a35d6a34aebce010567a80a0e15 upstream.
Before quota is enabled, a check on the preset quota inums in ext4_super_block is added to prevent wrong quota inodes from being loaded. In addition, when the quota fails to be enabled, the quota type and quota inum are printed to facilitate fault locating.
--- fs/ext4/super.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
fs/ext4/super.c +25 -3
@@ -5839,6 +5839,20 @@ static int ext4_quota_on(struct super_blreturn err; } +static inline bool ext4_check_quota_inum (int type,unsigned long qf_inum) +{ +switch (type) { +case USRQUOTA : +return qf_inum ==EXT4_USR_QUOTA_INO ; +case GRPQUOTA : +return qf_inum ==EXT4_GRP_QUOTA_INO ; +case PRJQUOTA : +return qf_inum >=EXT4_GOOD_OLD_FIRST_INO ; +default : +BUG (); + } +} +static int ext4_quota_enable (struct super_block *sb,int type,int format_id,unsigned int flags) {
@@ -5855,9 +5869,16 @@ static int ext4_quota_enable(struct supeif (!qf_inums[type])return -EPERM ; +if (!ext4_check_quota_inum (type, qf_inums[type])) { +ext4_error (sb,"Bad quota inum: %lu, type: %d" , + qf_inums[type], type); +return -EUCLEAN ; + } + qf_inode =ext4_iget (sb, qf_inums[type],EXT4_IGET_SPECIAL );if (IS_ERR (qf_inode)) { -ext4_error (sb,"Bad quota inode # %lu" , qf_inums[type]); +ext4_error (sb,"Bad quota inode: %lu, type: %d" , + qf_inums[type], type);return PTR_ERR (qf_inode); }
@@ -5896,8 +5917,9 @@ static int ext4_enable_quotas(struct supif (err) {ext4_warning (sb,"Failed to enable quota tracking " -"(type=%d, err=%d). Please run " -"e2fsck to fix." , type, err); +"(type=%d, err=%d, ino=%lu). " +"Please run e2fsck to fix." , type, + err, qf_inums[type]);for (type--; type >=0 ; type--) {struct inode *inode;
Greg Kroah-Hartman
maintainerPATCH 409/521 ext4: fix bug_on in __es_tree_search caused by bad boot loader inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 991ed014de0840c5dc405b679168924afb2952ac upstream.
We got a issue as fllows:
==================================================================
kernel BUG at fs/ext4/extents_status.c:203!
invalid opcode: 0000 [#1] PREEMPT SMP
CPU: 1 PID: 945 Comm: cat Not tainted 6.0.0-next-20221007-dirty #349 RIP: 0010:ext4_es_end.isra.0+0x34/0x42 RSP: 0018:ffffc9000143b768 EFLAGS: 00010203 RAX: 0000000000000000 RBX: ffff8881769cd0b8 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff8fc27cf7 RDI: 00000000ffffffff RBP: ffff8881769cd0bc R08: 0000000000000000 R09: ffffc9000143b5f8 R10: 0000000000000001 R11: 0000000000000001 R12: ffff8881769cd0a0 R13: ffff8881768e5668 R14: 00000000768e52f0 R15: 0000000000000000 FS: 00007f359f7f05c0(0000)GS:ffff88842fd00000(0000)knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f359f5a2000 CR3: 000000017130c000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> __es_tree_search.isra.0+0x6d/0xf5 ext4_es_cache_extent+0xfa/0x230 ext4_cache_extents+0xd2/0x110 ext4_find_extent+0x5d5/0x8c0 ext4_ext_map_blocks+0x9c/0x1d30 ext4_map_blocks+0x431/0xa50 ext4_mpage_readpages+0x48e/0xe40 ext4_readahead+0x47/0x50 read_pages+0x82/0x530 page_cache_ra_unbounded+0x199/0x2a0 do_page_cache_ra+0x47/0x70 page_cache_ra_order+0x242/0x400 ondemand_readahead+0x1e8/0x4b0 page_cache_sync_ra+0xf4/0x110 filemap_get_pages+0x131/0xb20 filemap_read+0xda/0x4b0 generic_file_read_iter+0x13a/0x250 ext4_file_read_iter+0x59/0x1d0 vfs_read+0x28f/0x460 ksys_read+0x73/0x160 __x64_sys_read+0x1e/0x30 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK> ==================================================================
In the above issue, ioctl invokes the swap_inode_boot_loader function to swap inode<5> and inode<12>. However, inode<5> contain incorrect imode and disordered extents, and i_nlink is set to 1. The extents check for inode in the ext4_iget function can be bypassed bacause 5 is EXT4_BOOT_LOADER_INO. While links_count is set to 1, the extents are not initialized in swap_inode_boot_loader. After the ioctl command is executed successfully, the extents are swapped to inode<12>, in this case, run the cat command to view inode<12>. And Bug_ON is triggered due to the incorrect extents.
When the boot loader inode is not initialized, its imode can be one of the following:
1) the imode is a bad type, which is marked as bad_inode in ext4_iget and set to S_IFREG.
2) the imode is good type but not S_IFREG.
3) the imode is S_IFREG.
The BUG_ON may be triggered by bypassing the check in cases 1 and 2. Therefore, when the boot loader inode is bad_inode or its imode is not S_IFREG, initialize the inode to avoid triggering the BUG.
--- fs/ext4/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ioctl.c +1 -1
@@ -169,7 +169,7 @@ static long swap_inode_boot_loader(struc/* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem (inode, inode_bl); -if (inode_bl->i_nlink ==0 ) { +if (is_bad_inode (inode_bl) || !S_ISREG (inode_bl->i_mode)) {/* this inode has never been used as a BOOT_LOADER */ set_nlink (inode_bl,1 );i_uid_write (inode_bl,0 );
Greg Kroah-Hartman
maintainerPATCH 410/521 ext4: init quota for old.inode in ext4_rename
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit fae381a3d79bb94aa2eb752170d47458d778b797 upstream.
Syzbot found the following issue:ext4_parse_param: s_want_extra_isize=128ext4_inode_info_init: s_want_extra_isize=32ext4_rename: old.inode=ffff88823869a2c8 old.dir=ffff888238699828 new.inode=ffff88823869d7e8 new.dir=ffff888238699828 __ext4_mark_inode_dirty: inode=ffff888238699828 ea_isize=32 want_ea_size=128 __ext4_mark_inode_dirty: inode=ffff88823869a2c8 ea_isize=32 want_ea_size=128ext4_xattr_block_set: inode=ffff88823869a2c8
------------[ cut here ]------------ WARNING: CPU: 13 PID: 2234 at fs/ext4/xattr.c:2070 ext4_xattr_block_set.cold+0x22/0x980 Modules linked in: RIP: 0010:ext4_xattr_block_set.cold+0x22/0x980 RSP: 0018:ffff888227d3f3b0 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff88823007a000 RCX: 0000000000000000 RDX: 0000000000000a03 RSI: 0000000000000040 RDI: ffff888230078178 RBP: 0000000000000000 R08: 000000000000002c R09: ffffed1075c7df8e R10: ffff8883ae3efc6b R11: ffffed1075c7df8d R12: 0000000000000000 R13: ffff88823869a2c8 R14: ffff8881012e0460 R15: dffffc0000000000 FS: 00007f350ac1f740(0000) GS:ffff8883ae200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f350a6ed6a0 CR3: 0000000237456000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> ? ext4_xattr_set_entry+0x3b7/0x2320 ? ext4_xattr_block_set+0x0/0x2020 ? ext4_xattr_set_entry+0x0/0x2320 ? ext4_xattr_check_entries+0x77/0x310 ? ext4_xattr_ibody_set+0x23b/0x340 ext4_xattr_move_to_block+0x594/0x720 ext4_expand_extra_isize_ea+0x59a/0x10f0 __ext4_expand_extra_isize+0x278/0x3f0 __ext4_mark_inode_dirty.cold+0x347/0x410 ext4_rename+0xed3/0x174f vfs_rename+0x13a7/0x2510 do_renameat2+0x55d/0x920 __x64_sys_rename+0x7d/0xb0 do_syscall_64+0x3b/0xa0 entry_SYSCALL_64_after_hwframe+0x72/0xdc
As 'ext4_rename' will modify 'old.inode' ctime and mark inode dirty, which may trigger expand 'extra_isize' and allocate block. If inode didn't init quota will lead to warning. To solve above issue, init 'old.inode' firstly in 'ext4_rename'.
--- fs/ext4/namei.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/namei.c +3 -0
@@ -3870,6 +3870,9 @@ static int ext4_cross_rename(struct inod retval =dquot_initialize (old.dir);if (retval)return retval; + retval =dquot_initialize (old.inode); +if (retval) +return retval; retval =dquot_initialize (new.dir);if (retval)return retval;
Greg Kroah-Hartman
maintainerPATCH 411/521 ext4: fix corruption when online resizing a 1K bigalloc fs
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 0aeaa2559d6d53358fca3e3fce73807367adca74 upstream.
When a backup superblock is updated in update_backups(), the primary superblock's offset in the group (that is, sbi->s_sbh->b_blocknr) is used as the backup superblock's offset in its group. However, when the block size is 1K and bigalloc is enabled, the two offsets are not equal. This causes the backup group descriptors to be overwritten by the superblock in update_backups(). Moreover, if meta_bg is enabled, the file system will be corrupted because this feature uses backup group descriptors.
To solve this issue, we use a more accurate ext4_group_first_block_no() as the offset of the backup superblock in its group.
--- fs/ext4/resize.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ext4/resize.c +3 -3
@@ -1567,8 +1567,8 @@ exit_journal:int meta_bg =ext4_has_feature_meta_bg (sb);sector_t old_gdb =0 ; -update_backups (sb, sbi->s_sbh->b_blocknr, (char *)es, -sizeof (struct ext4_super_block ),0 ); +update_backups (sb,ext4_group_first_block_no (sb,0 ), + (char *)es,sizeof (struct ext4_super_block ),0 );for (; gdb_num <= gdb_num_end; gdb_num++) {struct buffer_head *gdb_bh;
@@ -1775,7 +1775,7 @@ errout:if (test_opt (sb,DEBUG ))printk (KERN_DEBUG "EXT4-fs: extended group to %llu " "blocks\n" ,ext4_blocks_count (es)); -update_backups (sb,EXT4_SB (sb)->s_sbh->b_blocknr, +update_backups (sb,ext4_group_first_block_no (sb,0 ), (char *)es,sizeof (struct ext4_super_block ),0 ); }return err;
Greg Kroah-Hartman
maintainerPATCH 412/521 ext4: fix error code return to user-space in ext4_get_branch()
In reply to Greg Kroah-HartmanFrom: Luís Henriques <[email protected]>
commit 26d75a16af285a70863ba6a81f85d81e7e65da50 upstream.
If a block is out of range in ext4_get_branch(), -ENOMEM will be returned to user-space. Obviously, this error code isn't really useful. This patch fixes it by making sure the right error code (-EFSCORRUPTED) is propagated to user-space. EUCLEAN is more informative than ENOMEM.
--- fs/ext4/indirect.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/ext4/indirect.c +8 -1
@@ -148,6 +148,7 @@ static Indirect *ext4_get_branch(structstruct super_block *sb = inode->i_sb;Indirect *p = chain;struct buffer_head *bh; +unsigned int key;int ret = -EIO ; *err =0 ;
@@ -156,7 +157,13 @@ static Indirect *ext4_get_branch(structif (!p->key) goto no_block;while (--depth) { - bh =sb_getblk (sb,le32_to_cpu (p->key)); + key =le32_to_cpu (p->key); +if (key >ext4_blocks_count (EXT4_SB (sb)->s_es)) { +/* the block was out of range */ + ret = -EFSCORRUPTED ; + goto failure; + } + bh =sb_getblk (sb, key);if (unlikely (!bh)) { ret = -ENOMEM ; goto failure;
Greg Kroah-Hartman
maintainerPATCH 413/521 ext4: avoid BUG_ON when creating xattrs
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit b40ebaf63851b3a401b0dc9263843538f64f5ce6 upstream.
Commit fb0a387dcdcd ("ext4: limit block allocations for indirect-block files to < 2^32") added code to try to allocate xattr block with 32-bit block number for indirect block based files on the grounds that these files cannot use larger block numbers. It also added BUG_ON when allocated block could not fit into 32 bits. This is however bogus reasoning because xattr block is stored in inode->i_file_acl and inode->i_file_acl_hi and as such even indirect block based files can happily use full 48 bits for xattr block number. The proper handling seems to be there basically since 64-bit block number support was added. So remove the bogus limitation and BUG_ON.
--- fs/ext4/xattr.c | 8 -------- 1 file changed, 8 deletions(-)
fs/ext4/xattr.c +0 -8
@@ -2070,19 +2070,11 @@ inserted: goal =ext4_group_first_block_no (sb,EXT4_I (inode)->i_block_group); - -/* non-extent files can't have physical blocks past 2^32 */ -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) - goal = goal &EXT4_MAX_BLOCK_FILE_PHYS ; - block =ext4_new_meta_blocks (handle, inode, goal,0 ,NULL , &error);if (error) goto cleanup; -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) -BUG_ON (block >EXT4_MAX_BLOCK_FILE_PHYS ); -ea_idebug (inode,"creating block %llu" , (unsigned long long )block);
Greg Kroah-Hartman
maintainerPATCH 414/521 ext4: fix inode leak in ext4_xattr_inode_create() on an error path
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit e4db04f7d3dbbe16680e0ded27ea2a65b10f766a upstream.
There is issue as follows when do setxattr with inject fault:
[localhost]# fsck.ext4 -fn /dev/sda
e2fsck 1.46.6-rc1 (12-Sep-2022)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Unattached zero-length inode 15. Clear? no
Unattached inode 15
Connect to /lost+found? no
Pass 5: Checking group summary information
/dev/sda: ********** WARNING: Filesystem still has errors **********
/dev/sda: 15/655360 files (0.0% non-contiguous), 66755/2621440 blocks
This occurs in 'ext4_xattr_inode_create()'. If 'ext4_mark_inode_dirty()' fails, dropping i_nlink of the inode is needed. Or will lead to inode leak.
--- fs/ext4/xattr.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/xattr.c +3 -0
@@ -1446,6 +1446,9 @@ static struct inode *ext4_xattr_inode_crif (!err) err =ext4_inode_attach_jinode (ea_inode);if (err) { +if (ext4_xattr_inode_dec_ref (handle, ea_inode)) +ext4_warning_inode (ea_inode, +"cleanup dec ref error %d" , err);iput (ea_inode);return ERR_PTR (err); }
Greg Kroah-Hartman
maintainerPATCH 415/521 ext4: initialize quota before expanding inode in setproject ioctl
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit 1485f726c6dec1a1f85438f2962feaa3d585526f upstream.
Make sure we initialize quotas before possibly expanding inode space (and thus maybe needing to allocate external xattr block) in ext4_ioctl_setproject(). This prevents not accounting the necessary block allocation.
--- fs/ext4/ioctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ext4/ioctl.c +4 -4
@@ -449,6 +449,10 @@ static int ext4_ioctl_setproject(structif (ext4_is_quota_file (inode))return err; + err =dquot_initialize (inode); +if (err) +return err; + err =ext4_get_inode_loc (inode, &iloc);if (err)return err;
@@ -464,10 +468,6 @@ static int ext4_ioctl_setproject(structbrelse (iloc.bh); } - err =dquot_initialize (inode); -if (err) -return err; - handle =ext4_journal_start (inode,EXT4_HT_QUOTA ,EXT4_QUOTA_INIT_BLOCKS (sb) +EXT4_QUOTA_DEL_BLOCKS (sb) +3 );
Greg Kroah-Hartman
maintainerPATCH 416/521 ext4: avoid unaccounted block allocation when expanding inode
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit 8994d11395f8165b3deca1971946f549f0822630 upstream.
When expanding inode space in ext4_expand_extra_isize_ea() we may need to allocate external xattr block. If quota is not initialized for the inode, the block allocation will not be accounted into quota usage. Make sure the quota is initialized before we try to expand inode space.
--- fs/ext4/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ext4/inode.c +8 -0
@@ -6041,6 +6041,14 @@ static int __ext4_expand_extra_isize(strreturn 0 ; } +/* +* We may need to allocate external xattr block so we need quotas +* initialized. Here we can be called with various locks held so we +* cannot affort to initialize quotas ourselves. So just bail. +*/ +if (dquot_initialize_needed (inode)) +return -EAGAIN ; +/* try to expand with EAs present */ error =ext4_expand_extra_isize_ea (inode, new_extra_isize, raw_inode, handle);
Greg Kroah-Hartman
maintainerPATCH 417/521 ext4: allocate extended attribute value in vmalloc area
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit cc12a6f25e07ed05d5825a1664b67a970842b2ca upstream.
Now, extended attribute value maximum length is 64K. The memory requested here does not need continuous physical addresses, so it is appropriate to use kvmalloc to request memory. At the same time, it can also cope with the situation that the extended attribute will become longer in the future.
--- fs/ext4/xattr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/xattr.c +2 -2
@@ -2570,7 +2570,7 @@ static int ext4_xattr_move_to_block(hand is =kzalloc (sizeof (struct ext4_xattr_ibody_find ),GFP_NOFS ); bs =kzalloc (sizeof (struct ext4_xattr_block_find ),GFP_NOFS ); - buffer =kmalloc (value_size,GFP_NOFS ); + buffer =kvmalloc (value_size,GFP_NOFS ); b_entry_name =kmalloc (entry->e_name_len +1 ,GFP_NOFS );if (!is || !bs || !buffer || !b_entry_name) { error = -ENOMEM ;
@@ -2622,7 +2622,7 @@ static int ext4_xattr_move_to_block(hand error =0 ; out:kfree (b_entry_name); -kfree (buffer); +kvfree (buffer);if (is)brelse (is->iloc.bh);if (bs)
Greg Kroah-Hartman
maintainerPATCH 418/521 drm/amdgpu: make display pinning more flexible (v2)
In reply to Greg Kroah-HartmanFrom: Alex Deucher <[email protected]>
commit 81d0bcf9900932633d270d5bc4a54ff599c6ebdb upstream.
Only apply the static threshold for Stoney and Carrizo. This hardware has certain requirements that don't allow mixing of GTT and VRAM. Newer asics do not have these requirements so we should be able to be more flexible with where buffers end up.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
@@ -1387,7 +1387,8 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_buint32_t amdgpu_bo_get_preferred_pin_domain (struct amdgpu_device *adev,uint32_t domain) { -if (domain == (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) { +if ((domain == (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) && + ((adev->asic_type ==CHIP_CARRIZO ) || (adev->asic_type ==CHIP_STONEY ))) { domain =AMDGPU_GEM_DOMAIN_VRAM ;if (adev->gmc.real_vram_size <=AMDGPU_SG_THRESHOLD ) domain =AMDGPU_GEM_DOMAIN_GTT ;
Greg Kroah-Hartman
maintainerPATCH 419/521 btrfs: send: avoid unnecessary backref lookups when finding clone source
In reply to Greg Kroah-HartmanFrom: Filipe Manana <[email protected]>
[ Upstream commit 22a3c0ac8ed0043af209a15928ae4c4855b0a4c4 ]
At find_extent_clone(), unless we are given an inline extent, a file extent item that represents hole or an extent that starts beyond the i_size, we always do backref walking to look for clone sources, unless if we have more than SEND_MAX_EXTENT_REFS (64) known references on the extent.
However if we know we only have one reference in the extent item and only one clone source (the send root), then it's pointless to do the backref walking to search for clone sources, as we can't clone from any other root. So skip the backref walking in that case.
The following test was run on a non-debug kernel (Debian's default kernel config):
$ cat test.sh #!/bin/bash
DEV=/dev/sdi
MNT=/mnt/sdi
mkfs.btrfs -f $DEV
mount $DEV $MNT
# Create an extent tree that's not too small and none of the
# extents is shared.
for ((i = 1; i <= 50000; i++)); do
xfs_io -f -c "pwrite 0 4K" $MNT/file_$i > /dev/null
echo -ne "\r$i files created..."
done
echobtrfs subvolume snapshot -r $MNT $MNT/snap
start=$(date +%s%N) btrfs send $MNT/snap > /dev/null end=$(date +%s%N) dur=$(( (end - start) / 1000000 )) echo -e "\nsend took $dur milliseconds"
umount $MNT
Before this change:
send took 5389 milliseconds
After this change:
send took 4519 milliseconds (-16.1%)
Stable-dep-of: 63d5429f68a3 ("btrfs: replace strncpy() with strscpy()")
--- fs/btrfs/send.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/btrfs/send.c +10 -1
@@ -1306,6 +1306,7 @@ static int find_extent_clone(struct send_ctx *sctx,u64 disk_byte;u64 num_bytes;u64 extent_item_pos; +u64 extent_refs;u64 flags =0 ;struct btrfs_file_extent_item *fi;struct extent_buffer *eb = path->nodes[0 ];
@@ -1373,14 +1374,22 @@ static int find_extent_clone(struct send_ctx *sctx, ei =btrfs_item_ptr (tmp_path->nodes[0 ], tmp_path->slots[0 ], struct btrfs_extent_item); + extent_refs =btrfs_extent_refs (tmp_path->nodes[0 ], ei);/* * Backreference walking (iterate_extent_inodes() below) is currently * too expensive when an extent has a large number of references, both * in time spent and used memory. So for now just fallback to write * operations instead of clone operations when an extent has more than * a certain amount of references. +* +* Also, if we have only one reference and only the send root as a clone +* source - meaning no clone roots were given in the struct +* btrfs_ioctl_send_args passed to the send ioctl - then it's our +* reference and there's no point in doing backref walking which is +* expensive, so exit early. */ -if (btrfs_extent_refs (tmp_path->nodes[0 ], ei) >SEND_MAX_EXTENT_REFS ) { +if ((extent_refs ==1 && sctx->clone_roots_cnt ==1 ) || + extent_refs >SEND_MAX_EXTENT_REFS ) { ret = -ENOENT ; goto out; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 420/521 btrfs: replace strncpy() with strscpy()
In reply to Greg Kroah-Hartman[ Upstream commit 63d5429f68a3d4c4aa27e65a05196c17f86c41d6 ]
Using strncpy() on NUL-terminated strings are deprecated. To avoid possible forming of non-terminated string strscpy() should be used.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- fs/btrfs/ioctl.c | 9 +++------ fs/btrfs/rcu-string.h | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-)
fs/btrfs/ioctl.c +3 -6
@@ -3234,13 +3234,10 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info, di_args->bytes_used =btrfs_device_get_bytes_used (dev); di_args->total_bytes =btrfs_device_get_total_bytes (dev);memcpy (di_args->uuid, dev->uuid,sizeof (di_args->uuid)); -if (dev->name) { -strncpy (di_args->path,rcu_str_deref (dev->name), -sizeof (di_args->path) -1 ); - di_args->path[sizeof (di_args->path) -1 ] =0 ; - }else { +if (dev->name) +strscpy (di_args->path,rcu_str_deref (dev->name),sizeof (di_args->path)); +else di_args->path[0 ] ='\0' ; - } out:rcu_read_unlock ();
fs/btrfs/rcu-string.h +5 -1
@@ -18,7 +18,11 @@ static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask) (len * sizeof(char)), mask);if (!ret)return ret; -strncpy (ret->str, src, len); +/* Warn if the source got unexpectedly truncated. */ +if (WARN_ON (strscpy (ret->str, src, len) <0 )) { +kfree (ret); +return NULL ; + }return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 421/521 media: s5p-mfc: Fix to handle reference queue during finishing
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit d8a46bc4e1e0446459daa77c4ce14218d32dacf9 ]
On receiving last buffer driver puts MFC to MFCINST_FINISHING state which in turn skips transferring of frame from SRC to REF queue. This causes driver to stop MFC encoding and last frame is lost.
This patch guarantees safe handling of frames during MFCINST_FINISHING and correct clearing of workbit to avoid early stopping of encoding.
--- drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc_enc.c +10 -2
@@ -1224,6 +1224,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)unsigned long mb_y_addr, mb_c_addr;int slice_type;unsigned int strm_size; +bool src_ready; slice_type =s5p_mfc_hw_call (dev->mfc_ops, get_enc_slice_type, dev); strm_size =s5p_mfc_hw_call (dev->mfc_ops, get_enc_strm_size, dev);
@@ -1263,7 +1264,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) } } } -if ((ctx->src_queue_cnt >0 ) && (ctx->state ==MFCINST_RUNNING )) { +if (ctx->src_queue_cnt >0 && (ctx->state ==MFCINST_RUNNING || + ctx->state ==MFCINST_FINISHING )) { mb_entry = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);if (mb_entry->flags &MFC_BUF_FLAG_USED ) {
@@ -1294,7 +1296,13 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)vb2_set_plane_payload (&mb_entry->b->vb2_buf,0 , strm_size);vb2_buffer_done (&mb_entry->b->vb2_buf,VB2_BUF_STATE_DONE ); } -if ((ctx->src_queue_cnt ==0 ) || (ctx->dst_queue_cnt ==0 )) + + src_ready = true; +if (ctx->state ==MFCINST_RUNNING && ctx->src_queue_cnt ==0 ) + src_ready = false; +if (ctx->state ==MFCINST_FINISHING && ctx->ref_queue_cnt ==0 ) + src_ready = false; +if (!src_ready || ctx->dst_queue_cnt ==0 )clear_work_bit (ctx);return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 422/521 media: s5p-mfc: Clear workbit to handle error condition
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit d3f3c2fe54e30b0636496d842ffbb5ad3a547f9b ]
During error on CLOSE_INSTANCE command, ctx_work_bits was not getting cleared. During consequent mfc execution NULL pointer dereferencing of this context led to kernel panic. This patch fixes this issue by making sure to clear ctx_work_bits always.
--- drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c +3 -1
@@ -472,8 +472,10 @@ void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx)s5p_mfc_hw_call (dev->mfc_ops, try_run, dev);/* Wait until instance is returned or timeout occurred */ if (s5p_mfc_wait_for_done_ctx (ctx, -S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET ,0 )) +S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET ,0 )){ +clear_work_bit_irqsave (ctx);mfc_err ("Err returning instance\n" ); + }/* Free resources */ s5p_mfc_hw_call (dev->mfc_ops, release_codec_buffers, ctx);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 423/521 media: s5p-mfc: Fix in register read and write for H264
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit 06710cd5d2436135046898d7e4b9408c8bb99446 ]
Few of the H264 encoder registers written were not getting reflected since the read values were not stored and getting overwritten.
--- drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c +7 -7
@@ -1063,7 +1063,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx) }/* aspect ratio VUI */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<5 ); reg |= ((p_h264->vui_sar &0x1 ) <<5 );writel (reg, mfc_regs->e_h264_options);
@@ -1086,7 +1086,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)/* intra picture period for H.264 open GOP */ /* control */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<4 ); reg |= ((p_h264->open_gop &0x1 ) <<4 );writel (reg, mfc_regs->e_h264_options);
@@ -1100,23 +1100,23 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx) }/* 'WEIGHTED_BI_PREDICTION' for B is disable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x3 <<9 );writel (reg, mfc_regs->e_h264_options);/* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<14 );writel (reg, mfc_regs->e_h264_options);/* ASO */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<6 ); reg |= ((p_h264->aso &0x1 ) <<6 );writel (reg, mfc_regs->e_h264_options);/* hier qp enable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<8 ); reg |= ((p_h264->open_gop &0x1 ) <<8 );writel (reg, mfc_regs->e_h264_options);
@@ -1137,7 +1137,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)writel (reg, mfc_regs->e_h264_num_t_layer);/* frame packing SEI generation */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<25 ); reg |= ((p_h264->sei_frame_packing &0x1 ) <<25 );writel (reg, mfc_regs->e_h264_options);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 424/521 dm thin: resume even if in FAIL mode
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
[ Upstream commit 19eb1650afeb1aa86151f61900e9e5f1de5d8d02 ]
If a thinpool set fail_io while suspending, resume will fail with:
device-mapper: resume ioctl on vg-thinpool failed: Invalid argument
The thin-pool also can't be removed if an in-flight bio is in the deferred list.
This can be easily reproduced using:
echo "offline" > /sys/block/sda/device/state dd if=/dev/zero of=/dev/mapper/thin bs=4K count=1 dmsetup suspend /dev/mapper/pool mkfs.ext4 /dev/mapper/thin
dmsetup resume /dev/mapper/pool
The root cause is maybe_resize_data_dev() will check fail_io and return error before called dm_resume.
Fix this by adding FAIL mode check at the end of pool_preresume().
--- drivers/md/dm-thin.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/md/dm-thin.c +12 -4
@@ -3549,20 +3549,28 @@ static int pool_preresume(struct dm_target *ti)*/ r =bind_control_target (pool, ti);if (r) -return r; + goto out; r =maybe_resize_data_dev (ti, &need_commit1);if (r) -return r; + goto out; r =maybe_resize_metadata_dev (ti, &need_commit2);if (r) -return r; + goto out;if (need_commit1 || need_commit2) (void )commit (pool); +out: +/* +* When a thin-pool is PM_FAIL, it cannot be rebuilt if +* bio is in deferred list. Therefore need to return 0 +* to allow pool_resume() to flush IO. +*/ +if (r &&get_pool_mode (pool) ==PM_FAIL ) + r =0 ; -return 0 ; +return r; }static void pool_suspend_active_thins (struct pool *pool)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 425/521 perf probe: Use dwarf_attr_integrate as generic DWARF attr accessor
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit f828929ab7f0dc3353e4a617f94f297fa8f3dec3 ]
Use dwarf_attr_integrate() instead of dwarf_attr() for generic attribute acccessor functions, so that it can find the specified attribute from abstact origin DIE etc.
Stable-dep-of: a9dfc46c67b5 ("perf probe: Fix to get the DW_AT_decl_file and DW_AT_call_file as unsinged data")
--- tools/perf/util/dwarf-aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/dwarf-aux.c +2 -2
@@ -267,7 +267,7 @@ static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name, {Dwarf_Attribute attr; -if (dwarf_attr (tp_die, attr_name, &attr) ==NULL || +if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL ||dwarf_formudata (&attr, result) !=0 )return -ENOENT ;
@@ -280,7 +280,7 @@ static int die_get_attr_sdata(Dwarf_Die *tp_die, unsigned int attr_name, {Dwarf_Attribute attr; -if (dwarf_attr (tp_die, attr_name, &attr) ==NULL || +if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL ||dwarf_formsdata (&attr, result) !=0 )return -ENOENT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 426/521 perf probe: Fix to get the DW_AT_decl_file and DW_AT_call_file as unsinged data
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit a9dfc46c67b52ad43b8e335e28f4cf8002c67793 ]
DWARF version 5 standard Sec 2.14 says that
Any debugging information entry representing the declaration of an object, module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and DW_AT_decl_column attributes, each of whose value is an unsigned integer constant.
So it should be an unsigned integer data. Also, even though the standard doesn't clearly say the DW_AT_call_file is signed or unsigned, the elfutils (eu-readelf) interprets it as unsigned integer data and it is natural to handle it as unsigned integer data as same as DW_AT_decl_file. This changes the DW_AT_call_file as unsigned integer data too.
--- tools/perf/util/dwarf-aux.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
tools/perf/util/dwarf-aux.c +4 -17
@@ -274,19 +274,6 @@ static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name,return 0 ; } -/* Get attribute and translate it as a sdata */ -static int die_get_attr_sdata (Dwarf_Die *tp_die,unsigned int attr_name, -Dwarf_Sword *result) -{ -Dwarf_Attribute attr; - -if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL || -dwarf_formsdata (&attr, result) !=0 ) -return -ENOENT ; - -return 0 ; -} -/** * die_is_signed_type - Check whether a type DIE is signed or not * @tp_die: a DIE of a type
@@ -410,9 +397,9 @@ int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)/* Get the call file index number in CU DIE */ static int die_get_call_fileno (Dwarf_Die *in_die) { -Dwarf_Sword idx; +Dwarf_Word idx; -if (die_get_attr_sdata (in_die, DW_AT_call_file, &idx) ==0 ) +if (die_get_attr_udata (in_die, DW_AT_call_file, &idx) ==0 )return (int )idx;else return -ENOENT ;
@@ -421,9 +408,9 @@ static int die_get_call_fileno(Dwarf_Die *in_die)/* Get the declared file index number in CU DIE */ static int die_get_decl_fileno (Dwarf_Die *pdie) { -Dwarf_Sword idx; +Dwarf_Word idx; -if (die_get_attr_sdata (pdie, DW_AT_decl_file, &idx) ==0 ) +if (die_get_attr_udata (pdie, DW_AT_decl_file, &idx) ==0 )return (int )idx;else return -ENOENT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 427/521 ravb: Fix "failed to switch device to config mode" message during unbind
In reply to Greg Kroah-HartmanFrom: Biju Das <[email protected]>
[ Upstream commit c72a7e42592b2e18d862cf120876070947000d7a ]
This patch fixes the error "ravb 11c20000.ethernet eth0: failed to switch device to config mode" during unbind.
We are doing register access after pm_runtime_put_sync().
We usually do cleanup in reverse order of init. Currently in remove(), the "pm_runtime_put_sync" is not in reverse order.
Probe
reset_control_deassert(rstc); pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
remove
pm_runtime_put_sync(&pdev->dev); unregister_netdev(ndev); .. ravb_mdio_release(priv); pm_runtime_disable(&pdev->dev);
Consider the call to unregister_netdev() unregister_netdev->unregister_netdevice_queue->rollback_registered_many that calls the below functions which access the registers after pm_runtime_put_sync()
1) ravb_get_stats
2) ravb_close
--- drivers/net/ethernet/renesas/ravb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/renesas/ravb_main.c +1 -1
@@ -2199,11 +2199,11 @@ static int ravb_remove(struct platform_device *pdev) priv->desc_bat_dma);/* Set reset mode */ ravb_write (ndev,CCC_OPC_RESET ,CCC ); -pm_runtime_put_sync (&pdev->dev);unregister_netdev (ndev);netif_napi_del (&priv->napi[RAVB_NC ]);netif_napi_del (&priv->napi[RAVB_BE ]);ravb_mdio_release (priv); +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);free_netdev (ndev);platform_set_drvdata (pdev,NULL );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 428/521 riscv: remove unreachable !HAVE_FUNCTION_GRAPH_RET_ADDR_PTR code
In reply to Greg Kroah-HartmanFrom: Christoph Hellwig <[email protected]>
[ Upstream commit 877425424d6c853b804e6b6a6045a5b4ea97c510 ]
HAVE_FUNCTION_GRAPH_RET_ADDR_PTR is always defined for RISC-V.
Stable-dep-of: 5c3022e4a616 ("riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument")
--- arch/riscv/kernel/stacktrace.c | 4 ---- 1 file changed, 4 deletions(-)
arch/riscv/kernel/stacktrace.c +0 -4
@@ -64,12 +64,8 @@ static void notrace walk_stackframe(struct task_struct *task, frame = (struct stackframe *)fp -1 ; sp = fp; fp = frame->fp; -#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR pc =ftrace_graph_ret_addr (current,NULL , frame->ra, (unsigned long *)(fp -8 )); -#else - pc = frame->ra -0x4 ; -#endif } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 429/521 riscv/stacktrace: Fix stack output without ra on the stack top
In reply to Greg Kroah-HartmanFrom: Chen Huang <[email protected]>
[ Upstream commit f766f77a74f5784d8d4d3c36b1900731f97d08d0 ]
When a function doesn't have a callee, then it will not push ra into the stack, such as lkdtm_BUG() function,
addi sp,sp,-16
sd s0,8(sp)
addi s0,sp,16
ebreak
The struct stackframe use {fp,ra} to get information from stack, if walk_stackframe() with pr_regs, we will obtain wrong value and bad stacktrace,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 ---[ end trace 18da3fbdf08e25d5 ]---
Correct the next fp and pc, after that, full stacktrace shown as expects,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 [<ffffffe0008b24a4>] lkdtm_do_action+0x14/0x1c [<ffffffe00066c372>] direct_entry+0xc0/0x10a [<ffffffe000439f86>] full_proxy_write+0x42/0x6a [<ffffffe000309626>] vfs_write+0x7e/0x214 [<ffffffe00030992a>] ksys_write+0x98/0xc0 [<ffffffe000309960>] sys_write+0xe/0x16 [<ffffffe0002014bc>] ret_from_syscall+0x0/0x2 ---[ end trace 61917f3d9a9fadcd ]---
Stable-dep-of: 5c3022e4a616 ("riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument")
--- arch/riscv/kernel/stacktrace.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/stacktrace.c +9 -3
@@ -63,9 +63,15 @@ static void notrace walk_stackframe(struct task_struct *task,/* Unwind stack frame */ frame = (struct stackframe *)fp -1 ; sp = fp; - fp = frame->fp; - pc =ftrace_graph_ret_addr (current,NULL , frame->ra, - (unsigned long *)(fp -8 )); +if (regs && (regs->epc == pc) && (frame->fp &0x7 )) { + fp = frame->ra; + pc = regs->ra; + }else { + fp = frame->fp; + pc =ftrace_graph_ret_addr (current,NULL , frame->ra, + (unsigned long *)(fp -8 )); + } + } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 430/521 riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument
In reply to Greg Kroah-HartmanFrom: Guo Ren <[email protected]>
[ Upstream commit 5c3022e4a616d800cf5f4c3a981d7992179e44a1 ]
The 'retp' is a pointer to the return address on the stack, so we must pass the current return address pointer as the 'retp' argument to ftrace_push_return_trace(). Not parent function's return address on the stack.
--- arch/riscv/kernel/stacktrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/stacktrace.c +1 -1
@@ -69,7 +69,7 @@ static void notrace walk_stackframe(struct task_struct *task, }else { fp = frame->fp; pc =ftrace_graph_ret_addr (current,NULL , frame->ra, - (unsigned long *)(fp -8 )); + &frame->ra); } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 431/521 driver core: Set deferred_probe_timeout to a longer default if CONFIG_MODULES is set
In reply to Greg Kroah-HartmanFrom: John Stultz <[email protected]>
[ Upstream commit e2cec7d6853712295cef5377762165a489b2957f ]
When using modules, its common for the modules not to be loaded until quite late by userland. With the current code, driver_deferred_probe_check_state() will stop returning EPROBE_DEFER after late_initcall, which can cause module dependency resolution to fail after that.
So allow a longer window of 30 seconds (picked somewhat arbitrarily, but influenced by the similar regulator core timeout value) in the case where modules are enabled.
--- drivers/base/dd.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/base/dd.c +9 -0
@@ -220,7 +220,16 @@ static int deferred_devs_show(struct seq_file *s, void *data) }DEFINE_SHOW_ATTRIBUTE (deferred_devs); +#ifdef CONFIG_MODULES +/* +* In the case of modules, set the default probe timeout to +* 30 seconds to give userland some time to load needed modules +*/ +static int deferred_probe_timeout =30 ; +#else +/* In the case of !modules, no probe timeout needed */ static int deferred_probe_timeout =-1 ; +#endif static int __init deferred_probe_timeout_setup (char *str) { deferred_probe_timeout =simple_strtol (str,NULL ,10 );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 432/521 ext4: goto right label failed_mount3a
In reply to Greg Kroah-HartmanFrom: Jason Yan <[email protected]>
[ Upstream commit 43bd6f1b49b61f43de4d4e33661b8dbe8c911f14 ]
Before these two branches neither loaded the journal nor created the xattr cache. So the right label to goto is 'failed_mount3a'. Although this did not cause any issues because the error handler validated if the pointer is null. However this still made me confused when reading the code. So it's still worth to modify to goto the right label.
Stable-dep-of: 89481b5fa8c0 ("ext4: correct inconsistent error msg in nojournal mode")
--- fs/ext4/super.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/ext4/super.c +5 -5
@@ -4302,30 +4302,30 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ext4_has_feature_journal_needs_recovery(sb)) { ext4_msg(sb, KERN_ERR, "required journal recovery " "suppressed and not mounted read-only"); - goto failed_mount_wq; + goto failed_mount3a; } else {/* Nojournal mode, all journal mount options are illegal */ if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) {ext4_msg (sb,KERN_ERR ,"can't mount with " "journal_checksum, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; }if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) {ext4_msg (sb,KERN_ERR ,"can't mount with " "journal_async_commit, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; }if (sbi->s_commit_interval !=JBD2_DEFAULT_MAX_COMMIT_AGE *HZ ) {ext4_msg (sb,KERN_ERR ,"can't mount with " "commit=%lu, fs mounted w/o journal" , sbi->s_commit_interval /HZ ); - goto failed_mount_wq; + goto failed_mount3a; }if (EXT4_MOUNT_DATA_FLAGS & (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {ext4_msg (sb,KERN_ERR ,"can't mount with " "data=, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; } sbi->s_def_mount_opt &= ~EXT4_MOUNT_JOURNAL_CHECKSUM ;clear_opt (sb,JOURNAL_CHECKSUM );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 433/521 ext4: correct inconsistent error msg in nojournal mode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
[ Upstream commit 89481b5fa8c0640e62ba84c6020cee895f7ac643 ]
When we used the journal_async_commit mounting option in nojournal mode, the kernel told me that "can't mount with journal_checksum", was very confusing. I find that when we mount with journal_async_commit, both the JOURNAL_ASYNC_COMMIT and EXPLICIT_JOURNAL_CHECKSUM flags are set. However, in the error branch, CHECKSUM is checked before ASYNC_COMMIT. As a result, the above inconsistency occurs, and the ASYNC_COMMIT branch becomes dead code that cannot be executed. Therefore, we exchange the positions of the two judgments to make the error msg more accurate.
--- fs/ext4/super.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/ext4/super.c +5 -4
@@ -4305,14 +4305,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount3a; }else {/* Nojournal mode, all journal mount options are illegal */ -if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) { +if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) {ext4_msg (sb,KERN_ERR ,"can't mount with " -"journal_checksum, fs mounted w/o journal" ); +"journal_async_commit, fs mounted w/o journal" ); goto failed_mount3a; } -if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) { + +if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) {ext4_msg (sb,KERN_ERR ,"can't mount with " -"journal_async_commit, fs mounted w/o journal" ); +"journal_checksum, fs mounted w/o journal" ); goto failed_mount3a; }if (sbi->s_commit_interval !=JBD2_DEFAULT_MAX_COMMIT_AGE *HZ ) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 434/521 ext4: use kmemdup() to replace kmalloc + memcpy
In reply to Greg Kroah-HartmanFrom: Shuqi Zhang <[email protected]>
[ Upstream commit 4efd9f0d120c55b08852ee5605dbb02a77089a5d ]
Replace kmalloc + memcpy with kmemdup()
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/xattr.c +1 -2
@@ -1911,11 +1911,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,unlock_buffer (bs->bh);ea_bdebug (bs->bh,"cloning" ); - s->base =kmalloc (bs->bh->b_size,GFP_NOFS ); + s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); error = -ENOMEM ;if (s->base ==NULL ) goto cleanup; -memcpy (s->base,BHDR (bs->bh), bs->bh->b_size); s->first =ENTRY (header (s->base)+1 );header (s->base)->h_refcount =cpu_to_le32 (1 ); s->here =ENTRY (s->base + offset);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 435/521 mbcache: dont reclaim used entries
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 58318914186c157477b978b1739dfe2f1b9dc0fe ]
Do not reclaim entries that are currently used by somebody from a shrinker. Firstly, these entries are likely useful. Secondly, we will need to keep such entries to protect pending increment of xattr block refcount.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/mbcache.c +9 -1
@@ -287,7 +287,7 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache,while (nr_to_scan-- && !list_empty (&cache->c_list)) { entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list); -if (entry->e_referenced) { +if (entry->e_referenced ||atomic_read (&entry->e_refcnt) >2 ) { entry->e_referenced =0 ;list_move_tail (&entry->e_list, &cache->c_list);continue ;
@@ -301,6 +301,14 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache,spin_unlock (&cache->c_list_lock); head =mb_cache_entry_head (cache, entry->e_key);hlist_bl_lock (head); +/* Now a reliable check if the entry didn't get used... */ +if (atomic_read (&entry->e_refcnt) >2 ) { +hlist_bl_unlock (head); +spin_lock (&cache->c_list_lock); +list_add_tail (&entry->e_list, &cache->c_list); + cache->c_entry_count++; +continue ; + }if (!hlist_bl_unhashed (&entry->e_hash_list)) {hlist_bl_del_init (&entry->e_hash_list);atomic_dec (&entry->e_refcnt);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 436/521 mbcache: add functions to delete entry if unused
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 3dc96bba65f53daa217f0a8f43edad145286a8f5 ]
Add function mb_cache_entry_delete_or_get() to delete mbcache entry if it is unused and also add a function to wait for entry to become unused
- mb_cache_entry_wait_unused(). We do not share code between the two deleting function as one of them will go away soon.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 66 +++++++++++++++++++++++++++++++++++++++-- include/linux/mbcache.h | 10 ++++++- 2 files changed, 73 insertions(+), 3 deletions(-)
fs/mbcache.c +64 -2
@@ -10,7 +10,7 @@/* * Mbcache is a simple key-value store. Keys need not be unique, however * key-value pairs are expected to be unique (we use this fact in -* mb_cache_entry_delete()). +* mb_cache_entry_delete_or_get()). * * Ext2 and ext4 use this cache for deduplication of extended attribute blocks. * Ext4 also uses it for deduplication of xattr values stored in inodes.
@@ -124,6 +124,19 @@ void __mb_cache_entry_free(struct mb_cache_entry *entry) }EXPORT_SYMBOL (__mb_cache_entry_free); +/* +* mb_cache_entry_wait_unused - wait to be the last user of the entry +* +* @entry - entry to work on +* +* Wait to be the last user of the entry. +*/ +void mb_cache_entry_wait_unused (struct mb_cache_entry *entry) +{ +wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=3 ); +} +EXPORT_SYMBOL (mb_cache_entry_wait_unused); +static struct mb_cache_entry *__entry_find (struct mb_cache *cache,struct mb_cache_entry *entry,u32 key)
@@ -216,7 +229,7 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, }EXPORT_SYMBOL (mb_cache_entry_get); -/* mb_cache_entry_delete - remove a cache entry +/* mb_cache_entry_delete - try to remove a cache entry * @cache - cache we work with * @key - key * @value - value
@@ -253,6 +266,55 @@ void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value) }EXPORT_SYMBOL (mb_cache_entry_delete); +/* mb_cache_entry_delete_or_get - remove a cache entry if it has no users +* @cache - cache we work with +* @key - key +* @value - value +* +* Remove entry from cache @cache with key @key and value @value. The removal +* happens only if the entry is unused. The function returns NULL in case the +* entry was successfully removed or there's no entry in cache. Otherwise the +* function grabs reference of the entry that we failed to delete because it +* still has users and return it. +*/ +struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache, +u32 key,u64 value) +{ +struct hlist_bl_node *node; +struct hlist_bl_head *head; +struct mb_cache_entry *entry; + + head =mb_cache_entry_head (cache, key); +hlist_bl_lock (head); +hlist_bl_for_each_entry (entry, node, head, e_hash_list) { +if (entry->e_key == key && entry->e_value == value) { +if (atomic_read (&entry->e_refcnt) >2 ) { +atomic_inc (&entry->e_refcnt); +hlist_bl_unlock (head); +return entry; + } +/* We keep hash list reference to keep entry alive */ +hlist_bl_del_init (&entry->e_hash_list); +hlist_bl_unlock (head); +spin_lock (&cache->c_list_lock); +if (!list_empty (&entry->e_list)) { +list_del_init (&entry->e_list); +if (!WARN_ONCE (cache->c_entry_count ==0 , +"mbcache: attempt to decrement c_entry_count past zero" )) + cache->c_entry_count--; +atomic_dec (&entry->e_refcnt); + } +spin_unlock (&cache->c_list_lock); +mb_cache_entry_put (cache, entry); +return NULL ; + } + } +hlist_bl_unlock (head); + +return NULL ; +} +EXPORT_SYMBOL (mb_cache_entry_delete_or_get); +/* mb_cache_entry_touch - cache entry got used * @cache - cache the entry belongs to * @entry - entry that got used
include/linux/mbcache.h +9 -1
@@ -30,15 +30,23 @@ void mb_cache_destroy(struct mb_cache *cache);int mb_cache_entry_create (struct mb_cache *cache,gfp_t mask,u32 key,u64 value,bool reusable);void __mb_cache_entry_free (struct mb_cache_entry *entry); +void mb_cache_entry_wait_unused (struct mb_cache_entry *entry);static inline int mb_cache_entry_put (struct mb_cache *cache,struct mb_cache_entry *entry) { -if (!atomic_dec_and_test (&entry->e_refcnt)) +unsigned int cnt =atomic_dec_return (&entry->e_refcnt); + +if (cnt >0 ) { +if (cnt <=3 ) +wake_up_var (&entry->e_refcnt);return 0 ; + }__mb_cache_entry_free (entry);return 1 ; } +struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache, +u32 key,u64 value);void mb_cache_entry_delete (struct mb_cache *cache,u32 key,u64 value);struct mb_cache_entry *mb_cache_entry_get (struct mb_cache *cache,u32 key,u64 value);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 437/521 ext4: remove EA inode entry from mbcache on inode eviction
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 6bc0d63dad7f9f54d381925ee855b402f652fa39 ]
Currently we remove EA inode from mbcache as soon as its xattr refcount drops to zero. However there can be pending attempts to reuse the inode and thus refcount handling code has to handle the situation when refcount increases from zero anyway. So save some work and just keep EA inode in mbcache until it is getting evicted. At that moment we are sure following iget() of EA inode will fail anyway (or wait for eviction to finish and load things from the disk again) and so removing mbcache entry at that moment is fine and simplifies the code a bit.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/inode.c | 2 ++ fs/ext4/xattr.c | 24 ++++++++---------------- fs/ext4/xattr.h | 1 + 3 files changed, 11 insertions(+), 16 deletions(-)
fs/ext4/inode.c +2 -0
@@ -207,6 +207,8 @@ void ext4_evict_inode(struct inode *inode)trace_ext4_evict_inode (inode); +if (EXT4_I (inode)->i_flags &EXT4_EA_INODE_FL ) +ext4_evict_ea_inode (inode);if (inode->i_nlink) {/* * When journalling data dirty buffers are tracked only in the
fs/ext4/xattr.c +8 -16
@@ -434,6 +434,14 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,return err; } +/* Remove entry from mbcache when EA inode is getting evicted */ +void ext4_evict_ea_inode (struct inode *inode) +{ +if (EA_INODE_CACHE (inode)) +mb_cache_entry_delete (EA_INODE_CACHE (inode), +ext4_xattr_inode_get_hash (inode), inode->i_ino); +} + static int ext4_xattr_inode_verify_hashes(struct inode *ea_inode, struct ext4_xattr_entry *entry, void *buffer,
@@ -1019,10 +1027,8 @@ static int ext4_xattr_ensure_credits(handle_t *handle, struct inode *inode,static int ext4_xattr_inode_update_ref (handle_t *handle,struct inode *ea_inode,int ref_change) { -struct mb_cache *ea_inode_cache =EA_INODE_CACHE (ea_inode);struct ext4_iloc iloc;s64 ref_count; -u32 hash;int ret;inode_lock (ea_inode);
@@ -1047,14 +1053,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,set_nlink (ea_inode,1 );ext4_orphan_del (handle, ea_inode); - -if (ea_inode_cache) { - hash =ext4_xattr_inode_get_hash (ea_inode); -mb_cache_entry_create (ea_inode_cache, -GFP_NOFS , hash, - ea_inode->i_ino, - true/* reusable */ ); - } } }else { WARN_ONCE(ref_count < 0, "EA inode %lu ref_count=%lld",
@@ -1067,12 +1065,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,clear_nlink (ea_inode);ext4_orphan_add (handle, ea_inode); - -if (ea_inode_cache) { - hash =ext4_xattr_inode_get_hash (ea_inode); -mb_cache_entry_delete (ea_inode_cache, hash, - ea_inode->i_ino); - } } }
fs/ext4/xattr.h +1 -0
@@ -190,6 +190,7 @@ extern void ext4_xattr_inode_array_free(struct ext4_xattr_inode_array *array);extern int ext4_expand_extra_isize_ea (struct inode *inode,int new_extra_isize,struct ext4_inode *raw_inode,handle_t *handle); +extern void ext4_evict_ea_inode (struct inode *inode);extern const struct xattr_handler *ext4_xattr_handlers[];
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 438/521 ext4: unindent codeblock in ext4_xattr_block_set()
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit fd48e9acdf26d0cbd80051de07d4a735d05d29b2 ]
Remove unnecessary else (and thus indentation level) from a code block in ext4_xattr_block_set(). It will also make following code changes easier. No functional changes.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 39 deletions(-)
fs/ext4/xattr.c +38 -39
@@ -1867,6 +1867,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,#define header (x) ((struct ext4_xattr_header *)(x))if (s->base) { +int offset = (char *)s->here - bs->bh->b_data; +BUFFER_TRACE (bs->bh,"get_write_access" ); error =ext4_journal_get_write_access (handle, bs->bh);if (error)
@@ -1898,49 +1900,46 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,if (error) goto cleanup; goto inserted; - }else { -int offset = (char *)s->here - bs->bh->b_data; + } +unlock_buffer (bs->bh); +ea_bdebug (bs->bh,"cloning" ); + s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); + error = -ENOMEM ; +if (s->base ==NULL ) + goto cleanup; + s->first =ENTRY (header (s->base)+1 ); +header (s->base)->h_refcount =cpu_to_le32 (1 ); + s->here =ENTRY (s->base + offset); + s->end = s->base + bs->bh->b_size; -unlock_buffer (bs->bh); -ea_bdebug (bs->bh,"cloning" ); - s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); - error = -ENOMEM ; -if (s->base ==NULL ) +/* +* If existing entry points to an xattr inode, we need +* to prevent ext4_xattr_set_entry() from decrementing +* ref count on it because the reference belongs to the +* original block. In this case, make the entry look +* like it has an empty value. +*/ +if (!s->not_found && s->here->e_value_inum) { + ea_ino =le32_to_cpu (s->here->e_value_inum); + error =ext4_xattr_inode_iget (inode, ea_ino, +le32_to_cpu (s->here->e_hash), + &tmp_inode); +if (error) goto cleanup; - s->first =ENTRY (header (s->base)+1 ); -header (s->base)->h_refcount =cpu_to_le32 (1 ); - s->here =ENTRY (s->base + offset); - s->end = s->base + bs->bh->b_size; -/* -* If existing entry points to an xattr inode, we need -* to prevent ext4_xattr_set_entry() from decrementing -* ref count on it because the reference belongs to the -* original block. In this case, make the entry look -* like it has an empty value. -*/ -if (!s->not_found && s->here->e_value_inum) { - ea_ino =le32_to_cpu (s->here->e_value_inum); - error =ext4_xattr_inode_iget (inode, ea_ino, -le32_to_cpu (s->here->e_hash), - &tmp_inode); -if (error) - goto cleanup; - -if (!ext4_test_inode_state (tmp_inode, -EXT4_STATE_LUSTRE_EA_INODE )) { -/* -* Defer quota free call for previous -* inode until success is guaranteed. -*/ - old_ea_inode_quota =le32_to_cpu ( - s->here->e_value_size); - } -iput (tmp_inode); - - s->here->e_value_inum =0 ; - s->here->e_value_size =0 ; +if (!ext4_test_inode_state (tmp_inode, +EXT4_STATE_LUSTRE_EA_INODE )) { +/* +* Defer quota free call for previous +* inode until success is guaranteed. +*/ + old_ea_inode_quota =le32_to_cpu ( + s->here->e_value_size); } +iput (tmp_inode); + + s->here->e_value_inum =0 ; + s->here->e_value_size =0 ; } }else {/* Allocate a buffer where we construct the new block. */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 439/521 ext4: fix race when reusing xattr blocks
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 65f8b80053a1b2fd602daa6814e62d6fa90e5e9b ]
When ext4_xattr_block_set() decides to remove xattr block the following race can happen:
CPU1 CPU2ext4_xattr_block_set() ext4_xattr_release_block()
new_bh = ext4_xattr_block_cache_find()
lock_buffer(bh);
ref = le32_to_cpu(BHDR(bh)->h_refcount);
if (ref == 1) {
...
mb_cache_entry_delete();
unlock_buffer(bh);
ext4_free_blocks();
...
ext4_forget(..., bh, ...);
jbd2_journal_revoke(..., bh); ext4_journal_get_write_access(..., new_bh, ...)
do_get_write_access()
jbd2_journal_cancel_revoke(..., new_bh);Later the code in ext4_xattr_block_set() finds out the block got freed and cancels reusal of the block but the revoke stays canceled and so in case of block reuse and journal replay the filesystem can get corrupted. If the race works out slightly differently, we can also hit assertions in the jbd2 code.
Fix the problem by making sure that once matching mbcache entry is found, code dropping the last xattr block reference (or trying to modify xattr block in place) waits until the mbcache entry reference is dropped. This way code trying to reuse xattr block is protected from someone trying to drop the last reference to xattr block.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 67 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 22 deletions(-)
fs/ext4/xattr.c +45 -22
@@ -437,9 +437,16 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,/* Remove entry from mbcache when EA inode is getting evicted */ void ext4_evict_ea_inode (struct inode *inode) { -if (EA_INODE_CACHE (inode)) -mb_cache_entry_delete (EA_INODE_CACHE (inode), -ext4_xattr_inode_get_hash (inode), inode->i_ino); +struct mb_cache_entry *oe; + +if (!EA_INODE_CACHE (inode)) +return ; +/* Wait for entry to get unused so that we can remove it */ +while ((oe =mb_cache_entry_delete_or_get (EA_INODE_CACHE (inode), +ext4_xattr_inode_get_hash (inode), inode->i_ino))) { +mb_cache_entry_wait_unused (oe); +mb_cache_entry_put (EA_INODE_CACHE (inode), oe); + } } static int
@@ -1245,6 +1252,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,if (error) goto out; +retry_ref:lock_buffer (bh); hash =le32_to_cpu (BHDR (bh)->h_hash); ref =le32_to_cpu (BHDR (bh)->h_refcount);
@@ -1254,9 +1262,18 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,* This must happen under buffer lock for * ext4_xattr_block_set() to reliably detect freed block */ -if (ea_block_cache) -mb_cache_entry_delete (ea_block_cache, hash, - bh->b_blocknr); +if (ea_block_cache) { +struct mb_cache_entry *oe; + + oe =mb_cache_entry_delete_or_get (ea_block_cache, hash, + bh->b_blocknr); +if (oe) { +unlock_buffer (bh); +mb_cache_entry_wait_unused (oe); +mb_cache_entry_put (ea_block_cache, oe); + goto retry_ref; + } + }get_bh (bh);unlock_buffer (bh);
@@ -1883,9 +1900,20 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,* ext4_xattr_block_set() to reliably detect modified * block */ -if (ea_block_cache) -mb_cache_entry_delete (ea_block_cache, hash, - bs->bh->b_blocknr); +if (ea_block_cache) { +struct mb_cache_entry *oe; + + oe =mb_cache_entry_delete_or_get (ea_block_cache, + hash, bs->bh->b_blocknr); +if (oe) { +/* +* Xattr block is getting reused. Leave +* it alone. +*/ +mb_cache_entry_put (ea_block_cache, oe); + goto clone_block; + } + }ea_bdebug (bs->bh,"modifying in-place" ); error =ext4_xattr_set_entry (i, s, handle, inode, true/* is_block */ );
@@ -1901,6 +1929,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, goto cleanup; goto inserted; } +clone_block:unlock_buffer (bs->bh);ea_bdebug (bs->bh,"cloning" ); s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS );
@@ -2006,18 +2035,13 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,lock_buffer (new_bh);/* * We have to be careful about races with -* freeing, rehashing or adding references to -* xattr block. Once we hold buffer lock xattr -* block's state is stable so we can check -* whether the block got freed / rehashed or -* not. Since we unhash mbcache entry under -* buffer lock when freeing / rehashing xattr -* block, checking whether entry is still -* hashed is reliable. Same rules hold for -* e_reusable handling. +* adding references to xattr block. Once we +* hold buffer lock xattr block's state is +* stable so we can check the additional +* reference fits. */ -if (hlist_bl_unhashed (&ce->e_hash_list) || - !ce->e_reusable) { + ref =le32_to_cpu (BHDR (new_bh)->h_refcount) +1 ; +if (ref >EXT4_XATTR_REFCOUNT_MAX ) {/* * Undo everything and check mbcache * again.
@@ -2032,9 +2056,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, new_bh =NULL ; goto inserted; } - ref =le32_to_cpu (BHDR (new_bh)->h_refcount) +1 ;BHDR (new_bh)->h_refcount =cpu_to_le32 (ref); -if (ref >=EXT4_XATTR_REFCOUNT_MAX ) +if (ref ==EXT4_XATTR_REFCOUNT_MAX ) ce->e_reusable =0 ;ea_bdebug (new_bh,"reusing; refcount now=%d" , ref);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 440/521 mbcache: automatically delete entries from cache on freeing
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 307af6c879377c1c63e71cbdd978201f9c7ee8df ]
Use the fact that entries with elevated refcount are not removed from the hash and just move removal of the entry from the hash to the entry freeing time. When doing this we also change the generic code to hold one reference to the cache entry, not two of them, which makes code somewhat more obvious.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 108 +++++++++++++++------------------------- include/linux/mbcache.h | 24 ++++++--- 2 files changed, 55 insertions(+), 77 deletions(-)
fs/mbcache.c +39 -69
@@ -89,7 +89,7 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,return -ENOMEM ;INIT_LIST_HEAD (&entry->e_list); -/* One ref for hash, one ref returned */ +/* Initial hash reference */ atomic_set (&entry->e_refcnt,1 ); entry->e_key = key; entry->e_value = value;
@@ -105,21 +105,28 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key, } }hlist_bl_add_head (&entry->e_hash_list, head); -hlist_bl_unlock (head); - +/* +* Add entry to LRU list before it can be found by +* mb_cache_entry_delete() to avoid races +*/ spin_lock (&cache->c_list_lock);list_add_tail (&entry->e_list, &cache->c_list); -/* Grab ref for LRU list */ -atomic_inc (&entry->e_refcnt); cache->c_entry_count++;spin_unlock (&cache->c_list_lock); +hlist_bl_unlock (head);return 0 ; }EXPORT_SYMBOL (mb_cache_entry_create); -void __mb_cache_entry_free (struct mb_cache_entry *entry) +void __mb_cache_entry_free (struct mb_cache *cache,struct mb_cache_entry *entry) { +struct hlist_bl_head *head; + + head =mb_cache_entry_head (cache, entry->e_key); +hlist_bl_lock (head); +hlist_bl_del (&entry->e_hash_list); +hlist_bl_unlock (head);kmem_cache_free (mb_entry_cache, entry); }EXPORT_SYMBOL (__mb_cache_entry_free);
@@ -133,7 +140,7 @@ EXPORT_SYMBOL(__mb_cache_entry_free);*/ void mb_cache_entry_wait_unused (struct mb_cache_entry *entry) { -wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=3 ); +wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=2 ); }EXPORT_SYMBOL (mb_cache_entry_wait_unused);
@@ -154,10 +161,9 @@ static struct mb_cache_entry *__entry_find(struct mb_cache *cache,while (node) { entry = hlist_bl_entry(node, struct mb_cache_entry, e_hash_list); -if (entry->e_key == key && entry->e_reusable) { -atomic_inc (&entry->e_refcnt); +if (entry->e_key == key && entry->e_reusable && +atomic_inc_not_zero (&entry->e_refcnt)) goto out; - } node = node->next; } entry =NULL ;
@@ -217,10 +223,9 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, head =mb_cache_entry_head (cache, key);hlist_bl_lock (head);hlist_bl_for_each_entry (entry, node, head, e_hash_list) { -if (entry->e_key == key && entry->e_value == value) { -atomic_inc (&entry->e_refcnt); +if (entry->e_key == key && entry->e_value == value && +atomic_inc_not_zero (&entry->e_refcnt)) goto out; - } } entry =NULL ; out:
@@ -280,37 +285,25 @@ EXPORT_SYMBOL(mb_cache_entry_delete);struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache,u32 key,u64 value) { -struct hlist_bl_node *node; -struct hlist_bl_head *head;struct mb_cache_entry *entry; - head =mb_cache_entry_head (cache, key); -hlist_bl_lock (head); -hlist_bl_for_each_entry (entry, node, head, e_hash_list) { -if (entry->e_key == key && entry->e_value == value) { -if (atomic_read (&entry->e_refcnt) >2 ) { -atomic_inc (&entry->e_refcnt); -hlist_bl_unlock (head); -return entry; - } -/* We keep hash list reference to keep entry alive */ -hlist_bl_del_init (&entry->e_hash_list); -hlist_bl_unlock (head); -spin_lock (&cache->c_list_lock); -if (!list_empty (&entry->e_list)) { -list_del_init (&entry->e_list); -if (!WARN_ONCE (cache->c_entry_count ==0 , -"mbcache: attempt to decrement c_entry_count past zero" )) - cache->c_entry_count--; -atomic_dec (&entry->e_refcnt); - } -spin_unlock (&cache->c_list_lock); -mb_cache_entry_put (cache, entry); -return NULL ; - } - } -hlist_bl_unlock (head); + entry =mb_cache_entry_get (cache, key, value); +if (!entry) +return NULL ; +/* +* Drop the ref we got from mb_cache_entry_get() and the initial hash +* ref if we are the last user +*/ +if (atomic_cmpxchg (&entry->e_refcnt,2 ,0 ) !=2 ) +return entry; + +spin_lock (&cache->c_list_lock); +if (!list_empty (&entry->e_list)) +list_del_init (&entry->e_list); + cache->c_entry_count--; +spin_unlock (&cache->c_list_lock); +__mb_cache_entry_free (cache, entry);return NULL ; }EXPORT_SYMBOL (mb_cache_entry_delete_or_get);
@@ -342,42 +335,24 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, unsigned long nr_to_scan) {struct mb_cache_entry *entry; -struct hlist_bl_head *head;unsigned long shrunk =0 ;spin_lock (&cache->c_list_lock);while (nr_to_scan-- && !list_empty (&cache->c_list)) { entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list); -if (entry->e_referenced ||atomic_read (&entry->e_refcnt) >2 ) { +/* Drop initial hash reference if there is no user */ +if (entry->e_referenced || +atomic_cmpxchg (&entry->e_refcnt,1 ,0 ) !=1 ) { entry->e_referenced =0 ;list_move_tail (&entry->e_list, &cache->c_list);continue ; }list_del_init (&entry->e_list); cache->c_entry_count--; -/* -* We keep LRU list reference so that entry doesn't go away -* from under us. -*/ spin_unlock (&cache->c_list_lock); - head =mb_cache_entry_head (cache, entry->e_key); -hlist_bl_lock (head); -/* Now a reliable check if the entry didn't get used... */ -if (atomic_read (&entry->e_refcnt) >2 ) { -hlist_bl_unlock (head); -spin_lock (&cache->c_list_lock); -list_add_tail (&entry->e_list, &cache->c_list); - cache->c_entry_count++; -continue ; - } -if (!hlist_bl_unhashed (&entry->e_hash_list)) { -hlist_bl_del_init (&entry->e_hash_list); -atomic_dec (&entry->e_refcnt); - } -hlist_bl_unlock (head); -if (mb_cache_entry_put (cache, entry)) - shrunk++; +__mb_cache_entry_free (cache, entry); + shrunk++;cond_resched ();spin_lock (&cache->c_list_lock); }
@@ -469,11 +444,6 @@ void mb_cache_destroy(struct mb_cache *cache)* point. */ list_for_each_entry_safe (entry, next, &cache->c_list, e_list) { -if (!hlist_bl_unhashed (&entry->e_hash_list)) { -hlist_bl_del_init (&entry->e_hash_list); -atomic_dec (&entry->e_refcnt); - }else -WARN_ON (1 );list_del (&entry->e_list);WARN_ON (atomic_read (&entry->e_refcnt) !=1 );mb_cache_entry_put (cache, entry);
include/linux/mbcache.h +16 -8
@@ -13,8 +13,16 @@ struct mb_cache;struct mb_cache_entry {/* List of entries in cache - protected by cache->c_list_lock */ struct list_head e_list; -/* Hash table list - protected by hash chain bitlock */ +/* +* Hash table list - protected by hash chain bitlock. The entry is +* guaranteed to be hashed while e_refcnt > 0. +*/ struct hlist_bl_node e_hash_list; +/* +* Entry refcount. Once it reaches zero, entry is unhashed and freed. +* While refcount > 0, the entry is guaranteed to stay in the hash and +* e.g. mb_cache_entry_try_delete() will fail. +*/ atomic_t e_refcnt;/* Key in hash - stable during lifetime of the entry */ u32 e_key;
@@ -29,20 +37,20 @@ void mb_cache_destroy(struct mb_cache *cache);int mb_cache_entry_create (struct mb_cache *cache,gfp_t mask,u32 key,u64 value,bool reusable); -void __mb_cache_entry_free (struct mb_cache_entry *entry); +void __mb_cache_entry_free (struct mb_cache *cache, +struct mb_cache_entry *entry);void mb_cache_entry_wait_unused (struct mb_cache_entry *entry); -static inline int mb_cache_entry_put (struct mb_cache *cache, -struct mb_cache_entry *entry) +static inline void mb_cache_entry_put (struct mb_cache *cache, +struct mb_cache_entry *entry) {unsigned int cnt =atomic_dec_return (&entry->e_refcnt);if (cnt >0 ) { -if (cnt <=3 ) +if (cnt <=2 )wake_up_var (&entry->e_refcnt); -return 0 ; +return ; } -__mb_cache_entry_free (entry); -return 1 ; +__mb_cache_entry_free (cache, entry); } struct mb_cache_entry *mb_cache_entry_delete_or_get(struct mb_cache *cache,
Signature · 1 line
2.35.1