1. 31 Dec, 2019 40 commits
    • Nathan Chancellor's avatar
      tools/power/cpupower: Fix initializer override in hsw_ext_cstates · aac91ba6
      Nathan Chancellor authored
      [ Upstream commit 7e5705c6 ]
      
      When building cpupower with clang, the following warning appears:
      
       utils/idle_monitor/hsw_ext_idle.c:42:16: warning: initializer overrides
       prior initialization of this subobject [-Winitializer-overrides]
                       .desc                   = N_("Processor Package C2"),
                                                    ^~~~~~~~~~~~~~~~~~~~~~
       ./utils/helpers/helpers.h:25:33: note: expanded from macro 'N_'
       #define N_(String) gettext_noop(String)
                                       ^~~~~~
       ./utils/helpers/helpers.h:23:30: note: expanded from macro
       'gettext_noop'
       #define gettext_noop(String) String
                                    ^~~~~~
       utils/idle_monitor/hsw_ext_idle.c:41:16: note: previous initialization
       is here
                       .desc                   = N_("Processor Package C9"),
                                                    ^~~~~~~~~~~~~~~~~~~~~~
       ./utils/helpers/helpers.h:25:33: note: expanded from macro 'N_'
       #define N_(String) gettext_noop(String)
                                       ^~~~~~
       ./utils/helpers/helpers.h:23:30: note: expanded from macro
       'gettext_noop'
       #define gettext_noop(String) String
                                   ^~~~~~
       1 warning generated.
      
      This appears to be a copy and paste or merge mistake because the name
      and id fields both have PC9 in them, not PC2. Remove the second
      assignment to fix the warning.
      
      Fixes: 7ee767b6 ("cpupower: Add Haswell family 0x45 specific idle monitor to show PC8,9,10 states")
      Link: https://github.com/ClangBuiltLinux/linux/issues/718Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      aac91ba6
    • Janusz Krzysztofik's avatar
      media: ov6650: Fix stored crop rectangle not in sync with hardware · b9d63c82
      Janusz Krzysztofik authored
      [ Upstream commit 1463b371 ]
      
      The driver stores crop rectangle settings supposed to be in line with
      hardware state in a device private structure.  Since the driver initial
      submission, crop rectangle width and height settings are not updated
      correctly when rectangle offset settings are applied on hardware.  If
      an error occurs while the device is updated, the stored settings my no
      longer reflect hardware state and consecutive calls to .get_selection()
      as well as .get/set_fmt() may return incorrect information.  That in
      turn may affect ability of a bridge device to use correct DMA transfer
      settings if such incorrect informamtion on active frame format returned
      by .get/set_fmt() is used.
      
      Assuming a failed update of the device means its actual settings haven't
      changed, update crop rectangle width and height settings stored in the
      device private structure correctly while the rectangle offset is
      successfully applied on hardware so the stored values always reflect
      actual hardware state to the extent possible.
      
      Fixes: 2f6e2404 ("[media] SoC Camera: add driver for OV6650 sensor")
      Signed-off-by: default avatarJanusz Krzysztofik <jmkrzyszt@gmail.com>
      Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b9d63c82
    • Janusz Krzysztofik's avatar
      media: ov6650: Fix stored frame format not in sync with hardware · 384f83b8
      Janusz Krzysztofik authored
      [ Upstream commit 3143b459 ]
      
      The driver stores frame format settings supposed to be in line with
      hardware state in a device private structure.  Since the driver initial
      submission, those settings are updated before they are actually applied
      on hardware.  If an error occurs on device update, the stored settings
      my not reflect hardware state anymore and consecutive calls to
      .get_fmt() may return incorrect information.  That in turn may affect
      ability of a bridge device to use correct DMA transfer settings if such
      incorrect informmation on active frame format returned by .get_fmt() is
      used.
      
      Assuming a failed device update means its state hasn't changed, update
      frame format related settings stored in the device private structure
      only after they are successfully applied so the stored values always
      reflect hardware state as closely as possible.
      
      Fixes: 2f6e2404 ("[media] SoC Camera: add driver for OV6650 sensor")
      Signed-off-by: default avatarJanusz Krzysztofik <jmkrzyszt@gmail.com>
      Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      384f83b8
    • Benoit Parrot's avatar
      media: i2c: ov2659: Fix missing 720p register config · 018f35cd
      Benoit Parrot authored
      [ Upstream commit 9d669fbf ]
      
      The initial registers sequence is only loaded at probe
      time. Afterward only the resolution and format specific
      register are modified. Care must be taken to make sure
      registers modified by one resolution setting are reverted
      back when another resolution is programmed.
      
      This was not done properly for the 720p case.
      Signed-off-by: default avatarBenoit Parrot <bparrot@ti.com>
      Acked-by: default avatarLad, Prabhakar <prabhakar.csengg@gmail.com>
      Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      018f35cd
    • Janusz Krzysztofik's avatar
      media: ov6650: Fix crop rectangle alignment not passed back · 658f9554
      Janusz Krzysztofik authored
      [ Upstream commit 7b188d6b ]
      
      Commit 4f996594 ("[media] v4l2: make vidioc_s_crop const")
      introduced a writable copy of constified user requested crop rectangle
      in order to be able to perform hardware alignments on it.  Later
      on, commit 10d5509c ("[media] v4l2: remove g/s_crop from video
      ops") replaced s_crop() video operation using that const argument with
      set_selection() pad operation which had a corresponding argument not
      constified, however the original behavior of the driver was not
      restored.  Since that time, any hardware alignment applied on a user
      requested crop rectangle is not passed back to the user calling
      .set_selection() as it should be.
      
      Fix the issue by dropping the copy and replacing all references to it
      with references to the crop rectangle embedded in the user argument.
      
      Fixes: 10d5509c ("[media] v4l2: remove g/s_crop from video ops")
      Signed-off-by: default avatarJanusz Krzysztofik <jmkrzyszt@gmail.com>
      Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      658f9554
    • Benoit Parrot's avatar
      media: i2c: ov2659: fix s_stream return value · 2baeb5f2
      Benoit Parrot authored
      [ Upstream commit 85c4043f ]
      
      In ov2659_s_stream() return value for invoked function should be checked
      and propagated.
      Signed-off-by: default avatarBenoit Parrot <bparrot@ti.com>
      Acked-by: default avatarLad, Prabhakar <prabhakar.csengg@gmail.com>
      Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2baeb5f2
    • Benoit Parrot's avatar
      media: am437x-vpfe: Setting STD to current value is not an error · 3769fabb
      Benoit Parrot authored
      [ Upstream commit 13aa21cf ]
      
      VIDIOC_S_STD should not return an error if the value is identical
      to the current one.
      This error was highlighted by the v4l2-compliance test.
      Signed-off-by: default avatarBenoit Parrot <bparrot@ti.com>
      Acked-by: default avatarLad Prabhakar <prabhakar.csengg@gmail.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3769fabb
    • Max Gurtovoy's avatar
      IB/iser: bound protection_sg size by data_sg size · 81f3665c
      Max Gurtovoy authored
      [ Upstream commit 7718cf03 ]
      
      In case we don't set the sg_prot_tablesize, the scsi layer assign the
      default size (65535 entries). We should limit this size since we should
      take into consideration the underlaying device capability. This cap is
      considered when calculating the sg_tablesize. Otherwise, for example,
      we can get that /sys/block/sdb/queue/max_segments is 128 and
      /sys/block/sdb/queue/max_integrity_segments is 65535.
      
      Link: https://lore.kernel.org/r/1569359027-10987-1-git-send-email-maxg@mellanox.comSigned-off-by: default avatarMax Gurtovoy <maxg@mellanox.com>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      81f3665c
    • Anilkumar Kolli's avatar
      ath10k: fix backtrace on coredump · 83628c23
      Anilkumar Kolli authored
      [ Upstream commit d98ddae8 ]
      
      In a multiradio board with one QCA9984 and one AR9987
      after enabling the crashdump with module parameter
      coredump_mask=7, below backtrace is seen.
      
      vmalloc: allocation failure: 0 bytes
       kworker/u4:0: page allocation failure: order:0, mode:0x80d2
       CPU: 0 PID: 6 Comm: kworker/u4:0 Not tainted 3.14.77 #130
       Workqueue: ath10k_wq ath10k_core_register_work [ath10k_core]
       (unwind_backtrace) from [<c021abf8>] (show_stack+0x10/0x14)
       (dump_stack+0x80/0xa0)
       (warn_alloc_failed+0xd0/0xfc)
       (__vmalloc_node_range+0x1b4/0x1d8)
       (__vmalloc_node+0x34/0x40)
       (vzalloc+0x24/0x30)
       (ath10k_coredump_register+0x6c/0x88 [ath10k_core])
       (ath10k_core_register_work+0x350/0xb34 [ath10k_core])
       (process_one_work+0x20c/0x32c)
       (worker_thread+0x228/0x360)
      
      This is due to ath10k_hw_mem_layout is not defined for AR9987.
      For coredump undefined hw ramdump_size is 0.
      Check for the ramdump_size before allocation memory.
      
      Tested on: AR9987, QCA9984
      FW version: 10.4-3.9.0.2-00044
      Signed-off-by: default avatarAnilkumar Kolli <akolli@codeaurora.org>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      83628c23
    • Allen Pais's avatar
      libertas: fix a potential NULL pointer dereference · 60bb6967
      Allen Pais authored
      [ Upstream commit 7da413a1 ]
      
      alloc_workqueue is not checked for errors and as a result,
      a potential NULL dereference could occur.
      Signed-off-by: default avatarAllen Pais <allen.pais@oracle.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      60bb6967
    • Navid Emamdoost's avatar
      rtlwifi: prevent memory leak in rtl_usb_probe · 3717a450
      Navid Emamdoost authored
      [ Upstream commit 3f936169 ]
      
      In rtl_usb_probe if allocation for usb_data fails the allocated hw
      should be released. In addition the allocated rtlpriv->usb_data should
      be released on error handling path.
      Signed-off-by: default avatarNavid Emamdoost <navid.emamdoost@gmail.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3717a450
    • Connor Kuehl's avatar
      staging: rtl8188eu: fix possible null dereference · dd97f971
      Connor Kuehl authored
      [ Upstream commit 22824194 ]
      
      Inside a nested 'else' block at the beginning of this function is a
      call that assigns 'psta' to the return value of 'rtw_get_stainfo()'.
      If 'rtw_get_stainfo()' returns NULL and the flow of control reaches
      the 'else if' where 'psta' is dereferenced, then we will dereference
      a NULL pointer.
      
      Fix this by checking if 'psta' is not NULL before reading its
      'psta->qos_option' data member.
      
      Addresses-Coverity: ("Dereference null return value")
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Acked-by: default avatarLarry Finger <Larry.Finger@lwfinger.net>
      Link: https://lore.kernel.org/r/20190926150317.5894-1-connor.kuehl@canonical.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dd97f971
    • Navid Emamdoost's avatar
      staging: rtl8192u: fix multiple memory leaks on error path · 69af5fc1
      Navid Emamdoost authored
      [ Upstream commit ca312438 ]
      
      In rtl8192_tx on error handling path allocated urbs and also skb should
      be released.
      Signed-off-by: default avatarNavid Emamdoost <navid.emamdoost@gmail.com>
      Link: https://lore.kernel.org/r/20190920025137.29407-1-navid.emamdoost@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      69af5fc1
    • Lukasz Majewski's avatar
      spi: Add call to spi_slave_abort() function when spidev driver is released · e685d585
      Lukasz Majewski authored
      [ Upstream commit 9f918a72 ]
      
      This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
      in the slave mode (like NXP's dspi driver for Vybrid SoC).
      
      When SPI HW works in this mode - the master is responsible for providing
      CS and CLK signals. However, when some fault happens - like for example
      distortion on SPI lines - the SPI Linux driver needs a chance to recover
      from this abnormal situation and prepare itself for next (correct)
      transmission.
      
      This change doesn't pose any threat on drivers working in master mode as
      spi_slave_abort() function checks if SPI slave mode is supported.
      Signed-off-by: default avatarLukasz Majewski <lukma@denx.de>
      Link: https://lore.kernel.org/r/20190924110547.14770-2-lukma@denx.deSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Reported-by: default avatarkbuild test robot <lkp@intel.com>
      Link: https://lore.kernel.org/r/20190925091143.15468-2-lukma@denx.deSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e685d585
    • Christian König's avatar
      drm/amdgpu: grab the id mgr lock while accessing passid_mapping · 16bb81d5
      Christian König authored
      [ Upstream commit 6817bf28 ]
      
      Need to make sure that we actually dropping the right fence.
      Could be done with RCU as well, but to complicated for a fix.
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      Reviewed-by: default avatarChunming Zhou <david1.zhou@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      16bb81d5
    • Krzysztof Wilczynski's avatar
      iio: light: bh1750: Resolve compiler warning and make code more readable · cfcf92d8
      Krzysztof Wilczynski authored
      [ Upstream commit f552fde9 ]
      
      Separate the declaration of struct bh1750_chip_info from definition
      of bh1750_chip_info_tbl[] in a single statement as it makes the code
      hard to read, and with the extra newline it makes it look as if the
      bh1750_chip_info_tbl[] had no explicit type.
      
      This change also resolves the following compiler warning about the
      unusual position of the static keyword that can be seen when building
      with warnings enabled (W=1):
      
      drivers/iio/light/bh1750.c:64:1: warning:
        ‘static’ is not at beginning of declaration [-Wold-style-declaration]
      
      Related to commit 3a11fbb0 ("iio: light: add support for ROHM
      BH1710/BH1715/BH1721/BH1750/BH1751 ambient light sensors").
      Signed-off-by: default avatarKrzysztof Wilczynski <kw@linux.com>
      Acked-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cfcf92d8
    • Brian Masney's avatar
      drm/bridge: analogix-anx78xx: silence -EPROBE_DEFER warnings · 0f08ffb4
      Brian Masney authored
      [ Upstream commit 2708e876 ]
      
      Silence two warning messages that occur due to -EPROBE_DEFER errors to
      help cleanup the system boot log.
      Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
      Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20190815004854.19860-4-masneyb@onstation.orgSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      0f08ffb4
    • Laurent Pinchart's avatar
      drm/panel: Add missing drm_panel_init() in panel drivers · 183440c0
      Laurent Pinchart authored
      [ Upstream commit 65abbda8 ]
      
      Panels must be initialised with drm_panel_init(). Add the missing
      function call in the panel-raspberrypi-touchscreen.c and
      panel-sitronix-st7789v.c drivers.
      Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
      Link: https://patchwork.freedesktop.org/patch/msgid/20190823193245.23876-2-laurent.pinchart@ideasonboard.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      183440c0
    • Sean Paul's avatar
      drm: mst: Fix query_payload ack reply struct · f015785a
      Sean Paul authored
      [ Upstream commit 268de653 ]
      
      Spec says[1] Allocated_PBN is 16 bits
      
      [1]- DisplayPort 1.2 Spec, Section 2.11.9.8, Table 2-98
      
      Fixes: ad7f8a1f ("drm/helper: add Displayport multi-stream helper (v0.6)")
      Cc: Lyude Paul <lyude@redhat.com>
      Cc: Todd Previte <tprevite@gmail.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
      Cc: Maxime Ripard <maxime.ripard@bootlin.com>
      Cc: Sean Paul <sean@poorly.run>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: dri-devel@lists.freedesktop.org
      Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
      Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
      Link: https://patchwork.freedesktop.org/patch/msgid/20190829165223.129662-1-sean@poorly.runSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      f015785a
    • Takashi Iwai's avatar
      ALSA: hda/ca0132 - Fix work handling in delayed HP detection · c7401a47
      Takashi Iwai authored
      commit 42fb6b1d upstream.
      
      CA0132 has the delayed HP jack detection code that is invoked from the
      unsol handler, but it does a few weird things: it contains the cancel
      of a work inside the work handler, and yet it misses the cancel-sync
      call at (runtime-)suspend.  This patch addresses those issues.
      
      Fixes: 15c2b3cc ("ALSA: hda/ca0132 - Fix possible workqueue stall")
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191213085111.22855-4-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c7401a47
    • Takashi Iwai's avatar
      ALSA: hda/ca0132 - Avoid endless loop · db0e4617
      Takashi Iwai authored
      commit cb04fc3b upstream.
      
      Introduce a timeout to dspio_clear_response_queue() so that it won't
      be caught in an endless loop even if the hardware doesn't respond
      properly.
      
      Fixes: a73d511c ("ALSA: hda/ca0132: Add unsol handler for DSP and jack detection")
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191213085111.22855-3-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      db0e4617
    • Takashi Iwai's avatar
      ALSA: hda/ca0132 - Keep power on during processing DSP response · f25b90f1
      Takashi Iwai authored
      commit 377bc0cf upstream.
      
      We need to keep power on while processing the DSP response via unsol
      event.  Each snd_hda_codec_read() call does the power management, so
      it should work normally, but still it's safer to keep the power up for
      the whole function.
      
      Fixes: a73d511c ("ALSA: hda/ca0132: Add unsol handler for DSP and jack detection")
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191213085111.22855-2-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f25b90f1
    • Takashi Iwai's avatar
      ALSA: pcm: Avoid possible info leaks from PCM stream buffers · b05779d0
      Takashi Iwai authored
      commit add9d56d upstream.
      
      The current PCM code doesn't initialize explicitly the buffers
      allocated for PCM streams, hence it might leak some uninitialized
      kernel data or previous stream contents by mmapping or reading the
      buffer before actually starting the stream.
      
      Since this is a common problem, this patch simply adds the clearance
      of the buffer data at hw_params callback.  Although this does only
      zero-clear no matter which format is used, which doesn't mean the
      silence for some formats, but it should be OK because the intention is
      just to clear the previous data on the buffer.
      Reported-by: default avatarLionel Koenig <lionel.koenig@gmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191211155742.3213-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b05779d0
    • Filipe Manana's avatar
      Btrfs: fix removal logic of the tree mod log that leads to use-after-free issues · b3484913
      Filipe Manana authored
      commit 6609fee8 upstream.
      
      When a tree mod log user no longer needs to use the tree it calls
      btrfs_put_tree_mod_seq() to remove itself from the list of users and
      delete all no longer used elements of the tree's red black tree, which
      should be all elements with a sequence number less then our equals to
      the caller's sequence number. However the logic is broken because it
      can delete and free elements from the red black tree that have a
      sequence number greater then the caller's sequence number:
      
      1) At a point in time we have sequence numbers 1, 2, 3 and 4 in the
         tree mod log;
      
      2) The task which got assigned the sequence number 1 calls
         btrfs_put_tree_mod_seq();
      
      3) Sequence number 1 is deleted from the list of sequence numbers;
      
      4) The current minimum sequence number is computed to be the sequence
         number 2;
      
      5) A task using sequence number 2 is at tree_mod_log_rewind() and gets
         a pointer to one of its elements from the red black tree through
         a call to tree_mod_log_search();
      
      6) The task with sequence number 1 iterates the red black tree of tree
         modification elements and deletes (and frees) all elements with a
         sequence number less then or equals to 2 (the computed minimum sequence
         number) - it ends up only leaving elements with sequence numbers of 3
         and 4;
      
      7) The task with sequence number 2 now uses the pointer to its element,
         already freed by the other task, at __tree_mod_log_rewind(), resulting
         in a use-after-free issue. When CONFIG_DEBUG_PAGEALLOC=y it produces
         a trace like the following:
      
        [16804.546854] general protection fault: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC PTI
        [16804.547451] CPU: 0 PID: 28257 Comm: pool Tainted: G        W         5.4.0-rc8-btrfs-next-51 #1
        [16804.548059] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org 04/01/2014
        [16804.548666] RIP: 0010:rb_next+0x16/0x50
        (...)
        [16804.550581] RSP: 0018:ffffb948418ef9b0 EFLAGS: 00010202
        [16804.551227] RAX: 6b6b6b6b6b6b6b6b RBX: ffff90e0247f6600 RCX: 6b6b6b6b6b6b6b6b
        [16804.551873] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff90e0247f6600
        [16804.552504] RBP: ffff90dffe0d4688 R08: 0000000000000001 R09: 0000000000000000
        [16804.553136] R10: ffff90dffa4a0040 R11: 0000000000000000 R12: 000000000000002e
        [16804.553768] R13: ffff90e0247f6600 R14: 0000000000001663 R15: ffff90dff77862b8
        [16804.554399] FS:  00007f4b197ae700(0000) GS:ffff90e036a00000(0000) knlGS:0000000000000000
        [16804.555039] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        [16804.555683] CR2: 00007f4b10022000 CR3: 00000002060e2004 CR4: 00000000003606f0
        [16804.556336] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        [16804.556968] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        [16804.557583] Call Trace:
        [16804.558207]  __tree_mod_log_rewind+0xbf/0x280 [btrfs]
        [16804.558835]  btrfs_search_old_slot+0x105/0xd00 [btrfs]
        [16804.559468]  resolve_indirect_refs+0x1eb/0xc70 [btrfs]
        [16804.560087]  ? free_extent_buffer.part.19+0x5a/0xc0 [btrfs]
        [16804.560700]  find_parent_nodes+0x388/0x1120 [btrfs]
        [16804.561310]  btrfs_check_shared+0x115/0x1c0 [btrfs]
        [16804.561916]  ? extent_fiemap+0x59d/0x6d0 [btrfs]
        [16804.562518]  extent_fiemap+0x59d/0x6d0 [btrfs]
        [16804.563112]  ? __might_fault+0x11/0x90
        [16804.563706]  do_vfs_ioctl+0x45a/0x700
        [16804.564299]  ksys_ioctl+0x70/0x80
        [16804.564885]  ? trace_hardirqs_off_thunk+0x1a/0x20
        [16804.565461]  __x64_sys_ioctl+0x16/0x20
        [16804.566020]  do_syscall_64+0x5c/0x250
        [16804.566580]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
        [16804.567153] RIP: 0033:0x7f4b1ba2add7
        (...)
        [16804.568907] RSP: 002b:00007f4b197adc88 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
        [16804.569513] RAX: ffffffffffffffda RBX: 00007f4b100210d8 RCX: 00007f4b1ba2add7
        [16804.570133] RDX: 00007f4b100210d8 RSI: 00000000c020660b RDI: 0000000000000003
        [16804.570726] RBP: 000055de05a6cfe0 R08: 0000000000000000 R09: 00007f4b197add44
        [16804.571314] R10: 0000000000000000 R11: 0000000000000246 R12: 00007f4b197add48
        [16804.571905] R13: 00007f4b197add40 R14: 00007f4b100210d0 R15: 00007f4b197add50
        (...)
        [16804.575623] ---[ end trace 87317359aad4ba50 ]---
      
      Fix this by making btrfs_put_tree_mod_seq() skip deletion of elements that
      have a sequence number equals to the computed minimum sequence number, and
      not just elements with a sequence number greater then that minimum.
      
      Fixes: bd989ba3 ("Btrfs: add tree modification log functions")
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b3484913
    • Josef Bacik's avatar
      btrfs: handle ENOENT in btrfs_uuid_tree_iterate · 41c5a0b6
      Josef Bacik authored
      commit 714cd3e8 upstream.
      
      If we get an -ENOENT back from btrfs_uuid_iter_rem when iterating the
      uuid tree we'll just continue and do btrfs_next_item().  However we've
      done a btrfs_release_path() at this point and no longer have a valid
      path.  So increment the key and go back and do a normal search.
      
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      41c5a0b6
    • Josef Bacik's avatar
      btrfs: do not leak reloc root if we fail to read the fs root · f4e54ec6
      Josef Bacik authored
      commit ca1aa281 upstream.
      
      If we fail to read the fs root corresponding with a reloc root we'll
      just break out and free the reloc roots.  But we remove our current
      reloc_root from this list higher up, which means we'll leak this
      reloc_root.  Fix this by adding ourselves back to the reloc_roots list
      so we are properly cleaned up.
      
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f4e54ec6
    • Josef Bacik's avatar
      btrfs: skip log replay on orphaned roots · f5c97350
      Josef Bacik authored
      commit 9bc574de upstream.
      
      My fsstress modifications coupled with generic/475 uncovered a failure
      to mount and replay the log if we hit a orphaned root.  We do not want
      to replay the log for an orphan root, but it's completely legitimate to
      have an orphaned root with a log attached.  Fix this by simply skipping
      replaying the log.  We still need to pin it's root node so that we do
      not overwrite it while replaying other logs, as we re-read the log root
      at every stage of the replay.
      
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f5c97350
    • Josef Bacik's avatar
      btrfs: abort transaction after failed inode updates in create_subvol · 3130fcd5
      Josef Bacik authored
      commit c7e54b51 upstream.
      
      We can just abort the transaction here, and in fact do that for every
      other failure in this function except these two cases.
      
      CC: stable@vger.kernel.org # 4.4+
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3130fcd5
    • Anand Jain's avatar
      btrfs: send: remove WARN_ON for readonly mount · da9e9792
      Anand Jain authored
      commit fbd54297 upstream.
      
      We log warning if root::orphan_cleanup_state is not set to
      ORPHAN_CLEANUP_DONE in btrfs_ioctl_send(). However if the filesystem is
      mounted as readonly we skip the orphan item cleanup during the lookup
      and root::orphan_cleanup_state remains at the init state 0 instead of
      ORPHAN_CLEANUP_DONE (2). So during send in btrfs_ioctl_send() we hit the
      warning as below.
      
        WARN_ON(send_root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE);
      
      WARNING: CPU: 0 PID: 2616 at /Volumes/ws/btrfs-devel/fs/btrfs/send.c:7090 btrfs_ioctl_send+0xb2f/0x18c0 [btrfs]
      ::
      RIP: 0010:btrfs_ioctl_send+0xb2f/0x18c0 [btrfs]
      ::
      Call Trace:
      ::
      _btrfs_ioctl_send+0x7b/0x110 [btrfs]
      btrfs_ioctl+0x150a/0x2b00 [btrfs]
      ::
      do_vfs_ioctl+0xa9/0x620
      ? __fget+0xac/0xe0
      ksys_ioctl+0x60/0x90
      __x64_sys_ioctl+0x16/0x20
      do_syscall_64+0x49/0x130
      entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Reproducer:
        mkfs.btrfs -fq /dev/sdb
        mount /dev/sdb /btrfs
        btrfs subvolume create /btrfs/sv1
        btrfs subvolume snapshot -r /btrfs/sv1 /btrfs/ss1
        umount /btrfs
        mount -o ro /dev/sdb /btrfs
        btrfs send /btrfs/ss1 -f /tmp/f
      
      The warning exists because having orphan inodes could confuse send and
      cause it to fail or produce incorrect streams.  The two cases that would
      cause such send failures, which are already fixed are:
      
      1) Inodes that were unlinked - these are orphanized and remain with a
         link count of 0. These caused send operations to fail because it
         expected to always find at least one path for an inode. However this
         is no longer a problem since send is now able to deal with such
         inodes since commit 46b2f459 ("Btrfs: fix send failure when root
         has deleted files still open") and treats them as having been
         completely removed (the state after an orphan cleanup is performed).
      
      2) Inodes that were in the process of being truncated. These resulted in
         send not knowing about the truncation and potentially issue write
         operations full of zeroes for the range from the new file size to the
         old file size. This is no longer a problem because we no longer
         create orphan items for truncation since commit f7e9e8fc ("Btrfs:
         stop creating orphan items for truncate").
      
      As such before these commits, the WARN_ON here provided a clue in case
      something went wrong. Instead of being a warning against the
      root::orphan_cleanup_state value, it could have been more accurate by
      checking if there were actually any orphan items, and then issue a
      warning only if any exists, but that would be more expensive to check.
      Since orphanized inodes no longer cause problems for send, just remove
      the warning.
      Reported-by: default avatarChristoph Anton Mitterer <calestyo@scientia.net>
      Link: https://lore.kernel.org/linux-btrfs/21cb5e8d059f6e1496a903fa7bfc0a297e2f5370.camel@scientia.net/
      CC: stable@vger.kernel.org # 4.19+
      Suggested-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      da9e9792
    • Filipe Manana's avatar
      Btrfs: fix missing data checksums after replaying a log tree · 0151049a
      Filipe Manana authored
      commit 40e046ac upstream.
      
      When logging a file that has shared extents (reflinked with other files or
      with itself), we can end up logging multiple checksum items that cover
      overlapping ranges. This confuses the search for checksums at log replay
      time causing some checksums to never be added to the fs/subvolume tree.
      
      Consider the following example of a file that shares the same extent at
      offsets 0 and 256Kb:
      
         [ bytenr 13893632, offset 64Kb, len 64Kb  ]
         0                                         64Kb
      
         [ bytenr 13631488, offset 64Kb, len 192Kb ]
         64Kb                                      256Kb
      
         [ bytenr 13893632, offset 0, len 256Kb    ]
         256Kb                                     512Kb
      
      When logging the inode, at tree-log.c:copy_items(), when processing the
      file extent item at offset 0, we log a checksum item covering the range
      13959168 to 14024704, which corresponds to 13893632 + 64Kb and 13893632 +
      64Kb + 64Kb, respectively.
      
      Later when processing the extent item at offset 256K, we log the checksums
      for the range from 13893632 to 14155776 (which corresponds to 13893632 +
      256Kb). These checksums get merged with the checksum item for the range
      from 13631488 to 13893632 (13631488 + 256Kb), logged by a previous fsync.
      So after this we get the two following checksum items in the log tree:
      
         (...)
         item 6 key (EXTENT_CSUM EXTENT_CSUM 13631488) itemoff 3095 itemsize 512
                 range start 13631488 end 14155776 length 524288
         item 7 key (EXTENT_CSUM EXTENT_CSUM 13959168) itemoff 3031 itemsize 64
                 range start 13959168 end 14024704 length 65536
      
      The first one covers the range from the second one, they overlap.
      
      So far this does not cause a problem after replaying the log, because
      when replaying the file extent item for offset 256K, we copy all the
      checksums for the extent 13893632 from the log tree to the fs/subvolume
      tree, since searching for an checksum item for bytenr 13893632 leaves us
      at the first checksum item, which covers the whole range of the extent.
      
      However if we write 64Kb to file offset 256Kb for example, we will
      not be able to find and copy the checksums for the last 128Kb of the
      extent at bytenr 13893632, referenced by the file range 384Kb to 512Kb.
      
      After writing 64Kb into file offset 256Kb we get the following extent
      layout for our file:
      
         [ bytenr 13893632, offset 64K, len 64Kb   ]
         0                                         64Kb
      
         [ bytenr 13631488, offset 64Kb, len 192Kb ]
         64Kb                                      256Kb
      
         [ bytenr 14155776, offset 0, len 64Kb     ]
         256Kb                                     320Kb
      
         [ bytenr 13893632, offset 64Kb, len 192Kb ]
         320Kb                                     512Kb
      
      After fsync'ing the file, if we have a power failure and then mount
      the filesystem to replay the log, the following happens:
      
      1) When replaying the file extent item for file offset 320Kb, we
         lookup for the checksums for the extent range from 13959168
         (13893632 + 64Kb) to 14155776 (13893632 + 256Kb), through a call
         to btrfs_lookup_csums_range();
      
      2) btrfs_lookup_csums_range() finds the checksum item that starts
         precisely at offset 13959168 (item 7 in the log tree, shown before);
      
      3) However that checksum item only covers 64Kb of data, and not 192Kb
         of data;
      
      4) As a result only the checksums for the first 64Kb of data referenced
         by the file extent item are found and copied to the fs/subvolume tree.
         The remaining 128Kb of data, file range 384Kb to 512Kb, doesn't get
         the corresponding data checksums found and copied to the fs/subvolume
         tree.
      
      5) After replaying the log userspace will not be able to read the file
         range from 384Kb to 512Kb, because the checksums are missing and
         resulting in an -EIO error.
      
      The following steps reproduce this scenario:
      
        $ mkfs.btrfs -f /dev/sdc
        $ mount /dev/sdc /mnt/sdc
      
        $ xfs_io -f -c "pwrite -S 0xa3 0 256K" /mnt/sdc/foobar
        $ xfs_io -c "fsync" /mnt/sdc/foobar
        $ xfs_io -c "pwrite -S 0xc7 256K 256K" /mnt/sdc/foobar
      
        $ xfs_io -c "reflink /mnt/sdc/foobar 320K 0 64K" /mnt/sdc/foobar
        $ xfs_io -c "fsync" /mnt/sdc/foobar
      
        $ xfs_io -c "pwrite -S 0xe5 256K 64K" /mnt/sdc/foobar
        $ xfs_io -c "fsync" /mnt/sdc/foobar
      
        <power failure>
      
        $ mount /dev/sdc /mnt/sdc
        $ md5sum /mnt/sdc/foobar
        md5sum: /mnt/sdc/foobar: Input/output error
      
        $ dmesg | tail
        [165305.003464] BTRFS info (device sdc): no csum found for inode 257 start 401408
        [165305.004014] BTRFS info (device sdc): no csum found for inode 257 start 405504
        [165305.004559] BTRFS info (device sdc): no csum found for inode 257 start 409600
        [165305.005101] BTRFS info (device sdc): no csum found for inode 257 start 413696
        [165305.005627] BTRFS info (device sdc): no csum found for inode 257 start 417792
        [165305.006134] BTRFS info (device sdc): no csum found for inode 257 start 421888
        [165305.006625] BTRFS info (device sdc): no csum found for inode 257 start 425984
        [165305.007278] BTRFS info (device sdc): no csum found for inode 257 start 430080
        [165305.008248] BTRFS warning (device sdc): csum failed root 5 ino 257 off 393216 csum 0x1337385e expected csum 0x00000000 mirror 1
        [165305.009550] BTRFS warning (device sdc): csum failed root 5 ino 257 off 393216 csum 0x1337385e expected csum 0x00000000 mirror 1
      
      Fix this simply by deleting first any checksums, from the log tree, for the
      range of the extent we are logging at copy_items(). This ensures we do not
      get checksum items in the log tree that have overlapping ranges.
      
      This is a long time issue that has been present since we have the clone
      (and deduplication) ioctl, and can happen both when an extent is shared
      between different files and within the same file.
      
      A test case for fstests follows soon.
      
      CC: stable@vger.kernel.org # 4.4+
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0151049a
    • Josef Bacik's avatar
      btrfs: do not call synchronize_srcu() in inode_tree_del · 5e29efb4
      Josef Bacik authored
      commit f72ff01d upstream.
      
      Testing with the new fsstress uncovered a pretty nasty deadlock with
      lookup and snapshot deletion.
      
      Process A
      unlink
       -> final iput
         -> inode_tree_del
           -> synchronize_srcu(subvol_srcu)
      
      Process B
      btrfs_lookup  <- srcu_read_lock() acquired here
        -> btrfs_iget
          -> find inode that has I_FREEING set
            -> __wait_on_freeing_inode()
      
      We're holding the srcu_read_lock() while doing the iget in order to make
      sure our fs root doesn't go away, and then we are waiting for the inode
      to finish freeing.  However because the free'ing process is doing a
      synchronize_srcu() we deadlock.
      
      Fix this by dropping the synchronize_srcu() in inode_tree_del().  We
      don't need people to stop accessing the fs root at this point, we're
      only adding our empty root to the dead roots list.
      
      A larger much more invasive fix is forthcoming to address how we deal
      with fs roots, but this fixes the immediate problem.
      
      Fixes: 76dda93c ("Btrfs: add snapshot/subvolume destroy ioctl")
      CC: stable@vger.kernel.org # 4.4+
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5e29efb4
    • Josef Bacik's avatar
      btrfs: don't double lock the subvol_sem for rename exchange · 06f9b11e
      Josef Bacik authored
      commit 943eb3bf upstream.
      
      If we're rename exchanging two subvols we'll try to lock this lock
      twice, which is bad.  Just lock once if either of the ino's are subvols.
      
      Fixes: cdd1fedf ("btrfs: add support for RENAME_EXCHANGE and RENAME_WHITEOUT")
      CC: stable@vger.kernel.org # 4.4+
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      06f9b11e
    • Ido Schimmel's avatar
      selftests: forwarding: Delete IPv6 address at the end · 2dfbfb88
      Ido Schimmel authored
      [ Upstream commit 65cb1398 ]
      
      When creating the second host in h2_create(), two addresses are assigned
      to the interface, but only one is deleted. When running the test twice
      in a row the following error is observed:
      
      $ ./router_bridge_vlan.sh
      TEST: ping                                                          [ OK ]
      TEST: ping6                                                         [ OK ]
      TEST: vlan                                                          [ OK ]
      $ ./router_bridge_vlan.sh
      RTNETLINK answers: File exists
      TEST: ping                                                          [ OK ]
      TEST: ping6                                                         [ OK ]
      TEST: vlan                                                          [ OK ]
      
      Fix this by deleting the address during cleanup.
      
      Fixes: 5b1e7f9e ("selftests: forwarding: Test routed bridge interface")
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2dfbfb88
    • Xin Long's avatar
      sctp: fully initialize v4 addr in some functions · ce5c2032
      Xin Long authored
      [ Upstream commit b6f3320b ]
      
      Syzbot found a crash:
      
        BUG: KMSAN: uninit-value in crc32_body lib/crc32.c:112 [inline]
        BUG: KMSAN: uninit-value in crc32_le_generic lib/crc32.c:179 [inline]
        BUG: KMSAN: uninit-value in __crc32c_le_base+0x4fa/0xd30 lib/crc32.c:202
        Call Trace:
          crc32_body lib/crc32.c:112 [inline]
          crc32_le_generic lib/crc32.c:179 [inline]
          __crc32c_le_base+0x4fa/0xd30 lib/crc32.c:202
          chksum_update+0xb2/0x110 crypto/crc32c_generic.c:90
          crypto_shash_update+0x4c5/0x530 crypto/shash.c:107
          crc32c+0x150/0x220 lib/libcrc32c.c:47
          sctp_csum_update+0x89/0xa0 include/net/sctp/checksum.h:36
          __skb_checksum+0x1297/0x12a0 net/core/skbuff.c:2640
          sctp_compute_cksum include/net/sctp/checksum.h:59 [inline]
          sctp_packet_pack net/sctp/output.c:528 [inline]
          sctp_packet_transmit+0x40fb/0x4250 net/sctp/output.c:597
          sctp_outq_flush_transports net/sctp/outqueue.c:1146 [inline]
          sctp_outq_flush+0x1823/0x5d80 net/sctp/outqueue.c:1194
          sctp_outq_uncork+0xd0/0xf0 net/sctp/outqueue.c:757
          sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1781 [inline]
          sctp_side_effects net/sctp/sm_sideeffect.c:1184 [inline]
          sctp_do_sm+0x8fe1/0x9720 net/sctp/sm_sideeffect.c:1155
          sctp_primitive_REQUESTHEARTBEAT+0x175/0x1a0 net/sctp/primitive.c:185
          sctp_apply_peer_addr_params+0x212/0x1d40 net/sctp/socket.c:2433
          sctp_setsockopt_peer_addr_params net/sctp/socket.c:2686 [inline]
          sctp_setsockopt+0x189bb/0x19090 net/sctp/socket.c:4672
      
      The issue was caused by transport->ipaddr set with uninit addr param, which
      was passed by:
      
        sctp_transport_init net/sctp/transport.c:47 [inline]
        sctp_transport_new+0x248/0xa00 net/sctp/transport.c:100
        sctp_assoc_add_peer+0x5ba/0x2030 net/sctp/associola.c:611
        sctp_process_param net/sctp/sm_make_chunk.c:2524 [inline]
      
      where 'addr' is set by sctp_v4_from_addr_param(), and it doesn't initialize
      the padding of addr->v4.
      
      Later when calling sctp_make_heartbeat(), hbinfo.daddr(=transport->ipaddr)
      will become the part of skb, and the issue occurs.
      
      This patch is to fix it by initializing the padding of addr->v4 in
      sctp_v4_from_addr_param(), as well as other functions that do the similar
      thing, and these functions shouldn't trust that the caller initializes the
      memory, as Marcelo suggested.
      
      Reported-by: syzbot+6dcbfea81cd3d4dd0b02@syzkaller.appspotmail.com
      Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
      Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ce5c2032
    • Manish Chopra's avatar
      qede: Fix multicast mac configuration · 663c59ef
      Manish Chopra authored
      [ Upstream commit 0af67e49 ]
      
      Driver doesn't accommodate the configuration for max number
      of multicast mac addresses, in such particular case it leaves
      the device with improper/invalid multicast configuration state,
      causing connectivity issues (in lacp bonding like scenarios).
      Signed-off-by: default avatarManish Chopra <manishc@marvell.com>
      Signed-off-by: default avatarAriel Elior <aelior@marvell.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      663c59ef
    • Manish Chopra's avatar
      qede: Disable hardware gro when xdp prog is installed · 2db68986
      Manish Chopra authored
      [ Upstream commit 4c8dc005 ]
      
      commit 18c602de ("qede: Use NETIF_F_GRO_HW.") introduced
      a regression in driver that when xdp program is installed on
      qede device, device's aggregation feature (hardware GRO) is not
      getting disabled, which is unexpected with xdp.
      
      Fixes: 18c602de ("qede: Use NETIF_F_GRO_HW.")
      Signed-off-by: default avatarManish Chopra <manishc@marvell.com>
      Signed-off-by: default avatarAriel Elior <aelior@marvell.com>
      Reviewed-by: default avatarMichael Chan <michael.chan@broadcom.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2db68986
    • Cristian Birsan's avatar
      net: usb: lan78xx: Fix suspend/resume PHY register access error · 0c1b3970
      Cristian Birsan authored
      [ Upstream commit 20032b63 ]
      
      Lan78xx driver accesses the PHY registers through MDIO bus over USB
      connection. When performing a suspend/resume, the PHY registers can be
      accessed before the USB connection is resumed. This will generate an
      error and will prevent the device to resume correctly.
      This patch adds the dependency between the MDIO bus and USB device to
      allow correct handling of suspend/resume.
      
      Fixes: ce85e13a ("lan78xx: Update to use phylib instead of mii_if_info.")
      Signed-off-by: default avatarCristian Birsan <cristian.birsan@microchip.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0c1b3970
    • Ben Hutchings's avatar
      net: qlogic: Fix error paths in ql_alloc_large_buffers() · d56e7178
      Ben Hutchings authored
      [ Upstream commit cad46039 ]
      
      ql_alloc_large_buffers() has the usual RX buffer allocation
      loop where it allocates skbs and maps them for DMA.  It also
      treats failure as a fatal error.
      
      There are (at least) three bugs in the error paths:
      
      1. ql_free_large_buffers() assumes that the lrg_buf[] entry for the
      first buffer that couldn't be allocated will have .skb == NULL.
      But the qla_buf[] array is not zero-initialised.
      
      2. ql_free_large_buffers() DMA-unmaps all skbs in lrg_buf[].  This is
      incorrect for the last allocated skb, if DMA mapping failed.
      
      3. Commit 1acb8f2a ("net: qlogic: Fix memory leak in
      ql_alloc_large_buffers") added a direct call to dev_kfree_skb_any()
      after the skb is recorded in lrg_buf[], so ql_free_large_buffers()
      will double-free it.
      
      The bugs are somewhat inter-twined, so fix them all at once:
      
      * Clear each entry in qla_buf[] before attempting to allocate
        an skb for it.  This goes half-way to fixing bug 1.
      * Set the .skb field only after the skb is DMA-mapped.  This
        fixes the rest.
      
      Fixes: 1357bfcf ("qla3xxx: Dynamically size the rx buffer queue ...")
      Fixes: 0f8ab89e ("qla3xxx: Check return code from pci_map_single() ...")
      Fixes: 1acb8f2a ("net: qlogic: Fix memory leak in ql_alloc_large_buffers")
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d56e7178
    • Jia-Ju Bai's avatar
      net: nfc: nci: fix a possible sleep-in-atomic-context bug in nci_uart_tty_receive() · 5cc09cfd
      Jia-Ju Bai authored
      [ Upstream commit b7ac8936 ]
      
      The kernel may sleep while holding a spinlock.
      The function call path (from bottom to top) in Linux 4.19 is:
      
      net/nfc/nci/uart.c, 349:
      	nci_skb_alloc in nci_uart_default_recv_buf
      net/nfc/nci/uart.c, 255:
      	(FUNC_PTR)nci_uart_default_recv_buf in nci_uart_tty_receive
      net/nfc/nci/uart.c, 254:
      	spin_lock in nci_uart_tty_receive
      
      nci_skb_alloc(GFP_KERNEL) can sleep at runtime.
      (FUNC_PTR) means a function pointer is called.
      
      To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC for
      nci_skb_alloc().
      
      This bug is found by a static analysis tool STCheck written by myself.
      Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5cc09cfd
    • Jiangfeng Xiao's avatar
      net: hisilicon: Fix a BUG trigered by wrong bytes_compl · 821d2486
      Jiangfeng Xiao authored
      [ Upstream commit 90b3b339 ]
      
      When doing stress test, we get the following trace:
      kernel BUG at lib/dynamic_queue_limits.c:26!
      Internal error: Oops - BUG: 0 [#1] SMP ARM
      Modules linked in: hip04_eth
      CPU: 0 PID: 2003 Comm: tDblStackPcap0 Tainted: G           O L  4.4.197 #1
      Hardware name: Hisilicon A15
      task: c3637668 task.stack: de3bc000
      PC is at dql_completed+0x18/0x154
      LR is at hip04_tx_reclaim+0x110/0x174 [hip04_eth]
      pc : [<c041abfc>]    lr : [<bf0003a8>]    psr: 800f0313
      sp : de3bdc2c  ip : 00000000  fp : c020fb10
      r10: 00000000  r9 : c39b4224  r8 : 00000001
      r7 : 00000046  r6 : c39b4000  r5 : 0078f392  r4 : 0078f392
      r3 : 00000047  r2 : 00000000  r1 : 00000046  r0 : df5d5c80
      Flags: Nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
      Control: 32c5387d  Table: 1e189b80  DAC: 55555555
      Process tDblStackPcap0 (pid: 2003, stack limit = 0xde3bc190)
      Stack: (0xde3bdc2c to 0xde3be000)
      [<c041abfc>] (dql_completed) from [<bf0003a8>] (hip04_tx_reclaim+0x110/0x174 [hip04_eth])
      [<bf0003a8>] (hip04_tx_reclaim [hip04_eth]) from [<bf0012c0>] (hip04_rx_poll+0x20/0x388 [hip04_eth])
      [<bf0012c0>] (hip04_rx_poll [hip04_eth]) from [<c04c8d9c>] (net_rx_action+0x120/0x374)
      [<c04c8d9c>] (net_rx_action) from [<c021eaf4>] (__do_softirq+0x218/0x318)
      [<c021eaf4>] (__do_softirq) from [<c021eea0>] (irq_exit+0x88/0xac)
      [<c021eea0>] (irq_exit) from [<c0240130>] (msa_irq_exit+0x11c/0x1d4)
      [<c0240130>] (msa_irq_exit) from [<c0267ba8>] (__handle_domain_irq+0x110/0x148)
      [<c0267ba8>] (__handle_domain_irq) from [<c0201588>] (gic_handle_irq+0xd4/0x118)
      [<c0201588>] (gic_handle_irq) from [<c0558360>] (__irq_svc+0x40/0x58)
      Exception stack(0xde3bdde0 to 0xde3bde28)
      dde0: 00000000 00008001 c3637668 00000000 00000000 a00f0213 dd3627a0 c0af6380
      de00: c086d380 a00f0213 c0a22a50 de3bde6c 00000002 de3bde30 c0558138 c055813c
      de20: 600f0213 ffffffff
      [<c0558360>] (__irq_svc) from [<c055813c>] (_raw_spin_unlock_irqrestore+0x44/0x54)
      Kernel panic - not syncing: Fatal exception in interrupt
      
      Pre-modification code:
      int hip04_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
      {
      [...]
      [1]	priv->tx_head = TX_NEXT(tx_head);
      [2]	count++;
      [3]	netdev_sent_queue(ndev, skb->len);
      [...]
      }
      An rx interrupt occurs if hip04_mac_start_xmit just executes to the line 2,
      tx_head has been updated, but corresponding 'skb->len' has not been
      added to dql_queue.
      
      And then
      hip04_mac_interrupt->__napi_schedule->hip04_rx_poll->hip04_tx_reclaim
      
      In hip04_tx_reclaim, because tx_head has been updated,
      bytes_compl will plus an additional "skb-> len"
      which has not been added to dql_queue. And then
      trigger the BUG_ON(bytes_compl > num_queued - dql->num_completed).
      
      To solve the problem described above, we put
      "netdev_sent_queue(ndev, skb->len);"
      before
      "priv->tx_head = TX_NEXT(tx_head);"
      
      Fixes: a41ea46a ("net: hisilicon: new hip04 ethernet driver")
      Signed-off-by: default avatarJiangfeng Xiao <xiaojiangfeng@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      821d2486