Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2419187pxv; Sun, 11 Jul 2021 12:51:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/umVmUSYgIPT9b75fZCoGUP9X1PqSEZxhLtb1Af8P7gOPj1lzB/wtOkqVFdv3Z1VKDdmv X-Received: by 2002:a02:8521:: with SMTP id g30mr41149930jai.113.1626033080325; Sun, 11 Jul 2021 12:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626033080; cv=none; d=google.com; s=arc-20160816; b=Gbd0QVgGpfSFKjZwnlzYjHTjYmitgimGAcZTwcbVvxoV6YtqbrOcyKqfhf44LUyJUU JHThHrG971Co9doy+SMtYRceCowpRgA1XjxU/WSy9caIsVjlUaeknO1m0oSmob4+dH4w RbRa6L97YlfqZqcPp/fDClRkZxvSalIsr1N6ICIsTlDbH8zczIorRnK7kC7/Vb6NAPLL B5gsv2zUW1uCRPlAGC1aUvraBNiNuiB0CAmfRF6t9BUs3B0+yd30NYRxNfThN4jd09Z3 YlpsH9k+OwDjuhuToyYikGMoslcxLB7cXF1iD7vL6XG+LhtmJ+BHR/Dggredxy4J0Zzd EXZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:date:cc:to:from:subject:message-id; bh=HjIxvmK2PurHCNc5EpjRFwa/0rgwh4iST7QZPG85ig0=; b=rJCgmziwSZ/aOnLijFG6UCRJETrgFzpzWN0lOPy3sIGpPBkEXH+xVPR1Cpzw7IwHZ7 QrVHTUkaHXQWUkwnd3Xs4NYhtSj7aQDVAtaKi/6hPgI/4O/gdhR20AhtMPr4ylAMC3i2 pOUGzsKEvHPu70nmDyy11L56Fi148xvRqjX9ES/47X8+xqgRb5+NxuCNENNfVzFTdfbs Y718gJqliz2F5hgupuW+09x62O40Is/ys3rf17Fa7pWgCVwF7R5z1cRG8LycIfmeEHxO u2Teb43OHDesz44CMtOrbtR9L5GJ2CShbwFm6ipct3ZnhGg4alNC+9jNSE/+zoj0aFEY MFYw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si8603805ilg.108.2021.07.11.12.50.42; Sun, 11 Jul 2021 12:51:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbhGKTtD (ORCPT + 99 others); Sun, 11 Jul 2021 15:49:03 -0400 Received: from smtprelay0096.hostedemail.com ([216.40.44.96]:37884 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229544AbhGKTtC (ORCPT ); Sun, 11 Jul 2021 15:49:02 -0400 Received: from omf11.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 1FECF1834334A; Sun, 11 Jul 2021 19:46:15 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA id 1461720A295; Sun, 11 Jul 2021 19:46:13 +0000 (UTC) Message-ID: Subject: drm/amd/display: Simplify hdcp validate_bksv From: Joe Perches To: Bhawanpreet Lakha Cc: Kees Cook , Alex Deucher , amd-gfx@lists.freedesktop.org, dri-devel , LKML Date: Sun, 11 Jul 2021 12:46:12 -0700 Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=0.10 X-Stat-Signature: 539sh6xq8seofo8ke64ezq5hhueemyjt X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: 1461720A295 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX199Uq/CjUUQdOfJPyou+ohMOJSTDeqoedM= X-HE-Tag: 1626032773-460936 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 06888d571b51 ("drm/amd/display: Avoid HDCP over-read and corruption") fixed an overread with an invalid buffer length but added an unnecessary buffer and copy. Simplify the code by using a single uint64_t and __builtin_popcountll to count the number of bits set in the original bksv buffer instead of a loop. This also avoid a possible unaligned access of the temporary bksv. Signed-off-by: Joe Perches --- It seems quite odd 20 bits set is a magic number here. Should it be a specific be/le value instead? drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) 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 de872e7958b06..78a4c6dd95d99 100644 --- a/drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c +++ b/drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c @@ -28,17 +28,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(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv)); - n = *(uint64_t *)bksv; + memcpy(&n, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv)); - while (n) { - count++; - n &= (n - 1); - } - return (count == 20) ? MOD_HDCP_STATUS_SUCCESS : + return (__builtin_popcountll(n) == 20) ? MOD_HDCP_STATUS_SUCCESS : MOD_HDCP_STATUS_HDCP1_INVALID_BKSV; }