From: Qian Cai <quic_qiancai@quicinc.com>
To: "Thiébaud Weksteen" <tweek@google.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jeffrey Vander Stoep <jeffv@google.com>,
Saravana Kannan <saravanak@google.com>,
Alistair Delva <adelva@google.com>,
Adam Shih <adamshih@google.com>, <selinux@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] firmware_loader: use kernel credentials when reading firmware
Date: Wed, 27 Apr 2022 09:58:23 -0400 [thread overview]
Message-ID: <20220427135823.GD71@qian> (raw)
In-Reply-To: <20220422013215.2301793-1-tweek@google.com>
On Fri, Apr 22, 2022 at 11:32:15AM +1000, Thiébaud Weksteen wrote:
> drivers/base/firmware_loader/main.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
> index 94d1789a233e..8f3c2b2cfc61 100644
> --- a/drivers/base/firmware_loader/main.c
> +++ b/drivers/base/firmware_loader/main.c
> @@ -735,6 +735,8 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
> size_t offset, u32 opt_flags)
> {
> struct firmware *fw = NULL;
> + struct cred *kern_cred = NULL;
> + const struct cred *old_cred;
> bool nondirect = false;
> int ret;
>
> @@ -751,6 +753,18 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
> if (ret <= 0) /* error or already assigned */
> goto out;
>
> + /*
> + * We are about to try to access the firmware file. Because we may have been
> + * called by a driver when serving an unrelated request from userland, we use
> + * the kernel credentials to read the file.
> + */
> + kern_cred = prepare_kernel_cred(NULL);
This triggers quite some leak reports from kmemleak.
unreferenced object 0xffff0801e47690c0 (size 176):
comm "kworker/0:1", pid 14, jiffies 4294904047 (age 2208.624s)
hex dump (first 32 bytes):
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
kmem_cache_alloc
prepare_kernel_cred
_request_firmware
firmware_request_nowarn
firmware_request_nowarn at drivers/base/firmware_loader/main.c:933
nvkm_firmware_get [nouveau]
nvkm_firmware_get at drivers/gpu/drm/nouveau/nvkm/core/firmware.c:92
nvkm_firmware_load_name [nouveau]
nvkm_acr_lsfw_load_bl_inst_data_sig [nouveau]
gm200_gr_load [nouveau]
gf100_gr_new_ [nouveau]
tu102_gr_new [nouveau]
nvkm_device_ctor [nouveau]
nvkm_device_pci_new [nouveau]
nouveau_drm_probe [nouveau]
local_pci_probe
work_for_cpu_fn
process_one_work
> + if (!kern_cred) {
> + ret = -ENOMEM;
> + goto out;
> + }
> + old_cred = override_creds(kern_cred);
> +
> ret = fw_get_filesystem_firmware(device, fw->priv, "", NULL);
>
> /* Only full reads can support decompression, platform, and sysfs. */
> @@ -776,6 +790,8 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
> } else
> ret = assign_fw(fw, device);
>
> + revert_creds(old_cred);
> +
> out:
> if (ret < 0) {
> fw_abort_batch_reqs(fw);
> --
> 2.36.0.rc2.479.g8af0fa9b8e-goog
>
next prev parent reply other threads:[~2022-04-27 13:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-22 1:32 [PATCH v2] firmware_loader: use kernel credentials when reading firmware Thiébaud Weksteen
2022-04-22 14:37 ` Luis Chamberlain
2022-04-26 4:18 ` Thiébaud Weksteen
2022-04-26 16:31 ` Luis Chamberlain
2022-04-27 13:58 ` Qian Cai [this message]
2022-04-27 14:18 ` Greg Kroah-Hartman
2022-04-28 5:46 ` Thiébaud Weksteen
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=20220427135823.GD71@qian \
--to=quic_qiancai@quicinc.com \
--cc=adamshih@google.com \
--cc=adelva@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jeffv@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=saravanak@google.com \
--cc=selinux@vger.kernel.org \
--cc=tweek@google.com \
/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.