Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Apr 27, 2022
    • Hangbin Liu's avatar
      net/packet: fix packet_sock xmit return value checking · 8fb76adb
      Hangbin Liu authored
      [ Upstream commit 29e8e659 ]
      
      packet_sock xmit could be dev_queue_xmit, which also returns negative
      errors. So only checking positive errors is not enough, or userspace
      sendmsg may return success while packet is not send out.
      
      Move the net_xmit_errno() assignment in the braces as checkpatch.pl said
      do not use assignment in if condition.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Reported-by: default avatarFlavio Leitner <fbl@redhat.com>
      Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8fb76adb
    • Tony Lu's avatar
      net/smc: Fix sock leak when release after smc_shutdown() · a499cb5f
      Tony Lu authored
      [ Upstream commit 1a74e993 ]
      
      Since commit e5d5aadc
      
       ("net/smc: fix sk_refcnt underflow on linkdown
      and fallback"), for a fallback connection, __smc_release() does not call
      sock_put() if its state is already SMC_CLOSED.
      
      When calling smc_shutdown() after falling back, its state is set to
      SMC_CLOSED but does not call sock_put(), so this patch calls it.
      
      Reported-and-tested-by: default avatar <syzbot+6e29a053eb165bd50de5@syzkaller.appspotmail.com>
      Fixes: e5d5aadc
      
       ("net/smc: fix sk_refcnt underflow on linkdown and fallback")
      Signed-off-by: default avatarTony Lu <tonylu@linux.alibaba.com>
      Acked-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a499cb5f
    • David Howells's avatar
      rxrpc: Restore removed timer deletion · 60592f16
      David Howells authored
      [ Upstream commit ee3b0826 ]
      
      A recent patch[1] from Eric Dumazet flipped the order in which the
      keepalive timer and the keepalive worker were cancelled in order to fix a
      syzbot reported issue[2].  Unfortunately, this enables the mirror image bug
      whereby the timer races with rxrpc_exit_net(), restarting the worker after
      it has been cancelled:
      
      	CPU 1		CPU 2
      	===============	=====================
      			if (rxnet->live)
      			<INTERRUPT>
      	rxnet->live = false;
       	cancel_work_sync(&rxnet->peer_keepalive_work);
      			rxrpc_queue_work(&rxnet->peer_keepalive_work);
      	del_timer_sync(&rxnet->peer_keepalive_timer);
      
      Fix this by restoring the removed del_timer_sync() so that we try to remove
      the timer twice.  If the timer runs again, it should see ->live == false
      and not restart the worker.
      
      Fixes: 1946014c
      
       ("rxrpc: fix a race in rxrpc_exit_net()")
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Eric Dumazet <edumazet@google.com>
      cc: Marc Dionne <marc.dionne@auristor.com>
      cc: linux-afs@lists.infradead.org
      Link: https://lore.kernel.org/r/20220404183439.3537837-1-eric.dumazet@gmail.com/ [1]
      Link: https://syzkaller.appspot.com/bug?extid=724378c4bb58f703b09a
      
       [2]
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      60592f16
    • Sasha Neftin's avatar
      igc: Fix BUG: scheduling while atomic · fc7116a7
      Sasha Neftin authored
      [ Upstream commit c80a29f0 ]
      
      Replace usleep_range() method with udelay() method to allow atomic contexts
      in low-level MDIO access functions.
      
      The following issue can be seen by doing the following:
      $ modprobe -r bonding
      $ modprobe -v bonding max_bonds=1 mode=1 miimon=100 use_carrier=0
      $ ip link set bond0 up
      $ ifenslave bond0 eth0 eth1
      
      [  982.357308] BUG: scheduling while atomic: kworker/u64:0/9/0x00000002
      [  982.364431] INFO: lockdep is turned off.
      [  982.368824] Modules linked in: bonding sctp ip6_udp_tunnel udp_tunnel mlx4_ib ib_uverbs ib_core mlx4_en mlx4_core nfp tls sunrpc intel_rapl_msr iTCO_wdt iTCO_vendor_support mxm_wmi dcdbas intel_rapl_common sb_edac x86_pkg_temp_thermal intel_powerclamp coretemp kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel rapl intel_cstate intel_uncore pcspkr lpc_ich mei_me ipmi_ssif mei ipmi_si ipmi_devintf ipmi_msghandler wmi acpi_power_meter xfs libcrc32c sr_mod cdrom sd_mod t10_pi sg mgag200 drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops drm ahci libahci crc32c_intel libata i2c_algo_bit tg3 megaraid_sas igc dm_mirror dm_region_hash dm_log dm_mod [last unloaded: bonding]
      [  982.437941] CPU: 25 PID: 9 Comm: kworker/u64:0 Kdump: loaded Tainted: G        W        --------- -  - 4.18.0-348.el8.x86_64+debug #1
      [  982.451333] Hardware name: Dell Inc. PowerEdge R730/0H21J3, BIOS 2.7.0 12/005/2017
      [  982.459791] Workqueue: bond0 bond_mii_monitor [bonding]
      [  982.465622] Call Trace:
      [  982.468355]  dump_stack+0x8e/0xd0
      [  982.472056]  __schedule_bug.cold.60+0x3a/0x60
      [  982.476919]  __schedule+0x147b/0x1bc0
      [  982.481007]  ? firmware_map_remove+0x16b/0x16b
      [  982.485967]  ? hrtimer_fixup_init+0x40/0x40
      [  982.490625]  schedule+0xd9/0x250
      [  982.494227]  schedule_hrtimeout_range_clock+0x10d/0x2c0
      [  982.500058]  ? hrtimer_nanosleep_restart+0x130/0x130
      [  982.505598]  ? hrtimer_init_sleeper_on_stack+0x90/0x90
      [  982.511332]  ? usleep_range+0x88/0x130
      [  982.515514]  ? recalibrate_cpu_khz+0x10/0x10
      [  982.520279]  ? ktime_get+0xab/0x1c0
      [  982.524175]  ? usleep_range+0x88/0x130
      [  982.528355]  usleep_range+0xdd/0x130
      [  982.532344]  ? console_conditional_schedule+0x30/0x30
      [  982.537987]  ? igc_put_hw_semaphore+0x17/0x60 [igc]
      [  982.543432]  igc_read_phy_reg_gpy+0x111/0x2b0 [igc]
      [  982.548887]  igc_phy_has_link+0xfa/0x260 [igc]
      [  982.553847]  ? igc_get_phy_id+0x210/0x210 [igc]
      [  982.558894]  ? lock_acquire+0x34d/0x890
      [  982.563187]  ? lock_downgrade+0x710/0x710
      [  982.567659]  ? rcu_read_unlock+0x50/0x50
      [  982.572039]  igc_check_for_copper_link+0x106/0x210 [igc]
      [  982.577970]  ? igc_config_fc_after_link_up+0x840/0x840 [igc]
      [  982.584286]  ? rcu_read_unlock+0x50/0x50
      [  982.588661]  ? lock_release+0x591/0xb80
      [  982.592939]  ? lock_release+0x591/0xb80
      [  982.597220]  igc_has_link+0x113/0x330 [igc]
      [  982.601887]  ? lock_downgrade+0x710/0x710
      [  982.606362]  igc_ethtool_get_link+0x6d/0x90 [igc]
      [  982.611614]  bond_check_dev_link+0x131/0x2c0 [bonding]
      [  982.617350]  ? bond_time_in_interval+0xd0/0xd0 [bonding]
      [  982.623277]  ? rcu_read_lock_held+0x62/0xc0
      [  982.627944]  ? rcu_read_lock_sched_held+0xe0/0xe0
      [  982.633198]  bond_mii_monitor+0x314/0x2500 [bonding]
      [  982.638738]  ? lock_contended+0x880/0x880
      [  982.643214]  ? bond_miimon_link_change+0xa0/0xa0 [bonding]
      [  982.649336]  ? lock_acquire+0x34d/0x890
      [  982.653615]  ? lock_downgrade+0x710/0x710
      [  982.658089]  ? debug_object_deactivate+0x221/0x340
      [  982.663436]  ? rcu_read_unlock+0x50/0x50
      [  982.667811]  ? debug_print_object+0x2b0/0x2b0
      [  982.672672]  ? __switch_to_asm+0x41/0x70
      [  982.677049]  ? __switch_to_asm+0x35/0x70
      [  982.681426]  ? _raw_spin_unlock_irq+0x24/0x40
      [  982.686288]  ? trace_hardirqs_on+0x20/0x195
      [  982.690956]  ? _raw_spin_unlock_irq+0x24/0x40
      [  982.695818]  process_one_work+0x8f0/0x1770
      [  982.700390]  ? pwq_dec_nr_in_flight+0x320/0x320
      [  982.705443]  ? debug_show_held_locks+0x50/0x50
      [  982.710403]  worker_thread+0x87/0xb40
      [  982.714489]  ? process_one_work+0x1770/0x1770
      [  982.719349]  kthread+0x344/0x410
      [  982.722950]  ? kthread_insert_work_sanity_check+0xd0/0xd0
      [  982.728975]  ret_from_fork+0x3a/0x50
      
      Fixes: 5586838f
      
       ("igc: Add code for PHY support")
      Reported-by: default avatarCorinna Vinschen <vinschen@redhat.com>
      Suggested-by: default avatarDima Ruinskiy <dima.ruinskiy@intel.com>
      Signed-off-by: default avatarSasha Neftin <sasha.neftin@intel.com>
      Tested-by: default avatarCorinna Vinschen <vinschen@redhat.com>
      Tested-by: default avatarNaama Meir <naamax.meir@linux.intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fc7116a7
    • Sasha Neftin's avatar
      igc: Fix infinite loop in release_swfw_sync · 46b0e4f9
      Sasha Neftin authored
      [ Upstream commit 907862e9 ]
      
      An infinite loop may occur if we fail to acquire the HW semaphore,
      which is needed for resource release.
      This will typically happen if the hardware is surprise-removed.
      At this stage there is nothing to do, except log an error and quit.
      
      Fixes: c0071c7a
      
       ("igc: Add HW initialization code")
      Suggested-by: default avatarDima Ruinskiy <dima.ruinskiy@intel.com>
      Signed-off-by: default avatarSasha Neftin <sasha.neftin@intel.com>
      Tested-by: default avatarNaama Meir <naamax.meir@linux.intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      46b0e4f9
    • Sabrina Dubroca's avatar
      esp: limit skb_page_frag_refill use to a single page · c075c3ea
      Sabrina Dubroca authored
      [ Upstream commit 5bd8baab ]
      
      Commit ebe48d36 ("esp: Fix possible buffer overflow in ESP
      transformation") tried to fix skb_page_frag_refill usage in ESP by
      capping allocsize to 32k, but that doesn't completely solve the issue,
      as skb_page_frag_refill may return a single page. If that happens, we
      will write out of bounds, despite the check introduced in the previous
      patch.
      
      This patch forces COW in cases where we would end up calling
      skb_page_frag_refill with a size larger than a page (first in
      esp_output_head with tailen, then in esp_output_tail with
      skb->data_len).
      
      Fixes: cac2661c ("esp4: Avoid skb_cow_data whenever possible")
      Fixes: 03e2a30f
      
       ("esp6: Avoid skb_cow_data whenever possible")
      Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c075c3ea
    • Allen-KH Cheng's avatar
      spi: spi-mtk-nor: initialize spi controller after resume · 3f7914db
      Allen-KH Cheng authored
      [ Upstream commit 317c2045 ]
      
      After system resumes, the registers of nor controller are
      initialized with default values. The nor controller will
      not function properly.
      
      To handle both issues above, we add mtk_nor_init() in
      mtk_nor_resume after pm_runtime_force_resume().
      
      Fixes: 3bfd9103
      
       ("spi: spi-mtk-nor: Add power management support")
      
      Signed-off-by: default avatarAllen-KH Cheng <allen-kh.cheng@mediatek.com>
      Reviewed-by: default avatarRex-BC Chen <rex-bc.chen@mediatek.com>
      Link: https://lore.kernel.org/r/20220412115743.22641-1-allen-kh.cheng@mediatek.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3f7914db
    • zhangqilong's avatar
      dmaengine: mediatek:Fix PM usage reference leak of mtk_uart_apdma_alloc_chan_resources · f714abf2
      zhangqilong authored
      [ Upstream commit 545b2baa ]
      
      pm_runtime_get_sync will increment pm usage counter even it failed.
      Forgetting to putting operation will result in reference leak here.
      We fix it:
      1) Replacing it with pm_runtime_resume_and_get to keep usage counter
         balanced.
      2) Add putting operation before returning error.
      
      Fixes:9135408c
      
       ("dmaengine: mediatek: Add MediaTek UART APDMA support")
      Signed-off-by: default avatarZhang Qilong <zhangqilong3@huawei.com>
      Link: https://lore.kernel.org/r/20220319022142.142709-1-zhangqilong3@huawei.com
      
      
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f714abf2
    • Miaoqian Lin's avatar
      dmaengine: imx-sdma: Fix error checking in sdma_event_remap · 9bc949a1
      Miaoqian Lin authored
      [ Upstream commit 7104b9cb ]
      
      of_parse_phandle() returns NULL on errors, rather than error
      pointers. Using NULL check on grp_np to fix this.
      
      Fixes: d078cd1b
      
       ("dmaengine: imx-sdma: Add imx6sx platform support")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Link: https://lore.kernel.org/r/20220308064952.15743-1-linmq006@gmail.com
      
      
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9bc949a1
    • Srinivas Kandagatla's avatar
      ASoC: codecs: wcd934x: do not switch off SIDO Buck when codec is in use · 12aa8021
      Srinivas Kandagatla authored
      [ Upstream commit db6dd1be
      
       ]
      
      SIDO(Single-Inductor Dual-Ouput) Buck powers up both analog and digital
      circuits along with internal memory, powering off this is the last thing
      that codec should do when going to very low power.
      
      Current code was powering off this Buck if there are no users of sysclk,
      which is not correct. Powering off this buck will result in no register access.
      This code path was never tested until recently after adding pm support
      in SoundWire controller. Fix this by removing the buck poweroff when the
      codec is active and also the code that is not used.
      
      Without this patch all the read/write transactions will never complete and
      results in SLIMBus Errors like:
      
      qcom,slim-ngd qcom,slim-ngd.1: Tx:MT:0x0, MC:0x60, LA:0xcf failed:-110
      wcd934x-codec wcd934x-codec.1.auto: ASoC: error at soc_component_read_no_lock
      	on wcd934x-codec.1.auto for register: [0x00000d05] -110
      qcom,slim-ngd-ctrl 171c0000.slim: Error Interrupt received 0x82000000
      
      Reported-by: default avatarAmit Pundir <amit.pundir@linaro.org>
      Fixes: a61f3b4f
      
       ("ASoC: wcd934x: add support to wcd9340/wcd9341 codec")
      Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
      Tested-by: default avatarAmit Pundir <amit.pundir@linaro.org>
      Link: https://lore.kernel.org/r/20220407094313.2880-1-srinivas.kandagatla@linaro.org
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      12aa8021
    • Miaoqian Lin's avatar
      ASoC: msm8916-wcd-digital: Check failure for devm_snd_soc_register_component · b6f474cd
      Miaoqian Lin authored
      [ Upstream commit e927b05f ]
      
      devm_snd_soc_register_component() may fails, we should check the error
      and do the corresponding error handling.
      
      Fixes: 150db8c5
      
       ("ASoC: codecs: Add msm8916-wcd digital codec")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Link: https://lore.kernel.org/r/20220403115239.30140-1-linmq006@gmail.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b6f474cd
    • Mark Brown's avatar
      ASoC: atmel: Remove system clock tree configuration for at91sam9g20ek · 608fc588
      Mark Brown authored
      [ Upstream commit c775cbf6 ]
      
      The MCLK of the WM8731 on the AT91SAM9G20-EK board is connected to the
      PCK0 output of the SoC, intended in the reference software to be supplied
      using PLLB and programmed to 12MHz. As originally written for use with a
      board file the audio driver was responsible for configuring the entire tree
      but in the conversion to the common clock framework the registration of
      the named pck0 and pllb clocks was removed so the driver has failed to
      instantiate ever since.
      
      Since the WM8731 driver has had support for managing a MCLK provided via
      the common clock framework for some time we can simply drop all the clock
      management code from the machine driver other than configuration of the
      sysclk rate, the CODEC driver still respects that configuration from the
      machine driver.
      
      Fixes: ff78a189
      
       ("ARM: at91: remove old at91-specific clock driver")
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Reviewed-by: default avatarCodrin Ciubotariu <codrin.ciubotariu@microchip.com>
      Link: https://lore.kernel.org/r/20220325154241.1600757-2-broonie@kernel.org
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      608fc588
    • Jiazi Li's avatar
      dm: fix mempool NULL pointer race when completing IO · d29c78d3
      Jiazi Li authored
      commit d208b894
      
       upstream.
      
      dm_io_dec_pending() calls end_io_acct() first and will then dec md
      in-flight pending count. But if a task is swapping DM table at same
      time this can result in a crash due to mempool->elements being NULL:
      
      task1                             task2
      do_resume
       ->do_suspend
        ->dm_wait_for_completion
                                        bio_endio
      				   ->clone_endio
      				    ->dm_io_dec_pending
      				     ->end_io_acct
      				      ->wakeup task1
       ->dm_swap_table
        ->__bind
         ->__bind_mempools
          ->bioset_exit
           ->mempool_exit
                                           ->free_io
      
      [ 67.330330] Unable to handle kernel NULL pointer dereference at
      virtual address 0000000000000000
      ......
      [ 67.330494] pstate: 80400085 (Nzcv daIf +PAN -UAO)
      [ 67.330510] pc : mempool_free+0x70/0xa0
      [ 67.330515] lr : mempool_free+0x4c/0xa0
      [ 67.330520] sp : ffffff8008013b20
      [ 67.330524] x29: ffffff8008013b20 x28: 0000000000000004
      [ 67.330530] x27: ffffffa8c2ff40a0 x26: 00000000ffff1cc8
      [ 67.330535] x25: 0000000000000000 x24: ffffffdada34c800
      [ 67.330541] x23: 0000000000000000 x22: ffffffdada34c800
      [ 67.330547] x21: 00000000ffff1cc8 x20: ffffffd9a1304d80
      [ 67.330552] x19: ffffffdada34c970 x18: 000000b312625d9c
      [ 67.330558] x17: 00000000002dcfbf x16: 00000000000006dd
      [ 67.330563] x15: 000000000093b41e x14: 0000000000000010
      [ 67.330569] x13: 0000000000007f7a x12: 0000000034155555
      [ 67.330574] x11: 0000000000000001 x10: 0000000000000001
      [ 67.330579] x9 : 0000000000000000 x8 : 0000000000000000
      [ 67.330585] x7 : 0000000000000000 x6 : ffffff80148b5c1a
      [ 67.330590] x5 : ffffff8008013ae0 x4 : 0000000000000001
      [ 67.330596] x3 : ffffff80080139c8 x2 : ffffff801083bab8
      [ 67.330601] x1 : 0000000000000000 x0 : ffffffdada34c970
      [ 67.330609] Call trace:
      [ 67.330616] mempool_free+0x70/0xa0
      [ 67.330627] bio_put+0xf8/0x110
      [ 67.330638] dec_pending+0x13c/0x230
      [ 67.330644] clone_endio+0x90/0x180
      [ 67.330649] bio_endio+0x198/0x1b8
      [ 67.330655] dec_pending+0x190/0x230
      [ 67.330660] clone_endio+0x90/0x180
      [ 67.330665] bio_endio+0x198/0x1b8
      [ 67.330673] blk_update_request+0x214/0x428
      [ 67.330683] scsi_end_request+0x2c/0x300
      [ 67.330688] scsi_io_completion+0xa0/0x710
      [ 67.330695] scsi_finish_command+0xd8/0x110
      [ 67.330700] scsi_softirq_done+0x114/0x148
      [ 67.330708] blk_done_softirq+0x74/0xd0
      [ 67.330716] __do_softirq+0x18c/0x374
      [ 67.330724] irq_exit+0xb4/0xb8
      [ 67.330732] __handle_domain_irq+0x84/0xc0
      [ 67.330737] gic_handle_irq+0x148/0x1b0
      [ 67.330744] el1_irq+0xe8/0x190
      [ 67.330753] lpm_cpuidle_enter+0x4f8/0x538
      [ 67.330759] cpuidle_enter_state+0x1fc/0x398
      [ 67.330764] cpuidle_enter+0x18/0x20
      [ 67.330772] do_idle+0x1b4/0x290
      [ 67.330778] cpu_startup_entry+0x20/0x28
      [ 67.330786] secondary_start_kernel+0x160/0x170
      
      Fix this by:
      1) Establishing pointers to 'struct dm_io' members in
      dm_io_dec_pending() so that they may be passed into end_io_acct()
      _after_ free_io() is called.
      2) Moving end_io_acct() after free_io().
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJiazi Li <lijiazi@xiaomi.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarAkilesh Kailash <akailash@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d29c78d3
    • Tim Crawford's avatar
      ALSA: hda/realtek: Add quirk for Clevo NP70PNP · cf9b1954
      Tim Crawford authored
      commit 86222af0
      
       upstream.
      
      Fixes headset detection on Clevo NP70PNP.
      
      Signed-off-by: default avatarTim Crawford <tcrawford@system76.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20220421170412.3697-1-tcrawford@system76.com
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cf9b1954
    • Takashi Iwai's avatar
      ALSA: usb-audio: Clear MIDI port active flag after draining · 8ce3820f
      Takashi Iwai authored
      commit 0665886a
      
       upstream.
      
      When a rawmidi output stream is closed, it calls the drain at first,
      then does trigger-off only when the drain returns -ERESTARTSYS as a
      fallback.  It implies that each driver should turn off the stream
      properly after the drain.  Meanwhile, USB-audio MIDI interface didn't
      change the port->active flag after the drain.  This may leave the
      output work picking up the port that is closed right now, which
      eventually leads to a use-after-free for the already released rawmidi
      object.
      
      This patch fixes the bug by properly clearing the port->active flag
      after the output drain.
      
      Reported-by: default avatar <syzbot+70e777a39907d6d5fd0a@syzkaller.appspotmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/00000000000011555605dceaff03@google.com
      Link: https://lore.kernel.org/r/20220420130247.22062-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ce3820f
    • Eric Dumazet's avatar
      net/sched: cls_u32: fix netns refcount changes in u32_change() · 43ce33a6
      Eric Dumazet authored
      commit 3db09e76 upstream.
      
      We are now able to detect extra put_net() at the moment
      they happen, instead of much later in correct code paths.
      
      u32_init_knode() / tcf_exts_init() populates the ->exts.net
      pointer, but as mentioned in tcf_exts_init(),
      the refcount on netns has not been elevated yet.
      
      The refcount is taken only once tcf_exts_get_net()
      is called.
      
      So the two u32_destroy_key() calls from u32_change()
      are attempting to release an invalid reference on the netns.
      
      syzbot report:
      
      refcount_t: decrement hit 0; leaking memory.
      WARNING: CPU: 0 PID: 21708 at lib/refcount.c:31 refcount_warn_saturate+0xbf/0x1e0 lib/refcount.c:31
      Modules linked in:
      CPU: 0 PID: 21708 Comm: syz-executor.5 Not tainted 5.18.0-rc2-next-20220412-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      RIP: 0010:refcount_warn_saturate+0xbf/0x1e0 lib/refcount.c:31
      Code: 1d 14 b6 b2 09 31 ff 89 de e8 6d e9 89 fd 84 db 75 e0 e8 84 e5 89 fd 48 c7 c7 40 aa 26 8a c6 05 f4 b5 b2 09 01 e8 e5 81 2e 05 <0f> 0b eb c4 e8 68 e5 89 fd 0f b6 1d e3 b5 b2 09 31 ff 89 de e8 38
      RSP: 0018:ffffc900051af1b0 EFLAGS: 00010286
      RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
      RDX: 0000000000040000 RSI: ffffffff8160a0c8 RDI: fffff52000a35e28
      RBP: 0000000000000004 R08: 0000000000000000 R09: 0000000000000000
      R10: ffffffff81604a9e R11: 0000000000000000 R12: 1ffff92000a35e3b
      R13: 00000000ffffffef R14: ffff8880211a0194 R15: ffff8880577d0a00
      FS:  00007f25d183e700(0000) GS:ffff8880b9c00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007f19c859c028 CR3: 0000000051009000 CR4: 00000000003506f0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       <TASK>
       __refcount_dec include/linux/refcount.h:344 [inline]
       refcount_dec include/linux/refcount.h:359 [inline]
       ref_tracker_free+0x535/0x6b0 lib/ref_tracker.c:118
       netns_tracker_free include/net/net_namespace.h:327 [inline]
       put_net_track include/net/net_namespace.h:341 [inline]
       tcf_exts_put_net include/net/pkt_cls.h:255 [inline]
       u32_destroy_key.isra.0+0xa7/0x2b0 net/sched/cls_u32.c:394
       u32_change+0xe01/0x3140 net/sched/cls_u32.c:909
       tc_new_tfilter+0x98d/0x2200 net/sched/cls_api.c:2148
       rtnetlink_rcv_msg+0x80d/0xb80 net/core/rtnetlink.c:6016
       netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2495
       netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
       netlink_unicast+0x543/0x7f0 net/netlink/af_netlink.c:1345
       netlink_sendmsg+0x904/0xe00 net/netlink/af_netlink.c:1921
       sock_sendmsg_nosec net/socket.c:705 [inline]
       sock_sendmsg+0xcf/0x120 net/socket.c:725
       ____sys_sendmsg+0x6e2/0x800 net/socket.c:2413
       ___sys_sendmsg+0xf3/0x170 net/socket.c:2467
       __sys_sendmsg+0xe5/0x1b0 net/socket.c:2496
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      RIP: 0033:0x7f25d0689049
      Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
      RSP: 002b:00007f25d183e168 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
      RAX: ffffffffffffffda RBX: 00007f25d079c030 RCX: 00007f25d0689049
      RDX: 0000000000000000 RSI: 0000000020000340 RDI: 0000000000000005
      RBP: 00007f25d06e308d R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
      R13: 00007ffd0b752e3f R14: 00007f25d183e300 R15: 0000000000022000
       </TASK>
      
      Fixes: 35c55fc1
      
       ("cls_u32: use tcf_exts_get_net() before call_rcu()")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Jiri Pirko <jiri@resnulli.us>
      Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      43ce33a6
    • Bob Peterson's avatar
      gfs2: assign rgrp glock before compute_bitstructs · 04dd45d9
      Bob Peterson authored
      commit 428f651c
      
       upstream.
      
      Before this patch, function read_rindex_entry called compute_bitstructs
      before it allocated a glock for the rgrp. But if compute_bitstructs found
      a problem with the rgrp, it called gfs2_consist_rgrpd, and that called
      gfs2_dump_glock for rgd->rd_gl which had not yet been assigned.
      
      read_rindex_entry
         compute_bitstructs
            gfs2_consist_rgrpd
               gfs2_dump_glock <---------rgd->rd_gl was not set.
      
      This patch changes read_rindex_entry so it assigns an rgrp glock before
      calling compute_bitstructs so gfs2_dump_glock does not reference an
      unassigned pointer. If an error is discovered, the glock must also be
      put, so a new goto and label were added.
      
      Reported-by: default avatar <syzbot+c6fd14145e2f62ca0784@syzkaller.appspotmail.com>
      Signed-off-by: default avatarBob Peterson <rpeterso@redhat.com>
      Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      04dd45d9
    • Adrian Hunter's avatar
      perf tools: Fix segfault accessing sample_id xyarray · 378061c9
      Adrian Hunter authored
      commit a668cc07 upstream.
      
      perf_evsel::sample_id is an xyarray which can cause a segfault when
      accessed beyond its size. e.g.
      
        # perf record -e intel_pt// -C 1 sleep 1
        Segmentation fault (core dumped)
        #
      
      That is happening because a dummy event is opened to capture text poke
      events accross all CPUs, however the mmap logic is allocating according
      to the number of user_requested_cpus.
      
      In general, perf sometimes uses the evsel cpus to open events, and
      sometimes the evlist user_requested_cpus. However, it is not necessary
      to determine which case is which because the opened event file
      descriptors are also in an xyarray, the size of whch can be used
      to correctly allocate the size of the sample_id xyarray, because there
      is one ID per file descriptor.
      
      Note, in the affected code path, perf_evsel fd array is subsequently
      used to get the file descriptor for the mmap, so it makes sense for the
      xyarrays to be the same size ther...
      378061c9
    • Daniel Bristot de Oliveira's avatar
      tracing: Dump stacktrace trigger to the corresponding instance · 5e8446e3
      Daniel Bristot de Oliveira authored
      commit ce33c845 upstream.
      
      The stacktrace event trigger is not dumping the stacktrace to the instance
      where it was enabled, but to the global "instance."
      
      Use the private_data, pointing to the trigger file, to figure out the
      corresponding trace instance, and use it in the trigger action, like
      snapshot_trigger does.
      
      Link: https://lkml.kernel.org/r/afbb0b4f18ba92c276865bc97204d438473f4ebc.1645396236.git.bristot@kernel.org
      
      Cc: stable@vger.kernel.org
      Fixes: ae63b31e
      
       ("tracing: Separate out trace events from global variables")
      Reviewed-by: default avatarTom Zanussi <zanussi@kernel.org>
      Tested-by: default avatarTom Zanussi <zanussi@kernel.org>
      Signed-off-by: default avatarDaniel Bristot de Oliveira <bristot@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5e8446e3
    • Xiongwei Song's avatar
      mm: page_alloc: fix building error on -Werror=array-compare · 69848f94
      Xiongwei Song authored
      commit ca831f29 upstream.
      
      Arthur Marsh reported we would hit the error below when building kernel
      with gcc-12:
      
        CC      mm/page_alloc.o
        mm/page_alloc.c: In function `mem_init_print_info':
        mm/page_alloc.c:8173:27: error: comparison between two arrays [-Werror=array-compare]
         8173 |                 if (start <= pos && pos < end && size > adj) \
              |
      
      In C++20, the comparision between arrays should be warned.
      
      Link: https://lkml.kernel.org/r/20211125130928.32465-1-sxwjean@me.com
      
      
      Signed-off-by: default avatarXiongwei Song <sxwjean@gmail.com>
      Reported-by: default avatarArthur Marsh <arthur.marsh@internode.on.net>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Cc: Khem Raj <raj.khem@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69848f94
    • Kees Cook's avatar
      etherdevice: Adjust ether_addr* prototypes to silence -Wstringop-overead · 08ad7a77
      Kees Cook authored
      commit 2618a0da
      
       upstream.
      
      With GCC 12, -Wstringop-overread was warning about an implicit cast from
      char[6] to char[8]. However, the extra 2 bytes are always thrown away,
      alignment doesn't matter, and the risk of hitting the edge of unallocated
      memory has been accepted, so this prototype can just be converted to a
      regular char *. Silences:
      
      net/core/dev.c: In function ‘bpf_prog_run_generic_xdp’: net/core/dev.c:4618:21: warning: ‘ether_addr_equal_64bits’ reading 8 bytes from a region of size 6 [-Wstringop-overread]
       4618 |         orig_host = ether_addr_equal_64bits(eth->h_dest, > skb->dev->dev_addr);
            |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      net/core/dev.c:4618:21: note: referencing argument 1 of type ‘const u8[8]’ {aka ‘const unsigned char[8]’}
      net/core/dev.c:4618:21: note: referencing argument 2 of type ‘const u8[8]’ {aka ‘const unsigned char[8]’}
      In file included from net/core/dev.c:91: include/linux/etherdevice.h:375:20: note: in a call to function ‘ether_addr_equal_64bits’
        375 | static inline bool ether_addr_equal_64bits(const u8 addr1[6+2],
            |                    ^~~~~~~~~~~~~~~~~~~~~~~
      
      Reported-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Tested-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Link: https://lore.kernel.org/netdev/20220212090811.uuzk6d76agw2vv73@pengutronix.de
      
      
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: netdev@vger.kernel.org
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Cc: Khem Raj <raj.khem@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      08ad7a77
  2. Apr 20, 2022
    • Greg Kroah-Hartman's avatar
    • Duoming Zhou's avatar
      ax25: Fix UAF bugs in ax25 timers · 5c62d3bf
      Duoming Zhou authored
      commit 82e31755 upstream.
      
      There are race conditions that may lead to UAF bugs in
      ax25_heartbeat_expiry(), ax25_t1timer_expiry(), ax25_t2timer_expiry(),
      ax25_t3timer_expiry() and ax25_idletimer_expiry(), when we call
      ax25_release() to deallocate ax25_dev.
      
      One of the UAF bugs caused by ax25_release() is shown below:
      
            (Thread 1)                    |      (Thread 2)
      ax25_dev_device_up() //(1)          |
      ...                                 | ax25_kill_by_device()
      ax25_bind()          //(2)          |
      ax25_connect()                      | ...
       ax25_std_establish_data_link()     |
        ax25_start_t1timer()              | ax25_dev_device_down() //(3)
         mod_timer(&ax25->t1timer,..)     |
                                          | ax25_release()
         (wait a time)                    |  ...
                                          |  ax25_dev_put(ax25_dev) //(4)FREE
         ax25_t1timer_expiry()            |
          ax25->ax25_dev->values[..] //USE|  ...
           ...   ...
      5c62d3bf
    • Duoming Zhou's avatar
      ax25: Fix NULL pointer dereferences in ax25 timers · f934fa47
      Duoming Zhou authored
      commit fc6d01ff upstream.
      
      The previous commit 7ec02f5a ("ax25: fix NPD bug in ax25_disconnect")
      move ax25_disconnect into lock_sock() in order to prevent NPD bugs. But
      there are race conditions that may lead to null pointer dereferences in
      ax25_heartbeat_expiry(), ax25_t1timer_expiry(), ax25_t2timer_expiry(),
      ax25_t3timer_expiry() and ax25_idletimer_expiry(), when we use
      ax25_kill_by_device() to detach the ax25 device.
      
      One of the race conditions that cause null pointer dereferences can be
      shown as below:
      
            (Thread 1)                    |      (Thread 2)
      ax25_connect()                      |
       ax25_std_establish_data_link()     |
        ax25_start_t1timer()              |
         mod_timer(&ax25->t1timer,..)     |
                                          | ax25_kill_by_device()
         (wait a time)                    |  ...
                                          |  s->ax25_dev = NULL; //(1)
         ax25_t1timer_expiry()            |
          ax25->ax25_dev->values[..] //(2)|  ...
           ...                            |
      
      We set null to ax25_cb->ax25_dev in position (1) and dereference
      the null pointer in position (2).
      
      The corresponding fail log is shown below:
      ===============================================================
      BUG: kernel NULL pointer dereference, address: 0000000000000050
      CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.17.0-rc6-00794-g45690b7d0
      RIP: 0010:ax25_t1timer_expiry+0x12/0x40
      ...
      Call Trace:
       call_timer_fn+0x21/0x120
       __run_timers.part.0+0x1ca/0x250
       run_timer_softirq+0x2c/0x60
       __do_softirq+0xef/0x2f3
       irq_exit_rcu+0xb6/0x100
       sysvec_apic_timer_interrupt+0xa2/0xd0
      ...
      
      This patch moves ax25_disconnect() before s->ax25_dev = NULL
      and uses del_timer_sync() to delete timers in ax25_disconnect().
      If ax25_disconnect() is called by ax25_kill_by_device() or
      ax25->ax25_dev is NULL, the reason in ax25_disconnect() will be
      equal to ENETUNREACH, it will wait all timers to stop before we
      set null to s->ax25_dev in ax25_kill_by_device().
      
      Fixes: 7ec02f5a
      
       ("ax25: fix NPD bug in ax25_disconnect")
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [OP: backport to 5.10: adjust context]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f934fa47
    • Duoming Zhou's avatar
      ax25: fix NPD bug in ax25_disconnect · 145ea8d2
      Duoming Zhou authored
      commit 7ec02f5a
      
       upstream.
      
      The ax25_disconnect() in ax25_kill_by_device() is not
      protected by any locks, thus there is a race condition
      between ax25_disconnect() and ax25_destroy_socket().
      when ax25->sk is assigned as NULL by ax25_destroy_socket(),
      a NULL pointer dereference bug will occur if site (1) or (2)
      dereferences ax25->sk.
      
      ax25_kill_by_device()                | ax25_release()
        ax25_disconnect()                  |   ax25_destroy_socket()
          ...                              |
          if(ax25->sk != NULL)             |     ...
            ...                            |     ax25->sk = NULL;
            bh_lock_sock(ax25->sk); //(1)  |     ...
            ...                            |
            bh_unlock_sock(ax25->sk); //(2)|
      
      This patch moves ax25_disconnect() into lock_sock(), which can
      synchronize with ax25_destroy_socket() in ax25_release().
      
      Fail log:
      ===============================================================
      BUG: kernel NULL pointer dereference, address: 0000000000000088
      ...
      RIP: 0010:_raw_spin_lock+0x7e/0xd0
      ...
      Call Trace:
      ax25_disconnect+0xf6/0x220
      ax25_device_event+0x187/0x250
      raw_notifier_call_chain+0x5e/0x70
      dev_close_many+0x17d/0x230
      rollback_registered_many+0x1f1/0x950
      unregister_netdevice_queue+0x133/0x200
      unregister_netdev+0x13/0x20
      ...
      
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [OP: backport to 5.10: adjust context]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      145ea8d2
    • Duoming Zhou's avatar
      ax25: fix UAF bug in ax25_send_control() · a4942c6f
      Duoming Zhou authored
      commit 5352a761 upstream.
      
      There are UAF bugs in ax25_send_control(), when we call ax25_release()
      to deallocate ax25_dev. The possible race condition is shown below:
      
            (Thread 1)              |     (Thread 2)
      ax25_dev_device_up() //(1)    |
                                    | ax25_kill_by_device()
      ax25_bind()          //(2)    |
      ax25_connect()                | ...
       ax25->state = AX25_STATE_1   |
       ...                          | ax25_dev_device_down() //(3)
      
            (Thread 3)
      ax25_release()                |
       ax25_dev_put()  //(4) FREE   |
       case AX25_STATE_1:           |
        ax25_send_control()         |
         alloc_skb()       //USE    |
      
      The refcount of ax25_dev increases in position (1) and (2), and
      decreases in position (3) and (4). The ax25_dev will be freed
      before dereference sites in ax25_send_control().
      
      The following is part of the report:
      
      [  102.297448] BUG: KASAN: use-after-free in ax25_send_control+0x33/0x210
      [  102.297448] Read of size 8 at addr ffff888009e6e408 by task ax25_close/602
      [  102.297448] Call Trace:
      [  102.303751]  ax25_send_control+0x33/0x210
      [  102.303751]  ax25_release+0x356/0x450
      [  102.305431]  __sock_release+0x6d/0x120
      [  102.305431]  sock_close+0xf/0x20
      [  102.305431]  __fput+0x11f/0x420
      [  102.305431]  task_work_run+0x86/0xd0
      [  102.307130]  get_signal+0x1075/0x1220
      [  102.308253]  arch_do_signal_or_restart+0x1df/0xc00
      [  102.308253]  exit_to_user_mode_prepare+0x150/0x1e0
      [  102.308253]  syscall_exit_to_user_mode+0x19/0x50
      [  102.308253]  do_syscall_64+0x48/0x90
      [  102.308253]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  102.308253] RIP: 0033:0x405ae7
      
      This patch defers the free operation of ax25_dev and net_device after
      all corresponding dereference sites in ax25_release() to avoid UAF.
      
      Fixes: 9fd75b66
      
       ("ax25: Fix refcount leaks caused by ax25_cb_del()")
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      [OP: backport to 5.10: adjust dev_put_track()->dev_put()]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a4942c6f
    • Duoming Zhou's avatar
      ax25: Fix refcount leaks caused by ax25_cb_del() · b20a5ab0
      Duoming Zhou authored
      commit 9fd75b66 upstream.
      
      The previous commit d01ffb9e ("ax25: add refcount in ax25_dev to
      avoid UAF bugs") and commit feef318c ("ax25: fix UAF bugs of
      net_device caused by rebinding operation") increase the refcounts of
      ax25_dev and net_device in ax25_bind() and decrease the matching refcounts
      in ax25_kill_by_device() in order to prevent UAF bugs, but there are
      reference count leaks.
      
      The root cause of refcount leaks is shown below:
      
           (Thread 1)                      |      (Thread 2)
      ax25_bind()                          |
       ...                                 |
       ax25_addr_ax25dev()                 |
        ax25_dev_hold()   //(1)            |
        ...                                |
       dev_hold_track()   //(2)            |
       ...                                 | ax25_destroy_socket()
                                           |  ax25_cb_del()
                                           |   ...
                                           |   hlist_del_init() //(3)
                                           |
                                           |
           (Thread 3)                      |
      ax25_kill_by_device()                |
       ...                                 |
       ax25_for_each(s, &ax25_list) {      |
        if (s->ax25_dev == ax25_dev) //(4) |
         ...                               |
      
      Firstly, we use ax25_bind() to increase the refcount of ax25_dev in
      position (1) and increase the refcount of net_device in position (2).
      Then, we use ax25_cb_del() invoked by ax25_destroy_socket() to delete
      ax25_cb in hlist in position (3) before calling ax25_kill_by_device().
      Finally, the decrements of refcounts in ax25_kill_by_device() will not
      be executed, because no s->ax25_dev equals to ax25_dev in position (4).
      
      This patch adds decrements of refcounts in ax25_release() and use
      lock_sock() to do synchronization. If refcounts decrease in ax25_release(),
      the decrements of refcounts in ax25_kill_by_device() will not be
      executed and vice versa.
      
      Fixes: d01ffb9e ("ax25: add refcount in ax25_dev to avoid UAF bugs")
      Fixes: 87563a04 ("ax25: fix reference count leaks of ax25_dev")
      Fixes: feef318c
      
       ("ax25: fix UAF bugs of net_device caused by rebinding operation")
      Reported-by: default avatarThomas Osterried <thomas@osterried.de>
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [OP: backport to 5.10: adjust dev_put_track()->dev_put()]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b20a5ab0
    • Duoming Zhou's avatar
      ax25: fix UAF bugs of net_device caused by rebinding operation · 57cc15f5
      Duoming Zhou authored
      commit feef318c
      
       upstream.
      
      The ax25_kill_by_device() will set s->ax25_dev = NULL and
      call ax25_disconnect() to change states of ax25_cb and
      sock, if we call ax25_bind() before ax25_kill_by_device().
      
      However, if we call ax25_bind() again between the window of
      ax25_kill_by_device() and ax25_dev_device_down(), the values
      and states changed by ax25_kill_by_device() will be reassigned.
      
      Finally, ax25_dev_device_down() will deallocate net_device.
      If we dereference net_device in syscall functions such as
      ax25_release(), ax25_sendmsg(), ax25_getsockopt(), ax25_getname()
      and ax25_info_show(), a UAF bug will occur.
      
      One of the possible race conditions is shown below:
      
            (USE)                   |      (FREE)
      ax25_bind()                   |
                                    |  ax25_kill_by_device()
      ax25_bind()                   |
      ax25_connect()                |    ...
                                    |  ax25_dev_device_down()
                                    |    ...
                                    |    dev_put_track(dev, ...) //FREE
      ax25_release()                |    ...
        ax25_send_control()         |
          alloc_skb()      //USE    |
      
      the corresponding fail log is shown below:
      ===============================================================
      BUG: KASAN: use-after-free in ax25_send_control+0x43/0x210
      ...
      Call Trace:
        ...
        ax25_send_control+0x43/0x210
        ax25_release+0x2db/0x3b0
        __sock_release+0x6d/0x120
        sock_close+0xf/0x20
        __fput+0x11f/0x420
        ...
      Allocated by task 1283:
        ...
        __kasan_kmalloc+0x81/0xa0
        alloc_netdev_mqs+0x5a/0x680
        mkiss_open+0x6c/0x380
        tty_ldisc_open+0x55/0x90
        ...
      Freed by task 1969:
        ...
        kfree+0xa3/0x2c0
        device_release+0x54/0xe0
        kobject_put+0xa5/0x120
        tty_ldisc_kill+0x3e/0x80
        ...
      
      In order to fix these UAF bugs caused by rebinding operation,
      this patch adds dev_hold_track() into ax25_bind() and
      corresponding dev_put_track() into ax25_kill_by_device().
      
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [OP: backport to 5.10: adjust dev_put_track()->dev_put() and
      dev_hold_track()->dev_hold()]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      57cc15f5
    • Duoming Zhou's avatar
      ax25: fix reference count leaks of ax25_dev · 5ddae8d0
      Duoming Zhou authored
      commit 87563a04 upstream.
      
      The previous commit d01ffb9e ("ax25: add refcount in ax25_dev
      to avoid UAF bugs") introduces refcount into ax25_dev, but there
      are reference leak paths in ax25_ctl_ioctl(), ax25_fwd_ioctl(),
      ax25_rt_add(), ax25_rt_del() and ax25_rt_opt().
      
      This patch uses ax25_dev_put() and adjusts the position of
      ax25_addr_ax25dev() to fix reference cout leaks of ax25_dev.
      
      Fixes: d01ffb9e
      
       ("ax25: add refcount in ax25_dev to avoid UAF bugs")
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Link: https://lore.kernel.org/r/20220203150811.42256-1-duoming@zju.edu.cn
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      [OP: backport to 5.10: adjust context]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5ddae8d0
    • Duoming Zhou's avatar
      ax25: add refcount in ax25_dev to avoid UAF bugs · 5ea00fc6
      Duoming Zhou authored
      commit d01ffb9e
      
       upstream.
      
      If we dereference ax25_dev after we call kfree(ax25_dev) in
      ax25_dev_device_down(), it will lead to concurrency UAF bugs.
      There are eight syscall functions suffer from UAF bugs, include
      ax25_bind(), ax25_release(), ax25_connect(), ax25_ioctl(),
      ax25_getname(), ax25_sendmsg(), ax25_getsockopt() and
      ax25_info_show().
      
      One of the concurrency UAF can be shown as below:
      
        (USE)                       |    (FREE)
                                    |  ax25_device_event
                                    |    ax25_dev_device_down
      ax25_bind                     |    ...
        ...                         |      kfree(ax25_dev)
        ax25_fillin_cb()            |    ...
          ax25_fillin_cb_from_dev() |
        ...                         |
      
      The root cause of UAF bugs is that kfree(ax25_dev) in
      ax25_dev_device_down() is not protected by any locks.
      When ax25_dev, which there are still pointers point to,
      is released, the concurrency UAF bug will happen.
      
      This patch introduces refcount into ax25_dev in order to
      guarantee that there are no pointers point to it when ax25_dev
      is released.
      
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [OP: backport to 5.10: adjusted context]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5ea00fc6
    • Mike Christie's avatar
      scsi: iscsi: Fix unbound endpoint error handling · 36128863
      Mike Christie authored
      commit 03690d81 upstream.
      
      If a driver raises a connection error before the connection is bound, we
      can leave a cleanup_work queued that can later run and disconnect/stop a
      connection that is logged in. The problem is that drivers can call
      iscsi_conn_error_event for endpoints that are connected but not yet bound
      when something like the network port they are using is brought down.
      iscsi_cleanup_conn_work_fn will check for this and exit early, but if the
      cleanup_work is stuck behind other works, it might not get run until after
      userspace has done ep_disconnect. Because the endpoint is not yet bound
      there was no way for ep_disconnect to flush the work.
      
      The bug of leaving stop_conns queued was added in:
      
      Commit 23d6fefb ("scsi: iscsi: Fix in-kernel conn failure handling")
      
      and:
      
      Commit 0ab71045 ("scsi: iscsi: Perform connection failure entirely in
      kernel space")
      
      was supposed to fix it, but left this case.
      
      This patch moves the conn state check to before we even queue the work so
      we can avoid queueing.
      
      Link: https://lore.kernel.org/r/20220408001314.5014-7-michael.christie@oracle.com
      Fixes: 0ab71045
      
       ("scsi: iscsi: Perform connection failure entirely in kernel space")
      Tested-by: default avatarManish Rangankar <mrangankar@marvell.com>
      Reviewed-by: Lee Duncan <lduncan@@suse.com>
      Reviewed-by: default avatarChris Leech <cleech@redhat.com>
      Signed-off-by: default avatarMike Christie <michael.christie@oracle.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      36128863
    • Mike Christie's avatar
      scsi: iscsi: Fix endpoint reuse regression · 129db305
      Mike Christie authored
      commit 0aadafb5 upstream.
      
      This patch fixes a bug where when using iSCSI offload we can free an
      endpoint while userspace still thinks it's active. That then causes the
      endpoint ID to be reused for a new connection's endpoint while userspace
      still thinks the ID is for the original connection. Userspace will then end
      up disconnecting a running connection's endpoint or trying to bind to
      another connection's endpoint.
      
      This bug is a regression added in:
      
      Commit 23d6fefb ("scsi: iscsi: Fix in-kernel conn failure handling")
      
      where we added a in kernel ep_disconnect call to fix a bug in:
      
      Commit 0ab71045 ("scsi: iscsi: Perform connection failure entirely in
      kernel space")
      
      where we would call stop_conn without having done ep_disconnect. This early
      ep_disconnect call will then free the endpoint and it's ID while userspace
      still thinks the ID is valid.
      
      Fix the early release of the ID by having the in kernel recovery code keep
      a reference to the endpoint until userspace has called into the kernel to
      finish cleaning up the endpoint/connection. It requires the previous commit
      "scsi: iscsi: Release endpoint ID when its freed" which moved the freeing
      of the ID until when the endpoint is released.
      
      Link: https://lore.kernel.org/r/20220408001314.5014-5-michael.christie@oracle.com
      Fixes: 23d6fefb
      
       ("scsi: iscsi: Fix in-kernel conn failure handling")
      Tested-by: default avatarManish Rangankar <mrangankar@marvell.com>
      Reviewed-by: default avatarLee Duncan <lduncan@suse.com>
      Reviewed-by: default avatarChris Leech <cleech@redhat.com>
      Signed-off-by: default avatarMike Christie <michael.christie@oracle.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      129db305
    • Chao Gao's avatar
      dma-direct: avoid redundant memory sync for swiotlb · 26f827e0
      Chao Gao authored
      commit 9e02977b upstream.
      
      When we looked into FIO performance with swiotlb enabled in VM, we found
      swiotlb_bounce() is always called one more time than expected for each DMA
      read request.
      
      It turns out that the bounce buffer is copied to original DMA buffer twice
      after the completion of a DMA request (one is done by in
      dma_direct_sync_single_for_cpu(), the other by swiotlb_tbl_unmap_single()).
      But the content in bounce buffer actually doesn't change between the two
      rounds of copy. So, one round of copy is redundant.
      
      Pass DMA_ATTR_SKIP_CPU_SYNC flag to swiotlb_tbl_unmap_single() to
      skip the memory copy in it.
      
      This fix increases FIO 64KB sequential read throughput in a guest with
      swiotlb=force by 5.6%.
      
      Fixes: 55897af6
      
       ("dma-direct: merge swiotlb_dma_ops into the dma_direct code")
      Reported-by: default avatarWang Zhaoyang1 <zhaoyang1.wang@intel.com>
      Reported-by: default avatarGao Liang <liang.gao@intel.com>
      Signed-off-by: default avatarChao Gao <chao.gao@intel...>
      26f827e0
    • Anna-Maria Behnsen's avatar
      timers: Fix warning condition in __run_timers() · 9a5a4d23
      Anna-Maria Behnsen authored
      commit c54bc0fc upstream.
      
      When the timer base is empty, base::next_expiry is set to base::clk +
      NEXT_TIMER_MAX_DELTA and base::next_expiry_recalc is false. When no timer
      is queued until jiffies reaches base::next_expiry value, the warning for
      not finding any expired timer and base::next_expiry_recalc is false in
      __run_timers() triggers.
      
      To prevent triggering the warning in this valid scenario
      base::timers_pending needs to be added to the warning condition.
      
      Fixes: 31cd0e11
      
       ("timers: Recalculate next timer interrupt only when necessary")
      Reported-by: default avatarJohannes Berg <johannes@sipsolutions.net>
      Signed-off-by: default avatarAnna-Maria Behnsen <anna-maria@linutronix.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarFrederic Weisbecker <frederic@kernel.org>
      Link: https://lore.kernel.org/r/20220405191732.7438-3-anna-maria@linutronix.de
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9a5a4d23
    • Martin Povišer's avatar
      i2c: pasemi: Wait for write xfers to finish · 84837f43
      Martin Povišer authored
      commit bd8963e6 upstream.
      
      Wait for completion of write transfers before returning from the driver.
      At first sight it may seem advantageous to leave write transfers queued
      for the controller to carry out on its own time, but there's a couple of
      issues with it:
      
       * Driver doesn't check for FIFO space.
      
       * The queued writes can complete while the driver is in its I2C read
         transfer path which means it will get confused by the raising of
         XEN (the 'transaction ended' signal). This can cause a spurious
         ENODATA error due to premature reading of the MRXFIFO register.
      
      Adding the wait fixes some unreliability issues with the driver. There's
      some efficiency cost to it (especially with pasemi_smb_waitready doing
      its polling), but that will be alleviated once the driver receives
      interrupt support.
      
      Fixes: beb58aa3
      
       ("i2c: PA Semi SMBus driver")
      Signed-off-by: default avatarMartin Povišer <povik+lin@cutebit.org>
      Reviewed-by: default avatarSven Peter <sven@svenpeter.dev>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      84837f43
    • Nadav Amit's avatar
      smp: Fix offline cpu check in flush_smp_call_function_queue() · 89496d80
      Nadav Amit authored
      commit 9e949a38 upstream.
      
      The check in flush_smp_call_function_queue() for callbacks that are sent
      to offline CPUs currently checks whether the queue is empty.
      
      However, flush_smp_call_function_queue() has just deleted all the
      callbacks from the queue and moved all the entries into a local list.
      This checks would only be positive if some callbacks were added in the
      short time after llist_del_all() was called. This does not seem to be
      the intention of this check.
      
      Change the check to look at the local list to which the entries were
      moved instead of the queue from which all the callbacks were just
      removed.
      
      Fixes: 8d056c48
      
       ("CPU hotplug, smp: flush any pending IPI callbacks before CPU offline")
      Signed-off-by: default avatarNadav Amit <namit@vmware.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Link: https://lore.kernel.org/r/20220319072015.1495036-1-namit@vmware.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89496d80
    • Mikulas Patocka's avatar
      dm integrity: fix memory corruption when tag_size is less than digest size · cd02b268
      Mikulas Patocka authored
      commit 08c1af8f
      
       upstream.
      
      It is possible to set up dm-integrity in such a way that the
      "tag_size" parameter is less than the actual digest size. In this
      situation, a part of the digest beyond tag_size is ignored.
      
      In this case, dm-integrity would write beyond the end of the
      ic->recalc_tags array and corrupt memory. The corruption happened in
      integrity_recalc->integrity_sector_checksum->crypto_shash_final.
      
      Fix this corruption by increasing the tags array so that it has enough
      padding at the end to accomodate the loop in integrity_recalc() being
      able to write a full digest size for the last member of the tags
      array.
      
      Cc: stable@vger.kernel.org # v4.19+
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cd02b268
    • Nathan Chancellor's avatar
      ARM: davinci: da850-evm: Avoid NULL pointer dereference · 0a312ec6
      Nathan Chancellor authored
      commit 83a1cde5 upstream.
      
      With newer versions of GCC, there is a panic in da850_evm_config_emac()
      when booting multi_v5_defconfig in QEMU under the palmetto-bmc machine:
      
      Unable to handle kernel NULL pointer dereference at virtual address 00000020
      pgd = (ptrval)
      [00000020] *pgd=00000000
      Internal error: Oops: 5 [#1] PREEMPT ARM
      Modules linked in:
      CPU: 0 PID: 1 Comm: swapper Not tainted 5.15.0 #1
      Hardware name: Generic DT based system
      PC is at da850_evm_config_emac+0x1c/0x120
      LR is at do_one_initcall+0x50/0x1e0
      
      The emac_pdata pointer in soc_info is NULL because davinci_soc_info only
      gets populated on davinci machines but da850_evm_config_emac() is called
      on all machines via device_initcall().
      
      Move the rmii_en assignment below the machine check so that it is only
      dereferenced when running on a supported SoC.
      
      Fixes: bae10587
      
       ("davinci: DA850/OMAP-L138 EVM: implement autodetect of RMII PHY")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarBartosz Golaszewski <brgl@bgdev.pl>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/YcS4xVWs6bQlQSPC@archlinux-ax161/
      
      
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0a312ec6
    • Paul Gortmaker's avatar
      tick/nohz: Use WARN_ON_ONCE() to prevent console saturation · 0806f193
      Paul Gortmaker authored
      commit 40e97e42 upstream.
      
      While running some testing on code that happened to allow the variable
      tick_nohz_full_running to get set but with no "possible" NOHZ cores to
      back up that setting, this warning triggered:
      
              if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE))
                      WARN_ON(tick_nohz_full_running);
      
      The console was overwhemled with an endless stream of one WARN per tick
      per core and there was no way to even see what was going on w/o using a
      serial console to capture it and then trace it back to this.
      
      Change it to WARN_ON_ONCE().
      
      Fixes: 08ae95f4
      
       ("nohz_full: Allow the boot CPU to be nohz_full")
      Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20211206145950.10927-3-paul.gortmaker@windriver.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0806f193
    • Rei Yamamoto's avatar
      genirq/affinity: Consider that CPUs on nodes can be unbalanced · 0275c759
      Rei Yamamoto authored
      commit 08d835df upstream.
      
      If CPUs on a node are offline at boot time, the number of nodes is
      different when building affinity masks for present cpus and when building
      affinity masks for possible cpus. This causes the following problem:
      
      In the case that the number of vectors is less than the number of nodes
      there are cases where bits of masks for present cpus are overwritten when
      building masks for possible cpus.
      
      Fix this by excluding CPUs, which are not part of the current build mask
      (present/possible).
      
      [ tglx: Massaged changelog and added comment ]
      
      Fixes: b8259219
      
       ("genirq/affinity: Spread IRQs to all available NUMA nodes")
      Signed-off-by: default avatarRei Yamamoto <yamamoto.rei@jp.fujitsu.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20220331003309.10891-1-yamamoto.rei@jp.fujitsu.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0275c759