All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Kylene Jo Hall <kjhall@us.ibm.com>
Cc: linux-kernel@vger.kernel.org, tpmdd-devel@lists.sourceforge.net
Subject: Re: [PATCH 2/7] tpm: reorganize sysfs files - Updated patch
Date: Mon, 10 Apr 2006 14:46:23 -0700	[thread overview]
Message-ID: <20060410144623.110895d0.akpm@osdl.org> (raw)
In-Reply-To: <1144679825.4917.10.camel@localhost.localdomain>

Kylene Jo Hall <kjhall@us.ibm.com> wrote:
>
>  ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
>   		      char *buf)
>   {
>  -	u8 data[READ_PCR_RESULT_SIZE];
>  -	ssize_t len;
>  +	u8 data[30];
>  +	ssize_t rc;
>   	int i, j, num_pcrs;
>   	__be32 index;
>   	char *str = buf;
>  @@ -150,29 +190,24 @@ ssize_t tpm_show_pcrs(struct device *dev
>   	if (chip == NULL)
>   		return -ENODEV;
>   
>  -	memcpy(data, cap_pcr, sizeof(cap_pcr));
>  -	if ((len = tpm_transmit(chip, data, sizeof(data)))
>  -	    < CAP_PCR_RESULT_SIZE) {
>  -		dev_dbg(chip->dev, "A TPM error (%d) occurred "
>  -				"attempting to determine the number of PCRS\n",
>  -			be32_to_cpu(*((__be32 *) (data + 6))));
>  +	memcpy(data, tpm_cap, sizeof(tpm_cap));

I'd be a bit worried about potential for array overruns here.  If someone
later were to increase the size of tpm_cap[] we'll silently overrun data[].

One approach would be to do:

--- devel/drivers/char/tpm/tpm.c~tpm-reorganize-sysfs-files-fix	2006-04-10 14:43:16.000000000 -0700
+++ devel-akpm/drivers/char/tpm/tpm.c	2006-04-10 14:45:19.000000000 -0700
@@ -180,7 +180,7 @@ static const u8 pcrread[] = {
 ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
 		      char *buf)
 {
-	u8 data[30];
+	u8 data[ARRAY_SIZE(tpm_cap)];
 	ssize_t rc;
 	int i, j, num_pcrs;
 	__be32 index;
@@ -296,7 +296,7 @@ static const u8 cap_version[] = {
 ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
 		      char *buf)
 {
-	u8 data[30];
+	u8 data[max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(cap_version))];
 	ssize_t rc;
 	char *str = buf;
 
_


Does that look OK?

  reply	other threads:[~2006-04-10 22:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-10 14:37 [PATCH 2/7] tpm: reorganize sysfs files - Updated patch Kylene Jo Hall
2006-04-10 21:46 ` Andrew Morton [this message]
2006-04-11 14:24   ` Kylene Jo Hall
2006-04-11 18:18     ` Andrew Morton
2006-04-11 20:15       ` [PATCH] tpm: sysfs function buffer size fix Kylene Jo Hall
2006-04-11 20:45         ` Ingo Oeser
2006-04-11 21:05           ` Kylene Jo Hall
2006-04-11 22:32             ` [PATCH] tpm: compiler cleanup Kylene Jo Hall
  -- strict thread matches above, loose matches on Subject: below --
2006-04-05 19:48 [PATCH 2/7] tpm: reorganize sysfs files - Updated patch Kylene Jo Hall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060410144623.110895d0.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=kjhall@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tpmdd-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.