stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 3.18 09/45] net: support compat 64-bit time in {s,g}etsockopt
Date: Thu, 24 May 2018 11:38:17 +0200	[thread overview]
Message-ID: <20180524093121.701835354@linuxfoundation.org> (raw)
In-Reply-To: <20180524093120.599252450@linuxfoundation.org>

3.18-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
@@ -387,7 +387,8 @@ static int compat_sock_setsockopt(struct
 	if (optname == SO_ATTACH_FILTER)
 		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);
@@ -452,7 +453,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);
 }

  parent reply	other threads:[~2018-05-24  9:41 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24  9:38 [PATCH 3.18 00/45] 3.18.110-stable review Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 01/45] 8139too: Use disable_irq_nosync() in rtl8139_poll_controller() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 02/45] bridge: check iface upper dev when setting master via ioctl Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 03/45] dccp: fix tasklet usage Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 04/45] ipv4: fix memory leaks in udp_sendmsg, ping_v4_sendmsg Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 05/45] llc: better deal with too small mtu Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 06/45] net: ethernet: sun: niu set correct packet size in skb Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 07/45] net/mlx4_en: Verify coalescing parameters are in range Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 08/45] net_sched: fq: take care of throttled flows before reuse Greg Kroah-Hartman
2018-05-24  9:38 ` Greg Kroah-Hartman [this message]
2018-05-24  9:38 ` [PATCH 3.18 10/45] r8169: fix powering up RTL8168h Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 11/45] sctp: use the old asoc when making the cookie-ack chunk in dupcook_d Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 12/45] tg3: Fix vunmap() BUG_ON() triggered from tg3_free_consistent() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 13/45] bonding: do not allow rlb updates to invalid mac Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 14/45] tcp: ignore Fast Open on repair mode Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 15/45] sctp: fix the issue that the cookie-ack with auth cant get processed Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 16/45] sctp: delay the authentication for the duplicated cookie-echo chunk Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 18/45] lockd: lost rollback of set_grace_period() in lockd_down_net() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 19/45] Revert "ARM: dts: imx6qdl-wandboard: Fix audio channel swap" Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 20/45] l2tp: revert "l2tp: fix missing print session offset info" Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 21/45] pipe: cap initial pipe capacity according to pipe-max-size limit Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 22/45] kernel/exit.c: avoid undefined behaviour when calling wait4() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 23/45] usbip: usbip_host: refine probe and disconnect debug msgs to be useful Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 24/45] usbip: usbip_host: delete device from busid_table after rebind Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 25/45] usbip: usbip_host: run rebind from exit when module is removed Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 26/45] usbip: fix error handling in stub_probe() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 27/45] usbip: usbip_host: fix NULL-ptr deref and use-after-free errors Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 28/45] usbip: usbip_host: fix bad unlock balance during stub_probe() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 29/45] ALSA: usb: mixer: volume quirk for CM102-A+/102S+ Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 30/45] ALSA: control: fix a redundant-copy issue Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 31/45] powerpc: Dont preempt_disable() in show_cpuinfo() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 32/45] tracing/x86/xen: Remove zero data size trace events trace_xen_mmu_flush_tlb{_all} Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 33/45] powerpc/powernv: Fix NVRAM sleep in invalid context when crashing Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 34/45] efi: Avoid potential crashes, fix the struct efi_pci_io_protocol_32 definition for mixed mode Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 35/45] ARM: 8771/1: kprobes: Prohibit kprobes on do_undefinstr Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 36/45] tick/broadcast: Use for_each_cpu() specially on UP kernels Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 37/45] ARM: 8772/1: kprobes: Prohibit kprobes on get_user functions Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 38/45] net: test tailroom before appending to linear skb Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 39/45] tcp: purge write queue in tcp_connect_init() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 40/45] ext2: fix a block leak Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 41/45] scsi: libsas: defer ata device eh commands to libata Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 42/45] scsi: sg: allocate with __GFP_ZERO in sg_build_indirect() Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 43/45] cfg80211: limit wiphy names to 128 bytes Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 44/45] hfsplus: stop workqueue when fill_super() failed Greg Kroah-Hartman
2018-05-24  9:38 ` [PATCH 3.18 45/45] x86/kexec: Avoid double free_page() upon do_kexec_load() failure Greg Kroah-Hartman
2018-05-24 14:42 ` [PATCH 3.18 00/45] 3.18.110-stable review Nathan Chancellor
2018-05-24 14:44 ` Harsh Shandilya
2018-05-24 19:46   ` Greg Kroah-Hartman
2018-05-24 17:30 ` Guenter Roeck
2018-05-24 19:31 ` Shuah Khan

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=20180524093121.701835354@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).