Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1909753imm; Thu, 24 May 2018 02:46:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpS1lczU5dYEfLIamyMoUzBCvIDGUhxSLyXRTZpEdoh5GA01MCJ5eVLOZsamZ1yT1GVG2Mn X-Received: by 2002:a65:4204:: with SMTP id c4-v6mr5149068pgq.26.1527155166656; Thu, 24 May 2018 02:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527155166; cv=none; d=google.com; s=arc-20160816; b=GqFZq/UV6/CQhFT0z/xDBqmOkIvtgjF/DXtRtkchF1C6AvkjLXM1/OnU+Hw3Y9bABQ sNf/3MWP2rqa69gA/GChULI/a/bZ0ZTWLIflX9adH1NM85h71a1yc+ReDRLoBur6qGP1 AIJr9oRlkIzPA9pSXvJyvN4y7gj+THNagIXJaXpnkXR7268JIYpyE1fv0wR0SLAvwnCW B/nf/lXRVuJ8PIl4l9cv7V33hyfSWmcY5+1Ezk+sqAmSg7mZIvQhPnv3pSpSbo4j32ZX ezix0R6Y+U4i9bBFnfl7XJxk6f4jf7lSGsRa/8NDUhCtnOjcxseObZnBv13OPXUCWOLJ dolQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=li9NQmD01U39zT9x9y3dyITrt/ePb4zl+VZb634c46A=; b=GHcyIxzUAiQ6nKUN+tRGaBSShicVOr7bBbRrGXwFPQbpE06OskBTbY09v/WHsM4qCH 0DwIRlLII1KVwROyFYGNrq2cZ5PWky4GiGarQXL7DQxXb8fUkQAolg+vjPFSS5kvTbj/ JJIzx6JAjxhmQSWyLxhVnGKIElc4cBa1EBcrWOvtgmjkjg48fF+XbpOvvhf4WJjOxeef nAAcsWPqk9apBa859kMu3Duztp0gfzBKs1Rv/BPtYO/s4bfSCodXXgBKuH5r4ebb3ihQ 4fn0wjXAoInNLXdo5DcAa1TUnntLGsNUZwVRGiuRUsEzvYxV7S9IzsnBQ3/F3QlCbmkg iKug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=19BmGqNz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11-v6si21682454plt.455.2018.05.24.02.45.52; Thu, 24 May 2018 02:46:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=19BmGqNz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966667AbeEXJod (ORCPT + 99 others); Thu, 24 May 2018 05:44:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:55774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966655AbeEXJoa (ORCPT ); Thu, 24 May 2018 05:44:30 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0F1FA20892; Thu, 24 May 2018 09:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155069; bh=5rAh4k3DmSkzqMRihqlzVCg+tX60hs2poBtnRgk6EhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=19BmGqNzVM8M6oCAm1tQVaszLTxsHt9M1K+M2O4aEyoFZpvtzK6dFTprahQcD2Wbv rryuQB/Rs2eje1XpaGtTJxKaKKhdrKbzLEa8TPy2i4B/DkG1wHE9/M6v6ZfuhXGQou ZnkcGVFOcQFdew9GWEjhNcdvR7QZgVOIFIryDexQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gopal RajagopalSai , Lance Richardson , "David S. Miller" Subject: [PATCH 4.4 09/92] net: support compat 64-bit time in {s,g}etsockopt Date: Thu, 24 May 2018 11:37:46 +0200 Message-Id: <20180524093200.123957806@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lance Richardson [ 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 #include #include #include #include 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 Signed-off-by: Lance Richardson Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/compat.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/compat.c +++ b/net/compat.c @@ -358,7 +358,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); @@ -423,7 +424,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); }