Skip to content

Commit 8865c41

Browse files
David Woodhousedavem330
authored andcommitted
atm: 32-bit ioctl compatibility
We lack compat ioctl support through most of the ATM code. This patch deals with most of it, and I can now at least use BR2684 and PPPoATM with 32-bit userspace. I haven't added a .compat_ioctl method to struct atm_ioctl, because AFAICT none of the current users need any conversion -- so we can just call the ->ioctl() method in every case. I looked at br2684, clip, lec, mpc, pppoatm and atmtcp. In svc_compat_ioctl() the only mangling which is needed is to change COMPAT_ATM_ADDPARTY to ATM_ADDPARTY. Although it's defined as _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf) it doesn't actually _take_ a struct atm_iobuf as an argument -- it takes a struct sockaddr_atmsvc, which _is_ the same between 32-bit and 64-bit code, so doesn't need conversion. Almost all of vcc_ioctl() would have been identical, so I converted that into a core do_vcc_ioctl() function with an 'int compat' argument. I've done the same with atm_dev_ioctl(), where there _are_ a few differences, but still it's relatively contained and there would otherwise have been a lot of duplication. I haven't done any of the actual device-specific ioctls, although I've added a compat_ioctl method to struct atmdev_ops. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dcd39c9 commit 8865c41

8 files changed

Lines changed: 164 additions & 30 deletions

File tree

‎include/linux/atm.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,21 @@ static __inline__ int atmpvc_addr_in_use(struct sockaddr_atmpvc addr)
231231
*/
232232

233233
struct atmif_sioc {
234-
int number;
235-
int length;
236-
void __user *arg;
234+
int number;
235+
int length;
236+
void __user *arg;
237237
};
238238

239+
#ifdef __KERNEL__
240+
#ifdef CONFIG_COMPAT
241+
#include <linux/compat.h>
242+
struct compat_atmif_sioc {
243+
int number;
244+
int length;
245+
compat_uptr_t arg;
246+
};
247+
#endif
248+
#endif
249+
239250
typedef unsigned short atm_backend_t;
240251
#endif

‎include/linux/atmdev.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ struct atm_dev_stats {
100100
/* use backend to make new if */
101101
#define ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
102102
/* add party to p2mp call */
103+
#ifdef CONFIG_COMPAT
104+
/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
105+
#define COMPAT_ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4,struct compat_atm_iobuf)
106+
#endif
103107
#define ATM_DROPPARTY _IOW('a', ATMIOC_SPECIAL+5,int)
104108
/* drop party from p2mp call */
105109

@@ -224,6 +228,13 @@ struct atm_cirange {
224228
extern struct proc_dir_entry *atm_proc_root;
225229
#endif
226230

231+
#ifdef CONFIG_COMPAT
232+
#include <linux/compat.h>
233+
struct compat_atm_iobuf {
234+
int length;
235+
compat_uptr_t buffer;
236+
};
237+
#endif
227238

228239
struct k_atm_aal_stats {
229240
#define __HANDLE_ITEM(i) atomic_t i
@@ -379,6 +390,10 @@ struct atmdev_ops { /* only send is required */
379390
int (*open)(struct atm_vcc *vcc);
380391
void (*close)(struct atm_vcc *vcc);
381392
int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
393+
#ifdef CONFIG_COMPAT
394+
int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
395+
void __user *arg);
396+
#endif
382397
int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
383398
void __user *optval,int optlen);
384399
int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,

‎net/atm/common.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
1919
size_t total_len);
2020
unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait);
2121
int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
22+
int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
2223
int vcc_setsockopt(struct socket *sock, int level, int optname,
2324
char __user *optval, int optlen);
2425
int vcc_getsockopt(struct socket *sock, int level, int optname,

‎net/atm/ioctl.c‎

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/atmlec.h>
2020
#include <linux/mutex.h>
2121
#include <asm/ioctls.h>
22+
#include <net/compat.h>
2223

2324
#include "resources.h"
2425
#include "signaling.h" /* for WAITING and sigd_attach */
@@ -46,7 +47,7 @@ void deregister_atm_ioctl(struct atm_ioctl *ioctl)
4647
EXPORT_SYMBOL(register_atm_ioctl);
4748
EXPORT_SYMBOL(deregister_atm_ioctl);
4849

49-
int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
50+
static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg, int compat)
5051
{
5152
struct sock *sk = sock->sk;
5253
struct atm_vcc *vcc;
@@ -80,13 +81,25 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
8081
goto done;
8182
}
8283
case SIOCGSTAMP: /* borrowed from IP */
83-
error = sock_get_timestamp(sk, argp);
84+
#ifdef CONFIG_COMPAT
85+
if (compat)
86+
error = compat_sock_get_timestamp(sk, argp);
87+
else
88+
#endif
89+
error = sock_get_timestamp(sk, argp);
8490
goto done;
8591
case SIOCGSTAMPNS: /* borrowed from IP */
86-
error = sock_get_timestampns(sk, argp);
92+
#ifdef CONFIG_COMPAT
93+
if (compat)
94+
error = compat_sock_get_timestampns(sk, argp);
95+
else
96+
#endif
97+
error = sock_get_timestampns(sk, argp);
8798
goto done;
8899
case ATM_SETSC:
89-
printk(KERN_WARNING "ATM_SETSC is obsolete\n");
100+
if (net_ratelimit())
101+
printk(KERN_WARNING "ATM_SETSC is obsolete; used by %s:%d\n",
102+
current->comm, task_pid_nr(current));
90103
error = 0;
91104
goto done;
92105
case ATMSIGD_CTRL:
@@ -99,12 +112,23 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
99112
* info uses kernel pointers as opaque references,
100113
* so the holder of the file descriptor can scribble
101114
* on the kernel... so we should make sure that we
102-
* have the same privledges that /proc/kcore needs
115+
* have the same privileges that /proc/kcore needs
103116
*/
104117
if (!capable(CAP_SYS_RAWIO)) {
105118
error = -EPERM;
106119
goto done;
107120
}
121+
#ifdef CONFIG_COMPAT
122+
/* WTF? I don't even want to _think_ about making this
123+
work for 32-bit userspace. TBH I don't really want
124+
to think about it at all. dwmw2. */
125+
if (compat) {
126+
if (net_ratelimit())
127+
printk(KERN_WARNING "32-bit task cannot be atmsigd\n");
128+
error = -EINVAL;
129+
goto done;
130+
}
131+
#endif
108132
error = sigd_attach(vcc);
109133
if (!error)
110134
sock->state = SS_CONNECTED;
@@ -155,8 +179,21 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
155179
if (error != -ENOIOCTLCMD)
156180
goto done;
157181

158-
error = atm_dev_ioctl(cmd, argp);
182+
error = atm_dev_ioctl(cmd, argp, compat);
159183

160184
done:
161185
return error;
162186
}
187+
188+
189+
int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
190+
{
191+
return do_vcc_ioctl(sock, cmd, arg, 0);
192+
}
193+
194+
#ifdef CONFIG_COMPAT
195+
int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
196+
{
197+
return do_vcc_ioctl(sock, cmd, arg, 1);
198+
}
199+
#endif

‎net/atm/pvc.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ static const struct proto_ops pvc_proto_ops = {
113113
.getname = pvc_getname,
114114
.poll = vcc_poll,
115115
.ioctl = vcc_ioctl,
116+
#ifdef CONFIG_COMPAT
117+
.compat_ioctl = vcc_compat_ioctl,
118+
#endif
116119
.listen = sock_no_listen,
117120
.shutdown = pvc_shutdown,
118121
.setsockopt = pvc_setsockopt,

‎net/atm/resources.c‎

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,39 @@ static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg, in
195195
}
196196

197197

198-
int atm_dev_ioctl(unsigned int cmd, void __user *arg)
198+
int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
199199
{
200200
void __user *buf;
201201
int error, len, number, size = 0;
202202
struct atm_dev *dev;
203203
struct list_head *p;
204204
int *tmp_buf, *tmp_p;
205-
struct atm_iobuf __user *iobuf = arg;
206-
struct atmif_sioc __user *sioc = arg;
205+
int __user *sioc_len;
206+
int __user *iobuf_len;
207+
208+
#ifndef CONFIG_COMPAT
209+
compat = 0; /* Just so the compiler _knows_ */
210+
#endif
211+
207212
switch (cmd) {
208213
case ATM_GETNAMES:
209-
if (get_user(buf, &iobuf->buffer))
210-
return -EFAULT;
211-
if (get_user(len, &iobuf->length))
214+
215+
if (compat) {
216+
#ifdef CONFIG_COMPAT
217+
struct compat_atm_iobuf __user *ciobuf = arg;
218+
compat_uptr_t cbuf;
219+
iobuf_len = &ciobuf->length;
220+
if (get_user(cbuf, &ciobuf->buffer))
221+
return -EFAULT;
222+
buf = compat_ptr(cbuf);
223+
#endif
224+
} else {
225+
struct atm_iobuf __user *iobuf = arg;
226+
iobuf_len = &iobuf->length;
227+
if (get_user(buf, &iobuf->buffer))
228+
return -EFAULT;
229+
}
230+
if (get_user(len, iobuf_len))
212231
return -EFAULT;
213232
mutex_lock(&atm_dev_mutex);
214233
list_for_each(p, &atm_devs)
@@ -229,21 +248,40 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
229248
}
230249
mutex_unlock(&atm_dev_mutex);
231250
error = ((copy_to_user(buf, tmp_buf, size)) ||
232-
put_user(size, &iobuf->length))
251+
put_user(size, iobuf_len))
233252
? -EFAULT : 0;
234253
kfree(tmp_buf);
235254
return error;
236255
default:
237256
break;
238257
}
239258

240-
if (get_user(buf, &sioc->arg))
241-
return -EFAULT;
242-
if (get_user(len, &sioc->length))
243-
return -EFAULT;
244-
if (get_user(number, &sioc->number))
245-
return -EFAULT;
246-
259+
if (compat) {
260+
#ifdef CONFIG_COMPAT
261+
struct compat_atmif_sioc __user *csioc = arg;
262+
compat_uptr_t carg;
263+
264+
sioc_len = &csioc->length;
265+
if (get_user(carg, &csioc->arg))
266+
return -EFAULT;
267+
buf = compat_ptr(carg);
268+
269+
if (get_user(len, &csioc->length))
270+
return -EFAULT;
271+
if (get_user(number, &csioc->number))
272+
return -EFAULT;
273+
#endif
274+
} else {
275+
struct atmif_sioc __user *sioc = arg;
276+
277+
sioc_len = &sioc->length;
278+
if (get_user(buf, &sioc->arg))
279+
return -EFAULT;
280+
if (get_user(len, &sioc->length))
281+
return -EFAULT;
282+
if (get_user(number, &sioc->number))
283+
return -EFAULT;
284+
}
247285
if (!(dev = try_then_request_module(atm_dev_lookup(number),
248286
"atm-device-%d", number)))
249287
return -ENODEV;
@@ -358,7 +396,7 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
358396
size = error;
359397
/* may return 0, but later on size == 0 means "don't
360398
write the length" */
361-
error = put_user(size, &sioc->length)
399+
error = put_user(size, sioc_len)
362400
? -EFAULT : 0;
363401
goto done;
364402
case ATM_SETLOOP:
@@ -380,19 +418,29 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
380418
}
381419
/* fall through */
382420
default:
383-
if (!dev->ops->ioctl) {
384-
error = -EINVAL;
385-
goto done;
421+
if (compat) {
422+
#ifdef CONFIG_COMPAT
423+
if (!dev->ops->compat_ioctl) {
424+
error = -EINVAL;
425+
goto done;
426+
}
427+
size = dev->ops->compat_ioctl(dev, cmd, buf);
428+
#endif
429+
} else {
430+
if (!dev->ops->ioctl) {
431+
error = -EINVAL;
432+
goto done;
433+
}
434+
size = dev->ops->ioctl(dev, cmd, buf);
386435
}
387-
size = dev->ops->ioctl(dev, cmd, buf);
388436
if (size < 0) {
389437
error = (size == -ENOIOCTLCMD ? -EINVAL : size);
390438
goto done;
391439
}
392440
}
393441

394442
if (size)
395-
error = put_user(size, &sioc->length)
443+
error = put_user(size, sioc_len)
396444
? -EFAULT : 0;
397445
else
398446
error = 0;

‎net/atm/resources.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
extern struct list_head atm_devs;
1414
extern struct mutex atm_dev_mutex;
1515

16-
int atm_dev_ioctl(unsigned int cmd, void __user *arg);
16+
int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat);
1717

1818

1919
#ifdef CONFIG_PROC_FS

‎net/atm/svc.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,22 @@ static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
604604
return error;
605605
}
606606

607+
#ifdef CONFIG_COMPAT
608+
static int svc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
609+
{
610+
/* The definition of ATM_ADDPARTY uses the size of struct atm_iobuf.
611+
But actually it takes a struct sockaddr_atmsvc, which doesn't need
612+
compat handling. So all we have to do is fix up cmd... */
613+
if (cmd == COMPAT_ATM_ADDPARTY)
614+
cmd = ATM_ADDPARTY;
615+
616+
if (cmd == ATM_ADDPARTY || cmd == ATM_DROPPARTY)
617+
return svc_ioctl(sock, cmd, arg);
618+
else
619+
return vcc_compat_ioctl(sock, cmd, arg);
620+
}
621+
#endif /* CONFIG_COMPAT */
622+
607623
static const struct proto_ops svc_proto_ops = {
608624
.family = PF_ATMSVC,
609625
.owner = THIS_MODULE,
@@ -616,6 +632,9 @@ static const struct proto_ops svc_proto_ops = {
616632
.getname = svc_getname,
617633
.poll = vcc_poll,
618634
.ioctl = svc_ioctl,
635+
#ifdef CONFIG_COMPAT
636+
.compat_ioctl = svc_compat_ioctl,
637+
#endif
619638
.listen = svc_listen,
620639
.shutdown = svc_shutdown,
621640
.setsockopt = svc_setsockopt,

0 commit comments

Comments
 (0)