Received: by 10.223.185.111 with SMTP id b44csp913800wrg; Fri, 9 Mar 2018 16:43:24 -0800 (PST) X-Google-Smtp-Source: AG47ELu17823I/CVyw0V7QO5Z3rCJELsMez293LLdcPPY3D+Qu6wFCcaBzbT3I22FlAxCPChtVUc X-Received: by 10.101.78.139 with SMTP id b11mr298698pgs.229.1520642603937; Fri, 09 Mar 2018 16:43:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642603; cv=none; d=google.com; s=arc-20160816; b=D8RsCID35o5Ml6wgMikqQJMYFRcY1+HHf8K/0dkBxbb86pcdujxLFMWhVrFLZaukn8 IIgJRxivVpzEyFsaTKbuEzabUcUyynsN35WFpfm9v5PkLKpobBblAAFhYQhpYQkBzlKR 6qGBJgdclcK0aqTK6agtj89Dwv6/tK72uIZQwzhqzff1gV3mm1ZFL0k8/OkFOUsYrGkL sGJE5kEFBp789DuvjItXovhZRHPT5hMuw82KUAVc/363SrObIuCD9bGKXkTojIo2JCL6 j+ZTNGWw7+vQ19xb4pf+2n+YopVgLFHIk3SICHUi28WlnIATqwTfvqwC2B18qzpOEOyH B+CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=eU2qyRh8JiLw+69zsQ2cnj1xB7kFXRXxfV2Kh8MJZug=; b=dr0v+tcf6LES72GFulGEQjK1xqPoAOQTLk62GLhTmvLUeTnFN6E+ivFsywxRViEJO4 0uitbK1NzjEbkO/zQnz4Kew5eBd7fPTyhIF0Nawvwa/cgOiJe3VRWhsI+nL+nBQJz7PY 83Xopl6+RgL+If3lLCFRVcGjbVjWWeGw/EAhJzwPwz816y63LHGh+oxJEFII42VEI7ok z9+uD74B2fp+E85Hkjfy1vdhZ1U9Rrg8cQ1p4A65tk2KjfHchLuTh5n+9vYPx8Mk7OLe f2LdEvVbGGTnfyrvzsNNcUySnIzchwhRvmVmNs5HAB1d3ygM8G1R3VXqL+AQTLl8dA3F 1Aqw== ARC-Authentication-Results: i=1; mx.google.com; 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 k8si1521006pgc.472.2018.03.09.16.43.09; Fri, 09 Mar 2018 16:43:23 -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; 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 S933560AbeCJAU4 (ORCPT + 99 others); Fri, 9 Mar 2018 19:20:56 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39328 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933544AbeCJAUw (ORCPT ); Fri, 9 Mar 2018 19:20:52 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EE14C10C3; Sat, 10 Mar 2018 00:20:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "David S. Miller" , "Eric W. Biederman" , Dan Williams , Ben Hutchings Subject: [PATCH 4.4 33/36] mpls, nospec: Sanitize array index in mpls_label_ok() Date: Fri, 9 Mar 2018 16:18:49 -0800 Message-Id: <20180310001809.184616649@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001807.213987241@linuxfoundation.org> References: <20180310001807.213987241@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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. ------------------ From: Dan Williams commit 3968523f855050b8195134da951b87c20bd66130 upstream. mpls_label_ok() validates that the 'platform_label' array index from a userspace netlink message payload is valid. Under speculation the mpls_label_ok() result may not resolve in the CPU pipeline until after the index is used to access an array element. Sanitize the index to zero to prevent userspace-controlled arbitrary out-of-bounds speculation, a precursor for a speculative execution side channel vulnerability. Cc: "David S. Miller" Cc: Eric W. Biederman Signed-off-by: Dan Williams Signed-off-by: David S. Miller [bwh: Backported to 4.4: - mpls_label_ok() doesn't take an extack parameter - Drop change in mpls_getroute()] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- net/mpls/af_mpls.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -714,17 +715,20 @@ errout: return err; } -static bool mpls_label_ok(struct net *net, unsigned int index) +static bool mpls_label_ok(struct net *net, unsigned int *index) { + bool is_ok = true; + /* Reserved labels may not be set */ - if (index < MPLS_LABEL_FIRST_UNRESERVED) - return false; + if (*index < MPLS_LABEL_FIRST_UNRESERVED) + is_ok = false; /* The full 20 bit range may not be supported. */ - if (index >= net->mpls.platform_labels) - return false; + if (is_ok && *index >= net->mpls.platform_labels) + is_ok = false; - return true; + *index = array_index_nospec(*index, net->mpls.platform_labels); + return is_ok; } static int mpls_route_add(struct mpls_route_config *cfg) @@ -745,7 +749,7 @@ static int mpls_route_add(struct mpls_ro index = find_free_label(net); } - if (!mpls_label_ok(net, index)) + if (!mpls_label_ok(net, &index)) goto errout; /* Append makes no sense with mpls */ @@ -806,7 +810,7 @@ static int mpls_route_del(struct mpls_ro index = cfg->rc_label; - if (!mpls_label_ok(net, index)) + if (!mpls_label_ok(net, &index)) goto errout; mpls_route_update(net, index, NULL, &cfg->rc_nlinfo); @@ -1166,7 +1170,7 @@ static int rtm_to_route_config(struct sk goto errout; if (!mpls_label_ok(cfg->rc_nlinfo.nl_net, - cfg->rc_label)) + &cfg->rc_label)) goto errout; break; }