Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5758904ybe; Tue, 10 Sep 2019 08:24:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqygeXyOdulLLm5gY5g1fjdGyKx4cUtedyBGpp86ow6+4YlH6lAgG7w57wLl6k0yVv/v69EF X-Received: by 2002:a17:906:51a:: with SMTP id j26mr25019558eja.52.1568129061237; Tue, 10 Sep 2019 08:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568129061; cv=none; d=google.com; s=arc-20160816; b=tZFRGMorNBLvKo3ovu3VOKHCVa1MlGS/6qeIKnp/T5RRkzW/hMCv6//7RCWCZxqX67 RlGDXwu+tV5eg3jUPAE3jMxS0hjZkzC/3PiJqAHbvx1cqBZFGjJlLjhau6Q89tZQ0NMM lhIo43tkgYlWg1sE5svREMj1ekTHsDtY1TRyq0+J1FA1lUz+GgIEbTSqs0d1YpiagGMw i+gkSgo90dTAZrJNORTRcav1TCTX53AyDqh7jo2W+4CrE1MGFt5bR1kDNeI0fBohedM+ +6r3ZuhH+EHe79l/EPYi7FvpDtrGVKr/rdzQbM60d76z7ebhs+F/d1Zu0vI+IOZjr2QL mYBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=vmUuCMkzir2Sv0OO2nHQXi9m+juUE2w8XHaiTSroSHA=; b=ynGDYood9r5BYlnhiO1TXU5T62YChr1Dxj40rBfuv5760CT7acqwcEPN+oOXhrjRmF 3obDjXCe7nfavuhoeTjqA02x+VcPXaw0CmEvm+ALJMTar4axej7BeqshxnFpCfPhoQgI bCHE8zl5wIT17z6F8/awxvRQLeEnBuCxdKm/ut8IthCnknNYneA5paiz9BmQ35wbSY36 FQK+u40wg/Tumoq9okCZxoUbI/rOYycEKLONpEYiEPTuAvhzPHHo5cVkekAkJvQvzqBJ 9Yh7Str8Rg9pAxuKb7ULjxoaILE5W5RB+7vLV+VGOk+Y0yaDVPv6EMy9DQGozsdD51yX 6FlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="kYw/oUI/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay21si9526327ejb.176.2019.09.10.08.23.56; Tue, 10 Sep 2019 08:24:21 -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; dkim=pass header.i=@chromium.org header.s=google header.b="kYw/oUI/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405710AbfIJPTv (ORCPT + 99 others); Tue, 10 Sep 2019 11:19:51 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33033 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729662AbfIJPTu (ORCPT ); Tue, 10 Sep 2019 11:19:50 -0400 Received: by mail-wr1-f67.google.com with SMTP id u16so21109572wrr.0 for ; Tue, 10 Sep 2019 08:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=vmUuCMkzir2Sv0OO2nHQXi9m+juUE2w8XHaiTSroSHA=; b=kYw/oUI/H82GJRyFfkUzR4+OURd1LYYPwpXS5Eassv7VrsNI7XMdZAjX/Hem4mUJmh Q07kd8PYu2S/HY2W5SC/lu+yJ4R0w793l/6htAF9mDMKAzMoFl2DMq1iT6b+LwK6IaQ7 UOtLAN5bR7qX4XSlusnmqgKWZ9hozJtU1Zp8s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vmUuCMkzir2Sv0OO2nHQXi9m+juUE2w8XHaiTSroSHA=; b=WknDHH3DC4HHGtlK4LuwqnG9k9d0Y7QbofwBdp69CJpHh+4Bt4qLVBx/b3PcJshthk TpeqZ+a4U97LIgkqcXVVyDYaTZYknLA7LURBhxI9425tfbNBW3j4B7cWBCQEVuichH87 4PiRbzimsAQ7M6JuZfhCknI2Trd1hQVXnnUa4MupfhEI3H5D19u+b+68tMrecNWJ5U5G B0rAM4Evsxbjno/AQQk0s46T9lXnpss1IFR4NY2+udsp2JgfVAd9eUkqLbXHoOfkhqSk 6hjlDooLYNNhWsLQTH5ZBhOdkbdmYZcObwobUtMD0BR1tIzcYjBLhjaERhNy5E4orJnw Y/4w== X-Gm-Message-State: APjAAAVKQ4FN+8ihYPHxBVnYen0ybTyP0I5N2oXDiBxtWG1vRPZKSN1Z NODRZbSyBM1P1bsXhr0Hb8NVuY6lru3owR2A X-Received: by 2002:a5d:678a:: with SMTP id v10mr26708489wru.145.1568128788717; Tue, 10 Sep 2019 08:19:48 -0700 (PDT) Received: from penguin.lxd ([148.69.85.38]) by smtp.gmail.com with ESMTPSA id o22sm32753305wra.96.2019.09.10.08.19.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Sep 2019 08:19:48 -0700 (PDT) From: Nick Crews To: Alexandre Belloni , Alessandro Zummo Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Duncan Laurie , Enric Balletbo i Serra , Nick Crews Subject: [PATCH] rtc: wilco-ec: Sanitize values received from RTC Date: Tue, 10 Sep 2019 16:19:29 +0100 Message-Id: <20190910151929.780-1-ncrews@chromium.org> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 (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"); MODULE_DESCRIPTION("Wilco EC RTC driver"); -- 2.11.0