Skip to content

Commit

Permalink
Hardware: Enhance AcpiHwValidateRegister() with AccessWidth/BitOffset…
Browse files Browse the repository at this point in the history
… awareness

This patch enhances AcpiHwValidateRegister() to sanitize register
accesses with awareness of AccessWidth and BitOffset. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
  • Loading branch information
Lv Zheng committed Mar 15, 2016
1 parent cbcb775 commit 997a90f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions source/components/hardware/hwregs.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ AcpiHwValidateRegister (
UINT8 MaxBitWidth,
UINT64 *Address)
{
UINT8 BitWidth;
UINT8 BitEnd;
UINT8 AccessWidth;


/* Must have a valid pointer to a GAS structure */

Expand Down Expand Up @@ -192,24 +196,28 @@ AcpiHwValidateRegister (
return (AE_SUPPORT);
}

/* Validate the BitWidth */
/* Validate the AccessWidth */

if ((Reg->BitWidth != 8) &&
(Reg->BitWidth != 16) &&
(Reg->BitWidth != 32) &&
(Reg->BitWidth != MaxBitWidth))
if (Reg->AccessWidth > 4)
{
ACPI_ERROR ((AE_INFO,
"Unsupported register bit width: 0x%X", Reg->BitWidth));
"Unsupported register access width: 0x%X", Reg->AccessWidth));
return (AE_SUPPORT);
}

/* Validate the BitOffset. Just a warning for now. */
/* Validate the BitWidth, convert AccessWidth into number of bits */

if (Reg->BitOffset != 0)
BitEnd = Reg->BitOffset + Reg->BitWidth;
AccessWidth = Reg->AccessWidth ? Reg->AccessWidth : 1;
AccessWidth = 1 << (AccessWidth + 2);
BitWidth = ACPI_ROUND_UP (BitEnd, AccessWidth) -
ACPI_ROUND_DOWN (Reg->BitOffset, AccessWidth);
if (MaxBitWidth < BitWidth)
{
ACPI_WARNING ((AE_INFO,
"Unsupported register bit offset: 0x%X", Reg->BitOffset));
"Requested bit width 0x%X is smaller than register bit width 0x%X",
MaxBitWidth, BitWidth));
return (AE_SUPPORT);
}

return (AE_OK);
Expand Down

0 comments on commit 997a90f

Please sign in to comment.