linux/include/media
Hans Verkuil 2fc11536cf V4L/DVB: videobuf-dma-sg: set correct size in last sg element
This fixes a nasty memory corruption bug when using userptr I/O.
The function videobuf_pages_to_sg() sets up the scatter-gather list for the
DMA transfer to the userspace pages. The first transfer is setup correctly
(the size is set to PAGE_SIZE - offset), but all other transfers have size
PAGE_SIZE. This is wrong for the last transfer which may be less than PAGE_SIZE.

Most, if not all, drivers will program the boards DMA engine correctly, i.e.
even though the size in the last sg element is wrong, they will do their
own size calculations and make sure the right amount is DMA-ed, and so seemingly
prevent memory corruption.

However, behind the scenes the dynamic DMA mapping support (in lib/swiotlb.c)
may create bounce buffers if the memory pages are not in DMA-able memory.
This happens for example on a 64-bit linux with a board that only supports
32-bit DMA.

These bounce buffers DO use the information in the sg list to determine the
size. So while the DMA engine transfers the correct amount of data, when the
data is 'bounced' back too much is copied, causing buffer overwrites.

The fix is simple: calculate and set the correct size for the last sg list
element.

Signed-off-by: Hans Verkuil <hans.verkuil@tandberg.com>
Cc: stable@kernel.org
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2010-09-27 22:22:01 -03:00
..
davinci
adv7343.h
ak881x.h
bt819.h
cs53l32a.h
cs5345.h
cx2341x.h V4L/DVB: cx2341x: convert to the control framework 2010-08-08 23:43:05 -03:00
cx25840.h V4L/DVB: cx25840/ivtv: replace ugly priv control with s_config 2010-08-08 23:43:05 -03:00
i2c-addr.h
ir-common.h
ir-core.h V4L/DVB: IR: extend interfaces to support more device settings 2010-08-08 23:43:00 -03:00
ir-kbd-i2c.h
lirc.h V4L/DVB: IR: extend interfaces to support more device settings 2010-08-08 23:43:00 -03:00
lirc_dev.h
m52790.h
msp3400.h
mt9t112.h
ov772x.h
ovcamchip.h
pwc-ioctl.h
radio-si4713.h
rc-map.h V4L/DVB: staging/lirc: port lirc_streamzap to ir-core 2010-08-08 23:42:58 -03:00
rds.h
rj54n1cb0c.h
saa6752hs.h
saa7115.h
saa7127.h
saa7146.h
saa7146_vv.h
sh_mobile_ceu.h
sh_mobile_csi2.h
sh_vou.h
si4713.h
soc_camera.h
soc_camera_platform.h
soc_mediabus.h
timb_radio.h
tuner-types.h
tuner.h
tvaudio.h
tveeprom.h
tvp514x.h
tvp5150.h
tvp7002.h
tw9910.h
upd64031a.h
upd64083.h
v4l2-chip-ident.h
v4l2-common.h
v4l2-ctrls.h V4L/DVB: v4l2: Add new control handling framework 2010-08-08 23:43:03 -03:00
v4l2-dev.h V4L/DVB: v4l2: Add new control handling framework 2010-08-08 23:43:03 -03:00
v4l2-device.h V4L/DVB: v4l2: Add new control handling framework 2010-08-08 23:43:03 -03:00
v4l2-event.h
v4l2-fh.h
v4l2-i2c-drv.h
v4l2-int-device.h
v4l2-ioctl.h
v4l2-mediabus.h
v4l2-mem2mem.h
v4l2-subdev.h V4L/DVB: v4l2: Add new control handling framework 2010-08-08 23:43:03 -03:00
videobuf-core.h
videobuf-dma-contig.h
videobuf-dma-sg.h V4L/DVB: videobuf-dma-sg: set correct size in last sg element 2010-09-27 22:22:01 -03:00
videobuf-dvb.h
videobuf-vmalloc.h
wm8775.h