Skip to content

Commit 72fb96e

Browse files
edumazetdavem330
authored andcommitted
l2tp: do not use udp_ioctl()
udp_ioctl(), as its name suggests, is used by UDP protocols, but is also used by L2TP :( L2TP should use its own handler, because it really does not look the same. SIOCINQ for instance should not assume UDP checksum or headers. Thanks to Andrey and syzkaller team for providing the report and a nice reproducer. While crashes only happen on recent kernels (after commit 7c13f97 ("udp: do fwd memory scheduling on dequeue")), this probably needs to be backported to older kernels. Fixes: 7c13f97 ("udp: do fwd memory scheduling on dequeue") Fixes: 8558467 ("udp: Fix udp_poll() and ioctl()") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Andrey Konovalov <[email protected]> Acked-by: Paolo Abeni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7447095 commit 72fb96e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

net/l2tp/l2tp_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb,
263263
int l2tp_nl_register_ops(enum l2tp_pwtype pw_type,
264264
const struct l2tp_nl_cmd_ops *ops);
265265
void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type);
266+
int l2tp_ioctl(struct sock *sk, int cmd, unsigned long arg);
266267

267268
/* Session reference counts. Incremented when code obtains a reference
268269
* to a session.

net/l2tp/l2tp_ip.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1313

14+
#include <asm/ioctls.h>
1415
#include <linux/icmp.h>
1516
#include <linux/module.h>
1617
#include <linux/skbuff.h>
@@ -553,6 +554,30 @@ static int l2tp_ip_recvmsg(struct sock *sk, struct msghdr *msg,
553554
return err ? err : copied;
554555
}
555556

557+
int l2tp_ioctl(struct sock *sk, int cmd, unsigned long arg)
558+
{
559+
struct sk_buff *skb;
560+
int amount;
561+
562+
switch (cmd) {
563+
case SIOCOUTQ:
564+
amount = sk_wmem_alloc_get(sk);
565+
break;
566+
case SIOCINQ:
567+
spin_lock_bh(&sk->sk_receive_queue.lock);
568+
skb = skb_peek(&sk->sk_receive_queue);
569+
amount = skb ? skb->len : 0;
570+
spin_unlock_bh(&sk->sk_receive_queue.lock);
571+
break;
572+
573+
default:
574+
return -ENOIOCTLCMD;
575+
}
576+
577+
return put_user(amount, (int __user *)arg);
578+
}
579+
EXPORT_SYMBOL(l2tp_ioctl);
580+
556581
static struct proto l2tp_ip_prot = {
557582
.name = "L2TP/IP",
558583
.owner = THIS_MODULE,
@@ -561,7 +586,7 @@ static struct proto l2tp_ip_prot = {
561586
.bind = l2tp_ip_bind,
562587
.connect = l2tp_ip_connect,
563588
.disconnect = l2tp_ip_disconnect,
564-
.ioctl = udp_ioctl,
589+
.ioctl = l2tp_ioctl,
565590
.destroy = l2tp_ip_destroy_sock,
566591
.setsockopt = ip_setsockopt,
567592
.getsockopt = ip_getsockopt,

net/l2tp/l2tp_ip6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static struct proto l2tp_ip6_prot = {
722722
.bind = l2tp_ip6_bind,
723723
.connect = l2tp_ip6_connect,
724724
.disconnect = l2tp_ip6_disconnect,
725-
.ioctl = udp_ioctl,
725+
.ioctl = l2tp_ioctl,
726726
.destroy = l2tp_ip6_destroy_sock,
727727
.setsockopt = ipv6_setsockopt,
728728
.getsockopt = ipv6_getsockopt,

0 commit comments

Comments
 (0)