android_kernel_oneplus_msm8998/net
Stefano Brivio 85088e3870 ipv4: Return -ENETUNREACH if we can't create route but saddr is valid
[ Upstream commit 595e0651d0296bad2491a4a29a7a43eae6328b02 ]

...instead of -EINVAL. An issue was found with older kernel versions
while unplugging a NFS client with pending RPCs, and the wrong error
code here prevented it from recovering once link is back up with a
configured address.

Incidentally, this is not an issue anymore since commit 4f8943f80883
("SUNRPC: Replace direct task wakeups from softirq context"), included
in 5.2-rc7, had the effect of decoupling the forwarding of this error
by using SO_ERROR in xs_wake_error(), as pointed out by Benjamin
Coddington.

To the best of my knowledge, this isn't currently causing any further
issue, but the error code doesn't look appropriate anyway, and we
might hit this in other paths as well.

In detail, as analysed by Gonzalo Siero, once the route is deleted
because the interface is down, and can't be resolved and we return
-EINVAL here, this ends up, courtesy of inet_sk_rebuild_header(),
as the socket error seen by tcp_write_err(), called by
tcp_retransmit_timer().

In turn, tcp_write_err() indirectly calls xs_error_report(), which
wakes up the RPC pending tasks with a status of -EINVAL. This is then
seen by call_status() in the SUN RPC implementation, which aborts the
RPC call calling rpc_exit(), instead of handling this as a
potentially temporary condition, i.e. as a timeout.

Return -EINVAL only if the input parameters passed to
ip_route_output_key_hash_rcu() are actually invalid (this is the case
if the specified source address is multicast, limited broadcast or
all zeroes), but return -ENETUNREACH in all cases where, at the given
moment, the given source address doesn't allow resolving the route.

While at it, drop the initialisation of err to -ENETUNREACH, which
was added to __ip_route_output_key() back then by commit
0315e38270 ("net: Fix behaviour of unreachable, blackhole and
prohibit routes"), but actually had no effect, as it was, and is,
overwritten by the fib_lookup() return code assignment, and anyway
ignored in all other branches, including the if (fl4->saddr) one:
I find this rather confusing, as it would look like -ENETUNREACH is
the "default" error, while that statement has no effect.

Also note that after commit fc75fc8339 ("ipv4: dont create routes
on down devices"), we would get -ENETUNREACH if the device is down,
but -EINVAL if the source address is specified and we can't resolve
the route, and this appears to be rather inconsistent.

Reported-by: Stefan Walter <walteste@inf.ethz.ch>
Analysed-by: Benjamin Coddington <bcodding@redhat.com>
Analysed-by: Gonzalo Siero <gsierohu@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-10-29 09:13:23 +01:00
..
6lowpan
9p 9p/virtio: Add cleanup path in p9_virtio_init 2019-08-04 09:34:51 +02:00
802
8021q vlan: disable SIOCSHWTSTAMP in container 2019-05-16 19:45:17 +02:00
appletalk appletalk: enforce CAP_NET_RAW for raw sockets 2019-10-05 12:27:43 +02:00
atm net: atm: Fix potential Spectre v1 vulnerabilities 2019-04-27 09:33:59 +02:00
ax25 ax25: enforce CAP_NET_RAW for raw sockets 2019-10-05 12:27:43 +02:00
batman-adv batman-adv: fix for leaked TVLV handler. 2019-08-04 09:34:39 +02:00
bluetooth Revert "Bluetooth: validate BLE connection interval updates" 2019-10-05 12:27:36 +02:00
bridge bridge/mdb: remove wrong use of NLM_F_MULTI 2019-09-21 07:12:37 +02:00
caif
can can: purge socket error queue on sock destruct 2019-07-10 09:56:33 +02:00
ceph libceph: handle an empty authorize reply 2019-03-23 08:44:18 +01:00
core net: Fix null de-reference of device refcount 2019-09-21 07:12:39 +02:00
dcb
dccp dccp: do not use ipv6 header for ipv4 flow 2019-04-03 06:23:25 +02:00
decnet
dns_resolver
dsa net: dsa: slave: Don't propagate flag changes on down slave interfaces 2019-02-20 10:13:15 +01:00
ethernet
hsr net/hsr: fix possible crash in add_timer() 2019-03-23 08:44:31 +01:00
ieee802154 ieee802154: enforce CAP_NET_RAW for raw sockets 2019-10-05 12:27:43 +02:00
ipv4 ipv4: Return -ENETUNREACH if we can't create route but saddr is valid 2019-10-29 09:13:23 +01:00
ipv6 ipv6: drop incoming packets having a v4mapped source address 2019-10-07 21:01:04 +02:00
ipx
irda
iucv
key xfrm: clean up xfrm protocol checks 2019-09-16 08:13:35 +02:00
l2tp compat_ioctl: pppoe: fix PPPOEIOCSFWD handling 2019-08-11 12:20:46 +02:00
l3mdev
lapb lapb: fixed leak of control-blocks. 2019-06-22 08:18:25 +02:00
llc llc: fix skb leak in llc_build_and_send_ui_pkt() 2019-06-11 12:24:06 +02:00
mac80211 mac80211: handle deauthentication/disassociation from TDLS peer 2019-10-05 12:27:39 +02:00
mac802154
mpls
netfilter netfilter: nf_conntrack_ftp: Fix debug output 2019-09-21 07:12:51 +02:00
netlabel
netlink
netrom netrom: hold sock when setting skb->destructor 2019-08-04 09:34:54 +02:00
nfc NFC: fix attrs checks in netlink interface 2019-10-07 21:01:07 +02:00
openvswitch openvswitch: change type of UPCALL_PID attribute to NLA_UNSPEC 2019-10-05 12:27:41 +02:00
packet af_packet: tone down the Tx-ring unsupported spew. 2019-09-16 08:13:36 +02:00
phonet phonet: fix building with clang 2019-03-23 08:44:34 +01:00
rds net/rds: Fix error handling in rds_ib_add_one() 2019-10-07 21:01:06 +02:00
rfkill
rose net: rose: fix a possible stack overflow 2019-04-03 06:23:25 +02:00
rxrpc
sched net: avoid potential infinite loop in tc_ctl_action() 2019-10-29 09:13:22 +01:00
sctp sctp: change sctp_prot .no_autobind with true 2019-10-29 09:13:22 +01:00
sunrpc sunrpc: don't mark uninitialised items as VALID. 2019-05-16 19:44:44 +02:00
switchdev
tipc tipc: add NULL pointer check before calling kfree_rcu 2019-09-21 07:12:41 +02:00
unix missing barriers in some of unix_sock ->addr and ->path accesses 2019-03-23 08:44:31 +01:00
vmw_vsock vsock: cope with memory allocation failure at socket creation time 2019-02-23 09:05:13 +01:00
wimax
wireless nl80211: fix null pointer dereference 2019-10-29 09:13:20 +01:00
x25 net/x25: fix a race in x25_bind() 2019-03-23 08:44:30 +01:00
xfrm xfrm: clean up xfrm protocol checks 2019-09-16 08:13:35 +02:00
compat.c sock: Make sock->sk_stamp thread-safe 2019-01-13 10:05:28 +01:00
Kconfig
Makefile
socket.c sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names 2019-03-23 08:44:21 +01:00
sysctl_net.c