Skip to content

Commit fb24b62

Browse files
nordic-krchcfriedt
authored andcommitted
logging: Fix user space crash when runtime filtering is on
Logging module data (including filters) are not accessible by the user space. Macro for creating logs where creating local variable with filters before checking is we are in the user context. It was not used in that case but creating variable was violating access writes that resulted in failure. Removing variable creation and using filters directly in the if clause but after checking condition that it is not the user context. With this approach data is accessed only in the kernel mode. Cherry-picked with modifications from 4ee59e2. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 60e7a97 commit fb24b62

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

include/logging/log_core.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,8 @@ static inline char z_log_minimal_level_to_char(int level)
302302
} \
303303
\
304304
bool is_user_context = k_is_user_context(); \
305-
uint32_t filters = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
306-
(_dsource)->filters : 0;\
307305
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && !is_user_context && \
308-
_level > Z_LOG_RUNTIME_FILTER(filters)) { \
306+
_level > Z_LOG_RUNTIME_FILTER((_dsource)->filters)) { \
309307
break; \
310308
} \
311309
if (IS_ENABLED(CONFIG_LOG2)) { \
@@ -347,8 +345,6 @@ static inline char z_log_minimal_level_to_char(int level)
347345
break; \
348346
} \
349347
bool is_user_context = k_is_user_context(); \
350-
uint32_t filters = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
351-
(_dsource)->filters : 0;\
352348
\
353349
if (IS_ENABLED(CONFIG_LOG_MINIMAL)) { \
354350
Z_LOG_TO_PRINTK(_level, "%s", _str); \
@@ -357,7 +353,7 @@ static inline char z_log_minimal_level_to_char(int level)
357353
break; \
358354
} \
359355
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && !is_user_context && \
360-
_level > Z_LOG_RUNTIME_FILTER(filters)) { \
356+
_level > Z_LOG_RUNTIME_FILTER((_dsource)->filters)) { \
361357
break; \
362358
} \
363359
if (IS_ENABLED(CONFIG_LOG2)) { \

0 commit comments

Comments
 (0)