Received: by 10.192.165.156 with SMTP id m28csp543463imm; Tue, 17 Apr 2018 14:59:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx48qcVELNi9x4dSM+QcYpzNirI4F/469BrsPvB7UIkzUHTN+icDnlkzu9jn5cWP6tqvMyidb X-Received: by 10.99.38.66 with SMTP id m63mr3174387pgm.164.1524002350594; Tue, 17 Apr 2018 14:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524002350; cv=none; d=google.com; s=arc-20160816; b=qaO0GDPJPmlHr+qcRJvBfNsOaNtY7zruCp0nPl4AtdwPdwmtENWS6ELzJkC2cxPmYB fYEMVJXCUsDNojxKhnqSz99Yr2wqL400fy1/xJmPZMIDouFAbUIdrgA1n3C+408l9jlH tyIXFj45GFDiI/jUW3Vc9TjLMLz+YvbW+Y2FvkL4C48YKYws6FFpeiq6ccIYhymTiDnu pWYLodelqo/j15YNxlAoBesTSRMwZSlLqNBB24KWsp2s9s5TrE/kFZnOLNPRnIOZhuDN tEduh1eQ9DjB/VUr7TdpffYRQzZLXwS/SohKqaDrCp/PZkF8pyP/uvLp5AjkoPHcMtY+ Ba3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LVVMLjP/3egclZgBouU1wBm3I88p5Zl3JQQPpkvpucE=; b=TZ/OwgH5DjW3MrXw1VQknCMSnKtCEFMmM+rPE/plPJh6z0DdfNpJ/1/rIYUMzHzEFk bmIBmB9o0tiwyUpPGcwuGIeUYiE5KEM9k/clpo9Gj2a/zzU0p4O1cnKOdfYsvYrhBNr6 yZRJLIzFDD6/y6U38N4dAYjvfshpEWktVsoC6SXkRQ4Vv9eDUkl7gHNELQdKx3KEpsVv H9RkGVibwbv1fEJwXZI4a5vtXsEgwMxP/JbLkEuzfl/kklUB9rVAG8wS1rB35i10HBR0 XevLUg5jSv8nF2lqm4RQCPmRmVj20pMRYjpgtDNdnEJHkC+g4oj4vo9s2tX6FOgyBED9 LAAQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r59-v6si15227903plb.218.2018.04.17.14.58.56; Tue, 17 Apr 2018 14:59:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753031AbeDQV5s (ORCPT + 99 others); Tue, 17 Apr 2018 17:57:48 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38586 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752606AbeDQV5q (ORCPT ); Tue, 17 Apr 2018 17:57:46 -0400 Received: by mail-pf0-f195.google.com with SMTP id y69so12791304pfb.5 for ; Tue, 17 Apr 2018 14:57:46 -0700 (PDT) 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=LVVMLjP/3egclZgBouU1wBm3I88p5Zl3JQQPpkvpucE=; b=qDOPL8CVX1aNFgYUrudSx8r3CNDTXeygRGLQNzjmmKGTDktgWXNPoXIIKBEEQoLzyV FQQ+mWXWhpDhpkO5DH8cLBsrwmTzZiBy0AzgwYbAkK3A8D8QhIJHFiQtFgSV9n/us4LE XoZfTpZe8Z/xGjtubS6GLDasEy7dP8q4vtvIGhelzgeW9Ct95oAcgK5HaZuKLj/djIT+ zalqhRXMMijV9ddt2omR906rYommqeVp9mm9m5H8zIfTGB2AaAODAR2rmwiQCO3BRR6O qIfkphkdK423Hu8G3LMtiKXIymGBinUdaxR4AgTWx49LQQpvGlpdMFfRlC4GavmteBCU Synw== X-Gm-Message-State: ALQs6tDJ6WgRwxfRJQ7ZbW7dF23P8VxScrmJtCpUH4V0veq99X69U/vG yi9dKtzDZgrIB7ZVlOz4+USgfQ== X-Received: by 10.101.74.69 with SMTP id a5mr3232092pgu.32.1524002266114; Tue, 17 Apr 2018 14:57:46 -0700 (PDT) Received: from localhost.net ([2601:602:9802:a8dc::4dc5]) by smtp.gmail.com with ESMTPSA id b64sm29357402pgc.23.2018.04.17.14.57.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Apr 2018 14:57:45 -0700 (PDT) From: Laura Abbott To: "Max R . P . Grossmann" , Thomas Gleixner Cc: Laura Abbott , John Stultz , linux-kernel@vger.kernel.org Subject: [PATCH] posix-cpu-timers: Ensure set_process_cpu_timer is always evaluated Date: Tue, 17 Apr 2018 14:57:42 -0700 Message-Id: <20180417215742.2521-1-labbott@redhat.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit a9445e47d897 ("posix-cpu-timers: Make set_process_cpu_timer() more robust") moved the check into the 'if' statement. Unfortunately, it did so on the right side of an && which means that it may get short circuited and never evaluated. This is easily reproduced with: $ cat loop.c void main() { struct rlimit res; /* set the CPU time limit */ getrlimit(RLIMIT_CPU,&res); res.rlim_cur = 2; res.rlim_max = 2; setrlimit(RLIMIT_CPU,&res); while (1); } Which will hang forever instead of being killed. Fix this by pulling the evaluation out of the if statement but checking the return value instead. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1568337 Fixes: a9445e47d897 ("posix-cpu-timers: Make set_process_cpu_timer() more robust") Signed-off-by: Laura Abbott --- kernel/time/posix-cpu-timers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index ec9f5da6f163..9cfa7f907654 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -1187,10 +1187,12 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, u64 *newval, u64 *oldval) { u64 now; + int ret; WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED); + ret = cpu_timer_sample_group(clock_idx, tsk, &now); - if (oldval && cpu_timer_sample_group(clock_idx, tsk, &now) != -EINVAL) { + if (oldval && ret != -EINVAL) { /* * We are setting itimer. The *oldval is absolute and we update * it to be relative, *newval argument is relative and we update -- 2.17.0