<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
font-size:10.0pt;
font-family:"Courier New";}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:Consolas;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}
span.EmailStyle23
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> SHANMUGAM, SRINIVASAN <br>
<b>Sent:</b> Tuesday, January 30, 2024 3:18 PM<br>
<b>To:</b> Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com>; Pillai, Aurabindo <Aurabindo.Pillai@amd.com><br>
<b>Cc:</b> Cyr, Aric <Aric.Cyr@amd.com>; amd-gfx@lists.freedesktop.org; Somasundaram, Meenakshikumar <Meenakshikumar.Somasundaram@amd.com>; Huang, PeiChen (Pei-Chen) <PeiChen.Huang@amd.com><br>
<b>Subject:</b> Re: [PATCH] drm/amd/display: Fix buffer overflow in 'get_host_router_total_dp_tunnel_bw()'<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoPlainText">+ Cc: Tom Chung <<a href="mailto:chiahsuan.chung@amd.com">chiahsuan.chung@amd.com</a>><o:p></o:p></p>
<div>
<p class="MsoNormal">On 1/29/2024 9:19 PM, Srinivasan Shanmugam wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>The error message buffer overflow 'dc->links' 12 <= 12 suggests that the<o:p></o:p></pre>
<pre>code is trying to access an element of the dc->links array that is<o:p></o:p></pre>
<pre>beyond its bounds. In C, arrays are zero-indexed, so an array with 12<o:p></o:p></pre>
<pre>elements has valid indices from 0 to 11. Trying to access dc->links[12]<o:p></o:p></pre>
<pre>would be an attempt to access the 13th element of a 12-element array,<o:p></o:p></pre>
<pre>which is a buffer overflow.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>To fix this, ensure that the loop does not go beyond the last valid<o:p></o:p></pre>
<pre>index when accessing dc->links[i + 1] by subtracting 1 from the loop<o:p></o:p></pre>
<pre>condition.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>This would ensure that i + 1 is always a valid index in the array.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Fixes the below:<o:p></o:p></pre>
<pre>drivers/gpu/drm/amd/amdgpu/../display/dc/link/protocols/link_dp_dpia_bw.c:208 get_host_router_total_dp_tunnel_bw() error: buffer overflow 'dc->links' 12 <= 12<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Fixes: 9ed0893b7c58 ("drm/amd/display: Add dpia display mode validation logic")<o:p></o:p></pre>
<pre>Cc: PeiChen Huang <a href="mailto:peichen.huang@amd.com"><peichen.huang@amd.com></a><o:p></o:p></pre>
<pre>Cc: Aric Cyr <a href="mailto:aric.cyr@amd.com"><aric.cyr@amd.com></a><o:p></o:p></pre>
<pre>Cc: Rodrigo Siqueira <a href="mailto:rodrigo.siqueira@amd.com"><rodrigo.siqueira@amd.com></a><o:p></o:p></pre>
<pre>Cc: Aurabindo Pillai <a href="mailto:aurabindo.pillai@amd.com"><aurabindo.pillai@amd.com></a><o:p></o:p></pre>
<pre>Cc: Meenakshikumar Somasundaram <a href="mailto:meenakshikumar.somasundaram@amd.com"><meenakshikumar.somasundaram@amd.com></a><o:p></o:p></pre>
<pre>Signed-off-by: Srinivasan Shanmugam <a href="mailto:srinivasan.shanmugam@amd.com"><srinivasan.shanmugam@amd.com></a><o:p></o:p></pre>
<pre>---<o:p></o:p></pre>
<pre> drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c | 2 +-<o:p></o:p></pre>
<pre> 1 file changed, 1 insertion(+), 1 deletion(-)<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c<o:p></o:p></pre>
<pre>index dd0d2b206462..5491b707cec8 100644<o:p></o:p></pre>
<pre>--- a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c<o:p></o:p></pre>
<pre>+++ b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c<o:p></o:p></pre>
<pre>@@ -196,7 +196,7 @@ static int get_host_router_total_dp_tunnel_bw(const struct dc *dc, uint8_t hr_in<o:p></o:p></pre>
<pre> struct dc_link *link_dpia_primary, *link_dpia_secondary;<o:p></o:p></pre>
<pre> int total_bw = 0;<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<pre>- for (uint8_t i = 0; i < MAX_PIPES * 2; ++i) {<o:p></o:p></pre>
<pre>+ for (uint8_t i = 0; i < (MAX_PIPES * 2) - 1; ++i) {<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<pre> if (!dc->links[i] || dc->links[i]->ep_type != DISPLAY_ENDPOINT_USB4_DPIA)<o:p></o:p></pre>
<pre> continue;<o:p></o:p></pre>
</blockquote>
</div>
</div>
</body>
</html>