1. 05 Sep, 2018 35 commits
    • Sudarsana Reddy Kalluru's avatar
      qed: Fix possible race for the link state value. · f4e284f1
      Sudarsana Reddy Kalluru authored
      [ Upstream commit 58874c7b ]
      
      There's a possible race where driver can read link status in mid-transition
      and see that virtual-link is up yet speed is 0. Since in this
      mid-transition we're guaranteed to see a mailbox from MFW soon, we can
      afford to treat this as link down.
      
      Fixes: cc875c2e ("qed: Add link support")
      Signed-off-by: default avatarSudarsana Reddy Kalluru <Sudarsana.Kalluru@cavium.com>
      Signed-off-by: default avatarAriel Elior <ariel.elior@cavium.com>
      Signed-off-by: default avatarMichal Kalderon <Michal.Kalderon@cavium.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f4e284f1
    • Sudarsana Reddy Kalluru's avatar
      qed: Fix link flap issue due to mismatching EEE capabilities. · 77c65d5f
      Sudarsana Reddy Kalluru authored
      [ Upstream commit 4ad95a93 ]
      
      Apparently, MFW publishes EEE capabilities even for Fiber-boards that don't
      support them, and later since qed internally sets adv_caps it would cause
      link-flap avoidance (LFA) to fail when driver would initiate the link.
      This in turn delays the link, causing traffic to fail.
      
      Driver has been modified to not to ask MFW for any EEE config if EEE isn't
      to be enabled.
      
      Fixes: 645874e5 ("qed: Add support for Energy efficient ethernet.")
      Signed-off-by: default avatarSudarsana Reddy Kalluru <Sudarsana.Kalluru@cavium.com>
      Signed-off-by: default avatarAriel Elior <ariel.elior@cavium.com>
      Signed-off-by: default avatarMichal Kalderon <Michal.Kalderon@cavium.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77c65d5f
    • YueHaibing's avatar
      net: caif: Add a missing rcu_read_unlock() in caif_flow_cb · b970d8a1
      YueHaibing authored
      [ Upstream commit 64119e05 ]
      
      Add a missing rcu_read_unlock in the error path
      
      Fixes: c95567c8 ("caif: added check for potential null return")
      Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b970d8a1
    • Len Brown's avatar
      tools/power turbostat: fix -S on UP systems · a10170d9
      Len Brown authored
      [ Upstream commit 9d83601a ]
      
      The -S (system summary) option failed to print any data on a 1-processor system.
      Reported-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
      Signed-off-by: default avatarLen Brown <len.brown@intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a10170d9
    • Sean Christopherson's avatar
      KVM: vmx: use local variable for current_vmptr when emulating VMPTRST · 10ca6b3f
      Sean Christopherson authored
      [ Upstream commit 0a06d425 ]
      
      Do not expose the address of vmx->nested.current_vmptr to
      kvm_write_guest_virt_system() as the resulting __copy_to_user()
      call will trigger a WARN when CONFIG_HARDENED_USERCOPY is
      enabled.
      
      Opportunistically clean up variable names in handle_vmptrst()
      to improve readability, e.g. vmcs_gva is misleading as the
      memory operand of VMPTRST is plain memory, not a VMCS.
      Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Tested-by: default avatarPeter Shier <pshier@google.com>
      Reviewed-by: default avatarPeter Shier <pshier@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      10ca6b3f
    • Florian Westphal's avatar
      netfilter: nf_tables: don't allow to rename to already-pending name · 123534db
      Florian Westphal authored
      [ Upstream commit c6cc94df ]
      
      Its possible to rename two chains to the same name in one
      transaction:
      
      nft add chain t c1
      nft add chain t c2
      nft 'rename chain t c1 c3;rename chain t c2 c3'
      
      This creates two chains named 'c3'.
      
      Appears to be harmless, both chains can still be deleted both
      by name or handle, but, nevertheless, its a bug.
      
      Walk transaction log and also compare vs. the pending renames.
      
      Both chains can still be deleted, but nevertheless it is a bug as
      we don't allow to create chains with identical names, so we should
      prevent this from happening-by-rename too.
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      123534db
    • Florian Westphal's avatar
      netfilter: nf_tables: fix memory leaks on chain rename · 4a0144a4
      Florian Westphal authored
      [ Upstream commit 9f8aac0b ]
      
      The new name is stored in the transaction metadata, on commit,
      the pointers to the old and new names are swapped.
      
      Therefore in abort and commit case we have to free the
      pointer in the chain_trans container.
      
      In commit case, the pointer can be used by another cpu that
      is currently dumping the renamed chain, thus kfree needs to
      happen after waiting for rcu readers to complete.
      
      Fixes: b7263e07 ("netfilter: nf_tables: Allow chain name of up to 255 chars")
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4a0144a4
    • Daniel Borkmann's avatar
      bpf, ppc64: fix unexpected r0=0 exit path inside bpf_xadd · e3476a6d
      Daniel Borkmann authored
      [ Upstream commit b9c1e60e ]
      
      None of the JITs is allowed to implement exit paths from the BPF
      insn mappings other than BPF_JMP | BPF_EXIT. In the BPF core code
      we have a couple of rewrites in eBPF (e.g. LD_ABS / LD_IND) and
      in eBPF to cBPF translation to retain old existing behavior where
      exceptions may occur; they are also tightly controlled by the
      verifier where it disallows some of the features such as BPF to
      BPF calls when legacy LD_ABS / LD_IND ops are present in the BPF
      program. During recent review of all BPF_XADD JIT implementations
      I noticed that the ppc64 one is buggy in that it contains two
      jumps to exit paths. This is problematic as this can bypass verifier
      expectations e.g. pointed out in commit f6b1b3bf ("bpf: fix
      subprog verifier bypass by div/mod by 0 exception"). The first
      exit path is obsoleted by the fix in ca369602 ("bpf: allow xadd
      only on aligned memory") anyway, and for the second one we need to
      do a fetch, add and store loop if the reservation from lwarx/ldarx
      was lost in the meantime.
      
      Fixes: 156d0e29 ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF")
      Reviewed-by: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Reviewed-by: default avatarSandipan Das <sandipan@linux.vnet.ibm.com>
      Tested-by: default avatarSandipan Das <sandipan@linux.vnet.ibm.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e3476a6d
    • Taehee Yoo's avatar
      netfilter: nft_set_hash: add rcu_barrier() in the nft_rhash_destroy() · a685c4c4
      Taehee Yoo authored
      [ Upstream commit 9970a8e4 ]
      
      GC of set uses call_rcu() to destroy elements.
      So that elements would be destroyed after destroying sets and chains.
      But, elements should be destroyed before destroying sets and chains.
      In order to wait calling call_rcu(), a rcu_barrier() is added.
      
      In order to test correctly, below patch should be applied.
      https://patchwork.ozlabs.org/patch/940883/
      
      test scripts:
         %cat test.nft
         table ip aa {
      	   map map1 {
      		   type ipv4_addr : verdict; flags timeout;
      		   elements = {
      			   0 : jump a0,
      			   1 : jump a0,
      			   2 : jump a0,
      			   3 : jump a0,
      			   4 : jump a0,
      			   5 : jump a0,
      			   6 : jump a0,
      			   7 : jump a0,
      			   8 : jump a0,
      			   9 : jump a0,
      		   }
      		   timeout 1s;
      	   }
      	   chain a0 {
      	   }
         }
         flush ruleset
      
         [ ... ]
      
         table ip aa {
      	   map map1 {
      		   type ipv4_addr : verdict; flags timeout;
      		   elements = {
      			   0 : jump a0,
      			   1 : jump a0,
      			   2 : jump a0,
      			   3 : jump a0,
      			   4 : jump a0,
      			   5 : jump a0,
      			   6 : jump a0,
      			   7 : jump a0,
      			   8 : jump a0,
      			   9 : jump a0,
      		   }
      		   timeout 1s;
      	   }
      	   chain a0 {
      	   }
         }
         flush ruleset
      
      Splat looks like:
      [  200.795603] kernel BUG at net/netfilter/nf_tables_api.c:1363!
      [  200.806944] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI
      [  200.812253] CPU: 1 PID: 1582 Comm: nft Not tainted 4.17.0+ #24
      [  200.820297] Hardware name: To be filled by O.E.M. To be filled by O.E.M./Aptio CRB, BIOS 5.6.5 07/08/2015
      [  200.830309] RIP: 0010:nf_tables_chain_destroy.isra.34+0x62/0x240 [nf_tables]
      [  200.838317] Code: 43 50 85 c0 74 26 48 8b 45 00 48 8b 4d 08 ba 54 05 00 00 48 c7 c6 60 6d 29 c0 48 c7 c7 c0 65 29 c0
      4c 8b 40 08 e8 58 e5 fd f8 <0f> 0b 48 89 da 48 b8 00 00 00 00 00 fc ff
      [  200.860366] RSP: 0000:ffff880118dbf4d0 EFLAGS: 00010282
      [  200.866354] RAX: 0000000000000061 RBX: ffff88010cdeaf08 RCX: 0000000000000000
      [  200.874355] RDX: 0000000000000061 RSI: 0000000000000008 RDI: ffffed00231b7e90
      [  200.882361] RBP: ffff880118dbf4e8 R08: ffffed002373bcfb R09: ffffed002373bcfa
      [  200.890354] R10: 0000000000000000 R11: ffffed002373bcfb R12: dead000000000200
      [  200.898356] R13: dead000000000100 R14: ffffffffbb62af38 R15: dffffc0000000000
      [  200.906354] FS:  00007fefc31fd700(0000) GS:ffff88011b800000(0000) knlGS:0000000000000000
      [  200.915533] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  200.922355] CR2: 0000557f1c8e9128 CR3: 0000000106880000 CR4: 00000000001006e0
      [  200.930353] Call Trace:
      [  200.932351]  ? nf_tables_commit+0x26f6/0x2c60 [nf_tables]
      [  200.939525]  ? nf_tables_setelem_notify.constprop.49+0x1a0/0x1a0 [nf_tables]
      [  200.947525]  ? nf_tables_delchain+0x6e0/0x6e0 [nf_tables]
      [  200.952383]  ? nft_add_set_elem+0x1700/0x1700 [nf_tables]
      [  200.959532]  ? nla_parse+0xab/0x230
      [  200.963529]  ? nfnetlink_rcv_batch+0xd06/0x10d0 [nfnetlink]
      [  200.968384]  ? nfnetlink_net_init+0x130/0x130 [nfnetlink]
      [  200.975525]  ? debug_show_all_locks+0x290/0x290
      [  200.980363]  ? debug_show_all_locks+0x290/0x290
      [  200.986356]  ? sched_clock_cpu+0x132/0x170
      [  200.990352]  ? find_held_lock+0x39/0x1b0
      [  200.994355]  ? sched_clock_local+0x10d/0x130
      [  200.999531]  ? memset+0x1f/0x40
      
      Fixes: 9d098292 ("netfilter: nft_hash: add support for timeouts")
      Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a685c4c4
    • Eugeniu Rosca's avatar
      usb: gadget: f_uac2: fix endianness of 'struct cntrl_*_lay3' · 70e88fef
      Eugeniu Rosca authored
      [ Upstream commit eec24f2a ]
      
      The list [1] of commits doing endianness fixes in USB subsystem is long
      due to below quote from USB spec Revision 2.0 from April 27, 2000:
      
      ------------
      8.1 Byte/Bit Ordering
      
      Multiple byte fields in standard descriptors, requests, and responses
      are interpreted as and moved over the bus in little-endian order, i.e.
      LSB to MSB.
      ------------
      
      This commit belongs to the same family.
      
      [1] Example of endianness fixes in USB subsystem:
      commit 14e1d56c ("usb: gadget: f_uac2: endianness fixes.")
      commit 42370b82 ("usb: gadget: f_uac1: endianness fixes.")
      commit 63afd5cc ("USB: chaoskey: fix Alea quirk on big-endian hosts")
      commit 74098c4a ("usb: gadget: acm: fix endianness in notifications")
      commit cdd7928d ("ACM gadget: fix endianness in notifications")
      commit 323ece54 ("cdc-wdm: fix endianness bug in debug statements")
      commit e102609f ("usb: gadget: uvc: Fix endianness mismatches")
             list goes on
      
      Fixes: 132fcb46 ("usb: gadget: Add Audio Class 2.0 Driver")
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Reviewed-by: default avatarRuslan Bilovol <ruslan.bilovol@gmail.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      70e88fef
    • Peter Senna Tschudin's avatar
      tools: usb: ffs-test: Fix build on big endian systems · 7cd80fc1
      Peter Senna Tschudin authored
      [ Upstream commit a2b22ddd ]
      
      The tools/usb/ffs-test.c file defines cpu_to_le16/32 by using the C
      library htole16/32 function calls. However, cpu_to_le16/32 are used when
      initializing structures, i.e in a context where a function call is not
      allowed.
      
      It works fine on little endian systems because htole16/32 are defined by
      the C library as no-ops. But on big-endian systems, they are actually
      doing something, which might involve calling a function, causing build
      failures, such as:
      
         ffs-test.c:48:25: error: initializer element is not constant
          #define cpu_to_le32(x)  htole32(x)
                                  ^~~~~~~
         ffs-test.c:128:12: note: in expansion of macro ‘cpu_to_le32’
            .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
                     ^~~~~~~~~~~
      
      To solve this, we code cpu_to_le16/32 in a way that allows them to be
      used when initializing structures. This fix was imported from
      meta-openembedded/android-tools/fix-big-endian-build.patch written by
      Thomas Petazzoni <thomas.petazzoni@free-electrons.com>.
      
      CC: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
      Signed-off-by: default avatarPeter Senna Tschudin <peter.senna@gmail.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7cd80fc1
    • Randy Dunlap's avatar
      usb/phy: fix PPC64 build errors in phy-fsl-usb.c · 645fef5e
      Randy Dunlap authored
      [ Upstream commit a39ba90a ]
      
      Fix build errors when built for PPC64:
      These variables are only used on PPC32 so they don't need to be
      initialized for PPC64.
      
      ../drivers/usb/phy/phy-fsl-usb.c: In function 'usb_otg_start':
      ../drivers/usb/phy/phy-fsl-usb.c:865:3: error: '_fsl_readl' undeclared (first use in this function); did you mean 'fsl_readl'?
         _fsl_readl = _fsl_readl_be;
      ../drivers/usb/phy/phy-fsl-usb.c:865:16: error: '_fsl_readl_be' undeclared (first use in this function); did you mean 'fsl_readl'?
         _fsl_readl = _fsl_readl_be;
      ../drivers/usb/phy/phy-fsl-usb.c:866:3: error: '_fsl_writel' undeclared (first use in this function); did you mean 'fsl_writel'?
         _fsl_writel = _fsl_writel_be;
      ../drivers/usb/phy/phy-fsl-usb.c:866:17: error: '_fsl_writel_be' undeclared (first use in this function); did you mean 'fsl_writel'?
         _fsl_writel = _fsl_writel_be;
      ../drivers/usb/phy/phy-fsl-usb.c:868:16: error: '_fsl_readl_le' undeclared (first use in this function); did you mean 'fsl_readl'?
         _fsl_readl = _fsl_readl_le;
      ../drivers/usb/phy/phy-fsl-usb.c:869:17: error: '_fsl_writel_le' undeclared (first use in this function); did you mean 'fsl_writel'?
         _fsl_writel = _fsl_writel_le;
      
      and the sysfs "show" function return type should be ssize_t, not int:
      
      ../drivers/usb/phy/phy-fsl-usb.c:1042:49: error: initialization of 'ssize_t (*)(struct device *, struct device_attribute *, char *)' {aka 'long int (*)(struct device *, struct device_attribute *, char *)'} from incompatible pointer type 'int (*)(struct device *, struct device_attribute *, char *)' [-Werror=incompatible-pointer-types]
       static DEVICE_ATTR(fsl_usb2_otg_state, S_IRUGO, show_fsl_usb2_otg_state, NULL);
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: linux-usb@vger.kernel.org
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: linuxppc-dev@lists.ozlabs.org
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      645fef5e
    • Vladimir Zapolskiy's avatar
      usb: gadget: u_audio: protect stream runtime fields with stream spinlock · a362655d
      Vladimir Zapolskiy authored
      [ Upstream commit 56bc6158 ]
      
      The change protects almost the whole body of u_audio_iso_complete()
      function by PCM stream lock, this is mainly sufficient to avoid a race
      between USB request completion and stream termination, the change
      prevents a possibility of invalid memory access in interrupt context
      by memcpy():
      
          Unable to handle kernel paging request at virtual address 00004e80
          pgd = c0004000
          [00004e80] *pgd=00000000
          Internal error: Oops: 817 [#1] PREEMPT SMP ARM
          CPU: 0 PID: 3 Comm: ksoftirqd/0 Tainted: G         C   3.14.54+ #117
          task: da180b80 ti: da192000 task.ti: da192000
          PC is at memcpy+0x50/0x330
          LR is at 0xcdd92b0e
          pc : [<c029ef30>]    lr : [<cdd92b0e>]    psr: 20000193
          sp : da193ce4  ip : dd86ae26  fp : 0000b180
          r10: daf81680  r9 : 00000000  r8 : d58a01ea
          r7 : 2c0b43e4  r6 : acdfb08b  r5 : 01a271cf  r4 : 87389377
          r3 : 69469782  r2 : 00000020  r1 : daf82fe0  r0 : 00004e80
          Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
          Control: 10c5387d  Table: 2b70804a  DAC: 00000015
          Process ksoftirqd/0 (pid: 3, stack limit = 0xda192238)
      
      Also added a check for potential !runtime condition, commonly it is
      done by PCM_RUNTIME_CHECK(substream) in the beginning, however this
      does not completely prevent from oopses in u_audio_iso_complete(),
      because the proper protection scheme must be implemented in PCM
      library functions.
      
      An example of *not fixed* oops due to substream->runtime->*
      dereference by snd_pcm_running(substream) from
      snd_pcm_period_elapsed(), where substream->runtime is gone while
      waiting the substream lock:
      
          Unable to handle kernel paging request at virtual address 6b6b6b6b
          pgd = db7e4000
          [6b6b6b6b] *pgd=00000000
          CPU: 0 PID: 193 Comm: klogd Tainted: G         C   3.14.54+ #118
          task: db5ac500 ti: db60c000 task.ti: db60c000
          PC is at snd_pcm_period_elapsed+0x48/0xd8 [snd_pcm]
          LR is at snd_pcm_period_elapsed+0x40/0xd8 [snd_pcm]
          pc : [<>]    lr : [<>]    psr: 60000193
          Flags: nZCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment user
          Control: 10c5387d  Table: 2b7e404a  DAC: 00000015
          Process klogd (pid: 193, stack limit = 0xdb60c238)
          [<>] (snd_pcm_period_elapsed [snd_pcm]) from [<>] (udc_irq+0x500/0xbbc)
          [<>] (udc_irq) from [<>] (ci_irq+0x280/0x304)
          [<>] (ci_irq) from [<>] (handle_irq_event_percpu+0xa4/0x40c)
          [<>] (handle_irq_event_percpu) from [<>] (handle_irq_event+0x3c/0x5c)
          [<>] (handle_irq_event) from [<>] (handle_fasteoi_irq+0xc4/0x110)
          [<>] (handle_fasteoi_irq) from [<>] (generic_handle_irq+0x20/0x30)
          [<>] (generic_handle_irq) from [<>] (handle_IRQ+0x80/0xc0)
          [<>] (handle_IRQ) from [<>] (gic_handle_irq+0x3c/0x60)
          [<>] (gic_handle_irq) from [<>] (__irq_svc+0x44/0x78)
      Signed-off-by: default avatarVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
      [erosca: W/o this patch, with minimal instrumentation [1], I can
               consistently reproduce BUG: KASAN: use-after-free [2]]
      
      [1] Instrumentation to reproduce issue [2]:
      #  diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
      #  index a72295c953bb..bd0b308024fe 100644
      #  --- a/drivers/usb/gadget/function/u_audio.c
      #  +++ b/drivers/usb/gadget/function/u_audio.c
      #  @@ -16,6 +16,7 @@
      #   #include <sound/core.h>
      #   #include <sound/pcm.h>
      #   #include <sound/pcm_params.h>
      #  +#include <linux/delay.h>
      # 
      #   #include "u_audio.h"
      # 
      #  @@ -147,6 +148,8 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req)
      # 
      # 	spin_unlock_irqrestore(&prm->lock, flags);
      # 
      #  +	udelay(500); //delay here to increase probability of parallel activities
      #  +
      # 	/* Pack USB load in ALSA ring buffer */
      # 	pending = prm->dma_bytes - hw_ptr;
      
      [2] After applying [1], below BUG occurs on Rcar-H3-Salvator-X board:
      ==================================================================
      BUG: KASAN: use-after-free in u_audio_iso_complete+0x24c/0x520 [u_audio]
      Read of size 8 at addr ffff8006cafcc248 by task swapper/0/0
      
      CPU: 0 PID: 0 Comm: swapper/0 Tainted: G        WC      4.14.47+ #160
      Hardware name: Renesas Salvator-X board based on r8a7795 ES2.0+ (DT)
      Call trace:
      [<ffff2000080925ac>] dump_backtrace+0x0/0x364
      [<ffff200008092924>] show_stack+0x14/0x1c
      [<ffff200008f8dbcc>] dump_stack+0x108/0x174
      [<ffff2000083c71b8>] print_address_description+0x7c/0x32c
      [<ffff2000083c78e8>] kasan_report+0x324/0x354
      [<ffff2000083c6114>] __asan_load8+0x24/0x94
      [<ffff2000021d1b34>] u_audio_iso_complete+0x24c/0x520 [u_audio]
      [<ffff20000152fe50>] usb_gadget_giveback_request+0x480/0x4d0 [udc_core]
      [<ffff200001860ab8>] usbhsg_queue_done+0x100/0x130 [renesas_usbhs]
      [<ffff20000185f814>] usbhsf_pkt_handler+0x1a4/0x298 [renesas_usbhs]
      [<ffff20000185fb38>] usbhsf_irq_ready+0x128/0x178 [renesas_usbhs]
      [<ffff200001859cc8>] usbhs_interrupt+0x440/0x490 [renesas_usbhs]
      [<ffff2000081a0288>] __handle_irq_event_percpu+0x594/0xa58
      [<ffff2000081a07d0>] handle_irq_event_percpu+0x84/0x12c
      [<ffff2000081a0928>] handle_irq_event+0xb0/0x10c
      [<ffff2000081a8384>] handle_fasteoi_irq+0x1e0/0x2ec
      [<ffff20000819e5f8>] generic_handle_irq+0x2c/0x44
      [<ffff20000819f0d0>] __handle_domain_irq+0x190/0x194
      [<ffff20000808177c>] gic_handle_irq+0x80/0xac
      Exception stack(0xffff200009e97c80 to 0xffff200009e97dc0)
      7c80: 0000000000000000 0000000000000000 0000000000000003 ffff200008179298
      7ca0: ffff20000ae1c180 dfff200000000000 0000000000000000 ffff2000081f9a88
      7cc0: ffff200009eb5960 ffff200009e97cf0 0000000000001600 ffff0400041b064b
      7ce0: 0000000000000000 0000000000000002 0000000200000001 0000000000000001
      7d00: ffff20000842197c 0000ffff958c4970 0000000000000000 ffff8006da0d5b80
      7d20: ffff8006d4678498 0000000000000000 000000126bde0a8b ffff8006d4678480
      7d40: 0000000000000000 000000126bdbea64 ffff200008fd0000 ffff8006fffff980
      7d60: 00000000495f0018 ffff200009e97dc0 ffff200008b6c4ec ffff200009e97dc0
      7d80: ffff200008b6c4f0 0000000020000145 ffff8006da0d5b80 ffff8006d4678498
      7da0: ffffffffffffffff ffff8006d4678498 ffff200009e97dc0 ffff200008b6c4f0
      [<ffff200008084034>] el1_irq+0xb4/0x12c
      [<ffff200008b6c4f0>] cpuidle_enter_state+0x818/0x844
      [<ffff200008b6c59c>] cpuidle_enter+0x18/0x20
      [<ffff20000815f2e4>] call_cpuidle+0x98/0x9c
      [<ffff20000815f674>] do_idle+0x214/0x264
      [<ffff20000815facc>] cpu_startup_entry+0x20/0x24
      [<ffff200008fb09d8>] rest_init+0x30c/0x320
      [<ffff2000095f1338>] start_kernel+0x570/0x5b0
      ---<-snip->---
      
      Fixes: 132fcb46 ("usb: gadget: Add Audio Class 2.0 Driver")
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a362655d
    • Vladimir Zapolskiy's avatar
      usb: gadget: u_audio: remove cached period bytes value · c7d18686
      Vladimir Zapolskiy authored
      [ Upstream commit 773e53d5 ]
      
      Substream period size potentially can be changed in runtime, however
      this is not accounted in the data copying routine, the change replaces
      the cached value with an actual value from substream runtime.
      
      As a side effect the change also removes a potential division by zero
      in u_audio_iso_complete() function, if there is a race with
      uac_pcm_hw_free(), which sets prm->period_size to 0.
      
      Fixes: 132fcb46 ("usb: gadget: Add Audio Class 2.0 Driver")
      Signed-off-by: default avatarVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c7d18686
    • Vladimir Zapolskiy's avatar
      usb: gadget: u_audio: remove caching of stream buffer parameters · 42b09bec
      Vladimir Zapolskiy authored
      [ Upstream commit 96afb54e ]
      
      There is no necessity to copy PCM stream ring buffer area and size
      properties to UAC private data structure, these values can be got
      from substream itself.
      
      The change gives more control on substream and avoid stale caching.
      
      Fixes: 132fcb46 ("usb: gadget: Add Audio Class 2.0 Driver")
      Signed-off-by: default avatarVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      42b09bec
    • Joshua Frkuska's avatar
      usb: gadget: u_audio: update hw_ptr in iso_complete after data copied · 224c0d08
      Joshua Frkuska authored
      [ Upstream commit 6b37bd78 ]
      
      In u_audio_iso_complete, the runtime hw_ptr is updated before the
      data is actually copied over to/from the buffer/dma area. When
      ALSA uses this hw_ptr, the data may not actually be available to
      be used. This causes trash/stale audio to play/record. This
      patch updates the hw_ptr after the data has been copied to avoid
      this.
      
      Fixes: 132fcb46 ("usb: gadget: Add Audio Class 2.0 Driver")
      Signed-off-by: default avatarJoshua Frkuska <joshua_frkuska@mentor.com>
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      224c0d08
    • Eugeniu Rosca's avatar
      usb: gadget: u_audio: fix pcm/card naming in g_audio_setup() · dc126a1e
      Eugeniu Rosca authored
      [ Upstream commit dfa042fa ]
      
      Fix below smatch (v0.5.0-4443-g69e9094e11c1) warnings:
      drivers/usb/gadget/function/u_audio.c:607 g_audio_setup() warn: strcpy() 'pcm_name' of unknown size might be too large for 'pcm->name'
      drivers/usb/gadget/function/u_audio.c:614 g_audio_setup() warn: strcpy() 'card_name' of unknown size might be too large for 'card->driver'
      drivers/usb/gadget/function/u_audio.c:615 g_audio_setup() warn: strcpy() 'card_name' of unknown size might be too large for 'card->shortname'
      
      Below commits performed a similar 's/strcpy/strlcpy/' rework:
      * v2.6.31 commit 8372d498 ("ALSA: ctxfi - Fix PCM device naming")
      * v4.14 commit 003d3e70 ("ALSA: ad1848: fix format string overflow warning")
      * v4.14 commit 6d8b04de ("ALSA: cs423x: fix format string overflow warning")
      
      Fixes: eb9fecb9 ("usb: gadget: f_uac2: split out audio core")
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dc126a1e
    • Eugeniu Rosca's avatar
      usb: gadget: f_uac2: fix error handling in afunc_bind (again) · fa18ff7e
      Eugeniu Rosca authored
      [ Upstream commit e87581fe ]
      
      If usb_ep_autoconfig() fails (i.e. returns a null endpoint descriptor),
      we expect afunc_bind() to fail (i.e. return a negative error code).
      
      However, due to v4.10-rc1 commit f1d3861d ("usb: gadget: f_uac2: fix
      error handling at afunc_bind"), afunc_bind() returns zero, telling the
      caller that it succeeded. This then generates NULL pointer dereference
      in below scenario on Rcar H3-ES20-Salvator-X target:
      
      rcar-gen3:/home/root# modprobe g_audio
      [  626.521155] g_audio gadget: afunc_bind:565 Error!
      [  626.526319] g_audio gadget: Linux USB Audio Gadget, version: Feb 2, 2012
      [  626.533405] g_audio gadget: g_audio ready
      rcar-gen3:/home/root#
      rcar-gen3:/home/root# modprobe -r g_audio
      [  728.256707] ==================================================================
      [  728.264293] BUG: KASAN: null-ptr-deref in u_audio_stop_capture+0x70/0x268 [u_audio]
      [  728.272244] Read of size 8 at addr 00000000000000a0 by task modprobe/2545
      [  728.279309]
      [  728.280849] CPU: 0 PID: 2545 Comm: modprobe Tainted: G        WC      4.14.47+ #152
      [  728.288778] Hardware name: Renesas Salvator-X board based on r8a7795 ES2.0+ (DT)
      [  728.296454] Call trace:
      [  728.299151] [<ffff2000080925ac>] dump_backtrace+0x0/0x364
      [  728.304808] [<ffff200008092924>] show_stack+0x14/0x1c
      [  728.310081] [<ffff200008f8d5cc>] dump_stack+0x108/0x174
      [  728.315522] [<ffff2000083c77c8>] kasan_report+0x1fc/0x354
      [  728.321134] [<ffff2000083c611c>] __asan_load8+0x24/0x94
      [  728.326600] [<ffff2000021e1618>] u_audio_stop_capture+0x70/0x268 [u_audio]
      [  728.333735] [<ffff2000021f8b7c>] afunc_disable+0x44/0x60 [usb_f_uac2]
      [  728.340503] [<ffff20000218177c>] usb_remove_function+0x9c/0x210 [libcomposite]
      [  728.348060] [<ffff200002183320>] remove_config.isra.2+0x1d8/0x218 [libcomposite]
      [  728.355788] [<ffff200002186c54>] __composite_unbind+0x104/0x1f8 [libcomposite]
      [  728.363339] [<ffff200002186d58>] composite_unbind+0x10/0x18 [libcomposite]
      [  728.370536] [<ffff20000152f158>] usb_gadget_remove_driver+0xc0/0x170 [udc_core]
      [  728.378172] [<ffff20000153154c>] usb_gadget_unregister_driver+0x1cc/0x258 [udc_core]
      [  728.386274] [<ffff200002180de8>] usb_composite_unregister+0x10/0x18 [libcomposite]
      [  728.394116] [<ffff2000021d035c>] audio_driver_exit+0x14/0x28 [g_audio]
      [  728.400878] [<ffff200008213ed4>] SyS_delete_module+0x288/0x32c
      [  728.406935] Exception stack(0xffff8006cf6c7ec0 to 0xffff8006cf6c8000)
      [  728.413624] 7ec0: 0000000006136428 0000000000000800 0000000000000000 0000ffffd706efe8
      [  728.421718] 7ee0: 0000ffffd706efe9 000000000000000a 1999999999999999 0000000000000000
      [  728.429792] 7f00: 000000000000006a 000000000042c078 0000000000000000 0000000000000005
      [  728.437870] 7f20: 0000000000000000 0000000000000000 0000000000000004 0000000000000000
      [  728.445952] 7f40: 000000000042bfc8 0000ffffbc7c8f40 0000000000000000 00000000061363c0
      [  728.454035] 7f60: 0000000006136428 0000000000000000 0000000000000000 0000000006136428
      [  728.462114] 7f80: 000000000042c000 0000ffffd7071448 000000000042c000 0000000000000000
      [  728.470190] 7fa0: 00000000061350c0 0000ffffd7070010 000000000041129c 0000ffffd7070010
      [  728.478281] 7fc0: 0000ffffbc7c8f48 0000000060000000 0000000006136428 000000000000006a
      [  728.486351] 7fe0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
      [  728.494434] [<ffff200008084780>] el0_svc_naked+0x34/0x38
      [  728.499957] ==================================================================
      [  728.507801] Unable to handle kernel NULL pointer dereference at virtual address 000000a0
      [  728.517742] Mem abort info:
      [  728.520993]   Exception class = DABT (current EL), IL = 32 bits
      [  728.527375]   SET = 0, FnV = 0
      [  728.530731]   EA = 0, S1PTW = 0
      [  728.534361] Data abort info:
      [  728.537650]   ISV = 0, ISS = 0x00000006
      [  728.541863]   CM = 0, WnR = 0
      [  728.545167] user pgtable: 4k pages, 48-bit VAs, pgd = ffff8006c6100000
      [  728.552156] [00000000000000a0] *pgd=0000000716a8d003
      [  728.557519] , *pud=00000007116fc003
      [  728.561259] , *pmd=0000000000000000
      [  728.564985] Internal error: Oops: 96000006 [#1] PREEMPT SMP
      [  728.570815] Modules linked in:
      [  728.574023]  usb_f_uac2
      [  728.576560]  u_audio
      [  728.578827]  g_audio(-)
      [  728.581361]  libcomposite
      [  728.584071]  configfs
      [  728.586428]  aes_ce_blk
      [  728.588960]  sata_rcar
      [  728.591421]  crypto_simd
      [  728.594039]  cryptd
      [  728.596217]  libata
      [  728.598396]  aes_ce_cipher
      [  728.601188]  crc32_ce
      [  728.603542]  ghash_ce
      [  728.605896]  gf128mul
      [  728.608250]  aes_arm64
      [  728.610692]  scsi_mod
      [  728.613046]  sha2_ce
      [  728.615313]  xhci_plat_hcd
      [  728.618106]  sha256_arm64
      [  728.620811]  sha1_ce
      [  728.623077]  renesas_usbhs
      [  728.625869]  xhci_hcd
      [  728.628243]  renesas_usb3
      [  728.630948]  sha1_generic
      [  728.633670]  ravb_streaming(C)
      [  728.636814]  udc_core
      [  728.639168]  cpufreq_dt
      [  728.641697]  rcar_gen3_thermal
      [  728.644840]  usb_dmac
      [  728.647194]  pwm_rcar
      [  728.649548]  thermal_sys
      [  728.652165]  virt_dma
      [  728.654519]  mch_core(C)
      [  728.657137]  pwm_bl
      [  728.659315]  snd_soc_rcar
      [  728.662020]  snd_aloop
      [  728.664462]  snd_soc_generic_card
      [  728.667869]  snd_soc_ak4613
      [  728.670749]  ipv6
      [  728.672768]  autofs4
      [  728.675052] CPU: 0 PID: 2545 Comm: modprobe Tainted: G    B   WC      4.14.47+ #152
      [  728.682973] Hardware name: Renesas Salvator-X board based on r8a7795 ES2.0+ (DT)
      [  728.690637] task: ffff8006ced38000 task.stack: ffff8006cf6c0000
      [  728.696814] PC is at u_audio_stop_capture+0x70/0x268 [u_audio]
      [  728.702896] LR is at u_audio_stop_capture+0x70/0x268 [u_audio]
      [  728.708964] pc : [<ffff2000021e1618>] lr : [<ffff2000021e1618>] pstate: 60000145
      [  728.716620] sp : ffff8006cf6c7a50
      [  728.720154] x29: ffff8006cf6c7a50
      [  728.723760] x28: ffff8006ced38000
      [  728.727272] x27: ffff200008fd7000
      [  728.730857] x26: ffff2000021d2340
      [  728.734361] x25: 0000000000000000
      [  728.737948] x24: ffff200009e94b08
      [  728.741452] x23: 00000000000000a0
      [  728.745052] x22: 00000000000000a8
      [  728.748558] x21: 1ffff000d9ed8f7c
      [  728.752142] x20: ffff8006d671a800
      [  728.755646] x19: 0000000000000000
      [  728.759231] x18: 0000000000000000
      [  728.762736] x17: 0000ffffbc7c8f40
      [  728.766320] x16: ffff200008213c4c
      [  728.769823] x15: 0000000000000000
      [  728.773408] x14: 0720072007200720
      [  728.776912] x13: 0720072007200720
      [  728.780497] x12: ffffffffffffffff
      [  728.784001] x11: 0000000000000040
      [  728.787598] x10: 0000000000001600
      [  728.791103] x9 : ffff8006cf6c77a0
      [  728.794689] x8 : ffff8006ced39660
      [  728.798193] x7 : ffff20000811c738
      [  728.801794] x6 : 0000000000000000
      [  728.805299] x5 : dfff200000000000
      [  728.808885] x4 : ffff8006ced38000
      [  728.812390] x3 : ffff200008fb46e8
      [  728.815976] x2 : 0000000000000007
      [  728.819480] x1 : 3ba68643e7431500
      [  728.823066] x0 : 0000000000000000
      [  728.826574] Process modprobe (pid: 2545, stack limit = 0xffff8006cf6c0000)
      [  728.833704] Call trace:
      [  728.836292] Exception stack(0xffff8006cf6c7910 to 0xffff8006cf6c7a50)
      [  728.842987] 7900:                                   0000000000000000 3ba68643e7431500
      [  728.851084] 7920: 0000000000000007 ffff200008fb46e8 ffff8006ced38000 dfff200000000000
      [  728.859173] 7940: 0000000000000000 ffff20000811c738 ffff8006ced39660 ffff8006cf6c77a0
      [  728.867248] 7960: 0000000000001600 0000000000000040 ffffffffffffffff 0720072007200720
      [  728.875323] 7980: 0720072007200720 0000000000000000 ffff200008213c4c 0000ffffbc7c8f40
      [  728.883412] 79a0: 0000000000000000 0000000000000000 ffff8006d671a800 1ffff000d9ed8f7c
      [  728.891485] 79c0: 00000000000000a8 00000000000000a0 ffff200009e94b08 0000000000000000
      [  728.899561] 79e0: ffff2000021d2340 ffff200008fd7000 ffff8006ced38000 ffff8006cf6c7a50
      [  728.907636] 7a00: ffff2000021e1618 ffff8006cf6c7a50 ffff2000021e1618 0000000060000145
      [  728.915710] 7a20: 0000000000000008 0000000000000000 0000ffffffffffff 3ba68643e7431500
      [  728.923780] 7a40: ffff8006cf6c7a50 ffff2000021e1618
      [  728.928880] [<ffff2000021e1618>] u_audio_stop_capture+0x70/0x268 [u_audio]
      [  728.936032] [<ffff2000021f8b7c>] afunc_disable+0x44/0x60 [usb_f_uac2]
      [  728.942822] [<ffff20000218177c>] usb_remove_function+0x9c/0x210 [libcomposite]
      [  728.950385] [<ffff200002183320>] remove_config.isra.2+0x1d8/0x218 [libcomposite]
      [  728.958134] [<ffff200002186c54>] __composite_unbind+0x104/0x1f8 [libcomposite]
      [  728.965689] [<ffff200002186d58>] composite_unbind+0x10/0x18 [libcomposite]
      [  728.972882] [<ffff20000152f158>] usb_gadget_remove_driver+0xc0/0x170 [udc_core]
      [  728.980522] [<ffff20000153154c>] usb_gadget_unregister_driver+0x1cc/0x258 [udc_core]
      [  728.988638] [<ffff200002180de8>] usb_composite_unregister+0x10/0x18 [libcomposite]
      [  728.996472] [<ffff2000021d035c>] audio_driver_exit+0x14/0x28 [g_audio]
      [  729.003231] [<ffff200008213ed4>] SyS_delete_module+0x288/0x32c
      [  729.009278] Exception stack(0xffff8006cf6c7ec0 to 0xffff8006cf6c8000)
      [  729.015946] 7ec0: 0000000006136428 0000000000000800 0000000000000000 0000ffffd706efe8
      [  729.024022] 7ee0: 0000ffffd706efe9 000000000000000a 1999999999999999 0000000000000000
      [  729.032099] 7f00: 000000000000006a 000000000042c078 0000000000000000 0000000000000005
      [  729.040172] 7f20: 0000000000000000 0000000000000000 0000000000000004 0000000000000000
      [  729.048263] 7f40: 000000000042bfc8 0000ffffbc7c8f40 0000000000000000 00000000061363c0
      [  729.056337] 7f60: 0000000006136428 0000000000000000 0000000000000000 0000000006136428
      [  729.064411] 7f80: 000000000042c000 0000ffffd7071448 000000000042c000 0000000000000000
      [  729.072484] 7fa0: 00000000061350c0 0000ffffd7070010 000000000041129c 0000ffffd7070010
      [  729.080563] 7fc0: 0000ffffbc7c8f48 0000000060000000 0000000006136428 000000000000006a
      [  729.088636] 7fe0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
      [  729.096733] [<ffff200008084780>] el0_svc_naked+0x34/0x38
      [  729.102259] Code: 9597d1b3 aa1703e0 9102a276 958792b9 (f9405275)
      [  729.108617] ---[ end trace 7560c5fa3d100243 ]---
      
      After this patch is applied, the issue is fixed:
      rcar-gen3:/home/root# modprobe g_audio
      [   59.217127] g_audio gadget: afunc_bind:565 Error!
      [   59.222329] g_audio ee020000.usb: failed to start g_audio: -19
      modprobe: ERROR: could not insert 'g_audio': No such device
      rcar-gen3:/home/root# modprobe -r g_audio
      rcar-gen3:/home/root#
      
      Fixes: f1d3861d ("usb: gadget: f_uac2: fix error handling at afunc_bind")
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa18ff7e
    • Jia-Ju Bai's avatar
      usb: gadget: r8a66597: Fix a possible sleep-in-atomic-context bugs in r8a66597_queue() · 43b058dc
      Jia-Ju Bai authored
      [ Upstream commit f36b507c ]
      
      The driver may sleep in an interrupt handler.
      The function call path (from bottom to top) in Linux-4.16.7 is:
      
      [FUNC] r8a66597_queue(GFP_KERNEL)
      drivers/usb/gadget/udc/r8a66597-udc.c, 1193:
      		r8a66597_queue in get_status
      drivers/usb/gadget/udc/r8a66597-udc.c, 1301:
      		get_status in setup_packet
      drivers/usb/gadget/udc/r8a66597-udc.c, 1381:
      		setup_packet in irq_control_stage
      drivers/usb/gadget/udc/r8a66597-udc.c, 1508:
      		irq_control_stage in r8a66597_irq (interrupt handler)
      
      To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC.
      
      This bug is found by my static analysis tool (DSAC-2) and checked by
      my code review.
      Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      43b058dc
    • Jia-Ju Bai's avatar
      usb: gadget: r8a66597: Fix two possible sleep-in-atomic-context bugs in init_controller() · 3f41c2d0
      Jia-Ju Bai authored
      [ Upstream commit 0602088b ]
      
      The driver may sleep with holding a spinlock.
      The function call paths (from bottom to top) in Linux-4.16.7 are:
      
      [FUNC] msleep
      drivers/usb/gadget/udc/r8a66597-udc.c, 839:
      		msleep in init_controller
      drivers/usb/gadget/udc/r8a66597-udc.c, 96:
      		init_controller in r8a66597_usb_disconnect
      drivers/usb/gadget/udc/r8a66597-udc.c, 93:
      		spin_lock in r8a66597_usb_disconnect
      
      [FUNC] msleep
      drivers/usb/gadget/udc/r8a66597-udc.c, 835:
      		msleep in init_controller
      drivers/usb/gadget/udc/r8a66597-udc.c, 96:
      		init_controller in r8a66597_usb_disconnect
      drivers/usb/gadget/udc/r8a66597-udc.c, 93:
      		spin_lock in r8a66597_usb_disconnect
      
      To fix these bugs, msleep() is replaced with mdelay().
      
      This bug is found by my static analysis tool (DSAC-2) and checked by
      my code review.
      Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3f41c2d0
    • Josef Bacik's avatar
      nbd: handle unexpected replies better · 05ee6166
      Josef Bacik authored
      [ Upstream commit 8f3ea359 ]
      
      If the server or network is misbehaving and we get an unexpected reply
      we can sometimes miss the request not being started and wait on a
      request and never get a response, or even double complete the same
      request.  Fix this by replacing the send_complete completion with just a
      per command lock.  Add a per command cookie as well so that we can know
      if we're getting a double completion for a previous event.  Also check
      to make sure we dont have REQUEUED set as that means we raced with the
      timeout handler and need to just let the retry occur.
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      05ee6166
    • Josef Bacik's avatar
      nbd: don't requeue the same request twice. · ced413c5
      Josef Bacik authored
      [ Upstream commit d7d94d48 ]
      
      We can race with the snd timeout and the per-request timeout and end up
      requeuing the same request twice.  We can't use the send_complete
      completion to tell if everything is ok because we hold the tx_lock
      during send, so the timeout stuff will block waiting to mark the socket
      dead, and we could be marked complete and still requeue.  Instead add a
      flag to the socket so we know whether we've been requeued yet.
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ced413c5
    • Lucas Stach's avatar
      drm/imx: imx-ldb: check if channel is enabled before printing warning · 962ff36d
      Lucas Stach authored
      [ Upstream commit c80d673b ]
      
      If the second LVDS channel has been disabled in the DT when using dual-channel
      mode we should not print a warning.
      Signed-off-by: default avatarLucas Stach <l.stach@pengutronix.de>
      Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      962ff36d
    • Lucas Stach's avatar
      drm/imx: imx-ldb: disable LDB on driver bind · a43eac2d
      Lucas Stach authored
      [ Upstream commit b5826239 ]
      
      The LVDS signal integrity is only guaranteed when the correct enable
      sequence (first IPU DI, then LDB) is used. If the LDB display output was
      active before the imx-drm driver is loaded (like when a bootsplash was
      active) the DI will be disabled by the full IPU reset we do when loading
      the driver. The LDB control registers are not part of the IPU range and
      thus will remain unchanged.
      
      This leads to the LDB still being active when the DI is getting enabled,
      effectively reversing the required enable sequence. Fix this by also
      disabling the LDB on driver bind.
      Signed-off-by: default avatarLucas Stach <l.stach@pengutronix.de>
      Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a43eac2d
    • Varun Prakash's avatar
      scsi: libiscsi: fix possible NULL pointer dereference in case of TMF · 9ac1a464
      Varun Prakash authored
      [ Upstream commit a17037e7 ]
      
      In iscsi_check_tmf_restrictions() task->hdr is dereferenced to print the
      opcode, it is possible that task->hdr is NULL.
      
      There are two cases based on opcode argument:
      
      1. ISCSI_OP_SCSI_CMD - In this case alloc_pdu() is called
      after iscsi_check_tmf_restrictions()
      
      iscsi_prep_scsi_cmd_pdu() -> iscsi_check_tmf_restrictions() -> alloc_pdu().
      
      Transport drivers allocate memory for iSCSI hdr in alloc_pdu() and assign
      it to task->hdr. In case of TMF task->hdr will be NULL resulting in NULL
      pointer dereference.
      
      2. ISCSI_OP_SCSI_DATA_OUT - In this case transport driver can free the
      memory for iSCSI hdr after transmitting the pdu so task->hdr can be NULL or
      invalid.
      
      This patch fixes this issue by removing task->hdr->opcode from the printk
      statement.
      Signed-off-by: default avatarVarun Prakash <varun@chelsio.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9ac1a464
    • Varun Prakash's avatar
      scsi: target: iscsi: cxgbit: fix max iso npdu calculation · ca5fc53a
      Varun Prakash authored
      [ Upstream commit 1b350ea0 ]
      
      - rounddown CXGBIT_MAX_ISO_PAYLOAD by csk->emss before calculating
        max_iso_npdu to get max TCP payload in multiple of mss.
      
      - call cxgbit_set_digest() before cxgbit_set_iso_npdu() to set
        csk->submode, it is used in calculating number of iso pdus.
      Signed-off-by: default avatarVarun Prakash <varun@chelsio.com>
      Reviewed-by: default avatarMike Christie <mchristi@redhat.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ca5fc53a
    • Sean Paul's avatar
      drm/bridge: adv7511: Reset registers on hotplug · 384f0d9f
      Sean Paul authored
      [ Upstream commit 5f341756 ]
      
      The bridge loses its hw state when the cable is unplugged. If we detect
      this case in the hpd handler, reset its state.
      Reported-by: default avatarRob Clark <robdclark@gmail.com>
      Tested-by: default avatarRob Clark <robdclark@gmail.com>
      Reviewed-by: default avatarArchit Taneja <architt@codeaurora.org>
      Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
      Link: https://patchwork.freedesktop.org/patch/msgid/20180703165648.120401-1-seanpaul@chromium.orgSigned-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      384f0d9f
    • Bernd Edlinger's avatar
      nl80211: Add a missing break in parse_station_flags · 7cb625dd
      Bernd Edlinger authored
      [ Upstream commit 5cf3006c ]
      
      I was looking at usually suppressed gcc warnings,
      [-Wimplicit-fallthrough=] in this case:
      
      The code definitely looks like a break is missing here.
      However I am not able to test the NL80211_IFTYPE_MESH_POINT,
      nor do I actually know what might be :)
      So please use this patch with caution and only if you are
      able to do some testing.
      Signed-off-by: default avatarBernd Edlinger <bernd.edlinger@hotmail.de>
      [johannes: looks obvious enough to apply as is, interesting
       though that it never seems to have been a problem]
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7cb625dd
    • Theodore Ts'o's avatar
      ext4: clear mmp sequence number when remounting read-only · 147b89c4
      Theodore Ts'o authored
      [ Upstream commit 2dca60d9 ]
      
      Previously, when an MMP-protected file system is remounted read-only,
      the kmmpd thread would exit the next time it woke up (a few seconds
      later), without resetting the MMP sequence number back to
      EXT4_MMP_SEQ_CLEAN.
      
      Fix this by explicitly killing the MMP thread when the file system is
      remounted read-only.
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: Andreas Dilger <adilger@dilger.ca>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      147b89c4
    • mpubbise@codeaurora.org's avatar
      mac80211: add stations tied to AP_VLANs during hw reconfig · de044d4e
      mpubbise@codeaurora.org authored
      [ Upstream commit 19103a4b ]
      
      As part of hw reconfig, only stations linked to AP interfaces are added
      back to the driver ignoring those which are tied to AP_VLAN interfaces.
      
      It is true that there could be stations tied to the AP_VLAN interface while
      serving 4addr clients or when using AP_VLAN for VLAN operations; we should
      be adding these stations back to the driver as part of hw reconfig, failing
      to do so can cause functional issues.
      
      In the case of ath10k driver, the following errors were observed.
      
      ath10k_pci : failed to install key for non-existent peer XX:XX:XX:XX:XX:XX
      Workqueue: events_freezable ieee80211_restart_work [mac80211]
      (unwind_backtrace) from (show_stack+0x10/0x14)
      (show_stack) (dump_stack+0x80/0xa0)
      (dump_stack) (warn_slowpath_common+0x68/0x8c)
      (warn_slowpath_common) (warn_slowpath_null+0x18/0x20)
      (warn_slowpath_null) (ieee80211_enable_keys+0x88/0x154 [mac80211])
      (ieee80211_enable_keys) (ieee80211_reconfig+0xc90/0x19c8 [mac80211])
      (ieee80211_reconfig]) (ieee80211_restart_work+0x8c/0xa0 [mac80211])
      (ieee80211_restart_work) (process_one_work+0x284/0x488)
      (process_one_work) (worker_thread+0x228/0x360)
      (worker_thread) (kthread+0xd8/0xec)
      (kthread) (ret_from_fork+0x14/0x24)
      
      Also while bringing down the AP VAP, WARN_ONs and errors related to peer
      removal were observed.
      
      ath10k_pci : failed to clear all peer wep keys for vdev 0: -2
      ath10k_pci : failed to disassociate station: 8c:fd:f0:0a:8c:f5 vdev 0: -2
      (unwind_backtrace) (show_stack+0x10/0x14)
      (show_stack) (dump_stack+0x80/0xa0)
      (dump_stack) (warn_slowpath_common+0x68/0x8c)
      (warn_slowpath_common) (warn_slowpath_null+0x18/0x20)
      (warn_slowpath_null) (sta_set_sinfo+0xb98/0xc9c [mac80211])
      (sta_set_sinfo [mac80211]) (__sta_info_flush+0xf0/0x134 [mac80211])
      (__sta_info_flush [mac80211]) (ieee80211_stop_ap+0xe8/0x390 [mac80211])
      (ieee80211_stop_ap [mac80211]) (__cfg80211_stop_ap+0xe0/0x3dc [cfg80211])
      (__cfg80211_stop_ap [cfg80211]) (cfg80211_stop_ap+0x30/0x44 [cfg80211])
      (cfg80211_stop_ap [cfg80211]) (genl_rcv_msg+0x274/0x30c)
      (genl_rcv_msg) (netlink_rcv_skb+0x58/0xac)
      (netlink_rcv_skb) (genl_rcv+0x20/0x34)
      (genl_rcv) (netlink_unicast+0x11c/0x204)
      (netlink_unicast) (netlink_sendmsg+0x30c/0x370)
      (netlink_sendmsg) (sock_sendmsg+0x70/0x84)
      (sock_sendmsg) (___sys_sendmsg.part.3+0x188/0x228)
      (___sys_sendmsg.part.3) (__sys_sendmsg+0x4c/0x70)
      (__sys_sendmsg) (ret_fast_syscall+0x0/0x44)
      
      These issues got fixed by adding the stations which are
      tied to AP_VLANs back to the driver.
      Signed-off-by: default avatarManikanta Pubbisetty <mpubbise@codeaurora.org>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      de044d4e
    • Zhen Lei's avatar
      esp6: fix memleak on error path in esp6_input · b6f147a2
      Zhen Lei authored
      [ Upstream commit 7284fdf3 ]
      
      This ought to be an omission in e6194923 ("esp: Fix memleaks on error
      paths."). The memleak on error path in esp6_input is similar to esp_input
      of esp4.
      
      Fixes: e6194923 ("esp: Fix memleaks on error paths.")
      Fixes: 3f297707 ("ipsec: check return value of skb_to_sgvec always")
      Signed-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b6f147a2
    • Florian Westphal's avatar
      xfrm: free skb if nlsk pointer is NULL · 0118f86d
      Florian Westphal authored
      [ Upstream commit 86126b77 ]
      
      nlmsg_multicast() always frees the skb, so in case we cannot call
      it we must do that ourselves.
      
      Fixes: 21ee543e ("xfrm: fix race between netns cleanup and state expire notification")
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0118f86d
    • Tommi Rantala's avatar
      xfrm: fix missing dst_release() after policy blocking lbcast and multicast · d35cc7ed
      Tommi Rantala authored
      [ Upstream commit 8cc88773 ]
      
      Fix missing dst_release() when local broadcast or multicast traffic is
      xfrm policy blocked.
      
      For IPv4 this results to dst leak: ip_route_output_flow() allocates
      dst_entry via __ip_route_output_key() and passes it to
      xfrm_lookup_route(). xfrm_lookup returns ERR_PTR(-EPERM) that is
      propagated. The dst that was allocated is never released.
      
      IPv4 local broadcast testcase:
       ping -b 192.168.1.255 &
       sleep 1
       ip xfrm policy add src 0.0.0.0/0 dst 192.168.1.255/32 dir out action block
      
      IPv4 multicast testcase:
       ping 224.0.0.1 &
       sleep 1
       ip xfrm policy add src 0.0.0.0/0 dst 224.0.0.1/32 dir out action block
      
      For IPv6 the missing dst_release() causes trouble e.g. when used in netns:
       ip netns add TEST
       ip netns exec TEST ip link set lo up
       ip link add dummy0 type dummy
       ip link set dev dummy0 netns TEST
       ip netns exec TEST ip addr add fd00::1111 dev dummy0
       ip netns exec TEST ip link set dummy0 up
       ip netns exec TEST ping -6 -c 5 ff02::1%dummy0 &
       sleep 1
       ip netns exec TEST ip xfrm policy add src ::/0 dst ff02::1 dir out action block
       wait
       ip netns del TEST
      
      After netns deletion we see:
      [  258.239097] unregister_netdevice: waiting for lo to become free. Usage count = 2
      [  268.279061] unregister_netdevice: waiting for lo to become free. Usage count = 2
      [  278.367018] unregister_netdevice: waiting for lo to become free. Usage count = 2
      [  288.375259] unregister_netdevice: waiting for lo to become free. Usage count = 2
      
      Fixes: ac37e251 ("xfrm: release dst_orig in case of error in xfrm_lookup()")
      Signed-off-by: default avatarTommi Rantala <tommi.t.rantala@nokia.com>
      Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d35cc7ed
    • Eyal Birger's avatar
      vti6: fix PMTU caching and reporting on xmit · d2adc199
      Eyal Birger authored
      [ Upstream commit d6990976 ]
      
      When setting the skb->dst before doing the MTU check, the route PMTU
      caching and reporting is done on the new dst which is about to be
      released.
      
      Instead, PMTU handling should be done using the original dst.
      
      This is aligned with IPv4 VTI.
      
      Fixes: ccd740cb ("vti6: Add pmtu handling to vti6_xmit.")
      Signed-off-by: default avatarEyal Birger <eyal.birger@gmail.com>
      Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d2adc199
    • Paulo Flabiano Smorigo's avatar
  2. 24 Aug, 2018 5 commits