License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 17:07:57 +03:00
// SPDX-License-Identifier: GPL-2.0
2005-04-17 02:20:36 +04:00
/*
* ioctl32 . c : Conversion between 32 bit and 64 bit native ioctls .
*
* Copyright ( C ) 1997 - 2000 Jakub Jelinek ( jakub @ redhat . com )
* Copyright ( C ) 1998 Eddie C . Dost ( ecd @ skynet . be )
* Copyright ( C ) 2001 , 2002 Andi Kleen , SuSE Labs
2010-07-18 16:27:13 +04:00
* Copyright ( C ) 2003 Pavel Machek ( pavel @ ucw . cz )
2005-04-17 02:20:36 +04:00
*
* These routines maintain argument size conversion between 32 bit and 64 bit
* ioctls .
*/
2008-01-06 13:15:55 +03:00
# include <linux/joystick.h>
2005-04-17 02:20:36 +04:00
# include <linux/types.h>
# include <linux/compat.h>
# include <linux/kernel.h>
2006-01-11 23:17:46 +03:00
# include <linux/capability.h>
2005-04-17 02:20:36 +04:00
# include <linux/compiler.h>
# include <linux/sched.h>
# include <linux/smp.h>
# include <linux/ioctl.h>
# include <linux/if.h>
2009-03-31 07:33:13 +04:00
# include <linux/raid/md_u.h>
2009-06-19 22:28:07 +04:00
# include <linux/falloc.h>
2005-04-17 02:20:36 +04:00
# include <linux/file.h>
2012-03-04 16:56:55 +04:00
# include <linux/ppp-ioctl.h>
2005-04-17 02:20:36 +04:00
# include <linux/if_pppox.h>
# include <linux/mtio.h>
# include <linux/tty.h>
# include <linux/vt_kern.h>
# include <linux/raw.h>
# include <linux/blkdev.h>
# include <linux/rtc.h>
# include <linux/pci.h>
# include <linux/serial.h>
# include <linux/ctype.h>
# include <linux/syscalls.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/gfp.h>
2015-11-11 13:26:12 +03:00
# include <linux/cec.h>
2005-04-17 02:20:36 +04:00
2016-01-07 17:53:30 +03:00
# include "internal.h"
2005-04-17 02:20:36 +04:00
# include <net/bluetooth/bluetooth.h>
2014-07-11 06:58:29 +04:00
# include <net/bluetooth/hci_sock.h>
2005-04-17 02:20:36 +04:00
# include <net/bluetooth/rfcomm.h>
# include <linux/capi.h>
2006-06-26 11:25:35 +04:00
# include <linux/gigaset_dev.h>
2005-04-17 02:20:36 +04:00
2008-07-16 17:52:00 +04:00
# ifdef CONFIG_BLOCK
2011-07-02 00:32:26 +04:00
# include <linux/cdrom.h>
# include <linux/fd.h>
2005-04-17 02:20:36 +04:00
# include <scsi/scsi.h>
# include <scsi/scsi_ioctl.h>
# include <scsi/sg.h>
2008-07-16 17:52:00 +04:00
# endif
2005-04-17 02:20:36 +04:00
2016-12-24 22:46:01 +03:00
# include <linux/uaccess.h>
2005-04-17 02:20:36 +04:00
# include <linux/watchdog.h>
# include <linux/soundcard.h>
# include <linux/hiddev.h>
2005-11-16 11:52:57 +03:00
2009-11-05 21:52:55 +03:00
# include <linux/sort.h>
2007-07-29 11:50:42 +04:00
# ifdef CONFIG_SPARC
2018-08-17 04:10:42 +03:00
# include <linux/fb.h>
2007-07-29 11:50:42 +04:00
# include <asm/fbio.h>
# endif
2016-01-05 20:27:30 +03:00
# define convert_in_user(srcptr, dstptr) \
( { \
typeof ( * srcptr ) val ; \
\
get_user ( val , srcptr ) | | put_user ( val , dstptr ) ; \
} )
2016-01-07 17:53:30 +03:00
static int do_ioctl ( struct file * file , unsigned int cmd , unsigned long arg )
compat_ioctl: don't look up the fd twice
In code in fs/compat_ioctl.c that translates ioctl arguments
into a in-kernel structure, then performs sys_ioctl, possibly
under set_fs(KERNEL_DS), this commit changes the sys_ioctl
calls to do_ioctl calls. do_ioctl is a new function that does
the same thing as sys_ioctl, but doesn't look up the fd again.
This change is made to avoid (potential) security issues
because of ioctl handlers that accept one of the ioctl
commands I2C_FUNCS, VIDEO_GET_EVENT, MTIOCPOS, MTIOCGET,
TIOCGSERIAL, TIOCSSERIAL, RTC_IRQP_READ, RTC_EPOCH_READ.
This can happen for multiple reasons:
- The ioctl command number could be reused.
- The ioctl handler might not check the full ioctl
command. This is e.g. true for drm_ioctl.
- The ioctl handler is very special, e.g. cuse_file_ioctl
The real issue is that set_fs(KERNEL_DS) is used here,
but that's fixed in a separate commit
"compat_ioctl: don't call do_ioctl under set_fs(KERNEL_DS)".
This change mitigates potential security issues by
preventing a race that permits invocation of
unlocked_ioctl handlers under KERNEL_DS through compat
code even if a corresponding compat_ioctl handler exists.
So far, no way has been identified to use this to damage
kernel memory without having CAP_SYS_ADMIN in the init ns
(with the capability, doing reads/writes at arbitrary
kernel addresses should be easy through CUSE's ioctl
handler with FUSE_IOCTL_UNRESTRICTED set).
[AV: two missed sys_ioctl() taken care of]
Signed-off-by: Jann Horn <jann@thejh.net>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2016-01-05 20:27:29 +03:00
{
int err ;
err = security_file_ioctl ( file , cmd , arg ) ;
if ( err )
return err ;
2016-01-07 17:53:30 +03:00
return vfs_ioctl ( file , cmd , arg ) ;
compat_ioctl: don't look up the fd twice
In code in fs/compat_ioctl.c that translates ioctl arguments
into a in-kernel structure, then performs sys_ioctl, possibly
under set_fs(KERNEL_DS), this commit changes the sys_ioctl
calls to do_ioctl calls. do_ioctl is a new function that does
the same thing as sys_ioctl, but doesn't look up the fd again.
This change is made to avoid (potential) security issues
because of ioctl handlers that accept one of the ioctl
commands I2C_FUNCS, VIDEO_GET_EVENT, MTIOCPOS, MTIOCGET,
TIOCGSERIAL, TIOCSSERIAL, RTC_IRQP_READ, RTC_EPOCH_READ.
This can happen for multiple reasons:
- The ioctl command number could be reused.
- The ioctl handler might not check the full ioctl
command. This is e.g. true for drm_ioctl.
- The ioctl handler is very special, e.g. cuse_file_ioctl
The real issue is that set_fs(KERNEL_DS) is used here,
but that's fixed in a separate commit
"compat_ioctl: don't call do_ioctl under set_fs(KERNEL_DS)".
This change mitigates potential security issues by
preventing a race that permits invocation of
unlocked_ioctl handlers under KERNEL_DS through compat
code even if a corresponding compat_ioctl handler exists.
So far, no way has been identified to use this to damage
kernel memory without having CAP_SYS_ADMIN in the init ns
(with the capability, doing reads/writes at arbitrary
kernel addresses should be easy through CUSE's ioctl
handler with FUSE_IOCTL_UNRESTRICTED set).
[AV: two missed sys_ioctl() taken care of]
Signed-off-by: Jann Horn <jann@thejh.net>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2016-01-05 20:27:29 +03:00
}
[PATCH] BLOCK: Make it possible to disable the block layer [try #6]
Make it possible to disable the block layer. Not all embedded devices require
it, some can make do with just JFFS2, NFS, ramfs, etc - none of which require
the block layer to be present.
This patch does the following:
(*) Introduces CONFIG_BLOCK to disable the block layer, buffering and blockdev
support.
(*) Adds dependencies on CONFIG_BLOCK to any configuration item that controls
an item that uses the block layer. This includes:
(*) Block I/O tracing.
(*) Disk partition code.
(*) All filesystems that are block based, eg: Ext3, ReiserFS, ISOFS.
(*) The SCSI layer. As far as I can tell, even SCSI chardevs use the
block layer to do scheduling. Some drivers that use SCSI facilities -
such as USB storage - end up disabled indirectly from this.
(*) Various block-based device drivers, such as IDE and the old CDROM
drivers.
(*) MTD blockdev handling and FTL.
(*) JFFS - which uses set_bdev_super(), something it could avoid doing by
taking a leaf out of JFFS2's book.
(*) Makes most of the contents of linux/blkdev.h, linux/buffer_head.h and
linux/elevator.h contingent on CONFIG_BLOCK being set. sector_div() is,
however, still used in places, and so is still available.
(*) Also made contingent are the contents of linux/mpage.h, linux/genhd.h and
parts of linux/fs.h.
(*) Makes a number of files in fs/ contingent on CONFIG_BLOCK.
(*) Makes mm/bounce.c (bounce buffering) contingent on CONFIG_BLOCK.
(*) set_page_dirty() doesn't call __set_page_dirty_buffers() if CONFIG_BLOCK
is not enabled.
(*) fs/no-block.c is created to hold out-of-line stubs and things that are
required when CONFIG_BLOCK is not set:
(*) Default blockdev file operations (to give error ENODEV on opening).
(*) Makes some /proc changes:
(*) /proc/devices does not list any blockdevs.
(*) /proc/diskstats and /proc/partitions are contingent on CONFIG_BLOCK.
(*) Makes some compat ioctl handling contingent on CONFIG_BLOCK.
(*) If CONFIG_BLOCK is not defined, makes sys_quotactl() return -ENODEV if
given command other than Q_SYNC or if a special device is specified.
(*) In init/do_mounts.c, no reference is made to the blockdev routines if
CONFIG_BLOCK is not defined. This does not prohibit NFS roots or JFFS2.
(*) The bdflush, ioprio_set and ioprio_get syscalls can now be absent (return
error ENOSYS by way of cond_syscall if so).
(*) The seclvl_bd_claim() and seclvl_bd_release() security calls do nothing if
CONFIG_BLOCK is not set, since they can't then happen.
Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2006-09-30 22:45:40 +04:00
# ifdef CONFIG_BLOCK
2005-04-17 02:20:36 +04:00
typedef struct sg_io_hdr32 {
compat_int_t interface_id ; /* [i] 'S' for SCSI generic (required) */
compat_int_t dxfer_direction ; /* [i] data transfer direction */
unsigned char cmd_len ; /* [i] SCSI command length ( <= 16 bytes) */
unsigned char mx_sb_len ; /* [i] max length to write to sbp */
unsigned short iovec_count ; /* [i] 0 implies no scatter gather */
compat_uint_t dxfer_len ; /* [i] byte count of data transfer */
compat_uint_t dxferp ; /* [i], [*io] points to data transfer memory
or scatter gather list */
compat_uptr_t cmdp ; /* [i], [*i] points to command to perform */
compat_uptr_t sbp ; /* [i], [*o] points to sense_buffer memory */
compat_uint_t timeout ; /* [i] MAX_UINT->no timeout (unit: millisec) */
compat_uint_t flags ; /* [i] 0 -> default, see SG_FLAG... */
compat_int_t pack_id ; /* [i->o] unused internally (normally) */
compat_uptr_t usr_ptr ; /* [i->o] unused internally */
unsigned char status ; /* [o] scsi status */
unsigned char masked_status ; /* [o] shifted, masked scsi status */
unsigned char msg_status ; /* [o] messaging level data (optional) */
unsigned char sb_len_wr ; /* [o] byte count actually written to sbp */
unsigned short host_status ; /* [o] errors from host adapter */
unsigned short driver_status ; /* [o] errors from software driver */
compat_int_t resid ; /* [o] dxfer_len - actual_transferred */
compat_uint_t duration ; /* [o] time taken by cmd (unit: millisec) */
compat_uint_t info ; /* [o] auxiliary information */
} sg_io_hdr32_t ; /* 64 bytes long (on sparc32) */
typedef struct sg_iovec32 {
compat_uint_t iov_base ;
compat_uint_t iov_len ;
} sg_iovec32_t ;
static int sg_build_iovec ( sg_io_hdr_t __user * sgio , void __user * dxferp , u16 iovec_count )
{
sg_iovec_t __user * iov = ( sg_iovec_t __user * ) ( sgio + 1 ) ;
sg_iovec32_t __user * iov32 = dxferp ;
int i ;
for ( i = 0 ; i < iovec_count ; i + + ) {
u32 base , len ;
if ( get_user ( base , & iov32 [ i ] . iov_base ) | |
get_user ( len , & iov32 [ i ] . iov_len ) | |
put_user ( compat_ptr ( base ) , & iov [ i ] . iov_base ) | |
put_user ( len , & iov [ i ] . iov_len ) )
return - EFAULT ;
}
if ( put_user ( iov , & sgio - > dxferp ) )
return - EFAULT ;
return 0 ;
}
2016-01-07 17:53:30 +03:00
static int sg_ioctl_trans ( struct file * file , unsigned int cmd ,
2009-11-15 01:16:18 +03:00
sg_io_hdr32_t __user * sgio32 )
2005-04-17 02:20:36 +04:00
{
sg_io_hdr_t __user * sgio ;
u16 iovec_count ;
u32 data ;
void __user * dxferp ;
int err ;
2010-01-05 13:41:44 +03:00
int interface_id ;
if ( get_user ( interface_id , & sgio32 - > interface_id ) )
return - EFAULT ;
if ( interface_id ! = ' S ' )
2016-01-07 17:53:30 +03:00
return do_ioctl ( file , cmd , ( unsigned long ) sgio32 ) ;
2005-04-17 02:20:36 +04:00
if ( get_user ( iovec_count , & sgio32 - > iovec_count ) )
return - EFAULT ;
{
void __user * top = compat_alloc_user_space ( 0 ) ;
void __user * new = compat_alloc_user_space ( sizeof ( sg_io_hdr_t ) +
( iovec_count * sizeof ( sg_iovec_t ) ) ) ;
if ( new > top )
return - EINVAL ;
sgio = new ;
}
/* Ok, now construct. */
if ( copy_in_user ( & sgio - > interface_id , & sgio32 - > interface_id ,
( 2 * sizeof ( int ) ) +
( 2 * sizeof ( unsigned char ) ) +
( 1 * sizeof ( unsigned short ) ) +
( 1 * sizeof ( unsigned int ) ) ) )
return - EFAULT ;
if ( get_user ( data , & sgio32 - > dxferp ) )
return - EFAULT ;
dxferp = compat_ptr ( data ) ;
if ( iovec_count ) {
if ( sg_build_iovec ( sgio , dxferp , iovec_count ) )
return - EFAULT ;
} else {
if ( put_user ( dxferp , & sgio - > dxferp ) )
return - EFAULT ;
}
{
unsigned char __user * cmdp ;
unsigned char __user * sbp ;
if ( get_user ( data , & sgio32 - > cmdp ) )
return - EFAULT ;
cmdp = compat_ptr ( data ) ;
if ( get_user ( data , & sgio32 - > sbp ) )
return - EFAULT ;
sbp = compat_ptr ( data ) ;
if ( put_user ( cmdp , & sgio - > cmdp ) | |
put_user ( sbp , & sgio - > sbp ) )
return - EFAULT ;
}
if ( copy_in_user ( & sgio - > timeout , & sgio32 - > timeout ,
3 * sizeof ( int ) ) )
return - EFAULT ;
if ( get_user ( data , & sgio32 - > usr_ptr ) )
return - EFAULT ;
if ( put_user ( compat_ptr ( data ) , & sgio - > usr_ptr ) )
return - EFAULT ;
2016-01-07 17:53:30 +03:00
err = do_ioctl ( file , cmd , ( unsigned long ) sgio ) ;
2005-04-17 02:20:36 +04:00
if ( err > = 0 ) {
void __user * datap ;
if ( copy_in_user ( & sgio32 - > pack_id , & sgio - > pack_id ,
sizeof ( int ) ) | |
get_user ( datap , & sgio - > usr_ptr ) | |
put_user ( ( u32 ) ( unsigned long ) datap ,
& sgio32 - > usr_ptr ) | |
copy_in_user ( & sgio32 - > status , & sgio - > status ,
( 4 * sizeof ( unsigned char ) ) +
( 2 * sizeof ( unsigned short ) ) +
( 3 * sizeof ( int ) ) ) )
err = - EFAULT ;
}
return err ;
}
2006-01-12 00:44:03 +03:00
struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
char req_state ;
char orphan ;
char sg_io_owned ;
char problem ;
int pack_id ;
compat_uptr_t usr_ptr ;
unsigned int duration ;
int unused ;
} ;
2016-01-07 17:53:30 +03:00
static int sg_grt_trans ( struct file * file ,
compat_ioctl: don't look up the fd twice
In code in fs/compat_ioctl.c that translates ioctl arguments
into a in-kernel structure, then performs sys_ioctl, possibly
under set_fs(KERNEL_DS), this commit changes the sys_ioctl
calls to do_ioctl calls. do_ioctl is a new function that does
the same thing as sys_ioctl, but doesn't look up the fd again.
This change is made to avoid (potential) security issues
because of ioctl handlers that accept one of the ioctl
commands I2C_FUNCS, VIDEO_GET_EVENT, MTIOCPOS, MTIOCGET,
TIOCGSERIAL, TIOCSSERIAL, RTC_IRQP_READ, RTC_EPOCH_READ.
This can happen for multiple reasons:
- The ioctl command number could be reused.
- The ioctl handler might not check the full ioctl
command. This is e.g. true for drm_ioctl.
- The ioctl handler is very special, e.g. cuse_file_ioctl
The real issue is that set_fs(KERNEL_DS) is used here,
but that's fixed in a separate commit
"compat_ioctl: don't call do_ioctl under set_fs(KERNEL_DS)".
This change mitigates potential security issues by
preventing a race that permits invocation of
unlocked_ioctl handlers under KERNEL_DS through compat
code even if a corresponding compat_ioctl handler exists.
So far, no way has been identified to use this to damage
kernel memory without having CAP_SYS_ADMIN in the init ns
(with the capability, doing reads/writes at arbitrary
kernel addresses should be easy through CUSE's ioctl
handler with FUSE_IOCTL_UNRESTRICTED set).
[AV: two missed sys_ioctl() taken care of]
Signed-off-by: Jann Horn <jann@thejh.net>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2016-01-05 20:27:29 +03:00
unsigned int cmd , struct compat_sg_req_info __user * o )
2006-01-12 00:44:03 +03:00
{
int err , i ;
2006-02-01 14:33:33 +03:00
sg_req_info_t __user * r ;
2006-01-12 00:44:03 +03:00
r = compat_alloc_user_space ( sizeof ( sg_req_info_t ) * SG_MAX_QUEUE ) ;
2016-01-07 17:53:30 +03:00
err = do_ioctl ( file , cmd , ( unsigned long ) r ) ;
2006-01-12 00:44:03 +03:00
if ( err < 0 )
return err ;
for ( i = 0 ; i < SG_MAX_QUEUE ; i + + ) {
void __user * ptr ;
int d ;
if ( copy_in_user ( o + i , r + i , offsetof ( sg_req_info_t , usr_ptr ) ) | |
get_user ( ptr , & r [ i ] . usr_ptr ) | |
get_user ( d , & r [ i ] . duration ) | |
put_user ( ( u32 ) ( unsigned long ) ( ptr ) , & o [ i ] . usr_ptr ) | |
put_user ( d , & o [ i ] . duration ) )
return - EFAULT ;
}
return err ;
}
[PATCH] BLOCK: Make it possible to disable the block layer [try #6]
Make it possible to disable the block layer. Not all embedded devices require
it, some can make do with just JFFS2, NFS, ramfs, etc - none of which require
the block layer to be present.
This patch does the following:
(*) Introduces CONFIG_BLOCK to disable the block layer, buffering and blockdev
support.
(*) Adds dependencies on CONFIG_BLOCK to any configuration item that controls
an item that uses the block layer. This includes:
(*) Block I/O tracing.
(*) Disk partition code.
(*) All filesystems that are block based, eg: Ext3, ReiserFS, ISOFS.
(*) The SCSI layer. As far as I can tell, even SCSI chardevs use the
block layer to do scheduling. Some drivers that use SCSI facilities -
such as USB storage - end up disabled indirectly from this.
(*) Various block-based device drivers, such as IDE and the old CDROM
drivers.
(*) MTD blockdev handling and FTL.
(*) JFFS - which uses set_bdev_super(), something it could avoid doing by
taking a leaf out of JFFS2's book.
(*) Makes most of the contents of linux/blkdev.h, linux/buffer_head.h and
linux/elevator.h contingent on CONFIG_BLOCK being set. sector_div() is,
however, still used in places, and so is still available.
(*) Also made contingent are the contents of linux/mpage.h, linux/genhd.h and
parts of linux/fs.h.
(*) Makes a number of files in fs/ contingent on CONFIG_BLOCK.
(*) Makes mm/bounce.c (bounce buffering) contingent on CONFIG_BLOCK.
(*) set_page_dirty() doesn't call __set_page_dirty_buffers() if CONFIG_BLOCK
is not enabled.
(*) fs/no-block.c is created to hold out-of-line stubs and things that are
required when CONFIG_BLOCK is not set:
(*) Default blockdev file operations (to give error ENODEV on opening).
(*) Makes some /proc changes:
(*) /proc/devices does not list any blockdevs.
(*) /proc/diskstats and /proc/partitions are contingent on CONFIG_BLOCK.
(*) Makes some compat ioctl handling contingent on CONFIG_BLOCK.
(*) If CONFIG_BLOCK is not defined, makes sys_quotactl() return -ENODEV if
given command other than Q_SYNC or if a special device is specified.
(*) In init/do_mounts.c, no reference is made to the blockdev routines if
CONFIG_BLOCK is not defined. This does not prohibit NFS roots or JFFS2.
(*) The bdflush, ioprio_set and ioprio_get syscalls can now be absent (return
error ENOSYS by way of cond_syscall if so).
(*) The seclvl_bd_claim() and seclvl_bd_release() security calls do nothing if
CONFIG_BLOCK is not set, since they can't then happen.
Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2006-09-30 22:45:40 +04:00
# endif /* CONFIG_BLOCK */
2006-01-12 00:44:03 +03:00
2005-04-17 02:20:36 +04:00
struct sock_fprog32 {
unsigned short len ;
compat_caddr_t filter ;
} ;
# define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
# define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
2016-01-07 17:53:30 +03:00
static int ppp_sock_fprog_ioctl_trans ( struct file * file ,
compat_ioctl: don't look up the fd twice
In code in fs/compat_ioctl.c that translates ioctl arguments
into a in-kernel structure, then performs sys_ioctl, possibly
under set_fs(KERNEL_DS), this commit changes the sys_ioctl
calls to do_ioctl calls. do_ioctl is a new function that does
the same thing as sys_ioctl, but doesn't look up the fd again.
This change is made to avoid (potential) security issues
because of ioctl handlers that accept one of the ioctl
commands I2C_FUNCS, VIDEO_GET_EVENT, MTIOCPOS, MTIOCGET,
TIOCGSERIAL, TIOCSSERIAL, RTC_IRQP_READ, RTC_EPOCH_READ.
This can happen for multiple reasons:
- The ioctl command number could be reused.
- The ioctl handler might not check the full ioctl
command. This is e.g. true for drm_ioctl.
- The ioctl handler is very special, e.g. cuse_file_ioctl
The real issue is that set_fs(KERNEL_DS) is used here,
but that's fixed in a separate commit
"compat_ioctl: don't call do_ioctl under set_fs(KERNEL_DS)".
This change mitigates potential security issues by
preventing a race that permits invocation of
unlocked_ioctl handlers under KERNEL_DS through compat
code even if a corresponding compat_ioctl handler exists.
So far, no way has been identified to use this to damage
kernel memory without having CAP_SYS_ADMIN in the init ns
(with the capability, doing reads/writes at arbitrary
kernel addresses should be easy through CUSE's ioctl
handler with FUSE_IOCTL_UNRESTRICTED set).
[AV: two missed sys_ioctl() taken care of]
Signed-off-by: Jann Horn <jann@thejh.net>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2016-01-05 20:27:29 +03:00
unsigned int cmd , struct sock_fprog32 __user * u_fprog32 )
2005-04-17 02:20:36 +04:00
{
struct sock_fprog __user * u_fprog64 = compat_alloc_user_space ( sizeof ( struct sock_fprog ) ) ;
void __user * fptr64 ;
u32 fptr32 ;
u16 flen ;
if ( get_user ( flen , & u_fprog32 - > len ) | |
get_user ( fptr32 , & u_fprog32 - > filter ) )
return - EFAULT ;
fptr64 = compat_ptr ( fptr32 ) ;
if ( put_user ( flen , & u_fprog64 - > len ) | |
put_user ( fptr64 , & u_fprog64 - > filter ) )
return - EFAULT ;
if ( cmd = = PPPIOCSPASS32 )
cmd = PPPIOCSPASS ;
else
cmd = PPPIOCSACTIVE ;
2016-01-07 17:53:30 +03:00
return do_ioctl ( file , cmd , ( unsigned long ) u_fprog64 ) ;
2005-04-17 02:20:36 +04:00
}
struct ppp_option_data32 {
compat_caddr_t ptr ;
u32 length ;
compat_int_t transmit ;
} ;
# define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
struct ppp_idle32 {
compat_time_t xmit_idle ;
compat_time_t recv_idle ;
} ;
# define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
2016-01-07 17:53:30 +03:00
static int ppp_gidle ( struct file * file , unsigned int cmd ,
2009-11-15 01:16:18 +03:00
struct ppp_idle32 __user * idle32 )
2005-04-17 02:20:36 +04:00
{
struct ppp_idle __user * idle ;
__kernel_time_t xmit , recv ;
int err ;
idle = compat_alloc_user_space ( sizeof ( * idle ) ) ;
2016-01-07 17:53:30 +03:00
err = do_ioctl ( file , PPPIOCGIDLE , ( unsigned long ) idle ) ;
2005-04-17 02:20:36 +04:00
if ( ! err ) {
if ( get_user ( xmit , & idle - > xmit_idle ) | |
get_user ( recv , & idle - > recv_idle ) | |
put_user ( xmit , & idle32 - > xmit_idle ) | |
put_user ( recv , & idle32 - > recv_idle ) )
err = - EFAULT ;
}
return err ;
}
2016-01-07 17:53:30 +03:00
static int ppp_scompress ( struct file * file , unsigned int cmd ,
2009-11-15 01:16:18 +03:00
struct ppp_option_data32 __user * odata32 )
2005-04-17 02:20:36 +04:00
{
struct ppp_option_data __user * odata ;
__u32 data ;
void __user * datap ;
odata = compat_alloc_user_space ( sizeof ( * odata ) ) ;
if ( get_user ( data , & odata32 - > ptr ) )
return - EFAULT ;
datap = compat_ptr ( data ) ;
if ( put_user ( datap , & odata - > ptr ) )
return - EFAULT ;
if ( copy_in_user ( & odata - > length , & odata32 - > length ,
sizeof ( __u32 ) + sizeof ( int ) ) )
return - EFAULT ;
2016-01-07 17:53:30 +03:00
return do_ioctl ( file , PPPIOCSCOMPRESS , ( unsigned long ) odata ) ;
2005-04-17 02:20:36 +04:00
}
[PATCH] BLOCK: Make it possible to disable the block layer [try #6]
Make it possible to disable the block layer. Not all embedded devices require
it, some can make do with just JFFS2, NFS, ramfs, etc - none of which require
the block layer to be present.
This patch does the following:
(*) Introduces CONFIG_BLOCK to disable the block layer, buffering and blockdev
support.
(*) Adds dependencies on CONFIG_BLOCK to any configuration item that controls
an item that uses the block layer. This includes:
(*) Block I/O tracing.
(*) Disk partition code.
(*) All filesystems that are block based, eg: Ext3, ReiserFS, ISOFS.
(*) The SCSI layer. As far as I can tell, even SCSI chardevs use the
block layer to do scheduling. Some drivers that use SCSI facilities -
such as USB storage - end up disabled indirectly from this.
(*) Various block-based device drivers, such as IDE and the old CDROM
drivers.
(*) MTD blockdev handling and FTL.
(*) JFFS - which uses set_bdev_super(), something it could avoid doing by
taking a leaf out of JFFS2's book.
(*) Makes most of the contents of linux/blkdev.h, linux/buffer_head.h and
linux/elevator.h contingent on CONFIG_BLOCK being set. sector_div() is,
however, still used in places, and so is still available.
(*) Also made contingent are the contents of linux/mpage.h, linux/genhd.h and
parts of linux/fs.h.
(*) Makes a number of files in fs/ contingent on CONFIG_BLOCK.
(*) Makes mm/bounce.c (bounce buffering) contingent on CONFIG_BLOCK.
(*) set_page_dirty() doesn't call __set_page_dirty_buffers() if CONFIG_BLOCK
is not enabled.
(*) fs/no-block.c is created to hold out-of-line stubs and things that are
required when CONFIG_BLOCK is not set:
(*) Default blockdev file operations (to give error ENODEV on opening).
(*) Makes some /proc changes:
(*) /proc/devices does not list any blockdevs.
(*) /proc/diskstats and /proc/partitions are contingent on CONFIG_BLOCK.
(*) Makes some compat ioctl handling contingent on CONFIG_BLOCK.
(*) If CONFIG_BLOCK is not defined, makes sys_quotactl() return -ENODEV if
given command other than Q_SYNC or if a special device is specified.
(*) In init/do_mounts.c, no reference is made to the blockdev routines if
CONFIG_BLOCK is not defined. This does not prohibit NFS roots or JFFS2.
(*) The bdflush, ioprio_set and ioprio_get syscalls can now be absent (return
error ENOSYS by way of cond_syscall if so).
(*) The seclvl_bd_claim() and seclvl_bd_release() security calls do nothing if
CONFIG_BLOCK is not set, since they can't then happen.
Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2006-09-30 22:45:40 +04:00
# ifdef CONFIG_BLOCK
2005-04-17 02:20:36 +04:00
struct mtget32 {
compat_long_t mt_type ;
compat_long_t mt_resid ;
compat_long_t mt_dsreg ;
compat_long_t mt_gstat ;
compat_long_t mt_erreg ;
compat_daddr_t mt_fileno ;
compat_daddr_t mt_blkno ;
} ;
# define MTIOCGET32 _IOR('m', 2, struct mtget32)
struct mtpos32 {
compat_long_t mt_blkno ;
} ;
# define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
2016-01-07 17:53:30 +03:00
static int mt_ioctl_trans ( struct file * file ,
compat_ioctl: don't look up the fd twice
In code in fs/compat_ioctl.c that translates ioctl arguments
into a in-kernel structure, then performs sys_ioctl, possibly
under set_fs(KERNEL_DS), this commit changes the sys_ioctl
calls to do_ioctl calls. do_ioctl is a new function that does
the same thing as sys_ioctl, but doesn't look up the fd again.
This change is made to avoid (potential) security issues
because of ioctl handlers that accept one of the ioctl
commands I2C_FUNCS, VIDEO_GET_EVENT, MTIOCPOS, MTIOCGET,
TIOCGSERIAL, TIOCSSERIAL, RTC_IRQP_READ, RTC_EPOCH_READ.
This can happen for multiple reasons:
- The ioctl command number could be reused.
- The ioctl handler might not check the full ioctl
command. This is e.g. true for drm_ioctl.
- The ioctl handler is very special, e.g. cuse_file_ioctl
The real issue is that set_fs(KERNEL_DS) is used here,
but that's fixed in a separate commit
"compat_ioctl: don't call do_ioctl under set_fs(KERNEL_DS)".
This change mitigates potential security issues by
preventing a race that permits invocation of
unlocked_ioctl handlers under KERNEL_DS through compat
code even if a corresponding compat_ioctl handler exists.
So far, no way has been identified to use this to damage
kernel memory without having CAP_SYS_ADMIN in the init ns
(with the capability, doing reads/writes at arbitrary
kernel addresses should be easy through CUSE's ioctl
handler with FUSE_IOCTL_UNRESTRICTED set).
[AV: two missed sys_ioctl() taken care of]
Signed-off-by: Jann Horn <jann@thejh.net>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2016-01-05 20:27:29 +03:00
unsigned int cmd , void __user * argp )
2005-04-17 02:20:36 +04:00
{
2016-01-05 20:27:30 +03:00
/* NULL initialization to make gcc shut up */
struct mtget __user * get = NULL ;
2005-04-17 02:20:36 +04:00
struct mtget32 __user * umget32 ;
2016-01-05 20:27:30 +03:00
struct mtpos __user * pos = NULL ;
2005-04-17 02:20:36 +04:00
struct mtpos32 __user * upos32 ;
unsigned long kcmd ;
void * karg ;
int err = 0 ;
switch ( cmd ) {
case MTIOCPOS32 :
kcmd = MTIOCPOS ;
2016-01-05 20:27:30 +03:00
pos = compat_alloc_user_space ( sizeof ( * pos ) ) ;
karg = pos ;
2005-04-17 02:20:36 +04:00
break ;
2010-03-06 00:43:19 +03:00
default : /* MTIOCGET32 */
2005-04-17 02:20:36 +04:00
kcmd = MTIOCGET ;
2016-01-05 20:27:30 +03:00
get = compat_alloc_user_space ( sizeof ( * get ) ) ;
karg = get ;
2005-04-17 02:20:36 +04:00
break ;
}
2016-01-05 20:27:30 +03:00
if ( karg = = NULL )
return - EFAULT ;
2016-01-07 17:53:30 +03:00
err = do_ioctl ( file , kcmd , ( unsigned long ) karg ) ;
2005-04-17 02:20:36 +04:00
if ( err )
return err ;
switch ( cmd ) {
case MTIOCPOS32 :
2009-11-15 01:16:18 +03:00
upos32 = argp ;
2016-01-05 20:27:30 +03:00
err = convert_in_user ( & pos - > mt_blkno , & upos32 - > mt_blkno ) ;
2005-04-17 02:20:36 +04:00
break ;
case MTIOCGET32 :
2009-11-15 01:16:18 +03:00
umget32 = argp ;
2016-01-05 20:27:30 +03:00
err = convert_in_user ( & get - > mt_type , & umget32 - > mt_type ) ;
err | = convert_in_user ( & get - > mt_resid , & umget32 - > mt_resid ) ;
err | = convert_in_user ( & get - > mt_dsreg , & umget32 - > mt_dsreg ) ;
err | = convert_in_user ( & get - > mt_gstat , & umget32 - > mt_gstat ) ;
err | = convert_in_user ( & get - > mt_erreg , & umget32 - > mt_erreg ) ;
err | = convert_in_user ( & get - > mt_fileno , & umget32 - > mt_fileno ) ;
err | = convert_in_user ( & get - > mt_blkno , & umget32 - > mt_blkno ) ;
2005-04-17 02:20:36 +04:00
break ;
}
return err ? - EFAULT : 0 ;
}
[PATCH] BLOCK: Make it possible to disable the block layer [try #6]
Make it possible to disable the block layer. Not all embedded devices require
it, some can make do with just JFFS2, NFS, ramfs, etc - none of which require
the block layer to be present.
This patch does the following:
(*) Introduces CONFIG_BLOCK to disable the block layer, buffering and blockdev
support.
(*) Adds dependencies on CONFIG_BLOCK to any configuration item that controls
an item that uses the block layer. This includes:
(*) Block I/O tracing.
(*) Disk partition code.
(*) All filesystems that are block based, eg: Ext3, ReiserFS, ISOFS.
(*) The SCSI layer. As far as I can tell, even SCSI chardevs use the
block layer to do scheduling. Some drivers that use SCSI facilities -
such as USB storage - end up disabled indirectly from this.
(*) Various block-based device drivers, such as IDE and the old CDROM
drivers.
(*) MTD blockdev handling and FTL.
(*) JFFS - which uses set_bdev_super(), something it could avoid doing by
taking a leaf out of JFFS2's book.
(*) Makes most of the contents of linux/blkdev.h, linux/buffer_head.h and
linux/elevator.h contingent on CONFIG_BLOCK being set. sector_div() is,
however, still used in places, and so is still available.
(*) Also made contingent are the contents of linux/mpage.h, linux/genhd.h and
parts of linux/fs.h.
(*) Makes a number of files in fs/ contingent on CONFIG_BLOCK.
(*) Makes mm/bounce.c (bounce buffering) contingent on CONFIG_BLOCK.
(*) set_page_dirty() doesn't call __set_page_dirty_buffers() if CONFIG_BLOCK
is not enabled.
(*) fs/no-block.c is created to hold out-of-line stubs and things that are
required when CONFIG_BLOCK is not set:
(*) Default blockdev file operations (to give error ENODEV on opening).
(*) Makes some /proc changes:
(*) /proc/devices does not list any blockdevs.
(*) /proc/diskstats and /proc/partitions are contingent on CONFIG_BLOCK.
(*) Makes some compat ioctl handling contingent on CONFIG_BLOCK.
(*) If CONFIG_BLOCK is not defined, makes sys_quotactl() return -ENODEV if
given command other than Q_SYNC or if a special device is specified.
(*) In init/do_mounts.c, no reference is made to the blockdev routines if
CONFIG_BLOCK is not defined. This does not prohibit NFS roots or JFFS2.
(*) The bdflush, ioprio_set and ioprio_get syscalls can now be absent (return
error ENOSYS by way of cond_syscall if so).
(*) The seclvl_bd_claim() and seclvl_bd_release() security calls do nothing if
CONFIG_BLOCK is not set, since they can't then happen.
Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2006-09-30 22:45:40 +04:00
# endif /* CONFIG_BLOCK */
2005-04-17 02:20:36 +04:00
/* Bluetooth ioctls */
2010-07-09 23:28:36 +04:00
# define HCIUARTSETPROTO _IOW('U', 200, int)
# define HCIUARTGETPROTO _IOR('U', 201, int)
# define HCIUARTGETDEVICE _IOR('U', 202, int)
2010-07-12 18:37:04 +04:00
# define HCIUARTSETFLAGS _IOW('U', 203, int)
# define HCIUARTGETFLAGS _IOR('U', 204, int)
2005-04-17 02:20:36 +04:00
2006-01-10 07:52:11 +03:00
# define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
# define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
# define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
# define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
2016-01-07 17:53:30 +03:00
static int rtc_ioctl ( struct file * file ,
compat_ioctl: don't look up the fd twice
In code in fs/compat_ioctl.c that translates ioctl arguments
into a in-kernel structure, then performs sys_ioctl, possibly
under set_fs(KERNEL_DS), this commit changes the sys_ioctl
calls to do_ioctl calls. do_ioctl is a new function that does
the same thing as sys_ioctl, but doesn't look up the fd again.
This change is made to avoid (potential) security issues
because of ioctl handlers that accept one of the ioctl
commands I2C_FUNCS, VIDEO_GET_EVENT, MTIOCPOS, MTIOCGET,
TIOCGSERIAL, TIOCSSERIAL, RTC_IRQP_READ, RTC_EPOCH_READ.
This can happen for multiple reasons:
- The ioctl command number could be reused.
- The ioctl handler might not check the full ioctl
command. This is e.g. true for drm_ioctl.
- The ioctl handler is very special, e.g. cuse_file_ioctl
The real issue is that set_fs(KERNEL_DS) is used here,
but that's fixed in a separate commit
"compat_ioctl: don't call do_ioctl under set_fs(KERNEL_DS)".
This change mitigates potential security issues by
preventing a race that permits invocation of
unlocked_ioctl handlers under KERNEL_DS through compat
code even if a corresponding compat_ioctl handler exists.
So far, no way has been identified to use this to damage
kernel memory without having CAP_SYS_ADMIN in the init ns
(with the capability, doing reads/writes at arbitrary
kernel addresses should be easy through CUSE's ioctl
handler with FUSE_IOCTL_UNRESTRICTED set).
[AV: two missed sys_ioctl() taken care of]
Signed-off-by: Jann Horn <jann@thejh.net>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2016-01-05 20:27:29 +03:00
unsigned cmd , void __user * argp )
2006-01-10 07:52:11 +03:00
{
2016-01-05 20:27:30 +03:00
unsigned long __user * valp = compat_alloc_user_space ( sizeof ( * valp ) ) ;
2006-01-10 07:52:11 +03:00
int ret ;
2016-01-05 20:27:30 +03:00
if ( valp = = NULL )
return - EFAULT ;
2006-01-10 07:52:11 +03:00
switch ( cmd ) {
case RTC_IRQP_READ32 :
case RTC_EPOCH_READ32 :
2016-01-07 17:53:30 +03:00
ret = do_ioctl ( file , ( cmd = = RTC_IRQP_READ32 ) ?
2006-01-10 07:52:11 +03:00
RTC_IRQP_READ : RTC_EPOCH_READ ,
2016-01-05 20:27:30 +03:00
( unsigned long ) valp ) ;
2006-01-10 07:52:11 +03:00
if ( ret )
return ret ;
2016-01-05 20:27:30 +03:00
return convert_in_user ( valp , ( unsigned int __user * ) argp ) ;
2006-01-10 07:52:11 +03:00
case RTC_IRQP_SET32 :
2016-01-07 17:53:30 +03:00
return do_ioctl ( file , RTC_IRQP_SET , ( unsigned long ) argp ) ;
2006-01-10 07:52:11 +03:00
case RTC_EPOCH_SET32 :
2016-01-07 17:53:30 +03:00
return do_ioctl ( file , RTC_EPOCH_SET , ( unsigned long ) argp ) ;
2006-01-10 07:52:11 +03:00
}
2009-11-15 01:16:18 +03:00
return - ENOIOCTLCMD ;
2006-01-10 07:52:11 +03:00
}
2009-06-19 22:28:07 +04:00
/* on ia32 l_start is on a 32-bit boundary */
# if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
struct space_resv_32 {
__s16 l_type ;
__s16 l_whence ;
__s64 l_start __attribute__ ( ( packed ) ) ;
/* len == 0 means until end of file */
__s64 l_len __attribute__ ( ( packed ) ) ;
__s32 l_sysid ;
__u32 l_pid ;
__s32 l_pad [ 4 ] ; /* reserve area */
} ;
# define FS_IOC_RESVSP_32 _IOW ('X', 40, struct space_resv_32)
# define FS_IOC_RESVSP64_32 _IOW ('X', 42, struct space_resv_32)
/* just account for different alignment */
2009-11-15 01:16:18 +03:00
static int compat_ioctl_preallocate ( struct file * file ,
struct space_resv_32 __user * p32 )
2009-06-19 22:28:07 +04:00
{
struct space_resv __user * p = compat_alloc_user_space ( sizeof ( * p ) ) ;
if ( copy_in_user ( & p - > l_type , & p32 - > l_type , sizeof ( s16 ) ) | |
copy_in_user ( & p - > l_whence , & p32 - > l_whence , sizeof ( s16 ) ) | |
copy_in_user ( & p - > l_start , & p32 - > l_start , sizeof ( s64 ) ) | |
copy_in_user ( & p - > l_len , & p32 - > l_len , sizeof ( s64 ) ) | |
copy_in_user ( & p - > l_sysid , & p32 - > l_sysid , sizeof ( s32 ) ) | |
copy_in_user ( & p - > l_pid , & p32 - > l_pid , sizeof ( u32 ) ) | |
copy_in_user ( & p - > l_pad , & p32 - > l_pad , 4 * sizeof ( u32 ) ) )
return - EFAULT ;
return ioctl_preallocate ( file , p ) ;
}
# endif
2009-11-05 21:52:55 +03:00
/*
* simple reversible transform to make our table more evenly
* distributed after sorting .
*/
# define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff)
2007-05-08 11:29:21 +04:00
2017-04-29 01:15:12 +03:00
# define COMPATIBLE_IOCTL(cmd) XFORM((u32)cmd),
2007-05-02 21:27:20 +04:00
/* ioctl should not be warned about even if it's not implemented.
Valid reasons to use this :
- It is implemented with - > compat_ioctl on some device , but programs
call it on others too .
- The ioctl is not implemented in the native kernel , but programs
call it commonly anyways .
Most other reasons are not valid . */
# define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
2006-01-10 07:52:14 +03:00
2009-11-05 21:52:55 +03:00
static unsigned int ioctl_pointer [ ] = {
2007-05-08 11:29:07 +04:00
/* compatible ioctls first */
/* Little t */
COMPATIBLE_IOCTL ( TIOCOUTQ )
/* Little f */
COMPATIBLE_IOCTL ( FIOCLEX )
COMPATIBLE_IOCTL ( FIONCLEX )
COMPATIBLE_IOCTL ( FIOASYNC )
COMPATIBLE_IOCTL ( FIONBIO )
COMPATIBLE_IOCTL ( FIONREAD ) /* This is also TIOCINQ */
2009-08-07 02:07:37 +04:00
COMPATIBLE_IOCTL ( FS_IOC_FIEMAP )
2007-05-08 11:29:07 +04:00
/* 0x00 */
COMPATIBLE_IOCTL ( FIBMAP )
COMPATIBLE_IOCTL ( FIGETBSZ )
2009-02-26 23:32:51 +03:00
/* 'X' - originally XFS but some now in the VFS */
COMPATIBLE_IOCTL ( FIFREEZE )
COMPATIBLE_IOCTL ( FITHAW )
2015-07-09 19:05:15 +03:00
COMPATIBLE_IOCTL ( FITRIM )
2008-07-16 17:52:00 +04:00
# ifdef CONFIG_BLOCK
2007-05-08 11:29:07 +04:00
/* Big S */
COMPATIBLE_IOCTL ( SCSI_IOCTL_GET_IDLUN )
COMPATIBLE_IOCTL ( SCSI_IOCTL_DOORLOCK )
COMPATIBLE_IOCTL ( SCSI_IOCTL_DOORUNLOCK )
COMPATIBLE_IOCTL ( SCSI_IOCTL_TEST_UNIT_READY )
COMPATIBLE_IOCTL ( SCSI_IOCTL_GET_BUS_NUMBER )
COMPATIBLE_IOCTL ( SCSI_IOCTL_SEND_COMMAND )
COMPATIBLE_IOCTL ( SCSI_IOCTL_PROBE_HOST )
COMPATIBLE_IOCTL ( SCSI_IOCTL_GET_PCI )
2008-07-16 17:52:00 +04:00
# endif
2010-01-10 17:29:16 +03:00
/* Big V (don't complain on serial console) */
IGNORE_IOCTL ( VT_OPENQRY )
IGNORE_IOCTL ( VT_GETMODE )
2007-05-08 11:29:07 +04:00
/* Little p (/dev/rtc, /dev/envctrl, etc.) */
COMPATIBLE_IOCTL ( RTC_AIE_ON )
COMPATIBLE_IOCTL ( RTC_AIE_OFF )
COMPATIBLE_IOCTL ( RTC_UIE_ON )
COMPATIBLE_IOCTL ( RTC_UIE_OFF )
COMPATIBLE_IOCTL ( RTC_PIE_ON )
COMPATIBLE_IOCTL ( RTC_PIE_OFF )
COMPATIBLE_IOCTL ( RTC_WIE_ON )
COMPATIBLE_IOCTL ( RTC_WIE_OFF )
COMPATIBLE_IOCTL ( RTC_ALM_SET )
COMPATIBLE_IOCTL ( RTC_ALM_READ )
COMPATIBLE_IOCTL ( RTC_RD_TIME )
COMPATIBLE_IOCTL ( RTC_SET_TIME )
COMPATIBLE_IOCTL ( RTC_WKALM_SET )
COMPATIBLE_IOCTL ( RTC_WKALM_RD )
/*
* These two are only for the sbus rtc driver , but
* hwclock tries them on every rtc device first when
* running on sparc . On other architectures the entries
* are useless but harmless .
*/
COMPATIBLE_IOCTL ( _IOR ( ' p ' , 20 , int [ 7 ] ) ) /* RTCGET */
COMPATIBLE_IOCTL ( _IOW ( ' p ' , 21 , int [ 7 ] ) ) /* RTCSET */
/* Little m */
COMPATIBLE_IOCTL ( MTIOCTOP )
/* Socket level stuff */
COMPATIBLE_IOCTL ( FIOQSIZE )
2008-07-16 17:52:00 +04:00
# ifdef CONFIG_BLOCK
2010-02-10 18:14:04 +03:00
/* md calls this on random blockdevs */
IGNORE_IOCTL ( RAID_VERSION )
2011-07-02 00:32:26 +04:00
/* qemu/qemu-img might call these two on plain files for probing */
IGNORE_IOCTL ( CDROM_DRIVE_STATUS )
IGNORE_IOCTL ( FDGETPRM32 )
2007-05-08 11:29:07 +04:00
/* SG stuff */
COMPATIBLE_IOCTL ( SG_SET_TIMEOUT )
COMPATIBLE_IOCTL ( SG_GET_TIMEOUT )
COMPATIBLE_IOCTL ( SG_EMULATED_HOST )
COMPATIBLE_IOCTL ( SG_GET_TRANSFORM )
COMPATIBLE_IOCTL ( SG_SET_RESERVED_SIZE )
COMPATIBLE_IOCTL ( SG_GET_RESERVED_SIZE )
COMPATIBLE_IOCTL ( SG_GET_SCSI_ID )
COMPATIBLE_IOCTL ( SG_SET_FORCE_LOW_DMA )
COMPATIBLE_IOCTL ( SG_GET_LOW_DMA )
COMPATIBLE_IOCTL ( SG_SET_FORCE_PACK_ID )
COMPATIBLE_IOCTL ( SG_GET_PACK_ID )
COMPATIBLE_IOCTL ( SG_GET_NUM_WAITING )
COMPATIBLE_IOCTL ( SG_SET_DEBUG )
COMPATIBLE_IOCTL ( SG_GET_SG_TABLESIZE )
COMPATIBLE_IOCTL ( SG_GET_COMMAND_Q )
COMPATIBLE_IOCTL ( SG_SET_COMMAND_Q )
COMPATIBLE_IOCTL ( SG_GET_VERSION_NUM )
COMPATIBLE_IOCTL ( SG_NEXT_CMD_LEN )
COMPATIBLE_IOCTL ( SG_SCSI_RESET )
COMPATIBLE_IOCTL ( SG_GET_REQUEST_TABLE )
COMPATIBLE_IOCTL ( SG_SET_KEEP_ORPHAN )
COMPATIBLE_IOCTL ( SG_GET_KEEP_ORPHAN )
2008-07-16 17:52:00 +04:00
# endif
2007-05-08 11:29:07 +04:00
/* PPP stuff */
COMPATIBLE_IOCTL ( PPPIOCGFLAGS )
COMPATIBLE_IOCTL ( PPPIOCSFLAGS )
COMPATIBLE_IOCTL ( PPPIOCGASYNCMAP )
COMPATIBLE_IOCTL ( PPPIOCSASYNCMAP )
COMPATIBLE_IOCTL ( PPPIOCGUNIT )
COMPATIBLE_IOCTL ( PPPIOCGRASYNCMAP )
COMPATIBLE_IOCTL ( PPPIOCSRASYNCMAP )
COMPATIBLE_IOCTL ( PPPIOCGMRU )
COMPATIBLE_IOCTL ( PPPIOCSMRU )
COMPATIBLE_IOCTL ( PPPIOCSMAXCID )
COMPATIBLE_IOCTL ( PPPIOCGXASYNCMAP )
COMPATIBLE_IOCTL ( PPPIOCSXASYNCMAP )
COMPATIBLE_IOCTL ( PPPIOCXFERUNIT )
/* PPPIOCSCOMPRESS is translated */
COMPATIBLE_IOCTL ( PPPIOCGNPMODE )
COMPATIBLE_IOCTL ( PPPIOCSNPMODE )
COMPATIBLE_IOCTL ( PPPIOCGDEBUG )
COMPATIBLE_IOCTL ( PPPIOCSDEBUG )
/* PPPIOCSPASS is translated */
/* PPPIOCSACTIVE is translated */
/* PPPIOCGIDLE is translated */
COMPATIBLE_IOCTL ( PPPIOCNEWUNIT )
COMPATIBLE_IOCTL ( PPPIOCATTACH )
COMPATIBLE_IOCTL ( PPPIOCDETACH )
COMPATIBLE_IOCTL ( PPPIOCSMRRU )
COMPATIBLE_IOCTL ( PPPIOCCONNECT )
COMPATIBLE_IOCTL ( PPPIOCDISCONN )
COMPATIBLE_IOCTL ( PPPIOCATTCHAN )
COMPATIBLE_IOCTL ( PPPIOCGCHAN )
2011-08-06 16:12:04 +04:00
COMPATIBLE_IOCTL ( PPPIOCGL2TPSTATS )
2007-05-08 11:29:07 +04:00
/* PPPOX */
COMPATIBLE_IOCTL ( PPPOEIOCSFWD )
COMPATIBLE_IOCTL ( PPPOEIOCDFWD )
/* Big A */
/* sparc only */
/* Big Q for sound/OSS */
COMPATIBLE_IOCTL ( SNDCTL_SEQ_RESET )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_SYNC )
COMPATIBLE_IOCTL ( SNDCTL_SYNTH_INFO )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_CTRLRATE )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_GETOUTCOUNT )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_GETINCOUNT )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_PERCMODE )
COMPATIBLE_IOCTL ( SNDCTL_FM_LOAD_INSTR )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_TESTMIDI )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_RESETSAMPLES )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_NRSYNTHS )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_NRMIDIS )
COMPATIBLE_IOCTL ( SNDCTL_MIDI_INFO )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_THRESHOLD )
COMPATIBLE_IOCTL ( SNDCTL_SYNTH_MEMAVL )
COMPATIBLE_IOCTL ( SNDCTL_FM_4OP_ENABLE )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_PANIC )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_OUTOFBAND )
COMPATIBLE_IOCTL ( SNDCTL_SEQ_GETTIME )
COMPATIBLE_IOCTL ( SNDCTL_SYNTH_ID )
COMPATIBLE_IOCTL ( SNDCTL_SYNTH_CONTROL )
COMPATIBLE_IOCTL ( SNDCTL_SYNTH_REMOVESAMPLE )
/* Big T for sound/OSS */
COMPATIBLE_IOCTL ( SNDCTL_TMR_TIMEBASE )
COMPATIBLE_IOCTL ( SNDCTL_TMR_START )
COMPATIBLE_IOCTL ( SNDCTL_TMR_STOP )
COMPATIBLE_IOCTL ( SNDCTL_TMR_CONTINUE )
COMPATIBLE_IOCTL ( SNDCTL_TMR_TEMPO )
COMPATIBLE_IOCTL ( SNDCTL_TMR_SOURCE )
COMPATIBLE_IOCTL ( SNDCTL_TMR_METRONOME )
COMPATIBLE_IOCTL ( SNDCTL_TMR_SELECT )
/* Little m for sound/OSS */
COMPATIBLE_IOCTL ( SNDCTL_MIDI_PRETIME )
COMPATIBLE_IOCTL ( SNDCTL_MIDI_MPUMODE )
COMPATIBLE_IOCTL ( SNDCTL_MIDI_MPUCMD )
/* Big P for sound/OSS */
COMPATIBLE_IOCTL ( SNDCTL_DSP_RESET )
COMPATIBLE_IOCTL ( SNDCTL_DSP_SYNC )
COMPATIBLE_IOCTL ( SNDCTL_DSP_SPEED )
COMPATIBLE_IOCTL ( SNDCTL_DSP_STEREO )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETBLKSIZE )
COMPATIBLE_IOCTL ( SNDCTL_DSP_CHANNELS )
COMPATIBLE_IOCTL ( SOUND_PCM_WRITE_FILTER )
COMPATIBLE_IOCTL ( SNDCTL_DSP_POST )
COMPATIBLE_IOCTL ( SNDCTL_DSP_SUBDIVIDE )
COMPATIBLE_IOCTL ( SNDCTL_DSP_SETFRAGMENT )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETFMTS )
COMPATIBLE_IOCTL ( SNDCTL_DSP_SETFMT )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETOSPACE )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETISPACE )
COMPATIBLE_IOCTL ( SNDCTL_DSP_NONBLOCK )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETCAPS )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETTRIGGER )
COMPATIBLE_IOCTL ( SNDCTL_DSP_SETTRIGGER )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETIPTR )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETOPTR )
/* SNDCTL_DSP_MAPINBUF, XXX needs translation */
/* SNDCTL_DSP_MAPOUTBUF, XXX needs translation */
COMPATIBLE_IOCTL ( SNDCTL_DSP_SETSYNCRO )
COMPATIBLE_IOCTL ( SNDCTL_DSP_SETDUPLEX )
COMPATIBLE_IOCTL ( SNDCTL_DSP_GETODELAY )
COMPATIBLE_IOCTL ( SNDCTL_DSP_PROFILE )
COMPATIBLE_IOCTL ( SOUND_PCM_READ_RATE )
COMPATIBLE_IOCTL ( SOUND_PCM_READ_CHANNELS )
COMPATIBLE_IOCTL ( SOUND_PCM_READ_BITS )
COMPATIBLE_IOCTL ( SOUND_PCM_READ_FILTER )
/* Big C for sound/OSS */
COMPATIBLE_IOCTL ( SNDCTL_COPR_RESET )
COMPATIBLE_IOCTL ( SNDCTL_COPR_LOAD )
COMPATIBLE_IOCTL ( SNDCTL_COPR_RDATA )
COMPATIBLE_IOCTL ( SNDCTL_COPR_RCODE )
COMPATIBLE_IOCTL ( SNDCTL_COPR_WDATA )
COMPATIBLE_IOCTL ( SNDCTL_COPR_WCODE )
COMPATIBLE_IOCTL ( SNDCTL_COPR_RUN )
COMPATIBLE_IOCTL ( SNDCTL_COPR_HALT )
COMPATIBLE_IOCTL ( SNDCTL_COPR_SENDMSG )
COMPATIBLE_IOCTL ( SNDCTL_COPR_RCVMSG )
/* Big M for sound/OSS */
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_VOLUME )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_BASS )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_TREBLE )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_SYNTH )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_PCM )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_SPEAKER )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_LINE )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_MIC )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_CD )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_IMIX )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_ALTPCM )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_RECLEV )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_IGAIN )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_OGAIN )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_LINE1 )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_LINE2 )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_LINE3 )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_DIGITAL1 ) )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_DIGITAL2 ) )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_DIGITAL3 ) )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_PHONEIN ) )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_PHONEOUT ) )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_VIDEO ) )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_RADIO ) )
COMPATIBLE_IOCTL ( MIXER_READ ( SOUND_MIXER_MONITOR ) )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_MUTE )
/* SOUND_MIXER_READ_ENHANCE, same value as READ_MUTE */
/* SOUND_MIXER_READ_LOUD, same value as READ_MUTE */
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_RECSRC )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_DEVMASK )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_RECMASK )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_STEREODEVS )
COMPATIBLE_IOCTL ( SOUND_MIXER_READ_CAPS )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_VOLUME )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_BASS )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_TREBLE )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_SYNTH )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_PCM )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_SPEAKER )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_LINE )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_MIC )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_CD )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_IMIX )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_ALTPCM )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_RECLEV )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_IGAIN )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_OGAIN )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_LINE1 )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_LINE2 )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_LINE3 )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_DIGITAL1 ) )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_DIGITAL2 ) )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_DIGITAL3 ) )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_PHONEIN ) )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_PHONEOUT ) )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_VIDEO ) )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_RADIO ) )
COMPATIBLE_IOCTL ( MIXER_WRITE ( SOUND_MIXER_MONITOR ) )
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_MUTE )
/* SOUND_MIXER_WRITE_ENHANCE, same value as WRITE_MUTE */
/* SOUND_MIXER_WRITE_LOUD, same value as WRITE_MUTE */
COMPATIBLE_IOCTL ( SOUND_MIXER_WRITE_RECSRC )
COMPATIBLE_IOCTL ( SOUND_MIXER_INFO )
COMPATIBLE_IOCTL ( SOUND_OLD_MIXER_INFO )
COMPATIBLE_IOCTL ( SOUND_MIXER_ACCESS )
COMPATIBLE_IOCTL ( SOUND_MIXER_AGC )
COMPATIBLE_IOCTL ( SOUND_MIXER_3DSE )
COMPATIBLE_IOCTL ( SOUND_MIXER_PRIVATE1 )
COMPATIBLE_IOCTL ( SOUND_MIXER_PRIVATE2 )
COMPATIBLE_IOCTL ( SOUND_MIXER_PRIVATE3 )
COMPATIBLE_IOCTL ( SOUND_MIXER_PRIVATE4 )
COMPATIBLE_IOCTL ( SOUND_MIXER_PRIVATE5 )
COMPATIBLE_IOCTL ( SOUND_MIXER_GETLEVELS )
COMPATIBLE_IOCTL ( SOUND_MIXER_SETLEVELS )
COMPATIBLE_IOCTL ( OSS_GETVERSION )
/* Raw devices */
COMPATIBLE_IOCTL ( RAW_SETBIND )
COMPATIBLE_IOCTL ( RAW_GETBIND )
/* Watchdog */
COMPATIBLE_IOCTL ( WDIOC_GETSUPPORT )
COMPATIBLE_IOCTL ( WDIOC_GETSTATUS )
COMPATIBLE_IOCTL ( WDIOC_GETBOOTSTATUS )
COMPATIBLE_IOCTL ( WDIOC_GETTEMP )
COMPATIBLE_IOCTL ( WDIOC_SETOPTIONS )
COMPATIBLE_IOCTL ( WDIOC_KEEPALIVE )
COMPATIBLE_IOCTL ( WDIOC_SETTIMEOUT )
COMPATIBLE_IOCTL ( WDIOC_GETTIMEOUT )
2016-08-31 14:52:42 +03:00
COMPATIBLE_IOCTL ( WDIOC_SETPRETIMEOUT )
COMPATIBLE_IOCTL ( WDIOC_GETPRETIMEOUT )
2007-05-08 11:29:07 +04:00
/* Big R */
COMPATIBLE_IOCTL ( RNDGETENTCNT )
COMPATIBLE_IOCTL ( RNDADDTOENTCNT )
COMPATIBLE_IOCTL ( RNDGETPOOL )
COMPATIBLE_IOCTL ( RNDADDENTROPY )
COMPATIBLE_IOCTL ( RNDZAPENTCNT )
COMPATIBLE_IOCTL ( RNDCLEARPOOL )
/* Bluetooth */
COMPATIBLE_IOCTL ( HCIDEVUP )
COMPATIBLE_IOCTL ( HCIDEVDOWN )
COMPATIBLE_IOCTL ( HCIDEVRESET )
COMPATIBLE_IOCTL ( HCIDEVRESTAT )
COMPATIBLE_IOCTL ( HCIGETDEVLIST )
COMPATIBLE_IOCTL ( HCIGETDEVINFO )
COMPATIBLE_IOCTL ( HCIGETCONNLIST )
COMPATIBLE_IOCTL ( HCIGETCONNINFO )
2008-07-14 22:13:50 +04:00
COMPATIBLE_IOCTL ( HCIGETAUTHINFO )
2007-05-08 11:29:07 +04:00
COMPATIBLE_IOCTL ( HCISETRAW )
COMPATIBLE_IOCTL ( HCISETSCAN )
COMPATIBLE_IOCTL ( HCISETAUTH )
COMPATIBLE_IOCTL ( HCISETENCRYPT )
COMPATIBLE_IOCTL ( HCISETPTYPE )
COMPATIBLE_IOCTL ( HCISETLINKPOL )
COMPATIBLE_IOCTL ( HCISETLINKMODE )
COMPATIBLE_IOCTL ( HCISETACLMTU )
COMPATIBLE_IOCTL ( HCISETSCOMTU )
2010-05-18 15:20:32 +04:00
COMPATIBLE_IOCTL ( HCIBLOCKADDR )
COMPATIBLE_IOCTL ( HCIUNBLOCKADDR )
2007-05-08 11:29:07 +04:00
COMPATIBLE_IOCTL ( HCIINQUIRY )
COMPATIBLE_IOCTL ( HCIUARTSETPROTO )
COMPATIBLE_IOCTL ( HCIUARTGETPROTO )
2016-01-25 10:44:03 +03:00
COMPATIBLE_IOCTL ( HCIUARTGETDEVICE )
COMPATIBLE_IOCTL ( HCIUARTSETFLAGS )
COMPATIBLE_IOCTL ( HCIUARTGETFLAGS )
2007-05-08 11:29:07 +04:00
COMPATIBLE_IOCTL ( RFCOMMCREATEDEV )
COMPATIBLE_IOCTL ( RFCOMMRELEASEDEV )
COMPATIBLE_IOCTL ( RFCOMMGETDEVLIST )
COMPATIBLE_IOCTL ( RFCOMMGETDEVINFO )
COMPATIBLE_IOCTL ( RFCOMMSTEALDLC )
/* CAPI */
COMPATIBLE_IOCTL ( CAPI_REGISTER )
COMPATIBLE_IOCTL ( CAPI_GET_MANUFACTURER )
COMPATIBLE_IOCTL ( CAPI_GET_VERSION )
COMPATIBLE_IOCTL ( CAPI_GET_SERIAL )
COMPATIBLE_IOCTL ( CAPI_GET_PROFILE )
COMPATIBLE_IOCTL ( CAPI_MANUFACTURER_CMD )
COMPATIBLE_IOCTL ( CAPI_GET_ERRCODE )
COMPATIBLE_IOCTL ( CAPI_INSTALLED )
COMPATIBLE_IOCTL ( CAPI_GET_FLAGS )
COMPATIBLE_IOCTL ( CAPI_SET_FLAGS )
COMPATIBLE_IOCTL ( CAPI_CLR_FLAGS )
COMPATIBLE_IOCTL ( CAPI_NCCI_OPENCOUNT )
COMPATIBLE_IOCTL ( CAPI_NCCI_GETUNIT )
/* Misc. */
COMPATIBLE_IOCTL ( 0x41545900 ) /* ATYIO_CLKR */
COMPATIBLE_IOCTL ( 0x41545901 ) /* ATYIO_CLKW */
COMPATIBLE_IOCTL ( PCIIOC_CONTROLLER )
COMPATIBLE_IOCTL ( PCIIOC_MMAP_IS_IO )
COMPATIBLE_IOCTL ( PCIIOC_MMAP_IS_MEM )
COMPATIBLE_IOCTL ( PCIIOC_WRITE_COMBINE )
/* hiddev */
COMPATIBLE_IOCTL ( HIDIOCGVERSION )
COMPATIBLE_IOCTL ( HIDIOCAPPLICATION )
COMPATIBLE_IOCTL ( HIDIOCGDEVINFO )
COMPATIBLE_IOCTL ( HIDIOCGSTRING )
COMPATIBLE_IOCTL ( HIDIOCINITREPORT )
COMPATIBLE_IOCTL ( HIDIOCGREPORT )
COMPATIBLE_IOCTL ( HIDIOCSREPORT )
COMPATIBLE_IOCTL ( HIDIOCGREPORTINFO )
COMPATIBLE_IOCTL ( HIDIOCGFIELDINFO )
COMPATIBLE_IOCTL ( HIDIOCGUSAGE )
COMPATIBLE_IOCTL ( HIDIOCSUSAGE )
COMPATIBLE_IOCTL ( HIDIOCGUCODE )
COMPATIBLE_IOCTL ( HIDIOCGFLAG )
COMPATIBLE_IOCTL ( HIDIOCSFLAG )
COMPATIBLE_IOCTL ( HIDIOCGCOLLECTIONINDEX )
COMPATIBLE_IOCTL ( HIDIOCGCOLLECTIONINFO )
2008-01-06 13:15:55 +03:00
/* joystick */
COMPATIBLE_IOCTL ( JSIOCGVERSION )
COMPATIBLE_IOCTL ( JSIOCGAXES )
COMPATIBLE_IOCTL ( JSIOCGBUTTONS )
COMPATIBLE_IOCTL ( JSIOCGNAME ( 0 ) )
2007-05-02 21:27:21 +04:00
/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
but we don ' t want warnings on other file systems . So declare
them as compatible here . */
# define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
# define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
IGNORE_IOCTL ( VFAT_IOCTL_READDIR_BOTH32 )
IGNORE_IOCTL ( VFAT_IOCTL_READDIR_SHORT32 )
2007-07-16 10:42:01 +04:00
2007-07-29 11:50:42 +04:00
# ifdef CONFIG_SPARC
/* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
IGNORE_IOCTL ( FBIOGTYPE )
IGNORE_IOCTL ( FBIOSATTR )
IGNORE_IOCTL ( FBIOGATTR )
IGNORE_IOCTL ( FBIOSVIDEO )
IGNORE_IOCTL ( FBIOGVIDEO )
IGNORE_IOCTL ( FBIOSCURPOS )
IGNORE_IOCTL ( FBIOGCURPOS )
IGNORE_IOCTL ( FBIOGCURMAX )
IGNORE_IOCTL ( FBIOPUTCMAP32 )
IGNORE_IOCTL ( FBIOGETCMAP32 )
IGNORE_IOCTL ( FBIOSCURSOR32 )
IGNORE_IOCTL ( FBIOGCURSOR32 )
# endif
2006-01-10 07:52:14 +03:00
} ;
2005-11-16 11:52:57 +03:00
2009-05-22 02:04:16 +04:00
/*
* Convert common ioctl arguments based on their command number
*
* Please do not add any code in here . Instead , implement
* a compat_ioctl operation in the place that handleѕ the
* ioctl for the native case .
*/
2016-01-07 17:53:30 +03:00
static long do_ioctl_trans ( unsigned int cmd ,
2009-05-22 02:04:16 +04:00
unsigned long arg , struct file * file )
{
2009-11-15 01:16:18 +03:00
void __user * argp = compat_ptr ( arg ) ;
2009-05-22 02:04:16 +04:00
switch ( cmd ) {
case PPPIOCGIDLE32 :
2016-01-07 17:53:30 +03:00
return ppp_gidle ( file , cmd , argp ) ;
2009-05-22 02:04:16 +04:00
case PPPIOCSCOMPRESS32 :
2016-01-07 17:53:30 +03:00
return ppp_scompress ( file , cmd , argp ) ;
2009-05-22 02:04:16 +04:00
case PPPIOCSPASS32 :
case PPPIOCSACTIVE32 :
2016-01-07 17:53:30 +03:00
return ppp_sock_fprog_ioctl_trans ( file , cmd , argp ) ;
2009-05-22 02:04:16 +04:00
# ifdef CONFIG_BLOCK
case SG_IO :
2016-01-07 17:53:30 +03:00
return sg_ioctl_trans ( file , cmd , argp ) ;
2009-05-22 02:04:16 +04:00
case SG_GET_REQUEST_TABLE :
2016-01-07 17:53:30 +03:00
return sg_grt_trans ( file , cmd , argp ) ;
2009-05-22 02:04:16 +04:00
case MTIOCGET32 :
case MTIOCPOS32 :
2016-01-07 17:53:30 +03:00
return mt_ioctl_trans ( file , cmd , argp ) ;
2009-05-22 02:04:16 +04:00
# endif
/* Not implemented in the native kernel */
case RTC_IRQP_READ32 :
case RTC_IRQP_SET32 :
case RTC_EPOCH_READ32 :
case RTC_EPOCH_SET32 :
2016-01-07 17:53:30 +03:00
return rtc_ioctl ( file , cmd , argp ) ;
2009-05-22 02:04:16 +04:00
}
2009-11-05 21:13:51 +03:00
/*
* These take an integer instead of a pointer as ' arg ' ,
* so we must not do a compat_ptr ( ) translation .
*/
switch ( cmd ) {
/* RAID */
case HOT_REMOVE_DISK :
case HOT_ADD_DISK :
case SET_DISK_FAULTY :
case SET_BITMAP_FILE :
2016-01-07 17:53:30 +03:00
return vfs_ioctl ( file , cmd , arg ) ;
2009-11-05 21:13:51 +03:00
}
2009-05-22 02:04:16 +04:00
return - ENOIOCTLCMD ;
}
2009-11-05 21:52:55 +03:00
static int compat_ioctl_check_table ( unsigned int xcmd )
{
int i ;
const int max = ARRAY_SIZE ( ioctl_pointer ) - 1 ;
BUILD_BUG_ON ( max > = ( 1 < < 16 ) ) ;
/* guess initial offset into table, assuming a
normalized distribution */
i = ( ( xcmd > > 16 ) * max ) > > 16 ;
/* do linear search up first, until greater or equal */
while ( ioctl_pointer [ i ] < xcmd & & i < max )
i + + ;
/* then do linear search down */
while ( ioctl_pointer [ i ] > xcmd & & i > 0 )
i - - ;
return ioctl_pointer [ i ] = = xcmd ;
}
2014-03-04 19:07:52 +04:00
COMPAT_SYSCALL_DEFINE3 ( ioctl , unsigned int , fd , unsigned int , cmd ,
compat_ulong_t , arg32 )
2007-05-08 11:29:21 +04:00
{
2014-03-04 19:07:52 +04:00
unsigned long arg = arg32 ;
2012-08-28 20:52:22 +04:00
struct fd f = fdget ( fd ) ;
2007-05-08 11:29:21 +04:00
int error = - EBADF ;
2012-08-28 20:52:22 +04:00
if ( ! f . file )
2007-05-08 11:29:21 +04:00
goto out ;
/* RED-PEN how should LSM module know it's handling 32bit? */
2012-08-28 20:52:22 +04:00
error = security_file_ioctl ( f . file , cmd , arg ) ;
2007-05-08 11:29:21 +04:00
if ( error )
goto out_fput ;
/*
* To allow the compat_ioctl handlers to be self contained
* we need to check the common ioctls here first .
* Just handle them with the standard handlers below .
*/
switch ( cmd ) {
case FIOCLEX :
case FIONCLEX :
case FIONBIO :
case FIOASYNC :
case FIOQSIZE :
break ;
2009-06-19 22:28:07 +04:00
# if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
case FS_IOC_RESVSP_32 :
case FS_IOC_RESVSP64_32 :
2012-08-28 20:52:22 +04:00
error = compat_ioctl_preallocate ( f . file , compat_ptr ( arg ) ) ;
2009-06-19 22:28:07 +04:00
goto out_fput ;
# else
case FS_IOC_RESVSP :
case FS_IOC_RESVSP64 :
2012-08-28 20:52:22 +04:00
error = ioctl_preallocate ( f . file , compat_ptr ( arg ) ) ;
2009-06-19 22:28:07 +04:00
goto out_fput ;
# endif
2015-12-19 11:55:52 +03:00
case FICLONE :
case FICLONERANGE :
2015-12-19 11:55:59 +03:00
case FIDEDUPERANGE :
2017-09-29 22:24:06 +03:00
case FS_IOC_FIEMAP :
2015-12-19 11:55:52 +03:00
goto do_ioctl ;
2007-05-08 11:29:21 +04:00
case FIBMAP :
case FIGETBSZ :
case FIONREAD :
2013-01-24 02:07:38 +04:00
if ( S_ISREG ( file_inode ( f . file ) - > i_mode ) )
2007-05-08 11:29:21 +04:00
break ;
/*FALL THROUGH*/
default :
2013-09-23 00:27:52 +04:00
if ( f . file - > f_op - > compat_ioctl ) {
2012-08-28 20:52:22 +04:00
error = f . file - > f_op - > compat_ioctl ( f . file , cmd , arg ) ;
2007-05-08 11:29:21 +04:00
if ( error ! = - ENOIOCTLCMD )
goto out_fput ;
}
2013-09-23 00:27:52 +04:00
if ( ! f . file - > f_op - > unlocked_ioctl )
2007-05-08 11:29:21 +04:00
goto do_ioctl ;
break ;
}
2009-11-05 21:52:55 +03:00
if ( compat_ioctl_check_table ( XFORM ( cmd ) ) )
goto found_handler ;
2007-05-08 11:29:21 +04:00
2016-01-07 17:53:30 +03:00
error = do_ioctl_trans ( cmd , arg , f . file ) ;
2012-01-06 03:40:12 +04:00
if ( error = = - ENOIOCTLCMD )
error = - ENOTTY ;
2007-05-08 11:29:21 +04:00
goto out_fput ;
found_handler :
2009-11-05 21:13:51 +03:00
arg = ( unsigned long ) compat_ptr ( arg ) ;
2007-05-08 11:29:21 +04:00
do_ioctl :
2012-08-28 20:52:22 +04:00
error = do_vfs_ioctl ( f . file , fd , cmd , arg ) ;
2007-05-08 11:29:21 +04:00
out_fput :
2012-08-28 20:52:22 +04:00
fdput ( f ) ;
2007-05-08 11:29:21 +04:00
out :
return error ;
}
2009-11-05 21:52:55 +03:00
static int __init init_sys32_ioctl_cmp ( const void * p , const void * q )
2007-05-08 11:29:21 +04:00
{
2009-11-05 21:52:55 +03:00
unsigned int a , b ;
a = * ( unsigned int * ) p ;
b = * ( unsigned int * ) q ;
if ( a > b )
return 1 ;
if ( a < b )
return - 1 ;
return 0 ;
2007-05-08 11:29:21 +04:00
}
static int __init init_sys32_ioctl ( void )
{
2009-11-05 21:52:55 +03:00
sort ( ioctl_pointer , ARRAY_SIZE ( ioctl_pointer ) , sizeof ( * ioctl_pointer ) ,
init_sys32_ioctl_cmp , NULL ) ;
2007-05-08 11:29:21 +04:00
return 0 ;
}
__initcall ( init_sys32_ioctl ) ;