From: Wentao Liang <vulab@iscas.ac.cn>
To: Peter Rosin <peda@axentia.se>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
Kees Cook <kees@kernel.org>,
linux-kernel@vger.kernel.org, Wentao Liang <vulab@iscas.ac.cn>
Subject: [PATCH] mux: fix use-after-free and node leak in mux_get()
Date: Tue, 7 Apr 2026 03:53:06 +0000 [thread overview]
Message-ID: <20260407035306.243905-1-vulab@iscas.ac.cn> (raw)
In mux_get(), after obtaining args.np via of_parse_phandle_with_args(),
of_node_put(args.np) was called immediately. However, args.np is still
used in error paths for dev_err() printing. This leads to a use-after-
free when those error branches are taken.
Fix both issues by moving of_node_put(args.np) after all usage of
args.np, and introducing a common error label "put_and_ret_err" to
centralize node release. Also add missing of_node_put() in all error
path.
Fixes: 84564481bc45 ("mux: Add support for reading mux state from consumer DT node")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/mux/core.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index a3840fe0995f..517ad3075196 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -564,9 +564,10 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
}
mux_chip = of_find_mux_chip_by_node(args.np);
- of_node_put(args.np);
- if (!mux_chip)
- return ERR_PTR(-EPROBE_DEFER);
+ if (!mux_chip) {
+ ret = -EPROBE_DEFER;
+ goto put_and_ret_err;
+ }
controller = 0;
if (state) {
@@ -575,7 +576,8 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
dev_err(dev, "%pOF: wrong #mux-state-cells for %pOF\n",
np, args.np);
put_device(&mux_chip->dev);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto put_and_ret_err;
}
if (args.args_count == 2) {
@@ -591,7 +593,8 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
dev_err(dev, "%pOF: wrong #mux-control-cells for %pOF\n",
np, args.np);
put_device(&mux_chip->dev);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto put_and_ret_err;
}
if (args.args_count)
@@ -602,10 +605,16 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
dev_err(dev, "%pOF: bad mux controller %u specified in %pOF\n",
np, controller, args.np);
put_device(&mux_chip->dev);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto put_and_ret_err;
}
+ of_node_put(args.np);
return &mux_chip->mux[controller];
+
+put_and_ret_err:
+ of_node_put(args.np);
+ return ERR_PTR(ret);
}
/**
--
2.34.1
next reply other threads:[~2026-04-07 3:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 3:53 Wentao Liang [this message]
2026-04-08 8:10 ` Markus Elfring
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=20260407035306.243905-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peda@axentia.se \
--cc=thorsten.blum@linux.dev \
/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®