Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1930287imm; Thu, 24 May 2018 03:07:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoagCJyr0LQNNFLpSTg3SM/jvDrS8K9K+eI0Cb9KmhSIU0rBNngOnaHlM+lomOBBCODDeRx X-Received: by 2002:a62:4b16:: with SMTP id y22-v6mr6609401pfa.29.1527156430642; Thu, 24 May 2018 03:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527156430; cv=none; d=google.com; s=arc-20160816; b=hcPi5/QifE8wMdX5oQ0jGc59sgGeVI3oUuyK7CUSN81JLIhGEwB2O06Qv62qdthRg5 5W+ETVGLk67nh6hz9H4gfpQZxWzxtKolg8BmHPyqeROD4aVGrXDfGnoCS4x13SrMgAvl xMs0SbXwoMOLUl2uTezVrZqNmOgvANK/pS8PJ7O0GiSyNZMx3b20pMtMp8aBv3lylBPh sieabX68pmEiiEe/0uIQUOQDIc61wEpyr6UXjXd7SwxedD9YcOTpB29dU86BQLaQCRk1 2fk0w8dFTdg2p5Y9UhA6yX9CluvAI0O1zuer/kMST0VqQ2nXKObISs4h9AaGBQH5sVjm 6Xpg== 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=Js7B6BaTtD/N1W1o+wMVSR6lIw4lovIpZtuSq+X75Bc=; b=0XBAQ+3/Yee9tqp8OzcjGcioE5IFkCGHj0/XvOqZkO/GDdKI8EZ2e68cFL26wBxnK3 0lPcfHO/z1M6D/z/gfmpqvf1VUOxRYAUPRc/+YVKv3jMRxEnQd/Wi+fUMiVLPebLuO7A AiXVr08M0dehmBb0IjcJF8z4YdbITsqy5+7nSMIaORVQ002GxkyjsOWckD9YarS9twWO 72oJlwDGNVGsTVBZF3MKDAfr0HqwOm9s6Pi4I4gZl7D6tRaoLlObbT2q5idUTcvIiL1q ibAID5fZLzA1ANexCM6T3BtiVTTuDXB759EqqWAoXL5jJzgUcHV5dzkFvBd1qnDl0Yz8 UP6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RhsCgXwJ; 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 v10-v6si20909703plo.150.2018.05.24.03.06.56; Thu, 24 May 2018 03:07:10 -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=RhsCgXwJ; 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 S1031699AbeEXKGO (ORCPT + 99 others); Thu, 24 May 2018 06:06:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:55076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031659AbeEXKGC (ORCPT ); Thu, 24 May 2018 06:06:02 -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 5088C20870; Thu, 24 May 2018 10:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527156361; bh=URnYOGDAm+5lUM11cKPjariIvSbOUBQ0C/kL5QqjH0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RhsCgXwJhshJJ2Xjioyk0aLmeRgI7R/lEw3zqlXriRxWhrz3vIsqm0cJSfH/XXGdc apdWPCxqvNTB9wnuUUhKhkpHAL9a63gY44NsUMGJqrmOGK/wKWb1y7mA4fDZSSRArZ hNjGDFBYSWSMLiii9aagp3J57NIrDPTApJtOM6wQ= 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.16 159/161] rtc: tx4939: avoid unintended sign extension on a 24 bit shift Date: Thu, 24 May 2018 11:39:44 +0200 Message-Id: <20180524093037.282773399@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@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.16-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); }