Skip to content
  1. Sep 07, 2022
    • Tasos Sahanidis's avatar
      ALSA: emu10k1: Fix out of bounds access in snd_emu10k1_pcm_channel_alloc() · d29f5905
      Tasos Sahanidis authored
      
      
      The voice allocator sometimes begins allocating from near the end of the
      array and then wraps around, however snd_emu10k1_pcm_channel_alloc()
      accesses the newly allocated voices as if it never wrapped around.
      
      This results in out of bounds access if the first voice has a high enough
      index so that first_voice + requested_voice_count > NUM_G (64).
      The more voices are requested, the more likely it is for this to occur.
      
      This was initially discovered using PipeWire, however it can be reproduced
      by calling aplay multiple times with 16 channels:
      aplay -r 48000 -D plughw:CARD=Live,DEV=3 -c 16 /dev/zero
      
      UBSAN: array-index-out-of-bounds in sound/pci/emu10k1/emupcm.c:127:40
      index 65 is out of range for type 'snd_emu10k1_voice [64]'
      CPU: 1 PID: 31977 Comm: aplay Tainted: G        W IOE      6.0.0-rc2-emu10k1+ #7
      Hardware name: ASUSTEK COMPUTER INC P5W DH Deluxe/P5W DH Deluxe, BIOS 3002    07/22/2010
      Call Trace:
      <TASK>
      dump_stack_lvl+0x49/0x63
      dump_stack+0x10/0x16
      ubsan_epilogue+0x9/0x3f
      __ubsan_handle_out_of_bounds.cold+0x44/0x49
      snd_emu10k1_playback_hw_params+0x3bc/0x420 [snd_emu10k1]
      snd_pcm_hw_params+0x29f/0x600 [snd_pcm]
      snd_pcm_common_ioctl+0x188/0x1410 [snd_pcm]
      ? exit_to_user_mode_prepare+0x35/0x170
      ? do_syscall_64+0x69/0x90
      ? syscall_exit_to_user_mode+0x26/0x50
      ? do_syscall_64+0x69/0x90
      ? exit_to_user_mode_prepare+0x35/0x170
      snd_pcm_ioctl+0x27/0x40 [snd_pcm]
      __x64_sys_ioctl+0x95/0xd0
      do_syscall_64+0x5c/0x90
      ? do_syscall_64+0x69/0x90
      ? do_syscall_64+0x69/0x90
      entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Signed-off-by: default avatarTasos Sahanidis <tasos@tasossah.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/3707dcab-320a-62ff-63c0-73fc201ef756@tasossah.com
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      d29f5905
  2. Sep 06, 2022
    • Takashi Iwai's avatar
      ALSA: hda: Once again fix regression of page allocations with IOMMU · 37137ec2
      Takashi Iwai authored
      The last fix for trying to recover the regression on AMD platforms,
      unfortunately, leaded to yet another regression: it turned out that
      IOMMUs don't like the usage of raw page allocations.
      
      This is yet another attempt for addressing the log saga; at this time,
      we re-use the existing buffer allocation mechanism with SG-pages
      although we require only single pages.  The SG buffer allocation
      itself was confirmed to work for stream buffers, so it's relatively
      easy to adapt for other places.
      
      The only problem is: although the HD-audio code is accessing the
      address directly via dmab->address field, SG-pages don't set up it.
      For the ease of adaption, we now set up the dmab->addr field from the
      address of the first page as default, so that it can run with the
      HD-audio driver code as-is without the excessive call of
      snd_sgbuf_get_addr() multiple times; that's the only change in the
      memalloc helper side.  The rest is nothing but a flip of the dma_type
      field in the HD-audio side.
      
      Fixes: a8d302a0
      
       ("ALSA: memalloc: Revive x86-specific WC page allocations again")
      Reported-by: default avatarMikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
      Tested-by: default avatarMikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/CABXGCsO+kB2t5QyHY-rUe76npr1m0-5JOtt8g8SiHUo34ur7Ww@mail.gmail.com
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216112
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216363
      Link: https://lore.kernel.org/r/20220906090319.23358-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      37137ec2
    • Dongxiang Ke's avatar
      ALSA: usb-audio: Fix an out-of-bounds bug in __snd_usb_parse_audio_interface() · e53f47f6
      Dongxiang Ke authored
      
      
      There may be a bad USB audio device with a USB ID of (0x04fa, 0x4201) and
      the number of it's interfaces less than 4, an out-of-bounds read bug occurs
      when parsing the interface descriptor for this device.
      
      Fix this by checking the number of interfaces.
      
      Signed-off-by: default avatarDongxiang Ke <kdx.glider@gmail.com>
      Link: https://lore.kernel.org/r/20220906024928.10951-1-kdx.glider@gmail.com
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      e53f47f6
    • Mohan Kumar's avatar
      ALSA: hda/tegra: Align BDL entry to 4KB boundary · 8d44e604
      Mohan Kumar authored
      
      
      AZA HW may send a burst read/write request crossing 4K memory boundary.
      The 4KB boundary is not guaranteed by Tegra HDA HW. Make SW change to
      include the flag AZX_DCAPS_4K_BDLE_BOUNDARY to align BDLE to 4K
      boundary.
      
      Signed-off-by: default avatarMohan Kumar <mkumard@nvidia.com>
      Link: https://lore.kernel.org/r/20220905172420.3801-1-mkumard@nvidia.com
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      8d44e604
  3. Sep 05, 2022
    • Takashi Iwai's avatar
      ALSA: hda/sigmatel: Fix unused variable warning for beep power change · 51bdc8bb
      Takashi Iwai authored
      The newly added stac_check_power_status() caused a compile warning
      when CONFIG_SND_HDA_INPUT_BEEP is disabled.  Fix it.
      
      Fixes: 414d38ba
      
       ("ALSA: hda/sigmatel: Keep power up while beep is enabled")
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Link: https://lore.kernel.org/r/20220905130630.2845-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      51bdc8bb
    • Takashi Iwai's avatar
      ALSA: pcm: oss: Fix race at SNDCTL_DSP_SYNC · 8423f0b6
      Takashi Iwai authored
      
      
      There is a small race window at snd_pcm_oss_sync() that is called from
      OSS PCM SNDCTL_DSP_SYNC ioctl; namely the function calls
      snd_pcm_oss_make_ready() at first, then takes the params_lock mutex
      for the rest.  When the stream is set up again by another thread
      between them, it leads to inconsistency, and may result in unexpected
      results such as NULL dereference of OSS buffer as a fuzzer spotted
      recently.
      
      The fix is simply to cover snd_pcm_oss_make_ready() call into the same
      params_lock mutex with snd_pcm_oss_make_ready_locked() variant.
      
      Reported-and-tested-by: default avatarbutt3rflyh4ck <butterflyhuangxx@gmail.com>
      Reviewed-by: default avatarJaroslav Kysela <perex@perex.cz>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/CAFcO6XN7JDM4xSXGhtusQfS2mSBcx50VJKwQpCq=WeLt57aaZA@mail.gmail.com
      Link: https://lore.kernel.org/r/20220905060714.22549-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      8423f0b6
  4. Sep 04, 2022
  5. Sep 02, 2022
  6. Sep 01, 2022
    • Takashi Iwai's avatar
      ALSA: usb-audio: Split endpoint setups for hw_params and prepare · ff878b40
      Takashi Iwai authored
      One of the former changes for the endpoint management was the more
      consistent setup of endpoints at hw_params.
      snd_usb_endpoint_configure() is a single function that does the full
      setup, and it's called from both PCM hw_params and prepare callbacks.
      Although the EP setup at the prepare phase is usually skipped (by
      checking need_setup flag), it may be still effective in some cases
      like suspend/resume that requires the interface setup again.
      
      As it's a full and single setup, the invocation of
      snd_usb_endpoint_configure() includes not only the USB interface setup
      but also the buffer release and allocation.  OTOH, doing the buffer
      release and re-allocation at PCM prepare phase is rather superfluous,
      and better to be done only in the hw_params phase.
      
      For those optimizations, this patch splits the endpoint setup to two
      phases: snd_usb_endpoint_set_params() and snd_usb_endpoint_prepare(),
      to be called from hw_params and from prepare, respectively.
      
      Note that this patch changes the driver operation slightly,
      effectively moving the USB interface setup again to PCM prepare stage
      instead of hw_params stage, while the buffer allocation and such
      initializations are still done at hw_params stage.
      
      And, the change of the USB interface setup timing (moving to prepare)
      gave an interesting "fix", too: it was reported that the recent
      kernels caused silent output at the beginning on playbacks on some
      devices on Android, and this change casually fixed the regression.
      It seems that those devices are picky about the sample rate change (or
      the interface change?), and don't follow the too immediate rate
      changes.
      
      Meanwhile, Android operates the PCM in the following order:
      - open, then hw_params with the possibly highest sample rate
      - close without prepare
      - re-open, hw_params with the normal sample rate
      - prepare, and start streaming
      This procedure ended up the hw_params twice with different rates, and
      because the recent kernel did set up the sample rate twice one and
      after, it screwed up the device.  OTOH, the earlier kernels didn't set
      up the USB interface at hw_params, hence this problem didn't appear.
      
      Now, with this patch, the USB interface setup is again back to the
      prepare phase, and it works around the problem automagically.
      Although we should address the sample rate problem in a more solid
      way in future, let's keep things working as before for now.
      
      Fixes: bf6313a0
      
       ("ALSA: usb-audio: Refactor endpoint management")
      Cc: <stable@vger.kernel.org>
      Reported-by: default avatarchihhao chen <chihhao.chen@mediatek.com>
      Link: https://lore.kernel.org/r/87e6d6ae69d68dc588ac9acc8c0f24d6188375c3.camel@mediatek.com
      Link: https://lore.kernel.org/r/20220901124136.4984-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      ff878b40
    • Takashi Iwai's avatar
      ALSA: usb-audio: Register card again for iface over delayed_register option · 2027f114
      Takashi Iwai authored
      When the delayed registration is specified via either delayed_register
      option or the quirk, we delay the invocation of snd_card_register()
      until the given interface.  But if a wrong value has been set there
      and there are more interfaces over the given interface number,
      snd_card_register() call would be missing for those interfaces.
      
      This patch catches up those missing calls by fixing the comparison of
      the interface number.  Now the call is skipped only if the processed
      interface is less than the given interface, instead of the exact
      match.
      
      Fixes: b70038ef
      
       ("ALSA: usb-audio: Add delayed_register option")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216082
      Link: https://lore.kernel.org/r/20220831125901.4660-2-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      2027f114
    • Takashi Iwai's avatar
      ALSA: usb-audio: Inform the delayed registration more properly · 7e1afce5
      Takashi Iwai authored
      The info message that was added in the commit a4aad563 ("ALSA:
      usb-audio: Inform devices that need delayed registration") is actually
      useful to know the need for the delayed registration.  However, it
      turned out that this doesn't catch the all cases; namely, this warned
      only when a PCM stream is attached onto the existing PCM instance, but
      it doesn't count for a newly created PCM instance.  This made
      confusion as if there were no further delayed registration.
      
      This patch moves the check to the code path for either adding a stream
      or creating a PCM instance.  Also, make it simpler by checking the
      card->registered flag instead of querying each snd_device state.
      
      Fixes: a4aad563
      
       ("ALSA: usb-audio: Inform devices that need delayed registration")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216082
      Link: https://lore.kernel.org/r/20220831125901.4660-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      7e1afce5
  7. Aug 28, 2022
  8. Aug 26, 2022
  9. Aug 24, 2022
  10. Aug 23, 2022
    • Takashi Iwai's avatar
      ALSA: seq: oss: Fix data-race for max_midi_devs access · 22dec134
      Takashi Iwai authored
      
      
      ALSA OSS sequencer refers to a global variable max_midi_devs at
      creating a new port, storing it to its own field.  Meanwhile this
      variable may be changed by other sequencer events at
      snd_seq_oss_midi_check_exit_port() in parallel, which may cause a data
      race.
      
      OTOH, this data race itself is almost harmless, as the access to the
      MIDI device is done via get_mdev() and it's protected with a refcount,
      hence its presence is guaranteed.
      
      Though, it's sill better to address the data-race from the code sanity
      POV, and this patch adds the proper spinlock for the protection.
      
      Reported-by: default avatarAbhishek Shah <abhishek.shah@columbia.edu>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/CAEHB2493pZRXs863w58QWnUTtv3HHfg85aYhLn5HJHCwxqtHQg@mail.gmail.com
      Link: https://lore.kernel.org/r/20220823072717.1706-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      22dec134
  11. Aug 22, 2022
    • Takashi Iwai's avatar
      ALSA: memalloc: Revive x86-specific WC page allocations again · a8d302a0
      Takashi Iwai authored
      We dropped the x86-specific hack for WC-page allocations with a hope
      that the standard dma_alloc_wc() works nowadays.  Alas, it doesn't,
      and we need to take back some workaround again, but in a different
      form, as the previous one was broken for some platforms.
      
      This patch re-introduces the x86-specific WC-page allocations, but it
      uses rather the manual page allocations instead of
      dma_alloc_coherent().  The use of dma_alloc_coherent() was also a
      potential problem in the recent addition of the fallback allocation
      for noncontig pages, and this patch eliminates both at once.
      
      Fixes: 9882d63b
      
       ("ALSA: memalloc: Drop x86-specific hack for WC allocations")
      Cc: <stable@vger.kernel.org>
      BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=216363
      Link: https://lore.kernel.org/r/20220821155911.10715-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      a8d302a0
    • Linus Torvalds's avatar
      Linux 6.0-rc2 · 1c23f9e6
      Linus Torvalds authored
      v6.0-rc2
      1c23f9e6
    • Linus Torvalds's avatar
      Merge tag 'irq-urgent-2022-08-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · 4daa6a81
      Linus Torvalds authored
      Pull irq fixes from Ingo Molnar:
       "Misc irqchip fixes: LoongArch driver fixes and a Hyper-V IOMMU fix"
      
      * tag 'irq-urgent-2022-08-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        irqchip/loongson-liointc: Fix an error handling path in liointc_init()
        irqchip/loongarch: Fix irq_domain_alloc_fwnode() abuse
        irqchip/loongson-pch-pic: Move find_pch_pic() into CONFIG_ACPI
        irqchip/loongson-eiointc: Fix a build warning
        irqchip/loongson-eiointc: Fix irq affinity setting
        iommu/hyper-v: Use helper instead of directly accessing affinity
      4daa6a81
    • Linus Torvalds's avatar
      Merge tag 'perf-urgent-2022-08-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · 4f61f842
      Linus Torvalds authored
      Pull x86 kprobes fix from Ingo Molnar:
       "Fix a kprobes bug in JNG/JNLE emulation when a kprobe is installed at
        such instructions, possibly resulting in incorrect execution (the
        wrong branch taken)"
      
      * tag 'perf-urgent-2022-08-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        x86/kprobes: Fix JNG/JNLE emulation
      4f61f842
    • Linus Torvalds's avatar
      Merge tag 'trace-v6.0-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace · 7fb312d2
      Linus Torvalds authored
      Pull tracing fixes from Steven Rostedt:
       "Various fixes for tracing:
      
         - Fix a return value of traceprobe_parse_event_name()
      
         - Fix NULL pointer dereference from failed ftrace enabling
      
         - Fix NULL pointer dereference when asking for registers from eprobes
      
         - Make eprobes consistent with kprobes/uprobes, filters and
           histograms"
      
      * tag 'trace-v6.0-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
        tracing: Have filter accept "common_cpu" to be consistent
        tracing/probes: Have kprobes and uprobes use $COMM too
        tracing/eprobes: Have event probes be consistent with kprobes and uprobes
        tracing/eprobes: Fix reading of string fields
        tracing/eprobes: Do not hardcode $comm as a string
        tracing/eprobes: Do not allow eprobes to use $stack, or % for regs
        ftrace: Fix NULL pointer dereference in is_ftrace_trampoline when ftrace is dead
        tracing/perf: Fix double put of trace event when init fails
        tracing: React to error return from traceprobe_parse_event_name()
      7fb312d2
    • Steven Rostedt (Google)'s avatar
      tracing: Have filter accept "common_cpu" to be consistent · b2380577
      Steven Rostedt (Google) authored
      Make filtering consistent with histograms. As "cpu" can be a field of an
      event, allow for "common_cpu" to keep it from being confused with the
      "cpu" field of the event.
      
      Link: https://lkml.kernel.org/r/20220820134401.513062765@goodmis.org
      Link: https://lore.kernel.org/all/20220820220920.e42fa32b70505b1904f0a0ad@kernel.org/
      
      Cc: stable@vger.kernel.org
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Fixes: 1e3bac71
      
       ("tracing/histogram: Rename "cpu" to "common_cpu"")
      Suggested-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      b2380577
    • Steven Rostedt (Google)'s avatar
      tracing/probes: Have kprobes and uprobes use $COMM too · ab838444
      Steven Rostedt (Google) authored
      Both $comm and $COMM can be used to get current->comm in eprobes and the
      filtering and histogram logic. Make kprobes and uprobes consistent in this
      regard and allow both $comm and $COMM as well. Currently kprobes and
      uprobes only handle $comm, which is inconsistent with the other utilities,
      and can be confusing to users.
      
      Link: https://lkml.kernel.org/r/20220820134401.317014913@goodmis.org
      Link: https://lore.kernel.org/all/20220820220442.776e1ddaf8836e82edb34d01@kernel.org/
      
      Cc: stable@vger.kernel.org
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Fixes: 53305928
      
       ("tracing: probeevent: Introduce new argument fetching code")
      Suggested-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      ab838444
    • Steven Rostedt (Google)'s avatar
      tracing/eprobes: Have event probes be consistent with kprobes and uprobes · 6a832ec3
      Steven Rostedt (Google) authored
      Currently, if a symbol "@" is attempted to be used with an event probe
      (eprobes), it will cause a NULL pointer dereference crash.
      
      Both kprobes and uprobes can reference data other than the main registers.
      Such as immediate address, symbols and the current task name. Have eprobes
      do the same thing.
      
      For "comm", if "comm" is used and the event being attached to does not
      have the "comm" field, then make it the "$comm" that kprobes has. This is
      consistent to the way histograms and filters work.
      
      Link: https://lkml.kernel.org/r/20220820134401.136924220@goodmis.org
      
      Cc: stable@vger.kernel.org
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Fixes: 7491e2c4
      
       ("tracing: Add a probe that attaches to trace events")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      6a832ec3
    • Steven Rostedt (Google)'s avatar
      tracing/eprobes: Fix reading of string fields · f04dec93
      Steven Rostedt (Google) authored
      Currently when an event probe (eprobe) hooks to a string field, it does
      not display it as a string, but instead as a number. This makes the field
      rather useless. Handle the different kinds of strings, dynamic, static,
      relational/dynamic etc.
      
      Now when a string field is used, the ":string" type can be used to display
      it:
      
        echo "e:sw sched/sched_switch comm=$next_comm:string" > dynamic_events
      
      Link: https://lkml.kernel.org/r/20220820134400.959640191@goodmis.org
      
      Cc: stable@vger.kernel.org
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Fixes: 7491e2c4
      
       ("tracing: Add a probe that attaches to trace events")
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      f04dec93
    • Steven Rostedt (Google)'s avatar
      tracing/eprobes: Do not hardcode $comm as a string · 02333de9
      Steven Rostedt (Google) authored
      The variable $comm is hard coded as a string, which is true for both
      kprobes and uprobes, but for event probes (eprobes) it is a field name. In
      most cases the "comm" field would be a string, but there's no guarantee of
      that fact.
      
      Do not assume that comm is a string. Not to mention, it currently forces
      comm fields to fault, as string processing for event probes is currently
      broken.
      
      Link: https://lkml.kernel.org/r/20220820134400.756152112@goodmis.org
      
      Cc: stable@vger.kernel.org
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Fixes: 7491e2c4
      
       ("tracing: Add a probe that attaches to trace events")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      02333de9
    • Steven Rostedt (Google)'s avatar
      tracing/eprobes: Do not allow eprobes to use $stack, or % for regs · 2673c60e
      Steven Rostedt (Google) authored
      While playing with event probes (eprobes), I tried to see what would
      happen if I attempted to retrieve the instruction pointer (%rip) knowing
      that event probes do not use pt_regs. The result was:
      
       BUG: kernel NULL pointer dereference, address: 0000000000000024
       #PF: supervisor read access in kernel mode
       #PF: error_code(0x0000) - not-present page
       PGD 0 P4D 0
       Oops: 0000 [#1] PREEMPT SMP PTI
       CPU: 1 PID: 1847 Comm: trace-cmd Not tainted 5.19.0-rc5-test+ #309
       Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01
      v03.03 07/14/2016
       RIP: 0010:get_event_field.isra.0+0x0/0x50
       Code: ff 48 c7 c7 c0 8f 74 a1 e8 3d 8b f5 ff e8 88 09 f6 ff 4c 89 e7 e8
      50 6a 13 00 48 89 ef 5b 5d 41 5c 41 5d e9 42 6a 13 00 66 90 <48> 63 47 24
      8b 57 2c 48 01 c6 8b 47 28 83 f8 02 74 0e 83 f8 04 74
       RSP: 0018:ffff916c394bbaf0 EFLAGS: 00010086
       RAX: ffff916c854041d8 RBX: ffff916c8d9fbf50 RCX: ffff916c255d2000
       RDX: 0000000000000000 RSI: ffff916c255d2008 RDI: 0000000000000000
       RBP: 0000000000000000 R08: ffff916c3a2a0c08 R09: ffff916c394bbda8
       R10: 0000000000000000 R11: 0000000000000000 R12: ffff916c854041d8
       R13: ffff916c854041b0 R14: 0000000000000000 R15: 0000000000000000
       FS:  0000000000000000(0000) GS:ffff916c9ea40000(0000)
      knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: 0000000000000024 CR3: 000000011b60a002 CR4: 00000000001706e0
       Call Trace:
        <TASK>
        get_eprobe_size+0xb4/0x640
        ? __mod_node_page_state+0x72/0xc0
        __eprobe_trace_func+0x59/0x1a0
        ? __mod_lruvec_page_state+0xaa/0x1b0
        ? page_remove_file_rmap+0x14/0x230
        ? page_remove_rmap+0xda/0x170
        event_triggers_call+0x52/0xe0
        trace_event_buffer_commit+0x18f/0x240
        trace_event_raw_event_sched_wakeup_template+0x7a/0xb0
        try_to_wake_up+0x260/0x4c0
        __wake_up_common+0x80/0x180
        __wake_up_common_lock+0x7c/0xc0
        do_notify_parent+0x1c9/0x2a0
        exit_notify+0x1a9/0x220
        do_exit+0x2ba/0x450
        do_group_exit+0x2d/0x90
        __x64_sys_exit_group+0x14/0x20
        do_syscall_64+0x3b/0x90
        entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
      Obviously this is not the desired result.
      
      Move the testing for TPARG_FL_TPOINT which is only used for event probes
      to the top of the "$" variable check, as all the other variables are not
      used for event probes. Also add a check in the register parsing "%" to
      fail if an event probe is used.
      
      Link: https://lkml.kernel.org/r/20220820134400.564426983@goodmis.org
      
      Cc: stable@vger.kernel.org
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Fixes: 7491e2c4
      
       ("tracing: Add a probe that attaches to trace events")
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      2673c60e
    • Yang Jihong's avatar
      ftrace: Fix NULL pointer dereference in is_ftrace_trampoline when ftrace is dead · c3b0f72e
      Yang Jihong authored
      
      
      ftrace_startup does not remove ops from ftrace_ops_list when
      ftrace_startup_enable fails:
      
      register_ftrace_function
        ftrace_startup
          __register_ftrace_function
            ...
            add_ftrace_ops(&ftrace_ops_list, ops)
            ...
          ...
          ftrace_startup_enable // if ftrace failed to modify, ftrace_disabled is set to 1
          ...
        return 0 // ops is in the ftrace_ops_list.
      
      When ftrace_disabled = 1, unregister_ftrace_function simply returns without doing anything:
      unregister_ftrace_function
        ftrace_shutdown
          if (unlikely(ftrace_disabled))
                  return -ENODEV;  // return here, __unregister_ftrace_function is not executed,
                                   // as a result, ops is still in the ftrace_ops_list
          __unregister_ftrace_function
          ...
      
      If ops is dynamically allocated, it will be free later, in this case,
      is_ftrace_trampoline accesses NULL pointer:
      
      is_ftrace_trampoline
        ftrace_ops_trampoline
          do_for_each_ftrace_op(op, ftrace_ops_list) // OOPS! op may be NULL!
      
      Syzkaller reports as follows:
      [ 1203.506103] BUG: kernel NULL pointer dereference, address: 000000000000010b
      [ 1203.508039] #PF: supervisor read access in kernel mode
      [ 1203.508798] #PF: error_code(0x0000) - not-present page
      [ 1203.509558] PGD 800000011660b067 P4D 800000011660b067 PUD 130fb8067 PMD 0
      [ 1203.510560] Oops: 0000 [#1] SMP KASAN PTI
      [ 1203.511189] CPU: 6 PID: 29532 Comm: syz-executor.2 Tainted: G    B   W         5.10.0 #8
      [ 1203.512324] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
      [ 1203.513895] RIP: 0010:is_ftrace_trampoline+0x26/0xb0
      [ 1203.514644] Code: ff eb d3 90 41 55 41 54 49 89 fc 55 53 e8 f2 00 fd ff 48 8b 1d 3b 35 5d 03 e8 e6 00 fd ff 48 8d bb 90 00 00 00 e8 2a 81 26 00 <48> 8b ab 90 00 00 00 48 85 ed 74 1d e8 c9 00 fd ff 48 8d bb 98 00
      [ 1203.518838] RSP: 0018:ffffc900012cf960 EFLAGS: 00010246
      [ 1203.520092] RAX: 0000000000000000 RBX: 000000000000007b RCX: ffffffff8a331866
      [ 1203.521469] RDX: 0000000000000000 RSI: 0000000000000008 RDI: 000000000000010b
      [ 1203.522583] RBP: 0000000000000000 R08: 0000000000000000 R09: ffffffff8df18b07
      [ 1203.523550] R10: fffffbfff1be3160 R11: 0000000000000001 R12: 0000000000478399
      [ 1203.524596] R13: 0000000000000000 R14: ffff888145088000 R15: 0000000000000008
      [ 1203.525634] FS:  00007f429f5f4700(0000) GS:ffff8881daf00000(0000) knlGS:0000000000000000
      [ 1203.526801] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [ 1203.527626] CR2: 000000000000010b CR3: 0000000170e1e001 CR4: 00000000003706e0
      [ 1203.528611] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [ 1203.529605] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      
      Therefore, when ftrace_startup_enable fails, we need to rollback registration
      process and remove ops from ftrace_ops_list.
      
      Link: https://lkml.kernel.org/r/20220818032659.56209-1-yangjihong1@huawei.com
      
      Suggested-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarYang Jihong <yangjihong1@huawei.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      c3b0f72e
    • Steven Rostedt (Google)'s avatar
      tracing/perf: Fix double put of trace event when init fails · 7249921d
      Steven Rostedt (Google) authored
      If in perf_trace_event_init(), the perf_trace_event_open() fails, then it
      will call perf_trace_event_unreg() which will not only unregister the perf
      trace event, but will also call the put() function of the tp_event.
      
      The problem here is that the trace_event_try_get_ref() is called by the
      caller of perf_trace_event_init() and if perf_trace_event_init() returns a
      failure, it will then call trace_event_put(). But since the
      perf_trace_event_unreg() already called the trace_event_put() function, it
      triggers a WARN_ON().
      
       WARNING: CPU: 1 PID: 30309 at kernel/trace/trace_dynevent.c:46 trace_event_dyn_put_ref+0x15/0x20
      
      If perf_trace_event_reg() does not call the trace_event_try_get_ref() then
      the perf_trace_event_unreg() should not be calling trace_event_put(). This
      breaks symmetry and causes bugs like these.
      
      Pull out the trace_event_put() from perf_trace_event_unreg() and call it
      in the locations that perf_trace_event_unreg() is called. This not only
      fixes this bug, but also brings back the proper symmetry of the reg/unreg
      vs get/put logic.
      
      Link: https://lore.kernel.org/all/cover.1660347763.git.kjlx@templeofstupid.com/
      Link: https://lkml.kernel.org/r/20220816192817.43d5e17f@gandalf.local.home
      
      Cc: stable@vger.kernel.org
      Fixes: 1d18538e
      
       ("tracing: Have dynamic events have a ref counter")
      Reported-by: default avatarKrister Johansen <kjlx@templeofstupid.com>
      Reviewed-by: default avatarKrister Johansen <kjlx@templeofstupid.com>
      Tested-by: default avatarKrister Johansen <kjlx@templeofstupid.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      7249921d
    • Lukas Bulwahn's avatar
      tracing: React to error return from traceprobe_parse_event_name() · d8a64313
      Lukas Bulwahn authored
      The function traceprobe_parse_event_name() may set the first two function
      arguments to a non-null value and still return -EINVAL to indicate an
      unsuccessful completion of the function. Hence, it is not sufficient to
      just check the result of the two function arguments for being not null,
      but the return value also needs to be checked.
      
      Commit 95c104c3 ("tracing: Auto generate event name when creating a
      group of events") changed the error-return-value checking of the second
      traceprobe_parse_event_name() invocation in __trace_eprobe_create() and
      removed checking the return value to jump to the error handling case.
      
      Reinstate using the return value in the error-return-value checking.
      
      Link: https://lkml.kernel.org/r/20220811071734.20700-1-lukas.bulwahn@gmail.com
      
      Fixes: 95c104c3
      
       ("tracing: Auto generate event name when creating a group of events")
      Acked-by: default avatarLinyu Yuan <quic_linyyuan@quicinc.com>
      Signed-off-by: default avatarLukas Bulwahn <lukas.bulwahn@gmail.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      d8a64313
    • Linus Torvalds's avatar
      Merge tag 'i2c-for-6.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux · e3f259d3
      Linus Torvalds authored
      Pull i2c fixes from Wolfram Sang:
       "A revert to fix a regression introduced this merge window and a fix
        for proper error handling in the remove path of the iMX driver"
      
      * tag 'i2c-for-6.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
        i2c: imx: Make sure to unregister adapter on remove()
        Revert "i2c: scmi: Replace open coded device_get_match_data()"
      e3f259d3
    • Linus Torvalds's avatar
      Merge tag '6.0-rc1-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6 · 367bcbc5
      Linus Torvalds authored
      Pull cifs client fixes from Steve French:
      
       - memory leak fix
      
       - two small cleanups
      
       - trivial strlcpy removal
      
       - update missing entry for cifs headers in MAINTAINERS file
      
      * tag '6.0-rc1-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6:
        cifs: move from strlcpy with unused retval to strscpy
        cifs: Fix memory leak on the deferred close
        cifs: remove useless parameter 'is_fsctl' from SMB2_ioctl()
        cifs: remove unused server parameter from calc_smb_size()
        cifs: missing directory in MAINTAINERS file
      367bcbc5
    • Nick Desaulniers's avatar
      asm goto: eradicate CC_HAS_ASM_GOTO · a0a12c3e
      Nick Desaulniers authored
      
      
      GCC has supported asm goto since 4.5, and Clang has since version 9.0.0.
      The minimum supported versions of these tools for the build according to
      Documentation/process/changes.rst are 5.1 and 11.0.0 respectively.
      
      Remove the feature detection script, Kconfig option, and clean up some
      fallback code that is no longer supported.
      
      The removed script was also testing for a GCC specific bug that was
      fixed in the 4.7 release.
      
      Also remove workarounds for bpftrace using clang older than 9.0.0, since
      other BPF backend fixes are required at this point.
      
      Link: https://lore.kernel.org/lkml/CAK7LNATSr=BXKfkdW8f-H5VT_w=xBpT2ZQcZ7rm6JfkdE+QnmA@mail.gmail.com/
      Link: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48637
      Acked-by: default avatarBorislav Petkov <bp@suse.de>
      Suggested-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Suggested-by: default avatarAlexei Starovoitov <alexei.starovoitov@gmail.com>
      Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: default avatarIngo Molnar <mingo@kernel.org>
      Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      a0a12c3e
  12. Aug 21, 2022
    • Uwe Kleine-König's avatar
      i2c: imx: Make sure to unregister adapter on remove() · d98bdd3a
      Uwe Kleine-König authored
      If for whatever reasons pm_runtime_resume_and_get() fails and .remove() is
      exited early, the i2c adapter stays around and the irq still calls its
      handler, while the driver data and the register mapping go away. So if
      later the i2c adapter is accessed or the irq triggers this results in
      havoc accessing freed memory and unmapped registers.
      
      So unregister the software resources even if resume failed, and only skip
      the hardware access in that case.
      
      Fixes: 588eb93e
      
       ("i2c: imx: add runtime pm support to improve the performance")
      Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Acked-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      d98bdd3a
    • Wolfram Sang's avatar
      Revert "i2c: scmi: Replace open coded device_get_match_data()" · 3df71d70
      Wolfram Sang authored
      This reverts commit 9ae551de
      
      . We got a
      regression report, so ensure this machine boots again. We will come back
      with a better version hopefully.
      
      Reported-by: default avatarJosef Johansson <josef@oderland.se>
      Link: https://lore.kernel.org/r/4d2d5b04-0b6c-1cb1-a63f-dc06dfe1b5da@oderland.se
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      3df71d70
    • Linus Torvalds's avatar
      Merge tag 'kbuild-fixes-v6.0' of... · 15b3f48a
      Linus Torvalds authored
      Merge tag 'kbuild-fixes-v6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
      
      Pull Kbuild fixes from Masahiro Yamada:
      
       - Fix module versioning broken on some architectures
      
       - Make dummy-tools enable CONFIG_PPC_LONG_DOUBLE_128
      
       - Remove -Wformat-zero-length, which has no warning instance
      
       - Fix the order between drivers and libs in modules.order
      
       - Fix false-positive warnings in clang-analyzer
      
      * tag 'kbuild-fixes-v6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
        scripts/clang-tools: Remove DeprecatedOrUnsafeBufferHandling check
        kbuild: fix the modules order between drivers and libs
        scripts/Makefile.extrawarn: Do not disable clang's -Wformat-zero-length
        kbuild: dummy-tools: pretend we understand __LONG_DOUBLE_128__
        modpost: fix module versioning when a symbol lacks valid CRC
      15b3f48a
    • Linus Torvalds's avatar
      Merge tag 'perf-tools-fixes-for-v6.0-2022-08-19' of... · 16b3d851
      Linus Torvalds authored
      Merge tag 'perf-tools-fixes-for-v6.0-2022-08-19' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
      
      Pull perf tools fixes from Arnaldo Carvalho de Melo:
      
       - Fix alignment for cpu map masks in event encoding.
      
       - Support reading PERF_FORMAT_LOST, perf tool counterpart for a feature
         that was added in this merge window.
      
       - Sync perf tools copies of kernel headers: socket, msr-index, fscrypt,
         cpufeatures, i915_drm, kvm, vhost, perf_event.
      
      * tag 'perf-tools-fixes-for-v6.0-2022-08-19' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux:
        perf tools: Support reading PERF_FORMAT_LOST
        libperf: Add a test case for read formats
        libperf: Handle read format in perf_evsel__read()
        tools headers UAPI: Sync linux/perf_event.h with the kernel sources
        tools headers UAPI: Sync x86's asm/kvm.h with the kernel sources
        tools headers UAPI: Sync KVM's vmx.h header with the kernel sources
        tools include UAPI: Sync linux/vhost.h with the kernel sources
        tools headers kvm s390: Sync headers with the kernel sources
        tools headers UAPI: Sync linux/kvm.h with the kernel sources
        tools headers UAPI: Sync drm/i915_drm.h with the kernel sources
        tools headers cpufeatures: Sync with the kernel sources
        tools headers UAPI: Sync linux/fscrypt.h with the kernel sources
        tools arch x86: Sync the msr-index.h copy with the kernel sources
        perf beauty: Update copy of linux/socket.h with the kernel sources
        perf cpumap: Fix alignment for masks in event encoding
        perf cpumap: Compute mask size in constant time
        perf cpumap: Synthetic events and const/static
        perf cpumap: Const map for max()
      16b3d851
    • Linus Torvalds's avatar
      Merge tag 's390-6.0-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux · cc1807b9
      Linus Torvalds authored
      Pull s390 updates from Alexander Gordeev:
      
       - Fix a KVM crash on z12 and older machines caused by a wrong
         assumption that Query AP Configuration Information is always
         available.
      
       - Lower severity of excessive Hypervisor filesystem error messages
         when booting under KVM.
      
      * tag 's390-6.0-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux:
        s390/ap: fix crash on older machines based on QCI info missing
        s390/hypfs: avoid error message under KVM
      cc1807b9