Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp53499ybg; Mon, 8 Jun 2020 16:13:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaPzkYHRfNiwlmmEMZuCsH3Hrx2vcnBO1SIcKJ2fWW5jx1qNV2zM2qv5CctRulTYPiM92n X-Received: by 2002:aa7:cb8d:: with SMTP id r13mr23388743edt.12.1591658030641; Mon, 08 Jun 2020 16:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591658030; cv=none; d=google.com; s=arc-20160816; b=b+YeNGuZDzKyyNcTY+YhnFwEPi+IIXhoDQrvpF6lyichuLurD3eRL1lor1tzugFBlI c0Ofn8PxWs+NdoiUafSfNcNTSw43hXRO+tOpVhDFGJluju8vWf/Ja74uyFuggI6pEYe5 Pxyfl9WOwPpmZqCXFSOqOvhnwCCwmpETpWDYf2szR19KAVdXshcqFj+WKphaypTg8V6w Yis83P4Cuk0Z9B5+Iqg+HozNwyRNZTxPT7FiM+uOk4LWpDz/BCbyYAbRiujPlIs5wXfO 5iUF0zJj4UVlythxP/h9568YMOdGjWACG6Lg+j1SNCqhnVwNacEB6TUTMAuWTsMoTnSB cYGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rI8zP1D3Ke/HFfzC00Sb9eIPiM0B3aq9e9WJKqrFlsE=; b=S7mt0FcLFYx7ZdZBtt1EYJt/aKWet2D0cg4SCxAJi2e9fqu7NVsYh0KtcdwqUXnVnq Opvdk/unbl8q+g/ZYXQVMcAwKsh2+J0LSt5253iVz9XidC4O07GCRbdyH9RZpFVfBq3e +U1kldOV/Y5O6mNBWcQ3gT/HfNc/x/N/HR2W7RvJgCWqDkLZwt1BB7pvs69KH8w5I4Rr zQtX/QSCIBMRcWGchatRpFnJE4DBZ0zfO3cSR9gIRnh/C2C2I0rjzASkghl/TVyarK28 4ftsdUIBbsroh+LvlUKpzLkK671/X/Ix3PATCHUUz/zRDBg4ofKM2zeniIimU58v+Hcj sHkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZkKoznP8; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si6180954ejk.154.2020.06.08.16.13.27; Mon, 08 Jun 2020 16:13:50 -0700 (PDT) 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=@kernel.org header.s=default header.b=ZkKoznP8; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728799AbgFHXK7 (ORCPT + 99 others); Mon, 8 Jun 2020 19:10:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:55398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727115AbgFHXJh (ORCPT ); Mon, 8 Jun 2020 19:09:37 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F2EF920897; Mon, 8 Jun 2020 23:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657776; bh=IupQNesex1G6SUuR2nZDGISdq1rJoGT1/PvCdy8NC9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZkKoznP8O3+U43v+J9ngmTcky4ycAxrH0fqmvD2u6WPatyEywui/CLk0ry5w3098f MMw4pG7H2zFUAY12arvKGltsUyyi2SH9cClsK+axFO36A+ikuSCEsW6mpOZj4QeEJv i1N3NcCz8++eRxIOg8YYlc2YQtB5Ff3C2G7iIi9c= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dan Carpenter , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 159/274] media: cec: silence shift wrapping warning in __cec_s_log_addrs() Date: Mon, 8 Jun 2020 19:04:12 -0400 Message-Id: <20200608230607.3361041-159-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 3b5af3171e2d5a73ae6f04965ed653d039904eb6 ] The log_addrs->log_addr_type[i] value is a u8 which is controlled by the user and comes from the ioctl. If it's over 31 then that results in undefined behavior (shift wrapping) and that leads to a Smatch static checker warning. We already cap the value later so we can silence the warning just by re-ordering the existing checks. I think the UBSan checker will also catch this bug at runtime and generate a warning. But otherwise the bug is harmless. Fixes: 9881fe0ca187 ("[media] cec: add HDMI CEC framework (adapter)") Signed-off-by: Dan Carpenter Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/cec/cec-adap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/cec/cec-adap.c b/drivers/media/cec/cec-adap.c index 6c95dc471d4c..6a04d19a96b2 100644 --- a/drivers/media/cec/cec-adap.c +++ b/drivers/media/cec/cec-adap.c @@ -1734,6 +1734,10 @@ int __cec_s_log_addrs(struct cec_adapter *adap, unsigned j; log_addrs->log_addr[i] = CEC_LOG_ADDR_INVALID; + if (log_addrs->log_addr_type[i] > CEC_LOG_ADDR_TYPE_UNREGISTERED) { + dprintk(1, "unknown logical address type\n"); + return -EINVAL; + } if (type_mask & (1 << log_addrs->log_addr_type[i])) { dprintk(1, "duplicate logical address type\n"); return -EINVAL; @@ -1754,10 +1758,6 @@ int __cec_s_log_addrs(struct cec_adapter *adap, dprintk(1, "invalid primary device type\n"); return -EINVAL; } - if (log_addrs->log_addr_type[i] > CEC_LOG_ADDR_TYPE_UNREGISTERED) { - dprintk(1, "unknown logical address type\n"); - return -EINVAL; - } for (j = 0; j < feature_sz; j++) { if ((features[j] & 0x80) == 0) { if (op_is_dev_features) -- 2.25.1