Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2366325imm; Mon, 28 May 2018 06:50:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZocuFnQe6lvMLyC/mG2XmoMIUrSBlGqKpMIFpuOF2XA3i8b6Bk96Je+xcu6e12ksZ9RP080 X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr13583951plt.378.1527515400673; Mon, 28 May 2018 06:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527515400; cv=none; d=google.com; s=arc-20160816; b=uuuqtWAFPmiZh7V+AqOtUJHPR8YePRsZD9VAZFHwKTyvN44G/FlYkHGDtiGngRleW/ ArO4L7dc2xbm9Gs4/+c64gKGbLt7WUvClm2LSOPD8epwQ+1gtGGgYItuk2b0eioVplXg gUN3kXM2Rr6IJw35vEWpAzEyr/Nv/mOiEay6TjXcCGq7RPqJzwXHwyne5Ugqoayqvbf4 EuscbDzUnCCGcr3MDnSyXQlt9DLX+YvxGInQz49dxGoIQla7BcmBCK96CdihmNspGXIv ws/kDWBy/WpWao0m7ciEEobRyoBYIw9LvvYmnfAlYDS40jGf5REjC7xxXCQ32Bvp64h7 CaZQ== 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:dkim-signature :arc-authentication-results; bh=4mtcNSY0w3eOectD2ECEu22N1yDtRFfVono9qOYRIZ4=; b=JQ4ayfzIfjrGDGlsPPtLHRvu0itfyzTfK4YWACt2piUInoe2m+i7j33JhsIEJ6mflI dxkEjDtqrGkzW3mCxkqPc3Wx9aehE3yq52RH7r2YbJJutYfJKYrEsqwy80OMWGthBtA6 CoRJIGNRcpoJSkdDEaYjWmVbva2WH7mS0YXycBvlNGKTFVHYFo0adKV0vQo7lYXwOZzw KZSqgoUgwHBTzfM6AOuOGuwXtgwGCOwq5C0SgYI0ngez16wnEThS5ld1JgjcEZneteL0 3+RcZCA2Pyah2/xgUcP0LTP5/ntsQU8xE9TGDzRvm+rmwzwRjKB2jOh7PVy7f+Da0cFa 0UJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eTUN+y51; 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 33-v6si28444754plo.505.2018.05.28.06.49.46; Mon, 28 May 2018 06:50:00 -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=eTUN+y51; 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 S937489AbeE1Kma (ORCPT + 99 others); Mon, 28 May 2018 06:42:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:33672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937459AbeE1KmV (ORCPT ); Mon, 28 May 2018 06:42:21 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 1170B208A2; Mon, 28 May 2018 10:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504140; bh=vb0HjzkXmk76Pd0EaFwESGWvdo9rKUX6Hfls04yCzt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eTUN+y51OJ00MDsxsBTNrreDmDZS2yL497+SNEgutmaXHzI2Oy3aJ2Zm3aHpvJfmi IMOFVKmU3aYCod3BaivUIJABkx475Ii0nr1g+xwKMsxcIRs0587PVv5vtmGJq1yVRR X0AlEsqwBwE+ejAqCohaHM80qp0uYXbxU/pVNJ4k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Andrew Morton , Alexei Starovoitov , Dan Williams , Thomas Gleixner , Peter Zijlstra , Linus Torvalds Subject: [PATCH 4.14 028/496] kernel/sys.c: fix potential Spectre v1 issue Date: Mon, 28 May 2018 11:56:53 +0200 Message-Id: <20180528100320.773847829@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gustavo A. R. Silva commit 23d6aef74da86a33fa6bb75f79565e0a16ee97c2 upstream. `resource' can be controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: kernel/sys.c:1474 __do_compat_sys_old_getrlimit() warn: potential spectre issue 'get_current()->signal->rlim' (local cap) kernel/sys.c:1455 __do_sys_old_getrlimit() warn: potential spectre issue 'get_current()->signal->rlim' (local cap) Fix this by sanitizing *resource* before using it to index current->signal->rlim Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Link: http://lkml.kernel.org/r/20180515030038.GA11822@embeddedor.com Signed-off-by: Gustavo A. R. Silva Reviewed-by: Andrew Morton Cc: Alexei Starovoitov Cc: Dan Williams Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/sys.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1395,6 +1395,7 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned if (resource >= RLIM_NLIMITS) return -EINVAL; + resource = array_index_nospec(resource, RLIM_NLIMITS); task_lock(current->group_leader); x = current->signal->rlim[resource]; task_unlock(current->group_leader); @@ -1414,6 +1415,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, un if (resource >= RLIM_NLIMITS) return -EINVAL; + resource = array_index_nospec(resource, RLIM_NLIMITS); task_lock(current->group_leader); r = current->signal->rlim[resource]; task_unlock(current->group_leader);