From patchwork Tue Jul 8 08:49:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyogi Gim X-Patchwork-Id: 33179 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3CC6120969 for ; Tue, 8 Jul 2014 08:51:03 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id fp1sf37200291pdb.0 for ; Tue, 08 Jul 2014 01:51:03 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=tOfmo6FDMiUdM/MSWjoV+d43iqJbKS/Ezr3kLhooeDQ=; b=LbgltzqUFOdZ7u/gen91ZCyv6Z65B20rYvHKv1W1+AioQDTwIP6VA4KXpf0pxSPjST 5xxWgvgW9uQeHjoWQT0rB7/fUFWJ02Oprs1XVma75YFnBY2xKa3L8aMciNhVU4CRvL8z sIz77y1dsk4Oyj1VsJ6jgVJRAxDGPEYHunyisG+1+ZK8gtXM1ba4uRykgFlIL78Qm3wO g4qvTTkDYYN8OHhq3S4Y6q/qGcR57vJ4zcOeNznF0F2HEuFvogXroxrNJWixLWASHEP0 cpyy7/Zao6cZp7c2lrm3CoqTYw6c4V33kS1uMmUNI46DRdZgj7CHvPjUOZ1o6zsVFnmY xFCw== X-Gm-Message-State: ALoCoQnwc6jZf3U2XMh2elQEAsMm5c30T6Lt4phDrROBfjuiZR/rlYgHg8NKQBj1QgjkL+kV/k+z X-Received: by 10.67.23.231 with SMTP id id7mr13891957pad.8.1404809462083; Tue, 08 Jul 2014 01:51:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.179 with SMTP id m48ls2215328qga.84.gmail; Tue, 08 Jul 2014 01:51:02 -0700 (PDT) X-Received: by 10.220.81.194 with SMTP id y2mr17772497vck.29.1404809461980; Tue, 08 Jul 2014 01:51:01 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id kz4si14666016vdb.74.2014.07.08.01.51.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Jul 2014 01:51:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hy10so5212280vcb.3 for ; Tue, 08 Jul 2014 01:51:01 -0700 (PDT) X-Received: by 10.52.27.208 with SMTP id v16mr27727838vdg.21.1404809461898; Tue, 08 Jul 2014 01:51:01 -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 tc5csp752333vcb; Tue, 8 Jul 2014 01:51:01 -0700 (PDT) X-Received: by 10.66.117.38 with SMTP id kb6mr6385782pab.37.1404809461023; Tue, 08 Jul 2014 01:51:01 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ek5si5818350pdb.301.2014.07.08.01.51.00; Tue, 08 Jul 2014 01:51:00 -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 S1753619AbaGHIut (ORCPT + 27 others); Tue, 8 Jul 2014 04:50:49 -0400 Received: from lgeamrelo04.lge.com ([156.147.1.127]:61954 "EHLO lgeamrelo04.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753484AbaGHIur (ORCPT ); Tue, 8 Jul 2014 04:50:47 -0400 Received: from unknown (HELO localhost.localdomain) (165.186.175.61) by 156.147.1.127 with ESMTP; 8 Jul 2014 17:50:45 +0900 X-Original-SENDERIP: 165.186.175.61 X-Original-MAILFROM: hyogi.gim@lge.com From: Hyogi Gim To: John Stultz , KOSAKI Motohiro Cc: Thomas Gleixner , linux-kernel@vger.kernel.org, Hyogi Gim Subject: [PATCH] alarmtimers: verify the alarmtimer_type value from clock2alarm() Date: Tue, 8 Jul 2014 17:49:27 +0900 Message-Id: <1404809367-30207-1-git-send-email-hyogi.gim@lge.com> X-Mailer: git-send-email 1.8.3.2 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: hyogi.gim@lge.com 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.172 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: , clock2alarm() can return a minus value. so, we cannot use this returned value for a index of an array. but, some functions use this value directly as a index of an array: - alarm_clock_getres() - alarm_clock_get() - alarm_timer_create() - alarm_timer_nsleep() add the verification code for the returned alarmtimer_type from clock2alarm(). Signed-off-by: Hyogi Gim Cc: Thomas Gleixner --- kernel/time/alarmtimer.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 88c9c65..0b117c6 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -487,7 +487,14 @@ static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, */ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp) { - clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid; + enum alarmtimer_type type; + clockid_t baseid; + + type = clock2alarm(which_clock); + if (type < 0) + return -EINVAL; + + baseid = alarm_bases[type].base_clockid; if (!alarmtimer_get_rtcdev()) return -EINVAL; @@ -504,7 +511,14 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp) */ static int alarm_clock_get(clockid_t which_clock, struct timespec *tp) { - struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)]; + enum alarmtimer_type type; + struct alarm_base *base; + + type = clock2alarm(which_clock); + if (type < 0) + return -EINVAL; + + base = &alarm_bases[type]; if (!alarmtimer_get_rtcdev()) return -EINVAL; @@ -531,6 +545,9 @@ static int alarm_timer_create(struct k_itimer *new_timer) return -EPERM; type = clock2alarm(new_timer->it_clock); + if (type < 0) + return -EINVAL; + base = &alarm_bases[type]; alarm_init(&new_timer->it.alarm.alarmtimer, type, alarm_handle_timer); return 0; @@ -721,7 +738,7 @@ out: static int alarm_timer_nsleep(const clockid_t which_clock, int flags, struct timespec *tsreq, struct timespec __user *rmtp) { - enum alarmtimer_type type = clock2alarm(which_clock); + enum alarmtimer_type type; struct alarm alarm; ktime_t exp; int ret = 0; @@ -733,6 +750,10 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, if (!capable(CAP_WAKE_ALARM)) return -EPERM; + type = clock2alarm(which_clock); + if (type < 0) + return -EINVAL; + alarm_init(&alarm, type, alarmtimer_nsleep_wakeup); exp = timespec_to_ktime(*tsreq);