Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2011170imm; Thu, 24 May 2018 04:29:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZotfgg+SwXW3GKz3CaB3ucJ8inmUtNSPng6RRNjBV7eavTdLGSHxwjqCn292H4FycCJHE0K X-Received: by 2002:a63:a44a:: with SMTP id c10-v6mr5582125pgp.147.1527161369984; Thu, 24 May 2018 04:29:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527161369; cv=none; d=google.com; s=arc-20160816; b=t5Nq9hRLARimEVk6TVmZRoTP9DQhE3Ozy0G7jgaGlQ20sxzKWlrBIbl8Pc7wsWZeDh +/9YXECbMPFgJfdNca4EPY1DMqSGwiRMLfjwOjlXJYXZEhh7NENbdpZ23RMlQ2m1vDh5 Pxa5/5omaXihPKmhh5fD76K/eaW0hUoLbpaKcYxXX9de45iYZxBEDMc+A2m/FLu7ZJJx cNWe5Kkn521PSwqlecQaxU6P19Jk+DaeTVBPVvpwgKnPYT9R/5L328NsZYphOzFhL2dF uit7q540En8+I+eJwhUxAS9HPdGN8Uu8tgU1ut2J+9h/uJDUYbWPO4uEgCDh/teOHKre xjpg== 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=eHGUXDzTPXNMr8Cn3M/j3lRzxhKv8hcSfg/NtndyyPA=; b=TEEdRxw9Mpfr3/IBE+ZivlllbLAjzk9jvGkTAnxiBpINykQnTpOfdnhNFiPXEQxZth LoEYn+VA77h+m+MBw/2zhTs3RYxoPZb1Ky8bXGSFpYCAtNXf6lgp6chpQDUnQrFrEqd/ pv+lCDR1hnNabQHn76FcstwTb63nW7acca7GSvDDvUtnqyZHmhsybqLKBjjRawQWOf2U UZlh5uf6boPRpW8oTicCpBSItFnbpWyoYZ30OmWkPQQhtfu6C3dJE2ZsGc6XqR9/ju9C FMo2bB/gWbALpMC8UFTh1b0anTH4B+5XWDwgUWVOBogqzp+DMFf8QQcN+k+M3qGbgJpK WEDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v3agEVt2; 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 n2-v6si21927612plk.433.2018.05.24.04.29.15; Thu, 24 May 2018 04:29:29 -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=v3agEVt2; 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 S967681AbeEXJvV (ORCPT + 99 others); Thu, 24 May 2018 05:51:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:45324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967646AbeEXJvL (ORCPT ); Thu, 24 May 2018 05:51:11 -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 3314D208B1; Thu, 24 May 2018 09:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155470; bh=TT3sm0c9iVZYC2NFYi6qdFMqj1uhhwyOlH6U+5A7gy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v3agEVt2B3+1gaX7VZH19C/78RsE/OyX+1tm/AQoDVnO3aR2lOWVPNBESFIEEPb/s Sk6DfsBmfWqtCR151sMulgCjMhi/soxiAQyTHlC27642E04B4vbAUlbKgKrmdlBF6d rOkzeU3/VFriz97Aa8F0YIL+U2neyeLa/QSCKlHg= 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.9 96/96] rtc: tx4939: avoid unintended sign extension on a 24 bit shift Date: Thu, 24 May 2018 11:39:19 +0200 Message-Id: <20180524093611.408387540@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@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.9-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); }