From patchwork Mon Jul 7 21:06:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 33174 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ADC3220969 for ; Mon, 7 Jul 2014 21:06:22 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id w7sf3002661lbi.7 for ; Mon, 07 Jul 2014 14:06:21 -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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=9P9CNSl7q8ZJaigss8d8cAI9dbgRGNNeK06hGTWZAwc=; b=LdY6Rs/vFNCvSYoLvvlw2vxLmOGDJzRLMsN08vQUUkryc3NUYCXxSjZ+059G0Pg36j j11ZljAlR8oFBBfDfLDWyXKRTGU56HgpilYX2qXAoy3qovFWr+90+Wr4ZEpj+/H+nIXL 3MF9mPu3Gqbi9SE8cv/Wy/QbakjatAS4S6xQzaQOYi2fHXDV+L8KYAAb/hfqgVRWYx9t hPTVo8mpGEFPUTnHsY+pHcK6VBhFDbAJkSw7HDcBctDSgA6nNBH7Ms0nTLePhi4Agouh sKKr+K+wNzXbrI0/rKWV8I5J99l/Z3fibcD/YJOpeoO9TZ6GCZJ6r135qqR2tipZ6rld KUpw== X-Gm-Message-State: ALoCoQlSGUxvict4z3EWlgD0hik1TUaI83aVEGPKYPJuc0+anlAD44qybDC5+HkMjU7Ebjxs67aB X-Received: by 10.152.87.226 with SMTP id bb2mr3178609lab.5.1404767181186; Mon, 07 Jul 2014 14:06:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.71 with SMTP id o65ls2024197qgo.4.gmail; Mon, 07 Jul 2014 14:06:21 -0700 (PDT) X-Received: by 10.52.106.162 with SMTP id gv2mr12439401vdb.47.1404767181018; Mon, 07 Jul 2014 14:06:21 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id y3si19232915vdx.29.2014.07.07.14.06.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Jul 2014 14:06:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id jx11so4729313veb.33 for ; Mon, 07 Jul 2014 14:06:20 -0700 (PDT) X-Received: by 10.220.167.2 with SMTP id o2mr29611520vcy.8.1404767180920; Mon, 07 Jul 2014 14:06:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp704321vcb; Mon, 7 Jul 2014 14:06:20 -0700 (PDT) X-Received: by 10.67.15.40 with SMTP id fl8mr31333646pad.69.1404767180096; Mon, 07 Jul 2014 14:06:20 -0700 (PDT) Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by mx.google.com with ESMTPS id x6si5257738pdl.191.2014.07.07.14.06.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Jul 2014 14:06:20 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.46 as permitted sender) client-ip=209.85.220.46; Received: by mail-pa0-f46.google.com with SMTP id eu11so6003456pac.5 for ; Mon, 07 Jul 2014 14:06:19 -0700 (PDT) X-Received: by 10.66.131.39 with SMTP id oj7mr31139931pab.20.1404767179676; Mon, 07 Jul 2014 14:06:19 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id gu1sm53615791pbd.0.2014.07.07.14.06.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Jul 2014 14:06:18 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Thomas Gleixner , Ingo Molnar , Richard Cochran , Prarit Bhargava , Sharvil Nanavati , stable Subject: [PATCH] alarmtimer: Fix bug where relative alarm timers were treated as absolute Date: Mon, 7 Jul 2014 14:06:11 -0700 Message-Id: <1404767171-6902-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.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.128.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Sharvil Nanavati Cc: stable #3.0+ Reported-by: Sharvil Nanavati Signed-off-by: John Stultz --- Thomas, Ingo: Please consider for tip/timers/urgent for 3.16 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 88c9c65..fe75444 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;