Skip to content

Commit c915fe1

Browse files
Paolo Abenidavem330
authored andcommitted
udplite: fix NULL pointer dereference
The commit 850cbad ("udp: use it's own memory accounting schema") assumes that the socket proto has memory accounting enabled, but this is not the case for UDPLITE. Fix it enabling memory accounting for UDPLITE and performing fwd allocated memory reclaiming on socket shutdown. UDP and UDPLITE share now the same memory accounting limits. Also drop the backlog receive operation, since is no more needed. Fixes: 850cbad ("udp: use it's own memory accounting schema") Reported-by: Andrei Vagin <avagin@gmail.com> Suggested-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e6ca4f1 commit c915fe1

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

include/net/udp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
246246
}
247247

248248
/* net/ipv4/udp.c */
249+
void udp_destruct_sock(struct sock *sk);
249250
void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len);
250251
int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb);
251252
void udp_skb_destructor(struct sock *sk, struct sk_buff *skb);

include/net/udplite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static __inline__ int udplite_getfrag(void *from, char *to, int offset,
2727
static inline int udplite_sk_init(struct sock *sk)
2828
{
2929
udp_sk(sk)->pcflag = UDPLITE_BIT;
30+
sk->sk_destruct = udp_destruct_sock;
3031
return 0;
3132
}
3233

net/ipv4/udp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
12531253
}
12541254
EXPORT_SYMBOL_GPL(__udp_enqueue_schedule_skb);
12551255

1256-
static void udp_destruct_sock(struct sock *sk)
1256+
void udp_destruct_sock(struct sock *sk)
12571257
{
12581258
/* reclaim completely the forward allocated memory */
12591259
unsigned int total = 0;
@@ -1267,6 +1267,7 @@ static void udp_destruct_sock(struct sock *sk)
12671267

12681268
inet_sock_destruct(sk);
12691269
}
1270+
EXPORT_SYMBOL_GPL(udp_destruct_sock);
12701271

12711272
int udp_init_sock(struct sock *sk)
12721273
{

net/ipv4/udplite.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ struct proto udplite_prot = {
5050
.sendmsg = udp_sendmsg,
5151
.recvmsg = udp_recvmsg,
5252
.sendpage = udp_sendpage,
53-
.backlog_rcv = udp_queue_rcv_skb,
5453
.hash = udp_lib_hash,
5554
.unhash = udp_lib_unhash,
5655
.get_port = udp_v4_get_port,
56+
.memory_allocated = &udp_memory_allocated,
57+
.sysctl_mem = sysctl_udp_mem,
5758
.obj_size = sizeof(struct udp_sock),
5859
.h.udp_table = &udplite_table,
5960
#ifdef CONFIG_COMPAT

net/ipv6/udplite.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ struct proto udplitev6_prot = {
4545
.getsockopt = udpv6_getsockopt,
4646
.sendmsg = udpv6_sendmsg,
4747
.recvmsg = udpv6_recvmsg,
48-
.backlog_rcv = udpv6_queue_rcv_skb,
4948
.hash = udp_lib_hash,
5049
.unhash = udp_lib_unhash,
5150
.get_port = udp_v6_get_port,
51+
.memory_allocated = &udp_memory_allocated,
52+
.sysctl_mem = sysctl_udp_mem,
5253
.obj_size = sizeof(struct udp6_sock),
5354
.h.udp_table = &udplite_table,
5455
#ifdef CONFIG_COMPAT

0 commit comments

Comments
 (0)