07 Nov, 2020

2 commits

  • Mimic the pre-existing ACPI and Device Tree event log behavior by not
    creating the binary_bios_measurements file when the EFI TPM event log is
    empty.

    This fixes the following NULL pointer dereference that can occur when
    reading /sys/kernel/security/tpm0/binary_bios_measurements after the
    kernel received an empty event log from the firmware:

    BUG: kernel NULL pointer dereference, address: 000000000000002c
    #PF: supervisor read access in kernel mode
    #PF: error_code(0x0000) - not-present page
    PGD 0 P4D 0
    Oops: 0000 [#1] SMP PTI
    CPU: 2 PID: 3932 Comm: fwupdtpmevlog Not tainted 5.9.0-00003-g629990edad62 #17
    Hardware name: LENOVO 20LCS03L00/20LCS03L00, BIOS N27ET38W (1.24 ) 11/28/2019
    RIP: 0010:tpm2_bios_measurements_start+0x3a/0x550
    Code: 54 53 48 83 ec 68 48 8b 57 70 48 8b 1e 65 48 8b 04 25 28 00 00 00 48 89 45 d0 31 c0 48 8b 82 c0 06 00 00 48 8b 8a c8 06 00 00 8b 60 1c 48 89 4d a0 4c 89 e2 49 83 c4 20 48 83 fb 00 75 2a 49
    RSP: 0018:ffffa9c901203db0 EFLAGS: 00010246
    RAX: 0000000000000010 RBX: 0000000000000000 RCX: 0000000000000010
    RDX: ffff8ba1eb99c000 RSI: ffff8ba1e4ce8280 RDI: ffff8ba1e4ce8258
    RBP: ffffa9c901203e40 R08: ffffa9c901203dd8 R09: ffff8ba1ec443300
    R10: ffffa9c901203e50 R11: 0000000000000000 R12: ffff8ba1e4ce8280
    R13: ffffa9c901203ef0 R14: ffffa9c901203ef0 R15: ffff8ba1e4ce8258
    FS: 00007f6595460880(0000) GS:ffff8ba1ef880000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 000000000000002c CR3: 00000007d8d18003 CR4: 00000000003706e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    ? __kmalloc_node+0x113/0x320
    ? kvmalloc_node+0x31/0x80
    seq_read+0x94/0x420
    vfs_read+0xa7/0x190
    ksys_read+0xa7/0xe0
    __x64_sys_read+0x1a/0x20
    do_syscall_64+0x37/0x80
    entry_SYSCALL_64_after_hwframe+0x44/0xa9

    In this situation, the bios_event_log pointer in the tpm_bios_log struct
    was not NULL but was equal to the ZERO_SIZE_PTR (0x10) value. This was
    due to the following kmemdup() in tpm_read_log_efi():

    int tpm_read_log_efi(struct tpm_chip *chip)
    {
    ...
    /* malloc EventLog space */
    log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL);
    if (!log->bios_event_log) {
    ret = -ENOMEM;
    goto out;
    }
    ...
    }

    When log_size is zero, due to an empty event log from firmware,
    ZERO_SIZE_PTR is returned from kmemdup(). Upon a read of the
    binary_bios_measurements file, the tpm2_bios_measurements_start()
    function does not perform a ZERO_OR_NULL_PTR() check on the
    bios_event_log pointer before dereferencing it.

    Rather than add a ZERO_OR_NULL_PTR() check in functions that make use of
    the bios_event_log pointer, simply avoid creating the
    binary_bios_measurements_file as is done in other event log retrieval
    backends.

    Explicitly ignore all of the events in the final event log when the main
    event log is empty. The list of events in the final event log cannot be
    accurately parsed without referring to the first event in the main event
    log (the event log header) so the final event log is useless in such a
    situation.

    Fixes: 58cc1e4faf10 ("tpm: parse TPM event logs based on EFI table")
    Link: https://lore.kernel.org/linux-integrity/E1FDCCCB-CA51-4AEE-AC83-9CDE995EAE52@canonical.com/
    Reported-by: Kai-Heng Feng
    Reported-by: Kenneth R. Crudup
    Reported-by: Mimi Zohar
    Cc: Thiébaud Weksteen
    Cc: Ard Biesheuvel
    Signed-off-by: Tyler Hicks
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Tyler Hicks
     
  • There is a misconfiguration in the bios of the gpio pin used for the
    interrupt in the T490s. When interrupts are enabled in the tpm_tis
    driver code this results in an interrupt storm. This was initially
    reported when we attempted to enable the interrupt code in the tpm_tis
    driver, which previously wasn't setting a flag to enable it. Due to
    the reports of the interrupt storm that code was reverted and we went back
    to polling instead of using interrupts. Now that we know the T490s problem
    is a firmware issue, add code to check if the system is a T490s and
    disable interrupts if that is the case. This will allow us to enable
    interrupts for everyone else. If the user has a fixed bios they can
    force the enabling of interrupts with tpm_tis.interrupts=1 on the
    kernel command line.

    Cc: Peter Huewe
    Cc: Jason Gunthorpe
    Cc: Hans de Goede
    Signed-off-by: Jerry Snitselaar
    Reviewed-by: James Bottomley
    Reviewed-by: Hans de Goede
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Jerry Snitselaar
     

02 Oct, 2020

3 commits

  • Some TIS based TPMs can return 0xff to status reads if the locality
    hasn't been properly requested. Detect this condition by checking the
    bits that the TIS spec specifies must return zero are clear and return
    zero in that case. Also drop a warning so the problem can be
    identified in the calling path and fixed (usually a missing
    try_get_ops()).

    Signed-off-by: James Bottomley
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    James Bottomley
     
  • Use %*ph format to print small buffer as hex string.

    Signed-off-by: Andy Shevchenko
    Reviewed-by: Petr Vorel
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Andy Shevchenko
     
  • When fitted, the SynQuacer platform exposes its SPI TPM via a MMIO
    window that is backed by the SPI command sequencer in the SPI bus
    controller. This arrangement has the limitation that only byte size
    accesses are supported, and so we'll need to provide a separate module
    that take this into account.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Masahisa Kojima
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Masahisa Kojima
     

04 Aug, 2020

1 commit

  • Pull ARM SoC driver updates from Arnd Bergmann:
    "A couple of subsystems have their own subsystem maintainers but choose
    to have the code merged through the soc tree as upstream, as the code
    tends to be used across multiple SoCs or has SoC specific drivers
    itself:

    - memory controllers:

    Krzysztof Kozlowski takes ownership of the drivers/memory subsystem
    and its drivers, starting out with a set of cleanup patches.

    A larger driver for the Tegra memory controller that was
    accidentally missed for v5.8 is now added.

    - reset controllers:

    Only minor updates to drivers/reset this time

    - firmware:

    The "turris mox" firmware driver gains support for signed firmware
    blobs The tegra firmware driver gets extended to export some debug
    information Various updates to i.MX firmware drivers, mostly
    cosmetic

    - ARM SCMI/SCPI:

    A new mechanism for platform notifications is added, among a number
    of minor changes.

    - optee:

    Probing of the TEE bus is rewritten to better support detection of
    devices that depend on the tee-supplicant user space. A new
    firmware based trusted platform module (fTPM) driver is added based
    on OP-TEE

    - SoC attributes:

    A new driver is added to provide a generic soc_device for
    identifying a machine through the SMCCC ARCH_SOC_ID firmware
    interface rather than by probing SoC family specific registers.

    The series also contains some cleanups to the common soc_device
    code.

    There are also a number of updates to SoC specific drivers, the main
    ones are:

    - Mediatek cmdq driver gains a few in-kernel interfaces

    - Minor updates to Qualcomm RPMh, socinfo, rpm drivers, mostly adding
    support for additional SoC variants

    - The Qualcomm GENI core code gains interconnect path voting and
    performance level support, and integrating this into a number of
    device drivers.

    - A new driver for Samsung Exynos5800 voltage coupler for

    - Renesas RZ/G2H (R8A774E1) SoC support gets added to a couple of SoC
    specific device drivers

    - Updates to the TI K3 Ring Accelerator driver"

    * tag 'arm-drivers-5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc: (164 commits)
    soc: qcom: geni: Fix unused label warning
    soc: qcom: smd-rpm: Fix kerneldoc
    memory: jz4780_nemc: Only request IO memory the driver will use
    soc: qcom: pdr: Reorder the PD state indication ack
    MAINTAINERS: Add Git repository for memory controller drivers
    memory: brcmstb_dpfe: Fix language typo
    memory: samsung: exynos5422-dmc: Correct white space issues
    memory: samsung: exynos-srom: Correct alignment
    memory: pl172: Enclose macro argument usage in parenthesis
    memory: of: Correct kerneldoc
    memory: omap-gpmc: Fix language typo
    memory: omap-gpmc: Correct white space issues
    memory: omap-gpmc: Use 'unsigned int' for consistency
    memory: omap-gpmc: Enclose macro argument usage in parenthesis
    memory: omap-gpmc: Correct kerneldoc
    memory: mvebu-devbus: Align with open parenthesis
    memory: mvebu-devbus: Add missing braces to all arms of if statement
    memory: bt1-l2-ctl: Add blank lines after declarations
    soc: TI knav_qmss: make symbol 'knav_acc_range_ops' static
    firmware: ti_sci: Replace HTTP links with HTTPS ones
    ...

    Linus Torvalds
     

24 Jul, 2020

2 commits

  • In case a TPM2 is attached, search for a TPM2 ACPI table when trying
    to get the event log from ACPI. If one is found, use it to get the
    start and length of the log area. This allows non-UEFI systems, such
    as SeaBIOS, to pass an event log when using a TPM2.

    Cc: Peter Huewe
    Cc: Jason Gunthorpe
    Signed-off-by: Stefan Berger
    Reviewed-by: Jerry Snitselaar
    Signed-off-by: Jarkko Sakkinen

    Stefan Berger
     
  • The size of the buffers for storing context's and sessions can vary from
    arch to arch as PAGE_SIZE can be anything between 4 kB and 256 kB (the
    maximum for PPC64). Define a fixed buffer size set to 16 kB. This should be
    enough for most use with three handles (that is how many we allow at the
    moment). Parametrize the buffer size while doing this, so that it is easier
    to revisit this later on if required.

    Cc: stable@vger.kernel.org
    Reported-by: Stefan Berger
    Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces")
    Reviewed-by: Jerry Snitselaar
    Tested-by: Stefan Berger
    Signed-off-by: Jarkko Sakkinen

    Jarkko Sakkinen
     

13 Jul, 2020

1 commit

  • …ux-tee into arm/drivers

    Enable multi-stage OP-TEE bus enumeration

    Probes drivers on the OP-TEE bus in two steps. First for drivers which
    do not depend on tee-supplicant. After tee-supplicant has been started
    probe the devices which do depend on tee-supplicant.

    Also introduces driver which uses an OP-TEE based fTPM Trusted
    Application depends on tee-supplicant NV RAM implementation based on
    RPMB secure storage.

    * tag 'optee-bus-for-v5.9' of git://git.linaro.org/people/jens.wiklander/linux-tee:
    tpm_ftpm_tee: register driver on TEE bus
    optee: enable support for multi-stage bus enumeration
    optee: use uuid for sysfs driver entry

    Link: https://lore.kernel.org/r/20200710085230.GA1312913@jade
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>

    Arnd Bergmann
     

10 Jul, 2020

1 commit

  • OP-TEE based fTPM Trusted Application depends on tee-supplicant to
    provide NV RAM implementation based on RPMB secure storage. So this
    dependency can be resolved via TEE bus where we only invoke fTPM
    driver probe once fTPM device is registered on the bus which is only
    true after the tee-supplicant is up and running. Additionally, TEE bus
    provides auto device enumeration.

    Signed-off-by: Maxim Uvarov
    Suggested-by: Sumit Garg
    Suggested-by: Arnd Bergmann
    Reviewed-by: Sumit Garg
    Reviewed-by: Jarkko Sakkinen
    Tested-by: Sumit Garg
    Signed-off-by: Jens Wiklander

    Maxim Uvarov
     

07 Jul, 2020

1 commit

  • Removing IFX0102 from tpm_tis was not a right move because both tpm_tis
    and tpm_infineon use the same device ID. Revert the commit and add a
    remark about a bug caused by commit 93e1b7d42e1e ("[PATCH] tpm: add HID
    module parameter").

    Fixes: e918e570415c ("tpm_tis: Remove the HID IFX0102")
    Reported-by: Peter Huewe
    Reviewed-by: Jerry Snitselaar
    Signed-off-by: Jarkko Sakkinen

    Jarkko Sakkinen
     

02 Jul, 2020

7 commits

  • Acer C720 running Linux v5.3 reports this in klog:

    tpm_tis: 1.2 TPM (device-id 0xB, rev-id 16)
    tpm tpm0: tpm_try_transmit: send(): error -5
    tpm tpm0: A TPM error (-5) occurred attempting to determine the timeouts
    tpm_tis tpm_tis: Could not get TPM timeouts and durations
    tpm_tis 00:08: 1.2 TPM (device-id 0xB, rev-id 16)
    tpm tpm0: tpm_try_transmit: send(): error -5
    tpm tpm0: A TPM error (-5) occurred attempting to determine the timeouts
    tpm_tis 00:08: Could not get TPM timeouts and durations
    ima: No TPM chip found, activating TPM-bypass!
    tpm_inf_pnp 00:08: Found TPM with ID IFX0102

    % git --no-pager grep IFX0102 drivers/char/tpm
    drivers/char/tpm/tpm_infineon.c: {"IFX0102", 0},
    drivers/char/tpm/tpm_tis.c: {"IFX0102", 0}, /* Infineon */

    Obviously IFX0102 was added to the HID table for the TCG TIS driver by
    mistake.

    Fixes: 93e1b7d42e1e ("[PATCH] tpm: add HID module parameter")
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=203877
    Cc: stable@vger.kernel.org
    Cc: Kylene Jo Hall
    Reported-by: Ferry Toth:
    Reviewed-by: Jerry Snitselaar
    Signed-off-by: Jarkko Sakkinen

    Jarkko Sakkinen
     
  • On a Chromebook I'm working on I noticed a big (~1 second) delay
    during bootup where nothing was happening. Right around this big
    delay there were messages about the TPM:

    [ 2.311352] tpm_tis_spi spi0.0: TPM ready IRQ confirmed on attempt 2
    [ 3.332790] tpm_tis_spi spi0.0: Cr50 firmware version: ...

    I put a few printouts in and saw that tpm_tis_spi_init() (specifically
    tpm_chip_register() in that function) was taking the lion's share of
    this time, though ~115 ms of the time was in cr50_print_fw_version().

    Let's make a one-line change to prefer async probe for tpm_tis_spi.
    There's no reason we need to block other drivers from probing while we
    load.

    NOTES:
    * It's possible that other hardware runs through the init sequence
    faster than Cr50 and this isn't such a big problem for them.
    However, even if they are faster they are still doing _some_
    transfers over a SPI bus so this should benefit everyone even if to
    a lesser extent.
    * It's possible that there are extra delays in the code that could be
    optimized out. I didn't dig since once I enabled async probe they
    no longer impacted me.

    Signed-off-by: Douglas Anderson
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Douglas Anderson
     
  • The tpm2_get_cc_attrs_tbl() call will result in TPM commands being issued,
    which will need the use of the internal command/response buffer. But,
    we're issuing this *before* we've waited to make sure that buffer is
    allocated.

    This can result in intermittent failures to probe if the hypervisor / TPM
    implementation doesn't respond quickly enough. I find it fails almost
    every time with an 8 vcpu guest under KVM with software emulated TPM.

    To fix it, just move the tpm2_get_cc_attrs_tlb() call after the
    existing code to wait for initialization, which will ensure the buffer
    is allocated.

    Fixes: 18b3670d79ae9 ("tpm: ibmvtpm: Add support for TPM2")
    Signed-off-by: David Gibson
    Reviewed-by: Jerry Snitselaar
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    David Gibson
     
  • Trivial fix, the spelling of "drescription" is incorrect
    in function comment.

    Fix this.

    Signed-off-by: Binbin Zhou
    Acked-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Binbin Zhou
     
  • 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: Vasily Averin
    Reviewed-by: Jerry Snitselaar
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Vasily Averin
     
  • During flow control we are just reading from the TPM, yet our spi_xfer
    has the tx_buf and rx_buf both non-NULL which means we're requesting a
    full duplex transfer.

    SPI is always somewhat of a full duplex protocol anyway and in theory
    the other side shouldn't really be looking at what we're sending it
    during flow control, but it's still a bit ugly to be sending some
    "random" data when we shouldn't.

    The default tpm_tis_spi_flow_control() tries to address this by
    setting 'phy->iobuf[0] = 0'. This partially avoids the problem of
    sending "random" data, but since our tx_buf and rx_buf both point to
    the same place I believe there is the potential of us sending the
    TPM's previous byte back to it if we hit the retry loop.

    Another flow control implementation, cr50_spi_flow_control(), doesn't
    address this at all.

    Let's clean this up and just make the tx_buf NULL before we call
    flow_control(). Not only does this ensure that we're not sending any
    "random" bytes but it also possibly could make the SPI controller
    behave in a slightly more optimal way.

    NOTE: no actual observed problems are fixed by this patch--it's was
    just made based on code inspection.

    Signed-off-by: Douglas Anderson
    Reviewed-by: Paul Menzel
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Douglas Anderson
     
  • It has been reported that some TIS based TPMs are giving unexpected
    errors when using the O_NONBLOCK path of the TPM device. The problem
    is that some TPMs don't like it when you get and then relinquish a
    locality (as the tpm_try_get_ops()/tpm_put_ops() pair does) without
    sending a command. This currently happens all the time in the
    O_NONBLOCK write path. Fix this by moving the tpm_try_get_ops()
    further down the code to after the O_NONBLOCK determination is made.
    This is safe because the priv->buffer_mutex still protects the priv
    state being modified.

    BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=206275
    Fixes: d23d12484307 ("tpm: fix invalid locking in NONBLOCKING mode")
    Reported-by: Mario Limonciello
    Tested-by: Alex Guzman
    Cc: stable@vger.kernel.org
    Reviewed-by: Jerry Snitselaar
    Signed-off-by: James Bottomley
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    James Bottomley
     

14 Jun, 2020

1 commit

  • Since commit 84af7a6194e4 ("checkpatch: kconfig: prefer 'help' over
    '---help---'"), the number of '---help---' has been gradually
    decreasing, but there are still more than 2400 instances.

    This commit finishes the conversion. While I touched the lines,
    I also fixed the indentation.

    There are a variety of indentation styles found.

    a) 4 spaces + '---help---'
    b) 7 spaces + '---help---'
    c) 8 spaces + '---help---'
    d) 1 space + 1 tab + '---help---'
    e) 1 tab + '---help---' (correct indentation)
    f) 1 tab + 1 space + '---help---'
    g) 1 tab + 2 spaces + '---help---'

    In order to convert all of them to 1 tab + 'help', I ran the
    following commend:

    $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

22 May, 2020

2 commits

  • The current codebase makes use of the zero-length array language
    extension to the C90 standard, but the preferred mechanism to declare
    variable-length types such as these ones is a flexible array member[1][2],
    introduced in C99:

    struct foo {
    int stuff;
    struct boo array[];
    };

    By making use of the mechanism above, we will get a compiler warning
    in case the flexible array does not occur last in the structure, which
    will help us prevent some kind of undefined behavior bugs from being
    inadvertently introduced[3] to the codebase from now on.

    Also, notice that, dynamic memory allocations won't be affected by
    this change:

    "Flexible array members have incomplete type, and so the sizeof operator
    may not be applied. As a quirk of the original implementation of
    zero-length arrays, sizeof evaluates to zero."[1]

    sizeof(flexible-array-member) triggers a warning because flexible array
    members have incomplete type[1]. There are some instances of code in
    which the sizeof operator is being incorrectly/erroneously applied to
    zero-length arrays and the result is zero. Such instances may be hiding
    some bugs. So, this work (flexible-array member conversions) will also
    help to get completely rid of those sorts of issues.

    Also, the following issue shows up due to the flexible-array member
    having incomplete type[4]:

    drivers/char/tpm/eventlog/tpm2.c: In function ‘tpm2_bios_measurements_start’:
    drivers/char/tpm/eventlog/tpm2.c:54:46: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
    54 | size = sizeof(struct tcg_pcr_event) - sizeof(event_header->event)
    | ^
    drivers/char/tpm/eventlog/tpm2.c: In function ‘tpm2_bios_measurements_next’:
    drivers/char/tpm/eventlog/tpm2.c:102:10: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
    102 | sizeof(event_header->event) + event_header->event_size;
    | ^
    drivers/char/tpm/eventlog/tpm2.c: In function ‘tpm2_binary_bios_measurements_show’:
    drivers/char/tpm/eventlog/tpm2.c:140:10: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
    140 | sizeof(event_header->event) + event_header->event_size;
    | ^
    scripts/Makefile.build:266: recipe for target 'drivers/char/tpm/eventlog/tpm2.o' failed
    make[3]: *** [drivers/char/tpm/eventlog/tpm2.o] Error 1

    As mentioned above: "Flexible array members have incomplete type, and
    so the sizeof operator may not be applied. As a quirk of the original
    implementation of zero-length arrays, sizeof evaluates to zero."[1] As
    in "sizeof(event_header->event) always evaluated to 0, so removing it
    has no effect".

    Lastly, make use of the struct_size() helper to deal with the
    flexible array member and its host structure.

    This issue was found with the help of Coccinelle.

    [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
    [2] https://github.com/KSPP/linux/issues/21
    [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")
    [4] https://github.com/KSPP/linux/issues/43

    Signed-off-by: Gustavo A. R. Silva
    Reviewed-by: Kees Cook
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Gustavo A. R. Silva
     
  • There is export_uuid() function which exports uuid_t to the u8 array.
    Use it instead of open coding variant.

    This allows to hide the uuid_t internals.

    Signed-off-by: Andy Shevchenko
    Acked-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Andy Shevchenko
     

21 Apr, 2020

4 commits

  • Call disable_interrupts() if we have to revert to polling in order not to
    unnecessarily reserve the IRQ for the life-cycle of the driver.

    Cc: stable@vger.kernel.org # 4.5.x
    Reported-by: Hans de Goede
    Fixes: e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
    Signed-off-by: Jarkko Sakkinen

    Jarkko Sakkinen
     
  • For the algorithm that does not match the bank, a positive
    value EINVAL is returned here. I think this is a typo error.
    It is necessary to return an error value.

    Cc: stable@vger.kernel.org # 5.4.x
    Fixes: 9f75c8224631 ("KEYS: trusted: correctly initialize digests and fix locking issue")
    Signed-off-by: Tianjia Zhang
    Reviewed-by: Roberto Sassu
    Reviewed-by: Jerry Snitselaar
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Tianjia Zhang
     
  • tpm_ibmvtpm_send() can fail during PowerVM Live Partition Mobility resume
    with an H_CLOSED return from ibmvtpm_send_crq(). The PAPR says, 'The
    "partner partition suspended" transport event disables the associated CRQ
    such that any H_SEND_CRQ hcall() to the associated CRQ returns H_Closed
    until the CRQ has been explicitly enabled using the H_ENABLE_CRQ hcall.'
    This patch adds a check in tpm_ibmvtpm_send() for an H_CLOSED return from
    ibmvtpm_send_crq() and in that case calls tpm_ibmvtpm_resume() and
    retries the ibmvtpm_send_crq() once.

    Cc: stable@vger.kernel.org # 3.7.x
    Fixes: 132f76294744 ("drivers/char/tpm: Add new device driver to support IBM vTPM")
    Reported-by: Linh Pham
    Reviewed-by: Stefan Berger
    Signed-off-by: George Wilson
    Tested-by: Linh Pham
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    George Wilson
     
  • This patch fixes the following problem when the ibmvtpm driver
    is built as a module:

    ERROR: modpost: "tpm2_get_cc_attrs_tbl" [drivers/char/tpm/tpm_ibmvtpm.ko] undefined!
    make[1]: *** [scripts/Makefile.modpost:94: __modpost] Error 1
    make: *** [Makefile:1298: modules] Error 2

    Fixes: 18b3670d79ae ("tpm: ibmvtpm: Add support for TPM2")
    Signed-off-by: Stefan Berger
    Reported-by: Sachin Sant
    Tested-by: Sachin Sant
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Stefan Berger
     

06 Apr, 2020

1 commit

  • Commit 9255782f7061 ("sysfs: Wrap __compat_only_sysfs_link_entry_to_kobj
    function to change the symlink name") made this function a wrapper
    around a new non-underscored function, which is a bit odd. The normal
    naming convention is the other way around: the underscored function is
    the wrappee, and the non-underscored function is the wrapper.

    There's only one single user (well, two call-sites in that user) of the
    more limited double underscore version of this function, so just remove
    the oddly named wrapper entirely and just add the extra NULL argument to
    the user.

    I considered just doing that in the merge, but that tends to make
    history really hard to read.

    Link: https://lore.kernel.org/lkml/CAHk-=wgkkmNV5tMzQDmPAQuNJBuMcry--Jb+h8H1o4RA3kF7QQ@mail.gmail.com/
    Cc: Sourabh Jain
    Cc: Michael Ellerman
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

16 Mar, 2020

2 commits

  • Support TPM2 in the IBM vTPM driver. The hypervisor tells us what
    version of TPM is connected through the vio_device_id.

    In case a TPM2 device is found, we set the TPM_CHIP_FLAG_TPM2 flag
    and get the command codes attributes table. The driver does
    not need the timeouts and durations, though.

    Signed-off-by: Stefan Berger
    Acked-by: Nayna Jain
    Tested-by: Nayna Jain
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Stefan Berger
     
  • Synchronize with the results from the CRQs before continuing with
    the initialization. This avoids trying to send TPM commands while
    the rtce buffer has not been allocated, yet.

    This patch fixes an existing race condition that may occurr if the
    hypervisor does not quickly respond to the VTPM_GET_RTCE_BUFFER_SIZE
    request sent during initialization and therefore the ibmvtpm->rtce_buf
    has not been allocated at the time the first TPM command is sent.

    Fixes: 132f76294744 ("drivers/char/tpm: Add new device driver to support IBM vTPM")
    Signed-off-by: Stefan Berger
    Acked-by: Nayna Jain
    Tested-by: Nayna Jain
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Stefan Berger
     

13 Mar, 2020

6 commits

  • A vTPM 2.0 is identified by 'IBM,vtpm20' in the 'compatible' node in
    the device tree. Handle it in the same way as 'IBM,vtpm'.

    The vTPM 2.0's log is written in little endian format so that for this
    aspect we can rely on existing code.

    Signed-off-by: Stefan Berger
    Acked-by: Nayna Jain
    Tested-by: Nayna Jain
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Stefan Berger
     
  • In a recent change to the SPI subsystem [1], a new `delay` struct was added
    to replace the `delay_usecs`. This change replaces the current
    `delay_usecs` with `delay` for this driver.

    The `spi_transfer_delay_exec()` function [in the SPI framework] makes sure
    that both `delay_usecs` & `delay` are used (in this order to preserve
    backwards compatibility).

    [1] commit bebcfd272df6 ("spi: introduce `delay` field for
    `spi_transfer` + spi_transfer_delay_exec()")

    Signed-off-by: Sergiu Cuciurean
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Sergiu Cuciurean
     
  • In a recent change to the SPI subsystem [1], a new 'delay' struct was added
    to replace the 'delay_usecs'. This change replaces the current
    'delay_usecs' with 'delay' for this driver.

    The 'spi_transfer_delay_exec()' function [in the SPI framework] makes sure
    that both 'delay_usecs' & 'delay' are used (in this order to preserve
    backwards compatibility).

    [1] commit bebcfd272df6485 ("spi: introduce `delay` field for
    `spi_transfer` + spi_transfer_delay_exec()")

    Signed-off-by: Alexandru Ardelean
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Alexandru Ardelean
     
  • If .next function does not change position index,
    following .show function will repeat output related
    to current position index.

    For /sys/kernel/security/tpm0/binary_bios_measurements:
    1) read after lseek beyound end of file generates whole last line.
    2) read after lseek to middle of last line generates
    expected end of last line and unexpected whole last line once again.

    Cc: stable@vger.kernel.org # 4.19.x
    Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283
    Signed-off-by: Vasily Averin
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Vasily Averin
     
  • If .next function does not change position index,
    following .show function will repeat output related
    to current position index.

    In case of /sys/kernel/security/tpm0/ascii_bios_measurements
    and binary_bios_measurements:
    1) read after lseek beyound end of file generates whole last line.
    2) read after lseek to middle of last line generates
    expected end of last line and unexpected whole last line once again.

    Cc: stable@vger.kernel.org # 4.19.x
    Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283
    Signed-off-by: Vasily Averin
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Vasily Averin
     
  • If a TPM is in disabled state, it's reasonable for it to have an empty
    log. Bailing out of probe in this case means that the PPI interface
    isn't available, so there's no way to then enable the TPM from the OS.
    In general it seems reasonable to ignore log errors - they shouldn't
    interfere with any other TPM functionality.

    Signed-off-by: Matthew Garrett
    Cc: stable@vger.kernel.org # 4.19.x
    Reviewed-by: Jerry Snitselaar
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Matthew Garrett
     

18 Feb, 2020

2 commits

  • chip->allocated_banks, an array of tpm_bank_info structures, contains the
    list of TPM algorithm IDs of allocated PCR banks. It also contains the
    corresponding ID of the crypto subsystem, so that users of the TPM driver
    can calculate a digest for a PCR extend operation.

    However, if there is no mapping between TPM algorithm ID and crypto ID, the
    crypto_id field of tpm_bank_info remains set to zero (the array is
    allocated and initialized with kcalloc() in tpm2_get_pcr_allocation()).
    Zero should not be used as value for unknown mappings, as it is a valid
    crypto ID (HASH_ALGO_MD4).

    Thus, initialize crypto_id to HASH_ALGO__LAST.

    Cc: stable@vger.kernel.org # 5.1.x
    Fixes: 879b589210a9 ("tpm: retrieve digest size of unknown algorithms with PCR read")
    Signed-off-by: Roberto Sassu
    Reviewed-by: Petr Vorel
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Roberto Sassu
     
  • Revert tpm_tis_spi_mod.ko back to tpm_tis_spi.ko as the rename could
    break user space scripts. This can be achieved by renaming tpm_tis_spi.c
    as tpm_tis_spi_main.c. Then tpm_tis_spi-y can be used inside the
    makefile.

    Cc: Andrey Pronin
    Cc: Stephen Boyd
    Cc: stable@vger.kernel.org # 5.5.x
    Fixes: 797c0113c9a4 ("tpm: tpm_tis_spi: Support cr50 devices")
    Reported-by: Alexander Steffen
    Tested-by: Alexander Steffen
    Reviewed-by: Stephen Boyd
    Signed-off-by: Jarkko Sakkinen

    Jarkko Sakkinen
     

22 Jan, 2020

1 commit

  • Easily determining what TCG version a tpm device implements
    has been a pain point for userspace for a long time, so
    add a sysfs file to report the TCG major version of a tpm device.

    Also add an entry to Documentation/ABI/stable/sysfs-class-tpm
    describing the new file.

    Cc: Jarkko Sakkinen
    Cc: Mimi Zohar
    Cc: Peter Huewe
    Cc: Jason Gunthorpe
    Cc: linux-integrity@vger.kernel.org
    Signed-off-by: Jerry Snitselaar
    Reviewed-by: Mimi Zohar
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Jerry Snitselaar
     

09 Jan, 2020

1 commit

  • The priv->response_length can hold the size of an response or an negative
    error code, and the tpm_common_read() needs to handle both cases correctly.
    Changed the type of response_length to signed and accounted for negative
    value in tpm_common_read().

    Cc: stable@vger.kernel.org
    Fixes: d23d12484307 ("tpm: fix invalid locking in NONBLOCKING mode")
    Reported-by: Laura Abbott
    Signed-off-by: Tadeusz Struk
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Tadeusz Struk
     

07 Jan, 2020

2 commits

  • There has been a bunch of reports (one from kernel bugzilla linked)
    reporting that when this commit is applied it causes on some machines
    boot freezes.

    Unfortunately hardware where this commit causes a failure is not widely
    available (only one I'm aware is Lenovo T490), which means we cannot
    predict yet how long it will take to properly fix tpm_tis interrupt
    probing.

    Thus, the least worst short term action is to revert the code to the
    state before this commit. In long term we need fix the tpm_tis probing
    code to work on machines that Stefan's fix was supposed to fix.

    Fixes: 21df4a8b6018 ("tpm_tis: reserve chip for duration of tpm_tis_core_init")
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=205935
    Cc: stable@vger.kernel.org
    Cc: Jerry Snitselaar
    Cc: Dan Williams
    Tested-by: Dan Williams
    Tested-by: Xiaoping Zhou
    Signed-off-by: Stefan Berger
    Reported-by: Jerry Snitselaar
    Signed-off-by: Jarkko Sakkinen

    Stefan Berger
     
  • There has been a bunch of reports (one from kernel bugzilla linked)
    reporting that when this commit is applied it causes on some machines
    boot freezes.

    Unfortunately hardware where this commit causes a failure is not widely
    available (only one I'm aware is Lenovo T490), which means we cannot
    predict yet how long it will take to properly fix tpm_tis interrupt
    probing.

    Thus, the least worst short term action is to revert the code to the
    state before this commit. In long term we need fix the tpm_tis probing
    code to work on machines that Stefan's fix was supposed to fix.

    Link: https://bugzilla.kernel.org/show_bug.cgi?id=205935
    Fixes: 1ea32c83c699 ("tpm_tis_core: Set TPM_CHIP_FLAG_IRQ before probing for interrupts")
    Cc: stable@vger.kernel.org
    Cc: Jerry Snitselaar
    Cc: Dan Williams
    Tested-by: Dan Williams
    Tested-by: Xiaoping Zhou
    Signed-off-by: Stefan Berger
    Reported-by: Jerry Snitselaar
    Signed-off-by: Jarkko Sakkinen

    Stefan Berger