Skip to content

Commit fe81d9f

Browse files
hptasinskidavem330
authored andcommitted
net: sctp: Fix IPv6 ancestor_size calc in sctp_copy_descendant
When calculating ancestor_size with IPv6 enabled, simply using sizeof(struct ipv6_pinfo) doesn't account for extra bytes needed for alignment in the struct sctp6_sock. On x86, there aren't any extra bytes, but on ARM the ipv6_pinfo structure is aligned on an 8-byte boundary so there were 4 pad bytes that were omitted from the ancestor_size calculation. This would lead to corruption of the pd_lobby pointers, causing an oops when trying to free the sctp structure on socket close. Fixes: 636d25d ("sctp: not copy sctp_sock pd_lobby in sctp_copy_descendant") Signed-off-by: Henry Ptasinski <hptasinski@google.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b6e1178 commit fe81d9f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

include/net/sctp/structs.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,14 @@ struct sctp_sock {
226226
data_ready_signalled:1;
227227

228228
atomic_t pd_mode;
229+
230+
/* Fields after this point will be skipped on copies, like on accept
231+
* and peeloff operations
232+
*/
233+
229234
/* Receive to here while partial delivery is in effect. */
230235
struct sk_buff_head pd_lobby;
231236

232-
/* These must be the last fields, as they will skipped on copies,
233-
* like on accept and peeloff operations
234-
*/
235237
struct list_head auto_asconf_list;
236238
int do_auto_asconf;
237239
};

net/sctp/socket.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9220,13 +9220,10 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
92209220
static inline void sctp_copy_descendant(struct sock *sk_to,
92219221
const struct sock *sk_from)
92229222
{
9223-
int ancestor_size = sizeof(struct inet_sock) +
9224-
sizeof(struct sctp_sock) -
9225-
offsetof(struct sctp_sock, pd_lobby);
9226-
9227-
if (sk_from->sk_family == PF_INET6)
9228-
ancestor_size += sizeof(struct ipv6_pinfo);
9223+
size_t ancestor_size = sizeof(struct inet_sock);
92299224

9225+
ancestor_size += sk_from->sk_prot->obj_size;
9226+
ancestor_size -= offsetof(struct sctp_sock, pd_lobby);
92309227
__inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
92319228
}
92329229

0 commit comments

Comments
 (0)