Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3547587pxb; Mon, 24 Jan 2022 11:57:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhhVz36x+795esE2MVME0gydd9u4Q9ACAwJl2TRiPQ1NYhZchorf23gfg0b1T0d4OYLvkN X-Received: by 2002:a17:90a:4407:: with SMTP id s7mr3361647pjg.126.1643054246221; Mon, 24 Jan 2022 11:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054246; cv=none; d=google.com; s=arc-20160816; b=xzw9ok1vFkB+9FPsndbMfDZcfzkSub9WA9XP0RfHTAHc2M1BvMuH1aP/H433U55TDw VGF+B4gjHQuKwnK9Kdu4uLdGjY2wkj0r6kfPHQ04Bru97MnZxerxdja+kUy2TAuHfJQL DWtd/1Udz6FHkYijiBsEEYxDt9R9dzSjP6qUqoudvjzcNVlLnQi4NhXv9s9OmmA7C8nk SrMnXSS+GyO953U61IO+HLAQPHM+4hJs+U3hCMRzBmjnL3Aqqttk9ZUCgZ4PTcPBfW+n T6kQW1mAiHF9FKPimI19xvnHsOMQa4hxCI7z8JcAOTa51axpvBOOSvSobFVJ8oP6RkuO fwwQ== 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=GQvtFm0bN5R1ltiVBUAmHsoJGsz8/xlQELDNwBvBZTs=; b=Q+H54ngvD6XOGOPBgstscXLXbAeCXa4zUIxmE+5enCZHC/LASRI95zDPUojw6YM0Y1 0o1cHjI5C0djmXFVDJ/1AL2C9TUnmXaDlrmqF3lf/gsTm0o3okT9+IFaUBDlqMEFfSgq ZVoWzn9ZXozf+CTga/GD7MB1fDp4nUx2ZxoLV1YWksXX2RfgIyQwtxCzFaYVznqwsH2V T/6Li9yF8E3zq8FDp1PrY1Wgeu4LtVP6CPOaaepJTbfus04FJWKvyGZM2ZdvPI41RdJm H4onMMakr+ZxV+BnniJjlkFp9oYYTOicmXVZDkICh+ZN6NXIjcMBNrN+r8a7Nn0450nh 0k9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Mm5wWVaF; 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 b16si2442077plg.138.2022.01.24.11.57.14; Mon, 24 Jan 2022 11:57:26 -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=Mm5wWVaF; 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 S245598AbiAXSwK (ORCPT + 99 others); Mon, 24 Jan 2022 13:52:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343598AbiAXSvG (ORCPT ); Mon, 24 Jan 2022 13:51:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D62ECC061797; Mon, 24 Jan 2022 10:50:44 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 93094B810BD; Mon, 24 Jan 2022 18:50:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3126C340E5; Mon, 24 Jan 2022 18:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050242; bh=Z61lJENDMxEpYURPDCUWyB6NKwLICZ+bTHmh4lU0xC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mm5wWVaFtotYrn1GrH9QTS3Gn3r/gGW8UtZGroTdWIYaUjdaLyvIVvMJeRB9QmOPQ jbG/w5scnhyvpYg5XU2dGffDRWbTcgHqbRQ4Io+Jl94dqZrQiBp1hb540m1qGbs+Jn Z0phDjooTHfzIvs1tjoqeyDXvSAcjtxUK2BwyzQM= 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.4 012/114] rtc: cmos: take rtc_lock while reading from CMOS Date: Mon, 24 Jan 2022 19:41:47 +0100 Message-Id: <20220124183927.492636970@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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 @@ -343,7 +343,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;