Received: by 10.192.165.156 with SMTP id m28csp1119093imm; Wed, 11 Apr 2018 12:48:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx49PuUHd5l2z9xvhsNJZ6zPRyljrNovBsQWmZZHE7AuuvgEC8ky2ZtPUjQ2xvWBiIW/p1ytc X-Received: by 10.99.64.65 with SMTP id n62mr4353202pga.259.1523476099807; Wed, 11 Apr 2018 12:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523476099; cv=none; d=google.com; s=arc-20160816; b=hNdUtcJA4efqDTQkaeOVfA3+tqNCtJeBOFCifBTfXra62vXtNgWeOR+A8VTEWDjQuH WifcVQKj2nb3MMVJji5OcfnXbRzFO9MY2kEclrYhxA6Z7wZyp2wxneJdQnlD4vhMktBm T/3d8+726LDjtTTyf81RVlIMSWpLC9Fia1SggpsvDBtqS/2omJVDPi01WoDGEM0QB4zn Se/IgWwuwD6oZShTCncWF83d3fc90kUWMu9SyO1+deCdSsm3ZjM9a2YccoU28mZfImBK AIoEQtB+WsFcAhTMfOgDKEhVTZlgXnVA+L4ImPfGXPUJA4FVpMpkrs115cS3re4m0wzV /tBQ== 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=gSjMIbevDXclMZYH0euX3yrZgBbWTRvqrUPvTfxB7VQ=; b=m8uGkXl2loQjhIMh2tQad3k8zJWqiKwr4WJ2bLNhpGvG/zoOyGg+szpFuXFdEFdCsp oKFdPnO7pmAvgcUYtc7oxidykk/Q1q7YFxQNyzcGwxhtlwpZvcAIdlVMLeazVhisktge ZiXi/gtA/x1bIZaXxknH36mZoCHgb1bKXDMRczOpUtMNEjYUGwit7uM8quWGj+dkzWkZ L6KnmqdHs4BQURlzmQ7mLOtRM/EPuH5ynau5LpeyGEQ4xlBPJ8gxzzjp7JF4wPlU0/W6 r+v+jJrIKT6QJeKZKztrdKJCgCsIk2bhQC49+TGDJi/+E16btL4L8Eom6XOiYskUoMWD /hvQ== 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 r9si1352462pfg.8.2018.04.11.12.47.43; Wed, 11 Apr 2018 12:48: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 S1756640AbeDKTAJ (ORCPT + 99 others); Wed, 11 Apr 2018 15:00:09 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37606 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752973AbeDKTAG (ORCPT ); Wed, 11 Apr 2018 15:00:06 -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 CA8C49C1; Wed, 11 Apr 2018 19:00:05 +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 4.9 163/310] rtc: interface: Validate alarm-time before handling rollover Date: Wed, 11 Apr 2018 20:35:02 +0200 Message-Id: <20180411183629.399649660@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@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 4.9-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 @@ -227,6 +227,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 */ t_now = rtc_tm_to_time64(&now); t_alm = rtc_tm_to_time64(&alarm->time); @@ -278,9 +285,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,