Skip to content

memory corruption when using memset32() on RPi Zero #4798

Closed

Description

@npitre

Describe the bug

Any configuration enabling CONFIG_BCM2835_FAST_MEMCPY pulls in
an alternative memset() implementation to be found in
arch/arm/lib/memset_rpi.S.

This alternative implementation aliases __memset32() and __memset64()
to memset() which is totally wrong, resulting in actual memory corruption
whenever memset32() and/or memset64() is used.

Expected behaviour

memset32() is used to fill memory with 32-bit values.
Likewise for memset64().

Actual behaviour

The low 8 bits of provided value are repeated like memset() should do.

System

  • Which model of Raspberry Pi? e.g. Pi3B+, PiZeroW

PiZeroW

  • Which OS and version (cat /etc/rpi-issue)?

All of them.

  • Which firmware version (vcgencmd version)?

N/A

  • Which kernel version (uname -a)?

All kernels since commit 385b89c.

Additional context

I think the inclusion of an alternative memset() in a commit titled
"Improve __copy_to_user and __copy_from_user performance" was wrong
in the first place. There is nothing really that I can see to justify
an alternative implementation for ARMv6 here either, even if it hadn't
broken memset32() which is unacceptable.

Activity

  1. marcone commented on Jan 10, 2022

    @marcone
    Contributor

    The count parameter for memset32 and memset64 is also the number of uint32 or uint64 to store, not the number of bytes, so by aliasing it to memset it's not even going to fill the entire block of memory.
    (scratch that, this is already accounted for when memset32 calls __memset32)
    Still seems like filling memory with the wrong data could be a security issue though.

  2. pelwell commented on Jan 11, 2022

    @pelwell
    Contributor

    If you are in a position to build your own kernel, have a look at #4820 which should fix the problem. Tested with a hacked Kconfig on Pi 4, but should work as-is on Pi Zero etc.

  3. pelwell commented on Jan 11, 2022

    @pelwell
    Contributor

    Should now be fixed in rpi-5.10.y, rpi-5.15.y and rpi-5.16.y.

  4. popcornmix commented on Jan 24, 2022

    @popcornmix
    Collaborator

    @npitre okay to close?

  5. 273 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions