Skip to content

Commit 6f95772

Browse files
committed
Fix firmware loader uevent buffer NULL pointer dereference
The firmware class uevent function accessed the "fw_priv->buf" buffer without the proper locking and testing for NULL. This is an old bug (looks like it goes back to 2012 and commit 1244691: "firmware loader: introduce firmware_buf"), but for some reason it's triggering only now in 4.2-rc1. Shuah Khan is trying to bisect what it is that causes this to trigger more easily, but in the meantime let's just fix the bug since others are hitting it too (at least Ingo reports having seen it as well). Reported-and-tested-by: Shuah Khan <[email protected]> Acked-by: Ming Lei <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6b7339f commit 6f95772

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/base/firmware_class.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,8 @@ static void fw_dev_release(struct device *dev)
563563
kfree(fw_priv);
564564
}
565565

566-
static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
566+
static int do_firmware_uevent(struct firmware_priv *fw_priv, struct kobj_uevent_env *env)
567567
{
568-
struct firmware_priv *fw_priv = to_firmware_priv(dev);
569-
570568
if (add_uevent_var(env, "FIRMWARE=%s", fw_priv->buf->fw_id))
571569
return -ENOMEM;
572570
if (add_uevent_var(env, "TIMEOUT=%i", loading_timeout))
@@ -577,6 +575,18 @@ static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
577575
return 0;
578576
}
579577

578+
static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
579+
{
580+
struct firmware_priv *fw_priv = to_firmware_priv(dev);
581+
int err = 0;
582+
583+
mutex_lock(&fw_lock);
584+
if (fw_priv->buf)
585+
err = do_firmware_uevent(fw_priv, env);
586+
mutex_unlock(&fw_lock);
587+
return err;
588+
}
589+
580590
static struct class firmware_class = {
581591
.name = "firmware",
582592
.class_attrs = firmware_class_attrs,

0 commit comments

Comments
 (0)