Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp597436pxu; Thu, 15 Oct 2020 11:30:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkjExoltgL8J1AdzsDxsyBGbwDpuD3imxJnNftRwPZqWRhSbYXYeVTp9DPi4FNDEDCjezt X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr5900250edu.156.1602786615995; Thu, 15 Oct 2020 11:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602786615; cv=none; d=google.com; s=arc-20160816; b=x6/ycQQUjEo3cwveyihtkFULP3YChXT6p42eUvucyipL0mu/GbKjhMb7B/3JbxIQ+Q QgK2vrQF//e6Zlxgim27k9U4BgYLbiNmJMKSnsPsvV+6e5PJJXdqwFraLRpyKn7+V3qL b2H/KFPC7hIKw8ZLTZBe1SxVTrv0kP1MafyZdoCiVkAwpoH6nh9SWLUabJlzUjXH3IB0 drrczyilKtNm7iXsYF7/36+nE5+7o8oN7Gg/IPHjJkQGj74DrGWlfVh/M39jz7TfS80I RWZ+6LFVX8u1fDUpsIZSWES5DFjbI91+Cosbzq/VgGtdmObLINaeFkM3yyN3N6RSJGh8 z7ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=XWjeAwSwJUB4odQ/5eOsa55JFw248FhKheVyetCUznE=; b=xG1isXj0pPRra9/HW3IHNIOw6cDf30EEcvwZVi4I8D9hUcwEkVcnYWF5sSfXtYVdvg ynAgXiuA6e6blIT0HDGkPb6WyxmmNvQ2ZKKYmQtjPUj/IbqaeMdKkXh68jphz8aRG5Qz ZhdjzsPSu9qW3amfGGaIOQeZ+y8cij35OQfN+vNRdQ7cnazo1rv6ZobUGOvYYjhCCtxa FR62++bGbLLLweoLnniFOnh6dFKYzPdo04Y5B6wnw7AfxJCa+i9SEfOPDD0clmT9RVVQ e51AI6E8lwcyfiIvApu8k+QnA6SB9iUW7LPkGqymU06WFInJ6IQyuUwTCEFtGyGsGGO/ CcwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KDzaud37; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz16si2659169ejc.325.2020.10.15.11.29.45; Thu, 15 Oct 2020 11:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KDzaud37; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388773AbgJOQAm (ORCPT + 99 others); Thu, 15 Oct 2020 12:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388393AbgJOQAl (ORCPT ); Thu, 15 Oct 2020 12:00:41 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4831C061755; Thu, 15 Oct 2020 09:00:41 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id y14so2155342pgf.12; Thu, 15 Oct 2020 09:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=XWjeAwSwJUB4odQ/5eOsa55JFw248FhKheVyetCUznE=; b=KDzaud37AeZ7EnsiAUPFvKVuyDGeZo3s4QeIstQAQs3yqxVYuRAHhtFV7u5vdmoi6I 2J3mFrIhSCok2XSvyWOSlQSN167RnlPfp78PQZTthfdH86i05Ccprk3SCwdnDkfUO15Z MFor+el37FtaBbM3j3hXWb0kYCGwC79s4dZJdpoq0teQnL14WwJ4aJO8D+/ywf0rbgZk GplQuqTFXY2at6UmONUXRvJZCzgCZQQLIg1HghVrZFKcQEAliz1DBA/5QXn30qB/FQ1u xxpwHJLntzeFxFzUPfshZEjufRG2QTKp5zykcNZHNwheFE9OQruEFb+uXR9uuMu8U6BE x8kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XWjeAwSwJUB4odQ/5eOsa55JFw248FhKheVyetCUznE=; b=QIdCRNNSe1QH3IuzlLQPbxQSsHS9q6B6Gq0wUf+C/DHys/lMM/ZrTUO/sNmmYnaOh+ o92stJJJ4/RKvprRFP+DH7PDyHC/MZ1n2csbNVnkbCSFU7i3G3JSdcHZiHj+HAfzMK+l FM9V5BcPKRyc154ycUWeooQ3rqzFU7okpqRiutGDRvB1TyBpMNq7nmJIkmuem3S5fSWH aHCzXL2TMZgkht/RNZvLMeMsUxqmeQH7vfXxoEIPCQuzNtHMYmvIoUzHSqvqIj0hDCsV LtwXoPzD5GWbKBSxZbDPMOpgM49/O7VyHuRq3hcC0CFvw6Rvw5CQJEjdP6zKGgnbp+dW mkMw== X-Gm-Message-State: AOAM530KVkm3Usr+hOps5aQpvzHpWOvB3FSaiaYYSLV0kSExO1xC4cwI HysFKH+R3FCheOH5OcscwIQ= X-Received: by 2002:a63:5fca:: with SMTP id t193mr3794243pgb.261.1602777640967; Thu, 15 Oct 2020 09:00:40 -0700 (PDT) Received: from laptop.hsd1.wa.comcast.net ([2601:600:9b7f:872e:a655:30fb:7373:c762]) by smtp.gmail.com with ESMTPSA id q24sm3664414pgb.12.2020.10.15.09.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 09:00:40 -0700 (PDT) From: Andrei Vagin To: Thomas Gleixner , linux-kernel@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Darren Hart , Dmitry Safonov <0x7f454c46@gmail.com>, Shuah Khan , Andrei Vagin , stable@vger.kernel.org Subject: [PATCH 1/2 v2] futex: adjust a futex timeout with a per-timens offset Date: Thu, 15 Oct 2020 09:00:19 -0700 Message-Id: <20201015160020.293748-1-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For all commands except FUTEX_WAIT, timeout is interpreted as an absolute value. This absolute value is inside the task's time namespace and has to be converted to the host's time. Cc: Fixes: 5a590f35add9 ("posix-clocks: Wire up clock_gettime() with timens offsets") Reported-by: Hans van der Laan Signed-off-by: Andrei Vagin --- v2: * check FUTEX_CLOCK_REALTIME properly * fix futex_time32 too kernel/futex.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/futex.c b/kernel/futex.c index a5876694a60e..32056d2d4171 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, t = timespec64_to_ktime(ts); if (cmd == FUTEX_WAIT) t = ktime_add_safe(ktime_get(), t); + else if (!(op & FUTEX_CLOCK_REALTIME)) + t = timens_ktime_to_host(CLOCK_MONOTONIC, t); tp = &t; } /* @@ -3989,6 +3992,8 @@ SYSCALL_DEFINE6(futex_time32, u32 __user *, uaddr, int, op, u32, val, t = timespec64_to_ktime(ts); if (cmd == FUTEX_WAIT) t = ktime_add_safe(ktime_get(), t); + else if (!(op & FUTEX_CLOCK_REALTIME)) + t = timens_ktime_to_host(CLOCK_MONOTONIC, t); tp = &t; } if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE || -- 2.26.2