Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp52588imu; Thu, 8 Nov 2018 14:38:08 -0800 (PST) X-Google-Smtp-Source: AJdET5dQMz3MBpzlaew/qtj61+mpEayKmaRnzgsHHBhMe3Ydg7DhiBdi/70l1MVmXh+yI3Mu5ors X-Received: by 2002:a62:2782:: with SMTP id n124-v6mr6538219pfn.216.1541716688750; Thu, 08 Nov 2018 14:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716688; cv=none; d=google.com; s=arc-20160816; b=GQvYshNLjOFABrMgOHpRoausnEnwQqAxWoATW3WFQB91yrNEBjoip0NWEXb+VP8lSL V94bmgAwYp6L5JBId4+XdIOilu2Bae4yLmoYb0U7o0GUv4+ev7zBuTMLhWCeS+D/R72F ffQGvzrAlOl9DmY9LbkUI5ZakX2RxwdIMU5Gc1+p2gorxAx/g4tLIsPxKmpWMs8weejJ vLdjrVl4Yje/9+sc/IfyTHZevNKPHYiC9/1l4Nbn8i5kx4JQnhHSv7oOODDb0MbLEMQ3 3rlOjws0oY8XKZaGmK/5D1/1u5V8Fjsdu8/aTvqmtdNa8CuyIpcPFKnUmft/jK9pWtAx mnCA== 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=1wsWpRIG71KSEfvOKrPzZ7CyX9jWqI3Moek0z4XJq58=; b=LByQaoLUcS/tBBNZBC5lT/eolbi2YSneeAUz55XnBouH6faohU9uaBKAEbPyBXUN9R 5xTm+uXNYGr5waj57dmKb35urv9RpdlNrro4iEMBSIhpQPUHHh02Q77g96YKjhCGuDL+ dZtrljAHaAS2XyQsubze/AGGCxkbmGSIKk6r5bNGxXEbXYIOhJ+ziksIoL54Xb0E3x5e foWbtOzFvZip6Jaa4rFtMNwp62orvOmZW5N861P6wePaPCvYzF3AL9Ge0+0rcchOPWXN 61VofmtCPNxp6NG47qbmY3TUr2HeyOmnbInxA2EhnLqqhNZHUpRwOibu8il8EKGNRLGP 7Eug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hQPuuYAt; 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 j14si4813070pgi.354.2018.11.08.14.37.52; Thu, 08 Nov 2018 14:38:08 -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=hQPuuYAt; 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 S1728988AbeKIIPN (ORCPT + 99 others); Fri, 9 Nov 2018 03:15:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:53128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728344AbeKIHgA (ORCPT ); Fri, 9 Nov 2018 02:36:00 -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 AB393208E3; Thu, 8 Nov 2018 21:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714312; bh=CTjzpNoaAcAh6TIP9PAZfnk78D3MogcxhtG0WISzelU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hQPuuYAtR014gf9aws+sn1Nm15PhDKvR1Wfzg1TVybBM4Tgw1Q/rBdZ3QbidsW8G/ FVCt8NrV6IBoxnYUZZfAdj30r70rNUHuYLTy7P3A7bfKaqy6NkI5H5ONLZtIcftU5l nK0qbMXhU/LOZiM+RxRx4UEeZS8d75oqI1P6Nvqs= 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 4.4 001/114] xfrm: Validate address prefix lengths in the xfrm selector. Date: Thu, 8 Nov 2018 13:50:16 -0800 Message-Id: <20181108215059.146651302@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 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 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 a9b4491a3cc4..c2e98dcba9fe 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -151,10 +151,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; @@ -1312,10 +1318,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