Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2453110imd; Fri, 2 Nov 2018 11:39:28 -0700 (PDT) X-Google-Smtp-Source: AJdET5eCbTxbQOM8y+HELfU7/KVapX06QFoU2PnAqzt4rH6T3GSqwVMO3QUNDMUXmmZWTuwvaTgY X-Received: by 2002:a17:902:4381:: with SMTP id j1-v6mr12493427pld.59.1541183968369; Fri, 02 Nov 2018 11:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541183968; cv=none; d=google.com; s=arc-20160816; b=FxAakWeNEiN6bHFf2y/UHNHU3lri/yJuiY2oafhFRIhRa9/X6bjh3CVThJVqqSTEVR 2yvjuJHXcf9SKM+3mayiTfAvdm+o5vl5qT+B+UBCDHXAWEsLZKcy+RAicBpTsi/AkOyk V6u6ZcWYJNpRwuH9P9fZei/VdDBTrmRLqvcThKmIs9B8UCuZZwrcLdLtgwSXjzhhwWDB pSZwq/A91umvhBtpABvgVdAkBLrWQEHHlMdJDE9hlpKzbc371pHw729BA5q4B3w9mLE/ 8z49af4gu6O4NOEgneDVuRBZDYEbP3i7137LXvuasjmKs+rkx1RQVLVon+pW2dJT3bOd vUJg== 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=/7R1mh9JV2JBMJ7lhoKjqlHlbMGYJ420iNGZGsuD7Mo=; b=QPqBYsGUCCzm+93mlSUCvWVD//LJS4a9qxrbm0TMFSJJfc/4L6ll3hMO19AlUTTrr0 MuzUVtzhs76EI6HeLR6Se4cIqhLOoCtj/KXKGoP5qe0FIkaOI24BfipLJd/rpOMY0AkZ 5qtrLov97IBEodundX81gKYvInHjoMErcxlNigyMN1SCYnK8erVdwwN5VgVWRccpqa9i S5jPYC299jcvUGprqUadbOWltauvjuYYUCHZO51IE3g7seb7HDDVRsriAjxPb05zVyoH zkNPmKWdSqHyqRyXy/n1CwOZNHkdeBkm31srEWTpU+87ynw1FzM3SX4NiLajgas7A2uz YMhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Bi5cxJDr; 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 w11-v6si4488297ply.404.2018.11.02.11.39.13; Fri, 02 Nov 2018 11:39:28 -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=Bi5cxJDr; 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 S1728743AbeKCDqP (ORCPT + 99 others); Fri, 2 Nov 2018 23:46:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbeKCDqP (ORCPT ); Fri, 2 Nov 2018 23:46:15 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 606292081B; Fri, 2 Nov 2018 18:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541183883; bh=LZcz+yqXtH28lUl6+zXhlAtswFCHlZVRbSrz5QNK05Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bi5cxJDrONARKj/yk/E4gvkyRS3MYsRfmcmoT4BdSib7huT6cR8uW61abj12adi8e PNVKJO0LnaBoBD5KAho3F8SvjOiNJQCZ0/U0p10vTkkYKbk9xhjxeGtHSwLl6LRc38 G/zkxcXCHkGFG0O3rsrbYxVTwDReYEbL7ionv5fk= 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.18 001/150] xfrm: Validate address prefix lengths in the xfrm selector. Date: Fri, 2 Nov 2018 19:32:43 +0100 Message-Id: <20181102182902.381247027@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@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.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 33878e6e0d0a..5151b3ebf068 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; @@ -1359,10 +1365,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