Skip to content

Commit

Permalink
mfdbg, heap_dbg: add security_level on user mode
Browse files Browse the repository at this point in the history
In loadable builds, the user heap and kernel heap operate completely separately.
Only in some cases, such as when an allocation failure occurs during operation in the User Heap,
does the code execute by changing to the kernel area (privileged mode).

However, currently in mm modual, security_level is applied only in kernel area (privileged mode).
Since mm log is designed to output physical memory, it can cause potential security issues,
so if the OS is secure level state, security_level must be applied to not output memory in the user area as well.

Therfore, Change mfdbg and heap_dbg, which output mm logs, to check security_level in all env.

Signed-off-by: eunwoo.nam <eunwoo.nam@samsung.com>
  • Loading branch information
ewoodev authored and sunghan-chang committed Oct 26, 2023
1 parent 9b8c097 commit 0f974de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
20 changes: 9 additions & 11 deletions os/include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,15 @@ int get_errno(void);
#endif

#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
#define mfdbg(format, ...) \
do { \
if (abort_mode) { \
if (!IS_SECURE_STATE()) { \
lldbg(format, ##__VA_ARGS__); \
} \
} else if (up_interrupt_context()) { \
lldbg(format, ##__VA_ARGS__); \
} else { \
dbg(format, ##__VA_ARGS__); \
} \
#define mfdbg(format, ...) \
do { \
if (!IS_SECURE_STATE()) { \
if (abort_mode || up_interrupt_context()) { \
lldbg(format, ##__VA_ARGS__); \
} else { \
dbg(format, ##__VA_ARGS__); \
} \
} \
} while (0)
#else
#define mfdbg(format, ...) dbg(format, ##__VA_ARGS__)
Expand Down
5 changes: 5 additions & 0 deletions os/include/tinyara/security_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ int get_security_level(void);
* This function returns security level.
* If CONFIG_SECURITY_LEVEL is disabled, returns LOW_SECURITY_LEVEL.
****************************************************************************/
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
#define IS_SECURE_STATE() get_security_level()
#else
#define IS_SECURE_STATE() prctl(PR_GET_SECURITY_LEVEL)
#endif

#else
#define IS_SECURE_STATE() (LOW_SECURITY_LEVEL)
#endif
Expand Down
10 changes: 6 additions & 4 deletions os/mm/mm_heap/mm_heap_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@
int heap_dbg(const char *fmt, ...)
{
va_list ap;
int ret = 0;
int ret;

if (IS_SECURE_STATE()) {
return 0;
}

va_start(ap, fmt);
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
extern bool abort_mode;

if (abort_mode) {
if (!IS_SECURE_STATE()) {
ret = lowvsyslog(LOG_ERR, fmt, ap);
}
ret = lowvsyslog(LOG_ERR, fmt, ap);
} else {
ret = vsyslog(LOG_ERR, fmt, ap);
}
Expand Down

0 comments on commit 0f974de

Please sign in to comment.