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

Commit bd83cd7

Browse files
fcachereulgregkh
authored andcommitted
l2tp: fix kernel panic when using IPv4-mapped IPv6 addresses
[ Upstream commit e18503f ] 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 53d384a commit bd83cd7

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Diff for: net/l2tp/l2tp_core.c

+23-4
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ static void l2tp_recv_dequeue(struct l2tp_session *session)
499499
static inline int l2tp_verify_udp_checksum(struct sock *sk,
500500
struct sk_buff *skb)
501501
{
502+
struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
502503
struct udphdr *uh = udp_hdr(skb);
503504
u16 ulen = ntohs(uh->len);
504505
__wsum psum;
@@ -507,7 +508,7 @@ static inline int l2tp_verify_udp_checksum(struct sock *sk,
507508
return 0;
508509

509510
#if IS_ENABLED(CONFIG_IPV6)
510-
if (sk->sk_family == PF_INET6) {
511+
if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) {
511512
if (!uh->check) {
512513
LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n");
513514
return 1;
@@ -1071,7 +1072,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
10711072
/* Queue the packet to IP for output */
10721073
skb->local_df = 1;
10731074
#if IS_ENABLED(CONFIG_IPV6)
1074-
if (skb->sk->sk_family == PF_INET6)
1075+
if (skb->sk->sk_family == PF_INET6 && !tunnel->v4mapped)
10751076
error = inet6_csk_xmit(skb, NULL);
10761077
else
10771078
#endif
@@ -1198,7 +1199,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
11981199

11991200
/* Calculate UDP checksum if configured to do so */
12001201
#if IS_ENABLED(CONFIG_IPV6)
1201-
if (sk->sk_family == PF_INET6)
1202+
if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
12021203
l2tp_xmit_ipv6_csum(sk, skb, udp_len);
12031204
else
12041205
#endif
@@ -1647,6 +1648,24 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
16471648
if (cfg != NULL)
16481649
tunnel->debug = cfg->debug;
16491650

1651+
#if IS_ENABLED(CONFIG_IPV6)
1652+
if (sk->sk_family == PF_INET6) {
1653+
struct ipv6_pinfo *np = inet6_sk(sk);
1654+
1655+
if (ipv6_addr_v4mapped(&np->saddr) &&
1656+
ipv6_addr_v4mapped(&np->daddr)) {
1657+
struct inet_sock *inet = inet_sk(sk);
1658+
1659+
tunnel->v4mapped = true;
1660+
inet->inet_saddr = np->saddr.s6_addr32[3];
1661+
inet->inet_rcv_saddr = np->rcv_saddr.s6_addr32[3];
1662+
inet->inet_daddr = np->daddr.s6_addr32[3];
1663+
} else {
1664+
tunnel->v4mapped = false;
1665+
}
1666+
}
1667+
#endif
1668+
16501669
/* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
16511670
tunnel->encap = encap;
16521671
if (encap == L2TP_ENCAPTYPE_UDP) {
@@ -1655,7 +1674,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
16551674
udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
16561675
udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
16571676
#if IS_ENABLED(CONFIG_IPV6)
1658-
if (sk->sk_family == PF_INET6)
1677+
if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
16591678
udpv6_encap_enable();
16601679
else
16611680
#endif

Diff for: net/l2tp/l2tp_core.h

+3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ struct l2tp_tunnel {
189189
struct sock *sock; /* Parent socket */
190190
int fd; /* Parent fd, if tunnel socket
191191
* was created by userspace */
192+
#if IS_ENABLED(CONFIG_IPV6)
193+
bool v4mapped;
194+
#endif
192195

193196
struct work_struct del_work;
194197

0 commit comments

Comments
 (0)