Commit a082d39
committed
rtos: string: Add memory barrier to memset_s for security
Add Xtensa memory barrier (memw) instruction after memset() in
memset_s() implementation to prevent compiler dead store elimination
(DSE) optimization from removing the memory clearing operation.
When optimization flags like -O2 are enabled, compilers may perform dead
store elimination and incorrectly remove memset() calls used for
security purposes to scrub sensitive data from memory. This is critical
for confidential data handling where memory must be reliably cleared
after use.
The memory barrier ensures the memset operation completes and cannot be
optimized away, satisfying secure memory scrubbing requirements for
cryptographic operations and sensitive data processing.
Additionally, the patch removes the check for the return value of
memset. The standard C library memset always returns the pointer passed
as its first argument and does not indicate errors through its return
value. Error handling for a NULL destination is already performed
earlier in the function, so the return value check is unnecessary and
can be safely omitted.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>1 parent d6a2a4d commit a082d39
1 file changed
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
74 | 80 | | |
75 | 81 | | |
76 | 82 | | |
| |||
0 commit comments