From: Levi Yun <ppbuk5246@gmail.com>
To: keescook@chromium.org, ebiederm@xmission.com, viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Levi Yun <ppbuk5246@gmail.com>
Subject: [PATCH] fs/exec.c: Avoid a race in formats
Date: Thu, 24 Feb 2022 08:17:52 +0900 [thread overview]
Message-ID: <20220223231752.52241-1-ppbuk5246@gmail.com> (raw)
Suppose a module registers its own binfmt (custom) and formats is like:
+---------+ +----------+ +---------+
| custom | -> | format1 | -> | format2 |
+---------+ +----------+ +---------+
and try to call unregister_binfmt with custom NOT in __exit stage.
In that situation, below race scenario can happen.
CPU 0 CPU1
search_binary_handler ...
read_lock unregister_binfmt(custom)
list_for_each_entry < wait >
(get custom binfmt) ...
read_unlock ...
... list_del
custom binfmt return -ENOEXEC
get next fmt entry (LIST_POISON1)
Because CPU1 set the fmt->lh.next as LIST_POISON1,
CPU 0 get next binfmt as LIST_POISON1.
In that situation, CPU0 try to dereference LIST_POISON1 address and
makes PANIC.
To avoid this situation, check the fmt is valid.
And if it isn't valid, return -EAGAIN.
Signed-off-by: Levi Yun <ppbuk5246@gmail.com>
---
fs/exec.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/exec.c b/fs/exec.c
index 79f2c9483302..2042a1232656 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1720,6 +1720,12 @@ static int search_binary_handler(struct linux_binprm *bprm)
retry:
read_lock(&binfmt_lock);
list_for_each_entry(fmt, &formats, lh) {
+ if (fmt == LIST_POISON1) {
+ read_unlock(&binfmt_lock);
+ retval = -EAGAIN;
+ break;
+ }
+
if (!try_module_get(fmt->module))
continue;
read_unlock(&binfmt_lock);
--
2.34.1
next reply other threads:[~2022-02-23 23:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 23:17 Levi Yun [this message]
2022-02-23 23:24 ` Al Viro
2022-02-23 23:59 ` Yun Levi
2022-02-24 0:10 ` Yun Levi
2022-02-24 0:41 ` Eric W. Biederman
2022-02-24 0:51 ` Yun Levi
2022-02-24 2:24 ` Eric W. Biederman
2022-02-24 2:28 ` Yun Levi
2022-02-24 3:00 ` Al Viro
2022-02-24 3:13 ` Yun Levi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220223231752.52241-1-ppbuk5246@gmail.com \
--to=ppbuk5246@gmail.com \
--cc=ebiederm@xmission.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®