Skip to content
  1. Apr 10, 2021
    • Greg Kroah-Hartman's avatar
      Linux 4.14.230 · 958e517f
      Greg Kroah-Hartman authored
      
      
      Tested-by: default avatarJason Self <jason@bluehome.net>
      Tested-by: default avatarLinux Kernel Functional Testing <lkft@linaro.org>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Link: https://lore.kernel.org/r/20210409095300.391558233@linuxfoundation.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      v4.14.230
      958e517f
    • Angelo Dureghello's avatar
      can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate · 1bba2685
      Angelo Dureghello authored
      commit 47c5e474 upstream.
      
      For cases when flexcan is built-in, bitrate is still not set at
      registering. So flexcan_chip_freeze() generates:
      
      [    1.860000] *** ZERO DIVIDE ***   FORMAT=4
      [    1.860000] Current process id is 1
      [    1.860000] BAD KERNEL TRAP: 00000000
      [    1.860000] PC: [<402e70c8>] flexcan_chip_freeze+0x1a/0xa8
      
      To allow chip freeze, using an hardcoded timeout when bitrate is still
      not set.
      
      Fixes: ec15e27c
      
       ("can: flexcan: enable RX FIFO after FRZ/HALT valid")
      Link: https://lore.kernel.org/r/20210315231510.650593-1-angelo@kernel-space.org
      Signed-off-by: default avatarAngelo Dureghello <angelo@kernel-space.org>
      [mkl: use if instead of ? operator]
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Cc: Koen Vandeputte <koen.vandeputte@citymesh.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1bba2685
    • Masahiro Yamada's avatar
      init/Kconfig: make COMPILE_TEST depend on HAS_IOMEM · 4086850f
      Masahiro Yamada authored
      commit ea29b20a upstream.
      
      I read the commit log of the following two:
      
      - bc083a64 ("init/Kconfig: make COMPILE_TEST depend on !UML")
      - 334ef6ed
      
       ("init/Kconfig: make COMPILE_TEST depend on !S390")
      
      Both are talking about HAS_IOMEM dependency missing in many drivers.
      
      So, 'depends on HAS_IOMEM' seems the direct, sensible solution to me.
      
      This does not change the behavior of UML. UML still cannot enable
      COMPILE_TEST because it does not provide HAS_IOMEM.
      
      The current dependency for S390 is too strong. Under the condition of
      CONFIG_PCI=y, S390 provides HAS_IOMEM, hence can enable COMPILE_TEST.
      
      I also removed the meaningless 'default n'.
      
      Link: https://lkml.kernel.org/r/20210224140809.1067582-1-masahiroy@kernel.org
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Arnd Bergmann <arnd@kernel.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: KP Singh <kpsingh@google.com>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Quentin Perret <qperret@google.com>
      Cc: Valentin Schneider <valentin.schneider@arm.com>
      Cc: "Enrico Weigelt, metux IT consult" <lkml@metux.net>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4086850f
    • Heiko Carstens's avatar
      init/Kconfig: make COMPILE_TEST depend on !S390 · fa426149
      Heiko Carstens authored
      commit 334ef6ed upstream.
      
      While allmodconfig and allyesconfig build for s390 there are also
      various bots running compile tests with randconfig, where PCI is
      disabled. This reveals that a lot of drivers should actually depend on
      HAS_IOMEM.
      Adding this to each device driver would be a never ending story,
      therefore just disable COMPILE_TEST for s390.
      
      The reasoning is more or less the same as described in
      commit bc083a64
      
       ("init/Kconfig: make COMPILE_TEST depend on !UML").
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Suggested-by: default avatarArnd Bergmann <arnd@kernel.org>
      Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa426149
    • Piotr Krysiuk's avatar
      bpf, x86: Validate computation of branch displacements for x86-64 · 32f9a870
      Piotr Krysiuk authored
      commit e4d4d456
      
       upstream.
      
      The branch displacement logic in the BPF JIT compilers for x86 assumes
      that, for any generated branch instruction, the distance cannot
      increase between optimization passes.
      
      But this assumption can be violated due to how the distances are
      computed. Specifically, whenever a backward branch is processed in
      do_jit(), the distance is computed by subtracting the positions in the
      machine code from different optimization passes. This is because part
      of addrs[] is already updated for the current optimization pass, before
      the branch instruction is visited.
      
      And so the optimizer can expand blocks of machine code in some cases.
      
      This can confuse the optimizer logic, where it assumes that a fixed
      point has been reached for all machine code blocks once the total
      program size stops changing. And then the JIT compiler can output
      abnormal machine code containing incorrect branch displacements.
      
      To mitigate this issue, we assert that a fixed point is reached while
      populating the output image. This rejects any problematic programs.
      The issue affects both x86-32 and x86-64. We mitigate separately to
      ease backporting.
      
      Signed-off-by: default avatarPiotr Krysiuk <piotras@gmail.com>
      Reviewed-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      32f9a870
    • Vincent Whitchurch's avatar
      cifs: Silently ignore unknown oplock break handle · fee67e93
      Vincent Whitchurch authored
      [ Upstream commit 219481a8
      
       ]
      
      Make SMB2 not print out an error when an oplock break is received for an
      unknown handle, similar to SMB1.  The debug message which is printed for
      these unknown handles may also be misleading, so fix that too.
      
      The SMB2 lease break path is not affected by this patch.
      
      Without this, a program which writes to a file from one thread, and
      opens, reads, and writes the same file from another thread triggers the
      below errors several times a minute when run against a Samba server
      configured with "smb2 leases = no".
      
       CIFS: VFS: \\192.168.0.1 No task to wake, unknown frame received! NumMids 2
       00000000: 424d53fe 00000040 00000000 00000012  .SMB@...........
       00000010: 00000001 00000000 ffffffff ffffffff  ................
       00000020: 00000000 00000000 00000000 00000000  ................
       00000030: 00000000 00000000 00000000 00000000  ................
      
      Signed-off-by: default avatarVincent Whitchurch <vincent.whitchurch@axis.com>
      Reviewed-by: default avatarTom Talpey <tom@talpey.com>
      Reviewed-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fee67e93
    • Ronnie Sahlberg's avatar
      cifs: revalidate mapping when we open files for SMB1 POSIX · 9e62e366
      Ronnie Sahlberg authored
      [ Upstream commit cee8f4f6
      
       ]
      
      RHBZ: 1933527
      
      Under SMB1 + POSIX, if an inode is reused on a server after we have read and
      cached a part of a file, when we then open the new file with the
      re-cycled inode there is a chance that we may serve the old data out of cache
      to the application.
      This only happens for SMB1 (deprecated) and when posix are used.
      The simplest solution to avoid this race is to force a revalidate
      on smb1-posix open.
      
      Signed-off-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
      Reviewed-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9e62e366
    • Sergei Trofimovich's avatar
      ia64: mca: allocate early mca with GFP_ATOMIC · 12e4976f
      Sergei Trofimovich authored
      [ Upstream commit f2a419cf
      
       ]
      
      The sleep warning happens at early boot right at secondary CPU
      activation bootup:
      
          smp: Bringing up secondary CPUs ...
          BUG: sleeping function called from invalid context at mm/page_alloc.c:4942
          in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 0, name: swapper/1
          CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.12.0-rc2-00007-g79e228d0b611-dirty #99
          ..
          Call Trace:
            show_stack+0x90/0xc0
            dump_stack+0x150/0x1c0
            ___might_sleep+0x1c0/0x2a0
            __might_sleep+0xa0/0x160
            __alloc_pages_nodemask+0x1a0/0x600
            alloc_page_interleave+0x30/0x1c0
            alloc_pages_current+0x2c0/0x340
            __get_free_pages+0x30/0xa0
            ia64_mca_cpu_init+0x2d0/0x3a0
            cpu_init+0x8b0/0x1440
            start_secondary+0x60/0x700
            start_ap+0x750/0x780
          Fixed BSP b0 value from CPU 1
      
      As I understand interrupts are not enabled yet and system has a lot of
      memory.  There is little chance to sleep and switch to GFP_ATOMIC should
      be a no-op.
      
      Link: https://lkml.kernel.org/r/20210315085045.204414-1-slyfox@gentoo.org
      Signed-off-by: default avatarSergei Trofimovich <slyfox@gentoo.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      12e4976f
    • Martin Wilck's avatar
      scsi: target: pscsi: Clean up after failure in pscsi_map_sg() · a9222463
      Martin Wilck authored
      [ Upstream commit 36fa766f
      
       ]
      
      If pscsi_map_sg() fails, make sure to drop references to already allocated
      bios.
      
      Link: https://lore.kernel.org/r/20210323212431.15306-2-mwilck@suse.com
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarLee Duncan <lduncan@suse.com>
      Signed-off-by: default avatarMartin Wilck <mwilck@suse.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a9222463
    • Arnd Bergmann's avatar
      x86/build: Turn off -fcf-protection for realmode targets · 533dbcdc
      Arnd Bergmann authored
      [ Upstream commit 9fcb51c1
      
       ]
      
      The new Ubuntu GCC packages turn on -fcf-protection globally,
      which causes a build failure in the x86 realmode code:
      
        cc1: error: ‘-fcf-protection’ is not compatible with this target
      
      Turn it off explicitly on compilers that understand this option.
      
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Link: https://lore.kernel.org/r/20210323124846.1584944-1-arnd@kernel.org
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      533dbcdc
    • Esteve Varela Colominas's avatar
      platform/x86: thinkpad_acpi: Allow the FnLock LED to change state · c36b82c4
      Esteve Varela Colominas authored
      [ Upstream commit 3d677f12
      
       ]
      
      On many recent ThinkPad laptops, there's a new LED next to the ESC key,
      that indicates the FnLock status.
      When the Fn+ESC combo is pressed, FnLock is toggled, which causes the
      Media Key functionality to change, making it so that the media keys
      either perform their media key function, or function as an F-key by
      default. The Fn key can be used the access the alternate function at any
      time.
      
      With the current linux kernel, the LED doens't change state if you press
      the Fn+ESC key combo. However, the media key functionality *does*
      change. This is annoying, since the LED will stay on if it was on during
      bootup, and it makes it hard to keep track what the current state of the
      FnLock is.
      
      This patch calls an ACPI function, that gets the current media key
      state, when the Fn+ESC key combo is pressed. Through testing it was
      discovered that this function causes the LED to update correctly to
      reflect the current state when this function is called.
      
      The relevant ACPI calls are the following:
      \_SB_.PCI0.LPC0.EC0_.HKEY.GMKS: Get media key state, returns 0x603 if the FnLock mode is enabled, and 0x602 if it's disabled.
      \_SB_.PCI0.LPC0.EC0_.HKEY.SMKS: Set media key state, sending a 1 will enable FnLock mode, and a 0 will disable it.
      
      Relevant discussion:
      https://bugzilla.kernel.org/show_bug.cgi?id=207841
      https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1881015
      
      Signed-off-by: default avatarEsteve Varela Colominas <esteve.varela@gmail.com>
      Link: https://lore.kernel.org/r/20210315195823.23212-1-esteve.varela@gmail.com
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c36b82c4
    • Rob Clark's avatar
      drm/msm: Ratelimit invalid-fence message · 0865d928
      Rob Clark authored
      [ Upstream commit 7ad48d27
      
       ]
      
      We have seen a couple cases where low memory situations cause something
      bad to happen, followed by a flood of these messages obscuring the root
      cause.  Lets ratelimit the dmesg spam so that next time it happens we
      don't lose the kernel traces leading up to this.
      
      Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
      Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0865d928
    • Karthikeyan Kathirvel's avatar
      mac80211: choose first enabled channel for monitor · d601353c
      Karthikeyan Kathirvel authored
      [ Upstream commit 041c881a
      
       ]
      
      Even if the first channel from sband channel list is invalid
      or disabled mac80211 ends up choosing it as the default channel
      for monitor interfaces, making them not usable.
      
      Fix this by assigning the first available valid or enabled
      channel instead.
      
      Signed-off-by: default avatarKarthikeyan Kathirvel <kathirve@codeaurora.org>
      Link: https://lore.kernel.org/r/1615440547-7661-1-git-send-email-kathirve@codeaurora.org
      [reword commit message, comment, code cleanups]
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d601353c
    • Tong Zhang's avatar
      mISDN: fix crash in fritzpci · f2600b3e
      Tong Zhang authored
      [ Upstream commit a9f81244
      
       ]
      
      setup_fritz() in avmfritz.c might fail with -EIO and in this case the
      isac.type and isac.write_reg is not initialized and remains 0(NULL).
      A subsequent call to isac_release() will dereference isac->write_reg and
      crash.
      
      [    1.737444] BUG: kernel NULL pointer dereference, address: 0000000000000000
      [    1.737809] #PF: supervisor instruction fetch in kernel mode
      [    1.738106] #PF: error_code(0x0010) - not-present page
      [    1.738378] PGD 0 P4D 0
      [    1.738515] Oops: 0010 [#1] SMP NOPTI
      [    1.738711] CPU: 0 PID: 180 Comm: systemd-udevd Not tainted 5.12.0-rc2+ #78
      [    1.739077] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-48-gd9c812dda519-p
      rebuilt.qemu.org 04/01/2014
      [    1.739664] RIP: 0010:0x0
      [    1.739807] Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
      [    1.740200] RSP: 0018:ffffc9000027ba10 EFLAGS: 00010202
      [    1.740478] RAX: 0000000000000000 RBX: ffff888102f41840 RCX: 0000000000000027
      [    1.740853] RDX: 00000000000000ff RSI: 0000000000000020 RDI: ffff888102f41800
      [    1.741226] RBP: ffffc9000027ba20 R08: ffff88817bc18440 R09: ffffc9000027b808
      [    1.741600] R10: 0000000000000001 R11: 0000000000000001 R12: ffff888102f41840
      [    1.741976] R13: 00000000fffffffb R14: ffff888102f41800 R15: ffff8881008b0000
      [    1.742351] FS:  00007fda3a38a8c0(0000) GS:ffff88817bc00000(0000) knlGS:0000000000000000
      [    1.742774] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [    1.743076] CR2: ffffffffffffffd6 CR3: 00000001021ec000 CR4: 00000000000006f0
      [    1.743452] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [    1.743828] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [    1.744206] Call Trace:
      [    1.744339]  isac_release+0xcc/0xe0 [mISDNipac]
      [    1.744582]  fritzpci_probe.cold+0x282/0x739 [avmfritz]
      [    1.744861]  local_pci_probe+0x48/0x80
      [    1.745063]  pci_device_probe+0x10f/0x1c0
      [    1.745278]  really_probe+0xfb/0x420
      [    1.745471]  driver_probe_device+0xe9/0x160
      [    1.745693]  device_driver_attach+0x5d/0x70
      [    1.745917]  __driver_attach+0x8f/0x150
      [    1.746123]  ? device_driver_attach+0x70/0x70
      [    1.746354]  bus_for_each_dev+0x7e/0xc0
      [    1.746560]  driver_attach+0x1e/0x20
      [    1.746751]  bus_add_driver+0x152/0x1f0
      [    1.746957]  driver_register+0x74/0xd0
      [    1.747157]  ? 0xffffffffc00d8000
      [    1.747334]  __pci_register_driver+0x54/0x60
      [    1.747562]  AVM_init+0x36/0x1000 [avmfritz]
      [    1.747791]  do_one_initcall+0x48/0x1d0
      [    1.747997]  ? __cond_resched+0x19/0x30
      [    1.748206]  ? kmem_cache_alloc_trace+0x390/0x440
      [    1.748458]  ? do_init_module+0x28/0x250
      [    1.748669]  do_init_module+0x62/0x250
      [    1.748870]  load_module+0x23ee/0x26a0
      [    1.749073]  __do_sys_finit_module+0xc2/0x120
      [    1.749307]  ? __do_sys_finit_module+0xc2/0x120
      [    1.749549]  __x64_sys_finit_module+0x1a/0x20
      [    1.749782]  do_syscall_64+0x38/0x90
      
      Signed-off-by: default avatarTong Zhang <ztong0001@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f2600b3e
    • Pavel Andrianov's avatar
      net: pxa168_eth: Fix a potential data race in pxa168_eth_remove · 25c101b6
      Pavel Andrianov authored
      [ Upstream commit 0571a753
      
       ]
      
      pxa168_eth_remove() firstly calls unregister_netdev(),
      then cancels a timeout work. unregister_netdev() shuts down a device
      interface and removes it from the kernel tables. If the timeout occurs
      in parallel, the timeout work (pxa168_eth_tx_timeout_task) performs stop
      and open of the device. It may lead to an inconsistent state and memory
      leaks.
      
      Found by Linux Driver Verification project (linuxtesting.org).
      
      Signed-off-by: default avatarPavel Andrianov <andrianov@ispras.ru>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      25c101b6
    • Mans Rullgard's avatar
      ARM: dts: am33xx: add aliases for mmc interfaces · 7c12753c
      Mans Rullgard authored
      [ Upstream commit 9bbce32a ]
      
      Without DT aliases, the numbering of mmc interfaces is unpredictable.
      Adding them makes it possible to refer to devices consistently.  The
      popular suggestion to use UUIDs obviously doesn't work with a blank
      device fresh from the factory.
      
      See commit fa2d0aa9
      
       ("mmc: core: Allow setting slot index via
      device tree alias") for more discussion.
      
      Signed-off-by: default avatarMans Rullgard <mans@mansr.com>
      Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7c12753c
  2. Apr 07, 2021
    • Greg Kroah-Hartman's avatar
      Linux 4.14.229 · 0cc24401
      Greg Kroah-Hartman authored
      
      
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Tested-by: default avatarJason Self <jason@bluehome.net>
      Tested-by: default avatarLinux Kernel Functional Testing <lkft@linaro.org>
      Tested-by: default avatarHulk Robot <hulkrobot@huawei.com>
      Tested-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Link: https://lore.kernel.org/r/20210405085021.996963957@linuxfoundation.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      v4.14.229
      0cc24401
    • Du Cheng's avatar
      drivers: video: fbcon: fix NULL dereference in fbcon_cursor() · 1e353852
      Du Cheng authored
      commit 01faae51
      
       upstream.
      
      add null-check on function pointer before dereference on ops->cursor
      
      Reported-by: default avatar <syzbot+b67aaae8d3a927f68d20@syzkaller.appspotmail.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarDu Cheng <ducheng2@gmail.com>
      Link: https://lore.kernel.org/r/20210312081421.452405-1-ducheng2@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1e353852
    • Atul Gopinathan's avatar
      staging: rtl8192e: Change state information from u16 to u8 · 2bcc14fc
      Atul Gopinathan authored
      commit e78836ae upstream.
      
      The "u16 CcxRmState[2];" array field in struct "rtllib_network" has 4
      bytes in total while the operations performed on this array through-out
      the code base are only 2 bytes.
      
      The "CcxRmState" field is fed only 2 bytes of data using memcpy():
      
      (In rtllib_rx.c:1972)
      	memcpy(network->CcxRmState, &info_element->data[4], 2)
      
      With "info_element->data[]" being a u8 array, if 2 bytes are written
      into "CcxRmState" (whose one element is u16 size), then the 2 u8
      elements from "data[]" gets squashed and written into the first element
      ("CcxRmState[0]") while the second element ("CcxRmState[1]") is never
      fed with any data.
      
      Same in file rtllib_rx.c:2522:
      	 memcpy(dst->CcxRmState, src->CcxRmState, 2);
      
      The above line duplicates "src" data to "dst" but only writes 2 bytes
      (and not 4, which is the actual size). Again, only 1st element gets the
      value while the 2nd element remains uninitialized.
      
      This later makes operations done with CcxRmState unpredictable in the
      following lines as the 1st element is having a squashed number while the
      2nd element is having an uninitialized random number.
      
      rtllib_rx.c:1973:    if (network->CcxRmState[0] != 0)
      rtllib_rx.c:1977:    network->MBssidMask = network->CcxRmState[1] & 0x07;
      
      network->MBssidMask is also of type u8 and not u16.
      
      Fix this by changing the type of "CcxRmState" from u16 to u8 so that the
      data written into this array and read from it make sense and are not
      random values.
      
      NOTE: The wrong initialization of "CcxRmState" can be seen in the
      following commit:
      
      commit ecdfa446 ("Staging: add Realtek 8192 PCI wireless driver")
      
      The above commit created a file `rtl8192e/ieee80211.h` which used to
      have the faulty line. The file has been deleted (or possibly renamed)
      with the contents copied in to a new file `rtl8192e/rtllib.h` along with
      additional code in the commit 94a79942 (tagged in Fixes).
      
      Fixes: 94a79942
      
       ("From: wlanfae <wlanfae@realtek.com> [PATCH 1/8] rtl8192e: Import new version of driver from realtek")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAtul Gopinathan <atulgopinathan@gmail.com>
      Link: https://lore.kernel.org/r/20210323113413.29179-2-atulgopinathan@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2bcc14fc
    • Atul Gopinathan's avatar
      staging: rtl8192e: Fix incorrect source in memcpy() · 69811446
      Atul Gopinathan authored
      commit 72ad25fb upstream.
      
      The variable "info_element" is of the following type:
      
      	struct rtllib_info_element *info_element
      
      defined in drivers/staging/rtl8192e/rtllib.h:
      
      	struct rtllib_info_element {
      		u8 id;
      		u8 len;
      		u8 data[];
      	} __packed;
      
      The "len" field defines the size of the "data[]" array. The code is
      supposed to check if "info_element->len" is greater than 4 and later
      equal to 6. If this is satisfied then, the last two bytes (the 4th and
      5th element of u8 "data[]" array) are copied into "network->CcxRmState".
      
      Right now the code uses "memcpy()" with the source as "&info_element[4]"
      which would copy in wrong and unintended information. The struct
      "rtllib_info_element" has a size of 2 bytes for "id" and "len",
      therefore indexing will be done in interval of 2 bytes. So,
      "info_element[4]" would point to data which is beyond the memory
      allocated for this pointer (that is, at x+8, while "info_element" has
      been allocated only from x to x+7 (2 + 6 => 8 bytes)).
      
      This patch rectifies this error by using "&info_element->data[4]" which
      correctly copies the last two bytes of "data[]".
      
      NOTE: The faulty line of code came from the following commit:
      
      commit ecdfa446 ("Staging: add Realtek 8192 PCI wireless driver")
      
      The above commit created the file `rtl8192e/ieee80211/ieee80211_rx.c`
      which had the faulty line of code. This file has been deleted (or
      possibly renamed) with the contents copied in to a new file
      `rtl8192e/rtllib_rx.c` along with additional code in the commit
      94a79942 (tagged in Fixes).
      
      Fixes: 94a79942
      
       ("From: wlanfae <wlanfae@realtek.com> [PATCH 1/8] rtl8192e: Import new version of driver from realtek")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAtul Gopinathan <atulgopinathan@gmail.com>
      Link: https://lore.kernel.org/r/20210323113413.29179-1-atulgopinathan@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69811446
    • Tong Zhang's avatar
      usb: gadget: udc: amd5536udc_pci fix null-ptr-dereference · 6b4aa865
      Tong Zhang authored
      commit 72035f49 upstream.
      
      init_dma_pools() calls dma_pool_create(...dev->dev) to create dma pool.
      however, dev->dev is actually set after calling init_dma_pools(), which
      effectively makes dma_pool_create(..NULL) and cause crash.
      To fix this issue, init dma only after dev->dev is set.
      
      [    1.317993] RIP: 0010:dma_pool_create+0x83/0x290
      [    1.323257] Call Trace:
      [    1.323390]  ? pci_write_config_word+0x27/0x30
      [    1.323626]  init_dma_pools+0x41/0x1a0 [snps_udc_core]
      [    1.323899]  udc_pci_probe+0x202/0x2b1 [amd5536udc_pci]
      
      Fixes: 7c51247a
      
       (usb: gadget: udc: Provide correct arguments for 'dma_pool_create')
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarTong Zhang <ztong0001@gmail.com>
      Link: https://lore.kernel.org/r/20210317230400.357756-1-ztong0001@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6b4aa865
    • Johan Hovold's avatar
      USB: cdc-acm: fix use-after-free after probe failure · a110a1d0
      Johan Hovold authored
      commit 4e49bf37 upstream.
      
      If tty-device registration fails the driver would fail to release the
      data interface. When the device is later disconnected, the disconnect
      callback would still be called for the data interface and would go about
      releasing already freed resources.
      
      Fixes: c93d8195
      
       ("usb: cdc-acm: fix error handling in acm_probe()")
      Cc: stable@vger.kernel.org      # 3.9
      Cc: Alexey Khoroshilov <khoroshilov@ispras.ru>
      Acked-by: default avatarOliver Neukum <oneukum@suse.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Link: https://lore.kernel.org/r/20210322155318.9837-3-johan@kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a110a1d0
    • Oliver Neukum's avatar
      USB: cdc-acm: downgrade message to debug · 88fc6e1a
      Oliver Neukum authored
      commit e4c77070
      
       upstream.
      
      This failure is so common that logging an error here amounts
      to spamming log files.
      
      Reviewed-by: default avatarBruno Thomsen <bruno.thomsen@gmail.com>
      Signed-off-by: default avatarOliver Neukum <oneukum@suse.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210311130126.15972-2-oneukum@suse.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      88fc6e1a
    • Oliver Neukum's avatar
      USB: cdc-acm: untangle a circular dependency between callback and softint · 0ea16074
      Oliver Neukum authored
      commit 6069e3e9
      
       upstream.
      
      We have a cycle of callbacks scheduling works which submit
      URBs with thos callbacks. This needs to be blocked, stopped
      and unblocked to untangle the circle.
      
      The issue leads to faults like:
      
      [   55.068392] Unable to handle kernel paging request at virtual address 6b6b6c03
      [   55.075624] pgd = be866494
      [   55.078335] [6b6b6c03] *pgd=00000000
      [   55.081924] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
      [   55.087238] Modules linked in: ppp_async crc_ccitt ppp_generic slhc
      xt_TCPMSS xt_tcpmss xt_hl nf_log_ipv6 nf_log_ipv4 nf_log_common
      xt_policy xt_limit xt_conntrack xt_tcpudp xt_pkttype ip6table_mangle
      iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4
      iptable_mangle ip6table_filter ip6_tables iptable_filter ip_tables
      des_generic md5 sch_fq_codel cdc_mbim cdc_wdm cdc_ncm usbnet mii
      cdc_acm usb_storage ip_tunnel xfrm_user xfrm6_tunnel tunnel6
      xfrm4_tunnel tunnel4 esp6 esp4 ah6 ah4 xfrm_algo xt_LOG xt_LED
      xt_comment x_tables ipv6
      [   55.134954] CPU: 0 PID: 82 Comm: kworker/0:2 Tainted: G
         T 5.8.17 #1
      [   55.142526] Hardware name: Freescale i.MX7 Dual (Device Tree)
      [   55.148304] Workqueue: events acm_softint [cdc_acm]
      [   55.153196] PC is at kobject_get+0x10/0xa4
      [   55.157302] LR is at usb_get_dev+0x14/0x1c
      [   55.161402] pc : [<8047c06c>]    lr : [<80560448>]    psr: 20000193
      [   55.167671] sp : bca39ea8  ip : 00007374  fp : bf6cbd80
      [   55.172899] r10: 00000000  r9 : bdd92284  r8 : bdd92008
      [   55.178128] r7 : 6b6b6b6b  r6 : fffffffe  r5 : 60000113  r4 : 6b6b6be3
      [   55.184658] r3 : 6b6b6b6b  r2 : 00000111  r1 : 00000000  r0 : 6b6b6be3
      [   55.191191] Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM Segment none
      [   55.198417] Control: 10c5387d  Table: bcf0c06a  DAC: 00000051
      [   55.204168] Process kworker/0:2 (pid: 82, stack limit = 0x9bdd2a89)
      [   55.210439] Stack: (0xbca39ea8 to 0xbca3a000)
      [   55.214805] 9ea0:                   bf6cbd80 80769a50 6b6b6b6b 80560448 bdeb0500 8056bfe8
      [   55.222991] 9ec0: 00000002 b76da000 00000000 bdeb0500 bdd92448 bca38000 bdeb0510 8056d69c
      [   55.231177] 9ee0: bca38000 00000000 80c050fc 00000000 bca39f44 09d42015 00000000 00000001
      [   55.239363] 9f00: bdd92448 bdd92438 bdd92000 7f1158c4 bdd92448 bca2ee00 bf6cbd80 bf6cef00
      [   55.247549] 9f20: 00000000 00000000 00000000 801412d8 bf6cbd98 80c03d00 bca2ee00 bf6cbd80
      [   55.255735] 9f40: bca2ee14 bf6cbd98 80c03d00 00000008 bca38000 80141568 00000000 80c446ae
      [   55.263921] 9f60: 00000000 bc9ed880 bc9f0700 bca38000 bc117eb4 80141524 bca2ee00 bc9ed8a4
      [   55.272107] 9f80: 00000000 80147cc8 00000000 bc9f0700 80147b84 00000000 00000000 00000000
      [   55.280292] 9fa0: 00000000 00000000 00000000 80100148 00000000 00000000 00000000 00000000
      [   55.288477] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
      [   55.296662] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000
      [   55.304860] [<8047c06c>] (kobject_get) from [<80560448>] (usb_get_dev+0x14/0x1c)
      [   55.312271] [<80560448>] (usb_get_dev) from [<8056bfe8>] (usb_hcd_unlink_urb+0x50/0xd8)
      [   55.320286] [<8056bfe8>] (usb_hcd_unlink_urb) from [<8056d69c>] (usb_kill_urb.part.0+0x44/0xd0)
      [   55.329004] [<8056d69c>] (usb_kill_urb.part.0) from [<7f1158c4>] (acm_softint+0x4c/0x10c [cdc_acm])
      [   55.338082] [<7f1158c4>] (acm_softint [cdc_acm]) from [<801412d8>] (process_one_work+0x19c/0x3e8)
      [   55.346969] [<801412d8>] (process_one_work) from [<80141568>] (worker_thread+0x44/0x4dc)
      [   55.355072] [<80141568>] (worker_thread) from [<80147cc8>] (kthread+0x144/0x180)
      [   55.362481] [<80147cc8>] (kthread) from [<80100148>] (ret_from_fork+0x14/0x2c)
      [   55.369706] Exception stack(0xbca39fb0 to 0xbca39ff8)
      
      Tested-by: default avatarBruno Thomsen <bruno.thomsen@gmail.com>
      Signed-off-by: default avatarOliver Neukum <oneukum@suse.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210311130126.15972-1-oneukum@suse.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0ea16074
    • Oliver Neukum's avatar
      cdc-acm: fix BREAK rx code path adding necessary calls · 5b00c605
      Oliver Neukum authored
      commit 08dff274 upstream.
      
      Counting break events is nice but we should actually report them to
      the tty layer.
      
      Fixes: 5a6a62bd
      
       ("cdc-acm: add TIOCMIWAIT")
      Signed-off-by: default avatarOliver Neukum <oneukum@suse.com>
      Link: https://lore.kernel.org/r/20210311133714.31881-1-oneukum@suse.com
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5b00c605
    • Chunfeng Yun's avatar
      usb: xhci-mtk: fix broken streams issue on 0.96 xHCI · 7d8a4016
      Chunfeng Yun authored
      commit 6f978a30 upstream.
      
      The MediaTek 0.96 xHCI controller on some platforms does not
      support bulk stream even HCCPARAMS says supporting, due to MaxPSASize
      is set a default value 1 by mistake, here use XHCI_BROKEN_STREAMS
      quirk to fix it.
      
      Fixes: 94a631d9
      
       ("usb: xhci-mtk: check hcc_params after adding primary hcd")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarChunfeng Yun <chunfeng.yun@mediatek.com>
      Link: https://lore.kernel.org/r/1616482975-17841-4-git-send-email-chunfeng.yun@mediatek.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7d8a4016
    • Tony Lindgren's avatar
      usb: musb: Fix suspend with devices connected for a64 · 5dc2a68b
      Tony Lindgren authored
      commit 92af4fc6 upstream.
      
      Pinephone running on Allwinner A64 fails to suspend with USB devices
      connected as reported by Bhushan Shah <bshah@kde.org>. Reverting
      commit 5fbf7a25 ("usb: musb: fix idling for suspend after
      disconnect interrupt") fixes the issue.
      
      Let's add suspend checks also for suspend after disconnect interrupt
      quirk handling like we already do elsewhere.
      
      Fixes: 5fbf7a25
      
       ("usb: musb: fix idling for suspend after disconnect interrupt")
      Reported-by: default avatarBhushan Shah <bshah@kde.org>
      Tested-by: default avatarBhushan Shah <bshah@kde.org>
      Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
      Link: https://lore.kernel.org/r/20210324071142.42264-1-tony@atomide.com
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5dc2a68b
    • Vincent Palatin's avatar
      USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem · 99b948bd
      Vincent Palatin authored
      commit 0bd86049
      
       upstream.
      
      This LTE modem (M.2 card) has a bug in its power management:
      there is some kind of race condition for U3 wake-up between the host and
      the device. The modem firmware sometimes crashes/locks when both events
      happen at the same time and the modem fully drops off the USB bus (and
      sometimes re-enumerates, sometimes just gets stuck until the next
      reboot).
      
      Tested with the modem wired to the XHCI controller on an AMD 3015Ce
      platform. Without the patch, the modem dropped of the USB bus 5 times in
      3 days. With the quirk, it stayed connected for a week while the
      'runtime_suspended_time' counter incremented as excepted.
      
      Signed-off-by: default avatarVincent Palatin <vpalatin@chromium.org>
      Link: https://lore.kernel.org/r/20210319124802.2315195-1-vpalatin@chromium.org
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      99b948bd
    • Shuah Khan's avatar
      usbip: vhci_hcd fix shift out-of-bounds in vhci_hub_control() · ae6d3a93
      Shuah Khan authored
      commit 1cc5ed25
      
       upstream.
      
      Fix shift out-of-bounds in vhci_hub_control() SetPortFeature handling.
      
      UBSAN: shift-out-of-bounds in drivers/usb/usbip/vhci_hcd.c:605:42
      shift exponent 768 is too large for 32-bit type 'int'
      
      Reported-by: default avatar <syzbot+3dea30b047f41084de66@syzkaller.appspotmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Link: https://lore.kernel.org/r/20210324230654.34798-1-skhan@linuxfoundation.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ae6d3a93
    • Zheyu Ma's avatar
      firewire: nosy: Fix a use-after-free bug in nosy_ioctl() · 8aa6e548
      Zheyu Ma authored
      [ Upstream commit 829933ef
      
       ]
      
      For each device, the nosy driver allocates a pcilynx structure.
      A use-after-free might happen in the following scenario:
      
       1. Open nosy device for the first time and call ioctl with command
          NOSY_IOC_START, then a new client A will be malloced and added to
          doubly linked list.
       2. Open nosy device for the second time and call ioctl with command
          NOSY_IOC_START, then a new client B will be malloced and added to
          doubly linked list.
       3. Call ioctl with command NOSY_IOC_START for client A, then client A
          will be readded to the doubly linked list. Now the doubly linked
          list is messed up.
       4. Close the first nosy device and nosy_release will be called. In
          nosy_release, client A will be unlinked and freed.
       5. Close the second nosy device, and client A will be referenced,
          resulting in UAF.
      
      The root cause of this bug is that the element in the doubly linked list
      is reentered into the list.
      
      Fix this bug by adding a check before inserting a client.  If a client
      is already in the linked list, don't insert it.
      
      The following KASAN report reveals it:
      
         BUG: KASAN: use-after-free in nosy_release+0x1ea/0x210
         Write of size 8 at addr ffff888102ad7360 by task poc
         CPU: 3 PID: 337 Comm: poc Not tainted 5.12.0-rc5+ #6
         Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.12.0-59-gc9ba5276e321-prebuilt.qemu.org 04/01/2014
         Call Trace:
           nosy_release+0x1ea/0x210
           __fput+0x1e2/0x840
           task_work_run+0xe8/0x180
           exit_to_user_mode_prepare+0x114/0x120
           syscall_exit_to_user_mode+0x1d/0x40
           entry_SYSCALL_64_after_hwframe+0x44/0xae
      
         Allocated by task 337:
           nosy_open+0x154/0x4d0
           misc_open+0x2ec/0x410
           chrdev_open+0x20d/0x5a0
           do_dentry_open+0x40f/0xe80
           path_openat+0x1cf9/0x37b0
           do_filp_open+0x16d/0x390
           do_sys_openat2+0x11d/0x360
           __x64_sys_open+0xfd/0x1a0
           do_syscall_64+0x33/0x40
           entry_SYSCALL_64_after_hwframe+0x44/0xae
      
         Freed by task 337:
           kfree+0x8f/0x210
           nosy_release+0x158/0x210
           __fput+0x1e2/0x840
           task_work_run+0xe8/0x180
           exit_to_user_mode_prepare+0x114/0x120
           syscall_exit_to_user_mode+0x1d/0x40
           entry_SYSCALL_64_after_hwframe+0x44/0xae
      
         The buggy address belongs to the object at ffff888102ad7300 which belongs to the cache kmalloc-128 of size 128
         The buggy address is located 96 bytes inside of 128-byte region [ffff888102ad7300, ffff888102ad7380)
      
      [ Modified to use 'list_empty()' inside proper lock  - Linus ]
      
      Link: https://lore.kernel.org/lkml/1617433116-5930-1-git-send-email-zheyuma97@gmail.com/
      Reported-and-tested-by: default avatar马哲宇 (Zheyu Ma) <zheyuma97@gmail.com>
      Signed-off-by: default avatarZheyu Ma <zheyuma97@gmail.com>
      Cc: Greg Kroah-Hartman <greg@kroah.com>
      Cc: Stefan Richter <stefanr@s5r6.in-berlin.de>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8aa6e548
    • Dinghao Liu's avatar
      extcon: Fix error handling in extcon_dev_register · 2d956c59
      Dinghao Liu authored
      [ Upstream commit d3bdd1c3 ]
      
      When devm_kcalloc() fails, we should execute device_unregister()
      to unregister edev->dev from system.
      
      Fixes: 046050f6
      
       ("extcon: Update the prototype of extcon_register_notifier() with enum extcon")
      Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
      Signed-off-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2d956c59
    • Krzysztof Kozlowski's avatar
      extcon: Add stubs for extcon_register_notifier_all() functions · 8fb4f3e4
      Krzysztof Kozlowski authored
      [ Upstream commit c9570d4a ]
      
      Add stubs for extcon_register_notifier_all() function for !CONFIG_EXTCON
      case.  This is useful for compile testing and for drivers which use
      EXTCON but do not require it (therefore do not depend on CONFIG_EXTCON).
      
      Fixes: 815429b3
      
       ("extcon: Add new extcon_register_notifier_all() to monitor all external connectors")
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8fb4f3e4
    • Wang Panzhenzhuan's avatar
      pinctrl: rockchip: fix restore error in resume · b48ed846
      Wang Panzhenzhuan authored
      commit c971af25 upstream.
      
      The restore in resume should match to suspend which only set for RK3288
      SoCs pinctrl.
      
      Fixes: 8dca9331
      
       ("pinctrl: rockchip: save and restore gpio6_c6 pinmux in suspend/resume")
      Reviewed-by: default avatarJianqun Xu <jay.xu@rock-chips.com>
      Reviewed-by: default avatarHeiko Stuebner <heiko@sntech.de>
      Signed-off-by: default avatarWang Panzhenzhuan <randy.wang@rock-chips.com>
      Signed-off-by: default avatarJianqun Xu <jay.xu@rock-chips.com>
      Link: https://lore.kernel.org/r/20210223100725.269240-1-jay.xu@rock-chips.com
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b48ed846
    • Greg Thelen's avatar
      mm: writeback: use exact memcg dirty counts · f34769a0
      Greg Thelen authored
      commit 0b3d6e6f upstream.
      
      Since commit a983b5eb
      
       ("mm: memcontrol: fix excessive complexity in
      memory.stat reporting") memcg dirty and writeback counters are managed
      as:
      
       1) per-memcg per-cpu values in range of [-32..32]
      
       2) per-memcg atomic counter
      
      When a per-cpu counter cannot fit in [-32..32] it's flushed to the
      atomic.  Stat readers only check the atomic.  Thus readers such as
      balance_dirty_pages() may see a nontrivial error margin: 32 pages per
      cpu.
      
      Assuming 100 cpus:
         4k x86 page_size:  13 MiB error per memcg
        64k ppc page_size: 200 MiB error per memcg
      
      Considering that dirty+writeback are used together for some decisions the
      errors double.
      
      This inaccuracy can lead to undeserved oom kills.  One nasty case is
      when all per-cpu counters hold positive values offsetting an atomic
      negative value (i.e.  per_cpu[*]=32, atomic=n_cpu*-32).
      balance_dirty_pages() only consults the atomic and does not consider
      throttling the next n_cpu*32 dirty pages.  If the file_lru is in the
      13..200 MiB range then there's absolutely no dirty throttling, which
      burdens vmscan with only dirty+writeback pages thus resorting to oom
      kill.
      
      It could be argued that tiny containers are not supported, but it's more
      subtle.  It's the amount the space available for file lru that matters.
      If a container has memory.max-200MiB of non reclaimable memory, then it
      will also suffer such oom kills on a 100 cpu machine.
      
      The following test reliably ooms without this patch.  This patch avoids
      oom kills.
      
        $ cat test
        mount -t cgroup2 none /dev/cgroup
        cd /dev/cgroup
        echo +io +memory > cgroup.subtree_control
        mkdir test
        cd test
        echo 10M > memory.max
        (echo $BASHPID > cgroup.procs && exec /memcg-writeback-stress /foo)
        (echo $BASHPID > cgroup.procs && exec dd if=/dev/zero of=/foo bs=2M count=100)
      
        $ cat memcg-writeback-stress.c
        /*
         * Dirty pages from all but one cpu.
         * Clean pages from the non dirtying cpu.
         * This is to stress per cpu counter imbalance.
         * On a 100 cpu machine:
         * - per memcg per cpu dirty count is 32 pages for each of 99 cpus
         * - per memcg atomic is -99*32 pages
         * - thus the complete dirty limit: sum of all counters 0
         * - balance_dirty_pages() only sees atomic count -99*32 pages, which
         *   it max()s to 0.
         * - So a workload can dirty -99*32 pages before balance_dirty_pages()
         *   cares.
         */
        #define _GNU_SOURCE
        #include <err.h>
        #include <fcntl.h>
        #include <sched.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <sys/stat.h>
        #include <sys/sysinfo.h>
        #include <sys/types.h>
        #include <unistd.h>
      
        static char *buf;
        static int bufSize;
      
        static void set_affinity(int cpu)
        {
        	cpu_set_t affinity;
      
        	CPU_ZERO(&affinity);
        	CPU_SET(cpu, &affinity);
        	if (sched_setaffinity(0, sizeof(affinity), &affinity))
        		err(1, "sched_setaffinity");
        }
      
        static void dirty_on(int output_fd, int cpu)
        {
        	int i, wrote;
      
        	set_affinity(cpu);
        	for (i = 0; i < 32; i++) {
        		for (wrote = 0; wrote < bufSize; ) {
        			int ret = write(output_fd, buf+wrote, bufSize-wrote);
        			if (ret == -1)
        				err(1, "write");
        			wrote += ret;
        		}
        	}
        }
      
        int main(int argc, char **argv)
        {
        	int cpu, flush_cpu = 1, output_fd;
        	const char *output;
      
        	if (argc != 2)
        		errx(1, "usage: output_file");
      
        	output = argv[1];
        	bufSize = getpagesize();
        	buf = malloc(getpagesize());
        	if (buf == NULL)
        		errx(1, "malloc failed");
      
        	output_fd = open(output, O_CREAT|O_RDWR);
        	if (output_fd == -1)
        		err(1, "open(%s)", output);
      
        	for (cpu = 0; cpu < get_nprocs(); cpu++) {
        		if (cpu != flush_cpu)
        			dirty_on(output_fd, cpu);
        	}
      
        	set_affinity(flush_cpu);
        	if (fsync(output_fd))
        		err(1, "fsync(%s)", output);
        	if (close(output_fd))
        		err(1, "close(%s)", output);
        	free(buf);
        }
      
      Make balance_dirty_pages() and wb_over_bg_thresh() work harder to
      collect exact per memcg counters.  This avoids the aforementioned oom
      kills.
      
      This does not affect the overhead of memory.stat, which still reads the
      single atomic counter.
      
      Why not use percpu_counter? memcg already handles cpus going offline, so
      no need for that overhead from percpu_counter.  And the percpu_counter
      spinlocks are more heavyweight than is required.
      
      It probably also makes sense to use exact dirty and writeback counters
      in memcg oom reports.  But that is saved for later.
      
      Link: http://lkml.kernel.org/r/20190329174609.164344-1-gthelen@google.com
      Signed-off-by: default avatarGreg Thelen <gthelen@google.com>
      Reviewed-by: default avatarRoman Gushchin <guro@fb.com>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: <stable@vger.kernel.org>	[4.16+]
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f34769a0
    • Roman Gushchin's avatar
      mm: fix oom_kill event handling · 6f599379
      Roman Gushchin authored
      commit fe6bdfc8 upstream.
      
      Commit e27be240
      
       ("mm: memcg: make sure memory.events is uptodate
      when waking pollers") converted most of memcg event counters to
      per-memcg atomics, which made them less confusing for a user.  The
      "oom_kill" counter remained untouched, so now it behaves differently
      than other counters (including "oom").  This adds nothing but confusion.
      
      Let's fix this by adding the MEMCG_OOM_KILL event, and follow the
      MEMCG_OOM approach.
      
      This also removes a hack from count_memcg_event_mm(), introduced earlier
      specially for the OOM_KILL counter.
      
      [akpm@linux-foundation.org: fix for droppage of memcg-replace-mm-owner-with-mm-memcg.patch]
      Link: http://lkml.kernel.org/r/20180508124637.29984-1-guro@fb.com
      Signed-off-by: default avatarRoman Gushchin <guro@fb.com>
      Acked-by: default avatarKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Acked-by: default avatarMichal Hocko <mhocko@suse.com>
      Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      [fllinden@amazon.com: backport to 4.14, minor contextual changes]
      Signed-off-by: default avatarFrank van der Linden <fllinden@amazon.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6f599379
    • Aaron Lu's avatar
      mem_cgroup: make sure moving_account, move_lock_task and stat_cpu in the same cacheline · ad6e2898
      Aaron Lu authored
      commit e81bf979 upstream.
      
      The LKP robot found a 27% will-it-scale/page_fault3 performance
      regression regarding commit e27be240
      
      ("mm: memcg: make sure
      memory.events is uptodate when waking pollers").
      
      What the test does is:
       1 mkstemp() a 128M file on a tmpfs;
       2 start $nr_cpu processes, each to loop the following:
         2.1 mmap() this file in shared write mode;
         2.2 write 0 to this file in a PAGE_SIZE step till the end of the file;
         2.3 unmap() this file and repeat this process.
       3 After 5 minutes, check how many loops they managed to complete, the
         higher the better.
      
      The commit itself looks innocent enough as it merely changed some event
      counting mechanism and this test didn't trigger those events at all.
      Perf shows increased cycles spent on accessing root_mem_cgroup->stat_cpu
      in count_memcg_event_mm()(called by handle_mm_fault()) and in
      __mod_memcg_state() called by page_add_file_rmap().  So it's likely due
      to the changed layout of 'struct mem_cgroup' that either make stat_cpu
      falling into a constantly modifying cacheline or some hot fields stop
      being in the same cacheline.
      
      I verified this by moving memory_events[] back to where it was:
      
      : --- a/include/linux/memcontrol.h
      : +++ b/include/linux/memcontrol.h
      : @@ -205,7 +205,6 @@ struct mem_cgroup {
      :  	int		oom_kill_disable;
      :
      :  	/* memory.events */
      : -	atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS];
      :  	struct cgroup_file events_file;
      :
      :  	/* protect arrays of thresholds */
      : @@ -238,6 +237,7 @@ struct mem_cgroup {
      :  	struct mem_cgroup_stat_cpu __percpu *stat_cpu;
      :  	atomic_long_t		stat[MEMCG_NR_STAT];
      :  	atomic_long_t		events[NR_VM_EVENT_ITEMS];
      : +	atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS];
      :
      :  	unsigned long		socket_pressure;
      
      And performance restored.
      
      Later investigation found that as long as the following 3 fields
      moving_account, move_lock_task and stat_cpu are in the same cacheline,
      performance will be good.  To avoid future performance surprise by other
      commits changing the layout of 'struct mem_cgroup', this patch makes
      sure the 3 fields stay in the same cacheline.
      
      One concern of this approach is, moving_account and move_lock_task could
      be modified when a process changes memory cgroup while stat_cpu is a
      always read field, it might hurt to place them in the same cacheline.  I
      assume it is rare for a process to change memory cgroup so this should
      be OK.
      
      Link: https://lkml.kernel.org/r/20180528114019.GF9904@yexl-desktop
      Link: http://lkml.kernel.org/r/20180601071115.GA27302@intel.com
      Signed-off-by: default avatarAaron Lu <aaron.lu@intel.com>
      Reported-by: default avatarkernel test robot <xiaolong.ye@intel.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ad6e2898
    • Johannes Weiner's avatar
      mm: memcg: make sure memory.events is uptodate when waking pollers · 09031a8b
      Johannes Weiner authored
      commit e27be240 upstream.
      
      Commit a983b5eb ("mm: memcontrol: fix excessive complexity in
      memory.stat reporting") added per-cpu drift to all memory cgroup stats
      and events shown in memory.stat and memory.events.
      
      For memory.stat this is acceptable.  But memory.events issues file
      notifications, and somebody polling the file for changes will be
      confused when the counters in it are unchanged after a wakeup.
      
      Luckily, the events in memory.events - MEMCG_LOW, MEMCG_HIGH, MEMCG_MAX,
      MEMCG_OOM - are sufficiently rare and high-level that we don't need
      per-cpu buffering for them: MEMCG_HIGH and MEMCG_MAX would be the most
      frequent, but they're counting invocations of reclaim, which is a
      complex operation that touches many shared cachelines.
      
      This splits memory.events from the generic VM events and tracks them in
      their own, unbuffered atomic counters.  That's also cleaner, as it
      eliminates the ugly enum nesting of VM and cgroup events.
      
      [hannes@cmpxchg.org: "array subscript is above array bounds"]
        Link: http://lkml.kernel.org/r/20180406155441.GA20806@cmpxchg.org
      Link: http://lkml.kernel.org/r/20180405175507.GA24817@cmpxchg.org
      Fixes: a983b5eb
      
       ("mm: memcontrol: fix excessive complexity in memory.stat reporting")
      Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Reported-by: default avatarTejun Heo <tj@kernel.org>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Acked-by: default avatarMichal Hocko <mhocko@suse.com>
      Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
      Cc: Roman Gushchin <guro@fb.com>
      Cc: Rik van Riel <riel@surriel.com>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      09031a8b
    • Johannes Weiner's avatar
      mm: memcontrol: fix NR_WRITEBACK leak in memcg and system stats · cfc5a8f4
      Johannes Weiner authored
      commit c3cc3911 upstream.
      
      After commit a983b5eb ("mm: memcontrol: fix excessive complexity in
      memory.stat reporting"), we observed slowly upward creeping NR_WRITEBACK
      counts over the course of several days, both the per-memcg stats as well
      as the system counter in e.g.  /proc/meminfo.
      
      The conversion from full per-cpu stat counts to per-cpu cached atomic
      stat counts introduced an irq-unsafe RMW operation into the updates.
      
      Most stat updates come from process context, but one notable exception
      is the NR_WRITEBACK counter.  While writebacks are issued from process
      context, they are retired from (soft)irq context.
      
      When writeback completions interrupt the RMW counter updates of new
      writebacks being issued, the decs from the completions are lost.
      
      Since the global updates are routed through the joint lruvec API, both
      the memcg counters as well as the system counters are affected.
      
      This patch makes the joint stat and event API irq safe.
      
      Link: http://lkml.kernel.org/r/20180203082353.17284-1-hannes@cmpxchg.org
      Fixes: a983b5eb
      
       ("mm: memcontrol: fix excessive complexity in memory.stat reporting")
      Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Debugged-by: default avatarTejun Heo <tj@kernel.org>
      Reviewed-by: default avatarRik van Riel <riel@surriel.com>
      Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cfc5a8f4
    • Tetsuo Handa's avatar
      reiserfs: update reiserfs_xattrs_initialized() condition · 323900f6
      Tetsuo Handa authored
      commit 5e46d1b7 upstream.
      
      syzbot is reporting NULL pointer dereference at reiserfs_security_init()
      [1], for commit ab17c4f0 ("reiserfs: fixup xattr_root caching")
      is assuming that REISERFS_SB(s)->xattr_root != NULL in
      reiserfs_xattr_jcreate_nblocks() despite that commit made
      REISERFS_SB(sb)->priv_root != NULL && REISERFS_SB(s)->xattr_root == NULL
      case possible.
      
      I guess that commit 6cb4aff0
      
       ("reiserfs: fix oops while creating
      privroot with selinux enabled") wanted to check xattr_root != NULL
      before reiserfs_xattr_jcreate_nblocks(), for the changelog is talking
      about the xattr root.
      
        The issue is that while creating the privroot during mount
        reiserfs_security_init calls reiserfs_xattr_jcreate_nblocks which
        dereferences the xattr root. The xattr root doesn't exist, so we get
        an oops.
      
      Therefore, update reiserfs_xattrs_initialized() to check both the
      privroot and the xattr root.
      
      Link: https://syzkaller.appspot.com/bug?id=8abaedbdeb32c861dc5340544284167dd0e46cde # [1]
      Reported-and-tested-by: default avatarsyzbot <syzbot+690cb1e51970435f9775@syzkaller.appspotmail.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Fixes: 6cb4aff0
      
       ("reiserfs: fix oops while creating privroot with selinux enabled")
      Acked-by: default avatarJeff Mahoney <jeffm@suse.com>
      Acked-by: default avatarJan Kara <jack@suse.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      323900f6
    • Xℹ Ruoyao's avatar
      drm/amdgpu: check alignment on CPU page for bo map · e357ab38
      Xℹ Ruoyao authored
      commit e3512fb6
      
       upstream.
      
      The page table of AMDGPU requires an alignment to CPU page so we should
      check ioctl parameters for it.  Return -EINVAL if some parameter is
      unaligned to CPU page, instead of corrupt the page table sliently.
      
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarXi Ruoyao <xry111@mengyan1223.wang>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e357ab38