From: Viresh Kumar <viresh.kumar@linaro.org>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Dipen Patel <dipenp@nvidia.com>,
Thierry Reding <treding@nvidia.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] gpiolib: cdev: Don't access uninitialized descriptor
Date: Fri, 8 Jul 2022 16:55:48 +0530 [thread overview]
Message-ID: <585795d19c13a7136bc4b61307114591af2aea69.1657279521.git.viresh.kumar@linaro.org> (raw)
linereq_free() can be called from in the middle of errors, where the
descriptor may be NULL for few lines. Don't access uninitialized
descriptor pointer as it leads to kernel crash:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008
[...]
Call trace:
linereq_free+0x54/0xb8
linereq_create+0x424/0x570
gpio_ioctl+0x94/0x640
__arm64_sys_ioctl+0xac/0xf0
invoke_syscall+0x44/0x100
el0_svc_common.constprop.3+0x6c/0xf0
do_el0_svc+0x2c/0xb8
el0_svc+0x20/0x60
el0t_64_sync_handler+0x98/0xc0
el0t_64_sync+0x170/0x174
Fixes: 2068339a6c35 ("gpiolib: cdev: Add hardware timestamp clock type")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/gpio/gpiolib-cdev.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index f5aa5f93342a..d3d1b5aed282 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1460,11 +1460,13 @@ static ssize_t linereq_read(struct file *file,
static void linereq_free(struct linereq *lr)
{
unsigned int i;
- bool hte;
+ bool hte = false;
for (i = 0; i < lr->num_lines; i++) {
- hte = !!test_bit(FLAG_EVENT_CLOCK_HTE,
- &lr->lines[i].desc->flags);
+ if (lr->lines[i].desc) {
+ hte = !!test_bit(FLAG_EVENT_CLOCK_HTE,
+ &lr->lines[i].desc->flags);
+ }
edge_detector_stop(&lr->lines[i], hte);
if (lr->lines[i].desc)
gpiod_free(lr->lines[i].desc);
--
2.31.1.272.g89b43f80a514
next reply other threads:[~2022-07-08 11:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-08 11:25 Viresh Kumar [this message]
2022-07-08 13:31 ` [PATCH] gpiolib: cdev: Don't access uninitialized descriptor Bartosz Golaszewski
2022-07-08 15:13 ` Andy Shevchenko
2022-07-08 15:48 ` Bartosz Golaszewski
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=585795d19c13a7136bc4b61307114591af2aea69.1657279521.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=brgl@bgdev.pl \
--cc=dipenp@nvidia.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=treding@nvidia.com \
--cc=vincent.guittot@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).