Skip to content

staging: vc04_services: fix pointer arithmetic in create_pagelist - #7593

Merged
pelwell merged 4 commits into
raspberrypi:rpi-6.18.yfrom
nolasoft:rpi-6.18.y
Sep 3, 2026
Merged

staging: vc04_services: fix pointer arithmetic in create_pagelist#7593
pelwell merged 4 commits into
raspberrypi:rpi-6.18.yfrom
nolasoft:rpi-6.18.y

Conversation

@nolasoft

@nolasoft nolasoft commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix a pointer-arithmetic bug in the vmalloc handling path of create_pagelist().

Problem

In drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c:

struct page *pg =
    vmalloc_to_page(((unsigned int *)bulk->offset +
                     (actual_pages * PAGE_SIZE)));

Adding an integer to an unsigned int * multiplies the offset by sizeof(unsigned int) (4). Consequently the address becomes:bulk->offset + (actual_pages * PAGE_SIZE * 4)instead of the intended:bulk->offset + (actual_pages * PAGE_SIZE)Only the first page is correct; later pages are wrong. This can lead to
incorrect DMA mappings, data corruption, or NULL page pointers.

In the vmalloc path of create_pagelist(), the address passed to
vmalloc_to_page() was computed as:

    (unsigned int *)bulk->offset + (actual_pages * PAGE_SIZE)

Because pointer arithmetic on unsigned int * scales by sizeof(unsigned int),
this advances by 4 * PAGE_SIZE bytes instead of PAGE_SIZE. As a result,
only the first page is correct; subsequent pages point to the wrong
addresses.

Cast through char * (or void *) so the offset is applied in bytes.
@pelwell

pelwell commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

This looks like a valid fix to me. You should add:

Fixes: 0d2df8b10b54 ("staging: vchiq_core: Subsume 'offset' in struct vchiq_bulk")

FYI @uajain, who may want to upstream this himself.

vmalloc_to_page(((unsigned int *)bulk->offset +
(actual_pages * PAGE_SIZE)));
vmalloc_to_page((void *)((char *)bulk->offset +
(actual_pages * PAGE_SIZE)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build failure due to missing ; from the end of the line.

Comment thread drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c Outdated
@popcornmix

Copy link
Copy Markdown
Collaborator

Looks like this affects the legacy camera stack (bcm2835-camera) and legacy audio (bcm2835-audio, but only when force_bulk=1 or firmware peer_version<2).
Most other cases use zero copy, so don't hit this code.
Neither are these are common paths, but they can be enabled and if they are it will be fatal. So nice find.

@6by9

6by9 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Looks like this affects the legacy camera stack (bcm2835-camera)

I did have a report not so long back that bcm2835-camera wasn't working on 6.18. I confirmed that, but wasn't seeing crashes, and hadn't dug into the reason. This would be a plausible explanation.

@pelwell

pelwell commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Replacing (unsigned int *) with (void *) should be sufficient.

@nolasoft

nolasoft commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

now it should be ok, unfortunatly i edited it from github edit tool.

Comment thread drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@pelwell

pelwell commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Thanks - I'll squash the commits and patch up the commit message when I merge it.

@popcornmix

Copy link
Copy Markdown
Collaborator

Drop the spurious blank line when you merge.

@pelwell
pelwell merged commit 8dcfc7d into raspberrypi:rpi-6.18.y Sep 3, 2026
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Sep 4, 2026
kernel: staging: vc04_services: fix pointer arithmetic in create_pagelist
See: raspberrypi/linux#7593

kernel: rp1-pio+dw-axi-dmac: add cyclic DMA support, ability to select light vs heavy DMA
See: raspberrypi/linux#7598

kernel: overlays: ed-backlight-pwm: Add EDATEC PWM backlight overlay
See: raspberrypi/linux#7597

kernel: configs: Add CAN_VXCAN=m
See: raspberrypi/linux#7592

kernel: media/hevc_d: Improve checking and cleanup of decoder
See: raspberrypi/linux#7583

kernel: drm/vc4: hdmi: Don't write past the end of a packet RAM slot
See: raspberrypi/linux#7579

kernel: bcm2835-i2s: fail capture open cleanly when FIFO clear has no clock
See: raspberrypi/linux#7586

kernel: vc04_services: bounds and fd handling fixes
See: raspberrypi/linux#7576

kernel: overlays: wm8960-soundcard: Add media parameter
See: raspberrypi/linux#7577

kernel: overlays: rt5616: Add RT5616 audio codec overlay
See: raspberrypi/linux#7574

kernel: arm64: defconfig: Enable RT5616 codec in Pi configurations
See: raspberrypi/linux#7575
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Sep 4, 2026
kernel: staging: vc04_services: fix pointer arithmetic in create_pagelist
See: raspberrypi/linux#7593

kernel: rp1-pio+dw-axi-dmac: add cyclic DMA support, ability to select light vs heavy DMA
See: raspberrypi/linux#7598

kernel: overlays: ed-backlight-pwm: Add EDATEC PWM backlight overlay
See: raspberrypi/linux#7597

kernel: configs: Add CAN_VXCAN=m
See: raspberrypi/linux#7592

kernel: media/hevc_d: Improve checking and cleanup of decoder
See: raspberrypi/linux#7583

kernel: drm/vc4: hdmi: Don't write past the end of a packet RAM slot
See: raspberrypi/linux#7579

kernel: bcm2835-i2s: fail capture open cleanly when FIFO clear has no clock
See: raspberrypi/linux#7586

kernel: vc04_services: bounds and fd handling fixes
See: raspberrypi/linux#7576

kernel: overlays: wm8960-soundcard: Add media parameter
See: raspberrypi/linux#7577

kernel: overlays: rt5616: Add RT5616 audio codec overlay
See: raspberrypi/linux#7574

kernel: arm64: defconfig: Enable RT5616 codec in Pi configurations
See: raspberrypi/linux#7575
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants