Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 16991
b: refs/heads/master
c: d09cf7d
h: refs/heads/master
i:
  16989: 02bbf32
  16987: bbda763
  16983: 01b99a6
  16975: 72c7575
  16959: 66773f3
v: v3
  • Loading branch information
Kylene Jo Hall authored and Linus Torvalds committed Jan 9, 2006
1 parent 37e7a6b commit 54619c1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 31 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5e38291d80086f6972f471c7caffa03184de0bf0
refs/heads/master: d09cf7d77f62f6fb2f6d63fe5980583805f2d559
92 changes: 62 additions & 30 deletions trunk/drivers/char/tpm/tpm_bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#define MAX_TEXT_EVENT 1000 /* Max event string length */
#define ACPI_TCPA_SIG "TCPA" /* 0x41504354 /'TCPA' */

struct tpm_bios_log {
void *bios_event_log;
void *bios_event_log_end;
};

struct acpi_tcpa {
struct acpi_table_header hdr;
u16 reserved;
Expand Down Expand Up @@ -117,39 +122,34 @@ static const char* tcpa_pc_event_id_strings[] = {
"S-CRTM POST Contents",
};

/* (Binary) bios measurement buffer */
static void *tcg_eventlog;
static void *tcg_eventlog_addr_limit; /* MAX */

/* returns pointer to start of pos. entry of tcg log */
static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
{
loff_t i;
void *addr = tcg_eventlog;
struct tpm_bios_log *log = m->private;
void *addr = log->bios_event_log;
void *limit = log->bios_event_log_end;
struct tcpa_event *event;

/* read over *pos measurements */
for (i = 0; i < *pos; i++) {
event = addr;

if ((addr + sizeof(struct tcpa_event)) <
tcg_eventlog_addr_limit) {
if ((addr + sizeof(struct tcpa_event)) < limit) {
if (event->event_type == 0 && event->event_size == 0)
return NULL;
addr +=
sizeof(struct tcpa_event) + event->event_size;
addr += sizeof(struct tcpa_event) + event->event_size;
}
}

/* now check if current entry is valid */
if ((addr + sizeof(struct tcpa_event)) >= tcg_eventlog_addr_limit)
if ((addr + sizeof(struct tcpa_event)) >= limit)
return NULL;

event = addr;

if ((event->event_type == 0 && event->event_size == 0) ||
((addr + sizeof(struct tcpa_event) + event->event_size) >=
tcg_eventlog_addr_limit))
((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
return NULL;

return addr;
Expand All @@ -159,11 +159,13 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
loff_t *pos)
{
struct tcpa_event *event = v;
struct tpm_bios_log *log = m->private;
void *limit = log->bios_event_log_end;

v += sizeof(struct tcpa_event) + event->event_size;

/* now check if current entry is valid */
if ((v + sizeof(struct tcpa_event)) >= tcg_eventlog_addr_limit)
if ((v + sizeof(struct tcpa_event)) >= limit)
return NULL;

event = v;
Expand All @@ -172,8 +174,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
return NULL;

if ((event->event_type == 0 && event->event_size == 0) ||
((v + sizeof(struct tcpa_event) + event->event_size) >=
tcg_eventlog_addr_limit))
((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
return NULL;

(*pos)++;
Expand Down Expand Up @@ -312,10 +313,14 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
static int tpm_bios_measurements_release(struct inode *inode,
struct file *file)
{
if (tcg_eventlog) {
kfree(tcg_eventlog);
tcg_eventlog = NULL;
struct seq_file *seq = file->private_data;
struct tpm_bios_log *log = seq->private;

if (log) {
kfree(log->bios_event_log);
kfree(log);
}

return seq_release(inode, file);
}

Expand Down Expand Up @@ -367,13 +372,13 @@ static struct seq_operations tpm_binary_b_measurments_seqops = {
};

/* read binary bios log */
static int read_log(void)
static int read_log(struct tpm_bios_log *log)
{
struct acpi_tcpa *buff;
acpi_status status;
void *virt;

if (tcg_eventlog != NULL) {
if (log->bios_event_log != NULL) {
printk(KERN_ERR
"%s: ERROR - Eventlog already initialized\n",
__func__);
Expand All @@ -393,25 +398,24 @@ static int read_log(void)
}

if (buff->log_max_len == 0) {
printk(KERN_ERR "%s: ERROR - TCPA log area empty\n",
__func__);
printk(KERN_ERR "%s: ERROR - TCPA log area empty\n", __func__);
return -EIO;
}

/* malloc EventLog space */
tcg_eventlog = kmalloc(buff->log_max_len, GFP_KERNEL);
if (!tcg_eventlog) {
log->bios_event_log = kmalloc(buff->log_max_len, GFP_KERNEL);
if (!log->bios_event_log) {
printk
("%s: ERROR - Not enough Memory for BIOS measurements\n",
__func__);
return -ENOMEM;
}

tcg_eventlog_addr_limit = tcg_eventlog + buff->log_max_len;
log->bios_event_log_end = log->bios_event_log + buff->log_max_len;

acpi_os_map_memory(buff->log_start_addr, buff->log_max_len, &virt);

memcpy(tcg_eventlog, virt, buff->log_max_len);
memcpy(log->bios_event_log, virt, buff->log_max_len);

acpi_os_unmap_memory(virt, buff->log_max_len);
return 0;
Expand All @@ -421,12 +425,26 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode,
struct file *file)
{
int err;
struct tpm_bios_log *log;
struct seq_file *seq;

if ((err = read_log()))
log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
if (!log)
return -ENOMEM;

if ((err = read_log(log)))
return err;

/* now register seq file */
return seq_open(file, &tpm_ascii_b_measurments_seqops);
err = seq_open(file, &tpm_ascii_b_measurments_seqops);
if (!err) {
seq = file->private_data;
seq->private = log;
} else {
kfree(log->bios_event_log);
kfree(log);
}
return err;
}

struct file_operations tpm_ascii_bios_measurements_ops = {
Expand All @@ -440,12 +458,26 @@ static int tpm_binary_bios_measurements_open(struct inode *inode,
struct file *file)
{
int err;
struct tpm_bios_log *log;
struct seq_file *seq;

if ((err = read_log()))
log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
if (!log)
return -ENOMEM;

if ((err = read_log(log)))
return err;

/* now register seq file */
return seq_open(file, &tpm_binary_b_measurments_seqops);
err = seq_open(file, &tpm_binary_b_measurments_seqops);
if (!err) {
seq = file->private_data;
seq->private = log;
} else {
kfree(log->bios_event_log);
kfree(log);
}
return err;
}

struct file_operations tpm_binary_bios_measurements_ops = {
Expand Down

0 comments on commit 54619c1

Please sign in to comment.