2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2006-01-15 00:35:31 +08:00
|
|
|
/*
|
|
|
|
* arch/arm/kernel/sys_oabi-compat.c
|
|
|
|
*
|
|
|
|
* Compatibility wrappers for syscalls that are used from
|
|
|
|
* old ABI user space binaries with an EABI kernel.
|
|
|
|
*
|
|
|
|
* Author: Nicolas Pitre
|
|
|
|
* Created: Oct 7, 2005
|
|
|
|
* Copyright: MontaVista Software, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The legacy ABI and the new ARM EABI have different rules making some
|
|
|
|
* syscalls incompatible especially with structure arguments.
|
|
|
|
* Most notably, Eabi says 64-bit members should be 64-bit aligned instead of
|
|
|
|
* simply word aligned. EABI also pads structures to the size of the largest
|
|
|
|
* member it contains instead of the invariant 32-bit.
|
|
|
|
*
|
|
|
|
* The following syscalls are affected:
|
|
|
|
*
|
|
|
|
* sys_stat64:
|
|
|
|
* sys_lstat64:
|
|
|
|
* sys_fstat64:
|
2008-03-28 20:08:09 +08:00
|
|
|
* sys_fstatat64:
|
2006-01-15 00:35:31 +08:00
|
|
|
*
|
|
|
|
* struct stat64 has different sizes and some members are shifted
|
|
|
|
* Compatibility wrappers are needed for them and provided below.
|
|
|
|
*
|
|
|
|
* sys_fcntl64:
|
|
|
|
*
|
|
|
|
* struct flock64 has different sizes and some members are shifted
|
|
|
|
* A compatibility wrapper is needed and provided below.
|
|
|
|
*
|
|
|
|
* sys_statfs64:
|
|
|
|
* sys_fstatfs64:
|
|
|
|
*
|
|
|
|
* struct statfs64 has extra padding with EABI growing its size from
|
|
|
|
* 84 to 88. This struct is now __attribute__((packed,aligned(4)))
|
|
|
|
* with a small assembly wrapper to force the sz argument to 84 if it is 88
|
|
|
|
* to avoid copying the extra padding over user space unexpecting it.
|
|
|
|
*
|
|
|
|
* sys_newuname:
|
|
|
|
*
|
|
|
|
* struct new_utsname has no padding with EABI. No problem there.
|
|
|
|
*
|
|
|
|
* sys_epoll_ctl:
|
|
|
|
* sys_epoll_wait:
|
|
|
|
*
|
|
|
|
* struct epoll_event has its second member shifted also affecting the
|
|
|
|
* structure size. Compatibility wrappers are needed and provided below.
|
|
|
|
*
|
|
|
|
* sys_ipc:
|
|
|
|
* sys_semop:
|
|
|
|
* sys_semtimedop:
|
|
|
|
*
|
|
|
|
* struct sembuf loses its padding with EABI. Since arrays of them are
|
|
|
|
* used they have to be copyed to remove the padding. Compatibility wrappers
|
|
|
|
* provided below.
|
2006-02-09 05:19:36 +08:00
|
|
|
*
|
|
|
|
* sys_bind:
|
|
|
|
* sys_connect:
|
|
|
|
* sys_sendmsg:
|
|
|
|
* sys_sendto:
|
2006-02-17 06:36:13 +08:00
|
|
|
* sys_socketcall:
|
2006-02-09 05:19:36 +08:00
|
|
|
*
|
|
|
|
* struct sockaddr_un loses its padding with EABI. Since the size of the
|
|
|
|
* structure is used as a validation test in unix_mkname(), we need to
|
|
|
|
* change the length argument to 110 whenever it is 112. Compatibility
|
|
|
|
* wrappers provided below.
|
2006-01-15 00:35:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/syscalls.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
2017-02-03 00:54:15 +08:00
|
|
|
#include <linux/cred.h>
|
2006-01-15 00:35:31 +08:00
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/eventpoll.h>
|
|
|
|
#include <linux/sem.h>
|
2006-02-09 05:19:36 +08:00
|
|
|
#include <linux/socket.h>
|
2006-02-17 06:36:13 +08:00
|
|
|
#include <linux/net.h>
|
2007-10-17 14:29:24 +08:00
|
|
|
#include <linux/ipc.h>
|
2008-09-06 18:35:55 +08:00
|
|
|
#include <linux/uaccess.h>
|
2009-04-16 16:55:23 +08:00
|
|
|
#include <linux/slab.h>
|
2006-01-15 00:35:31 +08:00
|
|
|
|
|
|
|
struct oldabi_stat64 {
|
|
|
|
unsigned long long st_dev;
|
|
|
|
unsigned int __pad1;
|
|
|
|
unsigned long __st_ino;
|
|
|
|
unsigned int st_mode;
|
|
|
|
unsigned int st_nlink;
|
|
|
|
|
|
|
|
unsigned long st_uid;
|
|
|
|
unsigned long st_gid;
|
|
|
|
|
|
|
|
unsigned long long st_rdev;
|
|
|
|
unsigned int __pad2;
|
|
|
|
|
|
|
|
long long st_size;
|
|
|
|
unsigned long st_blksize;
|
|
|
|
unsigned long long st_blocks;
|
|
|
|
|
|
|
|
unsigned long st_atime;
|
|
|
|
unsigned long st_atime_nsec;
|
|
|
|
|
|
|
|
unsigned long st_mtime;
|
|
|
|
unsigned long st_mtime_nsec;
|
|
|
|
|
|
|
|
unsigned long st_ctime;
|
|
|
|
unsigned long st_ctime_nsec;
|
|
|
|
|
|
|
|
unsigned long long st_ino;
|
|
|
|
} __attribute__ ((packed,aligned(4)));
|
|
|
|
|
|
|
|
static long cp_oldabi_stat64(struct kstat *stat,
|
|
|
|
struct oldabi_stat64 __user *statbuf)
|
|
|
|
{
|
|
|
|
struct oldabi_stat64 tmp;
|
|
|
|
|
|
|
|
tmp.st_dev = huge_encode_dev(stat->dev);
|
|
|
|
tmp.__pad1 = 0;
|
|
|
|
tmp.__st_ino = stat->ino;
|
|
|
|
tmp.st_mode = stat->mode;
|
|
|
|
tmp.st_nlink = stat->nlink;
|
2012-02-10 01:10:30 +08:00
|
|
|
tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
|
|
|
|
tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
|
2006-01-15 00:35:31 +08:00
|
|
|
tmp.st_rdev = huge_encode_dev(stat->rdev);
|
|
|
|
tmp.st_size = stat->size;
|
|
|
|
tmp.st_blocks = stat->blocks;
|
|
|
|
tmp.__pad2 = 0;
|
|
|
|
tmp.st_blksize = stat->blksize;
|
|
|
|
tmp.st_atime = stat->atime.tv_sec;
|
|
|
|
tmp.st_atime_nsec = stat->atime.tv_nsec;
|
|
|
|
tmp.st_mtime = stat->mtime.tv_sec;
|
|
|
|
tmp.st_mtime_nsec = stat->mtime.tv_nsec;
|
|
|
|
tmp.st_ctime = stat->ctime.tv_sec;
|
|
|
|
tmp.st_ctime_nsec = stat->ctime.tv_nsec;
|
|
|
|
tmp.st_ino = stat->ino;
|
|
|
|
return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
2010-08-11 18:26:22 +08:00
|
|
|
asmlinkage long sys_oabi_stat64(const char __user * filename,
|
2006-01-15 00:35:31 +08:00
|
|
|
struct oldabi_stat64 __user * statbuf)
|
|
|
|
{
|
|
|
|
struct kstat stat;
|
|
|
|
int error = vfs_stat(filename, &stat);
|
|
|
|
if (!error)
|
|
|
|
error = cp_oldabi_stat64(&stat, statbuf);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-08-11 18:26:22 +08:00
|
|
|
asmlinkage long sys_oabi_lstat64(const char __user * filename,
|
2006-01-15 00:35:31 +08:00
|
|
|
struct oldabi_stat64 __user * statbuf)
|
|
|
|
{
|
|
|
|
struct kstat stat;
|
|
|
|
int error = vfs_lstat(filename, &stat);
|
|
|
|
if (!error)
|
|
|
|
error = cp_oldabi_stat64(&stat, statbuf);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long sys_oabi_fstat64(unsigned long fd,
|
|
|
|
struct oldabi_stat64 __user * statbuf)
|
|
|
|
{
|
|
|
|
struct kstat stat;
|
|
|
|
int error = vfs_fstat(fd, &stat);
|
|
|
|
if (!error)
|
|
|
|
error = cp_oldabi_stat64(&stat, statbuf);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2008-03-28 20:08:09 +08:00
|
|
|
asmlinkage long sys_oabi_fstatat64(int dfd,
|
2010-08-11 18:26:22 +08:00
|
|
|
const char __user *filename,
|
2008-03-28 20:08:09 +08:00
|
|
|
struct oldabi_stat64 __user *statbuf,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
struct kstat stat;
|
2009-04-09 00:05:42 +08:00
|
|
|
int error;
|
2008-03-28 20:08:09 +08:00
|
|
|
|
2009-04-09 00:05:42 +08:00
|
|
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
return cp_oldabi_stat64(&stat, statbuf);
|
2008-03-28 20:08:09 +08:00
|
|
|
}
|
|
|
|
|
2006-01-15 00:35:31 +08:00
|
|
|
struct oabi_flock64 {
|
|
|
|
short l_type;
|
|
|
|
short l_whence;
|
|
|
|
loff_t l_start;
|
|
|
|
loff_t l_len;
|
|
|
|
pid_t l_pid;
|
|
|
|
} __attribute__ ((packed,aligned(4)));
|
|
|
|
|
2015-12-29 09:47:08 +08:00
|
|
|
static long do_locks(unsigned int fd, unsigned int cmd,
|
2006-01-15 00:35:31 +08:00
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
struct flock64 kernel;
|
2015-12-29 09:47:08 +08:00
|
|
|
struct oabi_flock64 user;
|
|
|
|
mm_segment_t fs;
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
if (copy_from_user(&user, (struct oabi_flock64 __user *)arg,
|
|
|
|
sizeof(user)))
|
|
|
|
return -EFAULT;
|
|
|
|
kernel.l_type = user.l_type;
|
|
|
|
kernel.l_whence = user.l_whence;
|
|
|
|
kernel.l_start = user.l_start;
|
|
|
|
kernel.l_len = user.l_len;
|
|
|
|
kernel.l_pid = user.l_pid;
|
|
|
|
|
|
|
|
fs = get_fs();
|
|
|
|
set_fs(KERNEL_DS);
|
|
|
|
ret = sys_fcntl64(fd, cmd, (unsigned long)&kernel);
|
|
|
|
set_fs(fs);
|
|
|
|
|
|
|
|
if (!ret && (cmd == F_GETLK64 || cmd == F_OFD_GETLK)) {
|
|
|
|
user.l_type = kernel.l_type;
|
|
|
|
user.l_whence = kernel.l_whence;
|
|
|
|
user.l_start = kernel.l_start;
|
|
|
|
user.l_len = kernel.l_len;
|
|
|
|
user.l_pid = kernel.l_pid;
|
|
|
|
if (copy_to_user((struct oabi_flock64 __user *)arg,
|
|
|
|
&user, sizeof(user)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2006-01-15 00:35:31 +08:00
|
|
|
|
2015-12-29 09:47:08 +08:00
|
|
|
asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
2006-01-15 00:35:31 +08:00
|
|
|
switch (cmd) {
|
2014-04-22 20:23:58 +08:00
|
|
|
case F_OFD_GETLK:
|
|
|
|
case F_OFD_SETLK:
|
|
|
|
case F_OFD_SETLKW:
|
2006-01-15 00:35:31 +08:00
|
|
|
case F_GETLK64:
|
|
|
|
case F_SETLK64:
|
|
|
|
case F_SETLKW64:
|
2015-12-29 09:47:08 +08:00
|
|
|
return do_locks(fd, cmd, arg);
|
2006-01-15 00:35:31 +08:00
|
|
|
|
2015-12-29 09:47:08 +08:00
|
|
|
default:
|
|
|
|
return sys_fcntl64(fd, cmd, arg);
|
2006-01-15 00:35:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct oabi_epoll_event {
|
|
|
|
__u32 events;
|
|
|
|
__u64 data;
|
|
|
|
} __attribute__ ((packed,aligned(4)));
|
|
|
|
|
|
|
|
asmlinkage long sys_oabi_epoll_ctl(int epfd, int op, int fd,
|
|
|
|
struct oabi_epoll_event __user *event)
|
|
|
|
{
|
|
|
|
struct oabi_epoll_event user;
|
|
|
|
struct epoll_event kernel;
|
|
|
|
|
2020-04-03 18:06:47 +08:00
|
|
|
if (ep_op_has_event(op) &&
|
|
|
|
copy_from_user(&user, event, sizeof(user)))
|
2006-01-15 00:35:31 +08:00
|
|
|
return -EFAULT;
|
2020-04-03 18:06:47 +08:00
|
|
|
|
2006-01-15 00:35:31 +08:00
|
|
|
kernel.events = user.events;
|
|
|
|
kernel.data = user.data;
|
2020-04-03 18:06:47 +08:00
|
|
|
|
|
|
|
return do_epoll_ctl(epfd, op, fd, &kernel, false);
|
2006-01-15 00:35:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long sys_oabi_epoll_wait(int epfd,
|
|
|
|
struct oabi_epoll_event __user *events,
|
|
|
|
int maxevents, int timeout)
|
|
|
|
{
|
|
|
|
struct epoll_event *kbuf;
|
2018-09-11 17:12:49 +08:00
|
|
|
struct oabi_epoll_event e;
|
2006-01-15 00:35:31 +08:00
|
|
|
mm_segment_t fs;
|
|
|
|
long ret, err, i;
|
|
|
|
|
2016-07-29 02:55:41 +08:00
|
|
|
if (maxevents <= 0 ||
|
|
|
|
maxevents > (INT_MAX/sizeof(*kbuf)) ||
|
|
|
|
maxevents > (INT_MAX/sizeof(*events)))
|
2006-01-15 00:35:31 +08:00
|
|
|
return -EINVAL;
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 10:57:57 +08:00
|
|
|
if (!access_ok(events, sizeof(*events) * maxevents))
|
2016-07-29 02:55:41 +08:00
|
|
|
return -EFAULT;
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
kbuf = kmalloc_array(maxevents, sizeof(*kbuf), GFP_KERNEL);
|
2006-01-15 00:35:31 +08:00
|
|
|
if (!kbuf)
|
|
|
|
return -ENOMEM;
|
|
|
|
fs = get_fs();
|
|
|
|
set_fs(KERNEL_DS);
|
|
|
|
ret = sys_epoll_wait(epfd, kbuf, maxevents, timeout);
|
|
|
|
set_fs(fs);
|
|
|
|
err = 0;
|
|
|
|
for (i = 0; i < ret; i++) {
|
2018-09-11 17:12:49 +08:00
|
|
|
e.events = kbuf[i].events;
|
|
|
|
e.data = kbuf[i].data;
|
|
|
|
err = __copy_to_user(events, &e, sizeof(e));
|
|
|
|
if (err)
|
|
|
|
break;
|
2006-01-15 00:35:31 +08:00
|
|
|
events++;
|
|
|
|
}
|
|
|
|
kfree(kbuf);
|
|
|
|
return err ? -EFAULT : ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct oabi_sembuf {
|
|
|
|
unsigned short sem_num;
|
|
|
|
short sem_op;
|
|
|
|
short sem_flg;
|
|
|
|
unsigned short __pad;
|
|
|
|
};
|
|
|
|
|
|
|
|
asmlinkage long sys_oabi_semtimedop(int semid,
|
|
|
|
struct oabi_sembuf __user *tsops,
|
|
|
|
unsigned nsops,
|
2019-01-01 08:13:32 +08:00
|
|
|
const struct old_timespec32 __user *timeout)
|
2006-01-15 00:35:31 +08:00
|
|
|
{
|
|
|
|
struct sembuf *sops;
|
2019-01-01 08:13:32 +08:00
|
|
|
struct old_timespec32 local_timeout;
|
2006-01-15 00:35:31 +08:00
|
|
|
long err;
|
|
|
|
int i;
|
|
|
|
|
2011-04-29 22:48:07 +08:00
|
|
|
if (nsops < 1 || nsops > SEMOPM)
|
2006-01-15 00:35:31 +08:00
|
|
|
return -EINVAL;
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 10:57:57 +08:00
|
|
|
if (!access_ok(tsops, sizeof(*tsops) * nsops))
|
2016-07-29 02:55:41 +08:00
|
|
|
return -EFAULT;
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
sops = kmalloc_array(nsops, sizeof(*sops), GFP_KERNEL);
|
2006-01-15 00:35:31 +08:00
|
|
|
if (!sops)
|
|
|
|
return -ENOMEM;
|
|
|
|
err = 0;
|
|
|
|
for (i = 0; i < nsops; i++) {
|
2018-07-09 17:20:06 +08:00
|
|
|
struct oabi_sembuf osb;
|
|
|
|
err |= __copy_from_user(&osb, tsops, sizeof(osb));
|
|
|
|
sops[i].sem_num = osb.sem_num;
|
|
|
|
sops[i].sem_op = osb.sem_op;
|
|
|
|
sops[i].sem_flg = osb.sem_flg;
|
2006-01-15 00:35:31 +08:00
|
|
|
tsops++;
|
|
|
|
}
|
|
|
|
if (timeout) {
|
|
|
|
/* copy this as well before changing domain protection */
|
|
|
|
err |= copy_from_user(&local_timeout, timeout, sizeof(*timeout));
|
|
|
|
timeout = &local_timeout;
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
err = -EFAULT;
|
|
|
|
} else {
|
|
|
|
mm_segment_t fs = get_fs();
|
|
|
|
set_fs(KERNEL_DS);
|
2019-01-01 08:13:32 +08:00
|
|
|
err = sys_semtimedop_time32(semid, sops, nsops, timeout);
|
2006-01-15 00:35:31 +08:00
|
|
|
set_fs(fs);
|
|
|
|
}
|
|
|
|
kfree(sops);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long sys_oabi_semop(int semid, struct oabi_sembuf __user *tsops,
|
|
|
|
unsigned nsops)
|
|
|
|
{
|
|
|
|
return sys_oabi_semtimedop(semid, tsops, nsops, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage int sys_oabi_ipc(uint call, int first, int second, int third,
|
|
|
|
void __user *ptr, long fifth)
|
|
|
|
{
|
|
|
|
switch (call & 0xffff) {
|
|
|
|
case SEMOP:
|
|
|
|
return sys_oabi_semtimedop(first,
|
|
|
|
(struct oabi_sembuf __user *)ptr,
|
|
|
|
second, NULL);
|
|
|
|
case SEMTIMEDOP:
|
|
|
|
return sys_oabi_semtimedop(first,
|
|
|
|
(struct oabi_sembuf __user *)ptr,
|
|
|
|
second,
|
2019-01-01 08:13:32 +08:00
|
|
|
(const struct old_timespec32 __user *)fifth);
|
2006-01-15 00:35:31 +08:00
|
|
|
default:
|
|
|
|
return sys_ipc(call, first, second, third, ptr, fifth);
|
|
|
|
}
|
|
|
|
}
|
2006-02-09 05:19:36 +08:00
|
|
|
|
|
|
|
asmlinkage long sys_oabi_bind(int fd, struct sockaddr __user *addr, int addrlen)
|
|
|
|
{
|
|
|
|
sa_family_t sa_family;
|
|
|
|
if (addrlen == 112 &&
|
|
|
|
get_user(sa_family, &addr->sa_family) == 0 &&
|
|
|
|
sa_family == AF_UNIX)
|
|
|
|
addrlen = 110;
|
|
|
|
return sys_bind(fd, addr, addrlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long sys_oabi_connect(int fd, struct sockaddr __user *addr, int addrlen)
|
|
|
|
{
|
|
|
|
sa_family_t sa_family;
|
|
|
|
if (addrlen == 112 &&
|
|
|
|
get_user(sa_family, &addr->sa_family) == 0 &&
|
|
|
|
sa_family == AF_UNIX)
|
|
|
|
addrlen = 110;
|
|
|
|
return sys_connect(fd, addr, addrlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long sys_oabi_sendto(int fd, void __user *buff,
|
|
|
|
size_t len, unsigned flags,
|
|
|
|
struct sockaddr __user *addr,
|
|
|
|
int addrlen)
|
|
|
|
{
|
|
|
|
sa_family_t sa_family;
|
|
|
|
if (addrlen == 112 &&
|
|
|
|
get_user(sa_family, &addr->sa_family) == 0 &&
|
|
|
|
sa_family == AF_UNIX)
|
|
|
|
addrlen = 110;
|
|
|
|
return sys_sendto(fd, buff, len, flags, addr, addrlen);
|
|
|
|
}
|
|
|
|
|
separate kernel- and userland-side msghdr
Kernel-side struct msghdr is (currently) using the same layout as
userland one, but it's not a one-to-one copy - even without considering
32bit compat issues, we have msg_iov, msg_name and msg_control copied
to kernel[1]. It's fairly localized, so we get away with a few functions
where that knowledge is needed (and we could shrink that set even
more). Pretty much everything deals with the kernel-side variant and
the few places that want userland one just use a bunch of force-casts
to paper over the differences.
The thing is, kernel-side definition of struct msghdr is *not* exposed
in include/uapi - libc doesn't see it, etc. So we can add struct user_msghdr,
with proper annotations and let the few places that ever deal with those
beasts use it for userland pointers. Saner typechecking aside, that will
allow to change the layout of kernel-side msghdr - e.g. replace
msg_iov/msg_iovlen there with struct iov_iter, getting rid of the need
to modify the iovec as we copy data to/from it, etc.
We could introduce kernel_msghdr instead, but that would create much more
noise - the absolute majority of the instances would need to have the
type switched to kernel_msghdr and definition of struct msghdr in
include/linux/socket.h is not going to be seen by userland anyway.
This commit just introduces user_msghdr and switches the few places that
are dealing with userland-side msghdr to it.
[1] actually, it's even trickier than that - we copy msg_control for
sendmsg, but keep the userland address on recvmsg.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2014-04-07 02:03:05 +08:00
|
|
|
asmlinkage long sys_oabi_sendmsg(int fd, struct user_msghdr __user *msg, unsigned flags)
|
2006-02-09 05:19:36 +08:00
|
|
|
{
|
|
|
|
struct sockaddr __user *addr;
|
|
|
|
int msg_namelen;
|
|
|
|
sa_family_t sa_family;
|
|
|
|
if (msg &&
|
|
|
|
get_user(msg_namelen, &msg->msg_namelen) == 0 &&
|
|
|
|
msg_namelen == 112 &&
|
|
|
|
get_user(addr, &msg->msg_name) == 0 &&
|
|
|
|
get_user(sa_family, &addr->sa_family) == 0 &&
|
|
|
|
sa_family == AF_UNIX)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* HACK ALERT: there is a limit to how much backward bending
|
|
|
|
* we should do for what is actually a transitional
|
|
|
|
* compatibility layer. This already has known flaws with
|
|
|
|
* a few ioctls that we don't intend to fix. Therefore
|
|
|
|
* consider this blatent hack as another one... and take care
|
|
|
|
* to run for cover. In most cases it will "just work fine".
|
|
|
|
* If it doesn't, well, tough.
|
|
|
|
*/
|
|
|
|
put_user(110, &msg->msg_namelen);
|
|
|
|
}
|
|
|
|
return sys_sendmsg(fd, msg, flags);
|
|
|
|
}
|
|
|
|
|
2006-02-17 06:36:13 +08:00
|
|
|
asmlinkage long sys_oabi_socketcall(int call, unsigned long __user *args)
|
|
|
|
{
|
|
|
|
unsigned long r = -EFAULT, a[6];
|
|
|
|
|
|
|
|
switch (call) {
|
|
|
|
case SYS_BIND:
|
|
|
|
if (copy_from_user(a, args, 3 * sizeof(long)) == 0)
|
|
|
|
r = sys_oabi_bind(a[0], (struct sockaddr __user *)a[1], a[2]);
|
|
|
|
break;
|
|
|
|
case SYS_CONNECT:
|
|
|
|
if (copy_from_user(a, args, 3 * sizeof(long)) == 0)
|
|
|
|
r = sys_oabi_connect(a[0], (struct sockaddr __user *)a[1], a[2]);
|
|
|
|
break;
|
|
|
|
case SYS_SENDTO:
|
|
|
|
if (copy_from_user(a, args, 6 * sizeof(long)) == 0)
|
|
|
|
r = sys_oabi_sendto(a[0], (void __user *)a[1], a[2], a[3],
|
|
|
|
(struct sockaddr __user *)a[4], a[5]);
|
|
|
|
break;
|
|
|
|
case SYS_SENDMSG:
|
|
|
|
if (copy_from_user(a, args, 3 * sizeof(long)) == 0)
|
separate kernel- and userland-side msghdr
Kernel-side struct msghdr is (currently) using the same layout as
userland one, but it's not a one-to-one copy - even without considering
32bit compat issues, we have msg_iov, msg_name and msg_control copied
to kernel[1]. It's fairly localized, so we get away with a few functions
where that knowledge is needed (and we could shrink that set even
more). Pretty much everything deals with the kernel-side variant and
the few places that want userland one just use a bunch of force-casts
to paper over the differences.
The thing is, kernel-side definition of struct msghdr is *not* exposed
in include/uapi - libc doesn't see it, etc. So we can add struct user_msghdr,
with proper annotations and let the few places that ever deal with those
beasts use it for userland pointers. Saner typechecking aside, that will
allow to change the layout of kernel-side msghdr - e.g. replace
msg_iov/msg_iovlen there with struct iov_iter, getting rid of the need
to modify the iovec as we copy data to/from it, etc.
We could introduce kernel_msghdr instead, but that would create much more
noise - the absolute majority of the instances would need to have the
type switched to kernel_msghdr and definition of struct msghdr in
include/linux/socket.h is not going to be seen by userland anyway.
This commit just introduces user_msghdr and switches the few places that
are dealing with userland-side msghdr to it.
[1] actually, it's even trickier than that - we copy msg_control for
sendmsg, but keep the userland address on recvmsg.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2014-04-07 02:03:05 +08:00
|
|
|
r = sys_oabi_sendmsg(a[0], (struct user_msghdr __user *)a[1], a[2]);
|
2006-02-17 06:36:13 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r = sys_socketcall(call, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|