Received: by 10.213.65.68 with SMTP id h4csp877205imn; Tue, 27 Mar 2018 10:25:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx49m9mDWRMoWB841+O62GmZ+L2gRQvYy9gifl08DhYAEiSajbQO9K61qFkgc1SLB48+DMkbV X-Received: by 10.101.75.12 with SMTP id r12mr152814pgq.36.1522171503652; Tue, 27 Mar 2018 10:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522171503; cv=none; d=google.com; s=arc-20160816; b=WpYSpcy6ApC4jUgvJG8yd4zv8/xP7rk6T54PWkyARKAm7bTyimbOR/IF0AX6Y0OWkE s7EKMoh78CnN/zOTVyxdbCM+I9QKhKqXCprmRpBcMy7V2dvTgvwA4qc3aVX+CBNum5Hk B2f3UNYdN2s2MeKxJws/zgHviTk9vZUrNJIRjpPdIxBarrvVSFZ/XRCFcfIgrmEOm8Uy T5F8mmkNjHg9Xedlfcr9o59RNX68NF+cf8vFGMsCI/87ueKcCppDrPPo9oWrrQWNlt7C 08bVQl/oDp5fGvLGbT/7HNgjIjP063AP7dn2hCvwZXlMvzkSNPN821csob6sdVZyYO/9 BQbw== 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=tbnF4iUm2syYaw/IgRCr/gtrCeglyjrgUnAZBtNYmB4=; b=Mq6hzBNRlmBpHGrjTE9zMGlfpJSAvzqSH3WiP7iVPkNb5E61RSFx9gKIQ6JHjtcpR4 Y49i9KNNccm9LOagVN+UAZ/OEp+YoGjeUe82xmKOP1mNc1RbHPMBtwxtRBv7icKsoEdx N/sQ2O1tZcQQfX86bJ+fN5EABiC96P3qc7LvscetZLb4Ep+ZokbiHteP2CdeGz8L32g6 A18yiwMf4YcC4dOcoNK3LWOGSpD5MPKF8yequhRSCU055gYXbeW0NOMS0A20K7cRLAT7 2bs2cOdqeVWTnosXyYCLUUx8CuN/jqYahJZQWPOqmKTYGHxPW+FBHx6J4hW++rYBXW7E mqNw== 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 f5-v6si1492877plr.243.2018.03.27.10.24.49; Tue, 27 Mar 2018 10:25:03 -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; 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 S1754937AbeC0Qh2 (ORCPT + 99 others); Tue, 27 Mar 2018 12:37:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46270 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754591AbeC0Qh0 (ORCPT ); Tue, 27 Mar 2018 12:37:26 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 352E9F8E; Tue, 27 Mar 2018 16:37:26 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , "Peter Zijlstra (Intel)" , Dan Williams , Rasmus Villemoes , Linus Torvalds , David Woodhouse Subject: [PATCH 4.14 082/101] posix-timers: Protect posix clock array access against speculation Date: Tue, 27 Mar 2018 18:27:54 +0200 Message-Id: <20180327162755.088982907@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@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: Thomas Gleixner commit 19b558db12f9f4e45a22012bae7b4783e62224da upstream. The clockid argument of clockid_to_kclock() comes straight from user space via various syscalls and is used as index into the posix_clocks array. Protect it against spectre v1 array out of bounds speculation. Remove the redundant check for !posix_clock[id] as this is another source for speculation and does not provide any advantage over the return posix_clock[id] path which returns NULL in that case anyway. Signed-off-by: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) Acked-by: Dan Williams Cc: Rasmus Villemoes Cc: Greg KH Cc: stable@vger.kernel.org Cc: Linus Torvalds Cc: David Woodhouse Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1802151718320.1296@nanos.tec.linutronix.de Signed-off-by: Greg Kroah-Hartman --- kernel/time/posix-timers.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -50,6 +50,7 @@ #include #include #include +#include #include "timekeeping.h" #include "posix-timers.h" @@ -1346,11 +1347,15 @@ static const struct k_clock * const posi static const struct k_clock *clockid_to_kclock(const clockid_t id) { - if (id < 0) + clockid_t idx = id; + + if (id < 0) { return (id & CLOCKFD_MASK) == CLOCKFD ? &clock_posix_dynamic : &clock_posix_cpu; + } - if (id >= ARRAY_SIZE(posix_clocks) || !posix_clocks[id]) + if (id >= ARRAY_SIZE(posix_clocks)) return NULL; - return posix_clocks[id]; + + return posix_clocks[array_index_nospec(idx, ARRAY_SIZE(posix_clocks))]; }