logger: fix log->mutex + misc_mtx ab-ba deadlock 41/270041/1 accepted/tizen/unified/20220126.042654 submit/tizen/20220125.030100
authorŁukasz Stelmach <l.stelmach@samsung.com>
Mon, 24 Jan 2022 13:53:39 +0000 (14:53 +0100)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Mon, 24 Jan 2022 20:38:33 +0000 (21:38 +0100)
commit930977afe0e2ff5dac0b5aa78e6a1f59b9643067
tree84e6b48a4d2caebb5698799937460189f3f6902f
parent2a1b7faca59fe91191481e55f436dc4e187ffa5a
logger: fix log->mutex + misc_mtx ab-ba deadlock

When a forked process reopens a file for stdio logging during the first write(2)
after a fork(2), it holds log->mutex when it calls filp_open() which
in turn calls misc_open(). misc_open() takes misc_mtx.

If at the same time (after acquiring log->mutex and before misc_open()
is called) another process (e.g. dlogutil) opens the same logger
device for reading (open(2) -> misc_open() -> logger_open() ->
mutex_lock(log->mutex)), a race condition and a AB-BA deadlock occurs. To
avoid it log->mutex is released before calling make_new_file() and
reaquired after. It is safe to do so, because the log structure isn't
accessed.

Change-Id: Ibaab2947638997dca82c0e47146f77ce0f1bee57
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
kernel/logger.c