Received: by 10.192.165.156 with SMTP id m28csp566604imm; Thu, 19 Apr 2018 04:01:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx49DoG/rOEhou1EbMB1ok+tefPUXf5jnzI8/CkOzZvUGiKF0A2AN9qtPfuDLyfUst8jMn2eH X-Received: by 10.98.64.91 with SMTP id n88mr5420222pfa.229.1524135671133; Thu, 19 Apr 2018 04:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524135671; cv=none; d=google.com; s=arc-20160816; b=ZVm2rAPmlJeDzfdRCTHUEpc8LaIUxh3+v9OgwlHkNZHVnUuXcWD9dH5JAlAqA4EeOy Pc9vvYw+PhTB/R9NceQlYIlAjkZczuc2A8A0Xe0dWRxAe775berPEpfWmX9RXCOIbYJQ i+SVttntcvchOA8e3cBn/ukphQv6i+4x4IFWpopwHk/8zsL7TYvzU/1QWgS5nwH8uhIZ 8yYcWYmTLHdTrac/J8bg9z3asYAMfQiFZI765j3Jilv5l38znwBwRZOWbNH8u3IyYVh3 elYU/g8QPG/7E/m9HXiFglrdHK5e6+K8pch7XHhnXro+K9b0lCwMXdtt4/pSUsLZYXJg ABSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=kN0sHQi9Fq+QYFLD2v/e6EpriqXRoEjD7Co4ZNGvmN8=; b=mgGikEPbA1kIPXabjWj/EEFsuC9kR+QqNqBPca9Iw1psBIpbPOmqHmggtIkAKjKmg2 SMBEvemskmzXLKdM+UCyn9fUkyMryFg811kQLSM7XvDkHKeOJ/q4Gduun8ZlvNOXUXoU 6dasivKOnQr9G7egme6TSE9S9bKCxjxHcq5X433K3+gsuIE0YEK6jyHd9o8xx3L7wb89 BqGgm5GmfoNffZ7ZAC1C8vku3cPdhZ9ZK9k7IucbCxcpHlOu7K7ZwHllsPyff4J/MD7E fAmWRnkDBN+JmArWIfL0tJumBVWmbfky6aBsMANpTifCY7Y8kUp0TWytxk+fseCyL+Wk xbiw== 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 ay8-v6si3439643plb.244.2018.04.19.04.00.56; Thu, 19 Apr 2018 04:01:11 -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 S1752783AbeDSK7i (ORCPT + 99 others); Thu, 19 Apr 2018 06:59:38 -0400 Received: from terminus.zytor.com ([198.137.202.136]:36453 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752695AbeDSK7O (ORCPT ); Thu, 19 Apr 2018 06:59:14 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3JAwuB91697084; Thu, 19 Apr 2018 03:58:56 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3JAwuLE1697081; Thu, 19 Apr 2018 03:58:56 -0700 Date: Thu, 19 Apr 2018 03:58:56 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Laura Abbott Message-ID: Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, labbott@redhat.com, m@max.pm, tglx@linutronix.de, mingo@kernel.org, john.stultz@linaro.org Reply-To: hpa@zytor.com, linux-kernel@vger.kernel.org, labbott@redhat.com, m@max.pm, tglx@linutronix.de, mingo@kernel.org, john.stultz@linaro.org In-Reply-To: <20180417215742.2521-1-labbott@redhat.com> References: <20180417215742.2521-1-labbott@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/urgent] posix-cpu-timers: Ensure set_process_cpu_timer is always evaluated Git-Commit-ID: c3bca5d450b620dd3d36e14b5e1f43639fd47d6b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: c3bca5d450b620dd3d36e14b5e1f43639fd47d6b Gitweb: https://git.kernel.org/tip/c3bca5d450b620dd3d36e14b5e1f43639fd47d6b Author: Laura Abbott AuthorDate: Tue, 17 Apr 2018 14:57:42 -0700 Committer: Thomas Gleixner CommitDate: Thu, 19 Apr 2018 12:54:57 +0200 posix-cpu-timers: Ensure set_process_cpu_timer is always evaluated 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 --- 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 2541bd89f20e..5a6251ac6f7a 100644 --- 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_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