Received: by 10.192.165.148 with SMTP id m20csp523149imm; Wed, 25 Apr 2018 03:37:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+220uoJdL6w/Kj2u50wux3G/NwCn66L9MOfWmSMUBcKVIulP2Kp9Dl5wzKY1MjX/q6GxrI X-Received: by 10.99.140.14 with SMTP id m14mr23642450pgd.320.1524652647552; Wed, 25 Apr 2018 03:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524652647; cv=none; d=google.com; s=arc-20160816; b=B6T44mSMO94COqvceKHrQZzfOh2UtZK7K3egG0h4U3Gp7UzI5HVvRNX/+1zZobpOcL C5badJXdh3jUaxd14WnF+k1iQFG/iAC8B4z2w5YWOg/Pic1xUGVWnRenyua3Fsh2oZzt QsVRG9jObDDSEL9p0HDCKRKhPfeGzT5Szdj/lQarLmt47iUVvJtG+STKMHmhHwUAdFp8 8jhWn5weGHYD49TmiWLwVu+p1pm4EPDD1sm97rgSTWbPcytfjlBVJdgLpLAoGYsD5Yiy Ftxr9Is77F/lqA1IWMD1npNaw7sMNzdCu9OmvLe3hsqwyQmpnIuXkscX4YN7ifmQVdwt SBwQ== 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=PWNOQUuyOfK7mRSjXe/UBqmu2XYWe7awAF0rvnn61TQ=; b=I5/1ZHth2QQpcGZp5SZafyYkA7rxltFGdtRa/ANeEAlEcw4e4w78wWPB0uhUV7OP9n lIZr+4LpQ7f6espBZFfFpC8suQkAlKxTgqVvuo9urTjuee2UXfRVyDnyzdf+T33fTJje fxYGv34kE7qHsAR03rlYbSTzCeUBtM+H6vA2dEKaGbxO0Ptp6q16HpvDz0WuTb4OIgwB Kt0fP6QUTjeicnPWNhnVMahtZqAULZhLeW3IacQDc23yxS2zkmG+FjSdE04tYQWuLoP1 CtttRLJ3jiQEjRrGfbL86UOpUjH08c0BJos7nrTqAqA6JdRW6Juj46zyiHSMd9AWLLMf 8UYw== 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 h3-v6si16220335pld.137.2018.04.25.03.37.12; Wed, 25 Apr 2018 03:37:27 -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 S1753056AbeDYKfj (ORCPT + 99 others); Wed, 25 Apr 2018 06:35:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50976 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752895AbeDYKez (ORCPT ); Wed, 25 Apr 2018 06:34:55 -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 097F14A3; Wed, 25 Apr 2018 10:34:53 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laura Abbott , Thomas Gleixner , "Max R . P . Grossmann" , John Stultz Subject: [PATCH 4.16 07/26] posix-cpu-timers: Ensure set_process_cpu_timer is always evaluated Date: Wed, 25 Apr 2018 12:33:16 +0200 Message-Id: <20180425103315.145805470@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103314.842517924@linuxfoundation.org> References: <20180425103314.842517924@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Laura Abbott commit c3bca5d450b620dd3d36e14b5e1f43639fd47d6b upstream. 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 Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Cc: "Max R . P . Grossmann" Cc: John Stultz Link: https://lkml.kernel.org/r/20180417215742.2521-1-labbott@redhat.com Signed-off-by: Greg Kroah-Hartman --- kernel/time/posix-cpu-timers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -1205,10 +1205,12 @@ void set_process_cpu_timer(struct task_s 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