From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Gopal RajagopalSai <gopalsr83@gmail.com>,
Lance Richardson <lance.richardson.net@gmail.com>,
"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 4.16 16/55] net: support compat 64-bit time in {s,g}etsockopt
Date: Fri, 18 May 2018 10:15:12 +0200 [thread overview]
Message-ID: <20180518081458.265799303@linuxfoundation.org> (raw)
In-Reply-To: <20180518081457.428920292@linuxfoundation.org>
4.16-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lance Richardson <lance.richardson.net@gmail.com>
[ Upstream commit 988bf7243e03ef69238381594e0334a79cef74a6 ]
For the x32 ABI, struct timeval has two 64-bit fields. However
the kernel currently interprets the user-space values used for
the SO_RCVTIMEO and SO_SNDTIMEO socket options as having a pair
of 32-bit fields.
When the seconds portion of the requested timeout is less than 2**32,
the seconds portion of the effective timeout is correct but the
microseconds portion is zero. When the seconds portion of the
requested timeout is zero and the microseconds portion is non-zero,
the kernel interprets the timeout as zero (never timeout).
Fix by using 64-bit time for SO_RCVTIMEO/SO_SNDTIMEO as required
for the ABI.
The code included below demonstrates the problem.
Results before patch:
$ gcc -m64 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 2.008181 seconds
send time: 2.015985 seconds
$ gcc -m32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 2.016763 seconds
send time: 2.016062 seconds
$ gcc -mx32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 1.007239 seconds
send time: 1.023890 seconds
Results after patch:
$ gcc -m64 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.010062 seconds
send time: 2.015836 seconds
$ gcc -m32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.013974 seconds
send time: 2.015981 seconds
$ gcc -mx32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.030257 seconds
send time: 2.013383 seconds
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
void checkrc(char *str, int rc)
{
if (rc >= 0)
return;
perror(str);
exit(1);
}
static char buf[1024];
int main(int argc, char **argv)
{
int rc;
int socks[2];
struct timeval tv;
struct timeval start, end, delta;
rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socks);
checkrc("socketpair", rc);
/* set timeout to 1.999999 seconds */
tv.tv_sec = 1;
tv.tv_usec = 999999;
rc = setsockopt(socks[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
rc = setsockopt(socks[0], SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
checkrc("setsockopt", rc);
/* measure actual receive timeout */
gettimeofday(&start, NULL);
rc = recv(socks[0], buf, sizeof buf, 0);
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("recv time: %ld.%06ld seconds\n",
(long)delta.tv_sec, (long)delta.tv_usec);
/* fill send buffer */
do {
rc = send(socks[0], buf, sizeof buf, 0);
} while (rc > 0);
/* measure actual send timeout */
gettimeofday(&start, NULL);
rc = send(socks[0], buf, sizeof buf, 0);
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("send time: %ld.%06ld seconds\n",
(long)delta.tv_sec, (long)delta.tv_usec);
exit(0);
}
Fixes: 515c7af85ed9 ("x32: Use compat shims for {g,s}etsockopt")
Reported-by: Gopal RajagopalSai <gopalsr83@gmail.com>
Signed-off-by: Lance Richardson <lance.richardson.net@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
net/compat.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--- a/net/compat.c
+++ b/net/compat.c
@@ -377,7 +377,8 @@ static int compat_sock_setsockopt(struct
optname == SO_ATTACH_REUSEPORT_CBPF)
return do_set_attach_filter(sock, level, optname,
optval, optlen);
- if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
+ if (!COMPAT_USE_64BIT_TIME &&
+ (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
return do_set_sock_timeout(sock, level, optname, optval, optlen);
return sock_setsockopt(sock, level, optname, optval, optlen);
@@ -442,7 +443,8 @@ static int do_get_sock_timeout(struct so
static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen)
{
- if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
+ if (!COMPAT_USE_64BIT_TIME &&
+ (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
return do_get_sock_timeout(sock, level, optname, optval, optlen);
return sock_getsockopt(sock, level, optname, optval, optlen);
}
next prev parent reply other threads:[~2018-05-18 8:18 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-18 8:14 [PATCH 4.16 00/55] 4.16.10-stable review Greg Kroah-Hartman
2018-05-18 8:14 ` [PATCH 4.16 01/55] 8139too: Use disable_irq_nosync() in rtl8139_poll_controller() Greg Kroah-Hartman
2018-05-18 8:14 ` [PATCH 4.16 02/55] bridge: check iface upper dev when setting master via ioctl Greg Kroah-Hartman
2018-05-18 8:14 ` [PATCH 4.16 03/55] dccp: fix tasklet usage Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 04/55] ipv4: fix fnhe usage by non-cached routes Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 05/55] ipv4: fix memory leaks in udp_sendmsg, ping_v4_sendmsg Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 06/55] llc: better deal with too small mtu Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 07/55] net: ethernet: sun: niu set correct packet size in skb Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 08/55] net: ethernet: ti: cpsw: fix packet leaking in dual_mac mode Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 09/55] net/mlx4_en: Fix an error handling path in mlx4_en_init_netdev() Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 10/55] net/mlx4_en: Verify coalescing parameters are in range Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 11/55] net/mlx5e: Err if asked to offload TC match on frag being first Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 12/55] net/mlx5: E-Switch, Include VF RDMA stats in vport statistics Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 13/55] net sched actions: fix refcnt leak in skbmod Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 14/55] net_sched: fq: take care of throttled flows before reuse Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 15/55] net/smc: restrict non-blocking connect finish Greg Kroah-Hartman
2018-05-18 8:15 ` Greg Kroah-Hartman [this message]
2018-05-18 8:15 ` [PATCH 4.16 17/55] net/tls: Dont recursively call push_record during tls_write_space callbacks Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 18/55] net/tls: Fix connection stall on partial tls record Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 19/55] openvswitch: Dont swap table in nlattr_set() after OVS_ATTR_NESTED is found Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 21/55] r8169: fix powering up RTL8168h Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 22/55] rds: do not leak kernel memory to user land Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 23/55] sctp: delay the authentication for the duplicated cookie-echo chunk Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 24/55] sctp: fix the issue that the cookie-ack with auth cant get processed Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 25/55] sctp: handle two v4 addrs comparison in sctp_inet6_cmp_addr Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 26/55] sctp: remove sctp_chunk_put from fail_mark err path in sctp_ulpevent_make_rcvmsg Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 27/55] sctp: use the old asoc when making the cookie-ack chunk in dupcook_d Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 28/55] tcp_bbr: fix to zero idle_restart only upon S/ACKed data Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 29/55] tcp: ignore Fast Open on repair mode Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 30/55] tg3: Fix vunmap() BUG_ON() triggered from tg3_free_consistent() Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 31/55] bonding: do not allow rlb updates to invalid mac Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 32/55] bonding: send learning packets for vlans on slave Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 33/55] net: sched: fix error path in tcf_proto_create() when modules are not configured Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 34/55] net/mlx5e: TX, Use correct counter in dma_map error flow Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 35/55] net/mlx5: Avoid cleaning flow steering table twice during " Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 36/55] hv_netvsc: set master device Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 37/55] ipv6: fix uninit-value in ip6_multipath_l3_keys() Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 38/55] net/mlx5e: Allow offloading ipv4 header re-write for icmp Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 39/55] nsh: fix infinite loop Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 40/55] udp: fix SO_BINDTODEVICE Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 41/55] mlxsw: spectrum_switchdev: Do not remove mrouter port from MDBs ports list Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 42/55] net/mlx5e: DCBNL fix min inline header size for dscp Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 43/55] net: systemport: Correclty disambiguate driver instances Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 44/55] nfp: flower: set tunnel ttl value to net default Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 45/55] sctp: clear the new asocs stream outcnt in sctp_stream_update Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 46/55] tcp: restore autocorking Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 47/55] tipc: fix one byte leak in tipc_sk_set_orig_addr() Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 48/55] hv_netvsc: Fix net device attach on older Windows hosts Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 49/55] ipv4: reset fnhe_mtu_locked after cache route flushed Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 50/55] mlxsw: core: Fix an error handling path in mlxsw_core_bus_device_register() Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 51/55] net/mlx5: Fix mlx5_get_vector_affinity function Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 52/55] net: phy: sfp: fix the BR,min computation Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 53/55] net/smc: keep clcsock reference in smc_tcp_listen_work() Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 54/55] scsi: aacraid: Correct hba_send to include iu_type Greg Kroah-Hartman
2018-05-18 8:15 ` [PATCH 4.16 55/55] proc: do not access cmdline nor environ from file-backed areas Greg Kroah-Hartman
2018-05-18 13:29 ` [PATCH 4.16 00/55] 4.16.10-stable review Guenter Roeck
2018-05-18 13:56 ` Greg Kroah-Hartman
2018-05-18 19:25 ` Naresh Kamboju
2018-05-19 7:43 ` Greg Kroah-Hartman
2018-05-18 20:45 ` Shuah Khan
2018-05-19 7:42 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180518081458.265799303@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=davem@davemloft.net \
--cc=gopalsr83@gmail.com \
--cc=lance.richardson.net@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).