1. 20 9月, 2019 1 次提交
    • L
      hwrng: core - don't wait on add_early_randomness() · 78887832
      Laurent Vivier 提交于
      add_early_randomness() is called by hwrng_register() when the
      hardware is added. If this hardware and its module are present
      at boot, and if there is no data available the boot hangs until
      data are available and can't be interrupted.
      
      For instance, in the case of virtio-rng, in some cases the host can be
      not able to provide enough entropy for all the guests.
      
      We can have two easy ways to reproduce the problem but they rely on
      misconfiguration of the hypervisor or the egd daemon:
      
      - if virtio-rng device is configured to connect to the egd daemon of the
      host but when the virtio-rng driver asks for data the daemon is not
      connected,
      
      - if virtio-rng device is configured to connect to the egd daemon of the
      host but the egd daemon doesn't provide data.
      
      The guest kernel will hang at boot until the virtio-rng driver provides
      enough data.
      
      To avoid that, call rng_get_data() in non-blocking mode (wait=0)
      from add_early_randomness().
      Signed-off-by: NLaurent Vivier <lvivier@redhat.com>
      Fixes: d9e79726 ("hwrng: add randomness to system from rng...")
      Cc: <stable@vger.kernel.org>
      Reviewed-by: NTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      78887832
  2. 13 9月, 2019 1 次提交
  3. 09 9月, 2019 1 次提交
    • S
      random: Use wait_event_freezable() in add_hwgenerator_randomness() · 59b56948
      Stephen Boyd 提交于
      Sebastian reports that after commit ff296293 ("random: Support freezable
      kthreads in add_hwgenerator_randomness()") we can call might_sleep() when the
      task state is TASK_INTERRUPTIBLE (state=1). This leads to the following warning.
      
       do not call blocking ops when !TASK_RUNNING; state=1 set at [<00000000349d1489>] prepare_to_wait_event+0x5a/0x180
       WARNING: CPU: 0 PID: 828 at kernel/sched/core.c:6741 __might_sleep+0x6f/0x80
       Modules linked in:
      
       CPU: 0 PID: 828 Comm: hwrng Not tainted 5.3.0-rc7-next-20190903+ #46
       RIP: 0010:__might_sleep+0x6f/0x80
      
       Call Trace:
        kthread_freezable_should_stop+0x1b/0x60
        add_hwgenerator_randomness+0xdd/0x130
        hwrng_fillfn+0xbf/0x120
        kthread+0x10c/0x140
        ret_from_fork+0x27/0x50
      
      We shouldn't call kthread_freezable_should_stop() from deep within the
      wait_event code because the task state is still set as
      TASK_INTERRUPTIBLE instead of TASK_RUNNING and
      kthread_freezable_should_stop() will try to call into the freezer with
      the task in the wrong state. Use wait_event_freezable() instead so that
      it calls schedule() in the right place and tries to enter the freezer
      when the task state is TASK_RUNNING instead.
      Reported-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Tested-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Cc: Keerthy <j-keerthy@ti.com>
      Fixes: ff296293 ("random: Support freezable kthreads in add_hwgenerator_randomness()")
      Signed-off-by: NStephen Boyd <swboyd@chromium.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      59b56948
  4. 05 9月, 2019 1 次提交
    • D
      hwrng: timeriomem - relax check on memory resource size · 2a4bfd02
      Daniel Mack 提交于
      The timeriomem_rng driver only accesses the first 4 bytes of the given
      memory area and currently, it also forces that memory resource to be
      exactly 4 bytes in size.
      
      This, however, is problematic when used with device-trees that are
      generated from things like FPGA toolchains, where the minimum size
      of an exposed memory block may be something like 4k.
      
      Hence, let's only check for what's needed for the driver to operate
      properly; namely that we have enough memory available to read the
      random data from.
      Signed-off-by: NDaniel Mack <daniel@zonque.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      2a4bfd02
  5. 04 9月, 2019 2 次提交
  6. 02 9月, 2019 4 次提交
  7. 23 8月, 2019 3 次提交
    • H
      fdt: add support for rng-seed · 428826f5
      Hsin-Yi Wang 提交于
      Introducing a chosen node, rng-seed, which is an entropy that can be
      passed to kernel called very early to increase initial device
      randomness. Bootloader should provide this entropy and the value is
      read from /chosen/rng-seed in DT.
      
      Obtain of_fdt_crc32 for CRC check after early_init_dt_scan_nodes(),
      since early_init_dt_scan_chosen() would modify fdt to erase rng-seed.
      
      Add a new interface add_bootloader_randomness() for rng-seed use case.
      Depends on whether the seed is trustworthy, rng seed would be passed to
      add_hwgenerator_randomness(). Otherwise it would be passed to
      add_device_randomness(). Decision is controlled by kernel config
      RANDOM_TRUST_BOOTLOADER.
      Signed-off-by: NHsin-Yi Wang <hsinyi@chromium.org>
      Reviewed-by: NStephen Boyd <swboyd@chromium.org>
      Reviewed-by: NRob Herring <robh@kernel.org>
      Reviewed-by: Theodore Ts'o <tytso@mit.edu> # drivers/char/random.c
      Signed-off-by: NWill Deacon <will@kernel.org>
      428826f5
    • T
      ipmi: move message error checking to avoid deadlock · 38303521
      Tony Camuso 提交于
      V1->V2: in handle_one_rcv_msg, if data_size > 2, set requeue to zero and
              goto out instead of calling ipmi_free_msg.
              Kosuke Tatsukawa <tatsu@ab.jp.nec.com>
      
      In the source stack trace below, function set_need_watch tries to
      take out the same si_lock that was taken earlier by ipmi_thread.
      
      ipmi_thread() [drivers/char/ipmi/ipmi_si_intf.c:995]
       smi_event_handler() [drivers/char/ipmi/ipmi_si_intf.c:765]
        handle_transaction_done() [drivers/char/ipmi/ipmi_si_intf.c:555]
         deliver_recv_msg() [drivers/char/ipmi/ipmi_si_intf.c:283]
          ipmi_smi_msg_received() [drivers/char/ipmi/ipmi_msghandler.c:4503]
           intf_err_seq() [drivers/char/ipmi/ipmi_msghandler.c:1149]
            smi_remove_watch() [drivers/char/ipmi/ipmi_msghandler.c:999]
             set_need_watch() [drivers/char/ipmi/ipmi_si_intf.c:1066]
      
      Upstream commit e1891cff adds code to
      ipmi_smi_msg_received() to call smi_remove_watch() via intf_err_seq()
      and this seems to be causing the deadlock.
      
      commit e1891cff
      Author: Corey Minyard <cminyard@mvista.com>
      Date:   Wed Oct 24 15:17:04 2018 -0500
          ipmi: Make the smi watcher be disabled immediately when not needed
      
      The fix is to put all messages in the queue and move the message
      checking code out of ipmi_smi_msg_received and into handle_one_recv_msg,
      which processes the message checking after ipmi_thread releases its
      locks.
      
      Additionally,Kosuke Tatsukawa <tatsu@ab.jp.nec.com> reported that
      handle_new_recv_msgs calls ipmi_free_msg when handle_one_rcv_msg returns
      zero, so that the call to ipmi_free_msg in handle_one_rcv_msg introduced
      another panic when "ipmitool sensor list" was run in a loop. He
      submitted this part of the patch.
      
      +free_msg:
      +               requeue = 0;
      +               goto out;
      
      Reported by: Osamu Samukawa <osa-samukawa@tg.jp.nec.com>
      Characterized by: Kosuke Tatsukawa <tatsu@ab.jp.nec.com>
      Signed-off-by: NTony Camuso <tcamuso@redhat.com>
      Fixes: e1891cff ("ipmi: Make the smi watcher be disabled immediately when not needed")
      Cc: stable@vger.kernel.org # 5.1
      Signed-off-by: NCorey Minyard <cminyard@mvista.com>
      38303521
    • K
      ipmi_ssif: avoid registering duplicate ssif interface · c4436c91
      Kamlakant Patel 提交于
      It is possible that SSIF interface entry is present in both DMI and ACPI
      tables. In SMP systems, in such cases it is possible that ssif_probe could
      be called simultaneously from i2c interface (from ACPI) and from DMI on
      different CPUs at kernel boot. Both try to register same SSIF interface
      simultaneously and result in race.
      
      In such cases where ACPI and SMBIOS both IPMI entries are available, we
      need to prefer ACPI over SMBIOS so that ACPI functions work properly if
      they use IPMI.
      So, if we get an ACPI interface and have already registered an SMBIOS
      at the same address, we need to remove the SMBIOS one and add the ACPI.
      
      Log:
      [   38.774743] ipmi device interface
      [   38.805006] ipmi_ssif: IPMI SSIF Interface driver
      [   38.861979] ipmi_ssif i2c-IPI0001:06: ssif_probe CPU 99 ***
      [   38.863655] ipmi_ssif 0-000e: ssif_probe CPU 14 ***
      [   38.863658] ipmi_ssif: Trying SMBIOS-specified SSIF interface at i2c address 0xe, adapter xlp9xx-i2c, slave address 0x0
      [   38.869500] ipmi_ssif: Trying ACPI-specified SSIF interface at i2c address 0xe, adapter xlp9xx-i2c, slave address 0x0
      [   38.914530] ipmi_ssif: Unable to clear message flags: -22 7 c7
      [   38.952429] ipmi_ssif: Unable to clear message flags: -22 7 00
      [   38.994734] ipmi_ssif: Error getting global enables: -22 7 00
      [   39.015877] ipmi_ssif 0-000e: IPMI message handler: Found new BMC (man_id: 0x00b3d1, prod_id: 0x0001, dev_id: 0x20)
      [   39.377645] ipmi_ssif i2c-IPI0001:06: IPMI message handler: Found new BMC (man_id: 0x00b3d1, prod_id: 0x0001, dev_id: 0x20)
      [   39.387863] ipmi_ssif 0-000e: IPMI message handler: BMC returned incorrect response, expected netfn 7 cmd 42, got netfn 7 cmd 1
      ...
      [NOTE] : Added custom prints to explain the problem.
      
      In the above log, ssif_probe is executed simultaneously on two different
      CPUs.
      
      This patch fixes this issue in following way:
       - Adds ACPI entry also to the 'ssif_infos' list.
       - Checks the list if SMBIOS is already registered, removes it and adds
         ACPI.
       - If ACPI is already registered, it ignores SMBIOS.
       - Adds mutex lock throughout the probe process to avoid race.
      Signed-off-by: NKamlakant Patel <kamlakantp@marvell.com>
      Message-Id: <1566389064-27356-1-git-send-email-kamlakantp@marvell.com>
      Signed-off-by: NCorey Minyard <cminyard@mvista.com>
      c4436c91
  8. 22 8月, 2019 1 次提交
    • S
      random: Support freezable kthreads in add_hwgenerator_randomness() · ff296293
      Stephen Boyd 提交于
      The kthread calling this function is freezable after commit 03a3bb7a
      ("hwrng: core - Freeze khwrng thread during suspend") is applied.
      Unfortunately, this function uses wait_event_interruptible() but doesn't
      check for the kthread being woken up by the fake freezer signal. When a
      user suspends the system, this kthread will wake up and if it fails the
      entropy size check it will immediately go back to sleep and not go into
      the freezer. Eventually, suspend will fail because the task never froze
      and a warning message like this may appear:
      
       PM: suspend entry (deep)
       Filesystems sync: 0.000 seconds
       Freezing user space processes ... (elapsed 0.001 seconds) done.
       OOM killer disabled.
       Freezing remaining freezable tasks ...
       Freezing of tasks failed after 20.003 seconds (1 tasks refusing to freeze, wq_busy=0):
       hwrng           R  running task        0   289      2 0x00000020
       [<c08c64c4>] (__schedule) from [<c08c6a10>] (schedule+0x3c/0xc0)
       [<c08c6a10>] (schedule) from [<c05dbd8c>] (add_hwgenerator_randomness+0xb0/0x100)
       [<c05dbd8c>] (add_hwgenerator_randomness) from [<bf1803c8>] (hwrng_fillfn+0xc0/0x14c [rng_core])
       [<bf1803c8>] (hwrng_fillfn [rng_core]) from [<c015abec>] (kthread+0x134/0x148)
       [<c015abec>] (kthread) from [<c01010e8>] (ret_from_fork+0x14/0x2c)
      
      Check for a freezer signal here and skip adding any randomness if the
      task wakes up because it was frozen. This should make the kthread freeze
      properly and suspend work again.
      
      Fixes: 03a3bb7a ("hwrng: core - Freeze khwrng thread during suspend")
      Reported-by: NKeerthy <j-keerthy@ti.com>
      Tested-by: NKeerthy <j-keerthy@ti.com>
      Signed-off-by: NStephen Boyd <swboyd@chromium.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      ff296293
  9. 17 8月, 2019 7 次提交
  10. 15 8月, 2019 1 次提交
    • S
      hwrng: core - Freeze khwrng thread during suspend · 03a3bb7a
      Stephen Boyd 提交于
      The hwrng_fill() function can run while devices are suspending and
      resuming. If the hwrng is behind a bus such as i2c or SPI and that bus
      is suspended, the hwrng may hang the bus while attempting to add some
      randomness. It's been observed on ChromeOS devices with suspend-to-idle
      (s2idle) and an i2c based hwrng that this kthread may run and ask the
      hwrng device for randomness before the i2c bus has been resumed.
      
      Let's make this kthread freezable so that we don't try to touch the
      hwrng during suspend/resume. This ensures that we can't cause the hwrng
      backing driver to get into a bad state because the device is guaranteed
      to be resumed before the hwrng kthread is thawed.
      
      Cc: Andrey Pronin <apronin@chromium.org>
      Cc: Duncan Laurie <dlaurie@chromium.org>
      Cc: Jason Gunthorpe <jgg@ziepe.ca>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Alexander Steffen <Alexander.Steffen@infineon.com>
      Signed-off-by: NStephen Boyd <swboyd@chromium.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      03a3bb7a
  11. 08 8月, 2019 1 次提交
  12. 06 8月, 2019 1 次提交
    • C
      ipmi_si: Only schedule continuously in the thread in maintenance mode · 340ff31a
      Corey Minyard 提交于
      ipmi_thread() uses back-to-back schedule() to poll for command
      completion which, on some machines, can push up CPU consumption and
      heavily tax the scheduler locks leading to noticeable overall
      performance degradation.
      
      This was originally added so firmware updates through IPMI would
      complete in a timely manner.  But we can't kill the scheduler
      locks for that one use case.
      
      Instead, only run schedule() continuously in maintenance mode,
      where firmware updates should run.
      Signed-off-by: NCorey Minyard <cminyard@mvista.com>
      340ff31a
  13. 05 8月, 2019 2 次提交
  14. 02 8月, 2019 4 次提交
  15. 01 8月, 2019 1 次提交
  16. 27 7月, 2019 2 次提交
  17. 25 7月, 2019 3 次提交
    • K
      hpet: Fix division by zero in hpet_time_div() · 0c7d37f4
      Kefeng Wang 提交于
      The base value in do_div() called by hpet_time_div() is truncated from
      unsigned long to uint32_t, resulting in a divide-by-zero exception.
      
      UBSAN: Undefined behaviour in ../drivers/char/hpet.c:572:2
      division by zero
      CPU: 1 PID: 23682 Comm: syz-executor.3 Not tainted 4.4.184.x86_64+ #4
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014
       0000000000000000 b573382df1853d00 ffff8800a3287b98 ffffffff81ad7561
       ffff8800a3287c00 ffffffff838b35b0 ffffffff838b3860 ffff8800a3287c20
       0000000000000000 ffff8800a3287bb0 ffffffff81b8f25e ffffffff838b35a0
      Call Trace:
       [<ffffffff81ad7561>] __dump_stack lib/dump_stack.c:15 [inline]
       [<ffffffff81ad7561>] dump_stack+0xc1/0x120 lib/dump_stack.c:51
       [<ffffffff81b8f25e>] ubsan_epilogue+0x12/0x8d lib/ubsan.c:166
       [<ffffffff81b900cb>] __ubsan_handle_divrem_overflow+0x282/0x2c8 lib/ubsan.c:262
       [<ffffffff823560dd>] hpet_time_div drivers/char/hpet.c:572 [inline]
       [<ffffffff823560dd>] hpet_ioctl_common drivers/char/hpet.c:663 [inline]
       [<ffffffff823560dd>] hpet_ioctl_common.cold+0xa8/0xad drivers/char/hpet.c:577
       [<ffffffff81e63d56>] hpet_ioctl+0xc6/0x180 drivers/char/hpet.c:676
       [<ffffffff81711590>] vfs_ioctl fs/ioctl.c:43 [inline]
       [<ffffffff81711590>] file_ioctl fs/ioctl.c:470 [inline]
       [<ffffffff81711590>] do_vfs_ioctl+0x6e0/0xf70 fs/ioctl.c:605
       [<ffffffff81711eb4>] SYSC_ioctl fs/ioctl.c:622 [inline]
       [<ffffffff81711eb4>] SyS_ioctl+0x94/0xc0 fs/ioctl.c:613
       [<ffffffff82846003>] tracesys_phase2+0x90/0x95
      
      The main C reproducer autogenerated by syzkaller,
      
        syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
        memcpy((void*)0x20000100, "/dev/hpet\000", 10);
        syscall(__NR_openat, 0xffffffffffffff9c, 0x20000100, 0, 0);
        syscall(__NR_ioctl, r[0], 0x40086806, 0x40000000000000);
      
      Fix it by using div64_ul().
      Signed-off-by: NKefeng Wang <wangkefeng.wang@huawei.com>
      Signed-off-by: NZhang HongJun <zhanghongjun2@huawei.com>
      Cc: stable <stable@vger.kernel.org>
      Reviewed-by: NArnd Bergmann <arnd@arndb.de>
      Link: https://lore.kernel.org/r/20190711132757.130092-1-wangkefeng.wang@huawei.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0c7d37f4
    • J
      char: ppdev: Fix a possible null-pointer dereference in pp_release() · 7bdd9695
      Jia-Ju Bai 提交于
      In pp_release(), there is an if statement on line 730 to check whether
      pp->pdev is NULL:
          else if ((pp->flags & PP_CLAIMED) && pp->pdev && ...)
      
      When pp->pdev is NULL, it is used on line 743:
          info = &pp->pdev->port->ieee1284;
      and on line 748:
          parport_release(pp->pdev);
      
      Thus, a possible null-pointer dereference may occur.
      
      To fix this bug, pp->pdev is checked on line 740.
      
      This bug is found by a static analysis tool STCheck written by us.
      Signed-off-by: NJia-Ju Bai <baijiaju1990@gmail.com>
      Link: https://lore.kernel.org/r/20190724090426.1401-1-baijiaju1990@gmail.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7bdd9695
    • A
      Fix uninitialized variable in ipmb_dev_int.c · 71be7b0e
      Asmaa Mnebhi 提交于
      ret at line 112 of ipmb_dev_int.c is uninitialized which
      results in a warning during build regressions.
      This warning was found by build regression/improvement
      testing for v5.3-rc1.
      
      Reported-by: build regression/improvement testing for v5.3-rc1.
      Fixes: 51bd6f29 ("Add support for IPMB driver")
      Signed-off-by: NAsmaa Mnebhi <Asmaa@mellanox.com>
      Message-Id: <571dbb67cf58411d567953d9fb3739eb4789238b.1563996586.git.Asmaa@mellanox.com>
      Signed-off-by: NCorey Minyard <cminyard@mvista.com>
      71be7b0e
  18. 15 7月, 2019 3 次提交
  19. 25 6月, 2019 1 次提交