Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp59732imu; Thu, 8 Nov 2018 14:47:40 -0800 (PST) X-Google-Smtp-Source: AJdET5e/jSU0neWoEevPIdMkSQSW9r3kxngg53Muyp7HsAOKN1Pn0Az5Tj/9seqH4LXFSdd4nLi6 X-Received: by 2002:a63:af45:: with SMTP id s5-v6mr5354953pgo.125.1541717260835; Thu, 08 Nov 2018 14:47:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541717260; cv=none; d=google.com; s=arc-20160816; b=ZAqrMtRXbYvVvgRRcvmV+08T5Jobe+gQULAxmh3JW39SyX1LHWnVwk/92HoyXr1oOR QenYVXq1P9nG5pNyVBHafBwtXq5nUuMeEwWcoyZmGhYw4i+uxF8zAvyVtIlww4Dr92Fj jiBYn+PporSF8LDNjHFYFY1EHnSWFxrJdm5FxxML3HBT5k1PQmE9LGFKdALcZcYGmBnF VOAYLXIrg2Z5tuGlkMw2zuklCRKNuxVPd2M1HWOagtjSxFeCMCg5W8rmtA5O6Tq7nXnk aENHSOFUzq0g1UFX8LLqHJaq6IbxSPiVlU/SyU6Q3ks+r07vNmUD7XDpvjA22UduGv6b ZppA== 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=hS1ZoAP3vQOAyQ9oxqavfXyGNcBwndBhE8G5D9IzuHg=; b=eIZiioRCOhRMg4eC8/Helab5/PlaPT5Bra/k5tZ2p2Fi1iZWpnzkgZnYjBwKWx4Ej4 HqageFbVSegNFG2hHvym8niCsS43NUkD63fXUoVEHhHSRXOWpGB0kQH4cUXzkvamBrkY 0gwGThFHJ83oYb80kKSgcVmJYkPIiAiv+aLVqHVv2ukVnJDIaqxcv7BupqDMBD9cl0Y4 GJBag/zUtFfrn8U7EB/Erf2gj7DAv+BsEJCMN+pBC1ELgb8a/wsXcWRPdGtnURa5zoSg jgxzrkbIUAdGOzW9yTipM1GCtscSKHajl5PFEmKY8mlzYu/SWCndNTx8z9+tBBZBTxHo pDQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=arCSYf+b; 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 b23-v6si2089196pls.367.2018.11.08.14.47.25; Thu, 08 Nov 2018 14:47:40 -0800 (PST) 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=arCSYf+b; 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 S1728150AbeKIHbz (ORCPT + 99 others); Fri, 9 Nov 2018 02:31:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:46696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726694AbeKIHby (ORCPT ); Fri, 9 Nov 2018 02:31:54 -0500 Received: from localhost (unknown [208.72.13.198]) (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 86A6D20857; Thu, 8 Nov 2018 21:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714067; bh=qRhjYCOOt2j0eGkeOpfBJAOsdKpl8ny8BAlgzlXbDMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=arCSYf+bI7Z+vId/DWg07cDYn11EFJCPddit2bFt5/ruoKSzKQxUxSWS34w17sIng iR0TrvO1E6lDzYiWqHYlz2cGAnx+wPL0pBjW0tpQkqbpJI3DdbnyErVRccv8cQtgR1 JvK4s7AWWRvwvvO/g1MnXx8a9dN6H0LM0/Sc9/go= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Air Icy , Steffen Klassert , Sasha Levin Subject: [PATCH 3.18 020/144] xfrm: Validate address prefix lengths in the xfrm selector. Date: Thu, 8 Nov 2018 13:49:51 -0800 Message-Id: <20181108215056.256123428@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215054.826084593@linuxfoundation.org> References: <20181108215054.826084593@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 07bf7908950a8b14e81aa1807e3c667eab39287a ] We don't validate the address prefix lengths in the xfrm selector we got from userspace. This can lead to undefined behaviour in the address matching functions if the prefix is too big for the given address family. Fix this by checking the prefixes and refuse SA/policy insertation when a prefix is invalid. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Air Icy Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_user.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 4fe43d80c153..ca99638b5d5a 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -150,10 +150,16 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, err = -EINVAL; switch (p->family) { case AF_INET: + if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32) + goto out; + break; case AF_INET6: #if IS_ENABLED(CONFIG_IPV6) + if (p->sel.prefixlen_d > 128 || p->sel.prefixlen_s > 128) + goto out; + break; #else err = -EAFNOSUPPORT; @@ -1285,10 +1291,16 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p) switch (p->sel.family) { case AF_INET: + if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32) + return -EINVAL; + break; case AF_INET6: #if IS_ENABLED(CONFIG_IPV6) + if (p->sel.prefixlen_d > 128 || p->sel.prefixlen_s > 128) + return -EINVAL; + break; #else return -EAFNOSUPPORT; -- 2.17.1