Skip to content

Commit a9370ba

Browse files
committed
Validate Allwinner GPIO base address range
Ensure the retrieved base address fits within a 32-bit integer before mapping the memory. This prevents potential overflows when dealing with addresses on newer or different architecture variants.
1 parent bbc29d3 commit a9370ba

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

allwinner/gpio.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package allwinner
1010
import (
1111
"errors"
1212
"fmt"
13+
"math"
1314
"os"
1415
"path"
1516
"strconv"
@@ -1033,8 +1034,11 @@ func (d *driverGPIO) Init() (bool, error) {
10331034
}
10341035

10351036
// gpioBaseAddr is the physical base address of the GPIO registers.
1036-
gpioBaseAddr := uint32(getBaseAddress())
1037-
if err := pmem.MapAsPOD(uint64(gpioBaseAddr), &d.gpioMemory); err != nil {
1037+
gpioBaseAddr := getBaseAddress()
1038+
if gpioBaseAddr > math.MaxUint32 {
1039+
return true, fmt.Errorf("gpio base address 0x%X overflows uint32", gpioBaseAddr)
1040+
}
1041+
if err := pmem.MapAsPOD(gpioBaseAddr, &d.gpioMemory); err != nil {
10381042
if os.IsPermission(err) {
10391043
return true, fmt.Errorf("need more access, try as root: %v", err)
10401044
}

0 commit comments

Comments
 (0)