Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit e18503f

Browse files
fcachereuldavem330
authored andcommitted
l2tp: fix kernel panic when using IPv4-mapped IPv6 addresses
IPv4 mapped addresses cause kernel panic. The patch juste check whether the IPv6 address is an IPv4 mapped address. If so, use IPv4 API instead of IPv6. [ 940.026915] general protection fault: 0000 [#1] [ 940.026915] Modules linked in: l2tp_ppp l2tp_netlink l2tp_core pppox ppp_generic slhc loop psmouse [ 940.026915] CPU: 0 PID: 3184 Comm: memcheck-amd64- Not tainted 3.11.0+ #1 [ 940.026915] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007 [ 940.026915] task: ffff880007130e20 ti: ffff88000737e000 task.ti: ffff88000737e000 [ 940.026915] RIP: 0010:[<ffffffff81333780>] [<ffffffff81333780>] ip6_xmit+0x276/0x326 [ 940.026915] RSP: 0018:ffff88000737fd28 EFLAGS: 00010286 [ 940.026915] RAX: c748521a75ceff48 RBX: ffff880000c30800 RCX: 0000000000000000 [ 940.026915] RDX: ffff88000075cc4e RSI: 0000000000000028 RDI: ffff8800060e5a40 [ 940.026915] RBP: ffff8800060e5a40 R08: 0000000000000000 R09: ffff88000075cc90 [ 940.026915] R10: 0000000000000000 R11: 0000000000000000 R12: ffff88000737fda0 [ 940.026915] R13: 0000000000000000 R14: 0000000000002000 R15: ffff880005d3b580 [ 940.026915] FS: 00007f163dc5e800(0000) GS:ffffffff81623000(0000) knlGS:0000000000000000 [ 940.026915] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 940.026915] CR2: 00000004032dc940 CR3: 0000000005c25000 CR4: 00000000000006f0 [ 940.026915] Stack: [ 940.026915] ffff88000075cc4e ffffffff81694e90 ffff880000c30b38 0000000000000020 [ 940.026915] 11000000523c4bac ffff88000737fdb4 0000000000000000 ffff880000c30800 [ 940.026915] ffff880005d3b580 ffff880000c30b38 ffff8800060e5a40 0000000000000020 [ 940.026915] Call Trace: [ 940.026915] [<ffffffff81356cc3>] ? inet6_csk_xmit+0xa4/0xc4 [ 940.026915] [<ffffffffa0038535>] ? l2tp_xmit_skb+0x503/0x55a [l2tp_core] [ 940.026915] [<ffffffff812b8d3b>] ? pskb_expand_head+0x161/0x214 [ 940.026915] [<ffffffffa003e91d>] ? pppol2tp_xmit+0xf2/0x143 [l2tp_ppp] [ 940.026915] [<ffffffffa00292e0>] ? ppp_channel_push+0x36/0x8b [ppp_generic] [ 940.026915] [<ffffffffa00293fe>] ? ppp_write+0xaf/0xc5 [ppp_generic] [ 940.026915] [<ffffffff8110ead4>] ? vfs_write+0xa2/0x106 [ 940.026915] [<ffffffff8110edd6>] ? SyS_write+0x56/0x8a [ 940.026915] [<ffffffff81378ac0>] ? system_call_fastpath+0x16/0x1b [ 940.026915] Code: 00 49 8b 8f d8 00 00 00 66 83 7c 11 02 00 74 60 49 8b 47 58 48 83 e0 fe 48 8b 80 18 01 00 00 48 85 c0 74 13 48 8b 80 78 02 00 00 <48> ff 40 28 41 8b 57 68 48 01 50 30 48 8b 54 24 08 49 c7 c1 51 [ 940.026915] RIP [<ffffffff81333780>] ip6_xmit+0x276/0x326 [ 940.026915] RSP <ffff88000737fd28> [ 940.057945] ---[ end trace be8aba9a61c8b7f3 ]--- [ 940.058583] Kernel panic - not syncing: Fatal exception in interrupt Signed-off-by: François CACHEREUL <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 80ad1d6 commit e18503f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

net/l2tp/l2tp_core.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ static void l2tp_recv_dequeue(struct l2tp_session *session)
496496
static inline int l2tp_verify_udp_checksum(struct sock *sk,
497497
struct sk_buff *skb)
498498
{
499+
struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
499500
struct udphdr *uh = udp_hdr(skb);
500501
u16 ulen = ntohs(uh->len);
501502
__wsum psum;
@@ -504,7 +505,7 @@ static inline int l2tp_verify_udp_checksum(struct sock *sk,
504505
return 0;
505506

506507
#if IS_ENABLED(CONFIG_IPV6)
507-
if (sk->sk_family == PF_INET6) {
508+
if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) {
508509
if (!uh->check) {
509510
LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n");
510511
return 1;
@@ -1128,7 +1129,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
11281129
/* Queue the packet to IP for output */
11291130
skb->local_df = 1;
11301131
#if IS_ENABLED(CONFIG_IPV6)
1131-
if (skb->sk->sk_family == PF_INET6)
1132+
if (skb->sk->sk_family == PF_INET6 && !tunnel->v4mapped)
11321133
error = inet6_csk_xmit(skb, NULL);
11331134
else
11341135
#endif
@@ -1255,7 +1256,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
12551256

12561257
/* Calculate UDP checksum if configured to do so */
12571258
#if IS_ENABLED(CONFIG_IPV6)
1258-
if (sk->sk_family == PF_INET6)
1259+
if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
12591260
l2tp_xmit_ipv6_csum(sk, skb, udp_len);
12601261
else
12611262
#endif
@@ -1704,6 +1705,24 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
17041705
if (cfg != NULL)
17051706
tunnel->debug = cfg->debug;
17061707

1708+
#if IS_ENABLED(CONFIG_IPV6)
1709+
if (sk->sk_family == PF_INET6) {
1710+
struct ipv6_pinfo *np = inet6_sk(sk);
1711+
1712+
if (ipv6_addr_v4mapped(&np->saddr) &&
1713+
ipv6_addr_v4mapped(&np->daddr)) {
1714+
struct inet_sock *inet = inet_sk(sk);
1715+
1716+
tunnel->v4mapped = true;
1717+
inet->inet_saddr = np->saddr.s6_addr32[3];
1718+
inet->inet_rcv_saddr = np->rcv_saddr.s6_addr32[3];
1719+
inet->inet_daddr = np->daddr.s6_addr32[3];
1720+
} else {
1721+
tunnel->v4mapped = false;
1722+
}
1723+
}
1724+
#endif
1725+
17071726
/* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
17081727
tunnel->encap = encap;
17091728
if (encap == L2TP_ENCAPTYPE_UDP) {
@@ -1712,7 +1731,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
17121731
udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
17131732
udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
17141733
#if IS_ENABLED(CONFIG_IPV6)
1715-
if (sk->sk_family == PF_INET6)
1734+
if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
17161735
udpv6_encap_enable();
17171736
else
17181737
#endif

net/l2tp/l2tp_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ struct l2tp_tunnel {
194194
struct sock *sock; /* Parent socket */
195195
int fd; /* Parent fd, if tunnel socket
196196
* was created by userspace */
197+
#if IS_ENABLED(CONFIG_IPV6)
198+
bool v4mapped;
199+
#endif
197200

198201
struct work_struct del_work;
199202

0 commit comments

Comments
 (0)