1. 22 Jul, 2020 40 commits
    • AceLan Kao's avatar
      USB: serial: option: add Quectel EG95 LTE modem · 93a0589d
      AceLan Kao authored
      commit da6902e5 upstream.
      
      Add support for Quectel Wireless Solutions Co., Ltd. EG95 LTE modem
      
      T:  Bus=01 Lev=01 Prnt=01 Port=02 Cnt=02 Dev#=  5 Spd=480 MxCh= 0
      D:  Ver= 2.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs=  1
      P:  Vendor=2c7c ProdID=0195 Rev=03.18
      S:  Manufacturer=Android
      S:  Product=Android
      C:  #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA
      I:  If#=0x0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
      I:  If#=0x1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
      I:  If#=0x2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
      I:  If#=0x3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
      I:  If#=0x4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
      Signed-off-by: default avatarAceLan Kao <acelan.kao@canonical.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      93a0589d
    • Jörgen Storvist's avatar
      USB: serial: option: add GosunCn GM500 series · e230a30a
      Jörgen Storvist authored
      commit 08d4ef5c upstream.
      
      Add USB IDs for GosunCn GM500 series cellular modules.
      
      RNDIS config:
      usb-devices
      T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 12 Spd=480 MxCh= 0
      D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
      P:  Vendor=305a ProdID=1404 Rev=03.18
      S:  Manufacturer=Android
      S:  Product=Android
      S:  SerialNumber=
      C:  #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA
      I:  If#=0x0 Alt= 0 #EPs= 1 Cls=e0(wlcon) Sub=01 Prot=03 Driver=rndis_host
      I:  If#=0x1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=rndis_host
      I:  If#=0x2 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=option
      I:  If#=0x3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
      I:  If#=0x4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
      
      MBIM config:
      usb-devices
      T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 11 Spd=480 MxCh= 0
      D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
      P:  Vendor=305a ProdID=1405 Rev=03.18
      S:  Manufacturer=Android
      S:  Product=Android
      S:  SerialNumber=
      C:  #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA
      I:  If#=0x0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=option
      I:  If#=0x1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
      I:  If#=0x2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
      I:  If#=0x3 Alt= 0 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim
      I:  If#=0x4 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim
      
      ECM config:
      usb-devices
      T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 13 Spd=480 MxCh= 0
      D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
      P:  Vendor=305a ProdID=1406 Rev=03.18
      S:  Manufacturer=Android
      S:  Product=Android
      S:  SerialNumber=
      C:  #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA
      I:  If#=0x0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=option
      I:  If#=0x1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
      I:  If#=0x2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
      I:  If#=0x3 Alt= 0 #EPs= 1 Cls=02(commc) Sub=06 Prot=00 Driver=cdc_ether
      I:  If#=0x4 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_ether
      Signed-off-by: default avatarJörgen Storvist <jorgen.storvist@gmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e230a30a
    • Igor Moura's avatar
      USB: serial: ch341: add new Product ID for CH340 · a93327a3
      Igor Moura authored
      commit 5d0136f8 upstream.
      
      Add PID for CH340 that's found on some ESP8266 dev boards made by
      LilyGO. The specific device that contains such serial converter can be
      seen here: https://github.com/LilyGO/LILYGO-T-OI.
      
      Apparently, it's a regular CH340, but I've confirmed with others that
      also bought this board that the PID found on this device (0x7522)
      differs from other devices with the "same" converter (0x7523).
      Simply adding its PID to the driver and rebuilding it made it work
      as expected.
      Signed-off-by: default avatarIgor Moura <imphilippini@gmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a93327a3
    • James Hilliard's avatar
      USB: serial: cypress_m8: enable Simply Automated UPB PIM · 3fde2779
      James Hilliard authored
      commit 5c45d04c upstream.
      
      This is a UPB (Universal Powerline Bus) PIM (Powerline Interface Module)
      which allows for controlling multiple UPB compatible devices from Linux
      using the standard serial interface.
      
      Based on vendor application source code there are two different models
      of USB based PIM devices in addition to a number of RS232 based PIM's.
      
      The vendor UPB application source contains the following USB ID's:
      
      	#define USB_PCS_VENDOR_ID 0x04b4
      	#define USB_PCS_PIM_PRODUCT_ID 0x5500
      
      	#define USB_SAI_VENDOR_ID 0x17dd
      	#define USB_SAI_PIM_PRODUCT_ID 0x5500
      
      The first set of ID's correspond to the PIM variant sold by Powerline
      Control Systems while the second corresponds to the Simply Automated
      Incorporated PIM. As the product ID for both of these match the default
      cypress HID->COM RS232 product ID it assumed that they both use an
      internal variant of this HID->COM RS232 converter hardware. However
      as the vendor ID for the Simply Automated variant is different we need
      to also add it to the cypress_M8 driver so that it is properly
      detected.
      Signed-off-by: default avatarJames Hilliard <james.hilliard1@gmail.com>
      Link: https://lore.kernel.org/r/20200616220403.1807003-1-james.hilliard1@gmail.com
      Cc: stable@vger.kernel.org
      [ johan: amend VID define entry ]
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3fde2779
    • Johan Hovold's avatar
      USB: serial: iuu_phoenix: fix memory corruption · df5228f1
      Johan Hovold authored
      commit e7b931be upstream.
      
      The driver would happily overwrite its write buffer with user data in
      256 byte increments due to a removed buffer-space sanity check.
      
      Fixes: 5fcf62b0 ("tty: iuu_phoenix: fix locking.")
      Cc: stable <stable@vger.kernel.org>     # 2.6.31
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      df5228f1
    • Zhang Qiang's avatar
      usb: gadget: function: fix missing spinlock in f_uac1_legacy · cc5f881f
      Zhang Qiang authored
      commit 8778eb09 upstream.
      
      Add a missing spinlock protection for play_queue, because
      the play_queue may be destroyed when the "playback_work"
      work func and "f_audio_out_ep_complete" callback func
      operate this paly_queue at the same time.
      
      Fixes: c6994e6f ("USB: gadget: add USB Audio Gadget driver")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarZhang Qiang <qiang.zhang@windriver.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cc5f881f
    • Peter Chen's avatar
      usb: chipidea: core: add wakeup support for extcon · b3cfd4d2
      Peter Chen authored
      commit 876d4e1e upstream.
      
      If wakeup event occurred by extcon event, it needs to call
      ci_irq again since the first ci_irq calling at extcon notifier
      only wakes up controller, but do noop for event handling,
      it causes the extcon use case can't work well from low power mode.
      
      Cc: <stable@vger.kernel.org>
      Fixes: 3ecb3e09 ("usb: chipidea: Use extcon framework for VBUS and ID detect")
      Reported-by: default avatarPhilippe Schenker <philippe.schenker@toradex.com>
      Tested-by: default avatarPhilippe Schenker <philippe.schenker@toradex.com>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Link: https://lore.kernel.org/r/20200707060601.31907-2-peter.chen@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b3cfd4d2
    • Minas Harutyunyan's avatar
      usb: dwc2: Fix shutdown callback in platform · 46cfd55e
      Minas Harutyunyan authored
      commit 4fdf228c upstream.
      
      To avoid lot of interrupts from dwc2 core, which can be asserted in
      specific conditions need to disable interrupts on HW level instead of
      disable IRQs on Kernel level, because of IRQ can be shared between
      drivers.
      
      Cc: stable@vger.kernel.org
      Fixes: a40a0031 ("usb: dwc2: add shutdown callback to platform variant")
      Tested-by: default avatarFrank Mori Hess <fmh6jj@gmail.com>
      Reviewed-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Reviewed-by: default avatarDoug Anderson <dianders@chromium.org>
      Reviewed-by: default avatarFrank Mori Hess <fmh6jj@gmail.com>
      Signed-off-by: default avatarMinas Harutyunyan <hminas@synopsys.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      46cfd55e
    • Tom Rix's avatar
      USB: c67x00: fix use after free in c67x00_giveback_urb · 3810c5b8
      Tom Rix authored
      commit 211f0834 upstream.
      
      clang static analysis flags this error
      
      c67x00-sched.c:489:55: warning: Use of memory after it is freed [unix.Malloc]
              usb_hcd_giveback_urb(c67x00_hcd_to_hcd(c67x00), urb, urbp->status);
                                                                   ^~~~~~~~~~~~
      Problem happens in this block of code
      
      	c67x00_release_urb(c67x00, urb);
      	usb_hcd_unlink_urb_from_ep(c67x00_hcd_to_hcd(c67x00), urb);
      	spin_unlock(&c67x00->lock);
      	usb_hcd_giveback_urb(c67x00_hcd_to_hcd(c67x00), urb, urbp->status);
      
      In the call to c67x00_release_urb has this freeing of urbp
      
      	urbp = urb->hcpriv;
      	urb->hcpriv = NULL;
      	list_del(&urbp->hep_node);
      	kfree(urbp);
      
      And so urbp is freed before usb_hcd_giveback_urb uses it as its 3rd
      parameter.
      
      Since all is required is the status, pass the status directly as is
      done in c64x00_urb_dequeue
      
      Fixes: e9b29ffc ("USB: add Cypress c67x00 OTG controller HCD driver")
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200708131243.24336-1-trix@redhat.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3810c5b8
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fix race against the error recovery URB submission · 1a6bb2da
      Takashi Iwai authored
      commit 9b7e5208 upstream.
      
      USB MIDI driver has an error recovery mechanism to resubmit the URB in
      the delayed timer handler, and this may race with the standard start /
      stop operations.  Although both start and stop operations themselves
      don't race with each other due to the umidi->mutex protection, but
      this isn't applied to the timer handler.
      
      For fixing this potential race, the following changes are applied:
      
      - Since the timer handler can't use the mutex, we apply the
        umidi->disc_lock protection at each input stream URB submission;
        this also needs to change the GFP flag to GFP_ATOMIC
      - Add a check of the URB refcount and skip if already submitted
      - Move the timer cancel call at disconnection to the beginning of the
        procedure; this assures the in-flight timer handler is gone properly
        before killing all pending URBs
      
      Reported-by: syzbot+0f4ecfe6a2c322c81728@syzkaller.appspotmail.com
      Reported-by: syzbot+5f1d24c49c1d2c427497@syzkaller.appspotmail.com
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200710160656.16819-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1a6bb2da
    • Takashi Iwai's avatar
      ALSA: line6: Perform sanity check for each URB creation · da72db67
      Takashi Iwai authored
      commit 6e8a914a upstream.
      
      LINE6 drivers create stream URBs with a fixed pipe without checking
      its validity, and this may lead to a kernel WARNING at the submission
      when a malformed USB descriptor is passed.
      
      For avoiding the kernel warning, perform the similar sanity checks for
      each pipe type at creating a URB.
      
      Reported-by: syzbot+c190f6858a04ea7fbc52@syzkaller.appspotmail.com
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/s5hv9iv4hq8.wl-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      da72db67
    • Takashi Iwai's avatar
      usb: core: Add a helper function to check the validity of EP type in URB · 0c1dc2c6
      Takashi Iwai authored
      commit e901b987 upstream.
      
      This patch adds a new helper function to perform a sanity check of the
      given URB to see whether it contains a valid endpoint.  It's a light-
      weight version of what usb_submit_urb() does, but without the kernel
      warning followed by the stack trace, just returns an error code.
      
      Especially for a driver that doesn't parse the descriptor but fills
      the URB with the fixed endpoint (e.g. some quirks for non-compliant
      devices), this kind of check is preferable at the probe phase before
      actually submitting the urb.
      Tested-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0c1dc2c6
    • Dmitry Torokhov's avatar
      HID: magicmouse: do not set up autorepeat · 0c1663a3
      Dmitry Torokhov authored
      commit 6363d206 upstream.
      
      Neither the trackpad, nor the mouse want input core to generate autorepeat
      events for their buttons, so let's reset the bit (as hid-input sets it for
      these devices based on the usage vendor code).
      
      Cc: stable@vger.kernel.org
      Reported-by: default avatarYariv <oigevald+kernel@gmail.com>
      Tested-by: default avatarYariv <oigevald+kernel@gmail.com>
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0c1663a3
    • Álvaro Fernández Rojas's avatar
      mtd: rawnand: brcmnand: fix CS0 layout · 9311e9fb
      Álvaro Fernández Rojas authored
      commit 3d3fb3c5 upstream.
      
      Only v3.3-v5.0 have a different CS0 layout.
      Controllers before v3.3 use the same layout for every CS.
      
      Fixes: 27c5b17c ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller")
      Signed-off-by: default avatarÁlvaro Fernández Rojas <noltari@gmail.com>
      Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Link: https://lore.kernel.org/linux-mtd/20200522121524.4161539-3-noltari@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9311e9fb
    • Jin Yao's avatar
      perf stat: Zero all the 'ena' and 'run' array slot stats for interval mode · 407da522
      Jin Yao authored
      commit 0e0bf1ea upstream.
      
      As the code comments in perf_stat_process_counter() say, we calculate
      counter's data every interval, and the display code shows ps->res_stats
      avg value. We need to zero the stats for interval mode.
      
      But the current code only zeros the res_stats[0], it doesn't zero the
      res_stats[1] and res_stats[2], which are for ena and run of counter.
      
      This patch zeros the whole res_stats[] for interval mode.
      
      Fixes: 51fd2df1 ("perf stat: Fix interval output values")
      Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200409070755.17261-1-yao.jin@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      407da522
    • Krzysztof Kozlowski's avatar
      ARM: dts: socfpga: Align L2 cache-controller nodename with dtschema · 6a5cfeee
      Krzysztof Kozlowski authored
      [ Upstream commit d7adfe5f ]
      
      Fix dtschema validator warnings like:
          l2-cache@fffff000: $nodename:0:
              'l2-cache@fffff000' does not match '^(cache-controller|cpu)(@[0-9a-f,]+)*$'
      
      Fixes: 475dc86d ("arm: dts: socfpga: Add a base DTSI for Altera's Arria10 SOC")
      Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: default avatarDinh Nguyen <dinguyen@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6a5cfeee
    • Enric Balletbo i Serra's avatar
      Revert "thermal: mediatek: fix register index error" · 5e485535
      Enric Balletbo i Serra authored
      [ Upstream commit a8f62f18 ]
      
      This reverts commit eb9aecd9
      
      The above patch is supposed to fix a register index error on mt2701. It
      is not clear if the problem solved is a hang or just an invalid value
      returned, my guess is the second. The patch introduces, though, a new
      hang on MT8173 device making them unusable. So, seems reasonable, revert
      the patch because introduces a worst issue.
      
      The reason I send a revert instead of trying to fix the issue for MT8173
      is because the information needed to fix the issue is in the datasheet
      and is not public. So I am not really able to fix it.
      
      Fixes the following bug when CONFIG_MTK_THERMAL is set on MT8173
      devices.
      
      [    2.222488] Unable to handle kernel paging request at virtual address ffff8000125f5001
      [    2.230421] Mem abort info:
      [    2.233207]   ESR = 0x96000021
      [    2.236261]   EC = 0x25: DABT (current EL), IL = 32 bits
      [    2.241571]   SET = 0, FnV = 0
      [    2.244623]   EA = 0, S1PTW = 0
      [    2.247762] Data abort info:
      [    2.250640]   ISV = 0, ISS = 0x00000021
      [    2.254473]   CM = 0, WnR = 0
      [    2.257544] swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000041850000
      [    2.264251] [ffff8000125f5001] pgd=000000013ffff003, pud=000000013fffe003, pmd=000000013fff9003, pte=006800001100b707
      [    2.274867] Internal error: Oops: 96000021 [#1] PREEMPT SMP
      [    2.280432] Modules linked in:
      [    2.283483] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.7.0-rc6+ #162
      [    2.289914] Hardware name: Google Elm (DT)
      [    2.294003] pstate: 20000005 (nzCv daif -PAN -UAO)
      [    2.298792] pc : mtk_read_temp+0xb8/0x1c8
      [    2.302793] lr : mtk_read_temp+0x7c/0x1c8
      [    2.306794] sp : ffff80001003b930
      [    2.310100] x29: ffff80001003b930 x28: 0000000000000000
      [    2.315404] x27: 0000000000000002 x26: ffff0000f9550b10
      [    2.320709] x25: ffff0000f9550a80 x24: 0000000000000090
      [    2.326014] x23: ffff80001003ba24 x22: 00000000610344c0
      [    2.331318] x21: 0000000000002710 x20: 00000000000001f4
      [    2.336622] x19: 0000000000030d40 x18: ffff800011742ec0
      [    2.341926] x17: 0000000000000001 x16: 0000000000000001
      [    2.347230] x15: ffffffffffffffff x14: ffffff0000000000
      [    2.352535] x13: ffffffffffffffff x12: 0000000000000028
      [    2.357839] x11: 0000000000000003 x10: ffff800011295ec8
      [    2.363143] x9 : 000000000000291b x8 : 0000000000000002
      [    2.368447] x7 : 00000000000000a8 x6 : 0000000000000004
      [    2.373751] x5 : 0000000000000000 x4 : ffff800011295cb0
      [    2.379055] x3 : 0000000000000002 x2 : ffff8000125f5001
      [    2.384359] x1 : 0000000000000001 x0 : ffff0000f9550a80
      [    2.389665] Call trace:
      [    2.392105]  mtk_read_temp+0xb8/0x1c8
      [    2.395760]  of_thermal_get_temp+0x2c/0x40
      [    2.399849]  thermal_zone_get_temp+0x78/0x160
      [    2.404198]  thermal_zone_device_update.part.0+0x3c/0x1f8
      [    2.409589]  thermal_zone_device_update+0x34/0x48
      [    2.414286]  of_thermal_set_mode+0x58/0x88
      [    2.418375]  thermal_zone_of_sensor_register+0x1a8/0x1d8
      [    2.423679]  devm_thermal_zone_of_sensor_register+0x64/0xb0
      [    2.429242]  mtk_thermal_probe+0x690/0x7d0
      [    2.433333]  platform_drv_probe+0x5c/0xb0
      [    2.437335]  really_probe+0xe4/0x448
      [    2.440901]  driver_probe_device+0xe8/0x140
      [    2.445077]  device_driver_attach+0x7c/0x88
      [    2.449252]  __driver_attach+0xac/0x178
      [    2.453082]  bus_for_each_dev+0x78/0xc8
      [    2.456909]  driver_attach+0x2c/0x38
      [    2.460476]  bus_add_driver+0x14c/0x230
      [    2.464304]  driver_register+0x6c/0x128
      [    2.468131]  __platform_driver_register+0x50/0x60
      [    2.472831]  mtk_thermal_driver_init+0x24/0x30
      [    2.477268]  do_one_initcall+0x50/0x298
      [    2.481098]  kernel_init_freeable+0x1ec/0x264
      [    2.485450]  kernel_init+0x1c/0x110
      [    2.488931]  ret_from_fork+0x10/0x1c
      [    2.492502] Code: f9401081 f9400402 b8a67821 8b010042 (b9400042)
      [    2.498599] ---[ end trace e43e3105ed27dc99 ]---
      [    2.503367] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
      [    2.511020] SMP: stopping secondary CPUs
      [    2.514941] Kernel Offset: disabled
      [    2.518421] CPU features: 0x090002,25006005
      [    2.522595] Memory Limit: none
      [    2.525644] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]--
      
      Cc: Michael Kao <michael.kao@mediatek.com>
      Fixes: eb9aecd9 ("thermal: mediatek: fix register index error")
      Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
      Reviewed-by: default avatarMatthias Brugger <matthias.bgg@gmail.com>
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      Link: https://lore.kernel.org/r/20200707103412.1010823-1-enric.balletbo@collabora.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      5e485535
    • Dan Carpenter's avatar
      staging: comedi: verify array index is correct before using it · 9c6c379f
      Dan Carpenter authored
      [ Upstream commit ef75e14a ]
      
      This code reads from the array before verifying that "trig" is a valid
      index.  If the index is wildly out of bounds then reading from an
      invalid address could lead to an Oops.
      
      Fixes: a8c66b68 ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Link: https://lore.kernel.org/r/20200709102936.GA20875@mwandaSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9c6c379f
    • Michał Mirosław's avatar
      usb: gadget: udc: atmel: fix uninitialized read in debug printk · 755518f9
      Michał Mirosław authored
      [ Upstream commit 30517ffe ]
      
      Fixed commit moved the assignment of 'req', but did not update a
      reference in the DBG() call. Use the argument as it was renamed.
      
      Fixes: 5fb694f9 ("usb: gadget: udc: atmel: fix possible oops when unloading module")
      Signed-off-by: default avatarMichał Mirosław <mirq-linux@rere.qmqm.pl>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      755518f9
    • Marc Kleine-Budde's avatar
      spi: spi-sun6i: sun6i_spi_transfer_one(): fix setting of clock rate · 34319cf5
      Marc Kleine-Budde authored
      [ Upstream commit ed7815db ]
      
      A SPI transfer defines the _maximum_ speed of the SPI transfer. However the
      driver doesn't take into account that the clock divider is always rounded down
      (due to integer arithmetics). This results in a too high clock rate for the SPI
      transfer.
      
      E.g.: with a mclk_rate of 24 MHz and a SPI transfer speed of 10 MHz, the
      original code calculates a reg of "0", which results in a effective divider of
      "2" and a 12 MHz clock for the SPI transfer.
      
      This patch fixes the issue by using DIV_ROUND_UP() instead of a plain
      integer division.
      
      While there simplify the divider calculation for the CDR1 case, use
      order_base_2() instead of two ilog2() calculations.
      
      Fixes: 3558fe90 ("spi: sunxi: Add Allwinner A31 SPI controller driver")
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Acked-by: default avatarMaxime Ripard <mripard@kernel.org>
      Link: https://lore.kernel.org/r/20200706143443.9855-2-mkl@pengutronix.deSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      34319cf5
    • Jonathan Cameron's avatar
      iio:health:afe4404 Fix timestamp alignment and prevent data leak. · 68ff3812
      Jonathan Cameron authored
      [ Upstream commit f88eccca ]
      
      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 40 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: 87aec56e ("iio: health: Add driver for the TI AFE4404 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>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      68ff3812
    • Sasha Levin's avatar
      Revert "usb/ohci-platform: Fix a warning when hibernating" · dd37ca83
      Sasha Levin authored
      This reverts commit 104592a5.
      
      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>
      dd37ca83
    • Sasha Levin's avatar
      Revert "usb/xhci-plat: Set PM runtime as active on resume" · 10090394
      Sasha Levin authored
      This reverts commit 9e148a5e.
      
      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>
      10090394
    • Sasha Levin's avatar
      Revert "usb/ehci-platform: Set PM runtime as active on resume" · cff29865
      Sasha Levin authored
      This reverts commit 5365fc31.
      
      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>
      cff29865
    • Florian Fainelli's avatar
      net: dsa: bcm_sf2: Fix node reference count · a76dfef4
      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>
      a76dfef4
    • Angelo Dureghello's avatar
      spi: fix initial SPI_SR value in spi-fsl-dspi · 750c4f01
      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>
      750c4f01
    • Jonathan Cameron's avatar
      iio:health:afe4403 Fix timestamp alignment and prevent data leak. · c4216cfe
      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>
      c4216cfe
    • Jonathan Cameron's avatar
      iio:pressure:ms5611 Fix buffer element alignment · 065b529d
      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>
      065b529d
    • Navid Emamdoost's avatar
      iio: pressure: zpa2326: handle pm_runtime_get_sync failure · 2f776928
      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>
      2f776928
    • Chuhong Yuan's avatar
      iio: mma8452: Add missed iio_device_unregister() call in mma8452_probe() · de8a1ee6
      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>
      de8a1ee6
    • Dinghao Liu's avatar
      iio: magnetometer: ak8974: Fix runtime PM imbalance on error · 64b4892a
      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>
      64b4892a
    • Jonathan Cameron's avatar
      iio:magnetometer:ak8974: Fix alignment and data leak issues · 980eaca9
      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>
      980eaca9
    • Andy Shevchenko's avatar
      i2c: eg20t: Load module automatically if ID matches · bd9507d2
      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>
      bd9507d2
    • Cong Wang's avatar
      cgroup: Fix sock_cgroup_data on big-endian. · 65888672
      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>
      65888672
    • Cong Wang's avatar
      cgroup: fix cgroup_sk_alloc() for sk_clone_lock() · 51fbad61
      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>
      51fbad61
    • Eric Dumazet's avatar
      tcp: md5: allow changing MD5 keys in all socket states · 2d00b78d
      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>
      2d00b78d
    • Eric Dumazet's avatar
      tcp: md5: do not send silly options in SYNCOOKIES · ade339f5
      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>
      ade339f5
    • Christoph Paasch's avatar
      tcp: make sure listeners don't initialize congestion-control state · 35e7d27c
      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>
      35e7d27c
    • Sean Tranchetti's avatar
      genetlink: remove genl_bind · fad45a87
      Sean Tranchetti authored
      [ Upstream commit 1e82a62f ]
      
      A potential deadlock can occur during registering or unregistering a
      new generic netlink family between the main nl_table_lock and the
      cb_lock where each thread wants the lock held by the other, as
      demonstrated below.
      
      1) Thread 1 is performing a netlink_bind() operation on a socket. As part
         of this call, it will call netlink_lock_table(), incrementing the
         nl_table_users count to 1.
      2) Thread 2 is registering (or unregistering) a genl_family via the
         genl_(un)register_family() API. The cb_lock semaphore will be taken for
         writing.
      3) Thread 1 will call genl_bind() as part of the bind operation to handle
         subscribing to GENL multicast groups at the request of the user. It will
         attempt to take the cb_lock semaphore for reading, but it will fail and
         be scheduled away, waiting for Thread 2 to finish the write.
      4) Thread 2 will call netlink_table_grab() during the (un)registration
         call. However, as Thread 1 has incremented nl_table_users, it will not
         be able to proceed, and both threads will be stuck waiting for the
         other.
      
      genl_bind() is a noop, unless a genl_family implements the mcast_bind()
      function to handle setting up family-specific multicast operations. Since
      no one in-tree uses this functionality as Cong pointed out, simply removing
      the genl_bind() function will remove the possibility for deadlock, as there
      is no attempt by Thread 1 above to take the cb_lock semaphore.
      
      Fixes: c380d9a7 ("genetlink: pass multicast bind/unbind to families")
      Suggested-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Acked-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarSean Tranchetti <stranche@codeaurora.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fad45a87
    • Eric Dumazet's avatar
      tcp: md5: refine tcp_md5_do_add()/tcp_md5_hash_key() barriers · 66486965
      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>
      66486965