net: sctp: Fix IPv6 ancestor_size calc in sctp_copy_descendant
Subsystems (3)
PATCH 1/1 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.
--- net/sctp/socket.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/sctp/socket.c +6 -4
@@ -9220,12 +9220,14 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,static inline void sctp_copy_descendant (struct sock *sk_to,const struct sock *sk_from) { -int ancestor_size =sizeof (struct inet_sock ) + -sizeof (struct sctp_sock ) - - offsetof(struct sctp_sock , pd_lobby); +size_t ancestor_size =sizeof (struct inet_sock );if (sk_from->sk_family =PF_INET6 ) - ancestor_size +=sizeof (struct ipv6_pinfo ); + ancestor_size +=sizeof (struct sctp6_sock ); +else + ancestor_size +=sizeof (struct sctp_sock ); + + ancestor_size -= offsetof(struct sctp_sock , pd_lobby);__inet_sk_copy_descendant (sk_to, sk_from, ancestor_size); }
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Henry,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on net/master]
[also build test ERROR on net-next/master linus/master ipvs/master v5.9-rc5 next-20200917] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Henry-Ptasinski/net-sctp-Fix-IPv6-ancestor_size-calc-in-sctp_copy_descendant/20200918-100033 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 5f6857e808a8bd078296575b417c4b9d160b9779 config: arm64-randconfig-r026-20200917 (attached as .config) compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
net/sctp/socket.c: In function 'sctp_copy_descendant':
>> net/sctp/socket.c:9226:27: error: invalid application of 'sizeof' to incomplete type 'struct sctp6_sock'
9226 | ancestor_size += sizeof(struct sctp6_sock);
| ^~~~~~# https://github.com/0day-ci/linux/commit/3d29e6e42f7bbc9671df460a4e8250710db5fd28
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Henry-Ptasinski/net-sctp-Fix-IPv6-ancestor_size-calc-in-sctp_copy_descendant/20200918-100033 git checkout 3d29e6e42f7bbc9671df460a4e8250710db5fd28
vim +9226 net/sctp/socket.c
9219
9220 static inline void sctp_copy_descendant(struct sock *sk_to,
9221 const struct sock *sk_from)
9222 {
9223 size_t ancestor_size = sizeof(struct inet_sock);
9224
9225 if (sk_from->sk_family == PF_INET6)
> 9226 ancestor_size += sizeof(struct sctp6_sock);
9227 else
9228 ancestor_size += sizeof(struct sctp_sock);
9229
9230 ancestor_size -= offsetof(struct sctp_sock, pd_lobby);
9231
9232 __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
9233 }
9234
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Marcelo Ricardo Leitner
maintainerQuoted 8 lines · Henry Ptasinski
When calculating
ancestor_sizewith IPv6 enabled, simply usingsizeof(struct ipv6_pinfo)doesn't account for extra bytes needed for alignment in the structsctp6_sock. On x86, there aren't any extra bytes, but on ARM theipv6_pinfostructure is aligned on an 8-byte boundary so there were 4 pad bytes that were omitted from theancestor_sizecalculation. This would lead to corruption of thepd_lobbypointers, causing an oops when trying to free the sctp structure on socket close.
Makes sense.
Quoted 2 lines
Signed-off-by Henry Ptasinski <[email protected]>
Please add a:
net/sctp/socket.c void sctp_copy_sock(struct sock *newsk, struct sock *sk, · line 9220
Quoted 10 lines
--- net/sctp/socket.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)net/sctp/socket.c +0
-0@@ -9220,12 +9220,14 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk, static inline void sctp_copy_descendant(struct sock *sk_to,
^^^^^^ I'll send a patch to fix/remove this.
net/sctp/socket.c void sctp_copy_sock(struct sock *newsk, struct sock *sk, · line 9225
Quoted 5 lines
net/sctp/socket.c +0
-3const struct sock *sk_from) { -int ancestor_size =sizeof (struct inet_sock ) + -sizeof (struct sctp_sock ) - - offsetof(struct sctp_sock , pd_lobby);
^^^^^^^^
Then, as this patch is actually fixing the aforementioned commit, please also update the comment on sctp_sock definition, as pd_lobby now is also skipped.
net/sctp/socket.c void sctp_copy_sock(struct sock *newsk, struct sock *sk, · line 9226
Quoted 5 lines
net/sctp/socket.c +2
-1+size_t ancestor_size =sizeof (struct inet_sock );if (sk_from->sk_family =PF_INET6 ) - ancestor_size +=sizeof (struct ipv6_pinfo ); + ancestor_size +=sizeof (struct sctp6_sock );
As you probably noticed by the build bot email already, there need to be some protection to building without IPv6 enabled.
To avoid ifdefs here, something similar to how inet_sk_copy_descendant() is done is probably welcomed, but please feel free to be creative. :-)
Quoted 10 lines
net/sctp/socket.c +4
-0+else + ancestor_size +=sizeof (struct sctp_sock ); + + ancestor_size -= offsetof(struct sctp_sock , pd_lobby);__inet_sk_copy_descendant (sk_to, sk_from, ancestor_size); }Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
PATCH v2 1/1 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.
--- include/net/sctp/structs.h | 8 +++++--- net/sctp/socket.c | 9 +++------ 2 files changed, 8 insertions(+), 9 deletions(-)
include/net/sctp/structs.h +5 -3
@@ -226,12 +226,14 @@ struct sctp_sock { data_ready_signalled:1 ;atomic_t pd_mode; + +/* Fields after this point will be skipped on copies, like on accept +* and peeloff operations +*/ +/* Receive to here while partial delivery is in effect. */ struct sk_buff_head pd_lobby; -/* These must be the last fields, as they will skipped on copies, -* like on accept and peeloff operations -*/ struct list_head auto_asconf_list;int do_auto_asconf; };
net/sctp/socket.c +3 -6
@@ -9220,13 +9220,10 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,static inline void sctp_copy_descendant (struct sock *sk_to,const struct sock *sk_from) { -int ancestor_size =sizeof (struct inet_sock ) + -sizeof (struct sctp_sock ) - - offsetof(struct sctp_sock , pd_lobby); - -if (sk_from->sk_family =PF_INET6 ) - ancestor_size +=sizeof (struct ipv6_pinfo ); +size_t ancestor_size =sizeof (struct inet_sock ); + ancestor_size += sk_from->sk_prot->obj_size; + ancestor_size -= offsetof(struct sctp_sock , pd_lobby);__inet_sk_copy_descendant (sk_to, sk_from, ancestor_size); }
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
Quoted 11 lines · Henry Ptasinski
When calculating
ancestor_sizewith IPv6 enabled, simply usingsizeof(struct ipv6_pinfo)doesn't account for extra bytes needed for alignment in the structsctp6_sock. On x86, there aren't any extra bytes, but on ARM theipv6_pinfostructure is aligned on an 8-byte boundary so there were 4 pad bytes that were omitted from theancestor_sizecalculation. This would lead to corruption of thepd_lobbypointers, causing an oops when trying to free the sctp structure on socket close.Fixes 636d25d557d1 ("sctp: not copy sctp_sock pd_lobby in sctp_copy_descendant")Signed-off-by Henry Ptasinski <[email protected]>
...
net/sctp/socket.c void sctp_copy_sock(struct sock *newsk, struct sock *sk, · line 9225
Quoted 10 lines
{
net/sctp/socket.c +2
-6-int ancestor_size =sizeof (struct inet_sock ) + -sizeof (struct sctp_sock ) - - offsetof(struct sctp_sock , pd_lobby); - -if (sk_from->sk_family =PF_INET6 ) - ancestor_size +=sizeof (struct ipv6_pinfo ); +size_t ancestor_size =sizeof (struct inet_sock ); + ancestor_size += sk_from->sk_prot->obj_size;
Heh, of course. Nice one.
Quoted 7 lines
net/sctp/socket.c +1
-0+ ancestor_size -= offsetof(struct sctp_sock , pd_lobby);__inet_sk_copy_descendant (sk_to, sk_from, ancestor_size); }Signature · 2 lines
-- 2.28.0.681.g6f77f65b4e-goog
David Miller
maintainerFrom: Henry Ptasinski <[email protected]>
Date: Sat, 19 Sep 2020 00:12:11 +0000
Quoted 11 lines
When calculating
ancestor_sizewith IPv6 enabled, simply usingsizeof(struct ipv6_pinfo)doesn't account for extra bytes needed for alignment in the structsctp6_sock. On x86, there aren't any extra bytes, but on ARM theipv6_pinfostructure is aligned on an 8-byte boundary so there were 4 pad bytes that were omitted from theancestor_sizecalculation. This would lead to corruption of thepd_lobbypointers, causing an oops when trying to free the sctp structure on socket close.Fixes 636d25d557d1 ("sctp: not copy sctp_sock pd_lobby in sctp_copy_descendant")Signed-off-by Henry Ptasinski <[email protected]>
Applied and queued up for -stable, thank you.