From patchwork Tue Oct 27 13:47:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 312061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3E2CC4363A for ; Tue, 27 Oct 2020 17:24:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 725E421D42 for ; Tue, 27 Oct 2020 17:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603819445; bh=DfuOybiE0/kryS5zQ+oUbHWyBHHnPpeSbI96AM6mWTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dyRByNk4WJln4FR002uB5zKM2Q+od/mooZnxBZI+sqyfNG1gUDMjJzSmgWBctCq/A 86ichYAb904tb3fGFUjWdGuheWILTpg1ECOzB8nQG6HDy+QQ3oy7AIgPDB+Fd3n4mX GQ0rTtHwTUyc/gjbu7EaXVZqRqUAQRyBtDNHVpAo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1818825AbgJ0RYE (ORCPT ); Tue, 27 Oct 2020 13:24:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:54726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752297AbgJ0OyU (ORCPT ); Tue, 27 Oct 2020 10:54:20 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 3E72B20679; Tue, 27 Oct 2020 14:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810459; bh=DfuOybiE0/kryS5zQ+oUbHWyBHHnPpeSbI96AM6mWTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QY7N6yXcFIStOc+mimchDILXTK1dtUWWf56UBJNRkt96lok07YMqnnXFbsjvzzZlT 44nu7svfWSDxjBZn7XZcvS6xZo+2oihU7VTvdH5+ud3dBnCge5g85zhGP4RbkQ/DCh 9QoggF+llSBcxMTeQeGr2SZwC8FNbP1KsSz7qc90= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.8 116/633] media: uvcvideo: Silence shift-out-of-bounds warning Date: Tue, 27 Oct 2020 14:47:39 +0100 Message-Id: <20201027135528.139979505@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Laurent Pinchart [ Upstream commit 171994e498a0426cbe17f874c5c6af3c0af45200 ] UBSAN reports a shift-out-of-bounds warning in uvc_get_le_value(). The report is correct, but the issue should be harmless as the computed value isn't used when the shift is negative. This may however cause incorrect behaviour if a negative shift could generate adverse side effects (such as a trap on some architectures for instance). Regardless of whether that may happen or not, silence the warning as a full WARN backtrace isn't nice. Reported-by: Bart Van Assche Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver") Signed-off-by: Laurent Pinchart Reviewed-by: Bart Van Assche Tested-by: Bart Van Assche Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_ctrl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index e399b9fad7574..a30a8a731eda8 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -773,12 +773,16 @@ static s32 uvc_get_le_value(struct uvc_control_mapping *mapping, offset &= 7; mask = ((1LL << bits) - 1) << offset; - for (; bits > 0; data++) { + while (1) { u8 byte = *data & mask; value |= offset > 0 ? (byte >> offset) : (byte << (-offset)); bits -= 8 - (offset > 0 ? offset : 0); + if (bits <= 0) + break; + offset -= 8; mask = (1 << bits) - 1; + data++; } /* Sign-extend the value if needed. */