Skip to content

Commit 89bbfc9

Browse files
Shaun Pereiradavem330
authored andcommitted
[NET]: allow 32 bit socket ioctl in 64 bit kernel
Since the register_ioctl32_conversion() patch in the kernel is now obsolete, provide another method to allow 32 bit user space ioctls to reach the kernel. Signed-off-by: Shaun Pereira <spereira@tusc.com.au> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 67b52e5 commit 89bbfc9

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎include/linux/net.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ struct proto_ops {
143143
struct poll_table_struct *wait);
144144
int (*ioctl) (struct socket *sock, unsigned int cmd,
145145
unsigned long arg);
146+
int (*compat_ioctl) (struct socket *sock, unsigned int cmd,
147+
unsigned long arg);
146148
int (*listen) (struct socket *sock, int len);
147149
int (*shutdown) (struct socket *sock, int flags);
148150
int (*setsockopt)(struct socket *sock, int level,
@@ -251,6 +253,8 @@ SOCKCALL_UWRAP(name, poll, (struct file *file, struct socket *sock, struct poll_
251253
(file, sock, wait)) \
252254
SOCKCALL_WRAP(name, ioctl, (struct socket *sock, unsigned int cmd, \
253255
unsigned long arg), (sock, cmd, arg)) \
256+
SOCKCALL_WRAP(name, compat_ioctl, (struct socket *sock, unsigned int cmd, \
257+
unsigned long arg), (sock, cmd, arg)) \
254258
SOCKCALL_WRAP(name, listen, (struct socket *sock, int len), (sock, len)) \
255259
SOCKCALL_WRAP(name, shutdown, (struct socket *sock, int flags), (sock, flags)) \
256260
SOCKCALL_WRAP(name, setsockopt, (struct socket *sock, int level, int optname, \
@@ -275,6 +279,7 @@ static const struct proto_ops name##_ops = { \
275279
.getname = __lock_##name##_getname, \
276280
.poll = __lock_##name##_poll, \
277281
.ioctl = __lock_##name##_ioctl, \
282+
.compat_ioctl = __lock_##name##_compat_ioctl, \
278283
.listen = __lock_##name##_listen, \
279284
.shutdown = __lock_##name##_shutdown, \
280285
.setsockopt = __lock_##name##_setsockopt, \
@@ -283,6 +288,7 @@ static const struct proto_ops name##_ops = { \
283288
.recvmsg = __lock_##name##_recvmsg, \
284289
.mmap = __lock_##name##_mmap, \
285290
};
291+
286292
#endif
287293

288294
#define MODULE_ALIAS_NETPROTO(proto) \

‎net/socket.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ static unsigned int sock_poll(struct file *file,
107107
struct poll_table_struct *wait);
108108
static long sock_ioctl(struct file *file,
109109
unsigned int cmd, unsigned long arg);
110+
#ifdef CONFIG_COMPAT
111+
static long compat_sock_ioctl(struct file *file,
112+
unsigned int cmd, unsigned long arg);
113+
#endif
110114
static int sock_fasync(int fd, struct file *filp, int on);
111115
static ssize_t sock_readv(struct file *file, const struct iovec *vector,
112116
unsigned long count, loff_t *ppos);
@@ -128,6 +132,9 @@ static struct file_operations socket_file_ops = {
128132
.aio_write = sock_aio_write,
129133
.poll = sock_poll,
130134
.unlocked_ioctl = sock_ioctl,
135+
#ifdef CONFIG_COMPAT
136+
.compat_ioctl = compat_sock_ioctl,
137+
#endif
131138
.mmap = sock_mmap,
132139
.open = sock_no_open, /* special open code to disallow open via /proc */
133140
.release = sock_close,
@@ -2136,6 +2143,20 @@ void socket_seq_show(struct seq_file *seq)
21362143
}
21372144
#endif /* CONFIG_PROC_FS */
21382145

2146+
#ifdef CONFIG_COMPAT
2147+
static long compat_sock_ioctl(struct file *file, unsigned cmd,
2148+
unsigned long arg)
2149+
{
2150+
struct socket *sock = file->private_data;
2151+
int ret = -ENOIOCTLCMD;
2152+
2153+
if (sock->ops->compat_ioctl)
2154+
ret = sock->ops->compat_ioctl(sock, cmd, arg);
2155+
2156+
return ret;
2157+
}
2158+
#endif
2159+
21392160
/* ABI emulation layers need these two */
21402161
EXPORT_SYMBOL(move_addr_to_kernel);
21412162
EXPORT_SYMBOL(move_addr_to_user);

0 commit comments

Comments
 (0)