Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3623029pxb; Mon, 24 Jan 2022 13:45:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJz41FypMQqp5DfT7wQvJ+wilUej2NBH1SD6qyrIxUkJF05GuePU/r37W5h5TkYeyrf7kH9z X-Received: by 2002:a17:902:8f8a:b0:149:8d21:9f44 with SMTP id z10-20020a1709028f8a00b001498d219f44mr15964719plo.15.1643060591798; Mon, 24 Jan 2022 13:43:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060591; cv=none; d=google.com; s=arc-20160816; b=tiUuRNG+HLb3PHwInzbHjqsZrkk580QaMgWAUBG7Zjm2qjGPbCQD10W9i/LnuGJ/ja EH4bbPsD/En0UY9RNLd70H0XlPqu6U+5O4Xg07rfZnWTrEEc/E40m2n7krGQSCS3UcZu o6tV5SrYEPgo/KKlYCFgmVXBbo7ghkPv6yvLHvZK/Y/kqSiibHky7ZKliM9+zn+BgbnI 2kb9PQqMmHCgUFAjT7rIvGQfOGN9ckXuXS4lsku/Da99ixLjiwswIzFEjDQBBhnX/JKP KKCreA7BTqTnMd4uOQ11McrrYKq5zZbFnU70UB4xHgPUtK3DQfGNyxFX0YC6wQgezMSz VUXw== 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=SQsPjsQyvy0IwJGpWIBklkFKnmCkItHxCRN0m941ncs=; b=gUzO/wDAzMYbJnz7ZMU6dODEwpfenoc1iIbq9oQAVBUMDasKdNYE/IPhgQTLn6L2Hb 2QzhB+/aYdKfuurwuDwotLBifP3BIy3aon6kX3hmAwdssdbW+X66zgxhpgXCXnNsP7Ox g8eCkfOmFT4VjP4WibL/4O1PPGqpvA+O5ju2Amtn5mQiKXLvNwLFM7i6F8nCB0n2YA0E qJdiZ74L2eObxOlafueippGAVhFdwTpR+uvwoyFxe+IJXGYMUjKRQGEjw6NHWq7whMXz WZ2ushKDat34kVHtlDwbENXn3WhVrJO9T0FF92CNE+GAcztUa+uBJxXIAtwc47unZe1D QQyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RN5XSu4x; 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 q18si15526214plh.459.2022.01.24.13.42.58; Mon, 24 Jan 2022 13:43:11 -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=RN5XSu4x; 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 S1451074AbiAXVWE (ORCPT + 99 others); Mon, 24 Jan 2022 16:22:04 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:47652 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442282AbiAXUyL (ORCPT ); Mon, 24 Jan 2022 15:54:11 -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 4796960B11; Mon, 24 Jan 2022 20:54:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21F93C340E5; Mon, 24 Jan 2022 20:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057650; bh=MFXndqI8cxiHslc/dNlSaB1r9JTjhtiZBSwFf6F0MWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RN5XSu4x+4I7lIaV5IqOITU4SiDvbdIq3binhcXMFPTfvsG4iPK5uEcUr4xra2MLE gCwj9JsElybIgnI8IwRJbkfAfYpbY1wAGPSlI+xArmzhF6VWgWK3GXQWBzjiuIshSP C6pMLAEiBmfgClA7S7Kgk2jGAeGgVueJ9Fi/NA6M= 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 5.16 0034/1039] rtc: cmos: take rtc_lock while reading from CMOS Date: Mon, 24 Jan 2022 19:30:23 +0100 Message-Id: <20220124184126.276033378@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 @@ -457,7 +457,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;