From patchwork Wed Jul 30 12:14:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 34517 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f71.google.com (mail-oi0-f71.google.com [209.85.218.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AFC5D20792 for ; Wed, 30 Jul 2014 12:29:21 +0000 (UTC) Received: by mail-oi0-f71.google.com with SMTP id e131sf5171407oig.6 for ; Wed, 30 Jul 2014 05:29:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=GP13CvsIn9CoaKsV9ckWywWfEzun+yogY2DgrvmTlno=; b=A4Jyw5MwgfGvbQzrf+MfFXng+T9eozBYy7eV8M7ScCuGGOkhYavekzBFh/2F/PxjZG OIG8UmnYY19nieIxH6pMIEua/d5DS8HS/Ri4TGz+m0tYw1AlfDfRGXqGn1az9OaqY8pM PEsrYfnKFyVjfz9IPi0NmyEzdY2fyS2Y3l8RPRLSF99J8Rw9z1SmVkTaoUdla+2m4U5M EC6Q7wweJ1cUySUi3oviLKPU+R6vQ1IAGjPiYkPiW5S5sKSY9QgSx3Je0PlFp/5FBu24 +WwTUAU4W6XafZ1aLsh/1SqZ9rx0Oet4IzYHf9P4SQopEe5kodTZI0ZbQbbTrzv8TUSp 3PlA== X-Gm-Message-State: ALoCoQnQsmkmzTrHEQ6TO3YVvPkguQaExqAlIvBLsw19L/tGfBP+P/Ey0mLPrrTppun0K/pLW9Li X-Received: by 10.50.73.168 with SMTP id m8mr16357870igv.7.1406723360193; Wed, 30 Jul 2014 05:29:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.193 with SMTP id i59ls502854qge.20.gmail; Wed, 30 Jul 2014 05:29:20 -0700 (PDT) X-Received: by 10.52.231.226 with SMTP id tj2mr7387836vdc.16.1406723360106; Wed, 30 Jul 2014 05:29:20 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id cl2si1431989vcb.98.2014.07.30.05.29.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 05:29:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so1615675vcb.33 for ; Wed, 30 Jul 2014 05:29:20 -0700 (PDT) X-Received: by 10.52.129.165 with SMTP id nx5mr7284763vdb.25.1406723360019; Wed, 30 Jul 2014 05:29:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp23500vcb; Wed, 30 Jul 2014 05:29:19 -0700 (PDT) X-Received: by 10.68.106.194 with SMTP id gw2mr4181777pbb.85.1406723358890; Wed, 30 Jul 2014 05:29:18 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r2si1125543pdm.327.2014.07.30.05.29.18 for ; Wed, 30 Jul 2014 05:29:18 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754919AbaG3M3R (ORCPT + 26 others); Wed, 30 Jul 2014 08:29:17 -0400 Received: from ip4-83-240-18-248.cust.nbox.cz ([83.240.18.248]:36755 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752947AbaG3MPd (ORCPT ); Wed, 30 Jul 2014 08:15:33 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.83) (envelope-from ) id 1XCSn5-00045T-F4; Wed, 30 Jul 2014 14:15:31 +0200 From: Jiri Slaby To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, John Stultz , Thomas Gleixner , Ingo Molnar , Prarit Bhargava , Sharvil Nanavati , Jiri Slaby Subject: [PATCH 3.12 66/94] alarmtimer: Fix bug where relative alarm timers were treated as absolute Date: Wed, 30 Jul 2014 14:14:55 +0200 Message-Id: X-Mailer: git-send-email 2.0.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linux-kernel-owner@vger.kernel.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: John Stultz 3.12-stable review patch. If anyone has any objections, please let me know. =============== commit 16927776ae757d0d132bdbfabbfe2c498342bd59 upstream. Sharvil noticed with the posix timer_settime interface, using the CLOCK_REALTIME_ALARM or CLOCK_BOOTTIME_ALARM clockid, if the users tried to specify a relative time timer, it would incorrectly be treated as absolute regardless of the state of the flags argument. This patch corrects this, properly checking the absolute/relative flag, as well as adds further error checking that no invalid flag bits are set. Reported-by: Sharvil Nanavati Signed-off-by: John Stultz Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Prarit Bhargava Cc: Sharvil Nanavati Link: http://lkml.kernel.org/r/1404767171-6902-1-git-send-email-john.stultz@linaro.org Signed-off-by: Thomas Gleixner Signed-off-by: Jiri Slaby --- kernel/time/alarmtimer.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 88c9c65a430d..fe75444ae7ec 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -585,9 +585,14 @@ static int alarm_timer_set(struct k_itimer *timr, int flags, struct itimerspec *new_setting, struct itimerspec *old_setting) { + ktime_t exp; + if (!rtcdev) return -ENOTSUPP; + if (flags & ~TIMER_ABSTIME) + return -EINVAL; + if (old_setting) alarm_timer_get(timr, old_setting); @@ -597,8 +602,16 @@ static int alarm_timer_set(struct k_itimer *timr, int flags, /* start the timer */ timr->it.alarm.interval = timespec_to_ktime(new_setting->it_interval); - alarm_start(&timr->it.alarm.alarmtimer, - timespec_to_ktime(new_setting->it_value)); + exp = timespec_to_ktime(new_setting->it_value); + /* Convert (if necessary) to absolute time */ + if (flags != TIMER_ABSTIME) { + ktime_t now; + + now = alarm_bases[timr->it.alarm.alarmtimer.type].gettime(); + exp = ktime_add(now, exp); + } + + alarm_start(&timr->it.alarm.alarmtimer, exp); return 0; } @@ -730,6 +743,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, if (!alarmtimer_get_rtcdev()) return -ENOTSUPP; + if (flags & ~TIMER_ABSTIME) + return -EINVAL; + if (!capable(CAP_WAKE_ALARM)) return -EPERM;