android_kernel_samsung_msm8976/drivers
Daniel Mentz 8050f9150f media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic
commit a1dfb4c48cc1e64eeb7800a27c66a6f7e88d075a upstream.

The 32-bit compat v4l2 ioctl handling is implemented based on its 64-bit
equivalent. It converts 32-bit data structures into its 64-bit
equivalents and needs to provide the data to the 64-bit ioctl in user
space memory which is commonly allocated using
compat_alloc_user_space().

However, due to how that function is implemented, it can only be called
a single time for every syscall invocation.

Supposedly to avoid this limitation, the existing code uses a mix of
memory from the kernel stack and memory allocated through
compat_alloc_user_space().

Under normal circumstances, this would not work, because the 64-bit
ioctl expects all pointers to point to user space memory. As a
workaround, set_fs(KERNEL_DS) is called to temporarily disable this
extra safety check and allow kernel pointers. However, this might
introduce a security vulnerability: The result of the 32-bit to 64-bit
conversion is writeable by user space because the output buffer has been
allocated via compat_alloc_user_space(). A malicious user space process
could then manipulate pointers inside this output buffer, and due to the
previous set_fs(KERNEL_DS) call, functions like get_user() or put_user()
no longer prevent kernel memory access.

The new approach is to pre-calculate the total amount of user space
memory that is needed, allocate it using compat_alloc_user_space() and
then divide up the allocated memory to accommodate all data structures
that need to be converted.

An alternative approach would have been to retain the union type karg
that they allocated on the kernel stack in do_video_ioctl(), copy all
data from user space into karg and then back to user space. However, we
decided against this approach because it does not align with other
compat syscall implementations. Instead, we tried to replicate the
get_user/put_user pairs as found in other places in the kernel:

    if (get_user(clipcount, &up->clipcount) ||
        put_user(clipcount, &kp->clipcount)) return -EFAULT;

Notes from hans.verkuil@cisco.com:

This patch was taken from:
    97b733953c

Clearly nobody could be bothered to upstream this patch or at minimum
tell us :-( We only heard about this a week ago.

This patch was rebased and cleaned up. Compared to the original I
also swapped the order of the convert_in_user arguments so that they
matched copy_in_user. It was hard to review otherwise. I also replaced
the ALLOC_USER_SPACE/ALLOC_AND_GET by a normal function.

Fixes: 6b5a9492ca ("v4l: introduce string control support.")

Change-Id: I21922aafd7a3e7f61211a4584155971ea582c87f
Signed-off-by: Daniel Mentz <danielmentz@google.com>
Co-developed-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
[bwh: Rebased on top of some earlier fixes]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
2019-07-27 21:46:39 +02:00
..
accessibility
acpi ACPI: APEI / ERST: Fix missing error handling in erst_reader() 2019-07-27 21:46:19 +02:00
amba
android
ata libata: array underflow in ata_find_dev() 2019-07-27 21:44:15 +02:00
atm
auxdisplay
base PM / Domains: Fix unsafe iteration over modified list of device links 2019-07-27 21:44:14 +02:00
battery
battery_v2
bcma
bif
block
bluetooth
bus
cdrom
char drivers: char: mem: Fix wraparound check to allow mappings up to the end 2019-07-27 21:44:47 +02:00
clk clk: qcom: Remove unnecessary WARN 2019-07-27 21:45:56 +02:00
clocksource
connector
coresight
cpufreq cpufreq: s3c2416: double free on driver init error path 2019-07-27 21:44:36 +02:00
cpuidle cpuidle: Remove unnecessary WARN for calculate_residency 2019-07-27 21:45:56 +02:00
crypto crypto: n2 - cure use after free 2019-07-27 21:46:21 +02:00
dca
debug
debug_32
devfreq
dio
dma
edac
eisa
esoc
extcon
fingerprint
firewire
firmware
gpio gpio: Handle EPROBE_DEFER while probing 2019-07-27 21:45:55 +02:00
gpu
hid HID: i2c-hid: allocate hid buffers for real worst case 2019-07-27 21:45:51 +02:00
hsi
hv
hwmon
hwspinlock
i2c i2c: core-smbus: prevent stack corruption on read I2C_BLOCK_DATA 2019-07-27 21:46:30 +02:00
ide
idle
iio iio: adis_lib: Initialize trigger before requesting interrupt 2019-07-27 21:46:10 +02:00
infiniband
input input: synaptics_dsx: remove unused synaptics touch screen driver files 2019-07-27 21:46:00 +02:00
iommu iommu/amd: Finish TLB flush in amd_iommu_unmap() 2019-07-27 21:44:19 +02:00
ipack
irqchip
isdn
leds
lguest
macintosh
mailbox
md dm btree: fix serious bug in btree_split_beneath() 2019-07-27 21:46:30 +02:00
media media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic 2019-07-27 21:46:39 +02:00
memory
memstick
message
mfd mfd: omap-usb-tll: Fix inverted bit use for USB TLL mode 2019-07-27 21:44:34 +02:00
misc qseecom: Fix typo in format specifier 2019-07-27 21:44:44 +02:00
mmc
motor
mtd
muic
net tun: call dev_get_valid_name() before register_netdevice() 2019-07-27 21:45:50 +02:00
nfc
ntb
nubus
of of: fdt: add missing allocation-failure check 2019-07-27 21:44:47 +02:00
oprofile
parisc
parport
pci PCI / PM: Force devices to D0 in pci_pm_thaw_noirq() 2019-07-27 21:46:19 +02:00
pcmcia
phy
pinctrl pinctrl: sh-pfc: Do not unconditionally support PIN_CONFIG_BIAS_DISABLE 2019-07-27 21:43:46 +02:00
platform
pnp
power
pps
ps3
ptp
pwm
rapidio
regulator
remoteproc
reset
rpmsg
rtc rtc: set the alarm to the next expiring timer 2019-07-27 21:46:00 +02:00
s390 scsi: zfcp: trace HBA FSF response by default on dismiss or timedout late response 2019-07-27 21:44:18 +02:00
sbus
scsi scsi: use dma_get_cache_alignment() as minimum DMA alignment 2019-07-27 21:46:11 +02:00
sensorhub
sensors
sfi
sh
slimbus
sn
soc
soundwire
spi
spmi
ssb
ssbi
staging
switch
target target: Avoid mappedlun symlink creation during lun shutdown 2019-07-27 21:44:16 +02:00
tc
thermal msm_thermal: Handle defer while probing 2019-07-27 21:45:58 +02:00
tty n_tty: fix EXTPROC vs ICANON interaction with TIOCINQ (aka FIONREAD) 2019-07-27 21:46:21 +02:00
uio
usb USB: fix usbmon BUG trigger 2019-07-27 21:46:28 +02:00
uwb
vfio
vhost
video video: msm: samsung: Fix mode_max permissions 2019-07-27 21:45:54 +02:00
virt
virtio
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile