Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2501759imm; Mon, 28 May 2018 09:16:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKvdVKH6gpRTmtu/50tBXzYG8MRN7w6cD/wkyRAJX6q7gCC3r32F4phbZd63Zv/Krs93Uh X-Received: by 2002:a62:3745:: with SMTP id e66-v6mr14003987pfa.43.1527524188371; Mon, 28 May 2018 09:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527524188; cv=none; d=google.com; s=arc-20160816; b=RuWdV5QkQtqX1uRl4hRPmA+J0ePVujwaXPN0YHqjS8ECSBF2a1wabWXXOuPXfGZ6Js JqP0ZjDZa1bQ5dzGaNTQAaf2fDcvro5aR2k50aDHVBnEr2xSpDvhXPj6TivjOD9vk9Cm +sMPX/M5ozA8/YR+WORv0oLemzfR9tqPF+diTyrZyss5Mgeo6152MjfWrfptMnYW8No7 gvQQBXXXAXI4Mso/f0PKJ+XBbNbWdvKkTtmz2sd4pWepfNTZqxL85CjZ+Haye63dd1kS Km+1DscpKmv2I3ltwrBa8tjtc2YRoAs0mcMyD0RNzLWoS4XiruCPUTJkEMIQziasQWZJ HCqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=KjRfZa+VH9ZikEtuWMiYM1pLueI1RGZ338rd/d7pAv0=; b=RTf3QYc1zIl75Qoh62ofUDudsz7ePHfpkrdV/mXJBKPX7HrWByt3twdFMmjhxf36ua N1MC8fYgo3AqkZkb6hUpc9+SFQkmgHSKYxihA51BHACJ+tpBVVJEHY7DHuavlDHUqmRO W/xavi2NDQUiIoVN64GYUK6jmoYUFZlW75iSRzAt8MXek+DXSRVdY8/Lydxd5AuO8Izu rT51MxL00oLgs2HeRHQ0wbflLMVWBUIsD/0xjdSp4IkxbgTuMFKi3chi5rPid/uCtfrA KrZsj71ufd6FfmcK+TscpAyUdkq467oYjoMbi+g8Sy+rp8pEMiVh99KyOkAYbWljUdop o4vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uattAs7F; 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 v12-v6si29647317plo.264.2018.05.28.09.16.13; Mon, 28 May 2018 09:16:28 -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=@kernel.org header.s=default header.b=uattAs7F; 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 S939891AbeE1QPk (ORCPT + 99 others); Mon, 28 May 2018 12:15:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:32986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932338AbeE1KNH (ORCPT ); Mon, 28 May 2018 06:13:07 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 58ACD20843; Mon, 28 May 2018 10:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502386; bh=uz5goCawzFAW65i4gQ1xVm0DTF3NCsJb3XXPxP3Pcng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uattAs7F8VnLSutbiPNo61i+SMHxV6feNk24HNANZn6vNyQe/v7ryBYx5fbo769uz MR4CJ1YMIaaRHamS8nA52otmPYxC/s10kO7x4s396O8W3WSbMRIUMsOeUeveqKo11T nN+6sRtwdNWwQwAJFrBulqYZnO3ZtdR5pRmaDBPM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Alexandre Belloni , Sasha Levin Subject: [PATCH 3.18 166/185] rtc: tx4939: avoid unintended sign extension on a 24 bit shift Date: Mon, 28 May 2018 12:03:27 +0200 Message-Id: <20180528100112.686603640@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King [ Upstream commit 347876ad47b9923ce26e686173bbf46581802ffa ] The shifting of buf[5] by 24 bits to the left will be promoted to a 32 bit signed int and then sign-extended to an unsigned long. If the top bit of buf[5] is set then all then all the upper bits sec end up as also being set because of the sign-extension. Fix this by casting buf[5] to an unsigned long before the shift. Detected by CoverityScan, CID#1465292 ("Unintended sign extension") Fixes: 0e1492330cd2 ("rtc: add rtc-tx4939 driver") Signed-off-by: Colin Ian King Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-tx4939.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/rtc/rtc-tx4939.c +++ b/drivers/rtc/rtc-tx4939.c @@ -86,7 +86,8 @@ static int tx4939_rtc_read_time(struct d for (i = 2; i < 6; i++) buf[i] = __raw_readl(&rtcreg->dat); spin_unlock_irq(&pdata->lock); - sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; + sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | + (buf[3] << 8) | buf[2]; rtc_time_to_tm(sec, tm); return rtc_valid_tm(tm); } @@ -147,7 +148,8 @@ static int tx4939_rtc_read_alarm(struct alrm->enabled = (ctl & TX4939_RTCCTL_ALME) ? 1 : 0; alrm->pending = (ctl & TX4939_RTCCTL_ALMD) ? 1 : 0; spin_unlock_irq(&pdata->lock); - sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; + sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | + (buf[3] << 8) | buf[2]; rtc_time_to_tm(sec, &alrm->time); return rtc_valid_tm(&alrm->time); }