1. 14 9月, 2021 1 次提交
  2. 13 9月, 2021 1 次提交
  3. 05 8月, 2021 2 次提交
    • G
      net/ipv4/ipv6: Replace one-element arraya with flexible-array members · db243b79
      Gustavo A. R. Silva 提交于
      There is a regular need in the kernel to provide a way to declare having
      a dynamically sized set of trailing elements in a structure. Kernel code
      should always use “flexible array members”[1] for these cases. The older
      style of one-element or zero-length arrays should no longer be used[2].
      
      Use an anonymous union with a couple of anonymous structs in order to
      keep userspace unchanged and refactor the related code accordingly:
      
      $ pahole -C group_filter net/ipv4/ip_sockglue.o
      struct group_filter {
      	union {
      		struct {
      			__u32      gf_interface_aux;     /*     0     4 */
      
      			/* XXX 4 bytes hole, try to pack */
      
      			struct __kernel_sockaddr_storage gf_group_aux; /*     8   128 */
      			/* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
      			__u32      gf_fmode_aux;         /*   136     4 */
      			__u32      gf_numsrc_aux;        /*   140     4 */
      			struct __kernel_sockaddr_storage gf_slist[1]; /*   144   128 */
      		};                                       /*     0   272 */
      		struct {
      			__u32      gf_interface;         /*     0     4 */
      
      			/* XXX 4 bytes hole, try to pack */
      
      			struct __kernel_sockaddr_storage gf_group; /*     8   128 */
      			/* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
      			__u32      gf_fmode;             /*   136     4 */
      			__u32      gf_numsrc;            /*   140     4 */
      			struct __kernel_sockaddr_storage gf_slist_flex[0]; /*   144     0 */
      		};                                       /*     0   144 */
      	};                                               /*     0   272 */
      
      	/* size: 272, cachelines: 5, members: 1 */
      	/* last cacheline: 16 bytes */
      };
      
      $ pahole -C compat_group_filter net/ipv4/ip_sockglue.o
      struct compat_group_filter {
      	union {
      		struct {
      			__u32      gf_interface_aux;     /*     0     4 */
      			struct __kernel_sockaddr_storage gf_group_aux __attribute__((__aligned__(4))); /*     4   128 */
      			/* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */
      			__u32      gf_fmode_aux;         /*   132     4 */
      			__u32      gf_numsrc_aux;        /*   136     4 */
      			struct __kernel_sockaddr_storage gf_slist[1] __attribute__((__aligned__(4))); /*   140   128 */
      		} __attribute__((__packed__)) __attribute__((__aligned__(4)));                     /*     0   268 */
      		struct {
      			__u32      gf_interface;         /*     0     4 */
      			struct __kernel_sockaddr_storage gf_group __attribute__((__aligned__(4))); /*     4   128 */
      			/* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */
      			__u32      gf_fmode;             /*   132     4 */
      			__u32      gf_numsrc;            /*   136     4 */
      			struct __kernel_sockaddr_storage gf_slist_flex[0] __attribute__((__aligned__(4))); /*   140     0 */
      		} __attribute__((__packed__)) __attribute__((__aligned__(4)));                     /*     0   140 */
      	} __attribute__((__aligned__(1)));               /*     0   268 */
      
      	/* size: 268, cachelines: 5, members: 1 */
      	/* forced alignments: 1 */
      	/* last cacheline: 12 bytes */
      } __attribute__((__packed__));
      
      This helps with the ongoing efforts to globally enable -Warray-bounds
      and get us closer to being able to tighten the FORTIFY_SOURCE routines
      on memcpy().
      
      [1] https://en.wikipedia.org/wiki/Flexible_array_member
      [2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays
      
      Link: https://github.com/KSPP/linux/issues/79
      Link: https://github.com/KSPP/linux/issues/109Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      db243b79
    • G
      net/ipv4: Revert use of struct_size() helper · 4167a960
      Gustavo A. R. Silva 提交于
      Revert the use of structr_size() and stay with IP_MSFILTER_SIZE() for
      now, as in this case, the size of struct ip_msfilter didn't change with
      the addition of the flexible array imsf_slist_flex[]. So, if we use
      struct_size() we will be allocating and calculating the size of
      struct ip_msfilter with one too many items for imsf_slist_flex[].
      
      We might use struct_size() in the future, but for now let's stay
      with IP_MSFILTER_SIZE().
      
      Fixes: 	2d3e5caf ("net/ipv4: Replace one-element array with flexible-array member")
      Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4167a960
  4. 02 8月, 2021 1 次提交
  5. 25 8月, 2020 1 次提交
  6. 25 7月, 2020 8 次提交
  7. 20 7月, 2020 6 次提交
  8. 29 5月, 2020 5 次提交
  9. 26 5月, 2020 1 次提交
  10. 21 5月, 2020 8 次提交
  11. 12 5月, 2020 1 次提交
    • C
      net: cleanly handle kernel vs user buffers for ->msg_control · 1f466e1f
      Christoph Hellwig 提交于
      The msg_control field in struct msghdr can either contain a user
      pointer when used with the recvmsg system call, or a kernel pointer
      when used with sendmsg.  To complicate things further kernel_recvmsg
      can stuff a kernel pointer in and then use set_fs to make the uaccess
      helpers accept it.
      
      Replace it with a union of a kernel pointer msg_control field, and
      a user pointer msg_control_user one, and allow kernel_recvmsg operate
      on a proper kernel pointer using a bitfield to override the normal
      choice of a user pointer for recvmsg.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1f466e1f
  12. 26 5月, 2019 1 次提交
  13. 10 1月, 2019 1 次提交
  14. 06 11月, 2018 1 次提交
    • T
      net: bpfilter: fix iptables failure if bpfilter_umh is disabled · 97adadda
      Taehee Yoo 提交于
      When iptables command is executed, ip_{set/get}sockopt() try to upload
      bpfilter.ko if bpfilter is enabled. if it couldn't find bpfilter.ko,
      command is failed.
      bpfilter.ko is generated if CONFIG_BPFILTER_UMH is enabled.
      ip_{set/get}sockopt() only checks CONFIG_BPFILTER.
      So that if CONFIG_BPFILTER is enabled and CONFIG_BPFILTER_UMH is disabled,
      iptables command is always failed.
      
      test config:
         CONFIG_BPFILTER=y
         # CONFIG_BPFILTER_UMH is not set
      
      test command:
         %iptables -L
         iptables: No chain/target/match by that name.
      
      Fixes: d2ba09c1 ("net: add skeleton of bpfilter kernel module")
      Signed-off-by: NTaehee Yoo <ap420073@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      97adadda
  15. 03 10月, 2018 1 次提交
  16. 25 7月, 2018 1 次提交
    • W
      ip: in cmsg IP(V6)_ORIGDSTADDR call pskb_may_pull · 2efd4fca
      Willem de Bruijn 提交于
      Syzbot reported a read beyond the end of the skb head when returning
      IPV6_ORIGDSTADDR:
      
        BUG: KMSAN: kernel-infoleak in put_cmsg+0x5ef/0x860 net/core/scm.c:242
        CPU: 0 PID: 4501 Comm: syz-executor128 Not tainted 4.17.0+ #9
        Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
        Google 01/01/2011
        Call Trace:
          __dump_stack lib/dump_stack.c:77 [inline]
          dump_stack+0x185/0x1d0 lib/dump_stack.c:113
          kmsan_report+0x188/0x2a0 mm/kmsan/kmsan.c:1125
          kmsan_internal_check_memory+0x138/0x1f0 mm/kmsan/kmsan.c:1219
          kmsan_copy_to_user+0x7a/0x160 mm/kmsan/kmsan.c:1261
          copy_to_user include/linux/uaccess.h:184 [inline]
          put_cmsg+0x5ef/0x860 net/core/scm.c:242
          ip6_datagram_recv_specific_ctl+0x1cf3/0x1eb0 net/ipv6/datagram.c:719
          ip6_datagram_recv_ctl+0x41c/0x450 net/ipv6/datagram.c:733
          rawv6_recvmsg+0x10fb/0x1460 net/ipv6/raw.c:521
          [..]
      
      This logic and its ipv4 counterpart read the destination port from
      the packet at skb_transport_offset(skb) + 4.
      
      With MSG_MORE and a local SOCK_RAW sender, syzbot was able to cook a
      packet that stores headers exactly up to skb_transport_offset(skb) in
      the head and the remainder in a frag.
      
      Call pskb_may_pull before accessing the pointer to ensure that it lies
      in skb head.
      
      Link: http://lkml.kernel.org/r/CAF=yD-LEJwZj5a1-bAAj2Oy_hKmGygV6rsJ_WOrAYnv-fnayiQ@mail.gmail.com
      Reported-by: syzbot+9adb4b567003cac781f0@syzkaller.appspotmail.com
      Signed-off-by: NWillem de Bruijn <willemb@google.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2efd4fca