Received: by 10.223.185.116 with SMTP id b49csp2121554wrg; Thu, 15 Feb 2018 06:56:32 -0800 (PST) X-Google-Smtp-Source: AH8x224NMn2JWUrIQUwlugAK+iNtY/YI593MeQ4cQWy7IJmoy7I05sj7NoOBPgDGpPIoT+8xw1za X-Received: by 10.99.189.82 with SMTP id d18mr2455968pgp.172.1518706592565; Thu, 15 Feb 2018 06:56:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518706592; cv=none; d=google.com; s=arc-20160816; b=gdh5TWb+VCPALgTmvyM3PnrLw54M+zaXBeFSquvmO1D9Od6jANDuRlL5hlQmLnmbbl z78j0ffnmqfcnFwwyarJ6Wa6+X83TREe2f9LCRxQyr+3yyzw3ktSXYWdwXdkNScqEvwQ 4qXapqNiLoCzctDiQ43RHZR1A4YEveKPcBRvoJuCwd5lb7UG9vQVn39c+d+witiYoICI /p1VD7NsXsIPh9P3JcbE9GoDXm26Qi7IEdEO6aAHpPKYP73ufQEnslBUxGZBKfUMtSY0 Z1XAxME4cOp1aNjOX//hunN7e3t7JS4CSNmlXD3Zr2khivyfXfWoinueAKrc9TRucx6j Yf4w== 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 :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=QA/Fek0Kb/xxmcSVDvWJqHvhrINp/p7yu08DvOsNvCA=; b=gyBudaJtKUwVWRHtteJ6kyBHEvLdctXkVX4v08k3wU1lmoVkCmUhRUWbLOjKNk6b9I cNoC0hYW6Xw7nVpAcQysLZOCywDA/NEBSh02DSbzqpt4z8nrv7qRf1PjBLbsYlUxvbrX c6X4jKiy1sKDuQDsxrz89oN/rYnDZhw8E2sZprBbh3mAqr4pL7t/tALT96LQDPHEg1vN f98AY/1xbe7RyHXnAHerJFwy5GAITzsbeLwBa1hCe9Hvtoq3KKnoAAagqnklQzVjFIVb zs7nMniMCOqc1gaJoQMFC6RRGPkJePOp4VV4ind+SntoBHrl+PPULezo3SQZfur9d5KN po9w== 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 q76si11464216pfj.189.2018.02.15.06.56.18; Thu, 15 Feb 2018 06:56:32 -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 S1033680AbeBOOyx (ORCPT + 99 others); Thu, 15 Feb 2018 09:54:53 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:54453 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033250AbeBOOxR (ORCPT ); Thu, 15 Feb 2018 09:53:17 -0500 Received: from p4fea5f09.dip0.t-ipconnect.de ([79.234.95.9] helo=nanos.glx-home) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1emKr7-0006sO-Fs; Thu, 15 Feb 2018 15:49:49 +0100 Date: Thu, 15 Feb 2018 15:53:14 +0100 (CET) From: Thomas Gleixner To: Dan Williams cc: Rasmus Villemoes , LKML , Ingo Molnar , Linus Torvalds , David Woodhouse , Greg KH Subject: Re: [PATCH] posix-timers: Protect posix clock array access against speculation In-Reply-To: Message-ID: References: <45f8dece-e235-0831-4fe5-89ee7d27b959@prevas.dk> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 15 Feb 2018, Dan Williams wrote: > On Thu, Feb 15, 2018 at 6:05 AM, Rasmus Villemoes > wrote: > > (2) The line "if (id >= ARRAY_SIZE(posix_clocks) || !posix_clocks[id])" > > still seems to allow speculatively accessing posix_clocks[id]. Is that > > ok, and even if so, wouldn't it be cleaner to elide the > > !posix_clocks[id] check and just return the NULL safely fetched from the > > array in the following line? > > Right, this looks broken. I would expect: Indeed. Missed that. > if (id >= ARRAY_SIZE(posix_clocks)) > return NULL; > idx = array_index_nospec(idx, ARRAY_SIZE(posix_clocks)); > if (!posix_clocks[idx]) > return NULL; > return posix_clocks[idx]; The !posix_clocks[idx] check is pointless and always was. if (id >= ARRAY_SIZE(posix_clocks)) return NULL; idx = array_index_nospec(idx, ARRAY_SIZE(posix_clocks)); return posix_clocks[idx]; is sufficient. It returns NULL for !posix_clocks[idx] anyway. Thanks, tglx