<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style="--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>
GitLab
</title>
<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>
<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style="font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";">
<div class="content">
<p style="color: #777777;">
<a href="https://gitlab.rtems.org/D3athSkulll">SHIVAM DEOLANKAR</a>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5558#note_149044">commented</a>:
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Inspected bsps/arm/ the <strong style="font-weight: 600; margin-top: 0;">imxrt</strong> , <strong style="font-weight: 600;">efm32gg11</strong>, <strong style="font-weight: 600;">atsam , csb337 , csb336, stm32h7,</strong> <strong style="font-weight: 600;">stm32u5</strong> driver needs a fix, rest 2 drivers seemed fine.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">On reviewing console.c for arm/imxrt . Initially, the driver appeared safe as it delegates baud handling to the HAL. However, <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">LPUART_Init()</code> in <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">imxrt/mcux-sdk/drivers/lpuart/fsl_lpuart.c </code>performs division using the baud rate and only guards it with an assertion. Since assertions may be disabled, passing baud rate 0 can lead to divide-by-zero. Needs explicit check to reject baud rate 0 before calling the HAL.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">On reviewing console.c for <strong style="font-weight: 600; margin-top: 0;">arm/efm32gg11.</strong> The function passes baud directly to <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">attribs_init()</code>, where it is used in a division (<code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">/ baud</code>) without validation. If baud is 0, this results in a divide-by-zero. Needs explicit guard to reject baud rate 0 before calling <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">attribs_init()</code>.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Reviewed console.c for <strong style="font-weight: 600; margin-top: 0;">arm/atsam</strong>. It suffers from same issue. There is no guard and it performs division without any check. Needs explicit guard to reject baud rate 0.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Reviewed usart.c for <strong style="font-weight: 600; margin-top: 0;">arm/csb337 .</strong> Although a fallback baud is used when <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">B0</code> is provided, there is no guarantee the resulting baud is non-zero. The value is used in a division (<code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">/ baud</code>) without validation, which may lead to divide-by-zero. Needs explicit guard after conversion.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Reviewed uart.c for <strong style="font-weight: 600; margin-top: 0;">arm/csb336</strong> . The function passes baud directly to <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">imx_uart_set_baud()</code>, where it is used in a division (<code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">ref_freq / baud</code>) without validation. If baud is 0, this leads to a divide-by-zero. Added explicit guard to reject baud rate 0.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Reviewed console.c for <strong style="font-weight: 600; margin-top: 0;">arm/stm32h7</strong>. The function passes baud rate directly to <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">UART_SetConfig()</code>, which internally computes hardware parameters. Since baud rate 0 is not validated and may lead to divide-by-zero inside the HAL, this is solved by an explicit guard to reject baud rate 0 before calling the HAL.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Reviewing console.c for <strong style="font-weight: 600; margin-top: 0;">arm/stm32u5.</strong> The function passes baud rate directly to <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">UART_SetConfig()</code>, which internally computes hardware parameters. Since baud rate 0 is not validated and may lead to divide-by-zero inside the HAL, This also requires an explicit guard to reject baud rate 0 before calling the HAL.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">____________________________________________________________________________________</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">On reviewing console-config.c for <strong style="font-weight: 600; margin-top: 0;">arm/imx.</strong> Baud-dependent calculations are guarded with <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">if (baud != 0)</code>, ensuring no divide-by-zero occurs. B0 is safely ignored. No changes required.</p>
<p dir="auto" style="color: #3a383f; margin: 0;" align="initial">On reviewing hsu.c for <strong style="font-weight: 600; margin-top: 0;">arm/lpc32xx.</strong> No changes required since the case is handled like imx.</p>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5558#note_149044">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/3-4kd2velnyl180lux7btma8l3w/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5558#note_149044 at 1777090681
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5558#note_149044"}}</script>
</p>
</div>
</body>
</html>