Received: by 10.192.165.156 with SMTP id m28csp1064099imm; Wed, 11 Apr 2018 11:45:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx49LDsiIUrWvxuKLNHC40zQwxqayfWMYp8HiEbwBwaPHFvLAySoDmIrPaQALIeLBSQe/e1VP X-Received: by 2002:a17:902:24c:: with SMTP id 70-v6mr947236plc.384.1523472319384; Wed, 11 Apr 2018 11:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523472319; cv=none; d=google.com; s=arc-20160816; b=bRhuZa/NFYA0hmF1e8DI+J2HnY9ANonZ71Uu5tPBnZJkytGcZ7Bz7zPggQlsidB6BF ISIX5dQTfGbmTyT1RyfVGvYyctps2QoiHhX8GKSA6c8emGkDFxSYF/LFORBMHGXxepON 408pSlonPOl59XF+DzboyLXDwvurEHC5JMh0WjH6Vfez9XxTj/bTZTx7hbdSQN/7oyvJ ySb5i5xmBqruZFWGRk9PFQnXf8eLn2lkpBWIaqa8VjFVkeIjM+hRHAdstASK9jPtHc+0 uGdiFZE9lcbZQvSepgegVs3RGBye1tx0lbPNpczgWjcvUlyqJSCDwHWJkacH0zp+sx9A MoCg== 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=Bd1X1BpQJRprx31YB8LPX6phaXNdn+PqVw+IN3rmnxo=; b=Q4lJwhSOMNpintu+g4F/wOdosPAfxCJLTXnL3cOOtNetfQsT+A7Zpo08IZFMGEETQ9 z0hdoS+Lmh4WKygxsY4O60x17sMoN9HG0uDQB3dXr9xw2PGMSqXifoZ6XxEXdQCLJGrX q11GCaKh4XS3cxyXKyxP1kxm7dteSq2+rfE7zNRfXvdSDAQQVCqYjNMHkHFQ8AJKGmIh i6K8zzw4d4RuUkJ4+d2AYJWZravYjugI0FOTF0BS72v3jblNKfu2ktD8wKSaDs0WdYqb zL9aWPdlF5rcCOy2IztANa7hAhz88uftVla36RwETMZcP4iQDv/6PeFPUMJnE7IAKeKe e23A== 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 g8si1071863pgq.544.2018.04.11.11.44.42; Wed, 11 Apr 2018 11:45:19 -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 S1754587AbeDKSkP (ORCPT + 99 others); Wed, 11 Apr 2018 14:40:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56350 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753241AbeDKSkM (ORCPT ); Wed, 11 Apr 2018 14:40:12 -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 58BADC41; Wed, 11 Apr 2018 18:40:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve Best , Vaibhav Jain , Alexandre Belloni , Sasha Levin Subject: [PATCH 3.18 057/121] rtc: interface: Validate alarm-time before handling rollover Date: Wed, 11 Apr 2018 20:36:00 +0200 Message-Id: <20180411183459.752762871@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183456.195010921@linuxfoundation.org> References: <20180411183456.195010921@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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vaibhav Jain [ Upstream commit da96aea0ed177105cb13ee83b328f6c61e061d3f ] In function __rtc_read_alarm() its possible for an alarm time-stamp to be invalid even after replacing missing components with current time-stamp. The condition 'alarm->time.tm_year < 70' will trigger this case and will cause the call to 'rtc_tm_to_time64(&alarm->time)' return a negative value for variable t_alm. While handling alarm rollover this negative t_alm (assumed to seconds offset from '1970-01-01 00:00:00') is converted back to rtc_time via rtc_time64_to_tm() which results in this error log with seemingly garbage values: "rtc rtc0: invalid alarm value: -2-1--1041528741 2005511117:71582844:32" This error was generated when the rtc driver (rtc-opal in this case) returned an alarm time-stamp of '00-00-00 00:00:00' to indicate that the alarm is disabled. Though I have submitted a separate fix for the rtc-opal driver, this issue may potentially impact other existing/future rtc drivers. To fix this issue the patch validates the alarm time-stamp just after filling up the missing datetime components and if rtc_valid_tm() still reports it to be invalid then bails out of the function without handling the rollover. Reported-by: Steve Best Signed-off-by: Vaibhav Jain Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/interface.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -249,6 +249,13 @@ int __rtc_read_alarm(struct rtc_device * missing = year; } + /* Can't proceed if alarm is still invalid after replacing + * missing fields. + */ + err = rtc_valid_tm(&alarm->time); + if (err) + goto done; + /* with luck, no rollover is needed */ rtc_tm_to_time(&now, &t_now); rtc_tm_to_time(&alarm->time, &t_alm); @@ -300,9 +307,9 @@ int __rtc_read_alarm(struct rtc_device * dev_warn(&rtc->dev, "alarm rollover not handled\n"); } -done: err = rtc_valid_tm(&alarm->time); +done: if (err) { dev_warn(&rtc->dev, "invalid alarm value: %d-%d-%d %d:%d:%d\n", alarm->time.tm_year + 1900, alarm->time.tm_mon + 1,