tpm: xen-tpmfront: Use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows. Also, address the following sparse warning: drivers/char/tpm/xen-tpmfront.c:131:16: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/160 Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
This commit is contained in:
parent
8bdc3e05cc
commit
2dd634664d
|
@ -126,16 +126,16 @@ static void vtpm_cancel(struct tpm_chip *chip)
|
||||||
notify_remote_via_evtchn(priv->evtchn);
|
notify_remote_via_evtchn(priv->evtchn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int shr_data_offset(struct vtpm_shared_page *shr)
|
static size_t shr_data_offset(struct vtpm_shared_page *shr)
|
||||||
{
|
{
|
||||||
return sizeof(*shr) + sizeof(u32) * shr->nr_extra_pages;
|
return struct_size(shr, extra_pages, shr->nr_extra_pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
|
static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct tpm_private *priv = dev_get_drvdata(&chip->dev);
|
struct tpm_private *priv = dev_get_drvdata(&chip->dev);
|
||||||
struct vtpm_shared_page *shr = priv->shr;
|
struct vtpm_shared_page *shr = priv->shr;
|
||||||
unsigned int offset = shr_data_offset(shr);
|
size_t offset = shr_data_offset(shr);
|
||||||
|
|
||||||
u32 ordinal;
|
u32 ordinal;
|
||||||
unsigned long duration;
|
unsigned long duration;
|
||||||
|
@ -177,7 +177,7 @@ static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct tpm_private *priv = dev_get_drvdata(&chip->dev);
|
struct tpm_private *priv = dev_get_drvdata(&chip->dev);
|
||||||
struct vtpm_shared_page *shr = priv->shr;
|
struct vtpm_shared_page *shr = priv->shr;
|
||||||
unsigned int offset = shr_data_offset(shr);
|
size_t offset = shr_data_offset(shr);
|
||||||
size_t length = shr->length;
|
size_t length = shr->length;
|
||||||
|
|
||||||
if (shr->state == VTPM_STATE_IDLE)
|
if (shr->state == VTPM_STATE_IDLE)
|
||||||
|
|
Loading…
Reference in New Issue