Received: by 10.213.65.68 with SMTP id h4csp849178imn; Tue, 27 Mar 2018 09:54:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+MPWJwuma/ugKDDJNr0dzfZQ4i9qIVZwFVst/qYwYL/4AqKZq/v6ft8tznRQ8QODKPuZXU X-Received: by 2002:a17:902:2be4:: with SMTP id l91-v6mr122949plb.102.1522169697307; Tue, 27 Mar 2018 09:54:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522169697; cv=none; d=google.com; s=arc-20160816; b=hr9Qacqziz8xFJYXJbQ32iAzgJPqYKBTSLqmdU5c0yuxdSGbG+Ya5r5FLj3ToV4rA7 Y2sTMlrSVT55oyZxjaltuH1iItdkAxNnNQxoWgh8rDFRT1tCby+ZP34sYZ0/+TEJiH+k FOjpuUMCGQ1PNZD+5LyfChqC3qJBSAF27nbr15O31BCl5tEm1SbTstTw4TpQZZO0YaaY CShD+LSQDSs68K28GM9aleYSO5Bhrf5H1vbB2lFhIafBfjoxgwQzwkoTm7F6OFQTqWqh C3B4Op7FYV/NVc+JCFzIiMmtFjDGZEsChLmWnVtQEo2lm8EJBa1K4Q5gt8UUoUNkpZw5 0H2Q== 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=57gBCyflZR5udfwQscPVvdhSue56uBWXZPVpFWnsuyU=; b=JWunXq7nACS9lLtWy9SVnVsccg5RRPKDIj7fPRdXVBbzbT0zS4XTaV6vScE5ugFll+ eej6ES3gPReDAqWD6NSFonlo1NwPZnJI99MXpXIQoeJdoIOHYlAGPlOuOhZ+u6VGOkxi V+8FzNN3r5HY1PFyZV2ZyAGlNR8kFOAESQGr0BwnojGha6v/9LCQhPbICKWdyQRHZ3bf XYlQ+7Ejx2G9gAhFp+39UcU+mOrwk7rVfsYOGBzbMQMS789Oo0ps8rHWbvIPxNq+1gBJ ngs01tyShhQIE0SG6GYlSTDyPHfyHbxVHQnqmiKo+ZTOReB06tilT8tbweakLskfgPbY QY1A== 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 t28si1205032pfk.187.2018.03.27.09.54.42; Tue, 27 Mar 2018 09:54:57 -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 S1752985AbeC0QwF (ORCPT + 99 others); Tue, 27 Mar 2018 12:52:05 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49028 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755353AbeC0QmW (ORCPT ); Tue, 27 Mar 2018 12:42:22 -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 05C71FB6; Tue, 27 Mar 2018 16:42:20 +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.15 087/105] posix-timers: Protect posix clock array access against speculation Date: Tue, 27 Mar 2018 18:28:07 +0200 Message-Id: <20180327162803.562069125@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162757.813009222@linuxfoundation.org> References: <20180327162757.813009222@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.15-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))]; }