From: Luis Chamberlain <mcgrof@kernel.org>
To: Lukas Middendorf <kernel@tuxforce.de>,
Greg KH <gregkh@linuxfoundation.org>,
dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org, Antti Palosaari <crope@iki.fi>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org
Subject: Re: Is request_firmware() really safe to call in resume callback when /usr/lib/firmware is on btrfs?
Date: Sat, 3 Apr 2021 21:04:44 +0000 [thread overview]
Message-ID: <20210403210444.GU13911@42.do-not-panic.com> (raw)
In-Reply-To: <20210403202538.GW4332@42.do-not-panic.com>
On Sat, Apr 03, 2021 at 08:25:38PM +0000, Luis Chamberlain wrote:
> So creating say 1000 random files in /lib/firmware on a freshly created
> btrfs partition helps reproduce:
>
> mkfs.btrfs /dev/whatever
> mount /dev/wahtever /lib/firmware
> # Put it on /etc/fstab too
>
> Generate 1000 random files on it:
>
> ```
> for n in {1..1000}; do
> dd if=/dev/urandom of=/lib/firmware/file$( printf %03d "$n" ).bin bs=1 count=$((RANDOM + 1024 ))
> done
> ```
>
> Then reboot, upon reboot do:
>
> modprobe test_firmware
> echo 1 > /sys/devices/virtual/misc/test_firmware/config_enable_resume_test
> systemctl suspend
OK this fixes it but this just shows that likely the thaw'ing allows
a race to take place which we didn't expect. I'll do some more digging
for a proper fix.
diff --git a/fs/kernel_read_file.c b/fs/kernel_read_file.c
index 90d255fbdd9b..b9c37eefab35 100644
--- a/fs/kernel_read_file.c
+++ b/fs/kernel_read_file.c
@@ -4,6 +4,7 @@
#include <linux/kernel_read_file.h>
#include <linux/security.h>
#include <linux/vmalloc.h>
+#include <linux/umh.h>
/**
* kernel_read_file() - read file contents into a kernel buffer
@@ -156,17 +157,25 @@ int kernel_read_file_from_path_initns(const char *path, loff_t offset,
if (!path || !*path)
return -EINVAL;
+ ret = usermodehelper_read_trylock();
+ if (WARN_ON(ret)) {
+ pr_warn_once("Trying to do direct read when not available");
+ return ret;
+ }
task_lock(&init_task);
get_fs_root(init_task.fs, &root);
task_unlock(&init_task);
file = file_open_root(root.dentry, root.mnt, path, O_RDONLY, 0);
path_put(&root);
- if (IS_ERR(file))
+ if (IS_ERR(file)) {
+ usermodehelper_read_unlock();
return PTR_ERR(file);
+ }
ret = kernel_read_file(file, offset, buf, buf_size, file_size, id);
fput(file);
+ usermodehelper_read_unlock();
return ret;
}
EXPORT_SYMBOL_GPL(kernel_read_file_from_path_initns);
next prev parent reply other threads:[~2021-04-03 21:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-09 18:51 Is request_firmware() really safe to call in resume callback when /usr/lib/firmware is on btrfs? Lukas Middendorf
2020-08-13 16:37 ` Luis Chamberlain
2020-08-13 21:53 ` Lukas Middendorf
2020-08-13 22:13 ` Luis Chamberlain
2020-08-14 11:38 ` Lukas Middendorf
2020-08-14 16:37 ` Luis Chamberlain
2020-08-14 21:59 ` Lukas Middendorf
2020-08-17 15:20 ` Luis Chamberlain
2020-08-17 22:04 ` Lukas Middendorf
2020-08-18 14:37 ` Luis Chamberlain
2021-04-01 14:59 ` Lukas Middendorf
2021-04-02 18:02 ` Luis Chamberlain
2021-04-02 22:19 ` Luis Chamberlain
2021-04-02 22:58 ` Luis Chamberlain
2021-04-03 10:24 ` Lukas Middendorf
2021-04-03 16:07 ` Lukas Middendorf
2021-04-03 20:25 ` Luis Chamberlain
2021-04-03 21:04 ` Luis Chamberlain [this message]
2021-04-05 9:52 ` Lukas Middendorf
2021-04-04 0:50 ` Lukas Middendorf
2021-04-08 18:02 ` Luis Chamberlain
2021-04-16 23:17 ` Luis Chamberlain
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=20210403210444.GU13911@42.do-not-panic.com \
--to=mcgrof@kernel.org \
--cc=crope@iki.fi \
--cc=dsterba@suse.cz \
--cc=gregkh@linuxfoundation.org \
--cc=kernel@tuxforce.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.