android_kernel_samsung_msm8976/net/netfilter
Julian Anastasov 56635ddc59 ipvs: fix buffer overflow with sync daemon and service
commit 52f96757905bbf0edef47f3ee6c7c784e7f8ff8a upstream.

syzkaller reports for buffer overflow for interface name
when starting sync daemons [1]

What we do is that we copy user structure into larger stack
buffer but later we search NUL past the stack buffer.
The same happens for sched_name when adding/editing virtual server.

We are restricted by IP_VS_SCHEDNAME_MAXLEN and IP_VS_IFNAME_MAXLEN
being used as size in include/uapi/linux/ip_vs.h, so they
include the space for NUL.

As using strlcpy is wrong for unsafe source, replace it with
strscpy and add checks to return EINVAL if source string is not
NUL-terminated. The incomplete strlcpy fix comes from 2.6.13.

For the netlink interface reduce the len parameter for
IPVS_DAEMON_ATTR_MCAST_IFN and IPVS_SVC_ATTR_SCHED_NAME,
so that we get proper EINVAL.

[1]
kernel BUG at lib/string.c:1052!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
    (ftrace buffer empty)
Modules linked in:
CPU: 1 PID: 373 Comm: syz-executor936 Not tainted 4.17.0-rc4+ #45
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
RIP: 0010:fortify_panic+0x13/0x20 lib/string.c:1051
RSP: 0018:ffff8801c976f800 EFLAGS: 00010282
RAX: 0000000000000022 RBX: 0000000000000040 RCX: 0000000000000000
RDX: 0000000000000022 RSI: ffffffff8160f6f1 RDI: ffffed00392edef6
RBP: ffff8801c976f800 R08: ffff8801cf4c62c0 R09: ffffed003b5e4fb0
R10: ffffed003b5e4fb0 R11: ffff8801daf27d87 R12: ffff8801c976fa20
R13: ffff8801c976fae4 R14: ffff8801c976fae0 R15: 000000000000048b
FS:  00007fd99f75e700(0000) GS:ffff8801daf00000(0000)
knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000200001c0 CR3: 00000001d6843000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
  strlen include/linux/string.h:270 [inline]
  strlcpy include/linux/string.h:293 [inline]
  do_ip_vs_set_ctl+0x31c/0x1d00 net/netfilter/ipvs/ip_vs_ctl.c:2388
  nf_sockopt net/netfilter/nf_sockopt.c:106 [inline]
  nf_setsockopt+0x7d/0xd0 net/netfilter/nf_sockopt.c:115
  ip_setsockopt+0xd8/0xf0 net/ipv4/ip_sockglue.c:1253
  udp_setsockopt+0x62/0xa0 net/ipv4/udp.c:2487
  ipv6_setsockopt+0x149/0x170 net/ipv6/ipv6_sockglue.c:917
  tcp_setsockopt+0x93/0xe0 net/ipv4/tcp.c:3057
  sock_common_setsockopt+0x9a/0xe0 net/core/sock.c:3046
  __sys_setsockopt+0x1bd/0x390 net/socket.c:1903
  __do_sys_setsockopt net/socket.c:1914 [inline]
  __se_sys_setsockopt net/socket.c:1911 [inline]
  __x64_sys_setsockopt+0xbe/0x150 net/socket.c:1911
  do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:287
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x447369
RSP: 002b:00007fd99f75dda8 EFLAGS: 00000246 ORIG_RAX: 0000000000000036
RAX: ffffffffffffffda RBX: 00000000006e39e4 RCX: 0000000000447369
RDX: 000000000000048b RSI: 0000000000000000 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000018 R09: 0000000000000000
R10: 00000000200001c0 R11: 0000000000000246 R12: 00000000006e39e0
R13: 75a1ff93f0896195 R14: 6f745f3168746576 R15: 0000000000000001
Code: 08 5b 41 5c 41 5d 41 5e 41 5f 5d c3 0f 0b 48 89 df e8 d2 8f 48 fa eb
de 55 48 89 fe 48 c7 c7 60 65 64 88 48 89 e5 e8 91 dd f3 f9 <0f> 0b 90 90
90 90 90 90 90 90 90 90 90 55 48 89 e5 41 57 41 56
RIP: fortify_panic+0x13/0x20 lib/string.c:1051 RSP: ffff8801c976f800

Change-Id: I60d908e03538def93e5b6784d828da9fb88ac465
Reported-and-tested-by: syzbot+aac887f77319868646df@syzkaller.appspotmail.com
Fixes: e4ff67513096 ("ipvs: add sync_maxlen parameter for the sync daemon")
Fixes: 4da62fc70d ("[IPVS]: Fix for overflows")
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
[bwh: Backported to 3.16: Interface name is copied in start_sync_thread(),
 not do_ip_vs_set_ctl()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
2019-07-27 22:08:33 +02:00
..
ipset netfilter: ipset: small potential read beyond the end of buffer 2015-01-27 07:52:33 -08:00
ipvs ipvs: fix buffer overflow with sync daemon and service 2019-07-27 22:08:33 +02:00
Kconfig BACKPORT: netfilter: Kconfig: get rid of parens around depends on 2019-07-27 21:51:02 +02:00
Makefile
core.c
nf_conntrack_acct.c
nf_conntrack_amanda.c netfilter: Fix is to allow successful restore 2014-07-22 16:29:37 +05:30
nf_conntrack_broadcast.c
nf_conntrack_core.c This is the 3.10.99 stable release 2017-04-18 17:17:46 +02:00
nf_conntrack_ecache.c netfilter: invoke synchronize_rcu after set the _hook_ to NULL 2019-07-27 21:44:22 +02:00
nf_conntrack_expect.c netfilter: nf_conntrack: Support expectations in different zones 2015-10-22 14:37:50 -07:00
nf_conntrack_extend.c netfilter: nf_ct_ext: fix possible panic after nf_ct_extend_unregister 2019-07-27 21:44:26 +02:00
nf_conntrack_ftp.c
nf_conntrack_h323_asn1.c
nf_conntrack_h323_main.c
nf_conntrack_h323_types.c
nf_conntrack_helper.c
nf_conntrack_irc.c Netfilter: IRC DCC fixes 2015-06-19 14:38:50 +05:30
nf_conntrack_l3proto_generic.c
nf_conntrack_labels.c
nf_conntrack_netbios_ns.c
nf_conntrack_netlink.c netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize 2019-07-27 21:44:51 +02:00
nf_conntrack_pptp.c
nf_conntrack_proto.c
nf_conntrack_proto_dccp.c
nf_conntrack_proto_generic.c netfilter: conntrack: disable generic tracking for known protocols 2015-04-29 10:33:59 +02:00
nf_conntrack_proto_gre.c
nf_conntrack_proto_sctp.c
nf_conntrack_proto_tcp.c netfilter: nf_conntrack: avoid large timeout for mid-stream pickup 2014-10-05 14:54:15 -07:00
nf_conntrack_proto_udp.c
nf_conntrack_proto_udplite.c
nf_conntrack_sane.c
nf_conntrack_sip.c netfilter: Fix to MO call issue 2015-03-24 11:53:07 +05:30
nf_conntrack_snmp.c
nf_conntrack_standalone.c
nf_conntrack_tftp.c
nf_conntrack_timeout.c
nf_conntrack_timestamp.c
nf_internals.h
nf_log.c netfilter: nf_log: don't hold nf_log_mutex during user access 2019-07-27 21:50:15 +02:00
nf_nat_amanda.c
nf_nat_core.c netfilter: nf_nat: add full port randomization support 2019-07-27 22:08:25 +02:00
nf_nat_ftp.c
nf_nat_helper.c
nf_nat_irc.c netfilter:Changes to Allow IRC DCC 2014-11-17 09:24:00 +05:30
nf_nat_proto_common.c netfilter: nf_nat: add full port randomization support 2019-07-27 22:08:25 +02:00
nf_nat_proto_dccp.c
nf_nat_proto_sctp.c
nf_nat_proto_tcp.c
nf_nat_proto_udp.c
nf_nat_proto_udplite.c
nf_nat_proto_unknown.c
nf_nat_sip.c msm: netfilter: changes to handle contact address modification in SIP ALG 2015-01-28 01:54:53 -08:00
nf_nat_tftp.c
nf_queue.c
nf_sockopt.c
nf_tproxy_core.c
nfnetlink.c
nfnetlink_acct.c
nfnetlink_cthelper.c netfilter: nfnetlink_cthelper: Add missing permission checks 2019-07-27 21:45:53 +02:00
nfnetlink_cttimeout.c netfilter: invoke synchronize_rcu after set the _hook_ to NULL 2019-07-27 21:44:22 +02:00
nfnetlink_log.c netfilter: nf_log: release skbuff on nlmsg put failure 2014-11-21 09:22:54 -08:00
nfnetlink_queue_core.c netfilter: nf_queue: augment nfqa_cfg_policy 2019-07-27 21:52:53 +02:00
nfnetlink_queue_ct.c
x_tables.c netfilter: x_tables: avoid stack-out-of-bounds read in xt_copy_counters_from_user 2019-07-27 21:45:49 +02:00
xt_AUDIT.c
xt_CHECKSUM.c
xt_CLASSIFY.c
xt_CONNSECMARK.c
xt_CT.c
xt_DSCP.c
xt_HARDIDLETIMER.c netfilter:Notify user space on creating sysfs file 2019-07-27 21:51:05 +02:00
xt_HL.c
xt_HMARK.c
xt_IDLETIMER.c netfilter:Notify user space on creating sysfs file 2019-07-27 21:51:05 +02:00
xt_LED.c netfilter: x_tables: fix missing timer initialization in xt_LED 2019-07-27 21:49:20 +02:00
xt_LOG.c
xt_NETMAP.c
xt_NFLOG.c
xt_NFQUEUE.c
xt_RATEEST.c netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert 2019-07-27 21:49:19 +02:00
xt_REDIRECT.c
xt_SECMARK.c
xt_TCPMSS.c netfilter: xt_TCPMSS: correct return value in tcpmss_mangle_packet 2019-07-27 21:46:06 +02:00
xt_TCPOPTSTRIP.c
xt_TEE.c
xt_TPROXY.c
xt_TRACE.c
xt_addrtype.c
xt_bpf.c
xt_cluster.c
xt_comment.c
xt_connbytes.c
xt_connlabel.c
xt_connlimit.c
xt_connmark.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
xt_conntrack.c
xt_cpu.c
xt_dccp.c
xt_devgroup.c
xt_dscp.c
xt_ecn.c
xt_esp.c
xt_hashlimit.c
xt_helper.c
xt_hl.c
xt_iprange.c
xt_ipvs.c
xt_length.c
xt_limit.c
xt_mac.c
xt_mark.c
xt_multiport.c
xt_nat.c
xt_nfacct.c
xt_osf.c netfilter: xt_osf: Add missing permission checks 2019-07-27 21:45:53 +02:00
xt_owner.c
xt_physdev.c
xt_pkttype.c
xt_policy.c
xt_qtaguid.c BACKPORT: ANDROID: Use sk_uid to replace uid get from socket file 2019-07-27 21:51:34 +02:00
xt_qtaguid_internal.h BACKPORT: ANDROID: Use sk_uid to replace uid get from socket file 2019-07-27 21:51:34 +02:00
xt_qtaguid_print.c ANDROID: Add untag hacks to inet_release function 2019-07-27 21:50:41 +02:00
xt_qtaguid_print.h
xt_quota.c
xt_quota2.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
xt_rateest.c
xt_realm.c
xt_recent.c
xt_repldata.h
xt_sctp.c
xt_set.c
xt_socket.c netfilter: xt_socket: add XT_SOCKET_RESTORESKMARK flag 2015-12-14 09:53:08 -07:00
xt_state.c
xt_statistic.c
xt_string.c
xt_tcpmss.c
xt_tcpudp.c
xt_time.c
xt_u32.c