From mboxrd@z Thu Jan 1 00:00:00 1970 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=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 BF5A1C11F72 for ; Tue, 6 Jul 2021 11:34:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A655C608FC for ; Tue, 6 Jul 2021 11:34:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237246AbhGFLgC (ORCPT ); Tue, 6 Jul 2021 07:36:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:35298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233563AbhGFL0F (ORCPT ); Tue, 6 Jul 2021 07:26:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 36D9161363; Tue, 6 Jul 2021 11:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625570381; bh=Rq6Vllx5aizCaYRvGFri4AYkM3uXqJdalDaJzcbLmwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O8Uw1ttOyu6RXwDQAY4ou+z6T+tEqATtza6KcuX9sACNGBTCzdI2SSYBZU/hwPQ7P 43nNIN/Ezp/PTlQedNwm8ZNPQQyYk1CA0EdDpT/jeusqoYeao4tlyThJpxA0o2HJcP OfX2QI+uYeS0MpZVybBTT1f4gv+B5dKCi4kjxnhrDfkqwZ7JLEQ4VGo3954xAB19sU ALwyJcPe6nZVwM8B0k6xH6dyB250MUs9Df4XKslR4uDyubaP9KVkbXW3anVJhDRwD1 YlVvsKGu+LK3YYHPGVleLpz/v7A0oEe2A42dhLjLtQMm9KNHuMxgSOXgrLFTqyA2LU muQqw5JjYH0EA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Alex Deucher , Sasha Levin , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.12 056/160] drm/amd/display: Avoid HDCP over-read and corruption Date: Tue, 6 Jul 2021 07:16:42 -0400 Message-Id: <20210706111827.2060499-56-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706111827.2060499-1-sashal@kernel.org> References: <20210706111827.2060499-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit 06888d571b513cbfc0b41949948def6cb81021b2 ] Instead of reading the desired 5 bytes of the actual target field, the code was reading 8. This could result in a corrupted value if the trailing 3 bytes were non-zero, so instead use an appropriately sized and zero-initialized bounce buffer, and read only 5 bytes before casting to u64. Signed-off-by: Kees Cook Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c b/drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c index 73ca49f05bd3..eb56526ec32c 100644 --- a/drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c +++ b/drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c @@ -29,8 +29,10 @@ static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp) { uint64_t n = 0; uint8_t count = 0; + u8 bksv[sizeof(n)] = { }; - memcpy(&n, hdcp->auth.msg.hdcp1.bksv, sizeof(uint64_t)); + memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv)); + n = *(uint64_t *)bksv; while (n) { count++; -- 2.30.2