From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12405226F70; Wed, 25 Sep 2024 12:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727266620; cv=none; b=VH0wi+oo6dmoqi4DLHtT0zzspjW6en9VHmY6N0i0rtC2WNI1vh9Qqju1Jj/gsxZ4mSAD0XmIhTTXZ1brWC9ibUTRhd24BiKXLRehNOSo0/7+jkYSQGgmCVu4/E4jesU6gdML1h3FObgMERB2tc3Fi+A6XZoFnUfXlP71pd/wHgU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727266620; c=relaxed/simple; bh=gDqMv+RioLF7PDcEFu36rH47/gmJ0ZtLAKnGu6CwhvA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ts933piU9zhlAWZSw23DonUh4K6mq/KQMm/THO8BCUJ41EzLXtczKDlNm4pSsHIIOghJj7IwKKNv9XFBiy4m7JDen415LKx9b1w/KYfUZA97kdq/PRiM0YQHSpHYnCCt3VKPR2w9IKe0I2UT7GZZKDx1bvMwE/Tv5uinHUwAf7c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KpxOPavB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KpxOPavB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98A9CC4CEC7; Wed, 25 Sep 2024 12:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727266619; bh=gDqMv+RioLF7PDcEFu36rH47/gmJ0ZtLAKnGu6CwhvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KpxOPavBD3032/7CXTcrcX0Kh1W4nm4DoewNlRJqIhNN0kirJfQ1v6cgaS/r5ycu5 jwjKMaIVmykSo2GOk3BTi8VufKe6SBLilGqyrRFo5pfBEmDFkPyWW2GlWgILqitf+o mJo1JvhtTQXrD1qtZqD/E+LAUYaP83iJKmt+XcLGGdDTMa73uGZ4hOO3IIR8IJAQEM PXXmpqLke61s3DuiIL9jB1JcrTNk8Zf5vk+Mg9l8hfoQnFpxNcTU+If8jncngVU5k6 CprQkH/ZfBJdeKbuV/PN3g+vu7dtYHqT8xeuPAtOLNTXWEN7cvp4rH74DkRiFd9Hc2 gT30L5ZxWDQjw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alex Hung , Wenjing Liu , Daniel Wheeler , Rodrigo Siqueira , Alex Deucher , Sasha Levin , harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, roman.li@amd.com, hersenxs.wu@amd.com, george.shen@amd.com, allen.pan@amd.com, meenakshikumar.somasundaram@amd.com, stylon.wang@amd.com, michael.strauss@amd.com, aric.cyr@amd.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.6 112/139] drm/amd/display: Avoid overflow assignment in link_dp_cts Date: Wed, 25 Sep 2024 08:08:52 -0400 Message-ID: <20240925121137.1307574-112-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925121137.1307574-1-sashal@kernel.org> References: <20240925121137.1307574-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.52 Content-Transfer-Encoding: 8bit From: Alex Hung [ Upstream commit a15268787b79fd183dd526cc16bec9af4f4e49a1 ] sampling_rate is an uint8_t but is assigned an unsigned int, and thus it can overflow. As a result, sampling_rate is changed to uint32_t. Similarly, LINK_QUAL_PATTERN_SET has a size of 2 bits, and it should only be assigned to a value less or equal than 4. This fixes 2 INTEGER_OVERFLOW issues reported by Coverity. Signed-off-by: Alex Hung Reviewed-by: Wenjing Liu Tested-by: Daniel Wheeler Signed-off-by: Rodrigo Siqueira Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/display/dc/dc_dp_types.h | 2 +- drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c | 3 ++- drivers/gpu/drm/amd/display/include/dpcd_defs.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/dc_dp_types.h b/drivers/gpu/drm/amd/display/dc/dc_dp_types.h index 83719f5bea495..8df52f9ba0b7c 100644 --- a/drivers/gpu/drm/amd/display/dc/dc_dp_types.h +++ b/drivers/gpu/drm/amd/display/dc/dc_dp_types.h @@ -721,7 +721,7 @@ struct dp_audio_test_data_flags { struct dp_audio_test_data { struct dp_audio_test_data_flags flags; - uint8_t sampling_rate; + uint32_t sampling_rate; uint8_t channel_count; uint8_t pattern_type; uint8_t pattern_period[8]; diff --git a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c index fe4282771cd07..8a97d96f7d8bb 100644 --- a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c +++ b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c @@ -849,7 +849,8 @@ bool dp_set_test_pattern( core_link_read_dpcd(link, DP_TRAINING_PATTERN_SET, &training_pattern.raw, sizeof(training_pattern)); - training_pattern.v1_3.LINK_QUAL_PATTERN_SET = pattern; + if (pattern <= PHY_TEST_PATTERN_END_DP11) + training_pattern.v1_3.LINK_QUAL_PATTERN_SET = pattern; core_link_write_dpcd(link, DP_TRAINING_PATTERN_SET, &training_pattern.raw, sizeof(training_pattern)); diff --git a/drivers/gpu/drm/amd/display/include/dpcd_defs.h b/drivers/gpu/drm/amd/display/include/dpcd_defs.h index aee5170f5fb23..c246235e4afec 100644 --- a/drivers/gpu/drm/amd/display/include/dpcd_defs.h +++ b/drivers/gpu/drm/amd/display/include/dpcd_defs.h @@ -76,6 +76,7 @@ enum dpcd_phy_test_patterns { PHY_TEST_PATTERN_D10_2, PHY_TEST_PATTERN_SYMBOL_ERROR, PHY_TEST_PATTERN_PRBS7, + PHY_TEST_PATTERN_END_DP11 = PHY_TEST_PATTERN_PRBS7, PHY_TEST_PATTERN_80BIT_CUSTOM,/* For DP1.2 only */ PHY_TEST_PATTERN_CP2520_1, PHY_TEST_PATTERN_CP2520_2, -- 2.43.0