Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1966688imm; Thu, 24 May 2018 03:44:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpRzcVq6N0neykMSzZmQAFrKtzNZe/mb+1HMIDFUi9oHcU3DqgVu1vcJRGpG5vbDjtjaC1O X-Received: by 2002:a17:902:2805:: with SMTP id e5-v6mr6924781plb.55.1527158656224; Thu, 24 May 2018 03:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158656; cv=none; d=google.com; s=arc-20160816; b=fvZDosowmCI+bALrjjTq2fgv/6i2wjDKIojX1HArCBRznFsNwDXqUi9lIvv6W/BAin jltaOv7GZVJ/+Ngwi4z2Z5knBRVqp5giEzvSTqJiUt8ifBVJokF4MOiZm3fy1ItxQEkK Xc6/xbwNA+EiBlLG4Y+bCZKLvJg8Cuzpwk7r+luKJzR7fyY0R9tx+EKRa1EpqJujuX+w yLqKEPTrTHNak5KvOoDQbQEwLl4W6Op5Y/UAK6oC8Rxt+phekakKzk5XvdGBdV5ff+hi GZrT7jsQarhAfxnDNFGYw2D8YbQvXKCxqzAALj4JfSEEcy6AsiZFSI9FPzAiuVlW8BIZ Caqw== 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=dX1JMLfsFKbNFftEwprPYzvcrGP8TQTZeCuCk0znzCQ=; b=xZDCzG4yMG+FRdxD6pB+8ljjwUuKPyNMfBfQvzChYXuNVWrpQ68mPakLg3U06c/JqD 5FnwpVh3lKbQ5m782xyYjVgG9dQNtXpNBBAMOlqBARC0tE2G08aGHEsPJm++UfGItZ+Y ZMMeemWBQsxs4hugBWn2SzkSkh/K23sywFgWjoC9LM2ORhkUGZizRUyZjmjJkTAYX5rl BAIZ/6KnjjVDksgaNV85kAP6zrCQPXkZyYjkSHFIboU8XxhTaEzcw7yuxZylZdfLRGBg Rg5w8YgGf5TIkaBH/PwLlOc9UrH00Xb2Jd122+R97Q2vbWk/e7g1cAp06OnkfoacXdpc MlRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C5xTRU5D; 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 i125-v6si11573409pgc.88.2018.05.24.03.44.01; Thu, 24 May 2018 03:44:16 -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=C5xTRU5D; 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 S1032326AbeEXKmV (ORCPT + 99 others); Thu, 24 May 2018 06:42:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:38482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030466AbeEXJ6d (ORCPT ); Thu, 24 May 2018 05:58:33 -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 20C842088E; Thu, 24 May 2018 09:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155912; bh=9pVWjEwKCID7Kvys2QhAjFW7TiLIm5E7iqHe4yIgjms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C5xTRU5DYnJeUfuMzq51RGfXC1ap2j9Yp2JoSwo4QORb0zBjBQh4RcUmXGP/BwTrN r98lAPbr3qiNmGk9ndvwKZBHMeKiqql4cozKpNHFUWWWRT54eAoVhw6GnB4/8RCJnP KCzTAsaey5xEAxk8eJj7hcfCE3kxNWrWjX/Phl74= 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 4.14 163/165] rtc: tx4939: avoid unintended sign extension on a 24 bit shift Date: Thu, 24 May 2018 11:39:29 +0200 Message-Id: <20180524093628.672657652@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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 4.14-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); }