tpm-interface.c (a147918e79c3a239be59358af659ea9f0959538b) tpm-interface.c (58472f5cd4f6ff02488c8da3cdbf719e9dd21e48)
1/*
2 * Copyright (C) 2004 IBM Corporation
3 * Copyright (C) 2014 Intel Corporation
4 *
5 * Authors:
6 * Leendert van Doorn <leendert@watson.ibm.com>
7 * Dave Safford <safford@watson.ibm.com>
8 * Reiner Sailer <sailer@watson.ibm.com>

--- 314 unchanged lines hidden (view full) ---

323 duration = chip->duration[duration_idx];
324 if (duration <= 0)
325 return 2 * 60 * HZ;
326 else
327 return duration;
328}
329EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
330
1/*
2 * Copyright (C) 2004 IBM Corporation
3 * Copyright (C) 2014 Intel Corporation
4 *
5 * Authors:
6 * Leendert van Doorn <leendert@watson.ibm.com>
7 * Dave Safford <safford@watson.ibm.com>
8 * Reiner Sailer <sailer@watson.ibm.com>

--- 314 unchanged lines hidden (view full) ---

323 duration = chip->duration[duration_idx];
324 if (duration <= 0)
325 return 2 * 60 * HZ;
326 else
327 return duration;
328}
329EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
330
331static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd,
332 size_t len)
333{
334 const struct tpm_input_header *header = (const void *)cmd;
335 int i;
336 u32 cc;
337 u32 attrs;
338 unsigned int nr_handles;
339
340 if (len < TPM_HEADER_SIZE)
341 return false;
342
343 if (chip->flags & TPM_CHIP_FLAG_TPM2 && chip->nr_commands) {
344 cc = be32_to_cpu(header->ordinal);
345
346 i = tpm2_find_cc(chip, cc);
347 if (i < 0) {
348 dev_dbg(&chip->dev, "0x%04X is an invalid command\n",
349 cc);
350 return false;
351 }
352
353 attrs = chip->cc_attrs_tbl[i];
354 nr_handles =
355 4 * ((attrs >> TPM2_CC_ATTR_CHANDLES) & GENMASK(2, 0));
356 if (len < TPM_HEADER_SIZE + 4 * nr_handles)
357 goto err_len;
358 }
359
360 return true;
361err_len:
362 dev_dbg(&chip->dev,
363 "%s: insufficient command length %zu", __func__, len);
364 return false;
365}
366
331/**
332 * tmp_transmit - Internal kernel interface to transmit TPM commands.
333 *
334 * @chip: TPM chip to use
335 * @buf: TPM command buffer
336 * @bufsiz: length of the TPM command buffer
337 * @flags: tpm transmit flags - bitmap
338 *

--- 4 unchanged lines hidden (view full) ---

343ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
344 unsigned int flags)
345{
346 const struct tpm_output_header *header = (void *)buf;
347 ssize_t rc;
348 u32 count, ordinal;
349 unsigned long stop;
350
367/**
368 * tmp_transmit - Internal kernel interface to transmit TPM commands.
369 *
370 * @chip: TPM chip to use
371 * @buf: TPM command buffer
372 * @bufsiz: length of the TPM command buffer
373 * @flags: tpm transmit flags - bitmap
374 *

--- 4 unchanged lines hidden (view full) ---

379ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
380 unsigned int flags)
381{
382 const struct tpm_output_header *header = (void *)buf;
383 ssize_t rc;
384 u32 count, ordinal;
385 unsigned long stop;
386
351 if (bufsiz < TPM_HEADER_SIZE)
387 if (!tpm_validate_command(chip, buf, bufsiz))
352 return -EINVAL;
353
354 if (bufsiz > TPM_BUFSIZE)
355 bufsiz = TPM_BUFSIZE;
356
357 count = be32_to_cpu(*((__be32 *) (buf + 2)));
358 ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
359 if (count == 0)

--- 876 unchanged lines hidden ---
388 return -EINVAL;
389
390 if (bufsiz > TPM_BUFSIZE)
391 bufsiz = TPM_BUFSIZE;
392
393 count = be32_to_cpu(*((__be32 *) (buf + 2)));
394 ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
395 if (count == 0)

--- 876 unchanged lines hidden ---