Received: by 10.223.185.111 with SMTP id b44csp905128wrg; Fri, 9 Mar 2018 16:30:06 -0800 (PST) X-Google-Smtp-Source: AG47ELsFltSlS5h1xKpBnXysrlU9GYv+t7L8cGUatbSi1vGNyxbosEYecOhA6iRPMiyvC6k4WOWx X-Received: by 10.98.21.200 with SMTP id 191mr336831pfv.166.1520641806577; Fri, 09 Mar 2018 16:30:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520641806; cv=none; d=google.com; s=arc-20160816; b=C24fh5rCWldtDNzAVQVY9jic5GIs7J+ApyI4gAgdfXwwLqsFO9tMXgP7Y8aWEKjw5V uPa2zYIp3D9OSMtkPhm/eWBLPzFjybMLWCQ16iKMjEQDOEg0AB+4fMGHRfJsVY5502oC SrtKdMR/4HnRVy2Lpkf+Xi71rjt35Vb1puv+PEDY25lzDw4p3ReZ3hDvV+HyQMox2cyw QLYd5HeyxuVwvV3uPTxI8/t1wURh4QZX/WZpr8wRS5VbsXGWua7/MUZydLCP4HwkW3P2 ikaWsxkv8DB0v98hgGo5cEw+65anMM1P5Awr1seiGvGTqB6TEJwZT7hVE7M3vN2JPMMI qTAQ== 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=XxQx6UPkQ4yctrZcITXbzzQaq+LoJQXns4giOxS/4XE=; b=z2kYY4plMYSTJSOLz/ls8r1AB0MoezP7Fnu+JgnuD0vUagpVkTxhi9a2h8HdxUasPL BPn4aHWNlG8UXUSZn7YXbwnJIOcEgabFnEXzDYeGC6aIPzk4k+WPurG4+s7Cp1RQjVcO LdM/MupsFNdlkhFWrz1OBbwerPp5b+I3YBisC3D1m5xuZ+1Vci0viDGnB6t34QTBzPM1 y02wS+0DqFSe+ylX9bXMYu0GyxkLqbBPFBLpia30s4Q1osZculFxm/FTteq0X8AdnAkE t/SJsrgEBFFk2ruHpz8Lvu+O8vNvbmwHNigwFKV9xHn59OzI1kzQt2LbrmN88IFrSiPt aXzA== 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 94-v6si1730567ple.694.2018.03.09.16.29.51; Fri, 09 Mar 2018 16:30:06 -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 S934052AbeCJAXP (ORCPT + 99 others); Fri, 9 Mar 2018 19:23:15 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40378 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbeCJAXN (ORCPT ); Fri, 9 Mar 2018 19:23:13 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A9B5911A9; Sat, 10 Mar 2018 00:23:12 +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.9 58/65] mpls, nospec: Sanitize array index in mpls_label_ok() Date: Fri, 9 Mar 2018 16:18:58 -0800 Message-Id: <20180310001829.895424321@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@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.9-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 @@ -756,17 +757,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) @@ -787,7 +791,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 */ @@ -848,7 +852,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); @@ -1283,7 +1287,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; }