Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp584066img; Fri, 22 Mar 2019 04:33:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgvQCsJ0KwLku8B7x4kZiiBJO90+c7QtmcIIbgv77PgkWfGVA8RvPMvCd0Ywcc+jB9BxkK X-Received: by 2002:a63:cd10:: with SMTP id i16mr8106542pgg.90.1553254388965; Fri, 22 Mar 2019 04:33:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553254388; cv=none; d=google.com; s=arc-20160816; b=LGkcR2I3nQKi2mgdEhdD+NcjqVVmTp4JIjBec3wx+k9JsWVAXa5MkxXDLyHlaWz4d4 rWaleiWOXttP3xB1J27RzDMRZOqnpWQp8ctKguIxojXloI3yDSy6izsa00iN/6Dl5LAP LIeAR/KeyRp3Z+10CrfD9kbInB4vtLPNWRLW/W9stVM0yQtLkBwAzb9AEjLaWU2wQbvG dxXByi8L8pGoFDRLkf1HhEtu67ApuWA6h+10sP9IUU00chctWe975c2n1mH9enRbohVq rRIXsv2livPRrObPR4iKi8PIG10uxCrJ+RSFwR4W9qff9UD1W5kMO1F01GdTQtxbCSpK r81g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3fMW+0vzJy9QyT/Pt91xyqu5ETAxSQzz6xb1wp5rsT8=; b=0Afd/ZQfxzbphpPJO8hy6U7Hn+0q97c21ODaf3XzSgn+viEOjCOE6T51lZQ+CgyHbc 5OUTyhtmtQuGUVVsf0fGBFqJmqoOSrnd+QvTu+k9ziZn5zpv6ZobbooO5lP90aDONRFP pYVShiYu+fvMTSJV7Z4oii69Gmv9rlrCEK0EaLkpDhvBn9NkxGAbj+01PERyLumzwIu1 w1R/BL7Zco8Ms5lxVWqldXFfD8FEoR6EApyCHTqEMP8bP+zO6fhezPrr11jJtWCsVVNe KaUyJ1vHlXRCK9sHqfon7JfTho8OLOc6igIyn/C3d7vZh9Ub0rh2GBS/pbK6cHKWmlrP s/cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b6Ya7Pa1; 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 s14si6356460pgs.98.2019.03.22.04.32.50; Fri, 22 Mar 2019 04:33:08 -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=b6Ya7Pa1; 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 S1730111AbfCVLcH (ORCPT + 99 others); Fri, 22 Mar 2019 07:32:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:60402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728306AbfCVLcE (ORCPT ); Fri, 22 Mar 2019 07:32:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 893DD20449; Fri, 22 Mar 2019 11:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553254324; bh=XOzGluBYg3h32gvo7WQDBLD+AKArlsq7YH+ZEpCPHGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b6Ya7Pa18uKJSb0j/V6Uq8lhyZYC1NdGkSZSJvg/suE//e2u6mQY0amg+vQ3CWn0U K2GX9AnyHS0q/AC17CEGgh+1Z00Cjome2pea/PuD/NimDCFb5lunaqD3JHYSooaucF EAawX1bgPvfJi1aNbGl8uqagDOXhbaSpBjAfdbw8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, ZhangXiaoxu , Simon Horman , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.4 083/230] ipvs: Fix signed integer overflow when setsockopt timeout Date: Fri, 22 Mar 2019 12:13:41 +0100 Message-Id: <20190322111242.459322107@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111236.796964179@linuxfoundation.org> References: <20190322111236.796964179@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. ------------------ [ Upstream commit 53ab60baa1ac4f20b080a22c13b77b6373922fd7 ] There is a UBSAN bug report as below: UBSAN: Undefined behaviour in net/netfilter/ipvs/ip_vs_ctl.c:2227:21 signed integer overflow: -2147483647 * 1000 cannot be represented in type 'int' Reproduce program: #include #include #include #define IPPROTO_IP 0 #define IPPROTO_RAW 255 #define IP_VS_BASE_CTL (64+1024+64) #define IP_VS_SO_SET_TIMEOUT (IP_VS_BASE_CTL+10) /* The argument to IP_VS_SO_GET_TIMEOUT */ struct ipvs_timeout_t { int tcp_timeout; int tcp_fin_timeout; int udp_timeout; }; int main() { int ret = -1; int sockfd = -1; struct ipvs_timeout_t to; sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); if (sockfd == -1) { printf("socket init error\n"); return -1; } to.tcp_timeout = -2147483647; to.tcp_fin_timeout = -2147483647; to.udp_timeout = -2147483647; ret = setsockopt(sockfd, IPPROTO_IP, IP_VS_SO_SET_TIMEOUT, (char *)(&to), sizeof(to)); printf("setsockopt return %d\n", ret); return ret; } Return -EINVAL if the timeout value is negative or max than 'INT_MAX / HZ'. Signed-off-by: ZhangXiaoxu Acked-by: Simon Horman Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/ipvs/ip_vs_ctl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 3167ec76903a..56c62b65923f 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -2217,6 +2217,18 @@ static int ip_vs_set_timeout(struct netns_ipvs *ipvs, struct ip_vs_timeout_user u->tcp_fin_timeout, u->udp_timeout); +#ifdef CONFIG_IP_VS_PROTO_TCP + if (u->tcp_timeout < 0 || u->tcp_timeout > (INT_MAX / HZ) || + u->tcp_fin_timeout < 0 || u->tcp_fin_timeout > (INT_MAX / HZ)) { + return -EINVAL; + } +#endif + +#ifdef CONFIG_IP_VS_PROTO_UDP + if (u->udp_timeout < 0 || u->udp_timeout > (INT_MAX / HZ)) + return -EINVAL; +#endif + #ifdef CONFIG_IP_VS_PROTO_TCP if (u->tcp_timeout) { pd = ip_vs_proto_data_get(ipvs, IPPROTO_TCP); -- 2.19.1