Commit 18813ce3 authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] Fix ioctl32 wrapper (for SPARC)

IOCTL32 emulation
Fix ioctl32 wrapper design, using compat_alloc_user_space() now.
This will fix the crash on SPARC64.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 1efef61e
...@@ -36,24 +36,24 @@ struct sndrv_hwdep_dsp_image32 { ...@@ -36,24 +36,24 @@ struct sndrv_hwdep_dsp_image32 {
static inline int _snd_ioctl32_hwdep_dsp_image(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl) static inline int _snd_ioctl32_hwdep_dsp_image(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)
{ {
struct sndrv_hwdep_dsp_image data; struct sndrv_hwdep_dsp_image __user *data, *dst;
struct sndrv_hwdep_dsp_image32 data32; struct sndrv_hwdep_dsp_image32 __user *data32, *src;
mm_segment_t oldseg; compat_caddr_t ptr;
int err;
if (copy_from_user(&data32, (void __user *)arg, sizeof(data32))) data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
/* index and name */
if (copy_in_user(data, data32, 4 + 64))
return -EFAULT;
if (__get_user(ptr, &data32->image) ||
__put_user(compat_ptr(ptr), &data->image))
return -EFAULT; return -EFAULT;
memset(&data, 0, sizeof(data)); src = data32;
data.index = data32.index; dst = data;
memcpy(data.name, data32.name, sizeof(data.name)); COPY_CVT(length);
data.image = compat_ptr(data32.image); COPY_CVT(driver_data);
data.length = data32.length; return file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)data);
data.driver_data = data32.driver_data;
oldseg = get_fs();
set_fs(KERNEL_DS);
err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)&data);
set_fs(oldseg);
return err;
} }
DEFINE_ALSA_IOCTL_ENTRY(hwdep_dsp_image, hwdep_dsp_image, SNDRV_HWDEP_IOCTL_DSP_LOAD); DEFINE_ALSA_IOCTL_ENTRY(hwdep_dsp_image, hwdep_dsp_image, SNDRV_HWDEP_IOCTL_DSP_LOAD);
......
This diff is collapsed.
...@@ -28,20 +28,37 @@ ...@@ -28,20 +28,37 @@
#include <linux/compat.h> #include <linux/compat.h>
#define COPY(x) (dst->x = src->x) #define COPY(x) \
#define CPTR(x) (dst->x = compat_ptr(src->x)) do { \
if (copy_in_user(&dst->x, &src->x, sizeof(dst->x))) \
return -EFAULT; \
} while (0)
#define COPY_ARRAY(x) \
do { \
if (copy_in_user(dst->x, src->x, sizeof(dst->x))) \
return -EFAULT; \
} while (0)
#define COPY_CVT(x) \
do { \
__typeof__(src->x) __val_tmp; \
if (get_user(__val_tmp, &src->x) || \
put_user(__val_tmp, &dst->x))\
return -EFAULT; \
} while (0)
#define convert_from_32(type, dstp, srcp)\ #define convert_from_32(type, dstp, srcp)\
{\ {\
struct sndrv_##type *dst = dstp;\ struct sndrv_##type __user *dst = dstp;\
struct sndrv_##type##32 *src = srcp;\ struct sndrv_##type##32 __user *src = srcp;\
CVT_##sndrv_##type();\ CVT_##sndrv_##type();\
} }
#define convert_to_32(type, dstp, srcp)\ #define convert_to_32(type, dstp, srcp)\
{\ {\
struct sndrv_##type *src = srcp;\ struct sndrv_##type __user *src = srcp;\
struct sndrv_##type##32 *dst = dstp;\ struct sndrv_##type##32 __user *dst = dstp;\
CVT_##sndrv_##type();\ CVT_##sndrv_##type();\
} }
...@@ -49,65 +66,19 @@ ...@@ -49,65 +66,19 @@
#define DEFINE_ALSA_IOCTL(type) \ #define DEFINE_ALSA_IOCTL(type) \
static inline int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)\ static inline int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)\
{\ {\
struct sndrv_##type##32 data32;\ struct sndrv_##type##32 __user *data32;\
struct sndrv_##type data;\ struct sndrv_##type __user *data;\
mm_segment_t oldseg;\
int err;\
if (copy_from_user(&data32, (void __user *)arg, sizeof(data32)))\
return -EFAULT;\
memset(&data, 0, sizeof(data));\
convert_from_32(type, &data, &data32);\
oldseg = get_fs();\
set_fs(KERNEL_DS);\
err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)&data);\
set_fs(oldseg);\
if (err < 0) \
return err;\
if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
convert_to_32(type, &data32, &data);\
if (copy_to_user((void __user *)arg, &data32, sizeof(data32)))\
return -EFAULT;\
}\
return 0;\
}
#define DEFINE_ALSA_IOCTL_BIG(type) \
static inline int _snd_ioctl32_##type(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file, unsigned int native_ctl)\
{\
struct sndrv_##type##32 *data32;\
struct sndrv_##type *data;\
mm_segment_t oldseg;\
int err;\ int err;\
data32 = kmalloc(sizeof(*data32), GFP_KERNEL); \ data32 = compat_ptr(arg);\
data = kmalloc(sizeof(*data), GFP_KERNEL); \ data = compat_alloc_user_space(sizeof(*data));\
if (data32 == NULL || data == NULL) { \
err = -ENOMEM; \
goto __end; \
}\
if (copy_from_user(data32, (void __user *)arg, sizeof(*data32))) { \
err = -EFAULT; \
goto __end; \
}\
memset(data, 0, sizeof(*data));\
convert_from_32(type, data, data32);\ convert_from_32(type, data, data32);\
oldseg = get_fs();\
set_fs(KERNEL_DS);\
err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)data);\ err = file->f_op->ioctl(file->f_dentry->d_inode, file, native_ctl, (unsigned long)data);\
set_fs(oldseg);\
if (err < 0) \ if (err < 0) \
goto __end;\ return err;\
err = 0;\
if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\ if (native_ctl & (_IOC_READ << _IOC_DIRSHIFT)) {\
convert_to_32(type, data32, data);\ convert_to_32(type, data32, data);\
if (copy_to_user((void __user *)arg, data32, sizeof(*data32)))\
err = -EFAULT;\
}\ }\
__end:\ return 0;\
if (data)\
kfree(data);\
if (data32)\
kfree(data32);\
return err;\
} }
#define DEFINE_ALSA_IOCTL_ENTRY(name,type,native_ctl) \ #define DEFINE_ALSA_IOCTL_ENTRY(name,type,native_ctl) \
......
This diff is collapsed.
...@@ -38,9 +38,11 @@ struct sndrv_rawmidi_params32 { ...@@ -38,9 +38,11 @@ struct sndrv_rawmidi_params32 {
#define CVT_sndrv_rawmidi_params()\ #define CVT_sndrv_rawmidi_params()\
{\ {\
COPY(stream);\ COPY(stream);\
COPY(buffer_size);\ COPY_CVT(buffer_size);\
COPY(avail_min);\ COPY_CVT(avail_min);\
COPY(no_active_sensing);\ if (copy_in_user(((size_t __user *)&dst->avail_min + 1),\
((size_t __user *)&src->avail_min + 1), 4)) \
return -EFAULT;\
} }
struct sndrv_rawmidi_status32 { struct sndrv_rawmidi_status32 {
...@@ -54,10 +56,10 @@ struct sndrv_rawmidi_status32 { ...@@ -54,10 +56,10 @@ struct sndrv_rawmidi_status32 {
#define CVT_sndrv_rawmidi_status()\ #define CVT_sndrv_rawmidi_status()\
{\ {\
COPY(stream);\ COPY(stream);\
COPY(tstamp.tv_sec);\ COPY_CVT(tstamp.tv_sec);\
COPY(tstamp.tv_nsec);\ COPY_CVT(tstamp.tv_nsec);\
COPY(avail);\ COPY_CVT(avail);\
COPY(xruns);\ COPY_CVT(xruns);\
} }
DEFINE_ALSA_IOCTL(rawmidi_params); DEFINE_ALSA_IOCTL(rawmidi_params);
......
...@@ -42,13 +42,14 @@ struct sndrv_seq_port_info32 { ...@@ -42,13 +42,14 @@ struct sndrv_seq_port_info32 {
u32 kernel; /* reserved for kernel use (must be NULL) */ u32 kernel; /* reserved for kernel use (must be NULL) */
u32 flags; /* misc. conditioning */ u32 flags; /* misc. conditioning */
char reserved[60]; /* for future use */ unsigned char time_queue; /* queue # for timestamping */
char reserved[59]; /* for future use */
}; };
#define CVT_sndrv_seq_port_info()\ #define CVT_sndrv_seq_port_info()\
{\ {\
COPY(addr);\ COPY(addr);\
memcpy(dst->name, src->name, sizeof(dst->name));\ COPY_ARRAY(name);\
COPY(capability);\ COPY(capability);\
COPY(type);\ COPY(type);\
COPY(midi_channels);\ COPY(midi_channels);\
...@@ -57,6 +58,7 @@ struct sndrv_seq_port_info32 { ...@@ -57,6 +58,7 @@ struct sndrv_seq_port_info32 {
COPY(read_use);\ COPY(read_use);\
COPY(write_use);\ COPY(write_use);\
COPY(flags);\ COPY(flags);\
COPY(time_queue);\
} }
DEFINE_ALSA_IOCTL(seq_port_info); DEFINE_ALSA_IOCTL(seq_port_info);
......
...@@ -41,9 +41,9 @@ struct sndrv_timer_info32 { ...@@ -41,9 +41,9 @@ struct sndrv_timer_info32 {
{\ {\
COPY(flags);\ COPY(flags);\
COPY(card);\ COPY(card);\
memcpy(dst->id, src->id, sizeof(src->id));\ COPY_ARRAY(id);\
memcpy(dst->name, src->name, sizeof(src->name));\ COPY_ARRAY(name);\
COPY(resolution);\ COPY_CVT(resolution);\
} }
struct sndrv_timer_status32 { struct sndrv_timer_status32 {
...@@ -57,8 +57,8 @@ struct sndrv_timer_status32 { ...@@ -57,8 +57,8 @@ struct sndrv_timer_status32 {
#define CVT_sndrv_timer_status()\ #define CVT_sndrv_timer_status()\
{\ {\
COPY(tstamp.tv_sec);\ COPY_CVT(tstamp.tv_sec);\
COPY(tstamp.tv_nsec);\ COPY_CVT(tstamp.tv_nsec);\
COPY(resolution);\ COPY(resolution);\
COPY(lost);\ COPY(lost);\
COPY(overrun);\ COPY(overrun);\
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment