Skip to content

os/kernel/semaphore: avoid probable memory corruption.#7192

Merged
ewoodev merged 1 commit intoSamsung:masterfrom
singh-aditya-04:security_fix
Mar 19, 2026
Merged

os/kernel/semaphore: avoid probable memory corruption.#7192
ewoodev merged 1 commit intoSamsung:masterfrom
singh-aditya-04:security_fix

Conversation

@singh-aditya-04
Copy link
Copy Markdown
Contributor

if the number of threads exceed the CONFIG_SEM_NNESTPRIO it can cause the static array defined in TCB to overflow and cause corruption in tcb data.

To avoid this, restrict the sched priority information upto CONFIG_SEM_NNESTPRIO threads only and print error log if it exceeds.

struct tcb_s {

    uint8_t npend_reprio;           /* Number of nested reprioritizations  */
    uint8_t pend_reprios[CONFIG_SEM_NNESTPRIO];
    uint8_t base_priority;          /* "Normal" priority of the thread     */

}

Reproduction log details:

[Attacker-79] Started
[Attacker-71] Triggering else branch (prio 71)
sem_boostholderprio: npend_reprio:21 << Debug print added to print number of threads waiting
[Attacker-80] Started
[Attacker-72] Triggering else branch (prio 72)
sem_boostholderprio: npend_reprio:22 << This exceeds the CONFIG value of 16
[Attacker-81] Started
[Attacker-73] Triggering else branch (prio 73)
sem_boostholderprio: npend_reprio:23
[Attacker-82] Started

@singh-aditya-04 singh-aditya-04 force-pushed the security_fix branch 3 times, most recently from 54e57f2 to 023601a Compare March 18, 2026 09:12
Comment thread os/wqueue/kwqueue/kwork_inherit.c Outdated
if (wtcb->npend_reprio < CONFIG_SEM_NNESTPRIO) {
wtcb->pend_reprios[wtcb->npend_reprio] = reqprio;
wtcb->npend_reprio++;
} else {
Copy link
Copy Markdown
Contributor

@vivek1-j vivek1-j Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check indentation.
Line 146 and 148

if the number of threads exceed the CONFIG_SEM_NNESTPRIO
it can cause the static array defined in TCB to overflow
and cause corruption in tcb data.

To avoid this, restrict the sched priority information upto
CONFIG_SEM_NNESTPRIO threads only and print error log if it exceeds.

struct tcb_s {
---------------------------------------
        uint8_t npend_reprio;           /* Number of nested reprioritizations  */
        uint8_t pend_reprios[CONFIG_SEM_NNESTPRIO];
        uint8_t base_priority;          /* "Normal" priority of the thread     */
--------------------------------------
}

Reproduction log details:

[Attacker-79] Started
[Attacker-71] Triggering else branch (prio 71)
sem_boostholderprio: npend_reprio:21                  << Debug print added to print number of threads waiting
[Attacker-80] Started
[Attacker-72] Triggering else branch (prio 72)
sem_boostholderprio: npend_reprio:22                 << This exceeds the CONFIG value of 16
[Attacker-81] Started
[Attacker-73] Triggering else branch (prio 73)
sem_boostholderprio: npend_reprio:23
[Attacker-82] Started

Signed-off-by: Aditya Singh <aditya.s4@samsung.com>
Signed-off-by: Aashish Lakhwara <aashish.l@samsung.com>
@ewoodev ewoodev merged commit 4860dbd into Samsung:master Mar 19, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants