Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3558043pxb; Mon, 24 Jan 2022 12:10:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjbv1eJEusA7il64OOP9BGY6YNr42KoKc/M3pNzGvNsriEZ2pYgyRYmzFhtiFPhWeexiri X-Received: by 2002:a17:90a:3e4a:: with SMTP id t10mr8510pjm.70.1643055051818; Mon, 24 Jan 2022 12:10:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055051; cv=none; d=google.com; s=arc-20160816; b=bFUsQXKVddrfGlxsZGAwdKB/WDZsSlNJdSf735+S//amJ97tZmmHLKsWtSigfVQoap hBtvf6BGjrpEhIck9FVKMXiJ3HrOTzmzUdlaLGcMpuC6v88/wqBC5psiAMePi9f7A36+ hKj2Dtco/kWhR8Ywpd/n3B/dgSQidCF3o5o3yw2F71K+9XAyjmJNlvMBPUUUhSOow8wq JouhYtUcbA8fut/4sthwAjiPE3dbLK66T9w7qNoWwDgYynDu+J8gDct6CicqfvVum4l2 Z/45bVOwCqdWRXa56PLlRWz01I8ewt8VfsiaceFAxmK6gzHehqJ0m7WoHgoOf8hR+uV5 WYKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=phjjvKtdW7h6zgnATh9otIk+z7mZabZA/7PUmbU9HQI=; b=i14iAdOGcOUHJ9Mmd3Z4/TtWK5RA7aTuYmXW4A6Hfom9j/1e8eG2A1KIB2KxjIHXvk 2WqXRuOq9RGTcLaLtCuuBDwUqs9rVMw7ddzB9/SfHyZtYo6QmIg4AGsBpgIDLDgH0Hay gKK04hQYtMADGZYZyEoHMUTiwW3KWpPgd0faCYT6gd5hQBTsFekcIDgBE5R0l5cjM4nn j1s3WPys2txvcI6nrD21h6z4ZGkhvvJca0YCIyntvABS2O9MsysoUAQ1FENsTjWuZ3yI 4hkUsah+TF7dlAI8D1j+imXt707taWuMGNzxUI7SB9kpc+KOTrVsn/bAi+2keOk7yQx1 TieQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jx6USeD+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g15si16417862pfc.227.2022.01.24.12.10.39; Mon, 24 Jan 2022 12:10:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jx6USeD+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345390AbiAXTMM (ORCPT + 99 others); Mon, 24 Jan 2022 14:12:12 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:58834 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344567AbiAXTDP (ORCPT ); Mon, 24 Jan 2022 14:03:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F201260915; Mon, 24 Jan 2022 19:03:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2E31C340E5; Mon, 24 Jan 2022 19:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050994; bh=clj+vxpqqIICktGBM5OJvshuuNp5mLq7b+Nhg7gw3E4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jx6USeD+Xqmrhn+A53Yvs4jMnLrWToCLXgNZ7qJglSuLw4pLqoErpmWR2HfDDQlUK juTEyuLadiJcnm9xqfJTiLMbqUPBzoXBeCZI6N9DLLvh6yFAAFYUT4GHqEEbI3eyI4 emutt89OOXHwF6p4Ky6wqyuAMciyvEwKRg/nsHw0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Nobuhiro Iwamatsu , Alessandro Zummo , Alexandre Belloni Subject: [PATCH 4.14 020/186] rtc: cmos: take rtc_lock while reading from CMOS Date: Mon, 24 Jan 2022 19:41:35 +0100 Message-Id: <20220124183937.770167723@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mateusz Jończyk commit 454f47ff464325223129b9b5b8d0b61946ec704d upstream. Reading from the CMOS involves writing to the index register and then reading from the data register. Therefore access to the CMOS has to be serialized with rtc_lock. This invocation of CMOS_READ was not serialized, which could cause trouble when other code is accessing CMOS at the same time. Use spin_lock_irq() like the rest of the function. Nothing in kernel modifies the RTC_DM_BINARY bit, so there could be a separate pair of spin_lock_irq() / spin_unlock_irq() before doing the math. Signed-off-by: Mateusz Jończyk Reviewed-by: Nobuhiro Iwamatsu Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: stable@vger.kernel.org Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/20211210200131.153887-2-mat.jonczyk@o2.pl Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-cmos.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -421,7 +421,10 @@ static int cmos_set_alarm(struct device min = t->time.tm_min; sec = t->time.tm_sec; + spin_lock_irq(&rtc_lock); rtc_control = CMOS_READ(RTC_CONTROL); + spin_unlock_irq(&rtc_lock); + if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { /* Writing 0xff means "don't care" or "match all". */ mon = (mon <= 12) ? bin2bcd(mon) : 0xff;