Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1908454ybe; Thu, 12 Sep 2019 01:12:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZhBnfF2kLpzMALKI3eSwEpyXu6kPa3waURg19JyYdIMpZgNGh1BQjdYsiUvm54jLlJtyB X-Received: by 2002:aa7:dcc3:: with SMTP id w3mr40852276edu.202.1568275956371; Thu, 12 Sep 2019 01:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568275956; cv=none; d=google.com; s=arc-20160816; b=OFtsxbLIc02uqvMMaXWNgyvWgjyDYgVrvyPeaDrJ+FzvPpDEp+6fyND/idcITGm+1o ZNMpAV2wCOZD3o4dtUz70p5o/VY3/rdj6Tfh+4axP0oXm2k65bADKTw91qhH04oLfell wNxS2CsNYQkNo1YgaviKSbC2iJFqWhPKLZ+6hPrUWm93uI8v22C6tV1liIqZ+V4nPglS Z6ME1PKm79o+jpAY56fb4OD+x9mnIZsJZAxrPkUSHMNiddSQ3iWPnDIOONDpVpvmy7zL 2h0NNY/MpRPxgLsn7qsi6jDy3lvAWbaHX1azyb3Fxvkb4GYYqGij2APnuJ2uhR9V0y3r o1GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=AsMLrZ3wJcgHkZ10rVMDyPst3P1Av7WTPxqh5DL8l+I=; b=dnz67DcuhypCSlKTsEqmPc6Hjx/hJYn0bnGNNenS2TQi5Hx6131J7lp6CZa7GMvQn+ 7yNsaA4BY/PjWBKLPq1RggPfop4GL6CgAR+lUOaPNZHp5ryrnRA428FwWwwTwQ8j3j6T PEletPgGmrFwQy2GNBYvAnT4JeZvk5fXbd1fqAKYEaSWuqNHUmAH2MKGTPkqONc1RvGn 6Be9Oug/sbGrlZljpMqxAupvFq6akru1OorXMQC2uAmNTC1gbFeI5q6bvRl9wSpi/Nl+ 2cElbHIHhM2IQzUXVa5fiSb+k6dFrrsR4UySderklkaiP7rxluScbifHIisnDcBKqyIO emcA== 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 v10si3424639edc.224.2019.09.12.01.12.12; Thu, 12 Sep 2019 01:12:36 -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 S1729998AbfILIKC (ORCPT + 99 others); Thu, 12 Sep 2019 04:10:02 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:50019 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729903AbfILIKB (ORCPT ); Thu, 12 Sep 2019 04:10:01 -0400 X-Originating-IP: 213.58.148.146 Received: from localhost (unknown [213.58.148.146]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 1F9C4E0003; Thu, 12 Sep 2019 08:09:59 +0000 (UTC) Date: Thu, 12 Sep 2019 10:09:53 +0200 From: Alexandre Belloni To: Nick Crews Cc: Alessandro Zummo , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Duncan Laurie , Enric Balletbo i Serra Subject: Re: [PATCH] rtc: wilco-ec: Sanitize values received from RTC Message-ID: <20190912080953.GO21254@piout.net> References: <20190910151929.780-1-ncrews@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190910151929.780-1-ncrews@chromium.org> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nick, On 10/09/2019 16:19:29+0100, Nick Crews wrote: > Check that the time received from the RTC HW is valid, > otherwise the computation of rtc_year_days() in the next > line could, and sometimes does, crash the kernel. > > While we're at it, fix the license to plain "GPL". > > Signed-off-by: Nick Crews > --- > drivers/rtc/rtc-wilco-ec.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/rtc/rtc-wilco-ec.c b/drivers/rtc/rtc-wilco-ec.c > index 8ad4c4e6d557..0ccbf2dce832 100644 > --- a/drivers/rtc/rtc-wilco-ec.c > +++ b/drivers/rtc/rtc-wilco-ec.c > @@ -110,8 +110,16 @@ static int wilco_ec_rtc_read(struct device *dev, struct rtc_time *tm) > tm->tm_mday = rtc.day; > tm->tm_mon = rtc.month - 1; > tm->tm_year = rtc.year + (rtc.century * 100) - 1900; > - tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); If your driver doesn't care about yday, userspace doesn't either. You can simply not set it. > > + if (rtc_valid_tm(tm)) { > + dev_warn(dev, > + "Time computed from EC RTC is invalid: sec=%d, min=%d, hour=%d, mday=%d, mon=%d, year=%d", > + tm->tm_sec, tm->tm_min, tm->tm_hour, tm->mday, > + tm->mon, tm->year); > + return -EIO; > + } > + > + tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); > /* Don't compute day of week, we don't need it. */ > tm->tm_wday = -1; > > @@ -188,5 +196,5 @@ module_platform_driver(wilco_ec_rtc_driver); > > MODULE_ALIAS("platform:rtc-wilco-ec"); > MODULE_AUTHOR("Nick Crews "); > -MODULE_LICENSE("GPL v2"); > +MODULE_LICENSE("GPL"); This should be in a separate patch. > MODULE_DESCRIPTION("Wilco EC RTC driver"); > -- > 2.11.0 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com