1. 22 Jul, 2020 40 commits
    • Neil Armstrong's avatar
      doc: dt: bindings: usb: dwc3: Update entries for disabling SS instances in park mode · 0e27e2a5
      Neil Armstrong authored
      [ Upstream commit 3d157c28 ]
      
      This patch updates the documentation with the information related
      to the quirks that needs to be added for disabling all SuperSpeed XHCI
      instances in park mode.
      
      Cc: Dongjin Kim <tobetter@gmail.com>
      Cc: Jianxin Pan <jianxin.pan@amlogic.com>
      Cc: Thinh Nguyen <thinhn@synopsys.com>
      Cc: Jun Li <lijun.kernel@gmail.com>
      Reported-by: default avatarTim <elatllat@gmail.com>
      Signed-off-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
      Acked-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0e27e2a5
    • Chris Wulff's avatar
      ALSA: usb-audio: Create a registration quirk for Kingston HyperX Amp (0951:16d8) · 9407f45d
      Chris Wulff authored
      [ Upstream commit 55f73261 ]
      
      Create a quirk that allows special processing and/or
      skipping the call to snd_card_register.
      
      For HyperX AMP, which uses two interfaces, but only has
      a capture stream in the second, this allows the capture
      stream to merge with the first PCM.
      Signed-off-by: default avatarChris Wulff <crwulff@gmail.com>
      Link: https://lore.kernel.org/r/20200314165449.4086-3-crwulff@gmail.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9407f45d
    • Diego Elio Pettenò's avatar
      scsi: sr: remove references to BLK_DEV_SR_VENDOR, leave it enabled · d1a0c5bc
      Diego Elio Pettenò authored
      [ Upstream commit 679b2ec8 ]
      
      This kernel configuration is basically enabling/disabling sr driver quirks
      detection. While these quirks are for fairly rare devices (very old CD
      burners, and a glucometer), the additional detection of these models is a
      very minimal amount of code.
      
      The logic behind the quirks is always built into the sr driver.
      
      This also removes the config from all the defconfig files that are enabling
      this already.
      
      Link: https://lore.kernel.org/r/20200223191144.726-1-flameeyes@flameeyes.comReviewed-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarDiego Elio Pettenò <flameeyes@flameeyes.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d1a0c5bc
    • Claudiu Beznea's avatar
      ARM: at91: pm: add quirk for sam9x60's ulp1 · 919c5b8b
      Claudiu Beznea authored
      [ Upstream commit bb1a0e87 ]
      
      On SAM9X60 2 nop operations has to be introduced after setting
      WAITMODE bit in CKGR_MOR.
      Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea@microchip.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Link: https://lore.kernel.org/r/1579522208-19523-9-git-send-email-claudiu.beznea@microchip.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      919c5b8b
    • Hans de Goede's avatar
      HID: quirks: Remove ITE 8595 entry from hid_have_special_driver · 1a7a00bf
      Hans de Goede authored
      [ Upstream commit 3045696d ]
      
      The ITE 8595 chip used in various 2-in-1 keyboard docks works fine with
      the hid-generic driver (minus the RF_KILL key) and also keeps working fine
      when swapping drivers, so there is no need to have it in the
      hid_have_special_driver list.
      
      Note the other 2 USB ids in hid-ite.c were never added to
      hid_have_special_driver.
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1a7a00bf
    • Russell King's avatar
      net: sfp: add some quirks for GPON modules · d3205c26
      Russell King authored
      [ Upstream commit b0eae33b ]
      
      Marc Micalizzi reports that Huawei MA5671A and Alcatel/Lucent G-010S-P
      modules are capable of 2500base-X, but incorrectly report their
      capabilities in the EEPROM.  It seems rather common that GPON modules
      mis-report.
      
      Let's fix these modules by adding some quirks.
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d3205c26
    • Russell King's avatar
      net: sfp: add support for module quirks · 6772d329
      Russell King authored
      [ Upstream commit b34bb2cb ]
      
      Add support for applying module quirks to the list of supported
      ethtool link modes.
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6772d329
    • Sasha Levin's avatar
      Revert "usb/ehci-platform: Set PM runtime as active on resume" · 9b83c99f
      Sasha Levin authored
      This reverts commit 71f660a1.
      
      Eugeniu Rosca writes:
      
      On Thu, Jul 09, 2020 at 09:00:23AM +0200, Eugeniu Rosca wrote:
      >After integrating v4.14.186 commit 5410d158ca2a50 ("usb/ehci-platform:
      >Set PM runtime as active on resume") into downstream v4.14.x, we started
      >to consistently experience below panic [1] on every second s2ram of
      >R-Car H3 Salvator-X Renesas reference board.
      >
      >After some investigations, we concluded the following:
      > - the issue does not exist in vanilla v5.8-rc4+
      > - [bisecting shows that] the panic on v4.14.186 is caused by the lack
      >   of v5.6-rc1 commit 987351e1 ("phy: core: Add consumer device
      >   link support"). Getting evidence for that is easy. Reverting
      >   987351e1 in vanilla leads to a similar backtrace [2].
      >
      >Questions:
      > - Backporting 987351e1 ("phy: core: Add consumer device
      >   link support") to v4.14.187 looks challenging enough, so probably not
      >   worth it. Anybody to contradict this?
      > - Assuming no plans to backport the missing mainline commit to v4.14.x,
      >   should the following three v4.14.186 commits be reverted on v4.14.x?
      >   * baef809ea497a4 ("usb/ohci-platform: Fix a warning when hibernating")
      >   * 9f33eff4958885 ("usb/xhci-plat: Set PM runtime as active on resume")
      >   * 5410d158ca2a50 ("usb/ehci-platform: Set PM runtime as active on resume")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9b83c99f
    • Sasha Levin's avatar
      Revert "usb/xhci-plat: Set PM runtime as active on resume" · 7c201182
      Sasha Levin authored
      This reverts commit 661f5686.
      
      Eugeniu Rosca writes:
      
      On Thu, Jul 09, 2020 at 09:00:23AM +0200, Eugeniu Rosca wrote:
      >After integrating v4.14.186 commit 5410d158ca2a50 ("usb/ehci-platform:
      >Set PM runtime as active on resume") into downstream v4.14.x, we started
      >to consistently experience below panic [1] on every second s2ram of
      >R-Car H3 Salvator-X Renesas reference board.
      >
      >After some investigations, we concluded the following:
      > - the issue does not exist in vanilla v5.8-rc4+
      > - [bisecting shows that] the panic on v4.14.186 is caused by the lack
      >   of v5.6-rc1 commit 987351e1 ("phy: core: Add consumer device
      >   link support"). Getting evidence for that is easy. Reverting
      >   987351e1 in vanilla leads to a similar backtrace [2].
      >
      >Questions:
      > - Backporting 987351e1 ("phy: core: Add consumer device
      >   link support") to v4.14.187 looks challenging enough, so probably not
      >   worth it. Anybody to contradict this?
      > - Assuming no plans to backport the missing mainline commit to v4.14.x,
      >   should the following three v4.14.186 commits be reverted on v4.14.x?
      >   * baef809ea497a4 ("usb/ohci-platform: Fix a warning when hibernating")
      >   * 9f33eff4958885 ("usb/xhci-plat: Set PM runtime as active on resume")
      >   * 5410d158ca2a50 ("usb/ehci-platform: Set PM runtime as active on resume"
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7c201182
    • Sasha Levin's avatar
      Revert "usb/ohci-platform: Fix a warning when hibernating" · c0e76f2b
      Sasha Levin authored
      This reverts commit c83258a7.
      
      Eugeniu Rosca writes:
      
      On Thu, Jul 09, 2020 at 09:00:23AM +0200, Eugeniu Rosca wrote:
      >After integrating v4.14.186 commit 5410d158ca2a50 ("usb/ehci-platform:
      >Set PM runtime as active on resume") into downstream v4.14.x, we started
      >to consistently experience below panic [1] on every second s2ram of
      >R-Car H3 Salvator-X Renesas reference board.
      >
      >After some investigations, we concluded the following:
      > - the issue does not exist in vanilla v5.8-rc4+
      > - [bisecting shows that] the panic on v4.14.186 is caused by the lack
      >   of v5.6-rc1 commit 987351e1 ("phy: core: Add consumer device
      >   link support"). Getting evidence for that is easy. Reverting
      >   987351e1 in vanilla leads to a similar backtrace [2].
      >
      >Questions:
      > - Backporting 987351e1 ("phy: core: Add consumer device
      >   link support") to v4.14.187 looks challenging enough, so probably not
      >   worth it. Anybody to contradict this?
      > - Assuming no plans to backport the missing mainline commit to v4.14.x,
      >   should the following three v4.14.186 commits be reverted on v4.14.x?
      >   * baef809ea497a4 ("usb/ohci-platform: Fix a warning when hibernating")
      >   * 9f33eff4958885 ("usb/xhci-plat: Set PM runtime as active on resume")
      >   * 5410d158ca2a50 ("usb/ehci-platform: Set PM runtime as active on resume")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c0e76f2b
    • Florian Fainelli's avatar
      of: of_mdio: Correct loop scanning logic · e4c6078f
      Florian Fainelli authored
      [ Upstream commit 5a8d7f12 ]
      
      Commit 209c65b6 ("drivers/of/of_mdio.c:fix of_mdiobus_register()")
      introduced a break of the loop on the premise that a successful
      registration should exit the loop. The premise is correct but not to
      code, because rc && rc != -ENODEV is just a special error condition,
      that means we would exit the loop even with rc == -ENODEV which is
      absolutely not correct since this is the error code to indicate to the
      MDIO bus layer that scanning should continue.
      
      Fix this by explicitly checking for rc = 0 as the only valid condition
      to break out of the loop.
      
      Fixes: 209c65b6 ("drivers/of/of_mdio.c:fix of_mdiobus_register()")
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e4c6078f
    • Florian Fainelli's avatar
      net: dsa: bcm_sf2: Fix node reference count · de817599
      Florian Fainelli authored
      [ Upstream commit 8dbe4c5d ]
      
      of_find_node_by_name() will do an of_node_put() on the "from" argument.
      With CONFIG_OF_DYNAMIC enabled which checks for device_node reference
      counts, we would be getting a warning like this:
      
      [    6.347230] refcount_t: increment on 0; use-after-free.
      [    6.352498] WARNING: CPU: 3 PID: 77 at lib/refcount.c:156
      refcount_inc_checked+0x38/0x44
      [    6.360601] Modules linked in:
      [    6.363661] CPU: 3 PID: 77 Comm: kworker/3:1 Tainted: G        W
      5.4.46-gb78b3e9956e6 #13
      [    6.372546] Hardware name: BCM97278SV (DT)
      [    6.376649] Workqueue: events deferred_probe_work_func
      [    6.381796] pstate: 60000005 (nZCv daif -PAN -UAO)
      [    6.386595] pc : refcount_inc_checked+0x38/0x44
      [    6.391133] lr : refcount_inc_checked+0x38/0x44
      ...
      [    6.478791] Call trace:
      [    6.481243]  refcount_inc_checked+0x38/0x44
      [    6.485433]  kobject_get+0x3c/0x4c
      [    6.488840]  of_node_get+0x24/0x34
      [    6.492247]  of_irq_find_parent+0x3c/0xe0
      [    6.496263]  of_irq_parse_one+0xe4/0x1d0
      [    6.500191]  irq_of_parse_and_map+0x44/0x84
      [    6.504381]  bcm_sf2_sw_probe+0x22c/0x844
      [    6.508397]  platform_drv_probe+0x58/0xa8
      [    6.512413]  really_probe+0x238/0x3fc
      [    6.516081]  driver_probe_device+0x11c/0x12c
      [    6.520358]  __device_attach_driver+0xa8/0x100
      [    6.524808]  bus_for_each_drv+0xb4/0xd0
      [    6.528650]  __device_attach+0xd0/0x164
      [    6.532493]  device_initial_probe+0x24/0x30
      [    6.536682]  bus_probe_device+0x38/0x98
      [    6.540524]  deferred_probe_work_func+0xa8/0xd4
      [    6.545061]  process_one_work+0x178/0x288
      [    6.549078]  process_scheduled_works+0x44/0x48
      [    6.553529]  worker_thread+0x218/0x270
      [    6.557285]  kthread+0xdc/0xe4
      [    6.560344]  ret_from_fork+0x10/0x18
      [    6.563925] ---[ end trace 68f65caf69bb152a ]---
      
      Fix this by adding a of_node_get() to increment the reference count
      prior to the call.
      
      Fixes: afa3b592 ("net: dsa: bcm_sf2: Ensure correct sub-node is parsed")
      Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      de817599
    • Krzysztof Kozlowski's avatar
      spi: spi-fsl-dspi: Fix lockup if device is shutdown during SPI transfer · b34a6fd4
      Krzysztof Kozlowski authored
      [ Upstream commit 3c525b69 ]
      
      During shutdown, the driver should unregister the SPI controller
      and stop the hardware.  Otherwise the dspi_transfer_one_message() could
      wait on completion infinitely.
      
      Additionally, calling spi_unregister_controller() first in device
      shutdown reverse-matches the probe function, where SPI controller is
      registered at the end.
      
      Fixes: dc234825 ("spi: spi-fsl-dspi: Adding shutdown hook")
      Reported-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
      Tested-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200622110543.5035-2-krzk@kernel.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b34a6fd4
    • Angelo Dureghello's avatar
      spi: fix initial SPI_SR value in spi-fsl-dspi · 12b63332
      Angelo Dureghello authored
      [ Upstream commit aa54c1c9 ]
      
      On ColdFire mcf54418, using DSPI_DMA_MODE mode, spi transfers
      at first boot stage are not succeding:
      
      m25p80 spi0.1: unrecognized JEDEC id bytes: 00, 00, 00
      
      The reason is the SPI_SR initial value set by the driver, that
      is not clearing (not setting to 1) the RF_DF flag. After a tour
      on the dspi hw modules that use this driver(Vybrid, ColdFire and
      ls1021a) a better init value for SR register has been set.
      Signed-off-by: default avatarAngelo Dureghello <angelo@sysam.it>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      12b63332
    • Jonathan Cameron's avatar
      iio:health:afe4403 Fix timestamp alignment and prevent data leak. · 1e6734e7
      Jonathan Cameron authored
      commit 3f9c6d38 upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses a 32 byte array of smaller elements on the stack.
      As Lars also noted this anti pattern can involve a leak of data to
      userspace and that indeed can happen here.  We close both issues by
      moving to a suitable structure in the iio_priv() data with alignment
      explicitly requested.  This data is allocated with kzalloc so no
      data can leak appart from previous readings.
      
      Fixes: eec96d1e ("iio: health: Add driver for the TI AFE4403 heart monitor")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Acked-by: default avatarAndrew F. Davis <afd@ti.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1e6734e7
    • Jonathan Cameron's avatar
      iio:pressure:ms5611 Fix buffer element alignment · dcf600cf
      Jonathan Cameron authored
      commit 8db4afe1 upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses an array of smaller elements on the stack.
      Here there is no data leak possibility so use an explicit structure
      on the stack to ensure alignment and nice readable fashion.
      
      The forced alignment of ts isn't strictly necessary in this driver
      as the padding will be correct anyway (there isn't any).  However
      it is probably less fragile to have it there and it acts as
      documentation of the requirement.
      
      Fixes: 713bbb4e ("iio: pressure: ms5611: Add triggered buffer support")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Acked-by: default avatarTomasz Duszynski <tomasz.duszynski@octakon.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dcf600cf
    • Jonathan Cameron's avatar
      iio:humidity:hts221 Fix alignment and data leak issues · 30bdaafb
      Jonathan Cameron authored
      commit 5c49056a upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses an array of smaller elements on the stack.
      As Lars also noted this anti pattern can involve a leak of data to
      userspace and that indeed can happen here.  We close both issues by
      moving to a suitable structure in the iio_priv() data.
      This data is allocated with kzalloc so no data can leak
      apart from previous readings.
      
      Explicit alignment of ts needed to ensure consistent padding
      on all architectures (particularly x86_32 with it's 4 byte alignment
      of s64)
      
      Fixes: e4a70e3e ("iio: humidity: add support to hts221 rh/temp combo device")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Acked-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      30bdaafb
    • Navid Emamdoost's avatar
      iio: pressure: zpa2326: handle pm_runtime_get_sync failure · 24c26e80
      Navid Emamdoost authored
      commit d88de040 upstream.
      
      Calling pm_runtime_get_sync increments the counter even in case of
      failure, causing incorrect ref count. Call pm_runtime_put if
      pm_runtime_get_sync fails.
      Signed-off-by: default avatarNavid Emamdoost <navid.emamdoost@gmail.com>
      Fixes: 03b262f2 ("iio:pressure: initial zpa2326 barometer support")
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      24c26e80
    • Chuhong Yuan's avatar
      iio: mma8452: Add missed iio_device_unregister() call in mma8452_probe() · 6c438c81
      Chuhong Yuan authored
      commit d7369ae1 upstream.
      
      The function iio_device_register() was called in mma8452_probe().
      But the function iio_device_unregister() was not called after
      a call of the function mma8452_set_freefall_mode() failed.
      Thus add the missed function call for one error case.
      
      Fixes: 1a965d40 ("drivers:iio:accel:mma8452: added cleanup provision in case of failure.")
      Signed-off-by: default avatarChuhong Yuan <hslester96@gmail.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6c438c81
    • Dinghao Liu's avatar
      iio: magnetometer: ak8974: Fix runtime PM imbalance on error · 8e54c21c
      Dinghao Liu authored
      commit 0187294d upstream.
      
      When devm_regmap_init_i2c() returns an error code, a pairing
      runtime PM usage counter decrement is needed to keep the
      counter balanced. For error paths after ak8974_set_power(),
      ak8974_detect() and ak8974_reset(), things are the same.
      
      However, When iio_triggered_buffer_setup() returns an error
      code, there will be two PM usgae counter decrements.
      Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
      Fixes: 7c94a8b2 ("iio: magn: add a driver for AK8974")
      Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8e54c21c
    • Jonathan Cameron's avatar
      iio:humidity:hdc100x Fix alignment and data leak issues · 3fced142
      Jonathan Cameron authored
      commit ea5e7a7b upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses an array of smaller elements on the stack.
      As Lars also noted this anti pattern can involve a leak of data to
      userspace and that indeed can happen here.  We close both issues by
      moving to a suitable structure in the iio_priv() data.
      This data is allocated with kzalloc so no data can leak apart
      from previous readings.
      
      Fixes: 16bf793f ("iio: humidity: hdc100x: add triggered buffer support for HDC100X")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Acked-by: default avatarMatt Ranostay <matt.ranostay@konsulko.com>
      Cc: Alison Schofield <amsfield22@gmail.com>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3fced142
    • Jonathan Cameron's avatar
      iio:magnetometer:ak8974: Fix alignment and data leak issues · f2117df6
      Jonathan Cameron authored
      commit 838e00b1 upstream.
      
      One of a class of bugs pointed out by Lars in a recent review.
      iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
      to the size of the timestamp (8 bytes).  This is not guaranteed in
      this driver which uses an array of smaller elements on the stack.
      As Lars also noted this anti pattern can involve a leak of data to
      userspace and that indeed can happen here.  We close both issues by
      moving to a suitable structure in the iio_priv() data.
      
      This data is allocated with kzalloc so no data can leak appart from
      previous readings.
      
      Fixes: 7c94a8b2 ("iio: magn: add a driver for AK8974")
      Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f2117df6
    • Ard Biesheuvel's avatar
      arm64/alternatives: don't patch up internal branches · 47fed9aa
      Ard Biesheuvel authored
      [ Upstream commit 5679b281 ]
      
      Commit f7b93d42 ("arm64/alternatives: use subsections for replacement
      sequences") moved the alternatives replacement sequences into subsections,
      in order to keep the as close as possible to the code that they replace.
      
      Unfortunately, this broke the logic in branch_insn_requires_update,
      which assumed that any branch into kernel executable code was a branch
      that required updating, which is no longer the case now that the code
      sequences that are patched in are in the same section as the patch site
      itself.
      
      So the only way to discriminate branches that require updating and ones
      that don't is to check whether the branch targets the replacement sequence
      itself, and so we can drop the call to kernel_text_address() entirely.
      
      Fixes: f7b93d42 ("arm64/alternatives: use subsections for replacement sequences")
      Reported-by: default avatarAlexandru Elisei <alexandru.elisei@arm.com>
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Tested-by: default avatarAlexandru Elisei <alexandru.elisei@arm.com>
      Link: https://lore.kernel.org/r/20200709125953.30918-1-ardb@kernel.orgSigned-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      47fed9aa
    • Andy Shevchenko's avatar
      i2c: eg20t: Load module automatically if ID matches · 206c9c97
      Andy Shevchenko authored
      [ Upstream commit 5f90786b ]
      
      The driver can't be loaded automatically because it misses
      module alias to be provided. Add corresponding MODULE_DEVICE_TABLE()
      call to the driver.
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      206c9c97
    • Bob Peterson's avatar
      gfs2: read-only mounts should grab the sd_freeze_gl glock · f8bc4ff1
      Bob Peterson authored
      [ Upstream commit b780cc61 ]
      
      Before this patch, only read-write mounts would grab the freeze
      glock in read-only mode, as part of gfs2_make_fs_rw. So the freeze
      glock was never initialized. That meant requests to freeze, which
      request the glock in EX, were granted without any state transition.
      That meant you could mount a gfs2 file system, which is currently
      frozen on a different cluster node, in read-only mode.
      
      This patch makes read-only mounts lock the freeze glock in SH mode,
      which will block for file systems that are frozen on another node.
      Signed-off-by: default avatarBob Peterson <rpeterso@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f8bc4ff1
    • Vasily Averin's avatar
      tpm_tis: extra chip->ops check on error path in tpm_tis_core_init · 01729f8d
      Vasily Averin authored
      [ Upstream commit ccf6fb85 ]
      
      Found by smatch:
      drivers/char/tpm/tpm_tis_core.c:1088 tpm_tis_core_init() warn:
       variable dereferenced before check 'chip->ops' (see line 979)
      
      'chip->ops' is assigned in the beginning of function
      in tpmm_chip_alloc->tpm_chip_alloc
      and is used before first possible goto to error path.
      Signed-off-by: default avatarVasily Averin <vvs@virtuozzo.com>
      Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      01729f8d
    • Ard Biesheuvel's avatar
      arm64/alternatives: use subsections for replacement sequences · d6d91458
      Ard Biesheuvel authored
      [ Upstream commit f7b93d42 ]
      
      When building very large kernels, the logic that emits replacement
      sequences for alternatives fails when relative branches are present
      in the code that is emitted into the .altinstr_replacement section
      and patched in at the original site and fixed up. The reason is that
      the linker will insert veneers if relative branches go out of range,
      and due to the relative distance of the .altinstr_replacement from
      the .text section where its branch targets usually live, veneers
      may be emitted at the end of the .altinstr_replacement section, with
      the relative branches in the sequence pointed at the veneers instead
      of the actual target.
      
      The alternatives patching logic will attempt to fix up the branch to
      point to its original target, which will be the veneer in this case,
      but given that the patch site is likely to be far away as well, it
      will be out of range and so patching will fail. There are other cases
      where these veneers are problematic, e.g., when the target of the
      branch is in .text while the patch site is in .init.text, in which
      case putting the replacement sequence inside .text may not help either.
      
      So let's use subsections to emit the replacement code as closely as
      possible to the patch site, to ensure that veneers are only likely to
      be emitted if they are required at the patch site as well, in which
      case they will be in range for the replacement sequence both before
      and after it is transported to the patch site.
      
      This will prevent alternative sequences in non-init code from being
      released from memory after boot, but this is tolerable given that the
      entire section is only 512 KB on an allyesconfig build (which weighs in
      at 500+ MB for the entire Image). Also, note that modules today carry
      the replacement sequences in non-init sections as well, and any of
      those that target init code will be emitted into init sections after
      this change.
      
      This fixes an early crash when booting an allyesconfig kernel on a
      system where any of the alternatives sequences containing relative
      branches are activated at boot (e.g., ARM64_HAS_PAN on TX2)
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
      Cc: James Morse <james.morse@arm.com>
      Cc: Andre Przywara <andre.przywara@arm.com>
      Cc: Dave P Martin <dave.martin@arm.com>
      Link: https://lore.kernel.org/r/20200630081921.13443-1-ardb@kernel.orgSigned-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d6d91458
    • Angelo Dureghello's avatar
      m68k: mm: fix node memblock init · c24fb4f5
      Angelo Dureghello authored
      [ Upstream commit c43e5579 ]
      
      After pulling 5.7.0 (linux-next merge), mcf5441x mmu boot was
      hanging silently.
      
      memblock_add() seems not appropriate, since using MAX_NUMNODES
      as node id, while memblock_add_node() sets up memory for node id 0.
      Signed-off-by: default avatarAngelo Dureghello <angelo.dureghello@timesys.com>
      Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
      Signed-off-by: default avatarGreg Ungerer <gerg@linux-m68k.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c24fb4f5
    • Mike Rapoport's avatar
      m68k: nommu: register start of the memory with memblock · 0ea1f064
      Mike Rapoport authored
      [ Upstream commit d63bd8c8 ]
      
      The m68k nommu setup code didn't register the beginning of the physical
      memory with memblock because it was anyway occupied by the kernel. However,
      commit fa3354e4 ("mm: free_area_init: use maximal zone PFNs rather than
      zone sizes") changed zones initialization to use memblock.memory to detect
      the zone extents and this caused inconsistency between zone PFNs and the
      actual PFNs:
      
      BUG: Bad page state in process swapper  pfn:20165
      page:41fe0ca0 refcount:0 mapcount:1 mapping:00000000 index:0x0 flags: 0x0()
      raw: 00000000 00000100 00000122 00000000 00000000 00000000 00000000 00000000
      page dumped because: nonzero mapcount
      CPU: 0 PID: 1 Comm: swapper Not tainted 5.8.0-rc1-00001-g3a38f8a60c65-dirty #1
      Stack from 404c9ebc:
              404c9ebc 4029ab28 4029ab28 40088470 41fe0ca0 40299e21 40299df1 404ba2a4
              00020165 00000000 41fd2c10 402c7ba0 41fd2c04 40088504 41fe0ca0 40299e21
              00000000 40088a12 41fe0ca0 41fe0ca4 0000020a 00000000 00000001 402ca000
              00000000 41fe0ca0 41fd2c10 41fd2c10 00000000 00000000 402b2388 00000001
              400a0934 40091056 404c9f44 404c9f44 40088db4 402c7ba0 00000001 41fd2c04
              41fe0ca0 41fd2000 41fe0ca0 40089e02 4026ecf4 40089e4e 41fe0ca0 ffffffff
      Call Trace:
              [<40088470>] 0x40088470
       [<40088504>] 0x40088504
       [<40088a12>] 0x40088a12
       [<402ca000>] 0x402ca000
       [<400a0934>] 0x400a0934
      
      Adjust the memory registration with memblock to include the beginning of
      the physical memory and make sure that the area occupied by the kernel is
      marked as reserved.
      Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
      Signed-off-by: default avatarGreg Ungerer <gerg@linux-m68k.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0ea1f064
    • Navid Emamdoost's avatar
      drm/exynos: fix ref count leak in mic_pre_enable · b2cde935
      Navid Emamdoost authored
      [ Upstream commit d4f5a095 ]
      
      in mic_pre_enable, pm_runtime_get_sync is called which
      increments the counter even in case of failure, leading to incorrect
      ref count. In case of failure, decrement the ref count before returning.
      Signed-off-by: default avatarNavid Emamdoost <navid.emamdoost@gmail.com>
      Signed-off-by: default avatarInki Dae <inki.dae@samsung.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b2cde935
    • Bernard Zhao's avatar
      drm/msm: fix potential memleak in error branch · bf59aa00
      Bernard Zhao authored
      [ Upstream commit 177d3819 ]
      
      In function msm_submitqueue_create, the queue is a local
      variable, in return -EINVAL branch, queue didn`t add to ctx`s
      list yet, and also didn`t kfree, this maybe bring in potential
      memleak.
      Signed-off-by: default avatarBernard Zhao <bernard@vivo.com>
      [trivial commit msg fixup]
      Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bf59aa00
    • Toke Høiland-Jørgensen's avatar
      vlan: consolidate VLAN parsing code and limit max parsing depth · d4d0e6c0
      Toke Høiland-Jørgensen authored
      [ Upstream commit 469acedd ]
      
      Toshiaki pointed out that we now have two very similar functions to extract
      the L3 protocol number in the presence of VLAN tags. And Daniel pointed out
      that the unbounded parsing loop makes it possible for maliciously crafted
      packets to loop through potentially hundreds of tags.
      
      Fix both of these issues by consolidating the two parsing functions and
      limiting the VLAN tag parsing to a max depth of 8 tags. As part of this,
      switch over __vlan_get_protocol() to use skb_header_pointer() instead of
      pskb_may_pull(), to avoid the possible side effects of the latter and keep
      the skb pointer 'const' through all the parsing functions.
      
      v2:
      - Use limit of 8 tags instead of 32 (matching XMIT_RECURSION_LIMIT)
      Reported-by: default avatarToshiaki Makita <toshiaki.makita1@gmail.com>
      Reported-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Fixes: d7bf2ebe ("sched: consistently handle layer3 header accesses in the presence of VLANs")
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d4d0e6c0
    • Toke Høiland-Jørgensen's avatar
      sched: consistently handle layer3 header accesses in the presence of VLANs · 9fd235ff
      Toke Høiland-Jørgensen authored
      [ Upstream commit d7bf2ebe ]
      
      There are a couple of places in net/sched/ that check skb->protocol and act
      on the value there. However, in the presence of VLAN tags, the value stored
      in skb->protocol can be inconsistent based on whether VLAN acceleration is
      enabled. The commit quoted in the Fixes tag below fixed the users of
      skb->protocol to use a helper that will always see the VLAN ethertype.
      
      However, most of the callers don't actually handle the VLAN ethertype, but
      expect to find the IP header type in the protocol field. This means that
      things like changing the ECN field, or parsing diffserv values, stops
      working if there's a VLAN tag, or if there are multiple nested VLAN
      tags (QinQ).
      
      To fix this, change the helper to take an argument that indicates whether
      the caller wants to skip the VLAN tags or not. When skipping VLAN tags, we
      make sure to skip all of them, so behaviour is consistent even in QinQ
      mode.
      
      To make the helper usable from the ECN code, move it to if_vlan.h instead
      of pkt_sched.h.
      
      v3:
      - Remove empty lines
      - Move vlan variable definitions inside loop in skb_protocol()
      - Also use skb_protocol() helper in IP{,6}_ECN_decapsulate() and
        bpf_skb_ecn_set_ce()
      
      v2:
      - Use eth_type_vlan() helper in skb_protocol()
      - Also fix code that reads skb->protocol directly
      - Change a couple of 'if/else if' statements to switch constructs to avoid
        calling the helper twice
      Reported-by: default avatarIlya Ponetayev <i.ponetaev@ndmsystems.com>
      Fixes: d8b9605d ("net: sched: fix skb->protocol use in case of accelerated vlan path")
      Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9fd235ff
    • Cong Wang's avatar
      cgroup: Fix sock_cgroup_data on big-endian. · 6d584c6e
      Cong Wang authored
      [ Upstream commit 14b032b8 ]
      
      In order for no_refcnt and is_data to be the lowest order two
      bits in the 'val' we have to pad out the bitfield of the u8.
      
      Fixes: ad0f75e5 ("cgroup: fix cgroup_sk_alloc() for sk_clone_lock()")
      Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6d584c6e
    • Cong Wang's avatar
      cgroup: fix cgroup_sk_alloc() for sk_clone_lock() · 0505cc4c
      Cong Wang authored
      [ Upstream commit ad0f75e5 ]
      
      When we clone a socket in sk_clone_lock(), its sk_cgrp_data is
      copied, so the cgroup refcnt must be taken too. And, unlike the
      sk_alloc() path, sock_update_netprioidx() is not called here.
      Therefore, it is safe and necessary to grab the cgroup refcnt
      even when cgroup_sk_alloc is disabled.
      
      sk_clone_lock() is in BH context anyway, the in_interrupt()
      would terminate this function if called there. And for sk_alloc()
      skcd->val is always zero. So it's safe to factor out the code
      to make it more readable.
      
      The global variable 'cgroup_sk_alloc_disabled' is used to determine
      whether to take these reference counts. It is impossible to make
      the reference counting correct unless we save this bit of information
      in skcd->val. So, add a new bit there to record whether the socket
      has already taken the reference counts. This obviously relies on
      kmalloc() to align cgroup pointers to at least 4 bytes,
      ARCH_KMALLOC_MINALIGN is certainly larger than that.
      
      This bug seems to be introduced since the beginning, commit
      d979a39d ("cgroup: duplicate cgroup reference when cloning sockets")
      tried to fix it but not compeletely. It seems not easy to trigger until
      the recent commit 090e28b2
      ("netprio_cgroup: Fix unlimited memory leak of v2 cgroups") was merged.
      
      Fixes: bd1060a1 ("sock, cgroup: add sock->sk_cgroup")
      Reported-by: default avatarCameron Berkenpas <cam@neo-zeon.de>
      Reported-by: default avatarPeter Geis <pgwipeout@gmail.com>
      Reported-by: default avatarLu Fengqi <lufq.fnst@cn.fujitsu.com>
      Reported-by: default avatarDaniël Sonck <dsonck92@gmail.com>
      Reported-by: default avatarZhang Qiang <qiang.zhang@windriver.com>
      Tested-by: default avatarCameron Berkenpas <cam@neo-zeon.de>
      Tested-by: default avatarPeter Geis <pgwipeout@gmail.com>
      Tested-by: default avatarThomas Lamprecht <t.lamprecht@proxmox.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Roman Gushchin <guro@fb.com>
      Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0505cc4c
    • Eric Dumazet's avatar
      tcp: md5: allow changing MD5 keys in all socket states · 81b65501
      Eric Dumazet authored
      [ Upstream commit 1ca0fafd ]
      
      This essentially reverts commit 72123032 ("tcp: md5: reject TCP_MD5SIG
      or TCP_MD5SIG_EXT on established sockets")
      
      Mathieu reported that many vendors BGP implementations can
      actually switch TCP MD5 on established flows.
      
      Quoting Mathieu :
         Here is a list of a few network vendors along with their behavior
         with respect to TCP MD5:
      
         - Cisco: Allows for password to be changed, but within the hold-down
           timer (~180 seconds).
         - Juniper: When password is initially set on active connection it will
           reset, but after that any subsequent password changes no network
           resets.
         - Nokia: No notes on if they flap the tcp connection or not.
         - Ericsson/RedBack: Allows for 2 password (old/new) to co-exist until
           both sides are ok with new passwords.
         - Meta-Switch: Expects the password to be set before a connection is
           attempted, but no further info on whether they reset the TCP
           connection on a change.
         - Avaya: Disable the neighbor, then set password, then re-enable.
         - Zebos: Would normally allow the change when socket connected.
      
      We can revert my prior change because commit 9424e2e7 ("tcp: md5: fix potential
      overestimation of TCP option space") removed the leak of 4 kernel bytes to
      the wire that was the main reason for my patch.
      
      While doing my investigations, I found a bug when a MD5 key is changed, leading
      to these commits that stable teams want to consider before backporting this revert :
      
       Commit 6a2febec ("tcp: md5: add missing memory barriers in tcp_md5_do_add()/tcp_md5_hash_key()")
       Commit e6ced831 ("tcp: md5: refine tcp_md5_do_add()/tcp_md5_hash_key() barriers")
      
      Fixes: 72123032 "tcp: md5: reject TCP_MD5SIG or TCP_MD5SIG_EXT on established sockets"
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      81b65501
    • Eric Dumazet's avatar
      tcp: md5: refine tcp_md5_do_add()/tcp_md5_hash_key() barriers · 797a053e
      Eric Dumazet authored
      [ Upstream commit e6ced831 ]
      
      My prior fix went a bit too far, according to Herbert and Mathieu.
      
      Since we accept that concurrent TCP MD5 lookups might see inconsistent
      keys, we can use READ_ONCE()/WRITE_ONCE() instead of smp_rmb()/smp_wmb()
      
      Clearing all key->key[] is needed to avoid possible KMSAN reports,
      if key->keylen is increased. Since tcp_md5_do_add() is not fast path,
      using __GFP_ZERO to clear all struct tcp_md5sig_key is simpler.
      
      data_race() was added in linux-5.8 and will prevent KCSAN reports,
      this can safely be removed in stable backports, if data_race() is
      not yet backported.
      
      v2: use data_race() both in tcp_md5_hash_key() and tcp_md5_do_add()
      
      Fixes: 6a2febec ("tcp: md5: add missing memory barriers in tcp_md5_do_add()/tcp_md5_hash_key()")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Marco Elver <elver@google.com>
      Reviewed-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      797a053e
    • Eric Dumazet's avatar
      tcp: md5: do not send silly options in SYNCOOKIES · c83943a7
      Eric Dumazet authored
      [ Upstream commit e114e1e8 ]
      
      Whenever cookie_init_timestamp() has been used to encode
      ECN,SACK,WSCALE options, we can not remove the TS option in the SYNACK.
      
      Otherwise, tcp_synack_options() will still advertize options like WSCALE
      that we can not deduce later when receiving the packet from the client
      to complete 3WHS.
      
      Note that modern linux TCP stacks wont use MD5+TS+SACK in a SYN packet,
      but we can not know for sure that all TCP stacks have the same logic.
      
      Before the fix a tcpdump would exhibit this wrong exchange :
      
      10:12:15.464591 IP C > S: Flags [S], seq 4202415601, win 65535, options [nop,nop,md5 valid,mss 1400,sackOK,TS val 456965269 ecr 0,nop,wscale 8], length 0
      10:12:15.464602 IP S > C: Flags [S.], seq 253516766, ack 4202415602, win 65535, options [nop,nop,md5 valid,mss 1400,nop,nop,sackOK,nop,wscale 8], length 0
      10:12:15.464611 IP C > S: Flags [.], ack 1, win 256, options [nop,nop,md5 valid], length 0
      10:12:15.464678 IP C > S: Flags [P.], seq 1:13, ack 1, win 256, options [nop,nop,md5 valid], length 12
      10:12:15.464685 IP S > C: Flags [.], ack 13, win 65535, options [nop,nop,md5 valid], length 0
      
      After this patch the exchange looks saner :
      
      11:59:59.882990 IP C > S: Flags [S], seq 517075944, win 65535, options [nop,nop,md5 valid,mss 1400,sackOK,TS val 1751508483 ecr 0,nop,wscale 8], length 0
      11:59:59.883002 IP S > C: Flags [S.], seq 1902939253, ack 517075945, win 65535, options [nop,nop,md5 valid,mss 1400,sackOK,TS val 1751508479 ecr 1751508483,nop,wscale 8], length 0
      11:59:59.883012 IP C > S: Flags [.], ack 1, win 256, options [nop,nop,md5 valid,nop,nop,TS val 1751508483 ecr 1751508479], length 0
      11:59:59.883114 IP C > S: Flags [P.], seq 1:13, ack 1, win 256, options [nop,nop,md5 valid,nop,nop,TS val 1751508483 ecr 1751508479], length 12
      11:59:59.883122 IP S > C: Flags [.], ack 13, win 256, options [nop,nop,md5 valid,nop,nop,TS val 1751508483 ecr 1751508483], length 0
      11:59:59.883152 IP S > C: Flags [P.], seq 1:13, ack 13, win 256, options [nop,nop,md5 valid,nop,nop,TS val 1751508484 ecr 1751508483], length 12
      11:59:59.883170 IP C > S: Flags [.], ack 13, win 256, options [nop,nop,md5 valid,nop,nop,TS val 1751508484 ecr 1751508484], length 0
      
      Of course, no SACK block will ever be added later, but nothing should break.
      Technically, we could remove the 4 nops included in MD5+TS options,
      but again some stacks could break seeing not conventional alignment.
      
      Fixes: 4957faad ("TCPCT part 1g: Responder Cookie => Initiator")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: Florian Westphal <fw@strlen.de>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c83943a7
    • Eric Dumazet's avatar
      tcp: md5: add missing memory barriers in tcp_md5_do_add()/tcp_md5_hash_key() · ee66c2d1
      Eric Dumazet authored
      [ Upstream commit 6a2febec ]
      
      MD5 keys are read with RCU protection, and tcp_md5_do_add()
      might update in-place a prior key.
      
      Normally, typical RCU updates would allocate a new piece
      of memory. In this case only key->key and key->keylen might
      be updated, and we do not care if an incoming packet could
      see the old key, the new one, or some intermediate value,
      since changing the key on a live flow is known to be problematic
      anyway.
      
      We only want to make sure that in the case key->keylen
      is changed, cpus in tcp_md5_hash_key() wont try to use
      uninitialized data, or crash because key->keylen was
      read twice to feed sg_init_one() and ahash_request_set_crypt()
      
      Fixes: 9ea88a15 ("tcp: md5: check md5 signature without socket lock")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ee66c2d1
    • Christoph Paasch's avatar
      tcp: make sure listeners don't initialize congestion-control state · 030a998a
      Christoph Paasch authored
      [ Upstream commit ce69e563 ]
      
      syzkaller found its way into setsockopt with TCP_CONGESTION "cdg".
      tcp_cdg_init() does a kcalloc to store the gradients. As sk_clone_lock
      just copies all the memory, the allocated pointer will be copied as
      well, if the app called setsockopt(..., TCP_CONGESTION) on the listener.
      If now the socket will be destroyed before the congestion-control
      has properly been initialized (through a call to tcp_init_transfer), we
      will end up freeing memory that does not belong to that particular
      socket, opening the door to a double-free:
      
      [   11.413102] ==================================================================
      [   11.414181] BUG: KASAN: double-free or invalid-free in tcp_cleanup_congestion_control+0x58/0xd0
      [   11.415329]
      [   11.415560] CPU: 3 PID: 4884 Comm: syz-executor.5 Not tainted 5.8.0-rc2 #80
      [   11.416544] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014
      [   11.418148] Call Trace:
      [   11.418534]  <IRQ>
      [   11.418834]  dump_stack+0x7d/0xb0
      [   11.419297]  print_address_description.constprop.0+0x1a/0x210
      [   11.422079]  kasan_report_invalid_free+0x51/0x80
      [   11.423433]  __kasan_slab_free+0x15e/0x170
      [   11.424761]  kfree+0x8c/0x230
      [   11.425157]  tcp_cleanup_congestion_control+0x58/0xd0
      [   11.425872]  tcp_v4_destroy_sock+0x57/0x5a0
      [   11.426493]  inet_csk_destroy_sock+0x153/0x2c0
      [   11.427093]  tcp_v4_syn_recv_sock+0xb29/0x1100
      [   11.427731]  tcp_get_cookie_sock+0xc3/0x4a0
      [   11.429457]  cookie_v4_check+0x13d0/0x2500
      [   11.433189]  tcp_v4_do_rcv+0x60e/0x780
      [   11.433727]  tcp_v4_rcv+0x2869/0x2e10
      [   11.437143]  ip_protocol_deliver_rcu+0x23/0x190
      [   11.437810]  ip_local_deliver+0x294/0x350
      [   11.439566]  __netif_receive_skb_one_core+0x15d/0x1a0
      [   11.441995]  process_backlog+0x1b1/0x6b0
      [   11.443148]  net_rx_action+0x37e/0xc40
      [   11.445361]  __do_softirq+0x18c/0x61a
      [   11.445881]  asm_call_on_stack+0x12/0x20
      [   11.446409]  </IRQ>
      [   11.446716]  do_softirq_own_stack+0x34/0x40
      [   11.447259]  do_softirq.part.0+0x26/0x30
      [   11.447827]  __local_bh_enable_ip+0x46/0x50
      [   11.448406]  ip_finish_output2+0x60f/0x1bc0
      [   11.450109]  __ip_queue_xmit+0x71c/0x1b60
      [   11.451861]  __tcp_transmit_skb+0x1727/0x3bb0
      [   11.453789]  tcp_rcv_state_process+0x3070/0x4d3a
      [   11.456810]  tcp_v4_do_rcv+0x2ad/0x780
      [   11.457995]  __release_sock+0x14b/0x2c0
      [   11.458529]  release_sock+0x4a/0x170
      [   11.459005]  __inet_stream_connect+0x467/0xc80
      [   11.461435]  inet_stream_connect+0x4e/0xa0
      [   11.462043]  __sys_connect+0x204/0x270
      [   11.465515]  __x64_sys_connect+0x6a/0xb0
      [   11.466088]  do_syscall_64+0x3e/0x70
      [   11.466617]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      [   11.467341] RIP: 0033:0x7f56046dc469
      [   11.467844] Code: Bad RIP value.
      [   11.468282] RSP: 002b:00007f5604dccdd8 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
      [   11.469326] RAX: ffffffffffffffda RBX: 000000000068bf00 RCX: 00007f56046dc469
      [   11.470379] RDX: 0000000000000010 RSI: 0000000020000000 RDI: 0000000000000004
      [   11.471311] RBP: 00000000ffffffff R08: 0000000000000000 R09: 0000000000000000
      [   11.472286] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
      [   11.473341] R13: 000000000041427c R14: 00007f5604dcd5c0 R15: 0000000000000003
      [   11.474321]
      [   11.474527] Allocated by task 4884:
      [   11.475031]  save_stack+0x1b/0x40
      [   11.475548]  __kasan_kmalloc.constprop.0+0xc2/0xd0
      [   11.476182]  tcp_cdg_init+0xf0/0x150
      [   11.476744]  tcp_init_congestion_control+0x9b/0x3a0
      [   11.477435]  tcp_set_congestion_control+0x270/0x32f
      [   11.478088]  do_tcp_setsockopt.isra.0+0x521/0x1a00
      [   11.478744]  __sys_setsockopt+0xff/0x1e0
      [   11.479259]  __x64_sys_setsockopt+0xb5/0x150
      [   11.479895]  do_syscall_64+0x3e/0x70
      [   11.480395]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      [   11.481097]
      [   11.481321] Freed by task 4872:
      [   11.481783]  save_stack+0x1b/0x40
      [   11.482230]  __kasan_slab_free+0x12c/0x170
      [   11.482839]  kfree+0x8c/0x230
      [   11.483240]  tcp_cleanup_congestion_control+0x58/0xd0
      [   11.483948]  tcp_v4_destroy_sock+0x57/0x5a0
      [   11.484502]  inet_csk_destroy_sock+0x153/0x2c0
      [   11.485144]  tcp_close+0x932/0xfe0
      [   11.485642]  inet_release+0xc1/0x1c0
      [   11.486131]  __sock_release+0xc0/0x270
      [   11.486697]  sock_close+0xc/0x10
      [   11.487145]  __fput+0x277/0x780
      [   11.487632]  task_work_run+0xeb/0x180
      [   11.488118]  __prepare_exit_to_usermode+0x15a/0x160
      [   11.488834]  do_syscall_64+0x4a/0x70
      [   11.489326]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Wei Wang fixed a part of these CDG-malloc issues with commit c1201444
      ("tcp: memset ca_priv data to 0 properly").
      
      This patch here fixes the listener-scenario: We make sure that listeners
      setting the congestion-control through setsockopt won't initialize it
      (thus CDG never allocates on listeners). For those who use AF_UNSPEC to
      reuse a socket, tcp_disconnect() is changed to cleanup afterwards.
      
      (The issue can be reproduced at least down to v4.4.x.)
      
      Cc: Wei Wang <weiwan@google.com>
      Cc: Eric Dumazet <edumazet@google.com>
      Fixes: 2b0a8c9e ("tcp: add CDG congestion control")
      Signed-off-by: default avatarChristoph Paasch <cpaasch@apple.com>
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      030a998a