Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2284350imc; Tue, 12 Mar 2019 10:34:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqz91CbhvHMP4CT89p51I6hcUQXWiyOFkUL8YxGmMcR5S+H6kkiD2bMxRUQ8RJ/vzQifOQQZ X-Received: by 2002:a63:cc05:: with SMTP id x5mr35838991pgf.31.1552412040465; Tue, 12 Mar 2019 10:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552412040; cv=none; d=google.com; s=arc-20160816; b=zQ/+tdJlvtaO+Xt9niUimQdNelrxcKlj6OhuUTe/PwjhaJ9j5/+jBtquSAG3JAbshO w0tAgtRzJnspUYViTwKGjm/H4WXfKezrsdUKBKYqQlilqkW/+Gi3EPGdwpv4MzZAvFYZ j2ncu8yroaXxDG1peStEwovGPLzwrVemDJhLWWIwYNYoXTFvPufGUQaqG4sZHkfMxzil olcZ12sSszNXBs0SnE3jmmUibUa5J8Td79Qy4tbM4zuGOvKF9UNAR+GRu/ZOlqxRyx0O GirzxGlL9edySbq9SY1eo5cq/89/n2Aog0DTeZPkOMQKGdcOfosm16VPjGi+kUntaRjU x1YA== 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=hmiOQibZ534xobDS7A7RvsREYnXrOY1uBrjbXtcdrDA=; b=p1lK5OeCRb6LozyS6xSk64hzyQTj3+9uP2VKDonqFLdqz3ii1rdJRwtbRhGnZijyU3 W2OPNgUtyeAahe058ULLCjxWwbcWLwPZe6dp+i+xphQK2MdskBk1TwMh1pCM2m8K0mMh xO9o5TWeKGXBa+YrI7A3og0zZMbNlrfSbQI2PiDRoaMzH/wbY20qhpYuaJ3Pl3ce3kM8 GsA28CBKPuxr1fyB53T1SieEPa43Knp3kJwfPBq2QgEX2u76+WBNnILlfrnKfm6Jl5nW VoSSMa77CNawJX00FNgXsO+bH7IGxVGXFIXqfRxHNK2W53CN/nDWB3d95BbIbk7hjeFN WMeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="y+gjPt/4"; 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 cy1si9296610plb.429.2019.03.12.10.33.44; Tue, 12 Mar 2019 10:34:00 -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="y+gjPt/4"; 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 S1729473AbfCLRRL (ORCPT + 99 others); Tue, 12 Mar 2019 13:17:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:57614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728968AbfCLRQE (ORCPT ); Tue, 12 Mar 2019 13:16:04 -0400 Received: from localhost (unknown [104.133.8.98]) (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 025EF21850; Tue, 12 Mar 2019 17:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410964; bh=8h0ClOKckmUj/kya6Qke4sN/Cy6KQglprMPlDCvvIkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y+gjPt/4a361tFJE0GYkZFDRs2qN+nGujpzcy9oXu8kXEfeALESqCK9x4McoTQtoR jAZ7CLaXlnaWjm9duuaiH8PX/7PckmSmZykhEtb1B+KkK7gG2i4O6JOMTy8uK1Ay9t 7kA9bLu+BmZ+dMR4xSFkHJhKgxlYdclnqWX6SpeQ= 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.14 050/135] ipvs: Fix signed integer overflow when setsockopt timeout Date: Tue, 12 Mar 2019 10:08:17 -0700 Message-Id: <20190312170345.780652682@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170341.127810985@linuxfoundation.org> References: <20190312170341.127810985@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.14-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 2f45c3ce77ef..dff4ead3d117 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -2252,6 +2252,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